]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/strafehud.qc
Transifex autosync
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / strafehud.qc
index e4a91d42e059be3bcf2084e9ca5b6782addd2826..e4e339c44a53497c54e60485d00ce88b23468134 100644 (file)
@@ -2,13 +2,15 @@
 
 #include "strafehud.qh"
 
-#include <client/autocvars.qh>
-#include <client/miscfunctions.qh>
+#include <client/draw.qh>
+#include <client/hud/panel/racetimer.qh>
+#include <client/view.qh>
 #include <common/animdecide.qh>
 #include <common/ent_cs.qh>
 #include <common/mapinfo.qh>
 #include <common/physics/movetypes/movetypes.qh>
 #include <common/physics/player.qh>
+#include <common/resources/cl_resources.qh>
 #include <lib/csqcmodel/cl_player.qh>
 
 // StrafeHUD (#25)
@@ -35,12 +37,6 @@ bool state_fwd_prev = true;
 float state_fwd_time = 0;
 float starttime = 0;
 float startspeed = -1;
-float jumptime = 0;
-float jumpheight = -1;
-float jumpheight_persistent = -1;
-float jumpheight_prev = 0;
-float jumpspeed_prev = 0;
-bool  jumprestart = true;
 
 // provide basic panel cvars to old clients
 // TODO remove them after a future release (0.8.2+)
@@ -63,7 +59,7 @@ void HUD_StrafeHUD()
     {
         if(!autocvar_hud_panel_strafehud ||
            (spectatee_status == -1 && (autocvar_hud_panel_strafehud == 1 || autocvar_hud_panel_strafehud == 3)) ||
-           (autocvar_hud_panel_strafehud == 3 && !(ISGAMETYPE(RACE) || ISGAMETYPE(CTS)))) return;
+           (autocvar_hud_panel_strafehud == 3 && !MUTATOR_CALLHOOK(HUD_StrafeHUD_showoptional))) return;
     }
 
     HUD_Panel_LoadCvars();
@@ -104,6 +100,7 @@ void HUD_StrafeHUD()
         bool   onground                      = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR);
         bool   strafekeys;
         bool   swimming                      = strafeplayer.waterlevel >= WATERLEVEL_SWIMMING;
+        bool   spectating                    = entcs_GetSpecState(strafeplayer.sv_entnum) == ENTCS_SPEC_PURE;
         float  speed                         = !autocvar__hud_configure ? vlen(vec2(csqcplayer.velocity)) : 1337; // use local csqcmodel entity for this even when spectating, flickers too much otherwise
         float  maxspeed_crouch_mod           = IS_DUCKED(strafeplayer) && !swimming ? .5 : 1;
         float  maxspeed_water_mod            = swimming ? .7 : 1; // very simplified water physics, the hud will not work well (and is not supposed to) while swimming
@@ -121,8 +118,6 @@ void HUD_StrafeHUD()
         int    mode                          = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0;
         float  speed_conversion_factor       = GetSpeedUnitFactor(autocvar_hud_panel_strafehud_unit);
         float  length_conversion_factor      = GetLengthUnitFactor(autocvar_hud_panel_strafehud_unit);
-        string speed_unit                    = GetSpeedUnit(autocvar_hud_panel_strafehud_unit);
-        string length_unit                   = GetLengthUnit(autocvar_hud_panel_strafehud_unit);
         int    length_decimals               = autocvar_hud_panel_strafehud_unit >= 3 && autocvar_hud_panel_strafehud_unit <= 5 ? 6 : 2; // use more decimals when displaying km or miles
         float  antiflicker_angle             = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
         float  antiflicker_speed             = max(0, autocvar_hud_panel_strafehud_antiflicker_speed);
@@ -571,6 +566,7 @@ void HUD_StrafeHUD()
             }
         }
 
+        // experimental: slick detector
         slickdetector_height = panel_size.y * bound(0, autocvar_hud_panel_strafehud_slickdetector_height, 0.5);
         if(autocvar_hud_panel_strafehud_slickdetector_range > 0 && autocvar_hud_panel_strafehud_slickdetector_alpha > 0 && slickdetector_height > 0 && panel_size.x > 0) // dunno if slick detection works in spectate
         {
@@ -643,6 +639,7 @@ void HUD_StrafeHUD()
             {
                 vector startspeed_size = panel_size;
                 startspeed_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_startspeed_size, 5);
+                string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit);
                 drawstring_aspect(panel_pos + eY * panel_size.y, strcat(ftos_decimals(startspeed * speed_conversion_factor, 2), autocvar_hud_panel_strafehud_unit_show ? speed_unit : ""), startspeed_size, autocvar_hud_panel_strafehud_startspeed_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
             }
         }
@@ -653,58 +650,34 @@ void HUD_StrafeHUD()
         }
 
         // show height achieved by a single jump
-        if(autocvar_hud_panel_strafehud_jumpheight_fade > 0)
+        if(autocvar_hud_panel_strafehud_jumpheight_fade > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
         {
-            float text_alpha = 0;
-            float jumpheight_min = max(autocvar_hud_panel_strafehud_jumpheight_min * length_conversion_factor, 0);
-            float jumpheight_current = strafeplayer.origin.z;
-            float jumpspeed_current = strafeplayer.velocity.z;
-            if(jumpspeed_prev <= jumpspeed_current || jumpheight_prev > jumpheight_current || IS_ONGROUND(strafeplayer) || swimming || IS_DEAD(strafeplayer))
+            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) || IS_ONGROUND(strafeplayer) || swimming || IS_DEAD(strafeplayer) || spectating)
             {
-                jumprestart = true;
+                height_min = height_max = strafeplayer.origin.z;
             }
-            else
+            else if(strafeplayer.origin.z > height_max)
             {
-                if(jumpheight < 0 || jumprestart)
-                {
-                    jumprestart = false;
-                    jumpheight = 0;
-                    // this reduces accuracy a little bit but prevents all kind of bugs from carryover values at connect or when dying
-                    jumpheight_prev = jumpheight_current;
-                    jumpspeed_prev = jumpspeed_current;
-                }
-                else
-                {
-                    jumpheight += jumpheight_current - jumpheight_prev;
-                }
-                if(jumpheight > jumpheight_min && jumpheight > jumpheight_persistent)
-                {
+                height_max = strafeplayer.origin.z;
+                jumpheight = (height_max - height_min) * length_conversion_factor;
+
+                if(jumpheight > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
                     jumptime = time;
-                    jumpheight_persistent = jumpheight;
-                }
-            }
-            jumpheight_prev = jumpheight_current;
-            jumpspeed_prev = jumpspeed_current;
-            if(jumpheight_persistent > 0)
-            {
-                text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
-                if((time - jumptime) > autocvar_hud_panel_strafehud_jumpheight_fade)
-                {
-                    jumpheight_persistent = -1;
-                }
             }
-            if(jumpheight_persistent > 0 && text_alpha > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
+
+            if((time - jumptime) <= autocvar_hud_panel_strafehud_jumpheight_fade)
             {
+                float text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
                 vector jumpheight_size = panel_size;
                 jumpheight_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_jumpheight_size, 5);
-                drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight_persistent * length_conversion_factor, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit);
+                drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
             }
         }
-        else
-        {
-            jumpheight_prev = jumpspeed_prev = 0;
-            jumpheight = jumpheight_persistent = -1;
-        }
         draw_endBoldFont();
 
         if(speed < (maxspeed + antiflicker_speed) && !immobile)