Convert Settings to pure static
This commit is contained in:
@@ -23,7 +23,7 @@ namespace Inferno {
|
|||||||
s_instance = this;
|
s_instance = this;
|
||||||
|
|
||||||
// Initialize Settings
|
// Initialize Settings
|
||||||
new Settings();
|
Settings::initialize();
|
||||||
|
|
||||||
m_window = std::make_unique<Window>();
|
m_window = std::make_unique<Window>();
|
||||||
m_window->setEventCallback(NF_BIND_EVENT(Application::onEvent));
|
m_window->setEventCallback(NF_BIND_EVENT(Application::onEvent));
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ namespace Inferno {
|
|||||||
static float getMouseX();
|
static float getMouseX();
|
||||||
static float getMouseY();
|
static float getMouseY();
|
||||||
|
|
||||||
|
// -----------------------------------------
|
||||||
|
|
||||||
static inline float getXOffset() { return m_xOffset; }
|
static inline float getXOffset() { return m_xOffset; }
|
||||||
static inline float getYOffset() { return m_yOffset; }
|
static inline float getYOffset() { return m_yOffset; }
|
||||||
|
|
||||||
|
|||||||
@@ -1,46 +1,36 @@
|
|||||||
#include <fstream> // std::ifstream, std::ofstream
|
|
||||||
#include <iomanip> // std::setfill, std::setw
|
|
||||||
#include <string> // std::string
|
#include <string> // std::string
|
||||||
|
|
||||||
#include "inferno/core.h"
|
|
||||||
#include "inferno/file.h"
|
#include "inferno/file.h"
|
||||||
#include "inferno/log.h"
|
#include "inferno/log.h"
|
||||||
#include "inferno/settings.h"
|
#include "inferno/settings.h"
|
||||||
|
|
||||||
namespace Inferno {
|
namespace Inferno {
|
||||||
|
|
||||||
Settings* Settings::s_instance = nullptr;
|
bool Settings::m_initialized = false;
|
||||||
|
|
||||||
Settings::Settings(const char* path) :
|
const char* Settings::m_path = "assets/settings.json";
|
||||||
m_path(path)
|
SettingsProperties Settings::m_properties = {};
|
||||||
{
|
|
||||||
NF_CORE_ASSERT(!s_instance, "Settings already exists!");
|
|
||||||
s_instance = this;
|
|
||||||
|
|
||||||
this->initialize();
|
|
||||||
}
|
|
||||||
|
|
||||||
Settings::~Settings()
|
|
||||||
{
|
|
||||||
this->destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
void Settings::initialize()
|
void Settings::initialize()
|
||||||
{
|
{
|
||||||
this->update();
|
Settings::update();
|
||||||
|
|
||||||
|
m_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Settings::update()
|
void Settings::update()
|
||||||
{
|
{
|
||||||
nlohmann::json json = this->load();
|
if (m_initialized) {
|
||||||
|
Settings::destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
nlohmann::json json = Settings::load();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
m_properties.window.title = strdup(json["window"]["title"].get<std::string>().c_str());
|
m_properties.window.title = strdup(json["window"]["title"].get<std::string>().c_str());
|
||||||
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 = strdup(json["window"]["fullscreen"].get<std::string>().c_str()) ;
|
||||||
m_properties.window.vsync = json["window"]["vsync"].get<bool>();
|
m_properties.window.vsync = json["window"]["vsync"].get<bool>();
|
||||||
}
|
}
|
||||||
catch (...) {
|
catch (...) {
|
||||||
@@ -55,7 +45,7 @@ namespace Inferno {
|
|||||||
delete m_properties.window.fullscreen;
|
delete m_properties.window.fullscreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Settings::load() const
|
nlohmann::json Settings::load()
|
||||||
{
|
{
|
||||||
nlohmann::json json;
|
nlohmann::json json;
|
||||||
|
|
||||||
@@ -80,6 +70,4 @@ namespace Inferno {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,30 +13,22 @@ namespace Inferno {
|
|||||||
|
|
||||||
class Settings {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
Settings(const char* path = "assets/settings.json");
|
static void initialize();
|
||||||
virtual ~Settings();
|
static void update();
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
static nlohmann::json load();
|
||||||
|
static bool save();
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
|
|
||||||
void initialize();
|
static inline SettingsProperties &get() { return m_properties; }
|
||||||
void update();
|
|
||||||
// void render();
|
|
||||||
void destroy();
|
|
||||||
|
|
||||||
nlohmann::json load() const;
|
|
||||||
bool save();
|
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
|
|
||||||
static inline Settings &get() { return *s_instance; }
|
|
||||||
|
|
||||||
inline SettingsProperties &properties() { return m_properties; }
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* m_path;
|
static bool m_initialized;
|
||||||
SettingsProperties m_properties;
|
|
||||||
|
|
||||||
static Settings* s_instance;
|
static const char* m_path;
|
||||||
|
static SettingsProperties m_properties;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ namespace Inferno {
|
|||||||
Window::Window()
|
Window::Window()
|
||||||
{
|
{
|
||||||
m_windowProperties = {
|
m_windowProperties = {
|
||||||
Settings::get().properties().window.title,
|
Settings::get().window.title,
|
||||||
Settings::get().properties().window.width,
|
Settings::get().window.width,
|
||||||
Settings::get().properties().window.height,
|
Settings::get().window.height,
|
||||||
Settings::get().properties().window.fullscreen,
|
Settings::get().window.fullscreen,
|
||||||
Settings::get().properties().window.vsync,
|
Settings::get().window.vsync,
|
||||||
};
|
};
|
||||||
|
|
||||||
this->initialize();
|
this->initialize();
|
||||||
|
|||||||
Reference in New Issue
Block a user