]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: make anti flicker values configurable
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 21 Jun 2020 18:07:21 +0000 (20:07 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Sun, 21 Jun 2020 18:07:21 +0000 (20:07 +0200)
_hud_common.cfg
qcsrc/client/autocvars.qh
qcsrc/client/hud/panel/strafehud.qc

index 9320b5bc77237d515ebeeccd1d7569913fa6392e..51874c07df7baee33cdb2bfe78c9d0216e16c7a0 100644 (file)
@@ -132,7 +132,7 @@ seta hud_panel_strafehud_bar_color "1 1 1" "color of the strafe meter"
 seta hud_panel_strafehud_indicators "1" "show the strafe indicators"
 seta hud_panel_strafehud_indicator_color "0 1 0" "color of the strafe angle indicator"
 seta hud_panel_strafehud_indicator_switch_color "1 1 0" "color of the strafe angle indicator on the opposite side"
-seta hud_panel_strafehud_indicator_minspeed "-1" "minimum speed at which strafe angle indicators will be shown, uses physics maxspeed if negative"
+seta hud_panel_strafehud_indicator_minspeed "-1" "minimum speed in qu/s at which strafe angle indicators will be shown, uses physics maxspeed if negative"
 seta hud_panel_strafehud_angle "0" "the maximum angle displayed on the strafehud, \"0\" = dynamic"
 seta hud_panel_strafehud_good_color "0 1 1" "indicator color of the actual strafe angle if the angle matches the ideal angle"
 seta hud_panel_strafehud_warning_color "1 1 0" "indicator color of the actual strafe angle if the angle doesn't match the ideal angle"
@@ -144,6 +144,8 @@ seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before
 seta hud_panel_strafehud_timeout_strafe "0.1" "time after releasing the strafe keys before changing mode (prevents flickering when switching between left/right strafe turning)"
 seta hud_panel_strafehud_timeout_direction "0.5" "time it takes until direction changes (forward or backward strafe) are detected"
 seta hud_panel_strafehud_unstyled "0" "don't apply any progressbar styles to the strafehud"
+seta hud_panel_strafehud_antiflicker_angle "0.01" "how many degrees from 0° to 180° the hud ignores if it could cause visual disturbances otherwise"
+seta hud_panel_strafehud_antiflicker_speed "0.0001" "how many qu/s the hud ignores if it could cause visual disturbances otherwise"
 
 // hud panel aliases
 alias quickmenu "cl_cmd hud quickmenu ${* ?}"
index 3c3be484e5bb99d759b4df025ca0a13fb6fcb584..ff7058e4cde40cdfb67158d02b3c86fbf08fad19 100644 (file)
@@ -342,6 +342,8 @@ float autocvar_hud_panel_strafehud_timeout_ground = 0.03333333;
 float autocvar_hud_panel_strafehud_timeout_strafe = 0.1;
 float autocvar_hud_panel_strafehud_timeout_direction = 0.5;
 bool autocvar_hud_panel_strafehud_unstyled = false;
+float autocvar_hud_panel_strafehud_antiflicker_angle = 0.01;
+float autocvar_hud_panel_strafehud_antiflicker_speed = 0.0001;
 bool autocvar_hud_panel_timer;
 bool autocvar_hud_panel_timer_increment;
 float autocvar_hud_panel_update_interval;
index c9664f9ba1d80343f73c6bb1ca18d32ad9b9c84a..d8117be7dd988e5ad8450cf74e3d4aae756ec40f 100644 (file)
@@ -103,6 +103,8 @@ void HUD_StrafeHUD()
 
         // HUD
         int    mode                          = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0;
+        float  antiflicker_angle             = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180);
+        float  antiflicker_speed             = max(0, autocvar_hud_panel_strafehud_antiflicker_speed);
         float  minspeed;
         bool   straight_overturn             = false;
         float  hudangle;
@@ -286,11 +288,11 @@ void HUD_StrafeHUD()
         }
         if(turn)
         {
-            maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no crouching here because it doesn't affect air strafing
+            maxspeed = PHYS_MAXAIRSTRAFESPEED(strafeplayer); // no modifiers here because they don't affect air strafing
             wishangle = turnangle;
         }
 
-        minspeed = autocvar_hud_panel_strafehud_indicator_minspeed < 0 ? maxspeed + .1 : autocvar_hud_panel_strafehud_indicator_minspeed;
+        minspeed = autocvar_hud_panel_strafehud_indicator_minspeed < 0 ? maxspeed + antiflicker_speed : autocvar_hud_panel_strafehud_indicator_minspeed;
         show_indicators = (autocvar_hud_panel_strafehud_indicators && (speed >= minspeed));
 
         // get current strafing angle ranging from -180° to +180°
@@ -357,8 +359,8 @@ void HUD_StrafeHUD()
                     else angle -= 180;
                 }
 
-                // making the hud less flickery in case of rounding errors
-                if(angle > 179.9 || angle < -179.9)
+                // don't make the angle indicator switch side too much at ±180° if anti flicker is turned on
+                if(angle > (180 - antiflicker_angle) || angle < (-180 + antiflicker_angle))
                 {
                     straight_overturn = true;
                 }
@@ -413,7 +415,7 @@ void HUD_StrafeHUD()
         }
         else
         {
-            direction = (angle > .1 && angle < 179.9) ? 1 : angle < -.1 && angle > -179.9 ? -1 : 0; // little margin to prevent the direction caps from flickering between left and right
+            direction = (angle > antiflicker_angle && angle < (180 - antiflicker_angle)) ? 1 : (angle < -antiflicker_angle && angle > (-180 + antiflicker_angle)) ? -1 : 0;
         }
 
         // decelerating at this angle
@@ -581,7 +583,7 @@ void HUD_StrafeHUD()
             }
         }
 
-        if(speed < (maxspeed + .1) && speed > 0)
+        if(speed < (maxspeed + antiflicker_speed) && speed > 0)
         {
             bestangle_anywhere = true; // moving forward should suffice to gain speed
         }