diff --git a/include/blt/app.h b/include/blt/app.h index 53d585c..68bbe92 100644 --- a/include/blt/app.h +++ b/include/blt/app.h @@ -2,104 +2,51 @@ #include #include "traits.h" +#include #include #include "blt/std/logging.h" #include "status.h" #include "error_logging.h" +#include -namespace parks { - namespace Properties { - enum PROPERTIES { - // The display window's title - WINDOW_TITLE, - // the initial display width/height. This value does not change if the window is resized. Use Window::getWidth and Window::getHeight - WINDOW_WIDTH, - WINDOW_HEIGHT, - WINDOW_RESIZABLE, - RENDER_MODE, // INT - }; - - class Value_t { - public: - Value_t() = default; - - Value_t(const Value_t& value) = delete; - - virtual ~Value_t() = default; - - virtual void writeValue(std::ostream& ostream) = 0; - - virtual void readValue(std::istream istream) = 0; - }; - - template::value>::type* = nullptr> - class Value : public Value_t { - private: - T* m_Value; - public: - explicit Value(const T& v): m_Value(new T(v)) {} - - explicit Value(T* v): m_Value(v) {} - - Value() = default; - - inline const T& getValue() { return *m_Value; } - - inline void writeValue(std::ostream& ostream) final { - ostream << *m_Value; - } - - inline void readValue(std::istream istream) final { - istream >> *m_Value; - } - - ~Value() override { - delete m_Value; - } - }; - } +namespace blt::graphics { + enum class properties_t : int { + // The display window's title + WINDOW_TITLE, + // the initial display width/height. This value does not change if the window is resized. Use Window::getWidth and Window::getHeight + WINDOW_WIDTH, + WINDOW_HEIGHT, + WINDOW_RESIZABLE, + RENDER_MODE, // INT + }; + class Settings { public: + typedef std::variant property_t; Settings() = default; - ~Settings() { - for (auto* p : values) - delete p; - } + ~Settings() = default; - [[nodiscard]] Properties::Value_t* getProperty(Properties::PROPERTIES property) const { - //BLT_TRACE("Getting Property information (%d)", property); - //BLT_TRACE("Property: %d, Value: %d (Getting)", property, values[property]); - if (values.size() <= property) + [[nodiscard]] const property_t* getProperty(properties_t property) const { + if (values.size() <= static_cast(property)) return nullptr; - return values[property]; + return &values[static_cast(property)]; } template - [[nodiscard]] Properties::Value* getProperty(Properties::PROPERTIES property) const { - if (values.size() <= property) + [[nodiscard]] const T* getProperty(properties_t property) const { + if ((int)values.size() <= static_cast(property)) return nullptr; - return dynamic_cast*>(values[property]); + return &get(values[static_cast(property)]); } - void setProperty(Properties::PROPERTIES property, Properties::Value_t* value) { - BLT_TRACE("Setting property information (%d)", property); - BLT_TRACE("Values size / capacity (before): %d/%d", values.size(), - values.capacity()); - BLT_TRACE("Property: %d, Value: %d (Setting)", property, value); - if (values.capacity() <= property) - values.resize(property * 2); - values[property] = value; - BLT_TRACE("Values size / capacity (after): %d/%d", values.size(), - values.capacity()); - BLT_TRACE("Dumping values:"); - BLT_TRACE("---------------------"); - for (unsigned int i = 0; i < values.size(); i++) - BLT_TRACE("Value (%d): %d", i, values[i]); - BLT_TRACE("---------------------"); + void setProperty(properties_t property, property_t value) { + if (values.capacity() <= static_cast(property)) + values.resize(static_cast(property) * 2); + values[static_cast(property)] = std::move(value); } private: - std::vector values; + std::vector values; }; } \ No newline at end of file diff --git a/include/blt/config.h b/include/blt/config.h index e0f9cc9..31f9e78 100644 --- a/include/blt/config.h +++ b/include/blt/config.h @@ -7,7 +7,7 @@ #include -namespace parks { +namespace blt::graphics { # define PI 3.14159265358979323846 inline double degreeToRad(double deg){ diff --git a/include/blt/renderer/OpenGL.h b/include/blt/renderer/OpenGL.h index bc8b1b2..5e1c700 100644 --- a/include/blt/renderer/OpenGL.h +++ b/include/blt/renderer/OpenGL.h @@ -13,7 +13,7 @@ #include #include "stb/stb_image.h" -namespace parks { +namespace blt::graphics { class GLTexture2D { private: diff --git a/include/blt/renderer/engine.h b/include/blt/renderer/engine.h index 70749b3..9bedb38 100644 --- a/include/blt/renderer/engine.h +++ b/include/blt/renderer/engine.h @@ -15,7 +15,7 @@ #include "blt/shader/ui_shader.frag" #include "player.h" -namespace parks { +namespace blt::graphics { struct StaticEntity { blt::vec3 pos; uint32_t modelID; diff --git a/include/blt/renderer/player.h b/include/blt/renderer/player.h index 81424a0..fddfda8 100644 --- a/include/blt/renderer/player.h +++ b/include/blt/renderer/player.h @@ -8,7 +8,7 @@ #include "blt/math/vectors.h" #include "blt/math/matrix.h" -namespace parks { +namespace blt::graphics { class Controller; class CameraController; diff --git a/include/blt/renderer/resources.h b/include/blt/renderer/resources.h index 72dd732..7041c18 100644 --- a/include/blt/renderer/resources.h +++ b/include/blt/renderer/resources.h @@ -8,7 +8,7 @@ #include #include "OpenGL.h" -namespace parks::resources { +namespace blt::graphics::resources { namespace _defaults_ { static const std::string ASSUME_TEXTURE_NAME_ID = "NULL.NULL"; diff --git a/include/blt/status.h b/include/blt/status.h index 89e92aa..e0a3b7e 100644 --- a/include/blt/status.h +++ b/include/blt/status.h @@ -5,7 +5,7 @@ #ifndef PARKSNREC_STATUS_H #define PARKSNREC_STATUS_H -namespace parks { +namespace blt::graphics { static int NO_ERROR = 0; static int GLFW_ERROR = 1; static int GL_ERROR = 2; diff --git a/include/blt/traits.h b/include/blt/traits.h index b6903be..9b827bd 100644 --- a/include/blt/traits.h +++ b/include/blt/traits.h @@ -8,7 +8,7 @@ #include #include -namespace parks { +namespace blt::graphics { template struct is_streamable : public std::false_type {}; diff --git a/include/blt/window.h b/include/blt/window.h index 88a16c1..15f4fd9 100644 --- a/include/blt/window.h +++ b/include/blt/window.h @@ -6,7 +6,7 @@ #include "app.h" #include "blt/math/math.h" -namespace parks::Window { +namespace blt::graphics::Window { constexpr unsigned int UBO_MATRICES_COUNT = 4; diff --git a/src/parks/app.cpp b/src/parks/app.cpp index b85f4de..cb52487 100644 --- a/src/parks/app.cpp +++ b/src/parks/app.cpp @@ -1,5 +1,5 @@ #include "blt/app.h" -namespace parks { +namespace blt::graphics { } \ No newline at end of file diff --git a/src/parks/renderer/OpenGL.cpp b/src/parks/renderer/OpenGL.cpp index 4ae29a7..a8d138f 100644 --- a/src/parks/renderer/OpenGL.cpp +++ b/src/parks/renderer/OpenGL.cpp @@ -7,7 +7,7 @@ #include "blt/std/memory.h" #include -namespace parks { +namespace blt::graphics { static inline std::string removeEmptyFirstLines(const std::string &string) { auto lines = blt::string::split(string, "\n"); diff --git a/src/parks/renderer/engine.cpp b/src/parks/renderer/engine.cpp index fef2613..c9cf98e 100644 --- a/src/parks/renderer/engine.cpp +++ b/src/parks/renderer/engine.cpp @@ -9,7 +9,7 @@ #include #include -namespace parks { +namespace blt::graphics { Engine::Engine(const Settings& settings): settings(settings) { vao.bind(); @@ -42,11 +42,9 @@ namespace parks { basicCameraController.update(); #ifdef BUILD_DEV_TOOLS - auto renderMode = settings.getProperty( - Properties::RENDER_MODE - ); + auto renderMode = settings.getProperty(properties_t::RENDER_MODE); if (renderMode) - glPolygonMode(GL_FRONT_AND_BACK, renderMode->getValue()); + glPolygonMode(GL_FRONT_AND_BACK, *renderMode); if (Window::keyPressedLastFrame(GLFW_KEY_ESCAPE)) Window::setMouseVisible(!Window::isMouseVisible()); #endif diff --git a/src/parks/renderer/player.cpp b/src/parks/renderer/player.cpp index 0920fc3..bb23792 100644 --- a/src/parks/renderer/player.cpp +++ b/src/parks/renderer/player.cpp @@ -6,7 +6,7 @@ #include #include "blt/config.h" -namespace parks { +namespace blt::graphics { blt::mat4x4 CameraController::generateViewMatrix() { blt::mat4x4 view; diff --git a/src/parks/renderer/resources.cpp b/src/parks/renderer/resources.cpp index e6e0495..e4fa98b 100644 --- a/src/parks/renderer/resources.cpp +++ b/src/parks/renderer/resources.cpp @@ -10,7 +10,7 @@ #include "blt/error_logging.h" #include "blt/status.h" -namespace parks { +namespace blt::graphics { struct LoadableTexture { std::string path, name; diff --git a/src/parks/window.cpp b/src/parks/window.cpp index 928face..f19f2eb 100644 --- a/src/parks/window.cpp +++ b/src/parks/window.cpp @@ -8,7 +8,7 @@ #include #include -namespace parks { +namespace blt::graphics { std::string decodeGLFWError(int code) { switch (code) { @@ -110,9 +110,9 @@ namespace parks { glfwWindowHint(GLFW_SAMPLES, 4); window = glfwCreateWindow( - settings.getProperty(Properties::WINDOW_WIDTH)->getValue(), - settings.getProperty(Properties::WINDOW_HEIGHT)->getValue(), - settings.getProperty(Properties::WINDOW_TITLE)->getValue().c_str(), + *settings.getProperty(properties_t::WINDOW_WIDTH), + *settings.getProperty(properties_t::WINDOW_HEIGHT), + settings.getProperty(properties_t::WINDOW_TITLE)->c_str(), nullptr, nullptr ); @@ -159,7 +159,7 @@ namespace parks { void setupSharedWindowMatrices() { glGenBuffers(1, &Matrices.uboID); glBindBuffer(GL_UNIFORM_BUFFER, Matrices.uboID); - glBufferData(GL_UNIFORM_BUFFER, sizeof(blt::mat4x4) * parks::Window::UBO_MATRICES_COUNT, nullptr, GL_STATIC_DRAW); + glBufferData(GL_UNIFORM_BUFFER, sizeof(blt::mat4x4) * blt::graphics::Window::UBO_MATRICES_COUNT, nullptr, GL_STATIC_DRAW); glBindBufferBase(GL_UNIFORM_BUFFER, 0, Matrices.uboID); glBindBuffer(GL_UNIFORM_BUFFER, 0); } @@ -191,7 +191,7 @@ namespace parks { int version = gladLoadGL(glfwGetProcAddress); if (version == 0) { BLT_FATAL("Failed to initialize OpenGL context!"); - std::exit(parks::GL_ERROR); + std::exit(blt::graphics::GL_ERROR); } BLT_INFO("Loaded OpenGL %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version)); }