diff --git a/inferno/src/inferno/settings.cpp b/inferno/src/inferno/settings.cpp index a483db8..4f6bd34 100644 --- a/inferno/src/inferno/settings.cpp +++ b/inferno/src/inferno/settings.cpp @@ -1,4 +1,4 @@ -#include // std::string +#include // std::string #include "inferno/file.h" #include "inferno/log.h" @@ -6,8 +6,6 @@ namespace Inferno { - bool Settings::m_initialized = false; - const char* Settings::m_path = "assets/settings.json"; SettingsProperties Settings::m_properties = {}; @@ -15,24 +13,18 @@ namespace Inferno { { Settings::update(); - m_initialized = true; - dbg(Log::Info) << "Settings initialized"; } void Settings::update() { - if (m_initialized) { - Settings::destroy(); - } - nlohmann::json json = Settings::load(); try { - m_properties.window.title = strdup(json["window"]["title"].get().c_str()); + m_properties.window.title = json["window"]["title"].get(); m_properties.window.width = json["window"]["width"].get(); m_properties.window.height = json["window"]["height"].get(); - m_properties.window.fullscreen = strdup(json["window"]["fullscreen"].get().c_str()) ; + m_properties.window.fullscreen = json["window"]["fullscreen"].get(); m_properties.window.vsync = json["window"]["vsync"].get(); } catch (...) { @@ -42,9 +34,6 @@ namespace Inferno { void Settings::destroy() { - // Delete const char*s created by strdup() - delete m_properties.window.title; - delete m_properties.window.fullscreen; } nlohmann::json Settings::load() diff --git a/inferno/src/inferno/settings.h b/inferno/src/inferno/settings.h index a628138..251a99c 100644 --- a/inferno/src/inferno/settings.h +++ b/inferno/src/inferno/settings.h @@ -20,13 +20,9 @@ namespace Inferno { static nlohmann::json load(); static bool save(); -// ----------------------------------------- - - static inline SettingsProperties &get() { return m_properties; } + static inline SettingsProperties& get() { return m_properties; } private: - static bool m_initialized; - static const char* m_path; static SettingsProperties m_properties; }; diff --git a/inferno/src/inferno/window.cpp b/inferno/src/inferno/window.cpp index ef6cbbc..b0a2b65 100644 --- a/inferno/src/inferno/window.cpp +++ b/inferno/src/inferno/window.cpp @@ -38,7 +38,7 @@ namespace Inferno { void Window::initialize() { - const char* title = m_properties.title; + std::string title = m_properties.title; unsigned int width = m_properties.width; unsigned int height = m_properties.height; @@ -54,7 +54,7 @@ namespace Inferno { // glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); // Create GLFW window - m_window = glfwCreateWindow(width, height, title, nullptr, nullptr); + m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); s_windowCount++; ASSERT(m_window, "Failed to create GLFW window!"); @@ -200,13 +200,13 @@ namespace Inferno { unsigned int height = m_properties.height; int refresh = GLFW_DONT_CARE; - const char* fullscreen = m_properties.fullscreen; + std::string fullscreen = m_properties.fullscreen; const GLFWvidmode* mode = glfwGetVideoMode(monitor); - if (strcmp(fullscreen, "fullscreen") == 0) { + if (fullscreen.compare("fullscreen") == 0) { refresh = mode->refreshRate; } - else if (strcmp(fullscreen, "borderless") == 0) { + else if (fullscreen.compare("borderless") == 0) { width = mode->width; height = mode->height; refresh = mode->refreshRate; diff --git a/inferno/src/inferno/window.h b/inferno/src/inferno/window.h index fad114a..e8e064e 100644 --- a/inferno/src/inferno/window.h +++ b/inferno/src/inferno/window.h @@ -3,6 +3,7 @@ #include // std::function #include // std::shared_ptr +#include // std::string struct GLFWwindow; @@ -12,10 +13,10 @@ namespace Inferno { class Event; struct WindowProperties { - const char* title = "Inferno"; + std::string title = "Inferno"; int width = 1280; int height = 720; - const char* fullscreen = "windowed"; // windowed/fullscreen/borderless + std::string fullscreen = "windowed"; // windowed/fullscreen/borderless bool vsync = true; };