]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: make jump height feature more reliable
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 10 Jul 2022 14:10:42 +0000 (16:10 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 10 Jul 2022 14:59:53 +0000 (16:59 +0200)
qcsrc/client/hud/panel/strafehud.qc

index 99c02029665f3578f120bc4f96944f783c1c9056..514c2f19d1fe44e82676ef63e9d5b47222e56a9b 100644 (file)
@@ -860,23 +860,28 @@ void HUD_StrafeHUD()
         }
 
         // show height achieved by a single jump
+        // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc) but using velocity to calculate jump height would be
+        //        inaccurate in hud code (possibly different tick rate, doesn't run when hud isn't drawn, rounding errors)
         if(autocvar_hud_panel_strafehud_jumpheight_fade > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
         {
             static float height_min = 0, height_max = 0; // ground and peak of jump z coordinates
             static float jumpheight = 0, jumptime = 0;   // displayed value and timestamp for fade out
 
-            // tries to catch kill and spectate but those are not reliable, should just hook to kill/spectate/teleport and reset jump height there
-            if((strafeplayer.velocity.z <= 0 && height_max >= strafeplayer.origin.z) || onground || swimming || IS_DEAD(strafeplayer) || spectating)
+            // tries to catch kill and spectate but those are not reliable
+            if((strafeplayer.velocity.z <= 0) || onground || swimming || IS_DEAD(strafeplayer) || spectating)
             {
                 height_min = height_max = strafeplayer.origin.z;
             }
             else if(strafeplayer.origin.z > height_max)
             {
                 height_max = strafeplayer.origin.z;
-                jumpheight = (height_max - height_min) * length_conversion_factor;
+                float jumpheight_new = (height_max - height_min) * length_conversion_factor;
 
-                if(jumpheight > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
+                if(jumpheight_new > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
+                {
+                    jumpheight = jumpheight_new;
                     jumptime = time;
+                }
             }
 
             if((time - jumptime) <= autocvar_hud_panel_strafehud_jumpheight_fade)