From cff01c68b41a92a81a5f072c26619bb0059dcba8 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Tue, 23 Jun 2020 03:05:51 +0200 Subject: [PATCH] strafehud: add timeout values for left/right strafe to account for more variations of strafing --- _hud_common.cfg | 3 ++- qcsrc/client/autocvars.qh | 3 ++- qcsrc/client/hud/panel/strafehud.qc | 29 ++++++++++++++++++++++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 6e57f5b7e..201f19b5d 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -146,7 +146,8 @@ seta hud_panel_strafehud_direction_width "0.0075" "direction indicator width" seta hud_panel_strafehud_timeout_air "0" "time after take off before changing strafehud mode (prevents flickering on slick ramps)" seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before changing strafehud mode (prevents flickering on regular strafe turns)" 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_timeout_fwd_bkwd "0.5" "time it takes until direction changes (forward or backward movement) are detected" +seta hud_panel_strafehud_timeout_left_right "0" "time it takes until direction changes (left or right movement) 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" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 9361f2bd7..4ed427baa 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -344,7 +344,8 @@ float autocvar_hud_panel_strafehud_direction_width = 0.0075; float autocvar_hud_panel_strafehud_timeout_air = 0; 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; +float autocvar_hud_panel_strafehud_timeout_fwd_bkwd = 0.5; +float autocvar_hud_panel_strafehud_timeout_left_right = 0; 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; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 689417bd4..7cdae87b8 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -21,11 +21,15 @@ void HUD_StrafeHUD_Export(int fh) bool fwd = true; bool state_fwd = true; bool state_fwd_prev = true; +int direction = 0; +bool state_direction = true; +bool state_direction_prev = true; float demo_angle = -37; float demo_direction = 1; float demo_time = 0; float state_onground_time = 0; float state_strafekeys_time = 0; +float state_fwd_time = 0; float state_direction_time = 0; bool state_onground = false; bool state_strafekeys = false; @@ -94,7 +98,6 @@ void HUD_StrafeHUD() float vel_angle = vectoangles(strafeplayer.velocity).y; float view_angle = view_angles.y + 180; float angle; - float direction; vector movement = PHYS_INPUT_MOVEVALUES(strafeplayer); int keys = STAT(PRESSED_KEYS); int keys_fwd; @@ -343,11 +346,11 @@ void HUD_StrafeHUD() if(state_fwd_prev != state_fwd) { - state_direction_time = time; + state_fwd_time = time; } state_fwd_prev = state_fwd; - if((time - state_direction_time) >= autocvar_hud_panel_strafehud_timeout_direction || speed < maxspeed) // timeout when changing between forwards and backwards strafe + if((time - state_fwd_time) >= autocvar_hud_panel_strafehud_timeout_fwd_bkwd || speed < maxspeed) // timeout when changing between forwards and backwards movement { fwd = state_fwd; } @@ -409,13 +412,29 @@ void HUD_StrafeHUD() moveangle = angle + wishangle; + // determine whether the player is strafing left or right if(wishangle != 0) { - direction = wishangle > 0 ? 1 : -1; + state_direction = wishangle > 0 ? 1 : -1; } else { - direction = (angle > antiflicker_angle && angle < (180 - antiflicker_angle)) ? 1 : (angle < -antiflicker_angle && angle > (-180 + antiflicker_angle)) ? -1 : 0; + state_direction = (angle > antiflicker_angle && angle < (180 - antiflicker_angle)) ? 1 : (angle < -antiflicker_angle && angle > (-180 + antiflicker_angle)) ? -1 : 0; + } + + if(state_direction_prev != state_direction) + { + state_direction_time = time; + } + state_direction_prev = state_direction; + + if((time - state_direction_time) >= autocvar_hud_panel_strafehud_timeout_left_right || speed < maxspeed || direction == 0) // timeout when changing between left and right movement + { + direction = state_direction; + } + if(direction != 0) + { + wishangle = direction * fabs(wishangle); } // decelerating at this angle -- 2.39.2