diff options
Diffstat (limited to 'source/rendering')
-rw-r--r-- | source/rendering/StarAssetTextureGroup.cpp | 24 | ||||
-rw-r--r-- | source/rendering/StarAssetTextureGroup.hpp | 11 |
2 files changed, 18 insertions, 17 deletions
diff --git a/source/rendering/StarAssetTextureGroup.cpp b/source/rendering/StarAssetTextureGroup.cpp index 44b614a..afffab7 100644 --- a/source/rendering/StarAssetTextureGroup.cpp +++ b/source/rendering/StarAssetTextureGroup.cpp @@ -13,16 +13,16 @@ AssetTextureGroup::AssetTextureGroup(TextureGroupPtr textureGroup) Root::singleton().registerReloadListener(m_reloadTracker); } -TexturePtr AssetTextureGroup::loadTexture(String const& imageName) { - return loadTexture(imageName, false); +TexturePtr AssetTextureGroup::loadTexture(AssetPath const& imagePath) { + return loadTexture(imagePath, false); } -TexturePtr AssetTextureGroup::tryTexture(String const& imageName) { - return loadTexture(imageName, true); +TexturePtr AssetTextureGroup::tryTexture(AssetPath const& imagePath) { + return loadTexture(imagePath, true); } -bool AssetTextureGroup::textureLoaded(String const& imageName) const { - return m_textureMap.contains(imageName); +bool AssetTextureGroup::textureLoaded(AssetPath const& imagePath) const { + return m_textureMap.contains(imagePath); } void AssetTextureGroup::cleanup(int64_t textureTimeout) { @@ -50,8 +50,8 @@ void AssetTextureGroup::cleanup(int64_t textureTimeout) { } } -TexturePtr AssetTextureGroup::loadTexture(String const& imageName, bool tryTexture) { - if (auto p = m_textureMap.ptr(imageName)) { +TexturePtr AssetTextureGroup::loadTexture(AssetPath const& imagePath, bool tryTexture) { + if (auto p = m_textureMap.ptr(imagePath)) { p->second = Time::monotonicMilliseconds(); return p->first; } @@ -60,9 +60,9 @@ TexturePtr AssetTextureGroup::loadTexture(String const& imageName, bool tryTextu ImageConstPtr image; if (tryTexture) - image = assets->tryImage(imageName); + image = assets->tryImage(imagePath); else - image = assets->image(imageName); + image = assets->image(imagePath); if (!image) return {}; @@ -72,11 +72,11 @@ TexturePtr AssetTextureGroup::loadTexture(String const& imageName, bool tryTextu // in the texture group for these, so we keep track of the image pointers // returned to deduplicate them. if (auto existingTexture = m_textureDeduplicationMap.value(image)) { - m_textureMap.add(imageName, {existingTexture, Time::monotonicMilliseconds()}); + m_textureMap.add(imagePath, {existingTexture, Time::monotonicMilliseconds()}); return existingTexture; } else { auto texture = m_textureGroup->create(*image); - m_textureMap.add(imageName, {texture, Time::monotonicMilliseconds()}); + m_textureMap.add(imagePath, {texture, Time::monotonicMilliseconds()}); m_textureDeduplicationMap.add(image, texture); return texture; } diff --git a/source/rendering/StarAssetTextureGroup.hpp b/source/rendering/StarAssetTextureGroup.hpp index 0941ad0..205a321 100644 --- a/source/rendering/StarAssetTextureGroup.hpp +++ b/source/rendering/StarAssetTextureGroup.hpp @@ -6,6 +6,7 @@ #include "StarBiMap.hpp" #include "StarListener.hpp" #include "StarRenderer.hpp" +#include "StarAssetPath.hpp" namespace Star { @@ -20,14 +21,14 @@ public: // Load the given texture into the texture group if it is not loaded, and // return the texture pointer. - TexturePtr loadTexture(String const& imageName); + TexturePtr loadTexture(AssetPath const& imagePath); // If the texture is loaded and ready, returns the texture pointer, otherwise // queues the texture using Assets::tryImage and returns nullptr. - TexturePtr tryTexture(String const& imageName); + TexturePtr tryTexture(AssetPath const& imagePath); // Has the texture been loaded? - bool textureLoaded(String const& imageName) const; + bool textureLoaded(AssetPath const& imagePath) const; // Frees textures that haven't been used in more than 'textureTimeout' time. // If Root has been reloaded, will simply clear the texture group. @@ -37,10 +38,10 @@ private: // Returns the texture parameters. If tryTexture is true, then returns none // if the texture is not loaded, and queues it, otherwise loads texture // immediately - TexturePtr loadTexture(String const& imageName, bool tryTexture); + TexturePtr loadTexture(AssetPath const& imagePath, bool tryTexture); TextureGroupPtr m_textureGroup; - StringMap<pair<TexturePtr, int64_t>> m_textureMap; + HashMap<AssetPath, pair<TexturePtr, int64_t>> m_textureMap; HashMap<ImageConstPtr, TexturePtr> m_textureDeduplicationMap; TrackerListenerPtr m_reloadTracker; }; |