From 85e86772b269255ff327e30f9226539e71e510f0 Mon Sep 17 00:00:00 2001 From: trml Date: Thu, 26 May 2022 23:06:17 +0200 Subject: [PATCH] Don't keep track of characters in the predicted gameworld that are not in the snapshot and require pred characters to be alive --- src/game/client/gameclient.cpp | 26 ------------------- src/game/client/gameclient.h | 1 - .../client/prediction/entities/character.cpp | 4 +-- .../client/prediction/entities/character.h | 4 --- .../client/prediction/entities/pickup.cpp | 2 +- .../client/prediction/entities/projectile.cpp | 2 -- src/game/client/prediction/entity.h | 1 - src/game/client/prediction/gameworld.cpp | 4 +-- 8 files changed, 4 insertions(+), 40 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index e18976a82..352e66dbf 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -486,8 +486,6 @@ void CGameClient::OnConnected() m_GameWorld.m_WorldConfig.m_InfiniteAmmo = true; mem_zero(&m_GameInfo, sizeof(m_GameInfo)); m_PredictedDummyID = -1; - for(auto &LastWorldCharacter : m_aLastWorldCharacters) - LastWorldCharacter.m_Alive = false; LoadMapSettings(); if(Client()->State() != IClient::STATE_DEMOPLAYBACK && g_Config.m_ClAutoDemoOnConnect) @@ -813,7 +811,6 @@ void CGameClient::OnMessage(int MsgId, CUnpacker *pUnpacker, int Conn, bool Dumm if(!(m_GameWorld.m_WorldConfig.m_IsFNG && pMsg->m_Weapon == WEAPON_LASER)) { m_CharOrder.GiveWeak(pMsg->m_Victim); - m_aLastWorldCharacters[pMsg->m_Victim].m_Alive = false; if(CCharacter *pChar = m_GameWorld.GetCharacterByID(pMsg->m_Victim)) pChar->ResetPrediction(); m_GameWorld.ReleaseHooked(pMsg->m_Victim); @@ -2329,21 +2326,6 @@ void CGameClient::UpdatePrediction() m_GameWorld.m_Core.m_Tuning[g_Config.m_ClDummy].m_PlayerHooking = 1; } - // restore characters from previously saved ones if they temporarily left the snapshot - for(int i = 0; i < MAX_CLIENTS; i++) - if(m_aLastWorldCharacters[i].IsAlive() && m_Snap.m_aCharacters[i].m_Active && !m_GameWorld.GetCharacterByID(i)) - if(CCharacter *pCopy = new CCharacter(m_aLastWorldCharacters[i])) - { - m_GameWorld.InsertEntity(pCopy); - if(pCopy->m_FreezeTime > 0) - pCopy->m_FreezeTime = 0; - if(pCopy->Core()->m_HookedPlayer > 0) - { - pCopy->Core()->SetHookedPlayer(-1); - pCopy->Core()->m_HookState = HOOK_IDLE; - } - } - CCharacter *pLocalChar = m_GameWorld.GetCharacterByID(m_Snap.m_LocalClientID); CCharacter *pDummyChar = 0; if(PredictDummy()) @@ -2445,14 +2427,6 @@ void CGameClient::UpdatePrediction() m_GameWorld.NetObjAdd(EntData.m_Item.m_ID, EntData.m_Item.m_Type, EntData.m_pData, EntData.m_pDataEx); m_GameWorld.NetObjEnd(m_Snap.m_LocalClientID); - - // save the characters that are currently active - for(int i = 0; i < MAX_CLIENTS; i++) - if(CCharacter *pChar = m_GameWorld.GetCharacterByID(i)) - { - m_aLastWorldCharacters[i] = *pChar; - m_aLastWorldCharacters[i].DetachFromGameWorld(); - } } void CGameClient::UpdateRenderedCharacters() diff --git a/src/game/client/gameclient.h b/src/game/client/gameclient.h index 0da77531e..aa949b6b5 100644 --- a/src/game/client/gameclient.h +++ b/src/game/client/gameclient.h @@ -708,7 +708,6 @@ private: int m_PredictedDummyID; int m_IsDummySwapping; CCharOrder m_CharOrder; - class CCharacter m_aLastWorldCharacters[MAX_CLIENTS]; int m_SwitchStateTeam[NUM_DUMMIES]; enum diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index 62155b6f6..19076b0e3 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -305,7 +305,7 @@ void CCharacter::FireWeapon() { CCharacter *pTarget = apEnts[i]; - if((pTarget == this || (pTarget->IsAlive() && !CanCollide(pTarget->GetCID())))) + if((pTarget == this || !CanCollide(pTarget->GetCID()))) continue; // set his velocity to fast upward (for now) @@ -1110,7 +1110,6 @@ CCharacter::CCharacter(CGameWorld *pGameWorld, int ID, CNetObj_Character *pChar, m_LastJetpackStrength = 400.0f; m_Super = false; m_CanMoveInFreeze = false; - m_Alive = true; m_TeleCheckpoint = 0; m_StrongWeakID = 0; @@ -1301,7 +1300,6 @@ void CCharacter::Read(CNetObj_Character *pChar, CNetObj_DDNetCharacter *pExtende m_Core.m_JumpedTotal = m_Core.m_Jumps; m_AttackTick = pChar->m_AttackTick; m_LastSnapWeapon = pChar->m_Weapon; - m_Alive = true; SetTuneZone(GameWorld()->m_WorldConfig.m_UseTuneZones ? Collision()->IsTune(Collision()->GetMapIndex(m_Pos)) : 0); diff --git a/src/game/client/prediction/entities/character.h b/src/game/client/prediction/entities/character.h index 5c182d11b..6b3899952 100644 --- a/src/game/client/prediction/entities/character.h +++ b/src/game/client/prediction/entities/character.h @@ -63,9 +63,6 @@ public: void GiveNinja(); void RemoveNinja(); - bool IsAlive() { return m_Alive; } - - bool m_Alive; bool m_IsLocal; CTeamsCore *TeamsCore(); @@ -146,7 +143,6 @@ public: bool Match(CCharacter *pChar); void ResetPrediction(); - CCharacter() { m_Alive = false; } void SetTuneZone(int Zone); private: diff --git a/src/game/client/prediction/entities/pickup.cpp b/src/game/client/prediction/entities/pickup.cpp index f01f41729..bcf032369 100644 --- a/src/game/client/prediction/entities/pickup.cpp +++ b/src/game/client/prediction/entities/pickup.cpp @@ -13,7 +13,7 @@ void CPickup::Tick() for(int i = 0; i < Num; ++i) { CCharacter *pChr = apEnts[i]; - if(pChr && pChr->IsAlive()) + if(pChr) { if(GameWorld()->m_WorldConfig.m_IsVanilla && distance(m_Pos, pChr->m_Pos) >= 20.0f * 2) // pickup distance is shorter on vanilla due to using ClosestEntity continue; diff --git a/src/game/client/prediction/entities/projectile.cpp b/src/game/client/prediction/entities/projectile.cpp index 120ba4894..442e43c1a 100644 --- a/src/game/client/prediction/entities/projectile.cpp +++ b/src/game/client/prediction/entities/projectile.cpp @@ -90,8 +90,6 @@ void CProjectile::Tick() if( pOwnerChar && pTargetChr && - pOwnerChar->IsAlive() && - pTargetChr->IsAlive() && !pTargetChr->CanCollide(m_Owner)) { isWeaponCollide = true; diff --git a/src/game/client/prediction/entity.h b/src/game/client/prediction/entity.h index 426a6f283..88e48e387 100644 --- a/src/game/client/prediction/entity.h +++ b/src/game/client/prediction/entity.h @@ -70,7 +70,6 @@ public: m_SnapTicks = 0; m_MarkedForDestroy = false; } - void DetachFromGameWorld() { m_pGameWorld = 0; } CEntity() { diff --git a/src/game/client/prediction/gameworld.cpp b/src/game/client/prediction/gameworld.cpp index 33386feac..bb2d375f4 100644 --- a/src/game/client/prediction/gameworld.cpp +++ b/src/game/client/prediction/gameworld.cpp @@ -322,9 +322,9 @@ void CGameWorld::CreateExplosion(vec2 Pos, int Owner, int Weapon, bool NoDamage, if((int)Dmg) if((GetCharacterByID(Owner) ? !(GetCharacterByID(Owner)->m_Hit & CCharacter::DISABLE_HIT_GRENADE) : g_Config.m_SvHit || NoDamage) || Owner == pChar->GetCID()) { - if(Owner != -1 && pChar->IsAlive() && !pChar->CanCollide(Owner)) + if(Owner != -1 && !pChar->CanCollide(Owner)) continue; - if(Owner == -1 && ActivatedTeam != -1 && pChar->IsAlive() && pChar->Team() != ActivatedTeam) + if(Owner == -1 && ActivatedTeam != -1 && pChar->Team() != ActivatedTeam) continue; pChar->TakeDamage(ForceDir * Dmg * 2, (int)Dmg, Owner, Weapon); if(GetCharacterByID(Owner) ? GetCharacterByID(Owner)->m_Hit & CCharacter::DISABLE_HIT_GRENADE : !g_Config.m_SvHit || NoDamage)