Instead of choosing random songs in Endless, pre-shuffle them to

avoid repetition.
This commit is contained in:
Glenn Maynard
2002-09-04 03:29:42 +00:00
parent df7a03cd56
commit 1e6faf12a6
4 changed files with 32 additions and 14 deletions
+18 -4
View File
@@ -122,8 +122,15 @@ void Course::CreateEndlessCourseFromGroupAndDifficultyClass( CString sGroupName,
Song* pSong = apSongsInGroup[s];
AddStage( pSong, DifficultyClassToString(dc), "" );
}
Shuffle();
}
void Course::Shuffle()
{
/* Shuffle the list. */
for( int i = 0; i < m_iStages; ++i)
swap(SongOrdering[i], SongOrdering[rand() % m_iStages]);
}
Notes* Course::GetNotesForStage( int iStage )
{
@@ -154,13 +161,20 @@ Notes* Course::GetNotesForStage( int iStage )
}
void Course::GetSongAndNotesForCurrentStyle( CArray<Song*,Song*>& apSongsOut, CArray<Notes*,Notes*>& apNotesOut, CStringArray& asModifiersOut )
/* When bShuffled is true, returns courses in the song ordering list. */
void Course::GetSongAndNotesForCurrentStyle(
CArray<Song*,Song*>& apSongsOut,
CArray<Notes*,Notes*>& apNotesOut,
CStringArray& asModifiersOut,
bool bShuffled )
{
for( int i=0; i<m_iStages; i++ )
{
Song* pSong = m_apSongs[i];
Notes* pNotes = GetNotesForStage( i );
CString sModifiers = m_asModifiers[i];
int num = bShuffled? SongOrdering[i]:i;
Song* pSong = m_apSongs[num];
Notes* pNotes = GetNotesForStage( num );
CString sModifiers = m_asModifiers[num];
if( pNotes == NULL )
continue; // skip
+7 -1
View File
@@ -59,11 +59,17 @@ public:
m_apSongs[m_iStages] = pSong;
m_asDescriptions[m_iStages] = sDescription;
m_asModifiers[m_iStages] = sModifiers;
SongOrdering[m_iStages] = m_iStages;
m_iStages++;
}
void GetSongAndNotesForCurrentStyle( CArray<Song*,Song*>& apSongsOut, CArray<Notes*,Notes*>& apNotesOut, CStringArray& asModifiersOut );
void GetSongAndNotesForCurrentStyle( CArray<Song*,Song*>& apSongsOut, CArray<Notes*,Notes*>& apNotesOut, CStringArray& asModifiersOut, bool bShuffled );
D3DXCOLOR GetColor();
private:
int SongOrdering[MAX_COURSE_STAGES];
void Shuffle();
};
+1 -1
View File
@@ -558,7 +558,7 @@ void MusicWheel::BuildWheelItemDatas( CArray<WheelItemData, WheelItemData&> &arr
CArray<Song*,Song*> apSongs;
CArray<Notes*,Notes*> apNotes;
CStringArray asModifiers;
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers );
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers, false );
if( apNotes.GetSize() > 0 )
arrayWheelItemDatas.Add( WheelItemData(TYPE_COURSE, NULL, "", pCourse, pCourse->GetColor()) );
+6 -8
View File
@@ -131,7 +131,7 @@ ScreenGameplay::ScreenGameplay()
CArray<Song*,Song*> apSongs;
CArray<Notes*,Notes*> apNotes;
CStringArray asModifiers;
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers );
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers, true );
for( int i=0; i<apNotes.GetSize(); i++ )
{
@@ -451,7 +451,7 @@ bool ScreenGameplay::IsLastSong()
CArray<Song*,Song*> apSongs;
CArray<Notes*,Notes*> apNotes;
CStringArray asModifiers;
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers );
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers, true );
return GAMESTATE->m_iSongsIntoCourse >= apSongs.GetSize(); // there are no more songs left
}
@@ -480,13 +480,11 @@ void ScreenGameplay::LoadNextSong( bool bFirstLoad )
CArray<Song*,Song*> apSongs;
CArray<Notes*,Notes*> apNotes;
CStringArray asModifiers;
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers );
int iPlaySongIndex = -1;
if( pCourse->m_bRandomize )
iPlaySongIndex = rand() % apSongs.GetSize();
else
iPlaySongIndex = GAMESTATE->m_iSongsIntoCourse;
pCourse->GetSongAndNotesForCurrentStyle( apSongs, apNotes, asModifiers, true );
int iPlaySongIndex = GAMESTATE->m_iSongsIntoCourse;
iPlaySongIndex %= apSongs.GetSize();
GAMESTATE->m_pCurSong = apSongs[iPlaySongIndex];
for( p=0; p<NUM_PLAYERS; p++ )