From becd3755445bec19888e00af8f670f7844620cf0 Mon Sep 17 00:00:00 2001 From: Crash Cringle <30600688+CrashCringle12@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:32:56 -0500 Subject: [PATCH] Only UpdateMeterSort when necessary (when sorting), account for other games and styles. Songs are already sorted by title so no need to do so again (otherwise big boi lag) --- src/MusicWheel.cpp | 5 ++--- src/SongManager.cpp | 24 +++++++++--------------- src/SongManager.h | 2 +- src/SongUtil.h | 1 - src/StepMania.cpp | 1 - 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/MusicWheel.cpp b/src/MusicWheel.cpp index 08ace5f89a..aaa30bbd7e 100644 --- a/src/MusicWheel.cpp +++ b/src/MusicWheel.cpp @@ -571,6 +571,8 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh switch( so ) { case SORT_METER: + SONGMAN->UpdateMeterSort(arraySongs); + break; case SORT_PREFERRED: // obey order specified by the preferred sort list break; @@ -715,12 +717,9 @@ void MusicWheel::BuildWheelItemDatas( std::vector &arrayWh } break; case SORT_METER: - // If the sort order is Preferred handle it differently because we already know the sections if( bUseSections ) { int iSectionCount = 0; - // // Get all section names - std::map> meterSortSongsMap = SONGMAN->GetMeterToSongsMap(); for (auto const& [sectionName, songs] : SONGMAN->GetMeterToSongsMap()) { RageColor colorSection = SECTION_COLORS.GetValue(iSectionColorIndex); iSectionColorIndex = (iSectionColorIndex+1) % NUM_SECTION_COLORS; diff --git a/src/SongManager.cpp b/src/SongManager.cpp index d5d99ba11d..fc11f24bdd 100644 --- a/src/SongManager.cpp +++ b/src/SongManager.cpp @@ -214,7 +214,6 @@ void SongManager::Reload( bool bAllowFastLoad, LoadingWindow *ld ) PREFSMAN->m_bFastLoad.Set( oldVal ); UpdatePreferredSort(); - UpdateMeterSort(); } void SongManager::LoadAdditions( LoadingWindow *ld ) @@ -228,7 +227,6 @@ void SongManager::LoadAdditions( LoadingWindow *ld ) UNLOCKMAN->Reload(); UpdatePreferredSort(); - UpdateMeterSort(); } void SongManager::InitSongsFromDisk( LoadingWindow *ld, bool onlyAdditions ) @@ -1237,7 +1235,6 @@ void SongManager::Invalidate( const Song *pStaleSong ) UpdatePopular(); UpdateShuffled(); - UpdateMeterSort(); RefreshCourseGroupInfo(); } @@ -1630,17 +1627,19 @@ void SongManager::UpdatePopular() } } -void SongManager::UpdateMeterSort() { - std::vector apDifficultSongs = m_pSongs; +std::map> SongManager::UpdateMeterSort( std::vector songs) { + // Empty the map + m_mapSongsByDifficulty.clear(); + std::vector apDifficultSongs = songs; // For each song, for each step for( unsigned i = 0; i < apDifficultSongs.size(); ++i ) { - const std::vector &vSteps = apDifficultSongs[i]->GetAllSteps(); - for( unsigned j = 0; j < vSteps.size(); ++j ) + std::vector vpSteps; + SongUtil::GetPlayableSteps( apDifficultSongs[i], vpSteps ); + for( unsigned j = 0; j < vpSteps.size(); ++j ) { - Steps *pSteps = vSteps[j]; + Steps *pSteps = vpSteps[j]; // Check if the meter is already in m_mapSongsByDifficulty - if (std::find(m_mapSongsByDifficulty[pSteps->GetMeter()].begin(), m_mapSongsByDifficulty[pSteps->GetMeter()].end(), apDifficultSongs[i]) != m_mapSongsByDifficulty[pSteps->GetMeter()].end()) continue; else { @@ -1648,12 +1647,7 @@ void SongManager::UpdateMeterSort() { } } } - - // For each meter in m_mapSongsByDifficulty, sort the songs by title - for( unsigned i = 0; i < m_mapSongsByDifficulty.size(); ++i ) - { - SongUtil::SortSongPointerArrayByTitle( m_mapSongsByDifficulty[i] ); - } + return m_mapSongsByDifficulty; } diff --git a/src/SongManager.h b/src/SongManager.h index a9b21b0be2..f5c274c839 100644 --- a/src/SongManager.h +++ b/src/SongManager.h @@ -189,7 +189,7 @@ public: void UpdatePopular(); void UpdateShuffled(); // re-shuffle songs and courses - void UpdateMeterSort(); + std::map> UpdateMeterSort( std::vector songs); void SetPreferredSongs(RString sPreferredSongs, bool bIsAbsolute = false); void SetPreferredCourses(RString sPreferredCourses, bool bIsAbsolute = false); void UpdatePreferredSort(RString sPreferredSongs = "PreferredSongs.txt", RString sPreferredCourses = "PreferredCourses.txt"); diff --git a/src/SongUtil.h b/src/SongUtil.h index d3ee9d85ee..7d921c61ec 100644 --- a/src/SongUtil.h +++ b/src/SongUtil.h @@ -146,7 +146,6 @@ namespace SongUtil void SortSongPointerArrayByNumPlays( std::vector &vpSongsInOut, ProfileSlot slot, bool bDescending ); void SortSongPointerArrayByNumPlays( std::vector &vpSongsInOut, const Profile* pProfile, bool bDescending ); void SortSongPointerArrayByStepsTypeAndMeter( std::vector &vpSongsInOut, StepsType st, Difficulty dc ); - void SortSongPointerArrayByStepsTypeAndLevel( std::vector &vpSongsInOut, StepsType st, int iMeter ); RString GetSectionNameFromSongAndSort( const Song *pSong, SortOrder so ); void SortSongPointerArrayBySectionName( std::vector &vpSongsInOut, SortOrder so ); void SortByMostRecentlyPlayedForMachine( std::vector &vpSongsInOut ); diff --git a/src/StepMania.cpp b/src/StepMania.cpp index dc8b072962..9facfefd6c 100644 --- a/src/StepMania.cpp +++ b/src/StepMania.cpp @@ -1006,7 +1006,6 @@ int sm_main(int argc, char* argv[]) UNLOCKMAN = new UnlockManager; SONGMAN->UpdatePopular(); SONGMAN->UpdatePreferredSort(); - SONGMAN->UpdateMeterSort(); NETWORK = new NetworkManager; STATSMAN = new StatsManager;