]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: move forward/backward keys detection into separate function
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 27 Sep 2024 23:01:57 +0000 (01:01 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Fri, 27 Sep 2024 23:01:57 +0000 (01:01 +0200)
qcsrc/client/hud/panel/strafehud.qc
qcsrc/client/hud/panel/strafehud/util.qc
qcsrc/client/hud/panel/strafehud/util.qh

index 6d6198a1c3e629025cf9014ee58b4b56c50da328..62d16bca13b3b9401ab66e2ce2590af29432e450 100644 (file)
@@ -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;
index efd9d7b5bb3538bfeab68c4ccad210e3731b7827..5de6b0ae3a65fa0fa18d260d4e9c9be97542baee 100644 (file)
@@ -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)
 {
 
index b3a73e094d41391677ee835ed38e9d75984443d8..4aeb595e899ba4d507762d87e047a064fdda776f 100644 (file)
@@ -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);