From d3dadcc2e26c93ab285ba30fdf3a22318446a6ab Mon Sep 17 00:00:00 2001 From: Andrew Wong Date: Sat, 9 Aug 2003 22:08:17 +0000 Subject: [PATCH] (hopefully) bugfix for following bug: "Also, sorting courses by Average feet has some problems. At on point the order went Trip 5, World Tour, Road of Slow, Road of 2MB. The averages for these are 8.4, 7.89, 7.6, and 8.6. A bit out of order, eh?" NOTE: it has to compare floats, NOT ints. getmeter() doesn't work because it returns an integer, causing loss of decimal places --- stepmania/src/Course.cpp | 28 ++++++++++++++++++---------- stepmania/src/MusicWheel.cpp | 5 +++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/stepmania/src/Course.cpp b/stepmania/src/Course.cpp index f1a5d68196..b91189ebbb 100644 --- a/stepmania/src/Course.cpp +++ b/stepmania/src/Course.cpp @@ -841,15 +841,22 @@ static bool CompareCoursePointersByDifficulty(const Course* pCourse1, const Cour static bool CompareCoursePointersByAvgDifficulty(const Course* pCourse1, const Course* pCourse2) { - int iNum1 = pCourse1->GetMeter( false ); // SortOrder_AvgDifficulty; - int iNum2 = pCourse2->GetMeter( false ); // SortOrder_AvgDifficulty; + // GLENN: we must use the member variable because getmeter + // returns an int, and a loss of precision occurs when that + // happens. Anyways, we already have this variable + // from updatecoursestats. + // Plus players best/courses with randomo courses should + // go at the end. - if( iNum1 < iNum2 ) + float fNum1 = pCourse1->SortOrder_AvgDifficulty; + float fNum2 = pCourse2->SortOrder_AvgDifficulty; + + if( fNum1 < fNum2 ) return true; - else if( iNum1 > iNum2 ) + else if( fNum1 > fNum2 ) return false; - else // iNum1 == iNum2 - return CompareCoursePointersByAutogen( pCourse1, pCourse2 ); + else // fNum1 == fNum2 + return ( pCourse1->m_sName < pCourse2->m_sName ); } static bool CompareCoursePointersByTotalDifficulty(const Course* pCourse1, const Course* pCourse2) @@ -920,10 +927,7 @@ bool Course::HasBanner() const void Course::UpdateCourseStats() { - LOG->Trace("Updating course stats for %s", this->m_sName.c_str() ); - SortOrder_AvgDifficulty = 0; -// SortOrder_Ranking = 2; // handled in SongManager::UpdateRankingCourses SortOrder_TotalDifficulty = 0; unsigned i; @@ -952,5 +956,9 @@ void Course::UpdateCourseStats() // OPTIMIZATION: Ranking info isn't dependant on style, so // call it sparingly. Its handled on startup and when // themes change.. - + + LOG->Trace("%s: Total feet: %d, Average Difficulty: %f", + this->m_sName.c_str(), + SortOrder_TotalDifficulty, + SortOrder_AvgDifficulty); } diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index 080a43ceac..c38f151e0e 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -578,6 +578,11 @@ void MusicWheel::BuildWheelItemDatas( vector &arrayWheelItemDatas if (PREFSMAN->m_iCourseSortOrder != PrefsManager::COURSE_SORT_SONGS) { + // update course info first. It must be done here + // because doubles stats may differ from singles stats. + for(unsigned i = 0; i < apCourses.size(); i++) + apCourses[i]->UpdateCourseStats(); + if (PREFSMAN->m_iCourseSortOrder == PrefsManager::COURSE_SORT_METER) SortCoursePointerArrayByAvgDifficulty( apCourses );