Merge pull request #845 from pjft/improve-collections-performance

Only recreate GameList View if it can change type
This commit is contained in:
pjft 2024-01-11 16:50:32 +00:00 committed by GitHub
commit 5baa8f04fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 13 deletions

View file

@ -330,6 +330,24 @@ void ViewController::removeGameListView(SystemData* system)
}
}
ViewController::GameListViewType ViewController::getGameListViewType()
{
//decide type
GameListViewType selectedViewType = AUTOMATIC;
std::string viewPreference = Settings::getInstance()->getString("GamelistViewStyle");
if (viewPreference.compare("basic") == 0)
selectedViewType = BASIC;
if (viewPreference.compare("detailed") == 0)
selectedViewType = DETAILED;
if (viewPreference.compare("grid") == 0)
selectedViewType = GRID;
if (viewPreference.compare("video") == 0)
selectedViewType = VIDEO;
return selectedViewType;
}
std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* system)
{
//if we already made one, return that one
@ -344,17 +362,7 @@ std::shared_ptr<IGameListView> ViewController::getGameListView(SystemData* syste
bool themeHasVideoView = system->getTheme()->hasView("video");
//decide type
GameListViewType selectedViewType = AUTOMATIC;
std::string viewPreference = Settings::getInstance()->getString("GamelistViewStyle");
if (viewPreference.compare("basic") == 0)
selectedViewType = BASIC;
if (viewPreference.compare("detailed") == 0)
selectedViewType = DETAILED;
if (viewPreference.compare("grid") == 0)
selectedViewType = GRID;
if (viewPreference.compare("video") == 0)
selectedViewType = VIDEO;
GameListViewType selectedViewType = getGameListViewType();
if (selectedViewType == AUTOMATIC)
{

View file

@ -65,6 +65,8 @@ public:
VIDEO
};
ViewController::GameListViewType getGameListViewType();
struct State
{
ViewMode viewing;

View file

@ -31,8 +31,15 @@ void BasicGameListView::onFileChanged(FileData* file, FileChangeType change)
{
if(change == FILE_METADATA_CHANGED)
{
// might switch to a detailed view
ViewController::get()->reloadGameListView(this);
// might switch to a detailed view,
// so, to avoid recreating the view when not needed, we check if we are on auto and
// -- on basic (if we add details, might move to detailed)
// -- on detailed (if we add video, might upgrade to video)
// which are the only cases when an upgrade would happen, I believe?
if(ViewController::get()->getGameListViewType() == ViewController::AUTOMATIC &&
(this->getName() == "basic" || this->getName() == "detailed"))
ViewController::get()->reloadGameListView(this);
return;
}