From 839178dbb23526a5d7f43f3dc2dbd88a00b2d78c Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sat, 28 Sep 2024 01:01:57 +0200 Subject: [PATCH] strafehud: move forward/backward keys detection into separate function --- qcsrc/client/hud/panel/strafehud.qc | 22 +--------------------- qcsrc/client/hud/panel/strafehud/util.qc | 23 +++++++++++++++++++++++ qcsrc/client/hud/panel/strafehud/util.qh | 1 + 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 6d6198a1c..62d16bca1 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -139,27 +139,7 @@ void HUD_StrafeHUD() else movespeed = min(movespeed, maxspeed); - // determine whether the player is pressing forwards or backwards keys - int keys_fwd; - if(islocal) // if entity is local player - { - if(movement.x > 0) - keys_fwd = STRAFEHUD_KEYS_FORWARD; - else if(movement.x < 0) - keys_fwd = STRAFEHUD_KEYS_BACKWARD; - else - keys_fwd = STRAFEHUD_KEYS_NONE; - } - else // alternatively determine direction by querying pressed keys - { - if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD)) - keys_fwd = STRAFEHUD_KEYS_FORWARD; - else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD)) - keys_fwd = STRAFEHUD_KEYS_BACKWARD; - else - keys_fwd = STRAFEHUD_KEYS_NONE; - } - + int keys_fwd = StrafeHUD_DetermineForwardKeys(movement, keys, islocal); float wishangle = StrafeHUD_DetermineWishAngle(movement, keys, islocal); float absolute_wishangle = fabs(wishangle); // unmodified by side strafing code bool strafekeys = fabs(wishangle) > 45; diff --git a/qcsrc/client/hud/panel/strafehud/util.qc b/qcsrc/client/hud/panel/strafehud/util.qc index efd9d7b5b..5de6b0ae3 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qc +++ b/qcsrc/client/hud/panel/strafehud/util.qc @@ -213,6 +213,29 @@ float StrafeHUD_DetermineWishAngle(vector movement, int keys, bool islocal) return wishangle; } +// determine whether the player is pressing forwards or backwards keys +int StrafeHUD_DetermineForwardKeys(vector movement, int keys, bool islocal) +{ + if(islocal) // if entity is local player + { + if(movement.x > 0) + return STRAFEHUD_KEYS_FORWARD; + else if(movement.x < 0) + return STRAFEHUD_KEYS_BACKWARD; + else + return STRAFEHUD_KEYS_NONE; + } + else // alternatively determine direction by querying pressed keys + { + if((keys & KEY_FORWARD) && !(keys & KEY_BACKWARD)) + return STRAFEHUD_KEYS_FORWARD; + else if(!(keys & KEY_FORWARD) && (keys & KEY_BACKWARD)) + return STRAFEHUD_KEYS_BACKWARD; + else + return STRAFEHUD_KEYS_NONE; + } +} + float StrafeHUD_DetermineHudAngle(float absolute_wishangle, float absolute_overturnangle, float strafity) { diff --git a/qcsrc/client/hud/panel/strafehud/util.qh b/qcsrc/client/hud/panel/strafehud/util.qh index b3a73e094..4aeb595e8 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qh +++ b/qcsrc/client/hud/panel/strafehud/util.qh @@ -11,6 +11,7 @@ string StrafeHUD_GetLengthUnit(int); float StrafeHUD_DetermineWaterLevel(entity); float StrafeHUD_DetermineFrameTime(); float StrafeHUD_DetermineWishAngle(vector, int, bool); +int StrafeHUD_DetermineForwardKeys(vector, int, bool); float StrafeHUD_DetermineHudAngle(float, float, float); float StrafeHUD_DetermineDirection(float, float, float); bool StrafeHUD_DetermineJumpHeld(entity, int, bool); -- 2.39.2