diff --git a/inferno/src/inferno/settings.cpp b/inferno/src/inferno/settings.cpp index 5c16711..6c5e4f1 100644 --- a/inferno/src/inferno/settings.cpp +++ b/inferno/src/inferno/settings.cpp @@ -29,11 +29,11 @@ namespace Inferno { nlohmann::json m_json = this->load(); try { - m_properties.title = strdup(m_json["window"]["title"].get().c_str()); - m_properties.width = m_json["window"]["width"].get(); - m_properties.height = m_json["window"]["height"].get(); - m_properties.fullscreen = strdup(m_json["window"]["fullscreen"].get().c_str()); - m_properties.vsync = m_json["window"]["vsync"].get(); + m_properties.window.title = strdup(m_json["window"]["title"].get().c_str()); + m_properties.window.width = m_json["window"]["width"].get(); + m_properties.window.height = m_json["window"]["height"].get(); + m_properties.window.fullscreen = strdup(m_json["window"]["fullscreen"].get().c_str()); + m_properties.window.vsync = m_json["window"]["vsync"].get(); } catch (...) { NF_CORE_WARN("Settings syntax error: using default values"); @@ -43,8 +43,8 @@ namespace Inferno { void Settings::destroy() { // Delete const char*s created by strdup() - delete m_properties.title; - delete m_properties.fullscreen; + delete m_properties.window.title; + delete m_properties.window.fullscreen; } nlohmann::json Settings::load() const @@ -68,11 +68,11 @@ namespace Inferno { bool Settings::save() { nlohmann::json json; - json["window"]["title"] = m_properties.title; - json["window"]["width"] = m_properties.width; - json["window"]["height"] = m_properties.height; - json["window"]["fullscreen"] = m_properties.fullscreen; - json["window"]["vsync"] = m_properties.vsync; + json["window"]["title"] = m_properties.window.title; + json["window"]["width"] = m_properties.window.width; + json["window"]["height"] = m_properties.window.height; + json["window"]["fullscreen"] = m_properties.window.fullscreen; + json["window"]["vsync"] = m_properties.window.vsync; std::ofstream file (m_path); NF_CORE_ASSERT(file.is_open(), "Could not open settings file!"); diff --git a/inferno/src/inferno/settings.h b/inferno/src/inferno/settings.h index 768f4bf..6b5ac97 100644 --- a/inferno/src/inferno/settings.h +++ b/inferno/src/inferno/settings.h @@ -3,14 +3,12 @@ #include +#include "inferno/window.h" + namespace Inferno { struct SettingsProperties { - const char* title = "Inferno default"; - unsigned int width = 1280; - unsigned int height = 720; - const char* fullscreen = "windowed"; // windowed/fullscreen/borderless - bool vsync = true; + WindowProperties window; }; class Settings { diff --git a/inferno/src/inferno/window.cpp b/inferno/src/inferno/window.cpp index 4e291ce..82133e6 100644 --- a/inferno/src/inferno/window.cpp +++ b/inferno/src/inferno/window.cpp @@ -18,9 +18,11 @@ namespace Inferno { Window::Window() { m_windowProperties = { - Settings::get().properties().title, - Settings::get().properties().width, - Settings::get().properties().height, + Settings::get().properties().window.title, + Settings::get().properties().window.width, + Settings::get().properties().window.height, + Settings::get().properties().window.fullscreen, + Settings::get().properties().window.vsync, }; this->initialize(); @@ -33,9 +35,11 @@ namespace Inferno { void Window::initialize() { - const char* title = m_windowProperties.title; - unsigned int width = m_windowProperties.width; - unsigned int height = m_windowProperties.height; + const char* title = m_windowProperties.title; + unsigned int width = m_windowProperties.width; + unsigned int height = m_windowProperties.height; + const char* fullscreen = m_windowProperties.fullscreen; + bool vsync = m_windowProperties.vsync; // Only init once if (s_windowCount == 0) { @@ -52,11 +56,11 @@ namespace Inferno { // Windowed GLFWmonitor* monitor = nullptr; // Fullscreen - if (strcmp(Settings::get().properties().fullscreen, "fullscreen") == 0) { + if (strcmp(fullscreen, "fullscreen") == 0) { monitor = glfwGetPrimaryMonitor(); } // Borderless fullscreen - if (strcmp(Settings::get().properties().fullscreen, "borderless") == 0) { + if (strcmp(fullscreen, "borderless") == 0) { monitor = glfwGetPrimaryMonitor(); const GLFWvidmode* mode = glfwGetVideoMode(monitor); @@ -70,7 +74,7 @@ namespace Inferno { } // Vsync - if (!Settings::get().properties().vsync) { + if (!vsync) { glfwWindowHint(GLFW_DOUBLEBUFFER, GL_FALSE); } // -----------------------------------------