From 5318d0670d1d67b616231f031cd284d31662d619 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Tue, 24 Apr 2007 01:35:32 +0000 Subject: [PATCH] Previously, BeginStage was called in SGameplay and FinishStage was called in each place gameplay exits. This incremented the stage number in SSM, and was brittle: FinishStage was sprinkled in many odd places. Do both in SGameplay. This increments the stage number as soon as gameplay ends. This only affects evaluation. Use the stage number from StageStats there, instead of the current stage, and adjust branches. During evaluation, the game is on the upcoming stage and displaying old data for the last stage, instead of the stage continuing through evaluation. This also moves a bunch of scoring-related stuff out of SEvaluation, to the end of gameplay, where it belongs. Eval is almost const, and things won't break like they would before if Eval is not used. --- stepmania/src/GameState.cpp | 12 +++---- stepmania/src/ScreenContinue.cpp | 2 -- stepmania/src/ScreenEnding.cpp | 4 --- stepmania/src/ScreenEvaluation.cpp | 36 +++++++++++++------- stepmania/src/ScreenEvaluation.h | 3 ++ stepmania/src/ScreenGameplay.cpp | 23 ++++++++----- stepmania/src/ScreenNameEntryTraditional.cpp | 2 -- stepmania/src/ScreenSelectMusic.cpp | 4 --- 8 files changed, 46 insertions(+), 40 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 37643a35a4..1b9e4a8182 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -910,11 +910,7 @@ bool GameState::IsFinalStage() const if( IsCourseMode() ) return true; - /* This changes dynamically on ScreenSelectMusic as the wheel turns. */ - int iPredictedStageForCurSong = GetNumStagesForCurrentSongAndStepsOrCourse(); - if( iPredictedStageForCurSong == -1 ) - iPredictedStageForCurSong = 1; - return GetLargestCurrentStageIndexForAnyHumanPlayer() + iPredictedStageForCurSong == PREFSMAN->m_iSongsPerPlay; + return GetLargestCurrentStageIndexForAnyHumanPlayer() == PREFSMAN->m_iSongsPerPlay - 1; } bool GameState::IsAnExtraStage() const @@ -1202,8 +1198,8 @@ bool GameState::HasEarnedExtraStage() const m_pCurSteps[pn]->GetDifficulty() != Difficulty_Challenge ) continue; /* not hard enough! */ - if( (IsFinalStage() && STATSMAN->m_CurStageStats.m_player[pn].GetGrade() <= GRADE_TIER_FOR_EXTRA_1) || - (IsExtraStage() && STATSMAN->m_CurStageStats.m_player[pn].GetGrade() <= GRADE_TIER_FOR_EXTRA_2) ) + if( (IsExtraStage() && STATSMAN->m_CurStageStats.m_player[pn].GetGrade() <= GRADE_TIER_FOR_EXTRA_1) || + (IsExtraStage2() && STATSMAN->m_CurStageStats.m_player[pn].GetGrade() <= GRADE_TIER_FOR_EXTRA_2) ) { bOnePassed = true; break; @@ -1214,7 +1210,7 @@ bool GameState::HasEarnedExtraStage() const return false; /* If PickExtraStage, allow EX2 if the chosen song was correct. */ - if( PREFSMAN->m_bPickExtraStage && IsExtraStage() ) + if( PREFSMAN->m_bPickExtraStage && IsExtraStage2() ) { Song* pSong; Steps* pSteps; diff --git a/stepmania/src/ScreenContinue.cpp b/stepmania/src/ScreenContinue.cpp index c98d193a50..d5bbea9d25 100644 --- a/stepmania/src/ScreenContinue.cpp +++ b/stepmania/src/ScreenContinue.cpp @@ -34,8 +34,6 @@ void ScreenContinue::Init() void ScreenContinue::BeginScreen() { - GAMESTATE->FinishStage(); - GAMESTATE->SetCurrentStyle( NULL ); // unjoin all players with 0 stages left diff --git a/stepmania/src/ScreenEnding.cpp b/stepmania/src/ScreenEnding.cpp index 448d303797..1859da5bd2 100644 --- a/stepmania/src/ScreenEnding.cpp +++ b/stepmania/src/ScreenEnding.cpp @@ -76,10 +76,6 @@ ScreenEnding::ScreenEnding() : ScreenAttract( false/*dont reset GAMESTATE*/ ) STATSMAN->m_vPlayedStageStats.clear(); } - - - // Update final profile stats before we load them for display. - GAMESTATE->FinishStage(); } void ScreenEnding::Init() diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index f495e77242..3fc1816c5b 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -180,11 +180,7 @@ void ScreenEvaluation::Init() { LOG->Trace( "ScreenEvaluation::Init()" ); - /* Commit stats to the profile, so any profile stats displayed on this screen - * include the last game. */ - GAMESTATE->CommitStageStats(); - - m_pStageStats = &STATSMAN->m_CurStageStats; + m_pStageStats = &STATSMAN->m_vPlayedStageStats.back(); LIGHTSMAN->SetLightsMode( LIGHTSMODE_MENU ); ZERO( m_bSavedScreenshot ); @@ -195,10 +191,12 @@ void ScreenEvaluation::Init() // // Figure out which statistics and songs we're going to display // - STATSMAN->CalcAccumPlayedStageStats(); if( SUMMARY ) - STATSMAN->GetFinalEvalStageStats( STATSMAN->m_CurStageStats ); + { + STATSMAN->GetFinalEvalStageStats( m_FinalEvalStageStats ); + m_pStageStats = &m_FinalEvalStageStats; + } m_bFailed = m_pStageStats->AllFailed(); @@ -234,11 +232,8 @@ void ScreenEvaluation::Init() // // update persistent statistics // - // XXX - m_pStageStats->CommitScores( SUMMARY ); - - FOREACH_HumanPlayer( p ) - m_pStageStats->m_player[p].CalcAwards( p, m_pStageStats->m_bGaveUp, m_pStageStats->m_bUsedAutoplay ); + if( SUMMARY ) + m_pStageStats->CommitScores( true ); // Run this here, so STATSMAN->m_CurStageStats is available to overlays. ScreenWithMenuElements::Init(); @@ -820,6 +815,23 @@ void ScreenEvaluation::HandleMenuStart() StartTransitioningScreen( SM_GoToNextScreen ); } +// lua start +#include "LuaBinding.h" + +class LunaScreenEvaluation: public Luna +{ +public: + static int GetStageStats( T* p, lua_State *L ) { LuaHelpers::Push( L, p->GetStageStats() ); return 1; } + LunaScreenEvaluation() + { + ADD_METHOD( GetStageStats ); + } +}; + +LUA_REGISTER_DERIVED_CLASS( ScreenEvaluation, ScreenWithMenuElements ) + +// lua end + /* * (c) 2001-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ScreenEvaluation.h b/stepmania/src/ScreenEvaluation.h index 7cd6f0b160..825208bd1b 100644 --- a/stepmania/src/ScreenEvaluation.h +++ b/stepmania/src/ScreenEvaluation.h @@ -46,6 +46,8 @@ public: virtual void MenuBack( const InputEventPlus &input ); virtual void MenuStart( const InputEventPlus &input ); + virtual void PushSelf( lua_State *L ); + StageStats *GetStageStats() { return m_pStageStats; } protected: virtual bool GenericTweenOn() const { return true; } @@ -55,6 +57,7 @@ protected: bool m_bSummary; StageStats *m_pStageStats; + StageStats m_FinalEvalStageStats; // banner area Banner m_LargeBanner; diff --git a/stepmania/src/ScreenGameplay.cpp b/stepmania/src/ScreenGameplay.cpp index a63427db48..9cb2575553 100644 --- a/stepmania/src/ScreenGameplay.cpp +++ b/stepmania/src/ScreenGameplay.cpp @@ -385,10 +385,6 @@ void ScreenGameplay::Init() GAMESTATE->SaveCurrentSettingsToProfile(pn); } - /* Finish the last stage, if we havn't already. (For example, we might have - * gone from gameplay to evaluation back to gameplay.) */ - GAMESTATE->FinishStage(); - /* Called once per stage (single song or single course). */ GAMESTATE->BeginStage(); @@ -2240,9 +2236,22 @@ void ScreenGameplay::StageFinished( bool bBackedOut ) } } + if( bBackedOut ) + { + GAMESTATE->CancelStage(); + return; + } + // save current stage stats - if( !bBackedOut ) - STATSMAN->m_vPlayedStageStats.push_back( STATSMAN->m_CurStageStats ); + STATSMAN->m_vPlayedStageStats.push_back( STATSMAN->m_CurStageStats ); + + GAMESTATE->CommitStageStats(); + STATSMAN->m_CurStageStats.CommitScores( false ); + FOREACH_HumanPlayer( pn ) + STATSMAN->m_CurStageStats.m_player[pn].CalcAwards( pn, STATSMAN->m_CurStageStats.m_bGaveUp, STATSMAN->m_CurStageStats.m_bUsedAutoplay ); + + STATSMAN->CalcAccumPlayedStageStats(); + GAMESTATE->FinishStage(); } void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) @@ -2442,8 +2451,6 @@ void ScreenGameplay::HandleScreenMessage( const ScreenMessage SM ) SongFinished(); StageFinished( true ); - GAMESTATE->CancelStage(); - m_sNextScreen = GetPrevScreen(); if( AdjustSync::IsSyncDataChanged() ) diff --git a/stepmania/src/ScreenNameEntryTraditional.cpp b/stepmania/src/ScreenNameEntryTraditional.cpp index ba643981a6..96e431fe38 100644 --- a/stepmania/src/ScreenNameEntryTraditional.cpp +++ b/stepmania/src/ScreenNameEntryTraditional.cpp @@ -73,8 +73,6 @@ void ScreenNameEntryTraditional::Init() void ScreenNameEntryTraditional::BeginScreen() { - GAMESTATE->FinishStage(); - /* Find out if players are entering their name. */ FOREACH_PlayerNumber( pn ) { diff --git a/stepmania/src/ScreenSelectMusic.cpp b/stepmania/src/ScreenSelectMusic.cpp index 131919f079..3894ebc667 100644 --- a/stepmania/src/ScreenSelectMusic.cpp +++ b/stepmania/src/ScreenSelectMusic.cpp @@ -174,10 +174,6 @@ void ScreenSelectMusic::Init() void ScreenSelectMusic::BeginScreen() { - /* Finish any previous stage. It's OK to call this when we havn't played a stage yet. - * Do this before anything that might look at GAMESTATE->m_iCurrentStageIndex or GAMESTATE->m_iPlayerCurrentStageIndexForCurrentCredit. */ - GAMESTATE->FinishStage(); - LIGHTSMAN->SetLightsMode( LIGHTSMODE_MENU ); if( CommonMetrics::AUTO_SET_STYLE )