Add SongManager::ChooseRandomSong (from TitleMenu). Use it

when starting a demonstration.

Instead of queuing a bunch of SM_PlayAttract's, queue one and
have it requeue itself.

This means 1: if the demonstration fails to start, we don't stop
playing the attract.  (Well, if we don't have any songs, maybe
we don't want ot attract attention, but ...) and more importantly,
2: setting the SECONDS_BETWEEN_ATTRACT value to some obscenely
high value won't cause millions of messages to be queued.

Flatten the option selection loop a bit (this should probably be
moved somewhere, too.)
This commit is contained in:
Glenn Maynard
2002-08-20 20:38:40 +00:00
parent 748c21c0f8
commit 77dc160001
3 changed files with 57 additions and 50 deletions
+30
View File
@@ -538,3 +538,33 @@ load_from_course_failed:
default: ASSERT(0);
}
}
/* Pick a random song (for the demonstration). */
bool SongManager::ChooseRandomSong()
{
if( SONGMAN->m_pSongs.GetSize() == 0 )
return false;
int i;
for( i=0; i<600; i++ ) // try 600 times
{
Song* pSong = m_pSongs[ rand()%m_pSongs.GetSize() ];
for( int j=0; j<3; j++ ) // try 3 times
{
if( pSong->m_apNotes.GetSize() == 0 )
continue;
Notes* pNotes = pSong->m_apNotes[ rand()%pSong->m_apNotes.GetSize() ];
if( pNotes->m_NotesType != GAMESTATE->GetCurrentStyleDef()->m_NotesType )
continue;
// found something we can use!
GAMESTATE->m_pCurSong = pSong;
for( int p=0; p<NUM_PLAYERS; p++ )
GAMESTATE->m_pCurNotes[p] = pNotes;
return true;
}
}
return false;
}