mirror of
				https://github.com/NoelFB/blah.git
				synced 2025-10-27 23:01:32 +08:00 
			
		
		
		
	cleaning up App::config getter and removing App::is_running
This commit is contained in:
		| @ -98,16 +98,13 @@ namespace Blah | |||||||
| 		// Runs the application | 		// Runs the application | ||||||
| 		bool run(const Config* config); | 		bool run(const Config* config); | ||||||
|  |  | ||||||
| 		// Returns whether the application is running |  | ||||||
| 		bool is_running(); |  | ||||||
|  |  | ||||||
| 		// Exits the application. | 		// Exits the application. | ||||||
| 		// This only signals for the application to close, it will not stop | 		// This only signals for the application to close, it will not stop | ||||||
| 		// until the current update and render calls are finished. | 		// until the current update and render calls are finished. | ||||||
| 		void exit(); | 		void exit(); | ||||||
|  |  | ||||||
| 		// Gets the config data used to run the application | 		// Gets the config data used to run the application | ||||||
| 		const Config* config(); | 		const Config& config(); | ||||||
|  |  | ||||||
| 		// Gets the working path | 		// Gets the working path | ||||||
| 		const char* path(); | 		const char* path(); | ||||||
|  | |||||||
							
								
								
									
										11
									
								
								src/app.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/app.cpp
									
									
									
									
									
								
							| @ -127,7 +127,7 @@ bool App::run(const Config* c) | |||||||
