From e4157a744b720fb89216640f6586a61cd44a1bd1 Mon Sep 17 00:00:00 2001 From: Zwelf Date: Thu, 5 Jan 2023 20:24:06 +0100 Subject: [PATCH] Remove unused `m_FreezeTime == -1` state Reduces code complexity. Both `g_Config.m_SvFreezeDelay`[[1]] and `GetSwitchDelay(int Index)`[[2]] can only return non-negative numbers, therefore this is currently dead code and can be removed. The last time it was possible to pass a negative number was removed in https://github.com/ddnet/ddnet/commit/561ce6466671397979ed77f0cbf368f93f33361f#diff-29ffe32916052e1066eed938021aadfeb29f855d7c63d9c1ca3350aceffb79f3L1624 [1]: https://github.com/ddnet/ddnet/blob/c8ea372d9851709c2fe4db7362bdc07d263079ff/src/engine/shared/config_variables.h#L213 [2]: https://github.com/ddnet/ddnet/blob/c8ea372d9851709c2fe4db7362bdc07d263079ff/src/game/mapitems.h#L467 --- .../client/prediction/entities/character.cpp | 15 ++++------ src/game/server/entities/character.cpp | 30 ++++++++----------- 2 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index aef21437e..9cc02f654 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -489,7 +489,7 @@ void CCharacter::GiveNinja() { m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick(); m_Core.m_aWeapons[WEAPON_NINJA].m_Got = true; - if(!m_FreezeTime) + if(m_FreezeTime > 0) m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = -1; if(m_Core.m_ActiveWeapon != WEAPON_NINJA) m_LastWeapon = m_Core.m_ActiveWeapon; @@ -952,12 +952,9 @@ void CCharacter::DDRaceTick() m_Input.m_Jump = 0; //Hook and weapons are possible in live freeze } - if(m_FreezeTime > 0 || m_FreezeTime == -1) + if(m_FreezeTime > 0) { - if(m_FreezeTime > 0) - m_FreezeTime--; - else - m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick(); + m_FreezeTime--; if(!m_CanMoveInFreeze) { m_Input.m_Direction = 0; @@ -1046,11 +1043,11 @@ bool CCharacter::Freeze(int Seconds) { if(!GameWorld()->m_WorldConfig.m_PredictFreeze) return false; - if((Seconds <= 0 || m_Core.m_Super || m_FreezeTime == -1 || m_FreezeTime > Seconds * GameWorld()->GameTickSpeed()) && Seconds != -1) + if(Seconds <= 0 || m_Core.m_Super || m_FreezeTime > Seconds * GameWorld()->GameTickSpeed()) return false; - if(m_Core.m_FreezeStart < GameWorld()->GameTick() - GameWorld()->GameTickSpeed() || Seconds == -1) + if(m_Core.m_FreezeStart < GameWorld()->GameTick() - GameWorld()->GameTickSpeed()) { - m_FreezeTime = Seconds == -1 ? Seconds : Seconds * GameWorld()->GameTickSpeed(); + m_FreezeTime = Seconds * GameWorld()->GameTickSpeed(); m_Core.m_FreezeStart = GameWorld()->GameTick(); return true; } diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 3d6f8fff5..d5e7b31d0 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -976,12 +976,12 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) } // change eyes and use ninja graphic if player is frozen - if(m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_LiveFrozen) + if(m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_Core.m_LiveFrozen) { if(Emote == EMOTE_NORMAL) Emote = (m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) ? EMOTE_PAIN : EMOTE_BLINK; - if((m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_FreezeTime == -1) && SnappingClientVersion < VERSION_DDNET_NEW_HUD) + if((m_Core.m_DeepFrozen || m_FreezeTime > 0) && SnappingClientVersion < VERSION_DDNET_NEW_HUD) Weapon = WEAPON_NINJA; } @@ -1008,8 +1008,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) } // change eyes, use ninja graphic and set ammo count if player has ninjajetpack - if(m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_Core.m_DeepFrozen && - !(m_FreezeTime > 0 || m_FreezeTime == -1) && !m_Core.m_HasTelegunGun) + if(m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_Core.m_DeepFrozen && m_FreezeTime == 0 && !m_Core.m_HasTelegunGun) { if(Emote == EMOTE_NORMAL) Emote = EMOTE_HAPPY; @@ -1023,12 +1022,12 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) Health = m_Health; Armor = m_Armor; if(m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo > 0) - AmmoCount = (!m_FreezeTime) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0; + AmmoCount = (m_FreezeTime > 0) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0; } if(GetPlayer()->IsAfk() || GetPlayer()->IsPaused()) { - if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) + if(m_FreezeTime > 0 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) Emote = EMOTE_NORMAL; else Emote = EMOTE_BLINK; @@ -1084,7 +1083,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) pCharacter->m_Weapon = Weapon; pCharacter->m_AmmoCount = AmmoCount; - if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen) + if(m_FreezeTime > 0 || m_Core.m_DeepFrozen) pCharacter->m_AmmoCount = m_Core.m_FreezeStart + g_Config.m_SvFreezeDelay * Server()->TickSpeed(); else if(Weapon == WEAPON_NINJA) pCharacter->m_AmmoCount = m_Core.m_Ninja.m_ActivationTick + g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000; @@ -1999,7 +1998,7 @@ void CCharacter::SetRescue() void CCharacter::DDRaceTick() { mem_copy(&m_Input, &m_SavedInput, sizeof(m_Input)); - m_Armor = (m_FreezeTime >= 0) ? clamp(10 - (m_FreezeTime / 15), 0, 10) : 0; + m_Armor = clamp(10 - (m_FreezeTime / 15), 0, 10); if(m_Input.m_Direction != 0 || m_Input.m_Jump != 0) m_LastMove = Server()->Tick(); @@ -2009,16 +2008,13 @@ void CCharacter::DDRaceTick() m_Input.m_Jump = 0; // Hook is possible in live freeze } - if(m_FreezeTime > 0 || m_FreezeTime == -1) + if(m_FreezeTime > 0) { - if(m_FreezeTime % Server()->TickSpeed() == Server()->TickSpeed() - 1 || m_FreezeTime == -1) + if(m_FreezeTime % Server()->TickSpeed() == Server()->TickSpeed() - 1) { GameServer()->CreateDamageInd(m_Pos, 0, (m_FreezeTime + 1) / Server()->TickSpeed(), TeamMask() & GameServer()->ClientsMaskExcludeClientVersionAndHigher(VERSION_DDNET_NEW_HUD)); } - if(m_FreezeTime > 0) - m_FreezeTime--; - else - m_Core.m_Ninja.m_ActivationTick = Server()->Tick(); + m_FreezeTime--; m_Input.m_Direction = 0; m_Input.m_Jump = 0; m_Input.m_Hook = 0; @@ -2137,12 +2133,12 @@ void CCharacter::DDRacePostCoreTick() bool CCharacter::Freeze(int Seconds) { - if((Seconds <= 0 || m_Core.m_Super || m_FreezeTime == -1 || m_FreezeTime > Seconds * Server()->TickSpeed()) && Seconds != -1) + if(Seconds <= 0 || m_Core.m_Super || m_FreezeTime > Seconds * Server()->TickSpeed()) return false; - if(m_Core.m_FreezeStart < Server()->Tick() - Server()->TickSpeed() || Seconds == -1) + if(m_Core.m_FreezeStart < Server()->Tick() - Server()->TickSpeed()) { m_Armor = 0; - m_FreezeTime = Seconds == -1 ? Seconds : Seconds * Server()->TickSpeed(); + m_FreezeTime = Seconds * Server()->TickSpeed(); m_Core.m_FreezeStart = Server()->Tick(); return true; }