Browse Source

Convert Window properties strings to std::string, remove Settings initialized

master
Riyyi 3 years ago
parent
commit
cedce5e104
  1. 17
      inferno/src/inferno/settings.cpp
  2. 6
      inferno/src/inferno/settings.h
  3. 10
      inferno/src/inferno/window.cpp
  4. 5
      inferno/src/inferno/window.h

17
inferno/src/inferno/settings.cpp

@ -1,4 +1,4 @@
#include <string> // std::string
#include <string> // 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<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.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>();
}
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()

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

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

5
inferno/src/inferno/window.h

@ -3,6 +3,7 @@
#include <functional> // std::function
#include <memory> // std::shared_ptr
#include <string> // 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;
};

Loading…
Cancel
Save