From 357987b9def2dcc454ace402e3137240c66e1b68 Mon Sep 17 00:00:00 2001 From: Andrew Wong Date: Mon, 4 Aug 2003 09:18:26 +0000 Subject: [PATCH] changed way the course ranking sort is applied - now detects on startup and theme change rather than before each music wheel --- stepmania/src/Course.cpp | 22 ++++++---------------- stepmania/src/ScreenAppearanceOptions.cpp | 3 +++ stepmania/src/SongManager.cpp | 21 +++++++++++++++++++++ stepmania/src/SongManager.h | 1 + stepmania/src/StepMania.cpp | 3 +++ 5 files changed, 34 insertions(+), 16 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index 288f6f4f80..89f44a3ba1 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -904,7 +904,7 @@ void Course::UpdateCourseStats() LOG->Trace("Updating course stats for %s", this->m_sName.c_str() ); SortOrder_AvgDifficulty = 0; - SortOrder_Ranking = 2; +// SortOrder_Ranking = 2; // handled in SongManager::UpdateRankingCourses SortOrder_TotalDifficulty = 0; unsigned i; @@ -918,7 +918,7 @@ void Course::UpdateCourseStats() if (m_entries[ ci[i].CourseIndex ].type != Entry::fixed) { SortOrder_AvgDifficulty = 9999999; // large number - SortOrder_Ranking = 3; + if (SortOrder_Ranking == 2) SortOrder_Ranking++; SortOrder_TotalDifficulty = 999999; // large number return; } @@ -926,20 +926,10 @@ void Course::UpdateCourseStats() } SortOrder_AvgDifficulty = (float)SortOrder_TotalDifficulty/GetEstimatedNumStages(); - if (GetEstimatedNumStages() > 7) SortOrder_Ranking = 3; + if (GetEstimatedNumStages() > 7 && SortOrder_Ranking != 1) SortOrder_Ranking = 3; - // HACK: this function takes a while to execute because of - // the ranking portion at the end. Do so only if it is - // absolutely necessary. - if (PREFSMAN->m_iCourseSortOrder == PrefsManager::COURSE_SORT_RANK) - { - CStringArray RankingCourses; - - split( THEME->GetMetric("ScreenRanking","CoursesToShow"),",", RankingCourses); - - for(i = 0; i < RankingCourses.size(); i++) - if (!RankingCourses[i].CompareNoCase(this->m_sPath)) - SortOrder_Ranking = 1; - } + // OPTIMIZATION: Ranking info isn't dependant on style, so + // call it sparingly. Its handled on startup and when + // themes change.. } \ No newline at end of file diff --git a/stepmania/src/ScreenAppearanceOptions.cpp b/stepmania/src/ScreenAppearanceOptions.cpp index 67a793edd5..b21769a58a 100644 --- a/stepmania/src/ScreenAppearanceOptions.cpp +++ b/stepmania/src/ScreenAppearanceOptions.cpp @@ -24,6 +24,7 @@ #include "NoteSkinManager.h" #include "GameState.h" #include "ThemeManager.h" +#include "SongManager.h" enum { @@ -168,6 +169,8 @@ void ScreenAppearanceOptions::ExportOptions() { THEME->SwitchTheme( sNewTheme ); ApplyGraphicOptions(); // reset graphics to apply new window title and icon + + SONGMAN->UpdateRankingCourses(); // update ranking courses } TEXTUREMAN->DoDelayedDelete(); // delete all textures that don't have references diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index 0009f747ee..b51b410ac5 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1174,3 +1174,24 @@ void SongManager::UpdateBest() SortSongPointerArrayByMostPlayed( m_pBestSongs ); } +void SongManager::UpdateRankingCourses() +{ + /* Updating the ranking courses data is fairly expensive + * since it involves comparing strings. Do so sparingly. + */ + CStringArray RankingCourses; + + split( THEME->GetMetric("ScreenRanking","CoursesToShow"),",", RankingCourses); + + for(unsigned i=0; i < m_pCourses.size(); i++) + { + if (m_pCourses[i]->GetEstimatedNumStages() > 7) + m_pCourses[i]->SortOrder_Ranking = 3; + else + m_pCourses[i]->SortOrder_Ranking = 2; + + for(unsigned j = 0; j < RankingCourses.size(); j++) + if (!RankingCourses[j].CompareNoCase(m_pCourses[i]->m_sPath)) + m_pCourses[i]->SortOrder_Ranking = 1; + } +} \ No newline at end of file diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 7a03b9ab88..c2a0646fc3 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -108,6 +108,7 @@ public: void AddScores( NotesType nt, bool bPlayerEnabled[NUM_PLAYERS], RankingCategory hsc[NUM_PLAYERS], int iScore[NUM_PLAYERS], int iNewRecordIndexOut[NUM_PLAYERS] ); // set iNewRecordIndex = -1 if not a new record void UpdateBest(); + void UpdateRankingCourses(); protected: void LoadStepManiaSongDir( CString sDir, LoadingWindow *ld ); void LoadDWISongDir( CString sDir ); diff --git a/stepmania/src/StepMania.cpp b/stepmania/src/StepMania.cpp index 9b70750651..05153ecdb6 100644 --- a/stepmania/src/StepMania.cpp +++ b/stepmania/src/StepMania.cpp @@ -552,6 +552,9 @@ int main(int argc, char* argv[]) /* Load the unlocks into memory */ GAMESTATE->m_pUnlockingSys->LoadFromDATFile( UNLOCKS_PATH ); + /* Initialize which courses are ranking courses here. */ + SONGMAN->UpdateRankingCourses(); + /* Run the main loop. */ GameLoop();