Skip to content

Commit eb03d26

Browse files
committed
make repeating code into function
1 parent bfd4f04 commit eb03d26

File tree

2 files changed

+43
-104
lines changed

2 files changed

+43
-104
lines changed

src/game/client/gameclient.cpp

Lines changed: 41 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,6 +2417,43 @@ void CGameClient::UpdateEditorIngameMoved()
24172417
}
24182418
}
24192419

2420+
void CGameClient::ApplyPredictInputs(int Tick, bool Direct, CGameWorld& GameWorld)
2421+
{
2422+
for(int i = 0; i < MAX_CLIENTS; i++)
2423+
{
2424+
if(CCharacter *pChar = GameWorld.GetCharacterById(i))
2425+
{
2426+
if(i == m_aLocalIds[0] || (Client()->DummyConnected() && i == m_aLocalIds[1]))
2427+
continue;
2428+
2429+
const CNetMsg_Sv_PreInput PreInput = m_aClients[i].m_aPreInputs[Tick % 200];
2430+
if(PreInput.m_IntendedTick != Tick)
2431+
continue;
2432+
2433+
//convert preinput to input
2434+
CNetObj_PlayerInput Input = {0};
2435+
Input.m_Direction = PreInput.m_Direction;
2436+
Input.m_TargetX = PreInput.m_TargetX;
2437+
Input.m_TargetY = PreInput.m_TargetY;
2438+
Input.m_Jump = PreInput.m_Jump;
2439+
Input.m_Fire = PreInput.m_Fire;
2440+
Input.m_Hook = PreInput.m_Hook;
2441+
Input.m_WantedWeapon = PreInput.m_WantedWeapon;
2442+
Input.m_NextWeapon = PreInput.m_NextWeapon;
2443+
Input.m_PrevWeapon = PreInput.m_PrevWeapon;
2444+
2445+
if(Direct)
2446+
{
2447+
pChar->OnDirectInput(&Input);
2448+
}
2449+
else
2450+
{
2451+
pChar->OnPredictedInput(&Input);
2452+
}
2453+
}
2454+
}
2455+
}
2456+
24202457
void CGameClient::OnPredict()
24212458
{
24222459
// store the previous values so we can detect prediction errors
@@ -2513,32 +2550,7 @@ void CGameClient::OnPredict()
25132550

25142551
if(g_Config.m_ClAntiPingPreInput)
25152552
{
2516-
for(int i = 0; i < MAX_CLIENTS; i++)
2517-
{
2518-
if(CCharacter *pChar = m_PredictedWorld.GetCharacterById(i))
2519-
{
2520-
if(i == m_aLocalIds[0] || (Client()->DummyConnected() && i == m_aLocalIds[1]))
2521-
continue;
2522-
2523-
const CNetMsg_Sv_PreInput PreInput = m_aClients[i].m_aPreInputs[Tick % 200];
2524-
if(PreInput.m_IntendedTick != Tick)
2525-
continue;
2526-
2527-
//convert preinput to input
2528-
CNetObj_PlayerInput Input = {0};
2529-
Input.m_Direction = PreInput.m_Direction;
2530-
Input.m_TargetX = PreInput.m_TargetX;
2531-
Input.m_TargetY = PreInput.m_TargetY;
2532-
Input.m_Jump = PreInput.m_Jump;
2533-
Input.m_Fire = PreInput.m_Fire;
2534-
Input.m_Hook = PreInput.m_Hook;
2535-
Input.m_WantedWeapon = PreInput.m_WantedWeapon;
2536-
Input.m_NextWeapon = PreInput.m_NextWeapon;
2537-
Input.m_PrevWeapon = PreInput.m_PrevWeapon;
2538-
2539-
pChar->OnDirectInput(&Input);
2540-
}
2541-
}
2553+
ApplyPredictInputs(Tick, true, m_PredictedWorld);
25422554
}
25432555

25442556
m_PredictedWorld.m_GameTick = Tick;
@@ -2549,32 +2561,7 @@ void CGameClient::OnPredict()
25492561

25502562
if(g_Config.m_ClAntiPingPreInput)
25512563
{
2552-
for(int i = 0; i < MAX_CLIENTS; i++)
2553-
{
2554-
if(CCharacter *pChar = m_PredictedWorld.GetCharacterById(i))
2555-
{
2556-
if(pDummyChar == pChar || pLocalChar == pChar)
2557-
continue;
2558-
2559-
const CNetMsg_Sv_PreInput PreInput = m_aClients[i].m_aPreInputs[Tick % 200];
2560-
if(PreInput.m_IntendedTick != Tick)
2561-
continue;
2562-
2563-
//convert preinput to input
2564-
CNetObj_PlayerInput Input = {0};
2565-
Input.m_Direction = PreInput.m_Direction;
2566-
Input.m_TargetX = PreInput.m_TargetX;
2567-
Input.m_TargetY = PreInput.m_TargetY;
2568-
Input.m_Jump = PreInput.m_Jump;
2569-
Input.m_Fire = PreInput.m_Fire;
2570-
Input.m_Hook = PreInput.m_Hook;
2571-
Input.m_WantedWeapon = PreInput.m_WantedWeapon;
2572-
Input.m_NextWeapon = PreInput.m_NextWeapon;
2573-
Input.m_PrevWeapon = PreInput.m_PrevWeapon;
2574-
2575-
pChar->OnPredictedInput(&Input);
2576-
}
2577-
}
2564+
ApplyPredictInputs(Tick, false, m_PredictedWorld);
25782565
}
25792566

25802567
m_PredictedWorld.Tick();
@@ -3438,32 +3425,7 @@ void CGameClient::UpdatePrediction()
34383425

34393426
if(g_Config.m_ClAntiPingPreInput)
34403427
{
3441-
for(int i = 0; i < MAX_CLIENTS; i++)
3442-
{
3443-
if(CCharacter *pChar = m_GameWorld.GetCharacterById(i))
3444-
{
3445-
if(i == m_aLocalIds[0] || (Client()->DummyConnected() && i == m_aLocalIds[1]))
3446-
continue;
3447-
3448-
const CNetMsg_Sv_PreInput PreInput = m_aClients[i].m_aPreInputs[Tick % 200];
3449-
if(PreInput.m_IntendedTick != Tick)
3450-
continue;
3451-
3452-
//convert preinput to input
3453-
CNetObj_PlayerInput Input = {0};
3454-
Input.m_Direction = PreInput.m_Direction;
3455-
Input.m_TargetX = PreInput.m_TargetX;
3456-
Input.m_TargetY = PreInput.m_TargetY;
3457-
Input.m_Jump = PreInput.m_Jump;
3458-
Input.m_Fire = PreInput.m_Fire;
3459-
Input.m_Hook = PreInput.m_Hook;
3460-
Input.m_WantedWeapon = PreInput.m_WantedWeapon;
3461-
Input.m_NextWeapon = PreInput.m_NextWeapon;
3462-
Input.m_PrevWeapon = PreInput.m_PrevWeapon;
3463-
3464-
pChar->OnDirectInput(&Input);
3465-
}
3466-
}
3428+
ApplyPredictInputs(Tick, true, m_GameWorld);
34673429
}
34683430

34693431
m_GameWorld.m_GameTick = Tick;
@@ -3474,32 +3436,7 @@ void CGameClient::UpdatePrediction()
34743436

34753437
if(g_Config.m_ClAntiPingPreInput)
34763438
{
3477-
for(int i = 0; i < MAX_CLIENTS; i++)
3478-
{
3479-
if(CCharacter *pChar = m_GameWorld.GetCharacterById(i))
3480-
{
3481-
if(i == m_aLocalIds[0] || (Client()->DummyConnected() && i == m_aLocalIds[1]))
3482-
continue;
3483-
3484-
const CNetMsg_Sv_PreInput PreInput = m_aClients[i].m_aPreInputs[Tick % 200];
3485-
if(PreInput.m_IntendedTick != Tick)
3486-
continue;
3487-
3488-
//convert preinput to input
3489-
CNetObj_PlayerInput Input = {0};
3490-
Input.m_Direction = PreInput.m_Direction;
3491-
Input.m_TargetX = PreInput.m_TargetX;
3492-
Input.m_TargetY = PreInput.m_TargetY;
3493-
Input.m_Jump = PreInput.m_Jump;
3494-
Input.m_Fire = PreInput.m_Fire;
3495-
Input.m_Hook = PreInput.m_Hook;
3496-
Input.m_WantedWeapon = PreInput.m_WantedWeapon;
3497-
Input.m_NextWeapon = PreInput.m_NextWeapon;
3498-
Input.m_PrevWeapon = PreInput.m_PrevWeapon;
3499-
3500-
pChar->OnPredictedInput(&Input);
3501-
}
3502-
}
3439+
ApplyPredictInputs(Tick, false, m_GameWorld);
35033440
}
35043441

35053442
m_GameWorld.Tick();

src/game/client/gameclient.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,8 @@ class CGameClient : public IGameClient
653653
void SendKill() const;
654654
void SendReadyChange7();
655655

656+
void ApplyPredictInputs(int Tick, bool Direct, CGameWorld& GameWorld);
657+
656658
int m_aNextChangeInfo[NUM_DUMMIES];
657659

658660
// DDRace

0 commit comments

Comments
 (0)