]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Add jump speed text to physics hud
authorotta8634 <k9wolf@pm.me>
Tue, 24 Sep 2024 05:19:09 +0000 (13:19 +0800)
committerotta8634 <k9wolf@pm.me>
Tue, 24 Sep 2024 05:19:09 +0000 (13:19 +0800)
Replaces the unit text when shown
Currently includes some extra cases such as jumppads, bouncing on an
upward ramp, etc.

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

index 6af283e017340b4643636320a5d4e424b2160d72..847f36d92be61322b9b01b6685c65d694c530ec7 100644 (file)
@@ -107,8 +107,10 @@ seta hud_panel_engineinfo_framecounter_exponentialmovingaverage_instantupdate_ch
 seta hud_panel_engineinfo_framecounter_decimals "0" "amount of decimals to show"
 seta hud_panel_engineinfo_framecounter_time "0.1" "time between framerate display updates"
 
-seta hud_panel_physics_acceleration_movingaverage 1 "use an averaging method for calculating acceleration instead of the real value"
-seta hud_panel_physics_update_interval 0.016 "how often (in seconds) numeric values get updated on screen"
+seta hud_panel_physics_acceleration_movingaverage "1" "use an averaging method for calculating acceleration instead of the real value"
+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_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"
 seta hud_panel_itemstime_hidespawned "1" "if 1 hide an item from the panel when all the occurrences of it are available again; if 2 hide it when at least one occurrence is available again"
index efbf045cd5d5908d4c3defa10eb7f4c0700121a8..ec56ddc97508d0a28a43d09c300dde9675cc3f75 100644 (file)
@@ -3,6 +3,10 @@
 #include <client/draw.qh>
 #include <lib/csqcmodel/cl_player.qh>
 
+// jump speed
+#include <lib/csqcmodel/common.qh> // for IS_PLAYER() macro
+#include <common/resources/cl_resources.qh> // IS_DEAD() macro
+
 // Physics (#15)
 
 void HUD_Physics_Export(int fh)
@@ -26,7 +30,7 @@ void HUD_Physics_Export(int fh)
 }
 
 vector acc_prevspeed;
-float acc_prevtime, acc_avg, top_speed, top_speed_time;
+float acc_prevtime, acc_avg, top_speed, top_speed_time, jump_speed, jump_speed_time, prev_vel_z = 0;
 float physics_update_time, discrete_speed, discrete_acceleration;
 void HUD_Physics()
 {
@@ -39,8 +43,6 @@ void HUD_Physics()
 
        HUD_Panel_LoadCvars();
 
-       draw_beginBoldFont();
-
        if (autocvar_hud_panel_physics_dynamichud)
                HUD_Scale_Enable();
        else
@@ -52,6 +54,8 @@ void HUD_Physics()
                panel_size -= '2 2 0' * panel_bg_padding;
        }
 
+       draw_beginBoldFont();
+
        float acceleration_progressbar_scale = 0;
        if(autocvar_hud_panel_physics_progressbar && autocvar_hud_panel_physics_acceleration_progressbar_scale > 1)
                acceleration_progressbar_scale = autocvar_hud_panel_physics_acceleration_progressbar_scale;
@@ -150,19 +154,59 @@ void HUD_Physics()
        if (autocvar_hud_panel_physics_acceleration_progressbar_mode == 0)
                acceleration_baralign = 3; //override hud_panel_physics_baralign value for acceleration
 
