Skip to content

Commit

Permalink
fix major lag caused by cpp wheel pack progress
Browse files Browse the repository at this point in the history
by caching it
  • Loading branch information
poco0317 committed Nov 5, 2021
1 parent 7a9e52b commit 3e6cbbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
22 changes: 21 additions & 1 deletion src/Etterna/Actor/Menus/MusicWheel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#include "Etterna/Singletons/SongManager.h"
#include "Etterna/Models/Songs/SongUtil.h"
#include "Etterna/Models/StepsAndStyles/Style.h"
#include "Etterna/Singletons/ThemeManager.h"
#include "Etterna/Singletons/ThemeManager.h"
#include "Etterna/Singletons/ScoreManager.h"
#include "Etterna/Globals/rngthing.h"

#include <algorithm>
Expand Down Expand Up @@ -947,6 +948,7 @@ MusicWheel::BuildWheelItemDatas(

allSongsFiltered = arraySongs;
allSongsByGroupFiltered[so].clear();
packProgressByGroup[so].clear();

// make WheelItemDatas with sections

Expand Down Expand Up @@ -1056,6 +1058,24 @@ MusicWheel::BuildWheelItemDatas(
}
}
}
}
// calculate the pack progress numbers for the sortorder
if (PREFSMAN->m_bPackProgressInWheel) {
auto allsongs = allSongsByGroupFiltered.at(so);
for (auto& groupname_songlist_pair : allsongs) {
int num_played_songs = 0;
for (auto& s : groupname_songlist_pair.second) {
for (auto& chart : s->GetChartsOfCurrentGameMode()) {
if (SCOREMAN->KeyHasScores(chart->GetChartKey())) {
num_played_songs++;
break;
}
}
}
packProgressByGroup.at(so)[groupname_songlist_pair.first] =
num_played_songs;
}

}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Etterna/Actor/Menus/MusicWheel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ class MusicWheel : public WheelBase
std::vector<Song*> allSongsFiltered;
// all songs by sort order by group also filtered
std::vector<std::map<std::string, std::vector<Song*>>>
allSongsByGroupFiltered{ NUM_SortOrder };
allSongsByGroupFiltered{ NUM_SortOrder };
// song grade progress by group
std::vector<std::map<std::string, int>> packProgressByGroup{
NUM_SortOrder
};
auto SelectSongOrCourse() -> bool;
void SelectSongAfterSearch();

Expand Down
17 changes: 4 additions & 13 deletions src/Etterna/Actor/Menus/MusicWheelItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,19 +201,10 @@ MusicWheelItem::LoadFromWheelItemData(const WheelItemBaseData* pData,
type = MusicWheelItemType_SectionCollapsed;
}

auto all_songs_by_group = wheel->allSongsByGroupFiltered.at(GAMESTATE->m_SortOrder);
auto songs_in_group = all_songs_by_group.find(pWID->m_sText);
if (PREFSMAN->m_bPackProgressInWheel && songs_in_group != all_songs_by_group.end()) {
int num_played_songs = 0;

for (auto song : songs_in_group->second) {
for (auto chart : song->GetChartsOfCurrentGameMode()) {
if (SCOREMAN->KeyHasScores(chart->GetChartKey())) {
num_played_songs++;
break;
}
}
}
auto plays_by_group = wheel->packProgressByGroup.at(GAMESTATE->m_SortOrder);
auto plays_in_group = plays_by_group.find(pWID->m_sText);
if (PREFSMAN->m_bPackProgressInWheel && plays_in_group != plays_by_group.end()) {
int num_played_songs = plays_in_group->second;

RageColor color;
if (num_played_songs == pWID->m_iSectionCount) {
Expand Down

0 comments on commit 3e6cbbc

Please sign in to comment.