]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: cleanup of previous commit, small refactoring and format fixes
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 11 Sep 2022 20:41:14 +0000 (22:41 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 11 Sep 2022 20:41:14 +0000 (22:41 +0200)
qcsrc/client/hud/panel/strafehud.qc

index 01a2df2047adbb9fe2dd676f64349b5a38e54f49..4b30232af35348a1d83d3740cff525e4dcc3a079 100644 (file)
@@ -85,7 +85,7 @@ void HUD_StrafeHUD()
     {
         float strafe_waterlevel;
 
-        // get the player waterlevel without affecting the player entity
+        // get the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled
         {
             // store old values
             void old_contentstransition(int, int) = strafeplayer.contentstransition;
@@ -133,7 +133,6 @@ void HUD_StrafeHUD()
         float  bestspeed;
         float  maxaccel_phys                 = onground ? PHYS_ACCELERATE(strafeplayer) : PHYS_AIRACCELERATE(strafeplayer);
         float  maxaccel                      = !autocvar__hud_configure ? maxaccel_phys : 1;
-        float  frametime_phys;
         float  vel_angle                     = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0); // change the range from 0° - 360° to -180° - 180° to match how view_angle represents angles
         float  view_angle                    = PHYS_INPUT_ANGLES(strafeplayer).y;
         float  angle;
@@ -358,7 +357,8 @@ void HUD_StrafeHUD()
                     // calculate the maximum air strafe speed and acceleration
                     float strafity = 1 - (90 - fabs(wishangle)) / 45;
 
-                    if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0){
+                    if(PHYS_MAXAIRSTRAFESPEED(strafeplayer) != 0)
+                    {
                         maxspeed = GeomLerp(PHYS_MAXAIRSPEED(strafeplayer), strafity, PHYS_MAXAIRSTRAFESPEED(strafeplayer));
                         maxspeed = min(maxspeed, PHYS_MAXAIRSPEED(strafeplayer) * maxspeed_mod);
                     }
@@ -366,7 +366,8 @@ void HUD_StrafeHUD()
                     if(turnspeed == 0) turnspeed = maxspeed;
                     else turnspeed = min(turnspeed, maxspeed);
 
-                    if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0) {
+                    if(PHYS_AIRSTRAFEACCELERATE(strafeplayer) != 0)
+                    {
                         maxaccel = GeomLerp(PHYS_AIRACCELERATE(strafeplayer), strafity, PHYS_AIRSTRAFEACCELERATE(strafeplayer));
                     }
                     turnaccel = maxaccel;
@@ -405,21 +406,25 @@ void HUD_StrafeHUD()
         }
 
         maxaccel *= strafe_dt_avg * movespeed;
-        bestspeed = max(movespeed - maxaccel, 0);
+        bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration
 
-        float strafespeed = speed; // speed minus friction
+        float frictionspeed; // speed lost from friction
+        float strafespeed; // speed minus friction
 
-        if((strafespeed > 0) && onground){
+        if((speed > 0) && onground)
+        {
             float strafefriction = IS_ONSLICK(strafeplayer) ? PHYS_FRICTION_SLICK(strafeplayer) : PHYS_FRICTION(strafeplayer);
-            float f = 1 - strafe_dt_avg * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / strafespeed, 1);
 
-            if(f <= 0)
-                strafespeed = 0;
-            else
-                strafespeed *= f;
+            frictionspeed = speed * strafe_dt_avg * strafefriction * max(PHYS_STOPSPEED(strafeplayer) / speed, 1);
+            strafespeed = max(speed - frictionspeed, 0);
+        }
+        else
+        {
+            frictionspeed = 0;
+            strafespeed = speed;
         }
 
-        minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? bestspeed + (speed - strafespeed) : autocvar_hud_panel_strafehud_switch_minspeed;
+        minspeed = autocvar_hud_panel_strafehud_switch_minspeed < 0 ? bestspeed + frictionspeed : autocvar_hud_panel_strafehud_switch_minspeed;
 
         // get current strafing angle ranging from -180° to +180°
         if(!autocvar__hud_configure)
@@ -522,7 +527,7 @@ void HUD_StrafeHUD()
 
         // best angle to strafe at
         bestangle = (strafespeed > bestspeed ? acos(bestspeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0);
-        prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0);
+        prebestangle = (strafespeed > movespeed ? acos(movespeed / strafespeed) * RAD2DEG * (direction < 0 ? -1 : 1) : 0); // in case of ground friction we may decelerate if the acceleration is smaller than the speed loss from friction
         odd_bestangle = -bestangle - wishangle;
         bestangle -= wishangle;
         prebestangle -= wishangle;
@@ -1042,7 +1047,8 @@ void HUD_Panel_DrawStrafeHUD(float offset, float width, vector color, float alph
             else if(mirror_offset == 0) gradient_start = 1;
             else gradient_start = 0;
 
-            switch(gradient_start){
+            switch(gradient_start)
+            {
                 default:
                 case 0: // no offset required
                     gradient_offset = gradient_mirror_offset = 0;