A few small optimizations, some operations will be way faster now if fewer custom collections are in use. Also some sorting bug fixes and some code cleanup.

This commit is contained in:
Leon Styhre 2020-05-24 14:26:08 +02:00
parent f2f7d34bb6
commit 810b41bdc9
4 changed files with 50 additions and 21 deletions

View file

@ -174,6 +174,8 @@ void CollectionSystemManager::loadEnabledListFromSettings()
autoSelected.cend(), it->first) != autoSelected.cend()); autoSelected.cend(), it->first) != autoSelected.cend());
} }
mHasEnabledCustomCollection = false;
// Parse the custom collection settings list. // Parse the custom collection settings list.
std::vector<std::string> customSelected = Utils::String::commaStringToVector( std::vector<std::string> customSelected = Utils::String::commaStringToVector(
Settings::getInstance()->getString("CollectionSystemsCustom"), true); Settings::getInstance()->getString("CollectionSystemsCustom"), true);
@ -185,6 +187,8 @@ void CollectionSystemManager::loadEnabledListFromSettings()
it->second.isEnabled = (std::find(customSelected.cbegin(), it->second.isEnabled = (std::find(customSelected.cbegin(),
customSelected.cend(), it->first) != customSelected.cend()); customSelected.cend(), it->first) != customSelected.cend());
if (it->second.isEnabled)
mHasEnabledCustomCollection = true;
} }
} }
@ -196,6 +200,8 @@ void CollectionSystemManager::updateSystemsList()
// Add custom enabled collections. // Add custom enabled collections.
addEnabledCollectionsToDisplayedSystems(&mCustomCollectionSystemsData); addEnabledCollectionsToDisplayedSystems(&mCustomCollectionSystemsData);
// Don't sort bundled collections unless at least one collection is enabled.
if (!mIsEditingCustom && mHasEnabledCustomCollection) {
// Sort the bundled custom collections. // Sort the bundled custom collections.
if (mCustomCollectionsBundle->getRootFolder()->getChildren().size() > 0) { if (mCustomCollectionsBundle->getRootFolder()->getChildren().size() > 0) {
mCustomCollectionsBundle->getRootFolder()->sort(getSortTypeFromString( mCustomCollectionsBundle->getRootFolder()->sort(getSortTypeFromString(
@ -203,6 +209,7 @@ void CollectionSystemManager::updateSystemsList()
Settings::getInstance()->getBool("FavFirstCustom")); Settings::getInstance()->getBool("FavFirstCustom"));
SystemData::sSystemVector.push_back(mCustomCollectionsBundle); SystemData::sSystemVector.push_back(mCustomCollectionsBundle);
} }
}
// Add auto enabled collections. // Add auto enabled collections.
addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData); addEnabledCollectionsToDisplayedSystems(&mAutoCollectionSystemsData);
@ -239,6 +246,7 @@ void CollectionSystemManager::refreshCollectionSystems(FileData* file)
realSys.isEnabled = true; realSys.isEnabled = true;
realSys.isPopulated = true; realSys.isPopulated = true;
realSys.needsSave = false; realSys.needsSave = false;
realSys.decl.isCustom = false;
updateCollectionSystem(file, realSys); updateCollectionSystem(file, realSys);
} }
@ -251,6 +259,7 @@ void CollectionSystemManager::refreshCollectionSystems(FileData* file)
for (auto sysDataIt = allCollections.cbegin(); for (auto sysDataIt = allCollections.cbegin();
sysDataIt != allCollections.cend(); sysDataIt++) { sysDataIt != allCollections.cend(); sysDataIt++) {
if (sysDataIt->second.isEnabled)
updateCollectionSystem(file, sysDataIt->second); updateCollectionSystem(file, sysDataIt->second);
} }
} }
@ -263,6 +272,14 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
std::string key = file->getFullPath(); std::string key = file->getFullPath();
SystemData* curSys = sysData.system; SystemData* curSys = sysData.system;
bool mFavoritesSorting = false;
// Read the applicable favorite sorting setting depending on whether the
// system is a custom collection or not.
if (sysData.decl.isCustom)
mFavoritesSorting = Settings::getInstance()->getBool("FavFirstCustom");
else
mFavoritesSorting = Settings::getInstance()->getBool("FavoritesFirst");
const std::unordered_map<std::string, FileData*>&children = const std::unordered_map<std::string, FileData*>&children =
curSys->getRootFolder()->getChildrenByFilename(); curSys->getRootFolder()->getChildrenByFilename();
@ -304,15 +321,25 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
} }
} }
if (name == "recent") if (name == "recent") {
rootFolder->sort(getSortTypeFromString("last played, descending")); rootFolder->sort(getSortTypeFromString("last played, descending"));
else if (sysData.decl.isCustom == true && }
!Settings::getInstance()->getBool("UseCustomCollectionsSystem")) else if (sysData.decl.isCustom &&
!Settings::getInstance()->getBool("UseCustomCollectionsSystem")) {
rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()),
Settings::getInstance()->getBool("FavFirstCustom")); mFavoritesSorting);
else }
// If the game doesn't exist in the current system and it's a custom
// collection, then skip the sorting.
else if (sysData.decl.isCustom &&
children.find(file->getFullPath()) != children.cend()) {
rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()),
Settings::getInstance()->getBool("FavoritesFirst")); mFavoritesSorting);
}
else if (!sysData.decl.isCustom) {
rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()),
mFavoritesSorting);
}
if (name == "recent") { if (name == "recent") {
trimCollectionCount(rootFolder, LAST_PLAYED_MAX); trimCollectionCount(rootFolder, LAST_PLAYED_MAX);
@ -330,7 +357,7 @@ void CollectionSystemManager::updateCollectionSystem(FileData* file, CollectionS
std::string teststring1 = rootFolder->getPath(); std::string teststring1 = rootFolder->getPath();
// If it's a custom collection and the collections // If it's a custom collection and the collections
// are grouped, update the parent instead. // are grouped, update the parent instead.
if (sysData.decl.isCustom == true && if (sysData.decl.isCustom &&
Settings::getInstance()->getBool("UseCustomCollectionsSystem")) { Settings::getInstance()->getBool("UseCustomCollectionsSystem")) {
ViewController::get()->onFileChanged( ViewController::get()->onFileChanged(
rootFolder->getParent(), FILE_METADATA_CHANGED); rootFolder->getParent(), FILE_METADATA_CHANGED);
@ -547,7 +574,7 @@ bool CollectionSystemManager::toggleGameInCollection(FileData* file)
rootFolder->sort(getSortTypeFromString("last played, descending")); rootFolder->sort(getSortTypeFromString("last played, descending"));
else else
rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()), rootFolder->sort(getSortTypeFromString(rootFolder->getSortTypeString()),
Settings::getInstance()->getBool("FavoritesFirst")); Settings::getInstance()->getBool("FavFirstCustom"));
ViewController::get()->onFileChanged(systemViewToUpdate-> ViewController::get()->onFileChanged(systemViewToUpdate->
getRootFolder(), FILE_SORTED); getRootFolder(), FILE_SORTED);

View file

@ -103,6 +103,7 @@ private:
std::map<std::string, CollectionSystemData> mCustomCollectionSystemsData; std::map<std::string, CollectionSystemData> mCustomCollectionSystemsData;
Window* mWindow; Window* mWindow;
bool mIsEditingCustom; bool mIsEditingCustom;
bool mHasEnabledCustomCollection;
std::string mEditingCollection; std::string mEditingCollection;
CollectionSystemData* mEditingCollectionSystemData; CollectionSystemData* mEditingCollectionSystemData;

View file

@ -447,7 +447,8 @@ void GuiMenu::openUISettings()
SystemData::sSystemVector.cend(); it++) { SystemData::sSystemVector.cend(); it++) {
// The favorites and recent gamelists never sort favorites on top. // The favorites and recent gamelists never sort favorites on top.
if ((*it)->getName() == "favorites" || (*it)->getName() == "recent") if ((*it)->getName() == "favorites" || (*it)->getName() == "recent" ||
(*it)->getName() == "collections")
continue; continue;
// Don't re-sort custom collections as they have their own option // Don't re-sort custom collections as they have their own option

View file

@ -60,14 +60,14 @@ public:
virtual void onPositionChanged() {}; virtual void onPositionChanged() {};
// Sets the origin as a percentage of this image. // Sets the origin as a percentage of this image.
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center) // (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
Vector2f getOrigin() const; Vector2f getOrigin() const;
void setOrigin(float originX, float originY); void setOrigin(float originX, float originY);
inline void setOrigin(Vector2f origin) { setOrigin(origin.x(), origin.y()); } inline void setOrigin(Vector2f origin) { setOrigin(origin.x(), origin.y()); }
virtual void onOriginChanged() {}; virtual void onOriginChanged() {};
// Sets the rotation origin as a percentage of this image. // Sets the rotation origin as a percentage of this image.
// (e.g. (0, 0) is top left, (0.5, 0.5) is the center) // (e.g. (0, 0) is top left, (0.5, 0.5) is the center.)
Vector2f getRotationOrigin() const; Vector2f getRotationOrigin() const;
void setRotationOrigin(float originX, float originY); void setRotationOrigin(float originX, float originY);
inline void setRotationOrigin(Vector2f origin) inline void setRotationOrigin(Vector2f origin)
@ -159,15 +159,15 @@ public:
virtual HelpStyle getHelpStyle(); virtual HelpStyle getHelpStyle();
// Returns true if the component is busy doing background processing (e.g. HTTP downloads) // Returns true if the component is busy doing background processing (e.g. HTTP downloads).
bool isProcessing() const; bool isProcessing() const;
const static unsigned char MAX_ANIMATIONS = 4; const static unsigned char MAX_ANIMATIONS = 4;
protected: protected:
void renderChildren(const Transform4x4f& transform) const; void renderChildren(const Transform4x4f& transform) const;
void updateSelf(int deltaTime); // Updates animations void updateSelf(int deltaTime); // Updates animations.
void updateChildren(int deltaTime); // Updates animations void updateChildren(int deltaTime); // Updates animations.
unsigned char mOpacity; unsigned char mOpacity;
Window* mWindow; Window* mWindow;