cleaning up App::config getter and removing App::is_running

This commit is contained in:
Noel Berry
2021-05-09 19:40:50 -07:00
parent c51d397ccc
commit 76525f91c5
6 changed files with 28 additions and 36 deletions

View File

@ -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();

View File

@ -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;

View File

@ -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;
}