From 6685acd9cb49e8df4242695f0e7f82c9b60b9e33 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sun, 21 Jun 2020 20:07:21 +0200 Subject: [PATCH] strafehud: make anti flicker values configurable --- _hud_common.cfg | 4 +++- qcsrc/client/autocvars.qh | 2 ++ qcsrc/client/hud/panel/strafehud.qc | 14 ++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 9320b5bc7..51874c07d 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -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 ${* ?}" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 3c3be484e..ff7058e4c 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -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; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index c9664f9ba..d8117be7d 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -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 } -- 2.39.2