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. // as we will want to edit the selected collection within.
if (editingSystem == if (editingSystem ==
CollectionSystemsManager::getInstance()->getCustomCollectionsBundle()->getName()) { CollectionSystemsManager::getInstance()->getCustomCollectionsBundle()->getName()) {
FileData* file = getGamelist()->getCursor(); FileData* file {getGamelist()->getCursor()};
// Do we have the cursor on a specific collection?. // Do we have the cursor on a specific collection?.
if (file->getType() == FOLDER) if (file->getType() == FOLDER)
editingSystem = file->getName(); 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); mWindow->queueInfoPopup("CAN'T ADD FOLDERS TO CUSTOM COLLECTIONS", 4000);
} }
else { else {
MetaDataList* md = &entryToUpdate->getSourceFileData()->metadata; MetaDataList* md {&entryToUpdate->getSourceFileData()->metadata};
if (md->get("favorite") == "false") { if (md->get("favorite") == "false") {
md->set("favorite", "true"); md->set("favorite", "true");
mWindow->queueInfoPopup( mWindow->queueInfoPopup(

View file

@ -42,6 +42,12 @@ public:
FileData* getLastEntry() { return mPrimary->getLast(); } FileData* getLastEntry() { return mPrimary->getLast(); }
FileData* getFirstGameEntry() { return mFirstGameEntry; } FileData* getFirstGameEntry() { return mFirstGameEntry; }
void onDemandTextureLoad()
{
if (mPrimary != nullptr)
mPrimary->onDemandTextureLoad();
}
// These functions are used to retain the folder cursor history, for instance // These functions are used to retain the folder cursor history, for instance
// during a view reload. The calling function stores the history temporarily. // during a view reload. The calling function stores the history temporarily.
void copyCursorHistory(std::vector<FileData*>& cursorHistory) void copyCursorHistory(std::vector<FileData*>& cursorHistory)

View file

@ -57,6 +57,8 @@ void GamelistView::onFileChanged(FileData* file, bool reloadGamelist)
populateList(mRoot->getChildrenListToDisplay(), mRoot); populateList(mRoot->getChildrenListToDisplay(), mRoot);
setCursor(cursor); setCursor(cursor);
} }
onDemandTextureLoad();
} }
void GamelistView::onShow() void GamelistView::onShow()
@ -435,8 +437,8 @@ void GamelistView::updateView(const CursorState& state)
bool loadedTexture {false}; bool loadedTexture {false};
if (mCarousel != nullptr && mCarousel->isScrolling()) { if (mPrimary->isScrolling()) {
mCarousel->onDemandTextureLoad(); onDemandTextureLoad();
loadedTexture = true; loadedTexture = true;
} }
@ -449,8 +451,8 @@ void GamelistView::updateView(const CursorState& state)
if (file == mLastUpdated) if (file == mLastUpdated)
return; return;
if (mCarousel != nullptr && !loadedTexture) if (!loadedTexture)
mCarousel->onDemandTextureLoad(); onDemandTextureLoad();
if (state == CursorState::CURSOR_STOPPED) if (state == CursorState::CURSOR_STOPPED)
mLastUpdated = file; mLastUpdated = file;

View file

@ -742,7 +742,7 @@ std::shared_ptr<GamelistView> ViewController::getGamelistView(SystemData* system
bool themeHasVideoView {system->getTheme()->hasView("video")}; bool themeHasVideoView {system->getTheme()->hasView("video")};
// Decide which view style to use. // Decide which view style to use.
GamelistViewStyle selectedViewStyle = AUTOMATIC; GamelistViewStyle selectedViewStyle {AUTOMATIC};
std::string viewPreference {Settings::getInstance()->getString("GamelistViewStyle")}; std::string viewPreference {Settings::getInstance()->getString("GamelistViewStyle")};
if (viewPreference == "basic") if (viewPreference == "basic")
@ -995,7 +995,7 @@ void ViewController::reloadGamelistView(GamelistView* view, bool reloadTheme)
if (reloadTheme) if (reloadTheme)
system->loadTheme(); system->loadTheme();
system->getIndex()->setKidModeFilters(); system->getIndex()->setKidModeFilters();
std::shared_ptr<GamelistView> newView = getGamelistView(system); std::shared_ptr<GamelistView> newView {getGamelistView(system)};
// To counter having come from a placeholder. // To counter having come from a placeholder.
if (!cursor->isPlaceHolder()) { if (!cursor->isPlaceHolder()) {

View file

@ -52,7 +52,7 @@ public:
void addEntry(Entry& entry, const std::shared_ptr<ThemeData>& theme); void addEntry(Entry& entry, const std::shared_ptr<ThemeData>& theme);
void updateEntry(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); } Entry& getEntry(int index) { return mEntries.at(index); }
void onDemandTextureLoad(); void onDemandTextureLoad() override;
const CarouselType getType() { return mType; } const CarouselType getType() { return mType; }
const std::string& getItemType() { return mItemType; } const std::string& getItemType() { return mItemType; }
void setItemType(std::string itemType) { mItemType = itemType; } 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; renderItem.trans = itemTrans;
renderItems.emplace_back(renderItem); renderItems.emplace_back(renderItem);
if (singleEntry)
break;
} }
int belowCenter {static_cast<int>(std::round((renderItems.size() - centerOffset - 1) / 2))}; 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) if (mScrollVelocity != 0)
mPreviousScrollVelocity = mScrollVelocity; mPreviousScrollVelocity = mScrollVelocity;
if (endPos != mEntryCamOffset) { // Needed to make sure that overlapping items are renderered correctly.
// Needed to make sure that overlapping items are renderered correctly. if (startPos > endPos)
if (startPos > endPos) mPositiveDirection = true;
mPositiveDirection = true; else
else mPositiveDirection = false;
mPositiveDirection = false;
mEntryCamTarget = endPos; mEntryCamTarget = endPos;
Animation* anim {new LambdaAnimation( Animation* anim {new LambdaAnimation(
[this, startPos, endPos, posMax](float t) { [this, startPos, endPos, posMax](float t) {
t -= 1; t -= 1;
float f {glm::mix(startPos, endPos, t * t * t + 1)}; float f {glm::mix(startPos, endPos, t * t * t + 1)};
if (f < 0) if (f < 0)
f += posMax; f += posMax;
if (f >= posMax) if (f >= posMax)
f -= posMax; f -= posMax;
mEntryCamOffset = f; mEntryCamOffset = f;
}, },
500)}; 500)};
GuiComponent::setAnimation(anim, 0, nullptr, false, 0); GuiComponent::setAnimation(anim, 0, nullptr, false, 0);
}
if (mCursorChangedCallback && !mEntries.empty()) if (mCursorChangedCallback && !mEntries.empty())
mCursorChangedCallback(state); mCursorChangedCallback(state);

View file

@ -44,7 +44,8 @@ public:
virtual const size_t getNumEntries() = 0; virtual const size_t getNumEntries() = 0;
// Functions used by some primary components. // 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 #endif // ES_CORE_COMPONENTS_PRIMARY_COMPONENT_H