Skip to content

Commit

Permalink
Remove almost every usage of Foreach_playernumber
Browse files Browse the repository at this point in the history
for removing player_2
  • Loading branch information
poco0317 committed Dec 19, 2018
1 parent 5f657f2 commit 50e168f
Show file tree
Hide file tree
Showing 30 changed files with 534 additions and 691 deletions.
5 changes: 2 additions & 3 deletions src/Background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,7 @@ bool
BackgroundImpl::IsDangerAllVisible()
{
// The players are never in danger in FAIL_OFF.
FOREACH_PlayerNumber(
p) if (GAMESTATE->GetPlayerFailType(GAMESTATE->m_pPlayerState[p]) ==
if (GAMESTATE->GetPlayerFailType(GAMESTATE->m_pPlayerState[PLAYER_1]) ==
FailType_Off) return false;
if (!g_bShowDanger)
return false;
Expand Down Expand Up @@ -1027,7 +1026,7 @@ BrightnessOverlay::Set(float fBrightness)
{
RageColor c = GetBrightnessColor(fBrightness);

FOREACH_PlayerNumber(pn) m_quadBGBrightness[pn].SetDiffuse(c);
m_quadBGBrightness[PLAYER_1].SetDiffuse(c);
m_quadBGBrightnessFade.SetDiffuse(c);
}

Expand Down
256 changes: 124 additions & 132 deletions src/DancingCharacters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,111 +52,109 @@ const float MODEL_ROTATIONY_TWO_PLAYERS[NUM_PLAYERS] = { 0 };

DancingCharacters::DancingCharacters()
{
FOREACH_PlayerNumber(p)
PlayerNumber p = PLAYER_1;
m_pCharacter[p] = new Model;
m_2DIdleTimer[p].SetZero();
m_i2DAnimState[p] = AS2D_IDLE; // start on idle state
if (!GAMESTATE->IsPlayerEnabled(p))
return;

Character* pChar = GAMESTATE->m_pCurCharacters[p];
if (pChar == nullptr)
return;

// load in any potential 2D stuff
RString sCharacterDirectory = pChar->m_sCharDir;
RString sCurrentAnim;
sCurrentAnim = sCharacterDirectory + "2DIdle";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_pCharacter[p] = new Model;
m_2DIdleTimer[p].SetZero();
m_i2DAnimState[p] = AS2D_IDLE; // start on idle state
if (!GAMESTATE->IsPlayerEnabled(p))
continue;

Character* pChar = GAMESTATE->m_pCurCharacters[p];
if (pChar == nullptr)
continue;

// load in any potential 2D stuff
RString sCharacterDirectory = pChar->m_sCharDir;
RString sCurrentAnim;
sCurrentAnim = sCharacterDirectory + "2DIdle";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgIdle[p].Load(sCurrentAnim);
m_bgIdle[p]->SetXY(DC_X(p), DC_Y(p));
}
m_bgIdle[p].Load(sCurrentAnim);
m_bgIdle[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DMiss";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgMiss[p].Load(sCurrentAnim);
m_bgMiss[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DMiss";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgMiss[p].Load(sCurrentAnim);
m_bgMiss[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DGood";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgGood[p].Load(sCurrentAnim);
m_bgGood[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DGood";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgGood[p].Load(sCurrentAnim);
m_bgGood[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DGreat";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgGreat[p].Load(sCurrentAnim);
m_bgGreat[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DGreat";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgGreat[p].Load(sCurrentAnim);
m_bgGreat[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DFever";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgFever[p].Load(sCurrentAnim);
m_bgFever[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DFever";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgFever[p].Load(sCurrentAnim);
m_bgFever[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DFail";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgFail[p].Load(sCurrentAnim);
m_bgFail[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DFail";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgFail[p].Load(sCurrentAnim);
m_bgFail[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DWin";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgWin[p].Load(sCurrentAnim);
m_bgWin[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DWin";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgWin[p].Load(sCurrentAnim);
m_bgWin[p]->SetXY(DC_X(p), DC_Y(p));
}

sCurrentAnim = sCharacterDirectory + "2DWinFever";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgWinFever[p].Load(sCurrentAnim);
m_bgWinFever[p]->SetXY(DC_X(p), DC_Y(p));
}
sCurrentAnim = sCharacterDirectory + "2DWinFever";
if (DoesFileExist(sCurrentAnim +
"/BGAnimation.ini")) // check 2D Idle BGAnim exists
{
m_bgWinFever[p].Load(sCurrentAnim);
m_bgWinFever[p]->SetXY(DC_X(p), DC_Y(p));
}

if (pChar->GetModelPath().empty())
continue;
if (pChar->GetModelPath().empty())
return;

if (GAMESTATE->GetNumPlayersEnabled() == 2)
m_pCharacter[p]->SetX(MODEL_X_TWO_PLAYERS[p]);
else
m_pCharacter[p]->SetX(MODEL_X_ONE_PLAYER);

m_pCharacter[p]->LoadMilkshapeAscii(pChar->GetModelPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones("rest",
pChar->GetRestAnimationPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones(
"warmup", pChar->GetWarmUpAnimationPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones(
"dance", pChar->GetDanceAnimationPath());
m_pCharacter[p]->SetCullMode(CULL_NONE); // many of the models floating
// around have the vertex order
// flipped

m_pCharacter[p]->RunCommands(pChar->m_cmdInit);
}
if (GAMESTATE->GetNumPlayersEnabled() == 2)
m_pCharacter[p]->SetX(MODEL_X_TWO_PLAYERS[p]);
else
m_pCharacter[p]->SetX(MODEL_X_ONE_PLAYER);

m_pCharacter[p]->LoadMilkshapeAscii(pChar->GetModelPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones("rest",
pChar->GetRestAnimationPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones(
"warmup", pChar->GetWarmUpAnimationPath());
m_pCharacter[p]->LoadMilkshapeAsciiBones(
"dance", pChar->GetDanceAnimationPath());
m_pCharacter[p]->SetCullMode(CULL_NONE); // many of the models floating
// around have the vertex order
// flipped

m_pCharacter[p]->RunCommands(pChar->m_cmdInit);
}

DancingCharacters::~DancingCharacters()
{
FOREACH_PlayerNumber(p) delete m_pCharacter[p];
delete m_pCharacter[PLAYER_1];
}

void
Expand All @@ -175,8 +173,8 @@ DancingCharacters::LoadNextSong()
ASSERT(GAMESTATE->m_pCurSong != NULL);
m_fThisCameraEndBeat = GAMESTATE->m_pCurSong->GetFirstBeat();

FOREACH_PlayerNumber(p) if (GAMESTATE->IsPlayerEnabled(p)) m_pCharacter[p]
->PlayAnimation("rest");
if (GAMESTATE->IsPlayerEnabled(PLAYER_1))
m_pCharacter[PLAYER_1]->PlayAnimation("rest");
}

int
Expand All @@ -202,27 +200,23 @@ DancingCharacters::Update(float fDelta)
* at a very low music rate. */
fUpdateScale *= GAMESTATE->m_SongOptions.GetCurrent().m_fMusicRate;

FOREACH_PlayerNumber(p)
{
if (GAMESTATE->IsPlayerEnabled(p))
m_pCharacter[p]->Update(fDelta * fUpdateScale);
}
if (GAMESTATE->IsPlayerEnabled(PLAYER_1))
m_pCharacter[PLAYER_1]->Update(fDelta * fUpdateScale);
}

static bool bWasGameplayStarting = false;
bool bGameplayStarting = GAMESTATE->m_bGameplayLeadIn;
if (!bWasGameplayStarting && bGameplayStarting) {
FOREACH_PlayerNumber(p) if (GAMESTATE->IsPlayerEnabled(p))
m_pCharacter[p]
->PlayAnimation("warmup");
if (GAMESTATE->IsPlayerEnabled(PLAYER_1))
m_pCharacter[PLAYER_1]->PlayAnimation("warmup");
}
bWasGameplayStarting = bGameplayStarting;

static float fLastBeat = GAMESTATE->m_Position.m_fSongBeat;
float firstBeat = GAMESTATE->m_pCurSong->GetFirstBeat();
float fThisBeat = GAMESTATE->m_Position.m_fSongBeat;
if (fLastBeat < firstBeat && fThisBeat >= firstBeat) {
FOREACH_PlayerNumber(p) m_pCharacter[p]->PlayAnimation("dance");
m_pCharacter[PLAYER_1]->PlayAnimation("dance");
}
fLastBeat = fThisBeat;

Expand Down Expand Up @@ -273,42 +267,40 @@ DancingCharacters::Update(float fDelta)
/*
// is there any of this still around? This block of code is _ugly_. -Colby
// update any 2D stuff
FOREACH_PlayerNumber( p )
PlayerNumber p = PLAYER_1;
if( m_bgIdle[p].IsLoaded() )
{
if( m_bgIdle[p].IsLoaded() )
{
if( m_bgIdle[p].IsLoaded() && m_i2DAnimState[p] == AS2D_IDLE )
m_bgIdle[p]->Update( fDelta );
if( m_bgMiss[p].IsLoaded() && m_i2DAnimState[p] == AS2D_MISS )
m_bgMiss[p]->Update( fDelta );
if( m_bgGood[p].IsLoaded() && m_i2DAnimState[p] == AS2D_GOOD )
m_bgGood[p]->Update( fDelta );
if( m_bgGreat[p].IsLoaded() && m_i2DAnimState[p] == AS2D_GREAT )
m_bgGreat[p]->Update( fDelta );
if( m_bgFever[p].IsLoaded() && m_i2DAnimState[p] == AS2D_FEVER )
m_bgFever[p]->Update( fDelta );
if( m_bgFail[p].IsLoaded() && m_i2DAnimState[p] == AS2D_FAIL )
m_bgFail[p]->Update( fDelta );
if( m_bgWin[p].IsLoaded() && m_i2DAnimState[p] == AS2D_WIN )
m_bgWin[p]->Update( fDelta );
if( m_bgWinFever[p].IsLoaded() && m_i2DAnimState[p] == AS2D_WINFEVER
if( m_bgIdle[p].IsLoaded() && m_i2DAnimState[p] == AS2D_IDLE )
m_bgIdle[p]->Update( fDelta );
if( m_bgMiss[p].IsLoaded() && m_i2DAnimState[p] == AS2D_MISS )
m_bgMiss[p]->Update( fDelta );
if( m_bgGood[p].IsLoaded() && m_i2DAnimState[p] == AS2D_GOOD )
m_bgGood[p]->Update( fDelta );
if( m_bgGreat[p].IsLoaded() && m_i2DAnimState[p] == AS2D_GREAT )
m_bgGreat[p]->Update( fDelta );
if( m_bgFever[p].IsLoaded() && m_i2DAnimState[p] == AS2D_FEVER )
m_bgFever[p]->Update( fDelta );
if( m_bgFail[p].IsLoaded() && m_i2DAnimState[p] == AS2D_FAIL )
m_bgFail[p]->Update( fDelta );
if( m_bgWin[p].IsLoaded() && m_i2DAnimState[p] == AS2D_WIN )
m_bgWin[p]->Update( fDelta );
if( m_bgWinFever[p].IsLoaded() && m_i2DAnimState[p] == AS2D_WINFEVER
) m_bgWinFever[p]->Update(fDelta);
if(m_i2DAnimState[p] != AS2D_IDLE) // if we're not in idle state,
if(m_i2DAnimState[p] != AS2D_IDLE) // if we're not in idle state,
start a timer to return us to idle
{
// never return to idle state if we have failed / passed (i.e.
{
// never return to idle state if we have failed / passed (i.e.
completed) the song if(m_i2DAnimState[p] != AS2D_WINFEVER &&
m_i2DAnimState[p] != AS2D_FAIL && m_i2DAnimState[p] != AS2D_WIN)
{
if(m_2DIdleTimer[p].IsZero())
m_2DIdleTimer[p].Touch();
if(!m_2DIdleTimer[p].IsZero() && m_2DIdleTimer[p].Ago()
{
if(m_2DIdleTimer[p].IsZero())
m_2DIdleTimer[p].Touch();
if(!m_2DIdleTimer[p].IsZero() && m_2DIdleTimer[p].Ago()
> 1.0f)
{
m_2DIdleTimer[p].SetZero();
m_i2DAnimState[p] = AS2D_IDLE;
}
{
m_2DIdleTimer[p].SetZero();
m_i2DAnimState[p] = AS2D_IDLE;
}
}
}
Expand Down Expand Up @@ -391,8 +383,8 @@ DancingCharacters::DrawPrimitives()
/*
// Ugly! -Colby
// now draw any potential 2D stuff
FOREACH_PlayerNumber( p )
{
PlayerNumber p = PLAYER_1;
if(m_bgIdle[p].IsLoaded() && m_i2DAnimState[p] == AS2D_IDLE)
m_bgIdle[p]->Draw();
if(m_bgMiss[p].IsLoaded() && m_i2DAnimState[p] == AS2D_MISS)
Expand Down
Loading

0 comments on commit 50e168f

Please sign in to comment.