]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix issues with physics hud jumpspeed
authorotta8634 <k9wolf@pm.me>
Wed, 25 Sep 2024 06:00:20 +0000 (14:00 +0800)
committerotta8634 <k9wolf@pm.me>
Wed, 25 Sep 2024 06:00:20 +0000 (14:00 +0800)
Previous commit broke the previous-speed caching
Made it use xy-speed rather than xyz-speed (ignores vertical speed)
Made the cvar description reflect that it ignores vertical speed
Used previous-frame speed rather than current frame -- acceleration after
the jump would've already happened in the current frame

_hud_common.cfg
qcsrc/client/hud/panel/physics.qc

index 2b1ab01789287cdc2b56ae802754adde619f6dea..302c107d10bacd68b3be9b8e3d6cd283e7fafb05 100644 (file)
@@ -111,7 +111,7 @@ seta hud_panel_physics_acceleration_movingaverage "1" "use an averaging method f
 seta hud_panel_physics_acceleration_movingaverage_strength "10" "weighting given to the current value in the movingaverage averaging method"
 seta hud_panel_physics_acceleration_max_slick "-1" "acceleration progressbar gets completely filled up by this value (in g) while on slick, -1 = same as the normal max"
 seta hud_panel_physics_update_interval "0.016" "how often (in seconds) numeric values get updated on screen"
-seta hud_panel_physics_jumpspeed "0" "also show jump speed, replacing the speed unit text"
+seta hud_panel_physics_jumpspeed "0" "also show jump speed, replacing the speed unit text (NOTE: ignores vertical speed)"
 seta hud_panel_physics_jumpspeed_time "1" "how many seconds the jump speed takes to fade out"
 
 seta hud_panel_itemstime_progressbar_maxtime "30" "when left time is at least this amount, the status bar is full"
index 8b22fe661a46c94f3792c995404c6dbd50de04ef..0235787c79a147aa990107174e4035c912934ff7 100644 (file)
@@ -29,7 +29,8 @@ void HUD_Physics_Export(int fh)
 }
 
 vector acc_prev_vel;
-float acc_prevtime, acc_avg, top_speed, top_speed_time, jump_speed, jump_speed_time, prev_vel_z = 0;
+float acc_prevtime, acc_avg, top_speed, top_speed_time, jump_speed, jump_speed_time;
+float prev_vel_z = 0, prev_speed2d = 0;
 float physics_update_time, discrete_speed, discrete_acceleration;
 void HUD_Physics()
 {
@@ -69,17 +70,23 @@ void HUD_Physics()
                text_scale = min(autocvar_hud_panel_physics_text_scale, 5);
 
        // compute speed
-       float speed, conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit);
+       float conversion_factor = GetSpeedUnitFactor(autocvar_hud_speed_unit);
+       float speed, speed2d;
        float max_speed = floor(autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5);
        if (autocvar__hud_configure)
        {
-               speed = floor(max_speed * 0.65 + 0.5);
+               speed2d = floor(max_speed * 0.65 + 0.5);
+               speed = speed2d; // just ignore vertical speed in hud configure
                immobile = speed <= 0;
        }
-       else if (autocvar_hud_panel_physics_speed_vertical)
-               speed = floor(speed3d_phys * conversion_factor + 0.5);
        else
-               speed = floor(speed_phys * conversion_factor + 0.5);
+       {
+               speed2d = floor(speed_phys * conversion_factor + 0.5);
+               if (autocvar_hud_panel_physics_speed_vertical)
+                       speed = floor(speed3d_phys * conversion_factor + 0.5);
+               else
+                       speed = speed2d;
+       }
 
        // compute acceleration
        float acceleration, f;
@@ -165,7 +172,7 @@ void HUD_Physics()
        {
                if (autocvar__hud_configure)
                {
-                       top_speed = floor(max_speed * speed_size * 0.9 + 0.5); // slightly less than top speed text
+                       jump_speed = floor(max_speed * speed_size * 0.9 + 0.5); // slightly less than top speed text
                        f = 1;
                }
                else
@@ -174,9 +181,11 @@ void HUD_Physics()
                        {
                                // NOTE: this includes some situations where the player doesn't explicitly jump (e.g. jumppad, weapon kb)
                                // excluding them would be difficult. maybe they can be left in?
-                               jump_speed = speed;
+                               jump_speed = prev_speed2d;
                                jump_speed_time = time;
                        }
+                       prev_vel_z = vel_phys.z;
+                       prev_speed2d = speed2d;
                        float time_frac = (time - jump_speed_time) / max(1, autocvar_hud_panel_physics_jumpspeed_time);
                        f = time_frac > 1 ? 0 : cos(time_frac * PI / 2);
                }