+       //draw jump speed
+       vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
+       float speed_size = 0.75, unit_size = 0.4;
+       bool drew_jump_speed = false;
+       if (autocvar_hud_panel_physics_jumpspeed)
+       if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
+       {
+               if (autocvar__hud_configure)
+               {
+                       top_speed = floor( max_speed * speed_size * 0.9 + 0.5 ); // slightly less than top speed text
+                       f = 1;
+               }
+               else
+               {
+                       if(vel.z > prev_vel_z && !IS_DEAD(csqcplayer) && IS_PLAYER(csqcplayer))
+                       {
+                               // FIXME: this includes some situations where the player doesn't explicitly jump (e.g. bouncing on ramp, jumppad)
+                               // maybe these can be left in?
+                               jump_speed = speed;
+                               jump_speed_time = time;
+                       }               
+                       f = max(1, autocvar_hud_panel_physics_jumpspeed_time);
+                       // divide by f to make it start from 1
+                       f = cos( ((time - jump_speed_time) / f) * PI/2 );
+                       prev_vel_z = vel.z;
+               }
+               if (f > 0)
+               {
+                       unit_size = 0.5; //make the jump speed and top speed text the same size         
+                       if (speed_baralign)
+                               tmp_offset.x = 0;
+                       else
+                               tmp_offset.x = panel_size.x * speed_size;
+                       tmp_size.x   =  panel_size.x * (1 - speed_size);
+                       tmp_size.y   =  panel_size.y * unit_size * text_scale;
+                       tmp_offset.y = (panel_size.y * unit_size - tmp_size.y) / 2;
+                       drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(jump_speed), tmp_size, '0 1 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drew_jump_speed = true;
+               }
+       }
+
        //draw speed
        if(speed)
        if(autocvar_hud_panel_physics_progressbar == 1 || autocvar_hud_panel_physics_progressbar == 2)
                HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, autocvar_hud_progressbar_speed_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-       vector tmp_offset = '0 0 0', tmp_size = '0 0 0';
        if (autocvar_hud_panel_physics_text == 1 || autocvar_hud_panel_physics_text == 2)
        {
-               tmp_size.x = panel_size.x * 0.75;
+               tmp_size.x = panel_size.x * speed_size;
                tmp_size.y = panel_size.y * text_scale;
                if (speed_baralign)
-                       tmp_offset.x = panel_size.x - tmp_size.x;
-               //else
-                       //tmp_offset_x = 0;
+                       tmp_offset.x = panel_size.x * (1 - speed_size);
+               else
+                       tmp_offset.x = 0;
                tmp_offset.y = (panel_size.y - tmp_size.y) / 2;
                drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(discrete_speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
@@ -170,13 +214,12 @@ void HUD_Physics()
                if (speed_baralign)
                        tmp_offset.x = 0;
                else
-                       tmp_offset.x = tmp_size.x;
-               if (autocvar_hud_panel_physics_speed_unit_show)
+                       tmp_offset.x = panel_size.x * speed_size;
+               if (autocvar_hud_panel_physics_speed_unit_show && !drew_jump_speed)
                {
-                       //tmp_offset_y = 0;
-                       tmp_size.x = panel_size.x * (1 - 0.75);
-                       tmp_size.y = panel_size.y * 0.4 * text_scale;
-                       tmp_offset.y = (panel_size.y * 0.4 - tmp_size.y) / 2;
+                       tmp_size.x   =  panel_size.x * (1 - speed_size);
+                       tmp_size.y   =  panel_size.y * unit_size * text_scale;
+                       tmp_offset.y = (panel_size.y * unit_size - tmp_size.y) / 2;
                        string unit = GetSpeedUnit(autocvar_hud_speed_unit);
                        drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                }
@@ -188,7 +231,7 @@ void HUD_Physics()
        {
                if (autocvar__hud_configure)
                {
-                       top_speed = floor( max_speed * 0.75 + 0.5 );
+                       top_speed = floor( max_speed * speed_size + 0.5 );
                        f = 1;
                }
                else
@@ -233,10 +276,10 @@ void HUD_Physics()
                        }
 
                        //top speed
-                       tmp_offset.y = panel_size.y * 0.4;
-                       tmp_size.x = panel_size.x * (1 - 0.75);
-                       tmp_size.y = (panel_size.y - tmp_offset.y) * text_scale;
-                       tmp_offset.y += (panel_size.y - tmp_offset.y - tmp_size.y) / 2;
+                       tmp_offset.y  =  panel_size.y * unit_size;
+                       tmp_size.x    =  panel_size.x * (1 - speed_size);
+                       tmp_size.y    =  panel_size.y * (1 - unit_size) * text_scale;
+                       tmp_offset.y += (panel_size.y * (1 - unit_size) - tmp_size.y) / 2;
                        drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
                }
                else
index 353a970cd183f3d4eba889e60ed252b0ee8f04d6..6293dd1685f71fb53930725b1d52132c29c54a45 100644 (file)
@@ -20,6 +20,8 @@ int autocvar_hud_panel_physics_text;
 float autocvar_hud_panel_physics_text_scale;
 bool autocvar_hud_panel_physics_topspeed;
 float autocvar_hud_panel_physics_topspeed_time;
+bool autocvar_hud_panel_physics_jumpspeed = false;
+float autocvar_hud_panel_physics_jumpspeed_time = 1;
 
 vector autocvar_hud_progressbar_acceleration_color;
 vector autocvar_hud_progressbar_acceleration_neg_color;