Convert Window properties strings to std::string, remove Settings initialized
This commit is contained in:
@@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
bool Settings::m_initialized = false;
|
|
||||||
|
|
||||||
const char* Settings::m_path = "assets/settings.json";
|
const char* Settings::m_path = "assets/settings.json";
|
||||||
SettingsProperties Settings::m_properties = {};
|
SettingsProperties Settings::m_properties = {};
|
||||||
|
|
||||||
@@ -15,24 +13,18 @@ namespace Inferno {
|
|||||||
{
|
{
|
||||||
Settings::update();
|
Settings::update();
|
||||||
|
|
||||||
m_initialized = true;
|
|
||||||
|
|
||||||
dbg(Log::Info) << "Settings initialized";
|
dbg(Log::Info) << "Settings initialized";
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::update()
|
void Settings::update()
|
||||||
{
|
{
|
||||||
if (m_initialized) {
|
|
||||||
Settings::destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
nlohmann::json json = Settings::load();
|
nlohmann::json json = Settings::load();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_properties.window.title = strdup(json["window"]["title"].get<std::string>().c_str());
|
m_properties.window.title = json["window"]["title"].get<std::string>();
|
||||||
m_properties.window.width = json["window"]["width"].get<int>();
|
m_properties.window.width = json["window"]["width"].get<int>();
|
||||||
m_properties.window.height = json["window"]["height"].get<int>();
|
m_properties.window.height = json["window"]["height"].get<int>();
|
||||||
m_properties.window.fullscreen = strdup(json["window"]["fullscreen"].get<std::string>().c_str()) ;
|
m_properties.window.fullscreen = json["window"]["fullscreen"].get<std::string>();
|
||||||
m_properties.window.vsync = json["window"]["vsync"].get<bool>();
|
m_properties.window.vsync = json["window"]["vsync"].get<bool>();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
@@ -42,9 +34,6 @@ namespace Inferno {
|
|||||||
|
|
||||||
void Settings::destroy()
|
void Settings::destroy()
|
||||||
{
|
{
|
||||||
// Delete const char*s created by strdup()
|
|
||||||
delete m_properties.window.title;
|
|
||||||
delete m_properties.window.fullscreen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Settings::load()
|
nlohmann::json Settings::load()
|
||||||
|
|||||||
@@ -20,13 +20,9 @@ namespace Inferno {
|
|||||||
static nlohmann::json load();
|
static nlohmann::json load();
|
||||||
static bool save();
|
static bool save();
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
static inline SettingsProperties& get() { return m_properties; }
|
static inline SettingsProperties& get() { return m_properties; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static bool m_initialized;
|
|
||||||
|
|
||||||
static const char* m_path;
|
static const char* m_path;
|
||||||
static SettingsProperties m_properties;
|
static SettingsProperties m_properties;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace Inferno {
|
|||||||
|
|
||||||
void Window::initialize()
|
void Window::initialize()
|
||||||
{
|
{
|
||||||
const char* title = m_properties.title;
|
std::string title = m_properties.title;
|
||||||
unsigned int width = m_properties.width;
|
unsigned int width = m_properties.width;
|
||||||
unsigned int height = m_properties.height;
|
unsigned int height = m_properties.height;
|
||||||
|
|
||||||
@@ -54,7 +54,7 @@ namespace Inferno {
|
|||||||
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
// glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||||
|
|
||||||
// Create GLFW window
|
// Create GLFW window
|
||||||
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
||||||
s_windowCount++;
|
s_windowCount++;
|
||||||
ASSERT(m_window, "Failed to create GLFW window!");
|
ASSERT(m_window, "Failed to create GLFW window!");
|
||||||
|
|
||||||
@@ -200,13 +200,13 @@ namespace Inferno {
|
|||||||
unsigned int height = m_properties.height;
|
unsigned int height = m_properties.height;
|
||||||
int refresh = GLFW_DONT_CARE;
|
int refresh = GLFW_DONT_CARE;
|
||||||
|
|
||||||
const char* fullscreen = m_properties.fullscreen;
|
std::string fullscreen = m_properties.fullscreen;
|
||||||
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
|
||||||
|
|
||||||
if (strcmp(fullscreen, "fullscreen") == 0) {
|
if (fullscreen.compare("fullscreen") == 0) {
|
||||||
refresh = mode->refreshRate;
|
refresh = mode->refreshRate;
|
||||||
}
|
}
|
||||||
else if (strcmp(fullscreen, "borderless") == 0) {
|
else if (fullscreen.compare("borderless") == 0) {
|
||||||
width = mode->width;
|
width = mode->width;
|
||||||
height = mode->height;
|
height = mode->height;
|
||||||
refresh = mode->refreshRate;
|
refresh = mode->refreshRate;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <functional> // std::function
|
#include <functional> // std::function
|
||||||
#include <memory> // std::shared_ptr
|
#include <memory> // std::shared_ptr
|
||||||
|
#include <string> // std::string
|
||||||
|
|
||||||
struct GLFWwindow;
|
struct GLFWwindow;
|
||||||
|
|
||||||
@@ -12,10 +13,10 @@ namespace Inferno {
|
|||||||
class Event;
|
class Event;
|
||||||
|
|
||||||
struct WindowProperties {
|
struct WindowProperties {
|
||||||
const char* title = "Inferno";
|
std::string title = "Inferno";
|
||||||
int width = 1280;
|
int width = 1280;
|
||||||
int height = 720;
|
int height = 720;
|
||||||
const char* fullscreen = "windowed"; // windowed/fullscreen/borderless
|
std::string fullscreen = "windowed"; // windowed/fullscreen/borderless
|
||||||
bool vsync = true;
|
bool vsync = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user