From aeee2f561d4f4d0e2c3320a1c16033ad31291ff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Jul 2024 22:02:06 +0200 Subject: [PATCH 1/4] Remove dead code and obsolete TODO It seems unlikely we that would want to introduce a variable to tweak the hook behavior at this point, so the TODO is removed. --- src/game/gamecore.cpp | 11 +---------- src/game/gamecore.h | 1 - 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 0f37382b0..1ad98da05 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -332,8 +332,6 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) int teleNr = 0; int Hit = m_pCollision->IntersectLineTeleHook(m_HookPos, NewPos, &NewPos, 0, &teleNr); - // m_NewHook = false; - if(Hit) { if(Hit == TILE_NOHOOK) @@ -418,10 +416,6 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) m_HookState = HOOK_RETRACTED; m_HookPos = m_Pos; } - - // keep players hooked for a max of 1.5sec - // if(Server()->Tick() > hook_tick+(Server()->TickSpeed()*3)/2) - // release_hooked(); } // don't do this hook routine when we are already hooked to a player @@ -471,9 +465,6 @@ void CCharacterCore::TickDeferred() if(!pCharCore) continue; - // player *p = (player*)ent; - // if(pCharCore == this) // || !(p->flags&FLAG_ALIVE) - if(pCharCore == this || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, i))) continue; // make sure that we don't nudge our self @@ -505,7 +496,7 @@ void CCharacterCore::TickDeferred() // handle hook influence if(!m_HookHitDisabled && m_HookedPlayer == i && m_Tuning.m_PlayerHooking) { - if(Distance > PhysicalSize() * 1.50f) // TODO: fix tweakable variable + if(Distance > PhysicalSize() * 1.50f) { float HookAccel = m_Tuning.m_HookDragAccel * (Distance / m_Tuning.m_HookLength); float DragSpeed = m_Tuning.m_HookDragSpeed; diff --git a/src/game/gamecore.h b/src/game/gamecore.h index 0e7b405a3..c33b14e17 100644 --- a/src/game/gamecore.h +++ b/src/game/gamecore.h @@ -120,7 +120,6 @@ enum COREEVENT_HOOK_ATTACH_GROUND = 0x10, COREEVENT_HOOK_HIT_NOHOOK = 0x20, COREEVENT_HOOK_RETRACT = 0x40, - // COREEVENT_HOOK_TELE=0x80, }; // show others values - do not change them From 998adfcefcf5c269a7174b87e767228adc42dfc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Jul 2024 22:18:14 +0200 Subject: [PATCH 2/4] Remove redundant distance checks The check `Distance > 0.0f` is redundant because the same check already exists in the outer if-statement and the variable `Distance` is never modified. The check `D >= 0.0f` is redundant because mathematically any distance is greater or equal to zero. --- src/game/gamecore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 1ad98da05..2481364ed 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -479,7 +479,7 @@ void CCharacterCore::TickDeferred() bool CanCollide = (m_Super || pCharCore->m_Super) || (!m_CollisionDisabled && !pCharCore->m_CollisionDisabled && m_Tuning.m_PlayerCollision); - if(CanCollide && Distance < PhysicalSize() * 1.25f && Distance > 0.0f) + if(CanCollide && Distance < PhysicalSize() * 1.25f) { float a = (PhysicalSize() * 1.45f - Distance); float Velocity = 0.5f; @@ -580,7 +580,7 @@ void CCharacterCore::Move() if((!(pCharCore->m_Super || m_Super) && (m_Solo || pCharCore->m_Solo || pCharCore->m_CollisionDisabled || (m_Id != -1 && !m_pTeams->CanCollide(m_Id, p))))) continue; float D = distance(Pos, pCharCore->m_Pos); - if(D < PhysicalSize() && D >= 0.0f) + if(D < PhysicalSize()) { if(a > 0.0f) m_Pos = LastPos; From 660c1de8f29e4ef77f5ce1442cf1a4ce0a147700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Jul 2024 22:22:55 +0200 Subject: [PATCH 3/4] Remove unnecessary use of `this` The same variable `m_HookHitDisabled` is also being accessed without `this`. --- src/game/gamecore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 2481364ed..9bf36d98f 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -344,7 +344,7 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) } // Check against other players first - if(!this->m_HookHitDisabled && m_pWorld && m_Tuning.m_PlayerHooking && (m_HookState == HOOK_FLYING || !m_NewHook)) + if(!m_HookHitDisabled && m_pWorld && m_Tuning.m_PlayerHooking && (m_HookState == HOOK_FLYING || !m_NewHook)) { float Distance = 0.0f; for(int i = 0; i < MAX_CLIENTS; i++) From 7cbfe1623d555049a950a24a018894cfff4f1144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 9 Jul 2024 22:34:29 +0200 Subject: [PATCH 4/4] Avoid duplicate distance calculation Add variable `NewVelLength` to avoid calculating `length(NewVel)` twice. --- src/game/gamecore.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 9bf36d98f..042e64579 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -437,7 +437,8 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) vec2 NewVel = m_Vel + HookVel; // check if we are under the legal limit for the hook - if(length(NewVel) < m_Tuning.m_HookDragSpeed || length(NewVel) < length(m_Vel)) + const float NewVelLength = length(NewVel); + if(NewVelLength < m_Tuning.m_HookDragSpeed || NewVelLength < length(m_Vel)) m_Vel = NewVel; // no problem. apply }