update namepsaces to BLT. change property system to use std::variant
property system is now much simplermain
parent
bc0da7e7ba
commit
9f94b167d3
|
@ -2,104 +2,51 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "traits.h"
|
#include "traits.h"
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "blt/std/logging.h"
|
#include "blt/std/logging.h"
|
||||||
#include "status.h"
|
#include "status.h"
|
||||||
#include "error_logging.h"
|
#include "error_logging.h"
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
namespace Properties {
|
enum class properties_t : int {
|
||||||
enum PROPERTIES {
|
// The display window's title
|
||||||
// The display window's title
|
WINDOW_TITLE,
|
||||||
WINDOW_TITLE,
|
// the initial display width/height. This value does not change if the window is resized. Use Window::getWidth and Window::getHeight
|
||||||
// the initial display width/height. This value does not change if the window is resized. Use Window::getWidth and Window::getHeight
|
WINDOW_WIDTH,
|
||||||
WINDOW_WIDTH,
|
WINDOW_HEIGHT,
|
||||||
WINDOW_HEIGHT,
|
WINDOW_RESIZABLE,
|
||||||
WINDOW_RESIZABLE,
|
RENDER_MODE, // INT
|
||||||
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 {
|
class Settings {
|
||||||
public:
|
public:
|
||||||
|
typedef std::variant<int32_t, float, bool, std::string> property_t;
|
||||||
Settings() = default;
|
Settings() = default;
|
||||||
|
|
||||||
~Settings() {
|
~Settings() = default;
|
||||||
for (auto* p : values)
|
|
||||||
delete p;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] Properties::Value_t* getProperty(Properties::PROPERTIES property) const {
|
[[nodiscard]] const property_t* getProperty(properties_t property) const {
|
||||||
//BLT_TRACE("Getting Property information (%d)", property);
|
if (values.size() <= static_cast<int>(property))
|
||||||
//BLT_TRACE("Property: %d, Value: %d (Getting)", property, values[property]);
|
|
||||||
if (values.size() <= property)
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return values[property];
|
return &values[static_cast<int>(property)];
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
[[nodiscard]] Properties::Value<T>* getProperty(Properties::PROPERTIES property) const {
|
[[nodiscard]] const T* getProperty(properties_t property) const {
|
||||||
if (values.size() <= property)
|
if ((int)values.size() <= static_cast<int>(property))
|
||||||
return nullptr;
|
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) {
|
void setProperty(properties_t property, property_t value) {
|
||||||
BLT_TRACE("Setting property information (%d)", property);
|
if (values.capacity() <= static_cast<int>(property))
|
||||||
BLT_TRACE("Values size / capacity (before): %d/%d", values.size(),
|
values.resize(static_cast<int>(property) * 2);
|
||||||
values.capacity());
|
values[static_cast<int>(property)] = std::move(value);
|
||||||
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("---------------------");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Properties::Value_t*> values;
|
std::vector<property_t> values;
|
||||||
};
|
};
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
# define PI 3.14159265358979323846
|
# define PI 3.14159265358979323846
|
||||||
inline double degreeToRad(double deg){
|
inline double degreeToRad(double deg){
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include "stb/stb_image.h"
|
#include "stb/stb_image.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
class GLTexture2D {
|
class GLTexture2D {
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
#include "blt/shader/ui_shader.frag"
|
#include "blt/shader/ui_shader.frag"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
struct StaticEntity {
|
struct StaticEntity {
|
||||||
blt::vec3 pos;
|
blt::vec3 pos;
|
||||||
uint32_t modelID;
|
uint32_t modelID;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "blt/math/vectors.h"
|
#include "blt/math/vectors.h"
|
||||||
#include "blt/math/matrix.h"
|
#include "blt/math/matrix.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
class Controller;
|
class Controller;
|
||||||
class CameraController;
|
class CameraController;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "OpenGL.h"
|
#include "OpenGL.h"
|
||||||
|
|
||||||
namespace parks::resources {
|
namespace blt::graphics::resources {
|
||||||
|
|
||||||
namespace _defaults_ {
|
namespace _defaults_ {
|
||||||
static const std::string ASSUME_TEXTURE_NAME_ID = "NULL.NULL";
|
static const std::string ASSUME_TEXTURE_NAME_ID = "NULL.NULL";
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#ifndef PARKSNREC_STATUS_H
|
#ifndef PARKSNREC_STATUS_H
|
||||||
#define PARKSNREC_STATUS_H
|
#define PARKSNREC_STATUS_H
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
static int NO_ERROR = 0;
|
static int NO_ERROR = 0;
|
||||||
static int GLFW_ERROR = 1;
|
static int GLFW_ERROR = 1;
|
||||||
static int GL_ERROR = 2;
|
static int GL_ERROR = 2;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
template <typename T, typename Enable = void>
|
template <typename T, typename Enable = void>
|
||||||
struct is_streamable : public std::false_type {};
|
struct is_streamable : public std::false_type {};
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "app.h"
|
#include "app.h"
|
||||||
#include "blt/math/math.h"
|
#include "blt/math/math.h"
|
||||||
|
|
||||||
namespace parks::Window {
|
namespace blt::graphics::Window {
|
||||||
|
|
||||||
constexpr unsigned int UBO_MATRICES_COUNT = 4;
|
constexpr unsigned int UBO_MATRICES_COUNT = 4;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#include "blt/app.h"
|
#include "blt/app.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
}
|
}
|
|
@ -7,7 +7,7 @@
|
||||||
#include "blt/std/memory.h"
|
#include "blt/std/memory.h"
|
||||||
#include <blt/std/loader.h>
|
#include <blt/std/loader.h>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
static inline std::string removeEmptyFirstLines(const std::string &string) {
|
static inline std::string removeEmptyFirstLines(const std::string &string) {
|
||||||
auto lines = blt::string::split(string, "\n");
|
auto lines = blt::string::split(string, "\n");
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <barrier>
|
#include <barrier>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
Engine::Engine(const Settings& settings): settings(settings) {
|
Engine::Engine(const Settings& settings): settings(settings) {
|
||||||
vao.bind();
|
vao.bind();
|
||||||
|
@ -42,11 +42,9 @@ namespace parks {
|
||||||
basicCameraController.update();
|
basicCameraController.update();
|
||||||
|
|
||||||
#ifdef BUILD_DEV_TOOLS
|
#ifdef BUILD_DEV_TOOLS
|
||||||
auto renderMode = settings.getProperty<int>(
|
auto renderMode = settings.getProperty<int>(properties_t::RENDER_MODE);
|
||||||
Properties::RENDER_MODE
|
|
||||||
);
|
|
||||||
if (renderMode)
|
if (renderMode)
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, renderMode->getValue());
|
glPolygonMode(GL_FRONT_AND_BACK, *renderMode);
|
||||||
if (Window::keyPressedLastFrame(GLFW_KEY_ESCAPE))
|
if (Window::keyPressedLastFrame(GLFW_KEY_ESCAPE))
|
||||||
Window::setMouseVisible(!Window::isMouseVisible());
|
Window::setMouseVisible(!Window::isMouseVisible());
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
#include "blt/config.h"
|
#include "blt/config.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
blt::mat4x4 CameraController::generateViewMatrix() {
|
blt::mat4x4 CameraController::generateViewMatrix() {
|
||||||
blt::mat4x4 view;
|
blt::mat4x4 view;
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "blt/error_logging.h"
|
#include "blt/error_logging.h"
|
||||||
#include "blt/status.h"
|
#include "blt/status.h"
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
struct LoadableTexture {
|
struct LoadableTexture {
|
||||||
std::string path, name;
|
std::string path, name;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include <imgui_spectrum.h>
|
#include <imgui_spectrum.h>
|
||||||
#include <blt/std/time.h>
|
#include <blt/std/time.h>
|
||||||
|
|
||||||
namespace parks {
|
namespace blt::graphics {
|
||||||
|
|
||||||
std::string decodeGLFWError(int code) {
|
std::string decodeGLFWError(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
@ -110,9 +110,9 @@ namespace parks {
|
||||||
glfwWindowHint(GLFW_SAMPLES, 4);
|
glfwWindowHint(GLFW_SAMPLES, 4);
|
||||||
|
|
||||||
window = glfwCreateWindow(
|
window = glfwCreateWindow(
|
||||||
settings.getProperty<int>(Properties::WINDOW_WIDTH)->getValue(),
|
*settings.getProperty<int>(properties_t::WINDOW_WIDTH),
|
||||||
settings.getProperty<int>(Properties::WINDOW_HEIGHT)->getValue(),
|
*settings.getProperty<int>(properties_t::WINDOW_HEIGHT),
|
||||||
settings.getProperty<std::string>(Properties::WINDOW_TITLE)->getValue().c_str(),
|
settings.getProperty<std::string>(properties_t::WINDOW_TITLE)->c_str(),
|
||||||
nullptr, nullptr
|
nullptr, nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ namespace parks {
|
||||||
void setupSharedWindowMatrices() {
|
void setupSharedWindowMatrices() {
|
||||||
glGenBuffers(1, &Matrices.uboID);
|
glGenBuffers(1, &Matrices.uboID);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 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);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 0, Matrices.uboID);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ namespace parks {
|
||||||
int version = gladLoadGL(glfwGetProcAddress);
|
int version = gladLoadGL(glfwGetProcAddress);
|
||||||
if (version == 0) {
|
if (version == 0) {
|
||||||
BLT_FATAL("Failed to initialize OpenGL context!");
|
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));
|
BLT_INFO("Loaded OpenGL %d.%d", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue