From 123f29aa430ca62c8551015ad24d5d43e0e74fd3 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sun, 25 Sep 2022 19:38:24 +0200 Subject: [PATCH] Fixed multiple issues with carousel on-demand texture loading. Also cleaned up some code. --- es-app/src/guis/GuiGamelistOptions.cpp | 2 +- es-app/src/views/GamelistBase.cpp | 2 +- es-app/src/views/GamelistBase.h | 6 +++ es-app/src/views/GamelistView.cpp | 10 +++-- es-app/src/views/ViewController.cpp | 4 +- .../components/primary/CarouselComponent.h | 43 ++++++++++--------- .../src/components/primary/PrimaryComponent.h | 3 +- 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/es-app/src/guis/GuiGamelistOptions.cpp b/es-app/src/guis/GuiGamelistOptions.cpp index 61518586d..84f86da58 100644 --- a/es-app/src/guis/GuiGamelistOptions.cpp +++ b/es-app/src/guis/GuiGamelistOptions.cpp @@ -356,7 +356,7 @@ void GuiGamelistOptions::startEditMode() // as we will want to edit the selected collection within. if (editingSystem == CollectionSystemsManager::getInstance()->getCustomCollectionsBundle()->getName()) { - FileData* file = getGamelist()->getCursor(); + FileData* file {getGamelist()->getCursor()}; // Do we have the cursor on a specific collection?. if (file->getType() == FOLDER) editingSystem = file->getName(); diff --git a/es-app/src/views/GamelistBase.cpp b/es-app/src/views/GamelistBase.cpp index 2e419f61d..6258144bb 100644 --- a/es-app/src/views/GamelistBase.cpp +++ b/es-app/src/views/GamelistBase.cpp @@ -387,7 +387,7 @@ bool GamelistBase::input(InputConfig* config, Input input) mWindow->queueInfoPopup("CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS", 4000); } else { - MetaDataList* md = &entryToUpdate->getSourceFileData()->metadata; + MetaDataList* md {&entryToUpdate->getSourceFileData()->metadata}; if (md->get("favorite") == "false") { md->set("favorite", "true"); mWindow->queueInfoPopup( diff --git a/es-app/src/views/GamelistBase.h b/es-app/src/views/GamelistBase.h index 5b285b049..046a2d478 100644 --- a/es-app/src/views/GamelistBase.h +++ b/es-app/src/views/GamelistBase.h @@ -42,6 +42,12 @@ public: FileData* getLastEntry() { return mPrimary->getLast(); } FileData* getFirstGameEntry() { return mFirstGameEntry; } + void onDemandTextureLoad() + { + if (mPrimary != nullptr) + mPrimary->onDemandTextureLoad(); + } + // These functions are used to retain the folder cursor history, for instance // during a view reload. The calling function stores the history temporarily. void copyCursorHistory(std::vector& cursorHistory) diff --git a/es-app/src/views/GamelistView.cpp b/es-app/src/views/GamelistView.cpp index b743d9364..5e7133e6a 100644 --- a/es-app/src/views/GamelistView.cpp +++ b/es-app/src/views/GamelistView.cpp @@ -57,6 +57,8 @@ void GamelistView::onFileChanged(FileData* file, bool reloadGamelist) populateList(mRoot->getChildrenListToDisplay(), mRoot); setCursor(cursor); } + + onDemandTextureLoad(); } void GamelistView::onShow() @@ -435,8 +437,8 @@ void GamelistView::updateView(const CursorState& state) bool loadedTexture {false}; - if (mCarousel != nullptr && mCarousel->isScrolling()) { - mCarousel->onDemandTextureLoad(); + if (mPrimary->isScrolling()) { + onDemandTextureLoad(); loadedTexture = true; } @@ -449,8 +451,8 @@ void GamelistView::updateView(const CursorState& state) if (file == mLastUpdated) return; - if (mCarousel != nullptr && !loadedTexture) - mCarousel->onDemandTextureLoad(); + if (!loadedTexture) + onDemandTextureLoad(); if (state == CursorState::CURSOR_STOPPED) mLastUpdated = file; diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 882159fe6..cbb96a88a 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -742,7 +742,7 @@ std::shared_ptr ViewController::getGamelistView(SystemData* system bool themeHasVideoView {system->getTheme()->hasView("video")}; // Decide which view style to use. - GamelistViewStyle selectedViewStyle = AUTOMATIC; + GamelistViewStyle selectedViewStyle {AUTOMATIC}; std::string viewPreference {Settings::getInstance()->getString("GamelistViewStyle")}; if (viewPreference == "basic") @@ -995,7 +995,7 @@ void ViewController::reloadGamelistView(GamelistView* view, bool reloadTheme) if (reloadTheme) system->loadTheme(); system->getIndex()->setKidModeFilters(); - std::shared_ptr newView = getGamelistView(system); + std::shared_ptr newView {getGamelistView(system)}; // To counter having come from a placeholder. if (!cursor->isPlaceHolder()) { diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index b37ab42f5..974110e6d 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -52,7 +52,7 @@ public: void addEntry(Entry& entry, const std::shared_ptr& theme); void updateEntry(Entry& entry, const std::shared_ptr& theme); Entry& getEntry(int index) { return mEntries.at(index); } - void onDemandTextureLoad(); + void onDemandTextureLoad() override; const CarouselType getType() { return mType; } const std::string& getItemType() { return mItemType; } void setItemType(std::string itemType) { mItemType = itemType; } @@ -796,6 +796,9 @@ template void CarouselComponent::render(const glm::mat4& parentT renderItem.trans = itemTrans; renderItems.emplace_back(renderItem); + + if (singleEntry) + break; } int belowCenter {static_cast(std::round((renderItems.size() - centerOffset - 1) / 2))}; @@ -1286,30 +1289,28 @@ template void CarouselComponent::onCursorChanged(const CursorSta if (mScrollVelocity != 0) mPreviousScrollVelocity = mScrollVelocity; - if (endPos != mEntryCamOffset) { - // Needed to make sure that overlapping items are renderered correctly. - if (startPos > endPos) - mPositiveDirection = true; - else - mPositiveDirection = false; + // Needed to make sure that overlapping items are renderered correctly. + if (startPos > endPos) + mPositiveDirection = true; + else + mPositiveDirection = false; - mEntryCamTarget = endPos; + mEntryCamTarget = endPos; - Animation* anim {new LambdaAnimation( - [this, startPos, endPos, posMax](float t) { - t -= 1; - float f {glm::mix(startPos, endPos, t * t * t + 1)}; - if (f < 0) - f += posMax; - if (f >= posMax) - f -= posMax; + Animation* anim {new LambdaAnimation( + [this, startPos, endPos, posMax](float t) { + t -= 1; + float f {glm::mix(startPos, endPos, t * t * t + 1)}; + if (f < 0) + f += posMax; + if (f >= posMax) + f -= posMax; - mEntryCamOffset = f; - }, - 500)}; + mEntryCamOffset = f; + }, + 500)}; - GuiComponent::setAnimation(anim, 0, nullptr, false, 0); - } + GuiComponent::setAnimation(anim, 0, nullptr, false, 0); if (mCursorChangedCallback && !mEntries.empty()) mCursorChangedCallback(state); diff --git a/es-core/src/components/primary/PrimaryComponent.h b/es-core/src/components/primary/PrimaryComponent.h index 7d3945631..55d8ca4e5 100644 --- a/es-core/src/components/primary/PrimaryComponent.h +++ b/es-core/src/components/primary/PrimaryComponent.h @@ -44,7 +44,8 @@ public: virtual const size_t getNumEntries() = 0; // Functions used by some primary components. - virtual void setAlignment(PrimaryAlignment align) {}; + virtual void onDemandTextureLoad() {} + virtual void setAlignment(PrimaryAlignment align) {} }; #endif // ES_CORE_COMPONENTS_PRIMARY_COMPONENT_H