]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Center switch lines on strafehud
authorotta8634 <k9wolf@pm.me>
Sun, 1 Sep 2024 14:26:44 +0000 (22:26 +0800)
committerotta8634 <k9wolf@pm.me>
Mon, 2 Sep 2024 07:11:18 +0000 (15:11 +0800)
Previously the angle to aim at was the inner edge of the switch line,
... which is unintuitive and different to all other hud lines (eg. angle, bestangle, wturn)
This also stops calculation of angles for switch/wturn/direction if they're never going to be rendered

qcsrc/client/hud/panel/strafehud.qc

index a0147b2e7f04145f7ba327d81478425f3294377b..6ba9e4e34b4141a4cdeb3002d4d2e7b8857cac99 100644 (file)
@@ -173,12 +173,12 @@ void HUD_StrafeHUD()
                float  bestangle;
                float  prebestangle;
                float  odd_bestangle;
-               float  bestangle_offset;
-               float  switch_bestangle_offset;
+               float  bestangle_offset              = 0;
+               float  switch_bestangle_offset       = 0;
                bool   odd_angles                    = false;
                float  odd_bestangle_offset          = 0;
                float  switch_odd_bestangle_offset   = 0;
-               float  switch_bestangle_width;
+               float  switch_bestangle_width        = 0;
                float  wturn_bestangle               = 0;
                float  wturn_left_bestangle_offset   = 0;
                float  wturn_right_bestangle_offset  = 0;
@@ -192,8 +192,8 @@ void HUD_StrafeHUD()
                float  overturn_offset;
                float  overturn_width;
                float  slickdetector_height;
-               vector direction_size_vertical;
-               vector direction_size_horizontal;
+               vector direction_size_vertical       = '0 0 0';
+               vector direction_size_horizontal     = '0 0 0';
                float  range_minangle;
                float  text_offset_top               = 0;
                float  text_offset_bottom            = 0;
@@ -555,13 +555,13 @@ void HUD_StrafeHUD()
                 * ... but this very quickly loses accuracy -- should be a strictly decreasing function, yet it increases at only speed=722 with 125 fps
                 * also note this is only valid when such angle is not in the accelzone, formula taking acceleration into account is unfathomably complicated
                 * afaik there's no simplified version of this formula that doesn't involve complex numbers, other than one valid for only speed<27.1 roughly
-                * furthermore, this function quite rapidly approaches its asymptote of ~35.26°, e.g. being ~0.68° away when at only speed=600
+                * furthermore, this function quite rapidly approaches its asymptote of ~35.26, e.g. being ~0.68 away when at only speed=600
                 * this asymptote is independent of whether the player is crouching or has haste, although they must be airborne
-                * thus, the best option is to just draw the asymptote (±acos(sqrt(2/3))),
+                * thus, the best option is to just draw the asymptote (acos(sqrt(2/3))),
                 * ... but the proper angle can be drawn too if the player wants (autocvar_hud_panel_strafehud_wturn_proper)
                 * for now this is only enabled if sv_airaccel_qw == 1 && sv_aircontrol == 150, since otherwise W-turning gives acceleration
                 */
-               if(wturn_no_accel && !immobile)
+               if(autocvar_hud_panel_strafehud_wturn && wturn_no_accel && !immobile)
                {
                        float wturn_g = 32 * aircontrol * dt;
                        float wturn_V = 1 - (wturn_g * wturn_g) / (speed * speed);
@@ -570,7 +570,7 @@ void HUD_StrafeHUD()
                        else
                                wturn_bestangle = acos(sqrt(2 / 3)) * RAD2DEG;
                        real_wturn_bestangle = wturn_bestangle;
-                       if(fwd && turn) // if not W-turning, need to add 45/90° so it aligns to where it would be after changing to W-only
+                       if(fwd && turn) // if not W-turning, need to add 90°/45° so it aligns to where it would be after changing to W-only
                                wturn_bestangle += 90;
                        else if(fwd && wishangle != 0)
                                wturn_bestangle += 45;
@@ -616,21 +616,24 @@ void HUD_StrafeHUD()
                        currentangle_offset = bound(-hudangle / 2, angle, hudangle / 2) / hudangle * panel_size.x + panel_size.x / 2;
 
                // best strafe acceleration angle
-               bestangle_offset        =  bestangle / hudangle * panel_size.x + panel_size.x / 2;
-               switch_bestangle_offset = -bestangle / hudangle * panel_size.x + panel_size.x / 2;
-               switch_bestangle_width  = panel_size.x * autocvar_hud_panel_strafehud_switch_width;
-               if(!autocvar_hud_panel_strafehud_uncapped)
-                       switch_bestangle_width = max(switch_bestangle_width, 1);
-
-               if((angle > -wishangle && direction == STRAFEHUD_DIRECTION_LEFT) || (angle < -wishangle && direction == STRAFEHUD_DIRECTION_RIGHT))
+               if(autocvar_hud_panel_strafehud_switch && speed >= minspeed)
                {
-                       odd_angles = true;
-                       odd_bestangle_offset = odd_bestangle / hudangle * panel_size.x + panel_size.x / 2;
-                       switch_odd_bestangle_offset = (odd_bestangle + bestangle * 2) / hudangle * panel_size.x + panel_size.x / 2;
+                       bestangle_offset        =  bestangle / hudangle * panel_size.x + panel_size.x / 2;
+                       switch_bestangle_offset = -bestangle / hudangle * panel_size.x + panel_size.x / 2;
+                       switch_bestangle_width  = panel_size.x * autocvar_hud_panel_strafehud_switch_width;
+                       if(!autocvar_hud_panel_strafehud_uncapped)
+                               switch_bestangle_width = max(switch_bestangle_width, 1);
+
+                       if((angle > -wishangle && direction == STRAFEHUD_DIRECTION_LEFT) || (angle < -wishangle && direction == STRAFEHUD_DIRECTION_RIGHT))
+                       {
+                               odd_angles = true;
+                               odd_bestangle_offset = odd_bestangle / hudangle * panel_size.x + panel_size.x / 2;
+                               switch_odd_bestangle_offset = (odd_bestangle + bestangle * 2) / hudangle * panel_size.x + panel_size.x / 2;
+                       }
                }
 
                // best angle to aim at when W-turning to maximally rotate velocity vector
-               if(wturn_no_accel && !immobile)
+               if(autocvar_hud_panel_strafehud_wturn && wturn_no_accel && !immobile)
                {
                        bool wturn_show = autocvar_hud_panel_strafehud_wturn == 3 ? true
                                : autocvar_hud_panel_strafehud_wturn == 2 ? (fwd && !turn)
@@ -650,19 +653,6 @@ void HUD_StrafeHUD()
                        }
                }
 
