From cbc277bcf782691e7df08861846f0af7b2906b79 Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Mon, 6 Jul 2020 02:24:15 +0200 Subject: [PATCH] strafehud: add jump height and circle jump speed (speed crossing start trigger) text indicators --- _hud_common.cfg | 17 +++- qcsrc/client/autocvars.qh | 9 ++ qcsrc/client/hud/panel/strafehud.qc | 130 ++++++++++++++++++++++++++++ qcsrc/client/hud/panel/strafehud.qh | 2 + 4 files changed, 154 insertions(+), 4 deletions(-) diff --git a/_hud_common.cfg b/_hud_common.cfg index 21d771f67..f2be854d5 100644 --- a/_hud_common.cfg +++ b/_hud_common.cfg @@ -128,6 +128,8 @@ seta _hud_panel_strafehud_demo "0" "strafehud changes angle during configure" seta hud_panel_strafehud_mode "0" "strafehud mode which controls whether the strafehud is centered at \"0\" = view angle, \"1\" = velocity angle" seta hud_panel_strafehud_range "0" "the angle range up to 360 degrees displayed on the strafehud, \"0\" = dynamic (chooses the minimum range required to still see the whole area needed for accelerating at once)" seta hud_panel_strafehud_style "1" "\"0\" = no styling, \"1\" = progress bar style for the strafe bar, \"2\" = gradient for the strafe bar" +seta hud_panel_strafehud_unit "1" "speed unit (1 = qu/s, 2 = m/s, 3 = km/h, 4 = mph, 5 = knots), length unit (1 = qu, 2 = m, 3 = km, 4 = mi, 5 = nmi)" +seta hud_panel_strafehud_unit_show "1" "show units" seta hud_panel_strafehud_bar_neutral_color "1 1 1" "color of the strafe meter neutral zone" seta hud_panel_strafehud_bar_neutral_alpha "0.3" "opacity of the strafe meter neutral zone" seta hud_panel_strafehud_bar_accel_color "0 1 0" "color of the strafe meter acceleration zone" @@ -155,10 +157,17 @@ seta hud_panel_strafehud_slickdetector_granularity "2" "value from 0 to 4 which seta hud_panel_strafehud_slickdetector_color "0 1 1" "color of the slick detector indicator" seta hud_panel_strafehud_slickdetector_alpha "0.5" "opacity of the slick detector indicator" seta hud_panel_strafehud_slickdetector_height "0.125" "height of the slick detector indicator (relative to the panel height)" -seta hud_panel_strafehud_timeout_air "0.1" "time after take off before changing to air strafe physics when not jumping (visually more consistent hud while on slick downwards ramps)" -seta hud_panel_strafehud_timeout_ground "0.03333333" "time after landing before changing to non-air strafe physics (visually more consistent hud while strafe turning when touching the floor after every hop)" -seta hud_panel_strafehud_timeout_turn "0.1" "time after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)" -seta hud_panel_strafehud_timeout_direction "0.5" "time it takes until direction changes (forward or backward movement) are applied (set to zero if you intend to sideways strafe)" +seta hud_panel_strafehud_startspeed_fade "0" "fade time (in seconds) of the start speed text or \"0\" to disable" +seta hud_panel_strafehud_startspeed_color "1 0.75 0" "color of the start speed text" +seta hud_panel_strafehud_startspeed_size "1.5" "size of the start speed text (relative to the panel height)" +seta hud_panel_strafehud_jumpheight_fade "0" "fade time (in seconds) of the jump height text or \"0\" to disable" +seta hud_panel_strafehud_jumpheight_min "50" "minimum jump height to display in the selected unit" +seta hud_panel_strafehud_jumpheight_color "0 1 0.75" "color of the jump height text" +seta hud_panel_strafehud_jumpheight_size "1.5" "size of the jump height text (relative to the panel height)" +seta hud_panel_strafehud_timeout_air "0.1" "time (in seconds) after take off before changing to air strafe physics when not jumping (visually more consistent hud while on slick downwards ramps)" +seta hud_panel_strafehud_timeout_ground "0.03333333" "time (in seconds) after landing before changing to non-air strafe physics (visually more consistent hud while strafe turning when touching the floor after every hop)" +seta hud_panel_strafehud_timeout_turn "0.1" "time (in seconds) after releasing the strafe keys before changing mode (visually more consistent hud while switching between left/right strafe turning)" +seta hud_panel_strafehud_timeout_direction "0.5" "time (in seconds) it takes until direction changes (forward or backward movement) are applied (set to zero if you intend to sideways strafe)" seta hud_panel_strafehud_antiflicker_angle "0.01" "how many degrees from 0° to 180° the hud ignores if it could cause visual disturbances otherwise (and to counter rounding errors)" seta hud_panel_strafehud_antiflicker_speed "0.0001" "how many qu/s the hud ignores if it could cause visual disturbances otherwise (and to counter rounding errors)" diff --git a/qcsrc/client/autocvars.qh b/qcsrc/client/autocvars.qh index 2f6517c62..aefc91869 100644 --- a/qcsrc/client/autocvars.qh +++ b/qcsrc/client/autocvars.qh @@ -326,6 +326,8 @@ bool autocvar__hud_panel_strafehud_demo = false; int autocvar_hud_panel_strafehud_mode = 0; float autocvar_hud_panel_strafehud_range = 0; int autocvar_hud_panel_strafehud_style = 1; +int autocvar_hud_panel_strafehud_unit = 1; +bool autocvar_hud_panel_strafehud_unit_show = true; vector autocvar_hud_panel_strafehud_bar_neutral_color = '1 1 1'; float autocvar_hud_panel_strafehud_bar_neutral_alpha = 0.3; vector autocvar_hud_panel_strafehud_bar_accel_color = '0 1 0'; @@ -353,6 +355,13 @@ int autocvar_hud_panel_strafehud_slickdetector_granularity = 2; vector autocvar_hud_panel_strafehud_slickdetector_color = '0 1 1'; float autocvar_hud_panel_strafehud_slickdetector_alpha = 0.5; float autocvar_hud_panel_strafehud_slickdetector_height = 0.125; +float autocvar_hud_panel_strafehud_startspeed_fade = 0; +vector autocvar_hud_panel_strafehud_startspeed_color = '1 0.75 0'; +float autocvar_hud_panel_strafehud_startspeed_size = 1.5; +float autocvar_hud_panel_strafehud_jumpheight_fade = 0; +float autocvar_hud_panel_strafehud_jumpheight_min = 50; +vector autocvar_hud_panel_strafehud_jumpheight_color = '0 1 0.75'; +float autocvar_hud_panel_strafehud_jumpheight_size = 1.5; float autocvar_hud_panel_strafehud_timeout_air = 0.1; float autocvar_hud_panel_strafehud_timeout_ground = 0.03333333; float autocvar_hud_panel_strafehud_timeout_turn = 0.1; diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 15c7d0d14..e4a91d42e 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -33,6 +33,14 @@ bool fwd = true; bool state_fwd = true; bool state_fwd_prev = true; 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+) @@ -111,6 +119,11 @@ void HUD_StrafeHUD() // HUD int mode = autocvar_hud_panel_strafehud_mode >= 0 && autocvar_hud_panel_strafehud_mode <= 1 ? autocvar_hud_panel_strafehud_mode : 0; + float speed_conversion_factor = GetSpeedUnitFactor(autocvar_hud_panel_strafehud_unit); + float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_panel_strafehud_unit); + string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit); + string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit); + int length_decimals = autocvar_hud_panel_strafehud_unit >= 3 && autocvar_hud_panel_strafehud_unit <= 5 ? 6 : 2; // use more decimals when displaying km or miles float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180); float antiflicker_speed = max(0, autocvar_hud_panel_strafehud_antiflicker_speed); float minspeed; @@ -605,6 +618,95 @@ void HUD_StrafeHUD() } } + draw_beginBoldFont(); + // show speed when crossing the start trigger + if(autocvar_hud_panel_strafehud_startspeed_fade > 0) + { + float text_alpha = 0; + if(race_checkpoint == 254) // checkpoint 254 is the start trigger + { + if(starttime != race_checkpointtime) + { + starttime = race_checkpointtime; + startspeed = speed; + } + } + if(startspeed >= 0) + { + text_alpha = cos(((time - starttime) / autocvar_hud_panel_strafehud_startspeed_fade) * 90 * DEG2RAD); // fade non-linear like the physics panel does + if((time - starttime) > autocvar_hud_panel_strafehud_startspeed_fade) + { + startspeed = -1; + } + } + if(startspeed >= 0 && text_alpha > 0 && autocvar_hud_panel_strafehud_startspeed_size > 0) + { + vector startspeed_size = panel_size; + startspeed_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_startspeed_size, 5); + drawstring_aspect(panel_pos + eY * panel_size.y, strcat(ftos_decimals(startspeed * speed_conversion_factor, 2), autocvar_hud_panel_strafehud_unit_show ? speed_unit : ""), startspeed_size, autocvar_hud_panel_strafehud_startspeed_color, text_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } + else + { + starttime = 0; + startspeed = -1; + } + + // show height achieved by a single jump + if(autocvar_hud_panel_strafehud_jumpheight_fade > 0) + { + float text_alpha = 0; + float jumpheight_min = max(autocvar_hud_panel_strafehud_jumpheight_min * length_conversion_factor, 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)) + { + jumprestart = true; + } + else + { + if(jumpheight < 0 || jumprestart) + { + jumprestart = false; + jumpheight = 0; + // this reduces accuracy a little bit but prevents all kind of bugs from carryover values at connect or when dying + jumpheight_prev = jumpheight_current; + jumpspeed_prev = jumpspeed_current; + } + else + { + jumpheight += jumpheight_current - jumpheight_prev; + } + if(jumpheight > jumpheight_min && jumpheight > jumpheight_persistent) + { + 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) + { + vector jumpheight_size = panel_size; + jumpheight_size.y = panel_size.y * min(autocvar_hud_panel_strafehud_jumpheight_size, 5); + 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); + } + } + else + { + jumpheight_prev = jumpspeed_prev = 0; + jumpheight = jumpheight_persistent = -1; + } + draw_endBoldFont(); + if(speed < (maxspeed + antiflicker_speed) && !immobile) { bestangle_anywhere = true; // moving forward should suffice to gain speed @@ -780,3 +882,31 @@ void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float ori if(alpha_ratio > 0) drawfill(panel_pos + eX * (offset + i), gradient_size, StrafeHUD_mixColors(color1, color2, ratio), alpha_ratio, DRAWFLAG_NORMAL); } } + +// length unit conversion (km and miles are only included to match the GetSpeedUnit* functions) +float GetLengthUnitFactor(int length_unit) +{ + switch(length_unit) + { + default: + case 1: return 1.0; + case 2: return 0.0254; + case 3: return 0.0254 * 0.001; + case 4: return 0.0254 * 0.001 * 0.6213711922; + case 5: return 0.0254 * 0.001 * 0.5399568035; + } +} + +string GetLengthUnit(int length_unit) +{ + switch(length_unit) + { + // translator-friendly strings without the initial space + default: + case 1: return strcat(" ", _("qu")); + case 2: return strcat(" ", _("m")); + case 3: return strcat(" ", _("km")); + case 4: return strcat(" ", _("mi")); + case 5: return strcat(" ", _("nmi")); + } +} diff --git a/qcsrc/client/hud/panel/strafehud.qh b/qcsrc/client/hud/panel/strafehud.qh index d41700a79..acc43bde9 100644 --- a/qcsrc/client/hud/panel/strafehud.qh +++ b/qcsrc/client/hud/panel/strafehud.qh @@ -4,3 +4,5 @@ void HUD_Panel_DrawStrafeHUD(float, float, vector, float, int, int); vector StrafeHUD_mixColors(vector, vector, float); void StrafeHUD_drawGradient(vector, vector, vector, float, float, float, float, int); +float GetLengthUnitFactor(int); +string GetLengthUnit(int); -- 2.39.2