pass around a PlayerState and PlayerStageStats instead of PlayerNumber and looking things up in GameState

This commit is contained in:
Chris Danford
2005-08-23 20:40:47 +00:00
parent 0cedd92c67
commit 20bb281e18
21 changed files with 81 additions and 60 deletions
+9 -2
View File
@@ -5,6 +5,8 @@
#include "GameConstantsAndTypes.h"
#include "ActorFrame.h"
class PlayerState;
class PlayerStageStats;
class LifeMeter : public ActorFrame
{
@@ -12,7 +14,11 @@ public:
LifeMeter() {};
virtual ~LifeMeter() {};
virtual void Load( PlayerNumber pn ) { m_PlayerNumber = pn; }
virtual void Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
{
m_pPlayerState = pPlayerState;
m_pPlayerStageStats = pPlayerStageStats;
}
virtual void OnLoadSong() {};
virtual void OnSongEnded() {};
/* Change life after receiving a tap note grade. This *is* called for
@@ -30,7 +36,8 @@ public:
virtual void ForceFail() = 0;
protected:
PlayerNumber m_PlayerNumber;
const PlayerState *m_pPlayerState;
PlayerStageStats *m_pPlayerStageStats;
};
+11 -9
View File
@@ -100,15 +100,17 @@ LifeMeterBar::~LifeMeterBar()
SAFE_DELETE( m_pStream );
}
void LifeMeterBar::Load( PlayerNumber pn )
void LifeMeterBar::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
{
LifeMeter::Load( pn );
LifeMeter::Load( pPlayerState, pPlayerStageStats );
PlayerNumber pn = pPlayerState->m_PlayerNumber;
// Change life difficulty to really easy if merciful beginner on
bool bMercifulBeginnerInEffect =
GAMESTATE->m_PlayMode == PLAY_MODE_REGULAR &&
GAMESTATE->IsPlayerEnabled( pn ) &&
GAMESTATE->m_pCurSteps[m_PlayerNumber]->GetDifficulty() == DIFFICULTY_BEGINNER &&
GAMESTATE->IsPlayerEnabled( pPlayerState ) &&
GAMESTATE->m_pCurSteps[pn]->GetDifficulty() == DIFFICULTY_BEGINNER &&
PREFSMAN->m_bMercifulBeginner;
if( bMercifulBeginnerInEffect )
{
@@ -247,7 +249,7 @@ void LifeMeterBar::ChangeLife( float fDeltaLife )
}
/* If we've already failed, there's no point in letting them fill up the bar again. */
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailed )
if( m_pPlayerStageStats->bFailed )
fDeltaLife = 0;
switch( GAMESTATE->m_SongOptions.m_DrainType )
@@ -277,7 +279,7 @@ void LifeMeterBar::ChangeLife( float fDeltaLife )
AfterLifeChanged();
if( m_fLifePercentage <= FAIL_THRESHOLD )
STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier = true;
m_pPlayerStageStats->bFailedEarlier = true;
}
void LifeMeterBar::AfterLifeChanged()
@@ -287,9 +289,9 @@ void LifeMeterBar::AfterLifeChanged()
bool LifeMeterBar::IsPastPassmark() const
{
if( GAMESTATE->m_pPlayerState[m_PlayerNumber]->m_PlayerOptions.m_fPassmark > 0 )
if( m_pPlayerState->m_PlayerOptions.m_fPassmark > 0 )
{
return m_fLifePercentage >= GAMESTATE->m_pPlayerState[m_PlayerNumber]->m_PlayerOptions.m_fPassmark;
return m_fLifePercentage >= m_pPlayerState->m_PlayerOptions.m_fPassmark;
}
else
{
@@ -326,7 +328,7 @@ void LifeMeterBar::Update( float fDeltaTime )
m_pStream->SetPassingAlpha( m_fPassingAlpha );
m_pStream->SetHotAlpha( m_fHotAlpha );
if( m_fLifePercentage < DANGER_THRESHOLD && !GAMESTATE->IsPlayerDead(m_PlayerNumber) )
if( m_fLifePercentage < DANGER_THRESHOLD && !GAMESTATE->IsPlayerDead(m_pPlayerState) )
m_quadDangerGlow.SetDiffuseAlpha( 1 );
else
m_quadDangerGlow.SetDiffuseAlpha( 0 );
+1 -1
View File
@@ -14,7 +14,7 @@ public:
LifeMeterBar();
~LifeMeterBar();
virtual void Load( PlayerNumber pn );
virtual void Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats );
virtual void Update( float fDeltaTime );
virtual void DrawPrimitives();
+13 -10
View File
@@ -3,7 +3,7 @@
#include "GameState.h"
#include "ThemeManager.h"
#include "Steps.h"
#include "StatsManager.h"
#include "PlayerState.h"
const float BATTERY_X[NUM_PLAYERS] = { -92, +92 };
@@ -25,11 +25,11 @@ LifeMeterBattery::LifeMeterBattery()
m_soundLoseLife.Load( THEME->GetPathS("LifeMeterBattery","lose"),true );
}
void LifeMeterBattery::Load( PlayerNumber pn )
void LifeMeterBattery::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
{
LifeMeter::Load( pn );
LifeMeter::Load( pPlayerState, pPlayerStageStats );
bool bPlayerEnabled = GAMESTATE->IsPlayerEnabled(pn);
bool bPlayerEnabled = GAMESTATE->IsPlayerEnabled( pPlayerState );
m_sprFrame.Load( THEME->GetPathG("LifeMeterBattery","frame") );
this->AddChild( &m_sprFrame );
@@ -45,6 +45,8 @@ void LifeMeterBattery::Load( PlayerNumber pn )
if( bPlayerEnabled )
this->AddChild( &m_textNumLives );
PlayerNumber pn = pPlayerState->m_PlayerNumber;
m_sprFrame.SetZoomX( pn==PLAYER_1 ? 1.0f : -1.0f );
m_sprBattery.SetZoomX( pn==PLAYER_1 ? 1.0f : -1.0f );
m_sprBattery.SetX( BATTERY_X[pn] );
@@ -53,7 +55,7 @@ void LifeMeterBattery::Load( PlayerNumber pn )
if( bPlayerEnabled )
{
m_Percent.Load( pn, &STATSMAN->m_CurStageStats.m_player[pn], "LifeMeterBattery Percent", true );
m_Percent.Load( pPlayerState, pPlayerStageStats, "LifeMeterBattery Percent", true );
this->AddChild( &m_Percent );
}
@@ -62,13 +64,14 @@ void LifeMeterBattery::Load( PlayerNumber pn )
void LifeMeterBattery::OnSongEnded()
{
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier )
if( m_pPlayerStageStats->bFailedEarlier )
return;
if( m_iLivesLeft < GAMESTATE->m_SongOptions.m_iBatteryLives )
{
m_iTrailingLivesLeft = m_iLivesLeft;
m_iLivesLeft += ( GAMESTATE->m_pCurSteps[m_PlayerNumber]->GetMeter()>=8 ? 2 : 1 );
PlayerNumber pn = m_pPlayerState->m_PlayerNumber;
m_iLivesLeft += ( GAMESTATE->m_pCurSteps[pn]->GetMeter()>=8 ? 2 : 1 );
m_iLivesLeft = min( m_iLivesLeft, GAMESTATE->m_SongOptions.m_iBatteryLives );
m_soundGainLife.Play();
}
@@ -79,7 +82,7 @@ void LifeMeterBattery::OnSongEnded()
void LifeMeterBattery::ChangeLife( TapNoteScore score )
{
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier )
if( m_pPlayerStageStats->bFailedEarlier )
return;
switch( score )
@@ -107,7 +110,7 @@ void LifeMeterBattery::ChangeLife( TapNoteScore score )
ASSERT(0);
}
if( m_iLivesLeft == 0 )
STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier = true;
m_pPlayerStageStats->bFailedEarlier = true;
}
void LifeMeterBattery::ChangeLife( HoldNoteScore score, TapNoteScore tscore )
@@ -145,7 +148,7 @@ bool LifeMeterBattery::IsHot() const
bool LifeMeterBattery::IsFailing() const
{
return STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier;
return m_pPlayerStageStats->bFailedEarlier;
}
float LifeMeterBattery::GetLife() const
+1 -1
View File
@@ -15,7 +15,7 @@ class LifeMeterBattery : public LifeMeter
public:
LifeMeterBattery();
virtual void Load( PlayerNumber pn );
virtual void Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats );
virtual void Update( float fDeltaTime );
+12 -12
View File
@@ -1,13 +1,13 @@
#include "global.h"
#include "LifeMeterTime.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "Steps.h"
#include "StatsManager.h"
#include "ActorUtil.h"
#include "Course.h"
#include "PrefsManager.h"
#include "StreamDisplay.h"
#include "GameState.h"
#include "StatsManager.h"
const float FULL_LIFE_SECONDS = 1.5f*60;
@@ -24,9 +24,9 @@ LifeMeterTime::LifeMeterTime()
m_fLifeTotalLostSeconds = 0;
}
void LifeMeterTime::Load( PlayerNumber pn )
void LifeMeterTime::Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats )
{
LifeMeter::Load( pn );
LifeMeter::Load( pPlayerState, pPlayerStageStats );
const CString sType = "LifeMeterTime";
@@ -70,7 +70,7 @@ void LifeMeterTime::Load( PlayerNumber pn )
void LifeMeterTime::OnLoadSong()
{
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier )
if( m_pPlayerStageStats->bFailedEarlier )
return;
Course* pCourse = GAMESTATE->m_pCurCourse;
@@ -85,7 +85,7 @@ void LifeMeterTime::OnLoadSong()
void LifeMeterTime::ChangeLife( TapNoteScore tns )
{
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier )
if( m_pPlayerStageStats->bFailedEarlier )
return;
float fMeterChange = 0;
@@ -104,12 +104,12 @@ void LifeMeterTime::ChangeLife( TapNoteScore tns )
m_fLifeTotalLostSeconds -= fMeterChange;
if( GetLifeSeconds() <= 0 )
STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier = true;
m_pPlayerStageStats->bFailedEarlier = true;
}
void LifeMeterTime::ChangeLife( HoldNoteScore hns, TapNoteScore tns )
{
if( STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier )
if( m_pPlayerStageStats->bFailedEarlier )
return;
float fMeterChange = 0;
@@ -123,7 +123,7 @@ void LifeMeterTime::ChangeLife( HoldNoteScore hns, TapNoteScore tns )
m_fLifeTotalLostSeconds -= fMeterChange;
if( GetLifeSeconds() <= 0 )
STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier = true;
m_pPlayerStageStats->bFailedEarlier = true;
}
void LifeMeterTime::OnDancePointsChange()
@@ -143,7 +143,7 @@ bool LifeMeterTime::IsHot() const
bool LifeMeterTime::IsFailing() const
{
return STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].bFailedEarlier;
return m_pPlayerStageStats->bFailedEarlier;
}
void LifeMeterTime::Update( float fDeltaTime )
@@ -151,7 +151,7 @@ void LifeMeterTime::Update( float fDeltaTime )
// update current stage stats so ScoreDisplayLifeTime can show the right thing
float fSecs = GetLifeSeconds();
fSecs = max( 0, fSecs );
STATSMAN->m_CurStageStats.m_player[m_PlayerNumber].fLifeRemainingSeconds = fSecs;
m_pPlayerStageStats->fLifeRemainingSeconds = fSecs;
LifeMeter::Update( fDeltaTime );
@@ -160,7 +160,7 @@ void LifeMeterTime::Update( float fDeltaTime )
m_pStream->SetPassingAlpha( 0 );
m_pStream->SetHotAlpha( 0 );
if( m_pStream->GetTrailingLifePercent() < DANGER_THRESHOLD && !GAMESTATE->IsPlayerDead(m_PlayerNumber) )
if( m_pStream->GetTrailingLifePercent() < DANGER_THRESHOLD && !GAMESTATE->IsPlayerDead(m_pPlayerState) )
m_quadDangerGlow.SetDiffuseAlpha( 1 );
else
m_quadDangerGlow.SetDiffuseAlpha( 0 );
+1 -1
View File
@@ -18,7 +18,7 @@ class LifeMeterTime : public LifeMeter
public:
LifeMeterTime();
virtual void Load( PlayerNumber pn );
virtual void Load( const PlayerState *pPlayerState, PlayerStageStats *pPlayerStageStats );
virtual void Update( float fDeltaTime );
+6
View File
@@ -1,2 +1,8 @@
#include "global.h"
#include "ScoreDisplay.h"
void ScoreDisplay::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
m_pPlayerState = pPlayerState;
m_pPlayerStageStats = pPlayerStageStats;
}
+5 -3
View File
@@ -5,12 +5,13 @@
#include "ActorFrame.h"
#include "GameConstantsAndTypes.h"
struct PlayerState;
class PlayerState;
class PlayerStageStats;
class ScoreDisplay : public ActorFrame
{
public:
virtual void Init( const PlayerState* pPlayerState ) { m_pPlayerState = pPlayerState; }
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void SetScore( int iNewScore ) {}
virtual void OnLoadSong() {};
@@ -23,7 +24,8 @@ public:
virtual void OnJudgment( HoldNoteScore score, TapNoteScore tscore ) {};
protected:
const PlayerState* m_pPlayerState; // needed to look up statistics in GAMESTATE
const PlayerState* m_pPlayerState; // needed to look up stats
const PlayerStageStats* m_pPlayerStageStats; // needed to look up stats
};
#endif
+2 -2
View File
@@ -32,9 +32,9 @@ ScoreDisplayBattle::ScoreDisplayBattle()
m_TexturePreload.Load( asIconPaths[j] );
}
void ScoreDisplayBattle::Init( const PlayerState* pPlayerState )
void ScoreDisplayBattle::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState );
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
}
void ScoreDisplayBattle::Update( float fDelta )
+1 -1
View File
@@ -13,7 +13,7 @@ class ScoreDisplayBattle : public ScoreDisplay
{
public:
ScoreDisplayBattle();
virtual void Init( const PlayerState* pPlayerState );
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void Update( float fDelta );
+3 -3
View File
@@ -18,9 +18,9 @@ ScoreDisplayLifeTime::ScoreDisplayLifeTime()
LOG->Trace( "ScoreDisplayLifeTime::ScoreDisplayLifeTime()" );
}
void ScoreDisplayLifeTime::Init( const PlayerState* pPlayerState )
void ScoreDisplayLifeTime::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState );
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
const CString sType = "ScoreDisplayLifeTime";
@@ -65,7 +65,7 @@ void ScoreDisplayLifeTime::Update( float fDelta )
{
ScoreDisplay::Update( fDelta );
float fSecs = STATSMAN->m_CurStageStats.m_player[m_pPlayerState->m_PlayerNumber].fLifeRemainingSeconds;
float fSecs = m_pPlayerStageStats->fLifeRemainingSeconds;
CString s = SecondsToMSSMsMs(fSecs);
m_textTimeRemaining.SetText( s );
+1 -1
View File
@@ -12,7 +12,7 @@ class ScoreDisplayLifeTime : public ScoreDisplay
public:
ScoreDisplayLifeTime();
virtual void Init( const PlayerState* pPlayerState );
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void Update( float fDelta );
+2 -2
View File
@@ -24,9 +24,9 @@ ScoreDisplayNormal::ScoreDisplayNormal()
this->AddChild( &m_text );
}
void ScoreDisplayNormal::Init( const PlayerState* pPlayerState )
void ScoreDisplayNormal::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState );
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = pPlayerState->m_PlayerNumber;
+1 -1
View File
@@ -12,7 +12,7 @@ class ScoreDisplayNormal : public ScoreDisplay
public:
ScoreDisplayNormal();
virtual void Init( const PlayerState* pPlayerState );
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void SetScore( int iNewScore );
virtual void SetText( CString s ) { m_text.SetText(s); }
+2 -2
View File
@@ -24,9 +24,9 @@ ScoreDisplayOni::ScoreDisplayOni()
this->AddChild( &m_text );
}
void ScoreDisplayOni::Init( const PlayerState* pPlayerState )
void ScoreDisplayOni::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState );
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
// TODO: Remove use of PlayerNumber.
PlayerNumber pn = pPlayerState->m_PlayerNumber;
+1 -1
View File
@@ -12,7 +12,7 @@ class ScoreDisplayOni : public ScoreDisplay
public:
ScoreDisplayOni();
virtual void Init( const PlayerState* pPlayerState );
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void Update( float fDelta );
+5 -3
View File
@@ -14,11 +14,13 @@ ScoreDisplayPercentage::ScoreDisplayPercentage()
this->AddChild( &m_Percent );
}
void ScoreDisplayPercentage::Init( const PlayerState* pPlayerState )
void ScoreDisplayPercentage::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
m_Percent.Load(
pPlayerState->m_PlayerNumber,
&STATSMAN->m_CurStageStats.m_player[pPlayerState->m_PlayerNumber],
pPlayerState,
pPlayerStageStats,
"ScoreDisplayPercentage Percent",
true );
}
+1 -1
View File
@@ -11,7 +11,7 @@ class ScoreDisplayPercentage: public ScoreDisplay
{
public:
ScoreDisplayPercentage();
void Init( const PlayerState* pPlayerState );
void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
private:
AutoActor m_sprFrame;
+2 -3
View File
@@ -4,7 +4,6 @@
#include "RageLog.h"
#include "PrefsManager.h"
#include "RageLog.h"
#include "GameState.h"
#include "ThemeManager.h"
#include "ActorUtil.h"
#include "PlayerState.h"
@@ -34,9 +33,9 @@ ScoreDisplayRave::ScoreDisplayRave()
this->AddChild( &m_textLevel );
}
void ScoreDisplayRave::Init( const PlayerState* pPlayerState )
void ScoreDisplayRave::Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats )
{
ScoreDisplay::Init( pPlayerState );
ScoreDisplay::Init( pPlayerState, pPlayerStageStats );
PlayerNumber pn = pPlayerState->m_PlayerNumber;
+1 -1
View File
@@ -13,7 +13,7 @@ class ScoreDisplayRave : public ScoreDisplay
{
public:
ScoreDisplayRave();
virtual void Init( const PlayerState* pPlayerState );
virtual void Init( const PlayerState* pPlayerState, const PlayerStageStats* pPlayerStageStats );
virtual void Update( float fDelta );