From 4e4b6df7aaa16fef92109fc3d86a040e5f490277 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 23 Feb 2005 04:32:45 +0000 Subject: [PATCH] move code to StatsManager::CommitStatsToProfiles --- stepmania/src/GameState.cpp | 92 +------------------------------- stepmania/src/StatsManager.cpp | 96 ++++++++++++++++++++++++++++++++++ stepmania/src/StatsManager.h | 2 + 3 files changed, 99 insertions(+), 91 deletions(-) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ce99d0c44b..76f552c662 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -306,47 +306,6 @@ void GameState::PlayersFinalized() } } -/* This data is added to each player profile, and to the machine profile per-player. */ -void AddPlayerStatsToProfile( Profile *pProfile, const StageStats &ss, PlayerNumber pn ) -{ - ss.AssertValid( pn ); - CHECKPOINT; - - StyleID sID; - sID.FromStyle( ss.pStyle ); - - ASSERT( ss.vpSongs.size() == ss.m_player[pn].vpSteps.size() ); - for( unsigned i=0; im_iNumSongsPlayedByPlayMode[ss.playMode]++; - pProfile->m_iNumSongsPlayedByStyle[sID] ++; - pProfile->m_iNumSongsPlayedByDifficulty[pSteps->GetDifficulty()] ++; - - int iMeter = clamp( pSteps->GetMeter(), 0, MAX_METER ); - pProfile->m_iNumSongsPlayedByMeter[iMeter] ++; - } - - pProfile->m_iTotalDancePoints += ss.m_player[pn].iActualDancePoints; - - if( ss.StageType == StageStats::STAGE_EXTRA || ss.StageType == StageStats::STAGE_EXTRA2 ) - { - if( ss.m_player[pn].bFailed ) - ++pProfile->m_iNumExtraStagesFailed; - else - ++pProfile->m_iNumExtraStagesPassed; - } - - // If you fail in a course, you passed all but the final song. - // FIXME: Not true. If playing with 2 players, one player could have failed earlier. - if( !ss.m_player[pn].bFailed ) - { - pProfile->m_iNumStagesPassedByPlayMode[ss.playMode] ++; - pProfile->m_iNumStagesPassedByGrade[ss.m_player[pn].GetGrade()] ++; - } -} - void GameState::EndGame() { LOG->Trace( "GameState::EndGame" ); @@ -478,56 +437,7 @@ void GameState::FinishStage() if( m_bDemonstrationOrJukebox ) return; - // - // Add step totals. Use radarActual, since the player might have failed part way - // through the song, in which case we don't want to give credit for the rest of the - // song. - // - FOREACH_HumanPlayer( pn ) - { - int iNumTapsAndHolds = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_TAPS_AND_HOLDS]; - int iNumJumps = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_JUMPS]; - int iNumHolds = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HOLDS]; - int iNumMines = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_MINES]; - int iNumHands = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HANDS]; - float fCaloriesBurned = STATSMAN->m_CurStageStats.m_player[pn].fCaloriesBurned; - PROFILEMAN->AddStepTotals( pn, iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands, fCaloriesBurned ); - } - - - // Update profile stats - Profile* pMachineProfile = PROFILEMAN->GetMachineProfile(); - - int iGameplaySeconds = (int)truncf(STATSMAN->m_CurStageStats.fGameplaySeconds); - - pMachineProfile->m_iTotalGameplaySeconds += iGameplaySeconds; - pMachineProfile->m_iCurrentCombo = 0; - - CHECKPOINT; - FOREACH_HumanPlayer( pn ) - { - CHECKPOINT; - - Profile* pPlayerProfile = PROFILEMAN->GetProfile( pn ); - if( pPlayerProfile ) - { - pPlayerProfile->m_iTotalGameplaySeconds += iGameplaySeconds; - pPlayerProfile->m_iCurrentCombo = - PREFSMAN->m_bComboContinuesBetweenSongs ? - STATSMAN->m_CurStageStats.m_player[pn].iCurCombo : - 0; - } - - const StageStats& ss = STATSMAN->m_CurStageStats; - AddPlayerStatsToProfile( pMachineProfile, ss, pn ); - - if( pPlayerProfile ) - AddPlayerStatsToProfile( pPlayerProfile, ss, pn ); - - CHECKPOINT; - } - - + STATSMAN->CommitStatsToProfiles(); if( GAMESTATE->GetEventMode() ) { diff --git a/stepmania/src/StatsManager.cpp b/stepmania/src/StatsManager.cpp index 2736e8d66c..db13fbf64b 100644 --- a/stepmania/src/StatsManager.cpp +++ b/stepmania/src/StatsManager.cpp @@ -2,6 +2,9 @@ #include "StatsManager.h" #include "GameState.h" #include "Foreach.h" +#include "ProfileManager.h" +#include "PrefsManager.h" +#include "Steps.h" StatsManager* STATSMAN = NULL; // global object accessable from anywhere in the program @@ -72,6 +75,99 @@ void StatsManager::CalcAccumStageStats() m_AccumStageStats = AccumStageStats( m_vPlayedStageStats ); } +/* This data is added to each player profile, and to the machine profile per-player. */ +void AddPlayerStatsToProfile( Profile *pProfile, const StageStats &ss, PlayerNumber pn ) +{ + ss.AssertValid( pn ); + CHECKPOINT; + + StyleID sID; + sID.FromStyle( ss.pStyle ); + + ASSERT( ss.vpSongs.size() == ss.m_player[pn].vpSteps.size() ); + for( unsigned i=0; im_iNumSongsPlayedByPlayMode[ss.playMode]++; + pProfile->m_iNumSongsPlayedByStyle[sID] ++; + pProfile->m_iNumSongsPlayedByDifficulty[pSteps->GetDifficulty()] ++; + + int iMeter = clamp( pSteps->GetMeter(), 0, MAX_METER ); + pProfile->m_iNumSongsPlayedByMeter[iMeter] ++; + } + + pProfile->m_iTotalDancePoints += ss.m_player[pn].iActualDancePoints; + + if( ss.StageType == StageStats::STAGE_EXTRA || ss.StageType == StageStats::STAGE_EXTRA2 ) + { + if( ss.m_player[pn].bFailed ) + ++pProfile->m_iNumExtraStagesFailed; + else + ++pProfile->m_iNumExtraStagesPassed; + } + + // If you fail in a course, you passed all but the final song. + // FIXME: Not true. If playing with 2 players, one player could have failed earlier. + if( !ss.m_player[pn].bFailed ) + { + pProfile->m_iNumStagesPassedByPlayMode[ss.playMode] ++; + pProfile->m_iNumStagesPassedByGrade[ss.m_player[pn].GetGrade()] ++; + } +} + + +void StatsManager::CommitStatsToProfiles() +{ + // + // Add step totals. Use radarActual, since the player might have failed part way + // through the song, in which case we don't want to give credit for the rest of the + // song. + // + FOREACH_HumanPlayer( pn ) + { + int iNumTapsAndHolds = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_TAPS_AND_HOLDS]; + int iNumJumps = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_JUMPS]; + int iNumHolds = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HOLDS]; + int iNumMines = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_MINES]; + int iNumHands = (int) STATSMAN->m_CurStageStats.m_player[pn].radarActual[RADAR_NUM_HANDS]; + float fCaloriesBurned = STATSMAN->m_CurStageStats.m_player[pn].fCaloriesBurned; + PROFILEMAN->AddStepTotals( pn, iNumTapsAndHolds, iNumJumps, iNumHolds, iNumMines, iNumHands, fCaloriesBurned ); + } + + // Update profile stats + Profile* pMachineProfile = PROFILEMAN->GetMachineProfile(); + + int iGameplaySeconds = (int)truncf(STATSMAN->m_CurStageStats.fGameplaySeconds); + + pMachineProfile->m_iTotalGameplaySeconds += iGameplaySeconds; + pMachineProfile->m_iCurrentCombo = 0; + + CHECKPOINT; + FOREACH_HumanPlayer( pn ) + { + CHECKPOINT; + + Profile* pPlayerProfile = PROFILEMAN->GetProfile( pn ); + if( pPlayerProfile ) + { + pPlayerProfile->m_iTotalGameplaySeconds += iGameplaySeconds; + pPlayerProfile->m_iCurrentCombo = + PREFSMAN->m_bComboContinuesBetweenSongs ? + STATSMAN->m_CurStageStats.m_player[pn].iCurCombo : + 0; + } + + const StageStats& ss = STATSMAN->m_CurStageStats; + AddPlayerStatsToProfile( pMachineProfile, ss, pn ); + + if( pPlayerProfile ) + AddPlayerStatsToProfile( pPlayerProfile, ss, pn ); + + CHECKPOINT; + } +} + // lua start #include "LuaBinding.h" diff --git a/stepmania/src/StatsManager.h b/stepmania/src/StatsManager.h index eafeb4a6e1..c3d2f0fb17 100644 --- a/stepmania/src/StatsManager.h +++ b/stepmania/src/StatsManager.h @@ -21,6 +21,8 @@ public: void CalcAccumStageStats(); StageStats& GetAccumStageStats() { return m_AccumStageStats; } + void CommitStatsToProfiles(); + // Lua void PushSelf( lua_State *L );