Skip to content

Commit

Permalink
WIP create Option system for distributing changes
Browse files Browse the repository at this point in the history
Only Double types are replaced, rest is only
replaced as testing the deduction. All types work,
but we need to migrate all to switch to the hash based
system without iteration.
  • Loading branch information
enginmanap committed Nov 21, 2024
1 parent 1b98487 commit 4e43252
Show file tree
Hide file tree
Showing 57 changed files with 552 additions and 401 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
#include(cotire)

IF (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -mconsole -Wall -Wextra -Wnon-virtual-dtor -pedantic")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -mconsole -Wall -Wextra -Wnon-virtual-dtor -pedantic -fdiagnostics-all-candidates")
set(CMAKE_EXE_LINKER_FLAGS "-fuse-ld=lld ${CMAKE_EXE_LINKER_FLAGS}")
set(WINDOWS_SPECIFIC_LINK_LIBRARIES "imm32")
else()
Expand Down
2 changes: 1 addition & 1 deletion GraphicBackends/OpenGLESGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ void OpenGLESGraphics::attachGeneralUBOs(const GLuint program){//Attach the ligh
}


OpenGLESGraphics::OpenGLESGraphics(Options *options): GraphicsInterface(options), options(options) {}
OpenGLESGraphics::OpenGLESGraphics(OptionsUtil::Options *options): GraphicsInterface(options), options(options) {}

