]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
strafehud: simplify/improve some of the new functions
authorJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Mon, 2 Sep 2024 17:25:38 +0000 (19:25 +0200)
committerJuhu <5894800-Juhu_@users.noreply.gitlab.com>
Mon, 2 Sep 2024 17:39:20 +0000 (19:39 +0200)
qcsrc/client/hud/panel/strafehud.qc
qcsrc/client/hud/panel/strafehud/core.qc
qcsrc/client/hud/panel/strafehud/draw.qc
qcsrc/client/hud/panel/strafehud/util.qc
qcsrc/client/hud/panel/strafehud/util.qh

index 44b6ec0cecba0c276afc21ed084b0ae54bdd5269..de1e8af0021c4a40c703f8a2ac19f004758149b4 100644 (file)
@@ -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);
index 9b0c7b76013d5b98da71dae53af7c69c921be40c..ebf0875a8ccb3ecd3d3157b2ade1b09b41480e3a 100644 (file)
@@ -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,
index 8615406ae8dd189cd4a7bd98621ddc43b6959b0d..91bd964d31972fd40c4cdd5cc3b953f4712d25f4 100644 (file)
@@ -3,17 +3,10 @@
 #include <client/draw.qh>
 
 // 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;
index aa36d2f41e17fe6a0d38d6956afc6f75b3d76377..1d712892c5298934fdac57403a19388078e9d9cc 100644 (file)
@@ -4,9 +4,14 @@
 #include <common/physics/player.qh>
 #include <common/physics/movetypes/movetypes.qh>
 
+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;
+}
index d77712847e4ebf2118fd15af77bacde5c1423703..3fab9a04eb0b064fbb544c099ab72b013b4f4ecd 100644 (file)
@@ -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);