From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Mon, 18 Oct 2021 11:06:53 +0000 (+0200) Subject: Merge branch 'bones_was_here/strafehud_jumpheight' into Juhu/strafehud-fixes X-Git-Tag: xonotic-v0.8.6~136^2~37 X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=commitdiff_plain;h=bda29da7c83e61ef45bce71d9a0c53115cd56752 Merge branch 'bones_was_here/strafehud_jumpheight' into Juhu/strafehud-fixes --- bda29da7c83e61ef45bce71d9a0c53115cd56752 diff --cc qcsrc/client/hud/panel/strafehud.qc index b281d3ed4,5ddc30d23..8f0500053 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@@ -31,17 -31,12 +31,11 @@@ bool state_strafekeys = false float state_strafekeys_time = 0; bool turn = false; float turnangle; +float turnspeed; +float turnaccel; 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+) @@@ -760,180 -738,10 +754,157 @@@ void HUD_StrafeHUD( } } - if(currentangle_size.x > 0 && currentangle_size.y > 0 && autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0) + float angleheight_offset = currentangle_size.y; + float ghost_offset = 0; + if(autocvar_hud_panel_strafehud_bestangle && direction != 0) + { + ghost_offset = !odd_angles ? bestangle_offset : odd_bestangle_offset; + if(ghost_offset < 0) ghost_offset = 0; + if(ghost_offset > panel_size.x) ghost_offset = panel_size.x; + } + + switch(autocvar_hud_panel_strafehud_angle_style) + { + case 1: + if(currentangle_size.x > 0 && currentangle_size.y > 0) + { + if(autocvar_hud_panel_strafehud_bestangle && direction != 0) drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (ghost_offset - currentangle_size.x/2), currentangle_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + break; + case 2: + if(currentangle_size.x > 0 && currentangle_size.y > 0) + { + vector line_size = currentangle_size; + line_size.y = currentangle_size.y / (bound(2, autocvar_hud_panel_strafehud_angle_dashes, currentangle_size.y)*2-1); + for(float i = 0; i < currentangle_size.y; i += line_size.y*2) + { + if(i + line_size.y*2 >= currentangle_size.y) line_size.y = currentangle_size.y - i; + if(autocvar_hud_panel_strafehud_bestangle && direction != 0) drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (ghost_offset - line_size.x/2), line_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2 - i) + eX * (currentangle_offset - line_size.x/2), line_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); + } + } + break; + case 0: + default: + // don't offset text and arrows if the angle indicator line isn't drawn + angleheight_offset = panel_size.y; + } + + if(autocvar_hud_panel_strafehud_angle_arrow > 0) + { + if(arrow_size > 0) + { + if(autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3) + { + if(autocvar_hud_panel_strafehud_bestangle && direction != 0) StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * ghost_offset, arrow_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, true); + StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, true); + } + if(autocvar_hud_panel_strafehud_angle_arrow >= 2) + { + if(autocvar_hud_panel_strafehud_bestangle && direction != 0) StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * ghost_offset, arrow_size, autocvar_hud_panel_strafehud_bestangle_color, autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha, false); + StrafeHUD_drawStrafeArrow(panel_pos + eY * ((panel_size.y - angleheight_offset) / 2 + angleheight_offset) + eX * currentangle_offset, arrow_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, false); + } + } + } + + draw_beginBoldFont(); + // show speed when crossing the start trigger + if(autocvar_hud_panel_strafehud_startspeed_fade > 0) + { + float text_alpha = 0; + if((race_nextcheckpoint == 1) || (race_checkpoint == 254 && race_nextcheckpoint == 255)) // check if the start trigger was hit (will also trigger if the finish trigger was hit if those have the same ID) + { + 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 = autocvar_hud_panel_strafehud_startspeed_size; + if(!autocvar_hud_panel_strafehud_uncapped) + startspeed_size.y = min(startspeed_size.y, 10); + startspeed_size.y *= panel_size.y; + if(!autocvar_hud_panel_strafehud_uncapped) + startspeed_size.y = max(startspeed_size.y, 1); + + float text_offset = 0; + if((autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0) || (autocvar_hud_panel_strafehud_bestangle && autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha > 0)) + { + text_offset = (angleheight_offset - panel_size.y) / 2; + if(arrow_size > 0 && autocvar_hud_panel_strafehud_angle_arrow >= 2) + text_offset += arrow_size; + // make sure text doesn't draw inside the strafehud bar + text_offset = max(text_offset, 0); + } + + string speed_unit = GetSpeedUnit(autocvar_hud_panel_strafehud_unit); + drawstring_aspect(panel_pos + eY * (panel_size.y + text_offset), 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; + } + - // 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 || onground || swimming || IS_DEAD(strafeplayer) || spectating) - drawfill(panel_pos - eY * ((currentangle_size.y - panel_size.y) / 2) + eX * (currentangle_offset - currentangle_size.x/2), currentangle_size, currentangle_color, autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha, DRAWFLAG_NORMAL); ++ 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) || onground || 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 = autocvar_hud_panel_strafehud_jumpheight_size; + if(!autocvar_hud_panel_strafehud_uncapped) + jumpheight_size.y = min(jumpheight_size.y, 10); + jumpheight_size.y *= panel_size.y; + if(!autocvar_hud_panel_strafehud_uncapped) + jumpheight_size.y = max(jumpheight_size.y, 1); + + float text_offset = 0; + if((autocvar_hud_panel_strafehud_angle_alpha * panel_fg_alpha > 0) || (autocvar_hud_panel_strafehud_bestangle && autocvar_hud_panel_strafehud_bestangle_alpha * panel_fg_alpha > 0)) + { + text_offset = (angleheight_offset - panel_size.y) / 2; + if(arrow_size > 0 && autocvar_hud_panel_strafehud_angle_arrow == 1 || autocvar_hud_panel_strafehud_angle_arrow >= 3) + text_offset += arrow_size; + // make sure text doesn't draw inside the strafehud bar + text_offset = max(text_offset, 0); + } + + string length_unit = GetLengthUnit(autocvar_hud_panel_strafehud_unit); - drawstring_aspect(panel_pos - eY * (jumpheight_size.y + text_offset), 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 + text_offset), 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(); } }