diff --git a/src/dawn/display/IRenderManager.hpp b/src/dawn/display/IRenderManager.hpp index 2dd0c3a4..2dae0f24 100644 --- a/src/dawn/display/IRenderManager.hpp +++ b/src/dawn/display/IRenderManager.hpp @@ -58,14 +58,14 @@ namespace Dawn { * * @param renderFlags Render flags to use. */ - virtual void setRenderFlags(flag_t renderFlags) = 0; + virtual void setRenderFlags(const flag_t renderFlags) = 0; /** * Initialize / Start the Render Manager. * * @param game Game instance this render manager belongs to. */ - virtual void init(std::weak_ptr game) = 0; + virtual void init(const std::weak_ptr game) = 0; /** * Perform a synchronous frame update on the render manager. diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index ad349df4..e6b2f622 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -174,7 +174,7 @@ void RenderPipeline::renderSceneCamera(std::shared_ptr scene, std::shared ); // Now we've sorted everything! Let's actually start rendering. - Shader *boundShader = nullptr; + std::shared_ptr boundShader; std::map boundTextures; std::map boundBuffers; shaderbufferslot_t slot; diff --git a/src/dawn/display/shader/ShaderManager.cpp b/src/dawn/display/shader/ShaderManager.cpp index 527a4cf7..d6479629 100644 --- a/src/dawn/display/shader/ShaderManager.cpp +++ b/src/dawn/display/shader/ShaderManager.cpp @@ -13,9 +13,4 @@ ShaderManager::ShaderManager() { } ShaderManager::~ShaderManager() { - auto it = this->shaders.begin(); - while(it != this->shaders.end()) { - delete it->second; - ++it; - } } \ No newline at end of file diff --git a/src/dawn/display/shader/ShaderManager.hpp b/src/dawn/display/shader/ShaderManager.hpp index 88d494a3..892111a5 100644 --- a/src/dawn/display/shader/ShaderManager.hpp +++ b/src/dawn/display/shader/ShaderManager.hpp @@ -14,7 +14,7 @@ namespace Dawn { private: int32_t nextId; shaderlock_t nextLock; - std::map shaders; + std::map> shaders; std::map shaderLocks; std::map> shaderLocksByShader; @@ -28,7 +28,7 @@ namespace Dawn { shaderid_t getShaderId() { auto it = shaders.begin(); while(it != shaders.end()) { - auto asT = dynamic_cast(it->second); + auto asT = std::dynamic_pointer_cast(it->second); if(asT != nullptr) return asT->shaderId; ++it; } @@ -52,7 +52,7 @@ namespace Dawn { shaderlock_t lockShader() { auto shaderId = this->getShaderId(); if(shaderId == -1) { - T* shader = new T(); + auto shader = std::make_shared(); shader->compile(); shader->shaderId = this->nextId++; this->shaders[shader->shaderId] = shader; @@ -72,9 +72,9 @@ namespace Dawn { * @return The shader for the given lock. */ template - T * getShader(shaderlock_t lock) { + std::shared_ptr getShader(shaderlock_t lock) { auto shaderId = this->shaderLocks[lock]; - return (T*)this->shaders[shaderId]; + return std::static_pointer_cast(this->shaders[shaderId]); } /** @@ -94,8 +94,6 @@ namespace Dawn { if(locks.size() == 0) { this->shaderLocksByShader.erase(shaderId); - auto shader = (T*)this->shaders[shaderId]; - delete shader; this->shaders.erase(shaderId); } } diff --git a/src/dawn/display/shader/ShaderPass.hpp b/src/dawn/display/shader/ShaderPass.hpp index edc9eef0..1df1fd6d 100644 --- a/src/dawn/display/shader/ShaderPass.hpp +++ b/src/dawn/display/shader/ShaderPass.hpp @@ -11,7 +11,7 @@ namespace Dawn { struct ShaderPassItem; struct ShaderPassItem { - Shader *shader = nullptr; + std::shared_ptr shader; int32_t priority = 0; std::vector::iterator index; diff --git a/src/dawn/game/DawnGame.cpp b/src/dawn/game/DawnGame.cpp index 279ccab9..78926dd1 100644 --- a/src/dawn/game/DawnGame.cpp +++ b/src/dawn/game/DawnGame.cpp @@ -9,7 +9,7 @@ using namespace Dawn; DawnGame::DawnGame(const std::weak_ptr host) : host(host), - inputManager(this), + inputManager(), saveManager(this) { renderManager = std::make_shared(); diff --git a/src/dawn/host/DawnHost.hpp b/src/dawn/host/DawnHost.hpp index 47e25e50..a3cc9a6a 100644 --- a/src/dawn/host/DawnHost.hpp +++ b/src/dawn/host/DawnHost.hpp @@ -71,7 +71,7 @@ namespace Dawn { * @param delta How much time has passed (in seconds) since the last tick. * @return A status code, refer to DAWN_HOST_UPDATE_RESULT_{} definitions. */ - int32_t update(std::shared_ptr game, float_t delta); + int32_t update(std::shared_ptr game, const float_t delta); /** * Request the host to be unloaded. This is a bit different from dispose diff --git a/src/dawn/input/_InputManager.hpp b/src/dawn/input/_InputManager.hpp index dc22dfa4..99b47bdb 100644 --- a/src/dawn/input/_InputManager.hpp +++ b/src/dawn/input/_InputManager.hpp @@ -31,16 +31,9 @@ namespace Dawn { virtual float_t getInputValue(T axis) = 0; public: - DawnGame *game; - StateEvent eventBindPressed; StateEvent eventBindReleased; - IInputManager(DawnGame *game) { - assertNotNull(game, "IInputManager::IInputManager: Game cannot be null"); - this->game = game; - } - /** * Binds an axis to a bind. * diff --git a/src/dawnglfw/input/InputManager.cpp b/src/dawnglfw/input/InputManager.cpp index 634e32a8..084aee14 100644 --- a/src/dawnglfw/input/InputManager.cpp +++ b/src/dawnglfw/input/InputManager.cpp @@ -8,10 +8,6 @@ using namespace Dawn; -InputManager::InputManager(DawnGame *game) : IInputManager(game) { - -} - float_t InputManager::getInputValue(int32_t axis) { auto exist = this->rawInputValues.find(axis); if(exist == this->rawInputValues.end()) return 0.0f; diff --git a/src/dawnglfw/input/InputManager.hpp b/src/dawnglfw/input/InputManager.hpp index c9d48e0f..58b347e3 100644 --- a/src/dawnglfw/input/InputManager.hpp +++ b/src/dawnglfw/input/InputManager.hpp @@ -17,7 +17,5 @@ namespace Dawn { public: std::map rawInputValues; - - InputManager(DawnGame *game); }; } \ No newline at end of file diff --git a/src/dawnopengl/display/RenderManager.cpp b/src/dawnopengl/display/RenderManager.cpp index 82f35a32..599b0c74 100644 --- a/src/dawnopengl/display/RenderManager.cpp +++ b/src/dawnopengl/display/RenderManager.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "dawnopengl.hpp" +#include "assert/assertgl.hpp" #include "game/DawnGame.hpp" #include "display/RenderManager.hpp" @@ -15,11 +16,13 @@ RenderManager::RenderManager() : IRenderManager() { backBuffer = std::make_shared(*this); } -void RenderManager::init(std::weak_ptr game) { +void RenderManager::init(const std::weak_ptr game) { this->game = game; // Init the render pipeline - renderPipeline->init(std::static_pointer_cast(shared_from_this())); + renderPipeline->init( + std::static_pointer_cast(shared_from_this()) + ); // Lock the common shaders lockSimpleTextured = shaderManager->lockShader(); @@ -62,7 +65,7 @@ std::shared_ptr RenderManager::getShaderManager() { return shaderManager; } -void RenderManager::setRenderFlags(flag_t flags) { +void RenderManager::setRenderFlags(const flag_t flags) { renderFlags = flags; if((flags & RENDER_MANAGER_RENDER_FLAG_DEPTH_TEST) == 0) { diff --git a/src/dawnopengl/display/RenderManager.hpp b/src/dawnopengl/display/RenderManager.hpp index 657adf06..72a3eae1 100644 --- a/src/dawnopengl/display/RenderManager.hpp +++ b/src/dawnopengl/display/RenderManager.hpp @@ -4,7 +4,6 @@ // https://opensource.org/licenses/MIT #pragma once -#include "assert/assertgl.hpp" #include "display/BackBufferRenderTarget.hpp" #include "display/shader/ShaderManager.hpp" #include "display/shader/shaders/SimpleTexturedShader.hpp" @@ -23,9 +22,9 @@ namespace Dawn { public: std::shared_ptr backBuffer; - SimpleTexturedShader *simpleTexturedShader = nullptr; - UIShader *uiShader = nullptr; - FontShader *fontShader = nullptr; + std::shared_ptr simpleTexturedShader; + std::shared_ptr uiShader; + std::shared_ptr fontShader; /** * Construct a new RenderManager for a game instance. @@ -35,8 +34,8 @@ namespace Dawn { std::shared_ptr getBackBuffer() override; std::shared_ptr getRenderPipeline() override; std::shared_ptr getShaderManager() override; - void setRenderFlags(flag_t renderFlags) override; - void init(std::weak_ptr game) override; + void setRenderFlags(const flag_t renderFlags) override; + void init(const std::weak_ptr game) override; void update() override; /**