From 3d7d62047bd11e3e58ff1539d69d755a271aea62 Mon Sep 17 00:00:00 2001 From: Koerty Date: Fri, 8 Jun 2018 11:29:52 +0200 Subject: [PATCH] Grid fix freeze with big game collections This fix the infinite freeze with big game collections by storing the texture path instead of loading texture resource --- es-core/src/components/GridTileComponent.cpp | 3 + es-core/src/components/ImageGridComponent.h | 59 ++++++++++---------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/es-core/src/components/GridTileComponent.cpp b/es-core/src/components/GridTileComponent.cpp index 69cd1360e..7dbe2c028 100644 --- a/es-core/src/components/GridTileComponent.cpp +++ b/es-core/src/components/GridTileComponent.cpp @@ -151,6 +151,9 @@ bool GridTileComponent::isSelected() const void GridTileComponent::setImage(const std::string& path) { mImage->setImage(path); + + // Resize now to prevent flickering images when scrolling + resize(); } void GridTileComponent::setImage(const std::shared_ptr& texture) diff --git a/es-core/src/components/ImageGridComponent.h b/es-core/src/components/ImageGridComponent.h index e17d31dd3..e600624cc 100644 --- a/es-core/src/components/ImageGridComponent.h +++ b/es-core/src/components/ImageGridComponent.h @@ -15,7 +15,7 @@ enum ScrollDirection struct ImageGridData { - std::shared_ptr texture; + std::string texturePath; }; template @@ -66,8 +66,8 @@ private: const int texBuffersForward[4] = { 1, 2, 3, 3 }; bool mEntriesDirty; int mLastCursor; - std::shared_ptr mDefaultGameTexture; - std::shared_ptr mDefaultFolderTexture; + std::string mDefaultGameTexture; + std::string mDefaultFolderTexture; // TILES bool mLastRowPartial; @@ -89,8 +89,8 @@ ImageGridComponent::ImageGridComponent(Window* window) : IList::add(const std::string& name, const std::string& imag typename IList::Entry entry; entry.name = name; entry.object = obj; - - if (ResourceManager::getInstance()->fileExists(imagePath)) - { - entry.data.texture = TextureResource::get(imagePath); - } - else - { - // FileType::FOLDER = 2, but FileData is our template parameter T, - // so we don't want to bring that dependence to FileData here - if (obj->getType() == 2) - entry.data.texture = mDefaultFolderTexture; - else - entry.data.texture = mDefaultGameTexture; - } + entry.data.texturePath = imagePath; static_cast*>(this)->add(entry); mEntriesDirty = true; @@ -235,16 +222,15 @@ void ImageGridComponent::applyTheme(const std::shared_ptr& theme, LOG(LogWarning) << "Could not replace default game image, check path: " << path; else { - std::shared_ptr oldDefaultGameTexture = mDefaultGameTexture; - - mDefaultGameTexture = TextureResource::get(path); + std::string oldDefaultGameTexture = mDefaultGameTexture; + mDefaultGameTexture = path; // mEntries are already loaded at this point, // so we need to update them with new game image texture for (auto it = mEntries.begin(); it != mEntries.end(); it++) { - if ((*it).data.texture == oldDefaultGameTexture) - (*it).data.texture = mDefaultGameTexture; + if ((*it).data.texturePath == oldDefaultGameTexture) + (*it).data.texturePath = mDefaultGameTexture; } } } @@ -257,16 +243,15 @@ void ImageGridComponent::applyTheme(const std::shared_ptr& theme, LOG(LogWarning) << "Could not replace default folder image, check path: " << path; else { - std::shared_ptr oldDefaultFolderTexture = mDefaultFolderTexture; - - mDefaultFolderTexture = TextureResource::get(path); + std::string oldDefaultFolderTexture = mDefaultFolderTexture; + mDefaultFolderTexture = path; // mEntries are already loaded at this point, // so we need to update them with new folder image texture for (auto it = mEntries.begin(); it != mEntries.end(); it++) { - if ((*it).data.texture == oldDefaultFolderTexture) - (*it).data.texture = mDefaultFolderTexture; + if ((*it).data.texturePath == oldDefaultFolderTexture) + (*it).data.texturePath = mDefaultFolderTexture; } } } @@ -411,8 +396,22 @@ void ImageGridComponent::updateTileAtPos(int tilePos, int imgPos, int bufferT else { tile->setSelected(imgPos == mCursor); - tile->setImage(mEntries.at(imgPos).data.texture); tile->setVisible(true); + + std::string imagePath = mEntries.at(imgPos).data.texturePath; + if (ResourceManager::getInstance()->fileExists(imagePath)) + { + tile->setImage(imagePath); + } + else + { + // FileType::FOLDER = 2, but FileData is our template parameter T, + // so we don't want to bring that dependence to FileData here + if (mEntries.at(imgPos).object->getType() == 2) + tile->setImage(mDefaultFolderTexture); + else + tile->setImage(mDefaultGameTexture); + } } }