diff --git a/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.cpp b/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.cpp index 78721b3..72020c6 100644 --- a/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.cpp +++ b/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.cpp @@ -462,4 +462,10 @@ namespace Raylib { { return std::make_unique(text, position, fontSize, color); } + + TextureManager::getInstance() + { + static TextureManagerImpl instance; + return instance; + } } diff --git a/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.hpp b/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.hpp index 77fd695..253fe66 100644 --- a/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.hpp +++ b/libs/B-luga-graphics/include/B-luga-graphics/Raylib/Graphics/Graphics.hpp @@ -158,23 +158,9 @@ namespace Raylib { class TextureManager { public: - TextureManager(const TextureManager &) = delete; - TextureManager(TextureManager &&) = delete; - void operator=(const TextureManager &) = delete; - void operator=(TextureManager &&) = delete; - static TextureManager &getInstance(); ~TextureManager(); - ::Texture2D &getTexture(const std::string &fileName); - void unloadTextures(); - - private: - TextureManager() = default; - std::map _textures; - std::mutex _mutex; - // NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables) - static TextureManager _instance; - // NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables) + virtual void unloadTextures() = 0; }; class RayImage { diff --git a/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.cpp b/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.cpp index 1242a73..5265c93 100644 --- a/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.cpp +++ b/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.cpp @@ -1,7 +1,28 @@ #include "Graphics.hpp" +#include namespace Raylib { + ::Texture2D &TextureManagerImpl::getTexture(const std::string &fileName) + { + std::lock_guard lock(_mutex); + auto it = _textures.find(fileName); + + if (it == _textures.end()) { + _textures[fileName] = LoadTexture(fileName.c_str()); + } + return _textures[fileName]; + } + + void TextureManagerImpl::unloadTextures() + { + std::lock_guard lock(_mutex); + for (auto &it : _textures) { + UnloadTexture(it.second); + } + _textures.clear(); + } + RayImageImpl::RayImageImpl(const std::string &fileName) : _image(LoadImage(fileName.c_str())) { diff --git a/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.hpp b/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.hpp index 49b592b..22be336 100644 --- a/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.hpp +++ b/libs/B-luga-graphics/src/RaylibImpl/Graphics/Graphics.hpp @@ -45,6 +45,16 @@ namespace Raylib { ::Image _image; }; + class TextureManagerImpl : public TextureManager { + public: + ::Texture2D &getTexture(const std::string &fileName); + void unloadTextures() override; + + private: + std::map _textures; + std::mutex _mutex; + }; + class SpriteImpl : public Sprite { public: SpriteImpl(const std::string &fileName, float width, float height, std::size_t id);