OpenGLESGraphics::ContextInformation OpenGLESGraphics::getContextInformation() {
GraphicsInterface::ContextInformation contextInformation;
Expand Down
4 changes: 2 additions & 2 deletions GraphicBackends/OpenGLESGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class OpenGLESGraphics : public GraphicsInterface {

GLuint combineFrameBuffer;

Options *options;
OptionsUtil::Options *options;

const uint32_t lightUniformSize = (sizeof(glm::mat4) * 7) + (4 * sizeof(glm::vec4));
const uint32_t playerUniformSize = 6 * sizeof(glm::mat4) + 3 * sizeof(glm::vec4);
Expand Down Expand Up @@ -323,7 +323,7 @@ class OpenGLESGraphics : public GraphicsInterface {
public:


explicit OpenGLESGraphics(Options *options);
explicit OpenGLESGraphics(OptionsUtil::Options *options);

GraphicsInterface::ContextInformation getContextInformation();
bool createGraphicsBackend();
Expand Down
4 changes: 2 additions & 2 deletions GraphicBackends/OpenGLGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Utils/GLMUtils.h"
#include "Graphics/Texture.h"

std::shared_ptr<GraphicsInterface> createGraphicsBackend(Options* options) {
std::shared_ptr<GraphicsInterface> createGraphicsBackend(OptionsUtil::Options* options) {
return std::make_shared<OpenGLGraphics>(options);
}

Expand Down Expand Up @@ -321,7 +321,7 @@ void OpenGLGraphics::attachGeneralUBOs(const GLuint program){//Attach the light
}


OpenGLGraphics::OpenGLGraphics(Options *options): GraphicsInterface(options), options(options) {}
OpenGLGraphics::OpenGLGraphics(OptionsUtil::Options *options): GraphicsInterface(options), options(options) {}

OpenGLGraphics::ContextInformation OpenGLGraphics::getContextInformation() {
GraphicsInterface::ContextInformation contextInformation;
Expand Down
8 changes: 4 additions & 4 deletions GraphicBackends/OpenGLGraphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Light;
class GraphicsProgram;
class Texture;

extern "C" std::shared_ptr<GraphicsInterface> createGraphicsBackend(Options* options);
extern "C" std::shared_ptr<GraphicsInterface> createGraphicsBackend(OptionsUtil::Options* options);


class OpenGLGraphics : public GraphicsInterface {
Expand Down Expand Up @@ -209,7 +209,7 @@ class OpenGLGraphics : public GraphicsInterface {

GLuint combineFrameBuffer;

Options *options;
OptionsUtil::Options *options;

const uint32_t lightUniformSize = (sizeof(glm::mat4) * 6) + (4 * sizeof(glm::vec4));
const uint32_t playerUniformSize = 6 * sizeof(glm::mat4) + 3 * sizeof(glm::vec4);
Expand Down Expand Up @@ -324,7 +324,7 @@ class OpenGLGraphics : public GraphicsInterface {
public:


explicit OpenGLGraphics(Options *options);
explicit OpenGLGraphics(OptionsUtil::Options *options);

GraphicsInterface::ContextInformation getContextInformation();
bool createGraphicsBackend();
Expand Down Expand Up @@ -482,7 +482,7 @@ class OpenGLGraphics : public GraphicsInterface {
glScissor(x,y,width,height);
}

Options* getOptions() {
OptionsUtil::Options* getOptions() {
return options;
}
};
Expand Down
2 changes: 1 addition & 1 deletion libs/assimp
4 changes: 2 additions & 2 deletions src/API/Graphics/GraphicsInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class GraphicsInterface {
};

virtual void getRenderTriangleAndLineCount(uint32_t& triangleCount, uint32_t& lineCount) = 0;
explicit GraphicsInterface(Options *options [[gnu::unused]]) {};
explicit GraphicsInterface(OptionsUtil::Options *options [[gnu::unused]]) {};
virtual ContextInformation getContextInformation() = 0;
virtual bool createGraphicsBackend() = 0;
virtual ~GraphicsInterface() {};
Expand Down Expand Up @@ -184,7 +184,7 @@ class GraphicsInterface {
virtual void backupCurrentState() = 0;
virtual void restoreLastState() = 0;

virtual Options* getOptions() = 0;
virtual OptionsUtil::Options* getOptions() = 0;
};

#endif //LIMONENGINE_GRAPHICSINTERFACE_H
2 changes: 1 addition & 1 deletion src/BulletDebugDrawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "BulletDebugDrawer.h"
#include "Assets/AssetManager.h"

BulletDebugDrawer::BulletDebugDrawer(std::shared_ptr<AssetManager> assetManager, Options* options) : assetManager(assetManager), graphicsWrapper(assetManager->getGraphicsWrapper()), vao(0), vbo(0), ebo(0), options(options) {
BulletDebugDrawer::BulletDebugDrawer(std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options* options) : assetManager(assetManager), graphicsWrapper(assetManager->getGraphicsWrapper()), vao(0), vbo(0), ebo(0), options(options) {
renderProgram = std::make_shared<GraphicsProgram>(assetManager.get(), "./Engine/Shaders/Lines/vertex.glsl",
"./Engine/Shaders/Lines/fragment.glsl", false);
std::cout << "Render program is ready with id " << renderProgram->getID() << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/BulletDebugDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ class BulletDebugDrawer : public btIDebugDraw {
std::shared_ptr<GraphicsProgram> renderProgram;
uint32_t vao, vbo, ebo;
std::vector<Line> lineBuffer;
Options* options;
OptionsUtil::Options* options;
long debugDrawBufferSize;
public:
BulletDebugDrawer(std::shared_ptr<AssetManager> assetManager, Options* options);
BulletDebugDrawer(std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options* options);

void drawLine(const glm::vec3 &from, const glm::vec3 &to, const glm::vec3 &fromColor, const glm::vec3 &toColor, bool needsCameraTransform);

Expand Down
14 changes: 7 additions & 7 deletions src/Camera/CubeCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CubeCamera : public Camera {
std::vector<glm::mat4> renderMatrices;//these are used only for point lights for now
CameraAttachment* cameraAttachment;
glm::vec3 position, center, up, right;
Options *options;
OptionsUtil::Options *options;

bool dirty = true;
float activeDistance;
Expand All @@ -23,7 +23,7 @@ class CubeCamera : public Camera {

public:

CubeCamera(const std::string& name, Options *options, CameraAttachment* cameraAttachment) :
CubeCamera(const std::string& name, OptionsUtil::Options *options, CameraAttachment* cameraAttachment) :
cameraAttachment(cameraAttachment),
position(0,20,0),
center(glm::vec3(0, 0, -1)),
Expand Down Expand Up @@ -123,16 +123,16 @@ class CubeCamera : public Camera {

void setShadowMatricesForPosition(){
long sWidth, sHeight;
float near, far;
options->getOptionOrDefault("shadowMapPointWidth", sWidth, 512);
options->getOptionOrDefault("shadowMapPointHeight", sHeight, 512);
options->getOptionOrDefault("lightPerspectiveProjectionNearPlane", near, 0.1);
options->getOptionOrDefault("lightPerspectiveProjectionFarPlane", far, 100);

OptionsUtil::Options::Option<double> near = options->getOption<double>(HASH("lightPerspectiveProjectionNearPlane"));
OptionsUtil::Options::Option<double> far = options->getOption<double>(HASH("lightPerspectiveProjectionFarPlane"));

glm::mat4 lightProjectionMatrixPoint = glm::perspective(glm::radians(90.0f),
(float)sWidth/(float)sHeight,
near,
far);
(float)near.getOrDefault(0.1),
(float)far.getOrDefault(0.1));
renderMatrices[0] = lightProjectionMatrixPoint *
glm::lookAt(position, position + glm::vec3( 1.0, 0.0, 0.0), glm::vec3(0.0,-1.0, 0.0));
renderMatrices[1] = lightProjectionMatrixPoint *
Expand Down
12 changes: 6 additions & 6 deletions src/Camera/OrthographicCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class OrthographicCamera : public Camera {
std::vector<glm::vec4> frustumPlanes;
std::vector<glm::vec4> frustumCorners;
uint32_t cascadeIndex;
float lightOrthogonalProjectionZBottom;
Options *options;
OptionsUtil::Options *options;
OptionsUtil::Options::Option<double> lightOrthogonalProjectionZBottom;
uint32_t drawLineBufferId = 0;
uint32_t playerDrawLineBufferId = 0;
long frameCounter = 0;
Expand All @@ -29,19 +29,19 @@ class OrthographicCamera : public Camera {

public:

OrthographicCamera(const std::string &name, Options *options, uint32_t cascadeIndex, CameraAttachment *cameraAttachment) :
OrthographicCamera(const std::string &name, OptionsUtil::Options *options, uint32_t cascadeIndex, CameraAttachment *cameraAttachment) :
cameraAttachment(cameraAttachment),
position(0,20,0),
center(glm::vec3(0, 0, -1)),
up(glm::vec3(0, 1, 0)),
right(glm::vec3(-1, 0, 0)),
cascadeIndex(cascadeIndex),
options(options){
options(options),
lightOrthogonalProjectionZBottom(options->getOption<double>(HASH("lightOrthogonalProjectionBackOff"))){
this->name = name;

frustumPlanes.resize(6);
this->frustumCorners.resize(8);
options->getOptionOrDefault("lightOrthogonalProjectionBackOff", lightOrthogonalProjectionZBottom, -5000.0f);
}

CameraTypes getType() const override {
Expand Down Expand Up @@ -187,7 +187,7 @@ class OrthographicCamera : public Camera {
} else {
maxZ *= zMultiplier;
}
return glm::ortho(minX, maxX, minY, maxY, lightOrthogonalProjectionZBottom, maxZ);
return glm::ortho(minX, maxX, minY, maxY, (float)lightOrthogonalProjectionZBottom.getOrDefault(-5000.0f), maxZ);
}
};

Expand Down
12 changes: 7 additions & 5 deletions src/Camera/PerspectiveCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ class PerspectiveCamera : public Camera {
CameraAttachment* cameraAttachment;
float aspect;

Options *options;
OptionsUtil::Options *options;
bool dirty = true;

public:

PerspectiveCamera(const std::string& name, Options *options, CameraAttachment* cameraAttachment) :
PerspectiveCamera(const std::string& name, OptionsUtil::Options *options, CameraAttachment* cameraAttachment) :
view(glm::quat(0, 0, 0, -1)),
position(startPosition),
center(glm::vec3(0, 0, -1)),
Expand All @@ -51,7 +51,7 @@ class PerspectiveCamera : public Camera {
aspect = float(options->getScreenHeight()) / float(options->getScreenWidth());
this->frustumPlanes.resize(6);

perspectiveProjectionMatrix = glm::perspective(Options::PI/3.0f, 1.0f / aspect, 0.01f, 10000.0f);
perspectiveProjectionMatrix = glm::perspective(OptionsUtil::Options::PI/3.0f, 1.0f / aspect, 0.01f, 10000.0f);

long cascadeCount;
std::vector<float> cascadeLimits;
Expand All @@ -62,7 +62,9 @@ class PerspectiveCamera : public Camera {
this->frustumCorners.resize(1);
} else {
std::vector<long> cascadeListOption;
if(options->getOption("CascadeLimitList", cascadeListOption)) {
OptionsUtil::Options::Option<std::vector<long>> cascadeLimitListOptionOption = options->getOption<std::vector<long>>(HASH("CascadeLimitList"));
if(cascadeLimitListOptionOption.isUsable()) {
cascadeListOption = cascadeLimitListOptionOption.get();
//we have the option list, lets process
if(cascadeListOption.size() != (size_t)cascadeCount) {
std::cerr << "\"CascadeLimitList doesn't contain same number of elements as cascade count. Cascade setup will use defaults" << std::endl;
Expand All @@ -87,7 +89,7 @@ class PerspectiveCamera : public Camera {
}
//Now use the cascade limist to create the array of perspective projection matrixes
for (size_t i = 1; i < cascadeLimits.size(); ++i) {
cascadePerspectiveProjectionMatrices.emplace_back(glm::perspective(Options::PI / 3.0f, 1.0f / aspect, cascadeLimits[i - 1], cascadeLimits[i]));
cascadePerspectiveProjectionMatrices.emplace_back(glm::perspective(OptionsUtil::Options::PI / 3.0f, 1.0f / aspect, cascadeLimits[i - 1], cascadeLimits[i]));
}
frustumCorners.resize(cascadePerspectiveProjectionMatrices.size());
}
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/GUILayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void GUILayer::removeGuiElement(uint32_t guiElementID) {
}
}

bool GUILayer::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *LayersListNode, Options *options) {
bool GUILayer::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *LayersListNode, OptionsUtil::Options *options) {

tinyxml2::XMLElement *layerNode= document.NewElement("GUILayer");
LayersListNode->InsertEndChild(layerNode);
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/GUILayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GUILayer {

void setupForTime(long time);

bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *LayersListNode, Options *options);
bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *LayersListNode, OptionsUtil::Options *options);

GUIRenderable* getRenderableFromCoordinate(const glm::vec2& coordinates);
};
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/GUITextDynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GUITextDynamic: public GUITextBase {


public:
GUITextDynamic(GraphicsInterface* graphicsWrapper, Face *font, const glm::vec3 color, int width, int height, Options *options)
GUITextDynamic(GraphicsInterface* graphicsWrapper, Face *font, const glm::vec3 color, int width, int height, OptionsUtil::Options *options)
: GUITextBase(graphicsWrapper, font, color) {
lineHeight = face->getLineHeight()/64;
maxCharWidth = face->getMaxCharWidth()/64;
Expand Down
4 changes: 2 additions & 2 deletions src/GameObjects/GUIAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ GUIAnimation::~GUIAnimation() {
}


bool GUIAnimation::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, Options *options) {
bool GUIAnimation::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, OptionsUtil::Options *options) {
tinyxml2::XMLElement *guiButtonNode = document.NewElement("GUIElement");
parentNode->InsertEndChild(guiButtonNode);

Expand Down Expand Up @@ -109,7 +109,7 @@ bool GUIAnimation::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLEleme
}


GUIAnimation *GUIAnimation::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, Options *options) {
GUIAnimation *GUIAnimation::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options *options) {

tinyxml2::XMLElement* GUIRenderableAttribute;

Expand Down
4 changes: 2 additions & 2 deletions src/GameObjects/GUIAnimation.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class GUIAnimation : public GUIImageBase, public GameObject{

void addedToLayer(GUILayer* layer);

bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, Options *options);
bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, OptionsUtil::Options *options);

static GUIAnimation *
deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, Options *options); //will turn into factory class at some point
deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options *options); //will turn into factory class at some point

/******************** Game object methods ************************************/
ObjectTypes getTypeID() const override;
Expand Down
4 changes: 2 additions & 2 deletions src/GameObjects/GUIButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GUIButton::~GUIButton() {
}


bool GUIButton::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, Options *options) {
bool GUIButton::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, OptionsUtil::Options *options) {
tinyxml2::XMLElement *guiButtonNode = document.NewElement("GUIElement");
parentNode->InsertEndChild(guiButtonNode);

Expand Down Expand Up @@ -103,7 +103,7 @@ bool GUIButton::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement
}


GUIButton *GUIButton::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, Options *options,
GUIButton *GUIButton::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options *options,
LimonAPI *limonAPI) {

tinyxml2::XMLElement* GUIRenderableAttribute;
Expand Down
4 changes: 2 additions & 2 deletions src/GameObjects/GUIButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ class GUIButton : public GUIImageBase, public GameObject{

void addedToLayer(GUILayer* layer);

bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, Options *options);
bool serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, OptionsUtil::Options *options);

static GUIButton *deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, Options *options,
static GUIButton *deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options *options,
LimonAPI *limonAPI); //will turn into factory class at some point

void setOnHover(bool hover) {
Expand Down
6 changes: 3 additions & 3 deletions src/GameObjects/GUIImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "../Assets/TextureAsset.h"


GUIImage::GUIImage(uint32_t worldID, Options *options, std::shared_ptr<AssetManager> assetManager, const std::string name,
GUIImage::GUIImage(uint32_t worldID, OptionsUtil::Options *options, std::shared_ptr<AssetManager> assetManager, const std::string name,
const std::string &imageFile)
: GUIImageBase(
assetManager->getGraphicsWrapper(), assetManager, imageFile), worldID(worldID), name(name), options(options) {
Expand Down Expand Up @@ -40,7 +40,7 @@ GUIImage::~GUIImage() {
}


bool GUIImage::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, Options *options) {
bool GUIImage::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *parentNode, OptionsUtil::Options *options) {
tinyxml2::XMLElement *guiImageNode = document.NewElement("GUIElement");
parentNode->InsertEndChild(guiImageNode);

Expand Down Expand Up @@ -89,7 +89,7 @@ bool GUIImage::serialize(tinyxml2::XMLDocument &document, tinyxml2::XMLElement *
}


GUIImage *GUIImage::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, Options *options) {
GUIImage *GUIImage::deserialize(tinyxml2::XMLElement *GUIRenderableNode, std::shared_ptr<AssetManager> assetManager, OptionsUtil::Options *options) {

tinyxml2::XMLElement* GUIRenderableAttribute;

Expand Down
Loading

0 comments on commit 4e43252

Please sign in to comment.