diff --git a/inferno/src/inferno/assert.h b/inferno/src/inferno/assert.h index 7168ae7..1c76171 100644 --- a/inferno/src/inferno/assert.h +++ b/inferno/src/inferno/assert.h @@ -2,6 +2,7 @@ #define ASSERT_H #include // raise +#include // uint32_t #include "inferno/core.h" #include "inferno/io/log.h" @@ -43,7 +44,7 @@ namespace Inferno { #ifdef NF_ENABLE_ASSERTS template - inline void __assert_fail(const char* assertion, const char* file, unsigned int line, const char* function, P&&... parameters) + inline void __assert_fail(const char* assertion, const char* file, uint32_t line, const char* function, P&&... parameters) { dangerln(false, "ASSERTION `{}' FAILED.", assertion); diff --git a/inferno/src/inferno/settings.cpp b/inferno/src/inferno/settings.cpp index 06909ad..973557c 100644 --- a/inferno/src/inferno/settings.cpp +++ b/inferno/src/inferno/settings.cpp @@ -1,8 +1,10 @@ -#include // std::string +#include // uint32_t +#include // std::string #include "inferno/io/file.h" #include "inferno/io/log.h" #include "inferno/settings.h" +#include "inferno/util/json.h" namespace Inferno { @@ -21,16 +23,23 @@ namespace Inferno { nlohmann::json json; Settings::load(json); - try { - 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 = json["window"]["fullscreen"].get(); - m_properties.window.vsync = json["window"]["vsync"].get(); - } - catch (...) { - warn() << "Settings syntax error: using default values"; + if (!Json::hasProperty(json, "window")) { + warn() << "Settings has no window section, using default values"; + return; } + + auto window = json["window"]; + auto title = Json::parseStringProperty(window, "title", false); + auto width = Json::parseUnsignedProperty(window, "width", false); + auto height = Json::parseUnsignedProperty(window, "height", false); + auto fullscreen = Json::parseStringProperty(window, "fullscreen", false); + auto vsync = Json::parseBoolProperty(window, "vsync", false); + + if (title) m_properties.window.title = title.value(); + if (width) m_properties.window.width = width.value(); + if (height) m_properties.window.height = height.value(); + if (fullscreen) m_properties.window.fullscreen = fullscreen.value(); + if (vsync) m_properties.window.vsync = vsync.value(); } void Settings::destroy() diff --git a/inferno/src/inferno/window.cpp b/inferno/src/inferno/window.cpp index be10619..c05614e 100644 --- a/inferno/src/inferno/window.cpp +++ b/inferno/src/inferno/window.cpp @@ -42,10 +42,10 @@ namespace Inferno { void Window::initialize() { - std::string title = m_properties.title; - unsigned int width = m_properties.width; - unsigned int height = m_properties.height; - bool vsync = m_properties.vsync; + std::string title = m_properties.title; + uint32_t width = m_properties.width; + uint32_t height = m_properties.height; + bool vsync = m_properties.vsync; // Only init once if (s_windowCount == 0) { diff --git a/inferno/src/inferno/window.h b/inferno/src/inferno/window.h index 574b074..69f51dd 100644 --- a/inferno/src/inferno/window.h +++ b/inferno/src/inferno/window.h @@ -1,6 +1,7 @@ #ifndef WINDOW_H #define WINDOW_H +#include // uint32_t #include // std::function #include // std::shared_ptr #include // std::string @@ -14,8 +15,8 @@ namespace Inferno { struct WindowProperties { std::string title { "Inferno" }; - int width = 1280; - int height = 720; + uint32_t width = 1280; + uint32_t height = 720; std::string fullscreen { "windowed" }; // windowed/fullscreen/borderless bool vsync = true; }; @@ -42,8 +43,8 @@ namespace Inferno { bool shouldClose() const; inline float getAspect() const { return static_cast(m_properties.width) / static_cast(m_properties.height); } - inline int getWidth() const { return m_properties.width; } - inline int getHeight() const { return m_properties.height; } + inline uint32_t getWidth() const { return m_properties.width; } + inline uint32_t getHeight() const { return m_properties.height; } inline GLFWwindow* getWindow() const { return m_window; } inline const std::shared_ptr& getContext() const { return m_context; }