Fixed multiple issues with carousel on-demand texture loading.

Also cleaned up some code.
This commit is contained in:
Leon Styhre 2022-09-25 19:38:24 +02:00
parent b9af765657
commit 123f29aa43
7 changed files with 40 additions and 30 deletions

View file

@ -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();

View file

@ -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(

View file

@ -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<FileData*>& cursorHistory)

View file

@ -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;

View file

@ -742,7 +742,7 @@ std::shared_ptr<GamelistView> 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<GamelistView> newView = getGamelistView(system);
std::shared_ptr<GamelistView> newView {getGamelistView(system)};
// To counter having come from a placeholder.
if (!cursor->isPlaceHolder()) {

View file

@ -52,7 +52,7 @@ public:
void addEntry(Entry& entry, const std::shared_ptr<ThemeData>& theme);
void updateEntry(Entry& entry, const std::shared_ptr<ThemeData>& 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 <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
renderItem.trans = itemTrans;
renderItems.emplace_back(renderItem);
if (singleEntry)
break;
}
int belowCenter {static_cast<int>(std::round((renderItems.size() - centerOffset - 1) / 2))};
@ -1286,30 +1289,28 @@ template <typename T> void CarouselComponent<T>::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);

View file

@ -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