From ef8010e998cd73181e3e2cccd9818ae939803751 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sun, 1 Feb 2004 23:06:07 +0000 Subject: [PATCH] Add GetRandomCourse change GetRandom* to behave like a shuffle so it doesn't pick back-to-back dupes --- stepmania/src/GameState.cpp | 2 +- stepmania/src/MusicWheel.cpp | 2 +- stepmania/src/SongManager.cpp | 30 +++++++++++++++++++++++++++--- stepmania/src/SongManager.h | 5 ++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 5c58810454..efb580aa8a 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -121,7 +121,7 @@ void GameState::Reset() ResetMusicStatistics(); ResetStageStatistics(); - SONGMAN->UpdateBest(); + SONGMAN->UpdateBestAndShuffled(); g_vPlayedStageStats.clear(); diff --git a/stepmania/src/MusicWheel.cpp b/stepmania/src/MusicWheel.cpp index 76c3b8663b..d97dbe27ea 100644 --- a/stepmania/src/MusicWheel.cpp +++ b/stepmania/src/MusicWheel.cpp @@ -184,7 +184,7 @@ MusicWheel::MusicWheel() } /* Update for SORT_MOST_PLAYED. */ - SONGMAN->UpdateBest(); + SONGMAN->UpdateBestAndShuffled(); RageTimer timer; CString times; diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index c186e72767..3de6fa6b74 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -750,10 +750,26 @@ void SongManager::GetExtraStageInfo( bool bExtra2, const StyleDef *sd, Song* SongManager::GetRandomSong() { - if( m_pSongs.empty() ) + if( m_pShuffledSongs.empty() ) return NULL; - return SONGMAN->m_pSongs[ rand()%m_pSongs.size() ]; + static i = 0; + i++; + wrap( i, m_pShuffledSongs.size() ); + + return m_pShuffledSongs[ i ]; +} + +Course* SongManager::GetRandomCourse() +{ + if( m_pShuffledCourses.empty() ) + return NULL; + + static i = 0; + i++; + wrap( i, m_pShuffledCourses.size() ); + + return m_pShuffledCourses[ i ]; } Song* SongManager::GetSongFromDir( CString sDir ) @@ -841,8 +857,9 @@ Course *SongManager::FindCourse( CString sName ) return NULL; } -void SongManager::UpdateBest() +void SongManager::UpdateBestAndShuffled() { + // update players best for( int i = 0; i < NUM_MEMORY_CARDS; ++i ) { m_pBestSongs[i] = m_pSongs; @@ -851,6 +868,13 @@ void SongManager::UpdateBest() m_pBestCourses[i] = m_pCourses; SortCoursePointerArrayByMostPlayed( m_pBestCourses[i], (MemoryCard) i ); } + + // update shuffled + m_pShuffledSongs = m_pSongs; + random_shuffle( m_pShuffledSongs.begin(), m_pShuffledSongs.end() ); + + m_pShuffledCourses = m_pCourses; + random_shuffle( m_pShuffledCourses.begin(), m_pShuffledCourses.end() ); } void SongManager::UpdateRankingCourses() diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index da4180a2d6..51eb52bf96 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -72,6 +72,7 @@ public: int GetNumGroups() const; int GetNumCourses() const; Song* GetRandomSong(); + Course* GetRandomCourse(); void GetAllCourses( vector &AddTo, bool bIncludeAutogen ); @@ -87,7 +88,7 @@ public: Course* GetCourseFromName( CString sName ); - void UpdateBest(); // update Players Best + void UpdateBestAndShuffled(); // update Players Best void UpdateRankingCourses(); // courses shown on the ranking screen @@ -103,10 +104,12 @@ protected: vector m_pSongs; // all songs that can be played vector m_pBestSongs[NUM_MEMORY_CARDS]; + vector m_pShuffledSongs; // used by GetRandomSong CStringArray m_sGroupNames; CStringArray m_sGroupBannerPaths; // each song group may have a banner associated with it vector m_pCourses; vector m_pBestCourses[NUM_MEMORY_CARDS]; + vector m_pShuffledCourses; // used by GetRandomCourse };