diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index e89d23f9fe..40de53bab1 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -420,10 +420,15 @@ float GameState::GetSongPercent( float beat ) const return (beat - m_pCurSong->m_fFirstBeat) / m_pCurSong->m_fLastBeat; } -void GameState::IncrementStageIndex() +/* Called by ScreenGameplay. Set the length of the current song. */ +void GameState::BeginStage() { - // Increment the stage counter. - int iNumStagesOfLastSong = SongManager::GetNumStagesForSong( GAMESTATE->m_pCurSong ); + if( m_pCurSong ) + m_iNumStagesOfThisSong = SongManager::GetNumStagesForSong( GAMESTATE->m_pCurSong ); + else if( m_pCurCourse ) + m_iNumStagesOfThisSong = 1; + else + FAIL_M("fail"); /* what are we playing? */ if( GAMESTATE->IsExtraStage() || GAMESTATE->IsExtraStage2() ) { @@ -433,10 +438,23 @@ void GameState::IncrementStageIndex() * * We can't simply not choose long songs as extra stages: if there are no * regular songs to choose, we'll end up with no song to use as an extra stage. */ - iNumStagesOfLastSong = 1; + m_iNumStagesOfThisSong = 1; } +} - m_iCurrentStageIndex += iNumStagesOfLastSong; +/* Called by ScreenSelectMusic (etc). Increment the stage counter if we just played a + * song. Might be called more than once. */ +void GameState::FinishStage() +{ + /* If m_iNumStagesOfThisSong is 0, we've been called more than once before calling + * BeginStage. This can happen when backing out of the player options screen. */ + if( !m_iNumStagesOfThisSong ) + return; + + // Increment the stage counter. + m_iCurrentStageIndex += m_iNumStagesOfThisSong; + + m_iNumStagesOfThisSong = 0; } int GameState::GetStageIndex() const @@ -457,11 +475,13 @@ bool GameState::IsFinalStage() const { if( PREFSMAN->m_bEventMode ) return false; + + /* This changes dynamically on ScreenSelectMusic as the wheel turns. */ int iPredictedStageForCurSong = 1; if( m_pCurSong != NULL ) iPredictedStageForCurSong = SongManager::GetNumStagesForSong( m_pCurSong ); - return m_iCurrentStageIndex + iPredictedStageForCurSong == PREFSMAN->m_iNumArcadeStages; + return m_iCurrentStageIndex + m_iCurrentStageIndex == PREFSMAN->m_iNumArcadeStages; } bool GameState::IsExtraStage() const @@ -708,7 +728,7 @@ StageResult GameState::GetStageResult( PlayerNumber pn ) return win; } -void GameState::GetFinalEvalStatsAndSongs( StageStats& statsOut, vector& vSongsOut ) +void GameState::GetFinalEvalStatsAndSongs( StageStats& statsOut, vector& vSongsOut ) const { statsOut = StageStats(); diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 470d5889d7..e2e5cdc205 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -106,10 +106,12 @@ public: bool m_bEditing; // NoteField does special stuff when this is true bool m_bDemonstrationOrJukebox; // ScreenGameplay does special stuff when this is true bool m_bJukeboxUsesModifiers; - int m_iCurrentStageIndex; // incremented on Eval screen. For a Course, this is always 0 + int m_iNumStagesOfThisSong; + int m_iCurrentStageIndex; int GetStageIndex() const; - void IncrementStageIndex(); + void BeginStage(); + void FinishStage(); int GetNumStagesLeft() const; bool IsFinalStage() const; bool IsExtraStage() const; @@ -191,7 +193,7 @@ public: StageResult GetStageResult( PlayerNumber pn ); void ResetStageStatistics(); // Call this when it's time to play a new stage. - void GetFinalEvalStatsAndSongs( StageStats& statsOut, vector& vSongsOut ); // shown on arcade final evaluation + void GetFinalEvalStatsAndSongs( StageStats& statsOut, vector& vSongsOut ) const; // shown on arcade final evaluation // diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 4967a3a1bc..cb17409174 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -1355,8 +1355,5 @@ void ScreenEvaluation::EndScreen() break; } } - - if( m_Type == stage ) - GAMESTATE->IncrementStageIndex(); } diff --git a/stepmania/src/ScreenEz2SelectMusic.cpp b/stepmania/src/ScreenEz2SelectMusic.cpp index 3c2a9144b7..cbeb845e73 100644 --- a/stepmania/src/ScreenEz2SelectMusic.cpp +++ b/stepmania/src/ScreenEz2SelectMusic.cpp @@ -75,6 +75,9 @@ const ScreenMessage SM_NoSongs = ScreenMessage(SM_User+3); ScreenEz2SelectMusic::ScreenEz2SelectMusic( CString sName ) : Screen( sName ) { + /* Finish any previous stage. It's OK to call this when we havn't played a stage yet. */ + GAMESTATE->FinishStage(); + i_SkipAheadOffset = 0; LastInputTime = 0; ScrollStartTime = 0; diff --git a/stepmania/src/ScreenSelectCourse.cpp b/stepmania/src/ScreenSelectCourse.cpp index 8cc867d7f5..1c3eed7964 100644 --- a/stepmania/src/ScreenSelectCourse.cpp +++ b/stepmania/src/ScreenSelectCourse.cpp @@ -60,6 +60,9 @@ ScreenSelectCourse::ScreenSelectCourse( CString sClassName ) : Screen( sClassNam { LOG->Trace( "ScreenSelectCourse::ScreenSelectCourse()" ); + /* Finish any previous stage. It's OK to call this when we havn't played a stage yet. */ + GAMESTATE->FinishStage(); + CodeDetector::RefreshCacheItems(); SOUND->PlayMusic( THEME->GetPathToS("ScreenSelectCourse music") ); diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index fb38717300..5adcf2dc61 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -86,6 +86,9 @@ ScreenSelectMusic::ScreenSelectMusic( CString sClassName ) : Screen( sClassName m_bInCourseDisplayMode = GAMESTATE->IsCourseMode(); + /* Finish any previous stage. It's OK to call this when we havn't played a stage yet. */ + GAMESTATE->FinishStage(); + /* Cache: */ g_sFallbackCDTitlePath = THEME->GetPathToG("ScreenSelectMusic fallback cdtitle");