-               // direction indicator
-               direction_size_vertical.x = autocvar_hud_panel_strafehud_direction_width;
-               if(!autocvar_hud_panel_strafehud_uncapped)
-                       direction_size_vertical.x = min(direction_size_vertical.x, 1);
-               direction_size_vertical.x *= panel_size.y;
-               if(!autocvar_hud_panel_strafehud_uncapped)
-                       direction_size_vertical.x = max(direction_size_vertical.x, 1);
-               direction_size_vertical.y = panel_size.y + direction_size_vertical.x * 2;
-               direction_size_vertical.z = 0;
-               direction_size_horizontal.x = panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5);
-               direction_size_horizontal.y = direction_size_vertical.x;
-               direction_size_horizontal.z = 0;
-
                // the neutral zone fills the whole strafe bar
                if(immobile)
                {
@@ -791,44 +781,28 @@ void HUD_StrafeHUD()
                                autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha,
                                autocvar_hud_panel_strafehud_style, STRAFEHUD_GRADIENT_NONE, false);
 
-                       // only draw indicators if minspeed is reached
-                       if(autocvar_hud_panel_strafehud_switch && speed >= minspeed && switch_bestangle_width > 0 && autocvar_hud_panel_strafehud_switch_alpha > 0)
+                       // only draw switch indicators if minspeed is reached (switch_bestangle_width init to 0)
+                       if(autocvar_hud_panel_strafehud_switch && switch_bestangle_width > 0 && autocvar_hud_panel_strafehud_switch_alpha > 0)
                        {
                                // draw the switch indicator(s)
                                float offset = !odd_angles ? bestangle_offset : odd_bestangle_offset;
                                float switch_offset = !odd_angles ? switch_bestangle_offset : switch_odd_bestangle_offset;
 
-                               // remove switch indicator width from offset
-                               if(direction == STRAFEHUD_DIRECTION_LEFT)
-                               {
-                                       if(!odd_angles)
-                                               offset -= switch_bestangle_width;
-                                       else
-                                               switch_offset -= switch_bestangle_width;
-                               }
-                               else
-                               {
-                                       if(!odd_angles)
-                                               switch_offset -= switch_bestangle_width;
-                                       else
-                                               offset -= switch_bestangle_width;
-                               }
-
                                HUD_Panel_DrawStrafeHUD(
                                        switch_offset, switch_bestangle_width, hidden_width,
                                        autocvar_hud_panel_strafehud_switch_color,
                                        autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha,
-                                       STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, false);
+                                       STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, true);
 
                                if(direction == STRAFEHUD_DIRECTION_NONE)
                                        HUD_Panel_DrawStrafeHUD(
                                                offset, switch_bestangle_width, hidden_width,
                                                autocvar_hud_panel_strafehud_switch_color,
                                                autocvar_hud_panel_strafehud_switch_alpha * panel_fg_alpha,
-                                               STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, false);
+                                               STRAFEHUD_STYLE_DRAWFILL, STRAFEHUD_GRADIENT_NONE, true);
                        }
 
-                       // only draw indicators if conditions were met (wturn_bestangle_width init to 0)
+                       // only draw wturn indicators if conditions were met (wturn_bestangle_width init to 0)
                        if(autocvar_hud_panel_strafehud_wturn && wturn_bestangle_width > 0 && autocvar_hud_panel_strafehud_wturn_alpha > 0)
                        {
                                // draw the wturn indicators
@@ -913,6 +887,22 @@ void HUD_StrafeHUD()
                        text_offset_top = text_offset_bottom = slickdetector_height;
                }
 
+               // direction indicator
+               if(autocvar_hud_panel_strafehud_direction)
+               {
+                       direction_size_vertical.x = autocvar_hud_panel_strafehud_direction_width;
+                       if(!autocvar_hud_panel_strafehud_uncapped)
+                               direction_size_vertical.x = min(direction_size_vertical.x, 1);
+                       direction_size_vertical.x *= panel_size.y;
+                       if(!autocvar_hud_panel_strafehud_uncapped)
+                               direction_size_vertical.x = max(direction_size_vertical.x, 1);
+                       direction_size_vertical.y = panel_size.y + direction_size_vertical.x * 2;
+                       direction_size_vertical.z = 0;
+                       direction_size_horizontal.x = panel_size.x * min(autocvar_hud_panel_strafehud_direction_length, .5);
+                       direction_size_horizontal.y = direction_size_vertical.x;
+                       direction_size_horizontal.z = 0;
+               }
+
                if(autocvar_hud_panel_strafehud_direction &&
                   direction != STRAFEHUD_DIRECTION_NONE &&
                   direction_size_vertical.x > 0 &&