From 8bcee1e504833684b15ad77dbe198bddef8450a9 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Sat, 8 Oct 2022 00:57:20 +0200 Subject: [PATCH] strafehud: more code clean up, make jump height indicator work while spectating and remove deprecated include --- qcsrc/client/hud/panel/strafehud.qc | 45 +++++++++++++++++------------ qcsrc/client/hud/panel/strafehud.qh | 4 +++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 2df95ffd3..cd31314d9 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -3,15 +3,22 @@ #include "strafehud.qh" #include -#include -#include -#include -#include -#include -#include -#include -#include #include +#include +#include + +// non-essential +#include // for v_flipped state + +// non-local players +#include // anim_implicit_state +#include // CSQCModel_server2csqc() + +// start speed +#include // checkpoint information (race_*) + +// jump height +#include // IS_DEAD() macro // StrafeHUD (#25) @@ -72,7 +79,7 @@ void HUD_StrafeHUD() { float strafe_waterlevel; - // get the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled + // check the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled { // store old values void old_contentstransition(int, int) = strafeplayer.contentstransition; @@ -89,7 +96,7 @@ void HUD_StrafeHUD() strafeplayer.waterlevel = old_waterlevel; } - // presistent + // persistent static float onground_lasttime = 0; static float turn_lasttime = 0; static bool turn = false; @@ -103,12 +110,12 @@ void HUD_StrafeHUD() int keys = STAT(PRESSED_KEYS); bool jumpheld = islocal ? (PHYS_INPUT_BUTTON_JUMP(strafeplayer) || PHYS_INPUT_BUTTON_JETPACK(strafeplayer)) : (keys & KEY_JUMP); // doesn't work in spectator mode if spectated player uses +jetpack bool onground = (islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR)) && !jumpheld; // if jump is held assume we are in air + bool real_onground = onground; // doesn't get changed by ground timeout bool onground_expired; bool strafekeys; bool swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING; // the hud will not work well while 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_mod = IS_DUCKED(csqcplayer) ? .5 : 1; + float maxspeed_mod = IS_DUCKED(csqcplayer) ? .5 : 1; // only the local csqcplayer entity contains this information even when spectating float maxspeed_phys = onground ? PHYS_MAXSPEED(strafeplayer) : PHYS_MAXAIRSPEED(strafeplayer); float maxspeed = !autocvar__hud_configure ? maxspeed_phys * maxspeed_mod : 320; float movespeed; @@ -597,11 +604,11 @@ void HUD_StrafeHUD() switch(autocvar_hud_panel_strafehud_style) { default: - case 0: + case STRAFEHUD_STYLE_DRAWFILL: drawfill(panel_pos, panel_size, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); break; - case 1: + case STRAFEHUD_STYLE_PROGRESSBAR: HUD_Panel_DrawProgressBar(panel_pos, panel_size, "progressbar", 1, 0, 0, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } } @@ -781,7 +788,7 @@ void HUD_StrafeHUD() currentangle_offset = panel_size.x/2; } - if(autocvar_hud_panel_strafehud_style == 2 && !immobile) + if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT && !immobile) { float moveangle = angle + wishangle; float strafeangle = bestangle + wishangle; @@ -825,14 +832,14 @@ void HUD_StrafeHUD() switch(autocvar_hud_panel_strafehud_angle_style) { - case 1: + case STRAFEHUD_INDICATOR_SOLID: if(currentangle_size.x > 0 && currentangle_size.y > 0) { if(autocvar_hud_panel_strafehud_bestangle && direction != STRAFEHUD_DIRECTION_NONE) drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (ghost_offset - currentangle_size.x/2), currentangle_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); } break; - case 2: + case STRAFEHUD_INDICATOR_DASHED: if(currentangle_size.x > 0 && currentangle_size.y > 0) { vector line_size = currentangle_size; @@ -845,7 +852,7 @@ void HUD_StrafeHUD() } } break; - case 0: + case STRAFEHUD_INDICATOR_NONE: default: // don't offset text and arrows if the angle indicator line isn't drawn angleheight_offset = panel_size.y; @@ -918,7 +925,7 @@ void HUD_StrafeHUD() static float jumpheight = 0, jumptime = 0; // displayed value and timestamp for fade out // tries to catch kill and spectate but those are not reliable - if((strafeplayer.velocity.z <= 0) || IS_ONGROUND(strafeplayer) || swimming || IS_DEAD(strafeplayer) || spectating) + if((strafeplayer.velocity.z <= 0) || real_onground || swimming || IS_DEAD(strafeplayer) || !IS_PLAYER(strafeplayer)) { height_min = height_max = strafeplayer.origin.z; } diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index c170cf2d4..b351f936a 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -82,3 +82,7 @@ const int STRAFEHUD_GRADIENT_NONE = 0; const int STRAFEHUD_GRADIENT_LEFT = 1; const int STRAFEHUD_GRADIENT_RIGHT = 2; const int STRAFEHUD_GRADIENT_BOTH = 3; + +const int STRAFEHUD_INDICATOR_NONE = 0; +const int STRAFEHUD_INDICATOR_SOLID = 1; +const int STRAFEHUD_INDICATOR_DASHED = 2; -- 2.39.2