| 	app_is_exiting = false; | 	app_is_exiting = false; | ||||||
|  |  | ||||||
| 	// initialize the system | 	// initialize the system | ||||||
| 	if (!PlatformBackend::init(&app_config)) | 	if (!PlatformBackend::init(app_config)) | ||||||
| 	{ | 	{ | ||||||
| 		Log::error("Failed to initialize Platform module"); | 		Log::error("Failed to initialize Platform module"); | ||||||
| 		return false; | 		return false; | ||||||
| @ -183,20 +183,15 @@ bool App::run(const Config* c) | |||||||
| 	return true; | 	return true; | ||||||
| } | } | ||||||
|  |  | ||||||
| bool App::is_running() |  | ||||||
| { |  | ||||||
| 	return app_is_running; |  | ||||||
| } |  | ||||||
|  |  | ||||||
| void App::exit() | void App::exit() | ||||||
| { | { | ||||||
| 	if (!app_is_exiting && app_is_running) | 	if (!app_is_exiting && app_is_running) | ||||||
| 		app_is_exiting = true; | 		app_is_exiting = true; | ||||||
| } | } | ||||||
|  |  | ||||||
| const Config* App::config() | const Config& App::config() | ||||||
| { | { | ||||||
| 	return &app_config; | 	return app_config; | ||||||
| } | } | ||||||
|  |  | ||||||
| const char* App::path() | const char* App::path() | ||||||
|  | |||||||
| @ -13,9 +13,9 @@ void Log::info(const char* format, ...) | |||||||
| 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | ||||||
| 	va_end(ap); | 	va_end(ap); | ||||||
|  |  | ||||||
| 	if (App::is_running() && App::config()->on_log) | 	if (App::config().on_log) | ||||||
| 	{ | 	{ | ||||||
| 		App::config()->on_log(msg, Category::Info); | 		App::config().on_log(msg, Category::Info); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @ -31,9 +31,9 @@ void Log::warn(const char* format, ...) | |||||||
| 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | ||||||
| 	va_end(ap); | 	va_end(ap); | ||||||
|  |  | ||||||
| 	if (App::is_running() && App::config()->on_log) | 	if (App::config().on_log) | ||||||
| 	{ | 	{ | ||||||
| 		App::config()->on_log(msg, Category::Warning); | 		App::config().on_log(msg, Category::Warning); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
| @ -49,9 +49,9 @@ void Log::error(const char* format, ...) | |||||||
| 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | 	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, ap); | ||||||
| 	va_end(ap); | 	va_end(ap); | ||||||
|  |  | ||||||
| 	if (App::is_running() && App::config()->on_log) | 	if (App::config().on_log) | ||||||
| 	{ | 	{ | ||||||
| 		App::config()->on_log(msg, Category::Error); | 		App::config().on_log(msg, Category::Error); | ||||||
| 	} | 	} | ||||||
| 	else | 	else | ||||||
| 	{ | 	{ | ||||||
|  | |||||||
| @ -13,7 +13,7 @@ namespace Blah | |||||||
| 		typedef void* FileHandle; | 		typedef void* FileHandle; | ||||||
|  |  | ||||||
| 		// Initialize the System | 		// Initialize the System | ||||||
| 		bool init(const Config* config); | 		bool init(const Config& config); | ||||||
|  |  | ||||||
| 		// Called after the on_startup callback, but before the update loop begins | 		// Called after the on_startup callback, but before the update loop begins | ||||||
| 		void ready(); | 		void ready(); | ||||||
|  | |||||||
| @ -115,7 +115,7 @@ namespace Blah | |||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	bool PlatformBackend::init(const Config* config) | 	bool PlatformBackend::init(const Config& config) | ||||||
| 	{ | 	{ | ||||||
| 		// Required to call this for Windows | 		// Required to call this for Windows | ||||||
| 		// I'm not sure why SDL2 doesn't do this on Windows automatically? | 		// I'm not sure why SDL2 doesn't do this on Windows automatically? | ||||||
| @ -172,7 +172,7 @@ namespace Blah | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		// create the window | 		// create the window | ||||||
| 		window = SDL_CreateWindow(config->name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, config->width, config->height, flags); | 		window = SDL_CreateWindow(config.name, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, config.width, config.height, flags); | ||||||
| 		if (window == nullptr) | 		if (window == nullptr) | ||||||
| 		{ | 		{ | ||||||
| 			Log::error("Failed to create a Window"); | 			Log::error("Failed to create a Window"); | ||||||
| @ -195,8 +195,8 @@ namespace Blah | |||||||
| 				{ | 				{ | ||||||
| 					SDL_DisplayMode mode; | 					SDL_DisplayMode mode; | ||||||
| 					SDL_GetDesktopDisplayMode(display, &mode); | 					SDL_GetDesktopDisplayMode(display, &mode); | ||||||
| 					SDL_SetWindowPosition(window, (int)(mode.w - config->width * dpi) / 2, (int)(mode.h - config->height * dpi) / 2); | 					SDL_SetWindowPosition(window, (int)(mode.w - config.width * dpi) / 2, (int)(mode.h - config.height * dpi) / 2); | ||||||
| 					SDL_SetWindowSize(window, (int)(config->width * dpi), (int)(config->height * dpi)); | 					SDL_SetWindowSize(window, (int)(config.width * dpi), (int)(config.height * dpi)); | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| @ -264,9 +264,9 @@ namespace Blah | |||||||
| 		{ | 		{ | ||||||
| 			if (event.type == SDL_QUIT) | 			if (event.type == SDL_QUIT) | ||||||
| 			{ | 			{ | ||||||
| 				auto config = App::config(); | 				auto& config = App::config(); | ||||||
| 				if (config->on_exit_request != nullptr) | 				if (config.on_exit_request != nullptr) | ||||||
| 					config->on_exit_request(); | 					config.on_exit_request(); | ||||||
| 			} | 			} | ||||||
| 			// Mouse | 			// Mouse | ||||||
| 			else if (event.type == SDL_MOUSEBUTTONDOWN) | 			else if (event.type == SDL_MOUSEBUTTONDOWN) | ||||||
| @ -554,8 +554,8 @@ namespace Blah | |||||||
| 	{ | 	{ | ||||||
| 		if (userPath == nullptr) | 		if (userPath == nullptr) | ||||||
| 		{ | 		{ | ||||||
| 			const Config* config = App::config(); | 			auto& config = App::config(); | ||||||
| 			userPath = SDL_GetPrefPath(nullptr, config->name); | 			userPath = SDL_GetPrefPath(nullptr, config.name); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		return userPath; | 		return userPath; | ||||||
|  | |||||||
| @ -157,7 +157,7 @@ namespace Blah | |||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	bool PlatformBackend::init(const Config* config) | 	bool PlatformBackend::init(const Config& config) | ||||||
| 	{ | 	{ | ||||||
| 		// Required to call this for Windows | 		// Required to call this for Windows | ||||||
| 		SetProcessDPIAware(); | 		SetProcessDPIAware(); | ||||||
| @ -182,7 +182,7 @@ namespace Blah | |||||||
| 		RegisterClass(&wc); | 		RegisterClass(&wc); | ||||||
|  |  | ||||||
| 		// Create the Window Instance | 		// Create the Window Instance | ||||||
| 		g_hwnd = CreateWindow("BLAH WINDOW", config->name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 640, 480, NULL, NULL, hInstance, NULL); | 		g_hwnd = CreateWindow("BLAH WINDOW", config.name, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 640, 480, NULL, NULL, hInstance, NULL); | ||||||
|  |  | ||||||
| 		// Failed to create the Window | 		// Failed to create the Window | ||||||
| 		if (g_hwnd == NULL) | 		if (g_hwnd == NULL) | ||||||
| @ -271,7 +271,7 @@ namespace Blah | |||||||
| 				FilePath result; | 				FilePath result; | ||||||
| 				result.append_utf16((u16*)path, (u16*)end); | 				result.append_utf16((u16*)path, (u16*)end); | ||||||
|  |  | ||||||
| 				g_user_directory = Path::join(Path::normalize(result), config->name) + "/"; | 				g_user_directory = Path::join(Path::normalize(result), config.name) + "/"; | ||||||
| 			} | 			} | ||||||
| 			CoTaskMemFree(path); | 			CoTaskMemFree(path); | ||||||
| 		} | 		} | ||||||
| @ -288,8 +288,8 @@ namespace Blah | |||||||
| 		// Setup Window Size | 		// Setup Window Size | ||||||
| 		{ | 		{ | ||||||
| 			auto scale = get_content_scale(); | 			auto scale = get_content_scale(); | ||||||
| 			int sw = (int)(App::config()->width * scale); | 			int sw = (int)(App::config().width * scale); | ||||||
| 			int sh = (int)(App::config()->height * scale); | 			int sh = (int)(App::config().height * scale); | ||||||
| 			set_size(sw, sh); | 			set_size(sw, sh); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @ -317,9 +317,9 @@ namespace Blah | |||||||
| 		{ | 		{ | ||||||
| 		case WM_CLOSE: | 		case WM_CLOSE: | ||||||
| 		{ | 		{ | ||||||
| 			auto config = App::config(); | 			auto& config = App::config(); | ||||||
| 			if (config->on_exit_request != nullptr) | 			if (config.on_exit_request != nullptr) | ||||||
| 				config->on_exit_request(); | 				config.on_exit_request(); | ||||||
| 			return 0; | 			return 0; | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user