diff --git a/include/blah/app.h b/include/blah/app.h index d200149..1be0141 100644 --- a/include/blah/app.h +++ b/include/blah/app.h @@ -98,16 +98,13 @@ namespace Blah // Runs the application bool run(const Config* config); - // Returns whether the application is running - bool is_running(); - // Exits the application. // This only signals for the application to close, it will not stop // until the current update and render calls are finished. void exit(); // Gets the config data used to run the application - const Config* config(); + const Config& config(); // Gets the working path const char* path(); diff --git a/src/app.cpp b/src/app.cpp index b4746fa..c0f0013 100644 --- a/src/app.cpp +++ b/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() diff --git a/src/common.cpp b/src/common.cpp index 3cc4f71..7d95899 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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 { diff --git a/src/internal/platform_backend.h b/src/internal/platform_backend.h index 6ca47ac..8208ea5 100644 --- a/src/internal/platform_backend.h +++ b/src/internal/platform_backend.h @@ -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(); diff --git a/src/internal/platform_backend_sdl2.cpp b/src/internal/platform_backend_sdl2.cpp index aa9c68b..6ad0dc9 100644 --- a/src/internal/platform_backend_sdl2.cpp +++ b/src/internal/platform_backend_sdl2.cpp @@ -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; diff --git a/src/internal/platform_backend_win32.cpp b/src/internal/platform_backend_win32.cpp index cc6d1b2..37defab 100644 --- a/src/internal/platform_backend_win32.cpp +++ b/src/internal/platform_backend_win32.cpp @@ -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; }