float state_fwd_time = 0;
float starttime = 0;
float startspeed = -1;
-float jumptime = 0;
-float jumpheight = -1;
-float jumpheight_persistent = -1;
-float jumpheight_prev = 0;
-float jumpspeed_prev = 0;
-bool jumprestart = true;
// provide basic panel cvars to old clients
// TODO remove them after a future release (0.8.2+)
startspeed = -1;
}
- // experimental: show height achieved by a single jump (doesn't work in low gravity and may not be 100% accurate)
- if(autocvar_hud_panel_strafehud_jumpheight_fade > 0)
+ // show height achieved by a single jump
+ if(autocvar_hud_panel_strafehud_jumpheight_fade > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
{
- float text_alpha = 0;
- float jumpheight_min = max(autocvar_hud_panel_strafehud_jumpheight_min, 0);
- float jumpheight_current = strafeplayer.origin.z;
- float jumpspeed_current = strafeplayer.velocity.z;
- if(jumpspeed_prev <= jumpspeed_current || jumpheight_prev > jumpheight_current || IS_ONGROUND(strafeplayer) || swimming || IS_DEAD(strafeplayer) || spectating)
+ static float height_min = 0, height_max = 0; // ground and peak of jump z coordinates
+ static float jumpheight = 0, jumptime = 0; // displayed value and timestamp for fade out
+
+ // tries to catch kill and spectate but those are not reliable, should just hook to kill/spectate/teleport and reset jump height there
+ if((strafeplayer.velocity.z <= 0 && height_max >= strafeplayer.origin.z) || IS_ONGROUND(strafeplayer) || swimming || IS_DEAD(strafeplayer) || spectating)
{
- // tries to catch kill and spectate but those are not reliable, should just hook to kill/spectate/teleport and reset jump height there
- jumprestart = true;
+ height_min = height_max = strafeplayer.origin.z;
}
- else
+ else if(strafeplayer.origin.z > height_max)
{
- if(jumpheight < 0 || jumprestart)
- {
- jumprestart = false;
- jumpheight = 0;
- }
- else
- {
- jumpheight += jumpheight_current - jumpheight_prev;
- }
- if((jumpheight * length_conversion_factor) > jumpheight_min && jumpheight > jumpheight_persistent)
- {
+ height_max = strafeplayer.origin.z;
+ jumpheight = (height_max - height_min) * length_conversion_factor;
+
+ if(jumpheight > max(autocvar_hud_panel_strafehud_jumpheight_min, 0))
jumptime = time;
- jumpheight_persistent = jumpheight;
- }
- }
- jumpheight_prev = jumpheight_current;
- jumpspeed_prev = jumpspeed_current;
- if(jumpheight_persistent > 0)
- {
- text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
- if((time - jumptime) > autocvar_hud_panel_strafehud_jumpheight_fade)
- {
- jumpheight_persistent = -1;
- }
}
- if(jumpheight_persistent > 0 && text_alpha > 0 && autocvar_hud_panel_strafehud_jumpheight_size > 0)
+
+ if((time - jumptime) <= autocvar_hud_panel_strafehud_jumpheight_fade)
{
+ float text_alpha = cos(((time - jumptime) / autocvar_hud_panel_strafehud_jumpheight_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does
vector jumpheight_size = panel_size;
jumpheight_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_jumpheight_size, 5);
string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit);
- drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight_persistent * length_conversion_factor, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+ drawstring_aspect(panel_pos - eY * jumpheight_size.y, strcat(ftos_decimals(jumpheight, length_decimals), autocvar_hud_panel_strafehud_unit_show ? length_unit : ""), jumpheight_size, autocvar_hud_panel_strafehud_jumpheight_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
}
}
- else
- {
- jumpheight_prev = jumpspeed_prev = 0;
- jumpheight = jumpheight_persistent = -1;
- }
draw_endBoldFont();
if(speed < (maxspeed + antiflicker_speed) && !immobile)