From 899ace3eb6e3001943f5f14d3d3625f4f436f8a2 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 14 Aug 2022 21:31:02 +0200 Subject: [PATCH] Added a manualUnloadAll function to TextureResource. Also converted some variables to static inline and cleand up some code. --- es-core/src/resources/TextureResource.cpp | 7 +------ es-core/src/resources/TextureResource.h | 7 ++++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/es-core/src/resources/TextureResource.cpp b/es-core/src/resources/TextureResource.cpp index 67243ef90..ccff36c39 100644 --- a/es-core/src/resources/TextureResource.cpp +++ b/es-core/src/resources/TextureResource.cpp @@ -11,11 +11,6 @@ #include "utils/FileSystemUtil.h" #include "utils/StringUtil.h" -TextureDataManager TextureResource::sTextureDataManager; -std::map> - TextureResource::sTextureMap; -std::set TextureResource::sAllTextures; - TextureResource::TextureResource( const std::string& path, bool tile, bool dynamic, bool linearMagnify, bool forceRasterization) : mTextureData {nullptr} @@ -157,7 +152,7 @@ std::shared_ptr TextureResource::get(const std::string& path, return tex; } - TextureKeyType key(canonicalPath, tile); + TextureKeyType key {canonicalPath, tile}; auto foundTexture = sTextureMap.find(key); if (foundTexture != sTextureMap.cend()) { diff --git a/es-core/src/resources/TextureResource.h b/es-core/src/resources/TextureResource.h index cdefb03ce..aed214aed 100644 --- a/es-core/src/resources/TextureResource.h +++ b/es-core/src/resources/TextureResource.h @@ -35,6 +35,7 @@ public: void initFromPixels(const unsigned char* dataRGBA, size_t width, size_t height); virtual void initFromMemory(const char* data, size_t length); static void manualUnload(std::string path, bool tile); + static void manualUnloadAll() { sTextureMap.clear(); } // Returns the raw pixel values. std::vector getRawRGBAData(); @@ -79,7 +80,7 @@ private: std::shared_ptr mTextureData; // The texture data manager manages loading and unloading of filesystem based textures. - static TextureDataManager sTextureDataManager; + static inline TextureDataManager sTextureDataManager; glm::ivec2 mSize; glm::vec2 mSourceSize; @@ -87,9 +88,9 @@ private: using TextureKeyType = std::pair; // Map of textures, used to prevent duplicate textures. - static std::map> sTextureMap; + static inline std::map> sTextureMap; // Set of all textures, used for memory management. - static std::set sAllTextures; + static inline std::set sAllTextures; }; #endif // ES_CORE_RESOURCES_TEXTURE_RESOURCE_H