mirror of
				https://github.com/NoelFB/blah.git
				synced 2025-11-04 01:41:34 +08:00 
			
		
		
		
	cleaning up App::config getter and removing App::is_running
This commit is contained in:
		
							
								
								
									
										11
									
								
								src/app.cpp
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								src/app.cpp
									
									
									
									
									
								
							@ -127,7 +127,7 @@ bool App::run(const Config* c)
 | 
			
		||||
	app_is_exiting = false;
 | 
			
		||||
 | 
			
		||||
	// initialize the system
 | 
			
		||||
	if (!PlatformBackend::init(&app_config))
 | 
			
		||||
	if (!PlatformBackend::init(app_config))
 | 
			
		||||
	{
 | 
			
		||||
		Log::error("Failed to initialize Platform module");
 | 
			
		||||
		return false;
 | 
			
		||||
@ -183,20 +183,15 @@ bool App::run(const Config* c)
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool App::is_running()
 | 
			
		||||
{
 | 
			
		||||
	return app_is_running;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void App::exit()
 | 
			
		||||
{
 | 
			
		||||
	if (!app_is_exiting && app_is_running)
 | 
			
		||||
		app_is_exiting = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const Config* App::config()
 | 
			
		||||
const Config& App::config()
 | 
			
		||||
{
 | 
			
		||||
	return &app_config;
 | 
			
		||||
	return app_config;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* App::path()
 | 
			
		||||
 | 
			
		||||
@ -13,9 +13,9 @@ void Log::info(const char* format, ...)
 | 
			
		||||
	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, 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
 | 
			
		||||
	{
 | 
			
		||||
@ -31,9 +31,9 @@ void Log::warn(const char* format, ...)
 | 
			
		||||
	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, 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
 | 
			
		||||
	{
 | 
			
		||||
@ -49,9 +49,9 @@ void Log::error(const char* format, ...)
 | 
			
		||||
	vsnprintf(msg, sizeof(char) * BLAH_MESSAGE, format, 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
 | 
			
		||||
	{
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ namespace Blah
 | 
			
		||||
		typedef void* FileHandle;
 | 
			
		||||
 | 
			
		||||
		// 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
 | 
			
		||||
		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
 | 
			
		||||
		// I'm not sure why SDL2 doesn't do this on Windows automatically?
 | 
			
		||||
@ -172,7 +172,7 @@ namespace Blah
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 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)
 | 
			
		||||
		{
 | 
			
		||||
			Log::error("Failed to create a Window");
 | 
			
		||||
@ -195,8 +195,8 @@ namespace Blah
 | 
			
		||||
				{
 | 
			
		||||
					SDL_DisplayMode mode;
 | 
			
		||||
					SDL_GetDesktopDisplayMode(display, &mode);
 | 
			
		||||
					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_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));
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
@ -264,9 +264,9 @@ namespace Blah
 | 
			
		||||
		{
 | 
			
		||||
			if (event.type == SDL_QUIT)
 | 
			
		||||
			{
 | 
			
		||||
				auto config = App::config();
 | 
			
		||||
				if (config->on_exit_request != nullptr)
 | 
			
		||||
					config->on_exit_request();
 | 
			
		||||
				auto& config = App::config();
 | 
			
		||||
				if (config.on_exit_request != nullptr)
 | 
			
		||||
					config.on_exit_request();
 | 
			
		||||
			}
 | 
			
		||||
			// Mouse
 | 
			
		||||
			else if (event.type == SDL_MOUSEBUTTONDOWN)
 | 
			
		||||
@ -554,8 +554,8 @@ namespace Blah
 | 
			
		||||
	{
 | 
			
		||||
		if (userPath == nullptr)
 | 
			
		||||
		{
 | 
			
		||||
			const Config* config = App::config();
 | 
			
		||||
			userPath = SDL_GetPrefPath(nullptr, config->name);
 | 
			
		||||
			auto& config = App::config();
 | 
			
		||||
			userPath = SDL_GetPrefPath(nullptr, config.name);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		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
 | 
			
		||||
		SetProcessDPIAware();
 | 
			
		||||
@ -182,7 +182,7 @@ namespace Blah
 | 
			
		||||
		RegisterClass(&wc);
 | 
			
		||||
 | 
			
		||||
		// 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
 | 
			
		||||
		if (g_hwnd == NULL)
 | 
			
		||||
@ -271,7 +271,7 @@ namespace Blah
 | 
			
		||||
				FilePath result;
 | 
			
		||||
				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);
 | 
			
		||||
		}
 | 
			
		||||
@ -288,8 +288,8 @@ namespace Blah
 | 
			
		||||
		// Setup Window Size
 | 
			
		||||
		{
 | 
			
		||||
			auto scale = get_content_scale();
 | 
			
		||||
			int sw = (int)(App::config()->width * scale);
 | 
			
		||||
			int sh = (int)(App::config()->height * scale);
 | 
			
		||||
			int sw = (int)(App::config().width * scale);
 | 
			
		||||
			int sh = (int)(App::config().height * scale);
 | 
			
		||||
			set_size(sw, sh);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -317,9 +317,9 @@ namespace Blah
 | 
			
		||||
		{
 | 
			
		||||
		case WM_CLOSE:
 | 
			
		||||
		{
 | 
			
		||||
			auto config = App::config();
 | 
			
		||||
			if (config->on_exit_request != nullptr)
 | 
			
		||||
				config->on_exit_request();
 | 
			
		||||
			auto& config = App::config();
 | 
			
		||||
			if (config.on_exit_request != nullptr)
 | 
			
		||||
				config.on_exit_request();
 | 
			
		||||
			return 0;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user