update namepsaces to BLT. change property system to use std::variant
property system is now much simplermain
parent
bc0da7e7ba
commit
9f94b167d3
|
@ -2,14 +2,15 @@
|
|||
|
||||
#include <iostream>
|
||||
#include "traits.h"
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "blt/std/logging.h"
|
||||
#include "status.h"
|
||||
#include "error_logging.h"
|
||||
#include <variant>
|
||||
|
||||
namespace parks {
|
||||
namespace Properties {
|
||||
enum PROPERTIES {
|
||||
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
|
||||
|
@ -19,87 +20,33 @@ namespace parks {
|
|||
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<typename T, typename std::enable_if<parks::is_streamable<T>::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;
|
||||
}
|
||||
};
|
||||
}
|
||||
class Settings {
|
||||
public:
|
||||
typedef std::variant<int32_t, float, bool, std::string> 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<int>(property))
|
||||
return nullptr;
|
||||
return values[property];
|
||||
return &values[static_cast<int>(property)];
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
[[nodiscard]] Properties::Value<T>* getProperty(Properties::PROPERTIES property) const {
|
||||
if (values.size() <= property)
|
||||
[[nodiscard]] const T* getProperty(properties_t property) const {
|
||||
if ((int)values.size() <= static_cast<int>(property))
|
||||
return nullptr;
|
||||
return dynamic_cast<Properties::Value<T>*>(values[property]);
|
||||
return &get<T>(values[static_cast<int>(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<int>(property))
|
||||
values.resize(static_cast<int>(property) * 2);
|
||||
values[static_cast<int>(property)] = std::move(value);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<Properties::Value_t*> values;
|
||||
std::vector<property_t> values;
|
||||
};
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
# define PI 3.14159265358979323846
|
||||
inline double degreeToRad(double deg){
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#include <unordered_map>
|
||||
#include "stb/stb_image.h"
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
class GLTexture2D {
|
||||
private:
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "blt/math/vectors.h"
|
||||
#include "blt/math/matrix.h"
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
class Controller;
|
||||
class CameraController;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <string>
|
||||
#include "OpenGL.h"
|
||||
|
||||
namespace parks::resources {
|
||||
namespace blt::graphics::resources {
|
||||
|
||||
namespace _defaults_ {
|
||||
static const std::string ASSUME_TEXTURE_NAME_ID = "NULL.NULL";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <type_traits>
|
||||
#include <iostream>
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
template <typename T, typename Enable = void>
|
||||
struct is_streamable : public std::false_type {};
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "blt/app.h"
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
}
|
|
@ -7,7 +7,7 @@
|
|||
#include "blt/std/memory.h"
|
||||
#include <blt/std/loader.h>
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
static inline std::string removeEmptyFirstLines(const std::string &string) {
|
||||
auto lines = blt::string::split(string, "\n");
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#include <mutex>
|
||||
#include <barrier>
|
||||
|
||||
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<int>(
|
||||
Properties::RENDER_MODE
|
||||
);
|
||||
auto renderMode = settings.getProperty<int>(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
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
#include <imgui.h>
|
||||
#include "blt/config.h"
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
blt::mat4x4 CameraController::generateViewMatrix() {
|
||||
blt::mat4x4 view;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "blt/error_logging.h"
|
||||
#include "blt/status.h"
|
||||
|
||||
namespace parks {
|
||||
namespace blt::graphics {
|
||||
|
||||
struct LoadableTexture {
|
||||
std::string path, name;
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <imgui_spectrum.h>
|
||||
#include <blt/std/time.h>
|
||||
|
||||
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<int>(Properties::WINDOW_WIDTH)->getValue(),
|
||||
settings.getProperty<int>(Properties::WINDOW_HEIGHT)->getValue(),
|
||||
settings.getProperty<std::string>(Properties::WINDOW_TITLE)->getValue().c_str(),
|
||||
*settings.getProperty<int>(properties_t::WINDOW_WIDTH),
|
||||
*settings.getProperty<int>(properties_t::WINDOW_HEIGHT),
|
||||
settings.getProperty<std::string>(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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue