From bfa4bf8093d8b7bc88038df95ab02f317d3f2cbf Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Mon, 2 Sep 2024 19:25:38 +0200 Subject: [PATCH] strafehud: simplify/improve some of the new functions --- qcsrc/client/hud/panel/strafehud.qc | 14 +------------- qcsrc/client/hud/panel/strafehud/core.qc | 16 ++++++++-------- qcsrc/client/hud/panel/strafehud/draw.qc | 13 +++---------- qcsrc/client/hud/panel/strafehud/util.qc | 24 +++++++++++++++++++++++- qcsrc/client/hud/panel/strafehud/util.qh | 2 ++ 5 files changed, 37 insertions(+), 32 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 44b6ec0ce..de1e8af00 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -68,19 +68,7 @@ void HUD_StrafeHUD() if(csqcplayer && strafeplayer) { int keys = STAT(PRESSED_KEYS); - - // try to ignore if track_canjump is enabled, does not work in spectator mode if spectated player uses +jetpack or cl_movement_track_canjump - bool jumpheld = false; - if(islocal) - { - if((PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) && !PHYS_CL_TRACK_CANJUMP(strafeplayer)) - jumpheld = true; - } - else - { - if((keys & KEY_JUMP) && !PHYS_TRACK_CANJUMP(strafeplayer)) - jumpheld = true; - } + bool jumpheld = DetectJumpHeld(strafeplayer, keys, islocal); // does not get changed by ground timeout and is not affected by jump input bool real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR); diff --git a/qcsrc/client/hud/panel/strafehud/core.qc b/qcsrc/client/hud/panel/strafehud/core.qc index 9b0c7b760..ebf0875a8 100644 --- a/qcsrc/client/hud/panel/strafehud/core.qc +++ b/qcsrc/client/hud/panel/strafehud/core.qc @@ -89,7 +89,7 @@ void StrafeHUD_DrawStrafeMeter( // draw left acceleration zone HUD_Panel_drawStrafeHUD( - accelzone_left_startangle, accelzone_left_startangle + accelzone_offsetangle, + accelzone_left_startangle, accelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT, @@ -97,7 +97,7 @@ void StrafeHUD_DrawStrafeMeter( if(autocvar_hud_panel_strafehud_bar_preaccel) HUD_Panel_drawStrafeHUD( - preaccelzone_left_startangle, preaccelzone_left_startangle + preaccelzone_offsetangle, + preaccelzone_left_startangle, preaccelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT, @@ -105,7 +105,7 @@ void StrafeHUD_DrawStrafeMeter( // draw right acceleration zone HUD_Panel_drawStrafeHUD( - accelzone_right_startangle, accelzone_right_startangle + accelzone_offsetangle, + accelzone_right_startangle, accelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_RIGHT, @@ -113,7 +113,7 @@ void StrafeHUD_DrawStrafeMeter( if(autocvar_hud_panel_strafehud_bar_preaccel) HUD_Panel_drawStrafeHUD( - preaccelzone_right_startangle, preaccelzone_right_startangle + preaccelzone_offsetangle, + preaccelzone_right_startangle, preaccelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_LEFT, @@ -124,7 +124,7 @@ void StrafeHUD_DrawStrafeMeter( // acceleration decreases at 90 degrees but speed loss happens a little bit after 90 degrees, // however due to sv_airstopaccelerate that's hard to calculate HUD_Panel_drawStrafeHUD( - overturn_startangle, overturn_startangle + 180, // overturning area spans 180° + overturn_startangle, 180, // overturning area spans 180° autocvar_hud_panel_strafehud_bar_overturn_color, autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_BOTH, @@ -132,7 +132,7 @@ void StrafeHUD_DrawStrafeMeter( // draw neutral zone HUD_Panel_drawStrafeHUD( - neutral_startangle, neutral_startangle + neutral_endangle, + neutral_startangle, neutral_endangle, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_NONE, @@ -165,7 +165,7 @@ void StrafeHUD_DrawStrafeMeter( } HUD_Panel_drawStrafeHUD( - offsetangle, offsetangle + StrafeHUD_offsetToAngle(bestangle_width, hudangle), + offsetangle, StrafeHUD_offsetToAngle(bestangle_width, hudangle), autocvar_hud_panel_strafehud_switch_color, autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha, STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, @@ -173,7 +173,7 @@ void StrafeHUD_DrawStrafeMeter( if(direction == STRAFEHUD_DIRECTION_NONE) HUD_Panel_drawStrafeHUD( - opposite_offsetangle, opposite_offsetangle + StrafeHUD_offsetToAngle(bestangle_width, hudangle), + opposite_offsetangle, StrafeHUD_offsetToAngle(bestangle_width, hudangle), autocvar_hud_panel_strafehud_switch_color, autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha, STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, diff --git a/qcsrc/client/hud/panel/strafehud/draw.qc b/qcsrc/client/hud/panel/strafehud/draw.qc index 8615406ae..91bd964d3 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qc +++ b/qcsrc/client/hud/panel/strafehud/draw.qc @@ -3,17 +3,10 @@ #include // functions to make hud elements align perfectly in the hud area -void HUD_Panel_drawStrafeHUD(float fromangle, float toangle, vector color, float alpha, int type, int gradientType, bool doProject, float range) +void HUD_Panel_drawStrafeHUD(float startangle, float offsetangle, vector color, float alpha, int type, int gradientType, bool doProject, float range) { - if(toangle < fromangle) - { - float tmp = fromangle; - fromangle = toangle; - toangle = tmp; - } - - float offset = StrafeHUD_angleToOffset(fromangle % 360, range); - float width = StrafeHUD_angleToOffset(toangle, range) - StrafeHUD_angleToOffset(fromangle, range); + float offset = StrafeHUD_angleToOffset(startangle % 360, range); + float width = StrafeHUD_angleToWidth(offsetangle, range); float mirror_offset, mirror_width; vector size = panel_size; diff --git a/qcsrc/client/hud/panel/strafehud/util.qc b/qcsrc/client/hud/panel/strafehud/util.qc index aa36d2f41..1d712892c 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qc +++ b/qcsrc/client/hud/panel/strafehud/util.qc @@ -4,9 +4,14 @@ #include #include +float StrafeHUD_angleToWidth(float angle, float range) +{ + return angle / range * panel_size.x; +} + float StrafeHUD_angleToOffset(float angle, float range) { - return angle / range * panel_size.x + panel_size.x / 2; + return StrafeHUD_angleToWidth(angle, range) + panel_size.x / 2; } float StrafeHUD_offsetToAngle(float offset, float range) @@ -266,3 +271,20 @@ float StrafeHUD_determineDirection(float angle, float wishangle, float antiflick return STRAFEHUD_DIRECTION_NONE; } } + +// try to ignore if track_canjump is enabled, does not work in spectator mode if spectated player uses +jetpack or cl_movement_track_canjump +bool DetectJumpHeld(entity e, int keys, bool islocal) +{ + if(islocal) + { + if((PHYS_INPUT_BUTTON_JUMP(e) || PHYS_INPUT_BUTTON_JETPACK(e)) && !PHYS_CL_TRACK_CANJUMP(e)) + return true; + } + else + { + if((keys & KEY_JUMP) && !PHYS_TRACK_CANJUMP(e)) + return true; + } + + return false; +} diff --git a/qcsrc/client/hud/panel/strafehud/util.qh b/qcsrc/client/hud/panel/strafehud/util.qh index d77712847..3fab9a04e 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qh +++ b/qcsrc/client/hud/panel/strafehud/util.qh @@ -7,6 +7,7 @@ float StrafeHUD_project(float, float, bool); float StrafeHUD_projectAngle(float, float, bool); float StrafeHUD_projectOffset(float, float, bool); float StrafeHUD_projectWidth(float, float, float); +float StrafeHUD_angleToWidth(float, float); float StrafeHUD_angleToOffset(float, float); float StrafeHUD_offsetToAngle(float, float); float DetectWaterLevel(entity); @@ -14,3 +15,4 @@ float DetectFrameTime(); float DetectWishAngle(vector, int, bool); float StrafeHUD_determineHudAngle(float); float StrafeHUD_determineDirection(float, float, float); +bool DetectJumpHeld(entity, int, bool); -- 2.39.2