From 274c96bb6440ede5407a81b73babf16510ee4d55 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 25 Nov 2024 20:04:31 -0600 Subject: [PATCH] bit of cleanup --- src/dawn/asset/AssetDataLoader.cpp | 43 ++++++++++++++--------- src/dawn/asset/AssetDataLoader.hpp | 6 ++-- src/dawn/asset/AssetLoader.cpp | 2 +- src/dawn/asset/AssetLoader.hpp | 2 +- src/dawn/asset/AssetManager.cpp | 4 +-- src/dawn/asset/AssetManager.hpp | 8 ++--- src/dawn/asset/loader/JSONLoader.cpp | 2 +- src/dawn/asset/loader/JSONLoader.hpp | 2 +- src/dawn/asset/loader/TextureLoader.cpp | 2 +- src/dawn/asset/loader/TextureLoader.hpp | 2 +- src/dawn/asset/loader/TrueTypeLoader.cpp | 2 +- src/dawn/asset/loader/TrueTypeLoader.hpp | 2 +- src/dawn/component/Registry.cpp | 12 ------- src/dawn/component/Registry.hpp | 11 ------ src/dawn/component/display/Camera.cpp | 2 +- src/dawn/display/IRenderHost.cpp | 2 +- src/dawn/display/ITexture.hpp | 16 ++++----- src/dawn/display/RenderPipeline.cpp | 2 +- src/dawn/display/font/TrueTypeTexture.cpp | 8 ++--- src/dawn/display/font/TrueTypeTexture.hpp | 8 ++--- src/dawn/display/pass/RenderPass.hpp | 2 +- src/dawn/display/shader/IShader.cpp | 2 +- src/dawn/display/shader/IShader.hpp | 2 +- src/dawn/display/shader/IShaderStage.cpp | 2 +- src/dawn/display/shader/IShaderStage.hpp | 2 +- src/dawn/display/shader/ShaderManager.hpp | 18 +++++----- src/dawn/game/Game.cpp | 21 ++++++++--- src/dawn/game/Game.hpp | 6 ++-- src/dawn/locale/LocaleManager.cpp | 2 +- src/dawn/save/SaveManager.hpp | 4 +-- src/dawn/util/Math.hpp | 24 ++++++------- src/dawnglfw/display/RenderHost.cpp | 7 +++- src/dawnglfw/input/InputManager.cpp | 2 +- src/dawnlinux/main.cpp | 2 ++ src/dawnopengl/display/Texture.cpp | 4 +-- src/dawnopengl/display/Texture.hpp | 8 ++--- src/dawnrpg/scene/HelloWorldScene.cpp | 4 +-- 37 files changed, 128 insertions(+), 122 deletions(-) delete mode 100644 src/dawn/component/Registry.cpp delete mode 100644 src/dawn/component/Registry.hpp diff --git a/src/dawn/asset/AssetDataLoader.cpp b/src/dawn/asset/AssetDataLoader.cpp index 52b25da4..92b3191a 100644 --- a/src/dawn/asset/AssetDataLoader.cpp +++ b/src/dawn/asset/AssetDataLoader.cpp @@ -60,7 +60,9 @@ int32_t assetDataLoaderArchiveClose(struct archive *a, void *d) { // // // // // // // // // // // // // // // // // // // // // // // // // // // -AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) { +AssetDataLoader::AssetDataLoader(const std::string &fileName) : + fileName(fileName) +{ assertTrue( fileName.size() > 0, "IAssetDataLoader::IAssetDataLoader: fileName must be greater than 0" @@ -68,13 +70,16 @@ AssetDataLoader::AssetDataLoader(std::string fileName) : fileName(fileName) { } size_t AssetDataLoader::getSize() { - assertTrue(this->assetArchiveEntry != nullptr, "AssetDataLoader::getSize: Entry is NULL!"); - assertTrue(archive_entry_size_is_set(assetArchiveEntry), "assetGetSize: Entry size is not set!"); + assertTrue(this->assetArchiveEntry != nullptr, "Entry is NULL!"); + assertTrue( + archive_entry_size_is_set(assetArchiveEntry), + "Entry size is not set!" + ); return archive_entry_size(assetArchiveEntry); } size_t AssetDataLoader::getPosition() { - assertNotNull(this->assetArchiveFile, "AssetDataLoader::getPosition: File is not open!"); + assertNotNull(this->assetArchiveFile, "File is not open!"); return this->position; } @@ -123,8 +128,10 @@ void AssetDataLoader::open() { position = 0; // Iterate over each file to find the one for this asset loader. - while(archive_read_next_header(assetArchive, &assetArchiveEntry) == ARCHIVE_OK) { - const char_t *headerFile = (char_t*)archive_entry_pathname(assetArchiveEntry); + while(archive_read_next_header(assetArchive, &assetArchiveEntry)==ARCHIVE_OK){ + const char_t *headerFile = (char_t*)archive_entry_pathname( + assetArchiveEntry + ); if(std::string(headerFile) == this->fileName) return; int32_t ret = archive_read_data_skip(assetArchive); assertTrue(ret == ARCHIVE_OK, "Failed to skip data!"); @@ -151,11 +158,11 @@ int32_t AssetDataLoader::close() { return res; } -size_t AssetDataLoader::read(uint8_t *buffer, size_t size) { +size_t AssetDataLoader::read(uint8_t *buffer, const size_t &size) { assertNotNull(buffer, "Buffer is NULL!"); assertTrue(size > 0, "Size must be greater than 0!"); - assertNotNull(this->assetArchive, "assetRead: Archive is NULL!"); - assertNotNull(this->assetArchiveEntry, "assetRead: Entry is NULL!"); + assertNotNull(this->assetArchive, "Archive is NULL!"); + assertNotNull(this->assetArchiveEntry, "Entry is NULL!"); ssize_t read = archive_read_data(this->assetArchive, buffer, size); this->position += read; @@ -164,8 +171,8 @@ size_t AssetDataLoader::read(uint8_t *buffer, size_t size) { assertUnreachable(archive_error_string(this->assetArchive)); } - assertTrue(read != ARCHIVE_RETRY, "assetRead: Failed to read data (RETRY)!"); - assertTrue(read != ARCHIVE_WARN, "assetRead: Failed to read data (WARN)!"); + assertTrue(read != ARCHIVE_RETRY, "Failed to read data (RETRY)!"); + assertTrue(read != ARCHIVE_WARN, "Failed to read data (WARN)!"); return read; } @@ -185,17 +192,19 @@ size_t AssetDataLoader::readUntil( return i; } -size_t AssetDataLoader::skip(size_t n) { - assertTrue(n >= 0, "AssetDataLoader::skip: Byte count must be greater than 0."); +size_t AssetDataLoader::skip(const size_t &n) { + assertTrue(n >= 0, "Byte count must be greater than 0."); + assertTrue(n < (this->getSize() - this->position), "Cannot skip past EOF!"); uint8_t dumpBuffer[ASSET_LOADER_BUFFER_SIZE]; size_t skipped = 0; - size_t n2, n3; - while(n != 0) { + size_t n2, n3, n4; + n4 = n; + while(n4 != 0) { n2 = Math::min(n, ASSET_LOADER_BUFFER_SIZE); n3 = this->read(dumpBuffer, n2); - assertTrue(n3 == n2, "AssetDataLoader::skip: Failed to skip bytes!"); - n -= n3; + assertTrue(n3 == n2, "Failed to skip bytes!"); + n4 -= n3; } return skipped; diff --git a/src/dawn/asset/AssetDataLoader.hpp b/src/dawn/asset/AssetDataLoader.hpp index 926602b9..c06f095d 100644 --- a/src/dawn/asset/AssetDataLoader.hpp +++ b/src/dawn/asset/AssetDataLoader.hpp @@ -88,7 +88,7 @@ namespace Dawn { * * @param fileName File name of the asset that is to be loaded. */ - AssetDataLoader(std::string filename); + AssetDataLoader(const std::string &filename); /** * Get the size of the asset. @@ -134,7 +134,7 @@ namespace Dawn { * @param size Length of the data buffer (How many bytes to read). * @return The count of bytes read. */ - size_t read(uint8_t *buffer, size_t size); + size_t read(uint8_t *buffer, const size_t &size); /** * Reads bytes from the buffer until a given delimiter is found. Returned @@ -157,7 +157,7 @@ namespace Dawn { * @param n Count of bytes to progress the read head by. * @return Count of bytes progressed. */ - size_t skip(size_t n); + size_t skip(const size_t &n); /** * Rewind the read head to the beginning of the file. diff --git a/src/dawn/asset/AssetLoader.cpp b/src/dawn/asset/AssetLoader.cpp index e2e3a3a6..abdcd030 100644 --- a/src/dawn/asset/AssetLoader.cpp +++ b/src/dawn/asset/AssetLoader.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -AssetLoader::AssetLoader(const std::string name) : name(name) { +AssetLoader::AssetLoader(const std::string &name) : name(name) { assertTrue(name.size() > 0, "Asset::Asset: Name cannot be empty"); } diff --git a/src/dawn/asset/AssetLoader.hpp b/src/dawn/asset/AssetLoader.hpp index a9d78a2e..d971c444 100644 --- a/src/dawn/asset/AssetLoader.hpp +++ b/src/dawn/asset/AssetLoader.hpp @@ -17,7 +17,7 @@ namespace Dawn { * * @param name Name of the asset. */ - AssetLoader(const std::string name); + AssetLoader(const std::string &name); /** * Virtual function that will be called by the asset manager on a diff --git a/src/dawn/asset/AssetManager.cpp b/src/dawn/asset/AssetManager.cpp index 890e7686..f43c6675 100644 --- a/src/dawn/asset/AssetManager.cpp +++ b/src/dawn/asset/AssetManager.cpp @@ -26,7 +26,7 @@ void AssetManager::update() { } } -void AssetManager::removeExisting(const std::string filename) { +void AssetManager::removeExisting(const std::string &filename) { auto existing = std::find_if( pendingAssetLoaders.begin(), pendingAssetLoaders.end(), [&](auto &loader) { @@ -52,7 +52,7 @@ bool_t AssetManager::isEverythingLoaded() { return pendingAssetLoaders.size() == 0; } -bool_t AssetManager::isLoaded(const std::string filename) { +bool_t AssetManager::isLoaded(const std::string &filename) { auto existing = this->getExisting(filename); if(existing) return existing->loaded; return false; diff --git a/src/dawn/asset/AssetManager.hpp b/src/dawn/asset/AssetManager.hpp index ca1a6f27..b57cc91d 100644 --- a/src/dawn/asset/AssetManager.hpp +++ b/src/dawn/asset/AssetManager.hpp @@ -20,7 +20,7 @@ namespace Dawn { * @return The asset loader if it exists, otherwise nullptr. */ template - std::shared_ptr getExisting(const std::string filename) { + std::shared_ptr getExisting(const std::string &filename) { auto existing = std::find_if( pendingAssetLoaders.begin(), pendingAssetLoaders.end(), [&](auto &loader) { @@ -47,7 +47,7 @@ namespace Dawn { * * @param filename The filename of the asset to remove. */ - void removeExisting(const std::string filename); + void removeExisting(const std::string &filename); public: /** @@ -74,7 +74,7 @@ namespace Dawn { * @param filename The filename of the asset to check. * @return True if the asset has been loaded. */ - bool_t isLoaded(const std::string filename); + bool_t isLoaded(const std::string &filename); /** * Returns the asset loader for the given asset. @@ -83,7 +83,7 @@ namespace Dawn { * @return The asset loader for the given asset. */ template - std::shared_ptr get(const std::string filename) { + std::shared_ptr get(const std::string &filename) { auto existing = this->getExisting(filename); if(existing) return existing; diff --git a/src/dawn/asset/loader/JSONLoader.cpp b/src/dawn/asset/loader/JSONLoader.cpp index b713dd2d..30efbff9 100644 --- a/src/dawn/asset/loader/JSONLoader.cpp +++ b/src/dawn/asset/loader/JSONLoader.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -JSONLoader::JSONLoader(const std::string name) : +JSONLoader::JSONLoader(const std::string &name) : AssetLoader(name), loader(name), state(JSONLoaderState::INITIAL) diff --git a/src/dawn/asset/loader/JSONLoader.hpp b/src/dawn/asset/loader/JSONLoader.hpp index 3ffcff6f..58b3ad02 100644 --- a/src/dawn/asset/loader/JSONLoader.hpp +++ b/src/dawn/asset/loader/JSONLoader.hpp @@ -25,7 +25,7 @@ namespace Dawn { public: json data; - JSONLoader(const std::string name); + JSONLoader(const std::string &name); void updateSync() override; void updateAsync() override; ~JSONLoader(); diff --git a/src/dawn/asset/loader/TextureLoader.cpp b/src/dawn/asset/loader/TextureLoader.cpp index 14f2cbc8..a82ec130 100644 --- a/src/dawn/asset/loader/TextureLoader.cpp +++ b/src/dawn/asset/loader/TextureLoader.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -TextureLoader::TextureLoader(const std::string name) : +TextureLoader::TextureLoader(const std::string &name) : AssetLoader(name), loader(name + ".texture"), state(TextureLoaderLoadState::INITIAL) diff --git a/src/dawn/asset/loader/TextureLoader.hpp b/src/dawn/asset/loader/TextureLoader.hpp index d5b19ddf..8e3fbe07 100644 --- a/src/dawn/asset/loader/TextureLoader.hpp +++ b/src/dawn/asset/loader/TextureLoader.hpp @@ -41,7 +41,7 @@ namespace Dawn { * * @param name File name asset to load, omitting the extension. */ - TextureLoader(const std::string name); + TextureLoader(const std::string &name); void updateSync() override; void updateAsync() override; diff --git a/src/dawn/asset/loader/TrueTypeLoader.cpp b/src/dawn/asset/loader/TrueTypeLoader.cpp index 3d7a06b4..a37664c3 100644 --- a/src/dawn/asset/loader/TrueTypeLoader.cpp +++ b/src/dawn/asset/loader/TrueTypeLoader.cpp @@ -8,7 +8,7 @@ using namespace Dawn; -TrueTypeLoader::TrueTypeLoader(const std::string name) : +TrueTypeLoader::TrueTypeLoader(const std::string &name) : AssetLoader(name), loader(name + ".ttf") { diff --git a/src/dawn/asset/loader/TrueTypeLoader.hpp b/src/dawn/asset/loader/TrueTypeLoader.hpp index 8735dab4..1b23a0b4 100644 --- a/src/dawn/asset/loader/TrueTypeLoader.hpp +++ b/src/dawn/asset/loader/TrueTypeLoader.hpp @@ -33,7 +33,7 @@ namespace Dawn { * * @param name File name asset to load, omitting the extension. */ - TrueTypeLoader(const std::string name); + TrueTypeLoader(const std::string &name); void updateSync() override; void updateAsync() override; diff --git a/src/dawn/component/Registry.cpp b/src/dawn/component/Registry.cpp deleted file mode 100644 index 5e00bd1a..00000000 --- a/src/dawn/component/Registry.cpp +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#include "Registry.hpp" - -using namespace Dawn; - -void Dawn::someFunction(const char_t *someParam) { - printf("Hello, %s!\n", someParam); -} \ No newline at end of file diff --git a/src/dawn/component/Registry.hpp b/src/dawn/component/Registry.hpp deleted file mode 100644 index ba06050c..00000000 --- a/src/dawn/component/Registry.hpp +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2024 Dominic Masters -// -// This software is released under the MIT License. -// https://opensource.org/licenses/MIT - -#pragma once -#include "dawn.hpp" - -namespace Dawn { - static void someFunction(const char_t *someParam); -} \ No newline at end of file diff --git a/src/dawn/component/display/Camera.cpp b/src/dawn/component/display/Camera.cpp index 49a370c3..d988a7de 100644 --- a/src/dawn/component/display/Camera.cpp +++ b/src/dawn/component/display/Camera.cpp @@ -23,7 +23,7 @@ void Camera::onDispose() { std::shared_ptr Camera::getRenderTarget() { if(this->renderTarget) return this->renderTarget; - return getGame()->renderHost.getBackBufferRenderTarget(); + return getGame()->renderHost->getBackBufferRenderTarget(); } glm::mat4 Camera::getProjection() { diff --git a/src/dawn/display/IRenderHost.cpp b/src/dawn/display/IRenderHost.cpp index 06d8c5cf..f193affc 100644 --- a/src/dawn/display/IRenderHost.cpp +++ b/src/dawn/display/IRenderHost.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -IRenderHost::IRenderHost() : renderPipeline(), shaderManager() { +IRenderHost::IRenderHost() { } IRenderHost::~IRenderHost() { diff --git a/src/dawn/display/ITexture.hpp b/src/dawn/display/ITexture.hpp index dc0952e8..165c85b5 100644 --- a/src/dawn/display/ITexture.hpp +++ b/src/dawn/display/ITexture.hpp @@ -33,12 +33,12 @@ namespace Dawn { class ITexture { public: - enum TextureWrapMode wrapModeX = TextureWrapMode::REPEAT; - enum TextureWrapMode wrapModeY = TextureWrapMode::REPEAT; - enum TextureFilterMode filterModeMin = TextureFilterMode::NEAREST; - enum TextureFilterMode filterModeMag = TextureFilterMode::NEAREST; - enum TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST; - enum TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST; + TextureWrapMode wrapModeX = TextureWrapMode::REPEAT; + TextureWrapMode wrapModeY = TextureWrapMode::REPEAT; + TextureFilterMode filterModeMin = TextureFilterMode::NEAREST; + TextureFilterMode filterModeMag = TextureFilterMode::NEAREST; + TextureFilterMode mipMapFilterModeMin = TextureFilterMode::NEAREST; + TextureFilterMode mipMapFilterModeMag = TextureFilterMode::NEAREST; /** * Returns the width of the texture. @@ -65,8 +65,8 @@ namespace Dawn { virtual void setSize( const int32_t width, const int32_t height, - const enum TextureFormat format, - const enum TextureDataFormat dataFormat + const TextureFormat format, + const TextureDataFormat dataFormat ) = 0; /** diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index fc69fb5a..05fa1301 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -38,7 +38,7 @@ void RenderPipeline::renderScene( // Get a list of all cameras in the scene auto cameras = scene->findComponents(); - auto backBuffer = scene->getGame()->renderHost.getBackBufferRenderTarget(); + auto backBuffer = scene->getGame()->renderHost->getBackBufferRenderTarget(); std::shared_ptr backbufferCamera = nullptr; for(auto camera : cameras) { diff --git a/src/dawn/display/font/TrueTypeTexture.cpp b/src/dawn/display/font/TrueTypeTexture.cpp index e0bdc443..3aa3f75e 100644 --- a/src/dawn/display/font/TrueTypeTexture.cpp +++ b/src/dawn/display/font/TrueTypeTexture.cpp @@ -10,14 +10,14 @@ using namespace Dawn; -TrueTypeTexture::TrueTypeTexture(const uint32_t fontSize) : +TrueTypeTexture::TrueTypeTexture(const uint32_t &fontSize) : fontSize(fontSize) { assertTrue(fontSize > 0, "Font size cannot be zero"); texture = std::make_shared(); } -void TrueTypeTexture::setFace(const FT_Face face) { +void TrueTypeTexture::setFace(const FT_Face &face) { this->face = face; assertTrue(fontSize < 256, "Font size cannot be greater than 256"); @@ -130,7 +130,7 @@ void TrueTypeTexture::setFace(const FT_Face face) { delete[] buffer; } -struct TrueTypeCharacter TrueTypeTexture::getCharacterData(wchar_t c) { +struct TrueTypeCharacter TrueTypeTexture::getCharacterData(const wchar_t &c) { return this->characterData[c]; } @@ -138,7 +138,7 @@ glm::vec2 TrueTypeTexture::bufferStringToMesh( std::shared_ptr mesh, const std::wstring text, glm::vec2 &position, - bool_t flipY + const bool_t flipY ) { assertNotNull(mesh, "Mesh must be supplied and not null"); assertTrue(text.size() > 0, "Text must be at least one character long."); diff --git a/src/dawn/display/font/TrueTypeTexture.hpp b/src/dawn/display/font/TrueTypeTexture.hpp index ece25333..88b27775 100644 --- a/src/dawn/display/font/TrueTypeTexture.hpp +++ b/src/dawn/display/font/TrueTypeTexture.hpp @@ -25,14 +25,14 @@ namespace Dawn { * * @param fontSize Size of the font. */ - TrueTypeTexture(const uint32_t fontSize); + TrueTypeTexture(const uint32_t &fontSize); /** * Sets the face for this texture. * * @param face Face to set. */ - void setFace(const FT_Face face); + void setFace(const FT_Face &face); /** * Returns the character data for the given character. @@ -40,7 +40,7 @@ namespace Dawn { * @param c Character to get data for. * @return The Character data for the given character. */ - struct TrueTypeCharacter getCharacterData(wchar_t c); + struct TrueTypeCharacter getCharacterData(const wchar_t &c); /** * Buffers a string to the given mesh. @@ -55,7 +55,7 @@ namespace Dawn { std::shared_ptr mesh, const std::wstring text, glm::vec2 &position, - bool_t flipY = false + const bool_t flipY = false ); /** diff --git a/src/dawn/display/pass/RenderPass.hpp b/src/dawn/display/pass/RenderPass.hpp index 746c0136..53669b51 100644 --- a/src/dawn/display/pass/RenderPass.hpp +++ b/src/dawn/display/pass/RenderPass.hpp @@ -55,7 +55,7 @@ namespace Dawn { { //Get the shader shader = ( - self.getGame()->renderHost.shaderManager.getShader() + self.getGame()->renderHost->shaderManager.getShader() ); assertNotNull(shader, "Shader cannot be null!"); diff --git a/src/dawn/display/shader/IShader.cpp b/src/dawn/display/shader/IShader.cpp index 941406b1..cba02670 100644 --- a/src/dawn/display/shader/IShader.cpp +++ b/src/dawn/display/shader/IShader.cpp @@ -10,7 +10,7 @@ using namespace Dawn; -size_t shaderParameterTypeGetSize(const enum ShaderParameterType type) { +size_t shaderParameterTypeGetSize(const ShaderParameterType type) { switch(type) { case ShaderParameterType::VEC2: return sizeof(glm::vec2); diff --git a/src/dawn/display/shader/IShader.hpp b/src/dawn/display/shader/IShader.hpp index d83d5912..9cc7ff38 100644 --- a/src/dawn/display/shader/IShader.hpp +++ b/src/dawn/display/shader/IShader.hpp @@ -83,4 +83,4 @@ namespace Dawn { * @param type The type to get the size of. * @return Size of the type. */ -size_t shaderParameterTypeGetSize(const enum Dawn::ShaderParameterType type); \ No newline at end of file +size_t shaderParameterTypeGetSize(const Dawn::ShaderParameterType type); \ No newline at end of file diff --git a/src/dawn/display/shader/IShaderStage.cpp b/src/dawn/display/shader/IShaderStage.cpp index 1f395710..5fe3c852 100644 --- a/src/dawn/display/shader/IShaderStage.cpp +++ b/src/dawn/display/shader/IShaderStage.cpp @@ -7,7 +7,7 @@ using namespace Dawn; -IShaderStage::IShaderStage(const enum ShaderStageType type) : +IShaderStage::IShaderStage(const ShaderStageType type) : type(type) { diff --git a/src/dawn/display/shader/IShaderStage.hpp b/src/dawn/display/shader/IShaderStage.hpp index 87095e44..6d30a22d 100644 --- a/src/dawn/display/shader/IShaderStage.hpp +++ b/src/dawn/display/shader/IShaderStage.hpp @@ -22,7 +22,7 @@ namespace Dawn { * * @param type Type of shader stage. */ - IShaderStage(const enum ShaderStageType type); + IShaderStage(const ShaderStageType type); /** * Destroy the IShaderStage object diff --git a/src/dawn/display/shader/ShaderManager.hpp b/src/dawn/display/shader/ShaderManager.hpp index 762a7770..94224f1a 100644 --- a/src/dawn/display/shader/ShaderManager.hpp +++ b/src/dawn/display/shader/ShaderManager.hpp @@ -9,7 +9,7 @@ namespace Dawn { class ShaderManager { private: - std::vector> shaders; + std::vector> shaders; public: /** @@ -23,14 +23,12 @@ namespace Dawn { std::shared_ptr getShader() { auto itShaders = shaders.begin(); while(itShaders != shaders.end()) { - // auto shader = itShaders->lock(); - // if(!shader) { - // itShaders = shaders.erase(itShaders); - // continue; - // } - // std::shared_ptr casted = std::dynamic_pointer_cast(shader); + auto shader = itShaders->lock(); + if(!shader) { + itShaders = shaders.erase(itShaders); + continue; + } - auto shader = *itShaders; std::shared_ptr casted = std::dynamic_pointer_cast(shader); if(casted) return casted; itShaders++; @@ -41,5 +39,9 @@ namespace Dawn { newShader->init(); return newShader; } + + ~ShaderManager() { + shaders.clear(); + } }; } \ No newline at end of file diff --git a/src/dawn/game/Game.cpp b/src/dawn/game/Game.cpp index dd6c90f7..8d843ca5 100644 --- a/src/dawn/game/Game.cpp +++ b/src/dawn/game/Game.cpp @@ -14,8 +14,15 @@ Game::Game() { } void Game::init() { - localeManager.init(shared_from_this()); - renderHost.init(shared_from_this()); + renderHost = std::make_shared(); + renderHost->init(shared_from_this()); + + assetManager = std::make_shared(); + assetManager->init(); + + localeManager = std::make_shared(); + localeManager->init(shared_from_this()); + inputManager.init(shared_from_this()); saveManager.init(shared_from_this()); @@ -24,7 +31,7 @@ void Game::init() { } void Game::update() { - this->assetManager.update(); + this->assetManager->update(); if(nextFrameScene) { nextFrameScene->stage(); @@ -34,12 +41,12 @@ void Game::update() { timeManager.update(); if(currentScene) currentScene->update(); - renderHost.update(shared_from_this()); + renderHost->update(shared_from_this()); } bool_t Game::isCloseRequested() { return ( - renderHost.isCloseRequested() + renderHost->isCloseRequested() ); } @@ -48,4 +55,8 @@ std::shared_ptr Game::getCurrentScene() { } Game::~Game() { + currentScene = nullptr; + nextFrameScene = nullptr; + assetManager = nullptr; + renderHost = nullptr; } \ No newline at end of file diff --git a/src/dawn/game/Game.hpp b/src/dawn/game/Game.hpp index 31a09bc0..ef954c63 100644 --- a/src/dawn/game/Game.hpp +++ b/src/dawn/game/Game.hpp @@ -21,11 +21,11 @@ namespace Dawn { std::shared_ptr nextFrameScene = nullptr; public: - RenderHost renderHost; + std::shared_ptr renderHost; + std::shared_ptr assetManager; + std::shared_ptr localeManager; InputManager inputManager; TimeManager timeManager; - AssetManager assetManager; - LocaleManager localeManager; SaveManager saveManager; /** diff --git a/src/dawn/locale/LocaleManager.cpp b/src/dawn/locale/LocaleManager.cpp index 540e3050..97d2a1ec 100644 --- a/src/dawn/locale/LocaleManager.cpp +++ b/src/dawn/locale/LocaleManager.cpp @@ -17,7 +17,7 @@ void LocaleManager::init(const std::shared_ptr &game) { assertNotNull(game, "Game cannot be null."); this->game = game; - languageAsset = game->assetManager.get("en.json"); + languageAsset = game->assetManager->get("en.json"); } std::string LocaleManager::getString( diff --git a/src/dawn/save/SaveManager.hpp b/src/dawn/save/SaveManager.hpp index 74c6d2e8..a6f92424 100644 --- a/src/dawn/save/SaveManager.hpp +++ b/src/dawn/save/SaveManager.hpp @@ -50,7 +50,7 @@ namespace Dawn { * * @param slot Slot to delete. */ - void deleteSlot(int8_t slot); + void deleteSlot(const int8_t slot); /** * Returns the current slotted save file. @@ -64,7 +64,7 @@ namespace Dawn { * * @param slot The slot to set. */ - void useSlot(int8_t slot); + void useSlot(const int8_t slot); /** * Returns a list of used save slots, does not confirm if they are corrupt diff --git a/src/dawn/util/Math.hpp b/src/dawn/util/Math.hpp index 549fd22f..8429bb73 100644 --- a/src/dawn/util/Math.hpp +++ b/src/dawn/util/Math.hpp @@ -21,7 +21,7 @@ namespace Dawn { * @return The larger of the two numbers */ template - static T max(T left, T right) { + static T max(const T &left, const T &right) { return left < right ? right : left; } @@ -33,7 +33,7 @@ namespace Dawn { * @return Smaller of the two numbers. */ template - static T min(T left, T right) { + static T min(const T &left, const T &right) { return left < right ? left : right; } @@ -47,7 +47,7 @@ namespace Dawn { * @return The value, or the closest clamped value. */ template - static T clamp(T val, T min, T max) { + static T clamp(const T &val, const T &min, const T &max) { return mathMin(mathMax(val, min), max); } @@ -59,7 +59,7 @@ namespace Dawn { * @return The absolute value (-value if value < 0) */ template - static T abs(T value) { + static T abs(const T &value) { return value < 0 ? -value : value; } @@ -71,11 +71,11 @@ namespace Dawn { * @returns The modulo result. */ template - static inline T mod(T value, T modulo) { + static inline T mod(const T &value, const T &modulo) { return ((value % modulo) + modulo) % modulo; } - static inline float_t fmod(float_t value, float_t modulo) { + static inline float_t fmod(const float_t &value, const float_t &modulo) { float_t n = fmod(value, modulo); return n; } @@ -86,7 +86,7 @@ namespace Dawn { * @param n Degrees to convert. * @returns The number in radians. */ - static float_t deg2rad(float_t degrees) { + static float_t deg2rad(const float_t °rees) { return degrees * (MATH_PI / 180.0f); } @@ -95,7 +95,7 @@ namespace Dawn { * @param n Radians to convert. * @returns The number in degrees. */ - static float_t rad2deg(float_t n) { + static float_t rad2deg(const float_t &n) { return (n * 180.0f) / MATH_PI; } @@ -105,7 +105,7 @@ namespace Dawn { * @return Rounded number. */ template - static T round(const float_t n) { + static T round(const float_t &n) { return (T)roundf(n); } @@ -115,7 +115,7 @@ namespace Dawn { * @return Rounded number. */ template - static T floor(const float_t n) { + static T floor(const float_t &n) { return (T)floorf(n); } @@ -125,12 +125,12 @@ namespace Dawn { * @param n Number to get the square root of. * @return float_t */ - static float_t sqrt(const float_t n) { + static float_t sqrt(const float_t &n) { return sqrtf(n); } template - static T ceil(const float_t n) { + static T ceil(const float_t &n) { return (T)ceilf(n); } diff --git a/src/dawnglfw/display/RenderHost.cpp b/src/dawnglfw/display/RenderHost.cpp index 9549290b..3004aab5 100644 --- a/src/dawnglfw/display/RenderHost.cpp +++ b/src/dawnglfw/display/RenderHost.cpp @@ -79,7 +79,7 @@ void RenderHost::init(const std::shared_ptr game) { // if(this->window == nullptr || window != this->window) return; Game* game = (Game*)glfwGetWindowUserPointer(window); assertNotNull(game, "Game cannot be null!"); - game->renderHost.backBufferRenderTarget->setSize(width, height); + game->renderHost->backBufferRenderTarget->setSize(width, height); }); } @@ -94,12 +94,16 @@ void RenderHost::update(const std::shared_ptr game) { GL_ONE_MINUS_SRC_ALPHA ); assertNoGLError(); + glDepthMask(GL_TRUE); assertNoGLError(); + glDepthFunc(GL_LESS); assertNoGLError(); + // glEnable(GL_DEPTH_TEST); assertNoGLError(); + glEnable(GL_BLEND); assertNoGLError(); @@ -123,6 +127,7 @@ std::shared_ptr RenderHost::getBackBufferRenderTarget() { } RenderHost::~RenderHost() { + std::cout << "RenderHost cleanup" << std::endl; if(this->window != nullptr) { glfwDestroyWindow(this->window); this->window = nullptr; diff --git a/src/dawnglfw/input/InputManager.cpp b/src/dawnglfw/input/InputManager.cpp index 08698a1c..98080202 100644 --- a/src/dawnglfw/input/InputManager.cpp +++ b/src/dawnglfw/input/InputManager.cpp @@ -9,7 +9,7 @@ using namespace Dawn; void InputManager::init(const std::shared_ptr game) { - auto window = game->renderHost.window; + auto window = game->renderHost->window; glfwSetCursorPosCallback(window, []( GLFWwindow* window, diff --git a/src/dawnlinux/main.cpp b/src/dawnlinux/main.cpp index e26b1e4c..f2cdc23a 100644 --- a/src/dawnlinux/main.cpp +++ b/src/dawnlinux/main.cpp @@ -73,5 +73,7 @@ int32_t main(int32_t argc, const char **argv) { game->update(); } + game = nullptr; + return 0; } \ No newline at end of file diff --git a/src/dawnopengl/display/Texture.cpp b/src/dawnopengl/display/Texture.cpp index 90c5cf39..f124dd30 100644 --- a/src/dawnopengl/display/Texture.cpp +++ b/src/dawnopengl/display/Texture.cpp @@ -33,8 +33,8 @@ bool_t Texture::isReady() { void Texture::setSize( const int32_t width, const int32_t height, - const enum TextureFormat format, - const enum TextureDataFormat dataFormat + const TextureFormat format, + const TextureDataFormat dataFormat ) { if(this->id != -1) { glDeleteTextures(1, &this->id); diff --git a/src/dawnopengl/display/Texture.hpp b/src/dawnopengl/display/Texture.hpp index 15677102..be459cc9 100644 --- a/src/dawnopengl/display/Texture.hpp +++ b/src/dawnopengl/display/Texture.hpp @@ -17,8 +17,8 @@ namespace Dawn { int32_t width = -1; int32_t height = -1; GLuint id = -1; - enum TextureFormat format; - enum TextureDataFormat dataFormat; + TextureFormat format; + TextureDataFormat dataFormat; void updateTextureProperties(); void bufferRaw(const void *data); @@ -29,8 +29,8 @@ namespace Dawn { void setSize( const int32_t width, const int32_t height, - const enum TextureFormat format, - const enum TextureDataFormat dataForat + const TextureFormat format, + const TextureDataFormat dataForat ) override; bool_t isReady() override; void buffer(const struct ColorU8 pixels[]) override; diff --git a/src/dawnrpg/scene/HelloWorldScene.cpp b/src/dawnrpg/scene/HelloWorldScene.cpp index c8a6c94c..5ed66530 100644 --- a/src/dawnrpg/scene/HelloWorldScene.cpp +++ b/src/dawnrpg/scene/HelloWorldScene.cpp @@ -14,8 +14,8 @@ using namespace Dawn; void Dawn::helloWorldScene(Scene &s) { - while(!s.getGame()->assetManager.isEverythingLoaded()) { - s.getGame()->assetManager.update(); + while(!s.getGame()->assetManager->isEverythingLoaded()) { + s.getGame()->assetManager->update(); } auto cameraItem = s.createSceneItem();