From 3f9543cdcc26004011f88e855cdb2002f7d0349a Mon Sep 17 00:00:00 2001 From: Juhu <5894800-Juhu_@users.noreply.gitlab.com> Date: Mon, 16 Sep 2024 20:24:46 +0200 Subject: [PATCH] strafehud: improved function naming, moved the mix color function to util.qc + indentation fix --- qcsrc/client/hud/panel/strafehud.qc | 30 ++++++++-------- qcsrc/client/hud/panel/strafehud/core.qc | 20 +++++------ qcsrc/client/hud/panel/strafehud/core.qh | 2 +- qcsrc/client/hud/panel/strafehud/draw.qc | 39 ++++++++------------ qcsrc/client/hud/panel/strafehud/draw.qh | 9 +++-- qcsrc/client/hud/panel/strafehud/extra.qc | 20 +++++------ qcsrc/client/hud/panel/strafehud/extra.qh | 10 +++--- qcsrc/client/hud/panel/strafehud/util.qc | 43 ++++++++++++++--------- qcsrc/client/hud/panel/strafehud/util.qh | 27 +++++++------- 9 files changed, 100 insertions(+), 100 deletions(-) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 63cdef577..854197399 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -68,7 +68,7 @@ void HUD_StrafeHUD() if(csqcplayer && strafeplayer) { int keys = STAT(PRESSED_KEYS); - bool jumpheld = DetectJumpHeld(strafeplayer, keys, islocal); + bool jumpheld = StrafeHUD_DetermineJumpHeld(strafeplayer, keys, islocal); // does not get changed by ground timeout and is not affected by jump input bool real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR); @@ -81,7 +81,7 @@ void HUD_StrafeHUD() bool onslick = real_onslick; // the hud will not work well while swimming - float strafe_waterlevel = DetectWaterLevel(strafeplayer); + float strafe_waterlevel = StrafeHUD_DetermineWaterLevel(strafeplayer); bool swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING; static float onground_lasttime = 0; @@ -161,7 +161,7 @@ void HUD_StrafeHUD() keys_fwd = STRAFEHUD_KEYS_NONE; } - float wishangle = DetectWishAngle(movement, keys, islocal); + float wishangle = StrafeHUD_DetermineWishAngle(movement, keys, islocal); bool strafekeys = fabs(wishangle) > 45; // determine minimum required angle to display full strafe range @@ -170,7 +170,7 @@ void HUD_StrafeHUD() range_minangle = 90 - range_minangle; // calculate value which is never >90 or <45 range_minangle *= 2; // multiply to accommodate for both sides of the hud - float hudangle = StrafeHUD_determineHudAngle(range_minangle); + float hudangle = StrafeHUD_DetermineHudAngle(range_minangle); // detect air strafe turning static bool turn = false; @@ -214,7 +214,7 @@ void HUD_StrafeHUD() } } - float dt = DetectFrameTime(); + float dt = StrafeHUD_DetermineFrameTime(); maxaccel *= dt * movespeed; float bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration @@ -345,7 +345,7 @@ void HUD_StrafeHUD() float absolute_prebestangle = prebestangle; float antiflicker_angle = bound(0, autocvar_hud_panel_strafehud_antiflicker_angle, 180); - float direction = StrafeHUD_determineDirection(angle, wishangle, antiflicker_angle); + float direction = StrafeHUD_DetermineDirection(angle, wishangle, antiflicker_angle); if(direction == STRAFEHUD_DIRECTION_LEFT) // the angle becomes negative in case we strafe left { @@ -423,7 +423,7 @@ void HUD_StrafeHUD() } if(autocvar_hud_panel_strafehud_style == STRAFEHUD_STYLE_GRADIENT) - currentangle_color = StrafeHUD_mixColors( + currentangle_color = StrafeHUD_MixColors( autocvar_hud_panel_strafehud_angle_neutral_color, currentangle_color, fabs(strafe_ratio)); } @@ -468,10 +468,10 @@ void HUD_StrafeHUD() { bool angle_indicator_visible = false; - // minimum speed for change indicators - float minspeed = autocvar_hud_panel_strafehud_switch_minspeed; - if(minspeed < 0) - minspeed = bestspeed + frictionspeed; + // minimum speed for change indicators + float minspeed = autocvar_hud_panel_strafehud_switch_minspeed; + if(minspeed < 0) + minspeed = bestspeed + frictionspeed; // only draw change indicators if minspeed is reached if(autocvar_hud_panel_strafehud_switch && speed >= minspeed) @@ -550,12 +550,12 @@ void HUD_StrafeHUD() } } - text_offset_bottom += StrafeHUD_drawVerticalAngle(text_offset_bottom); + text_offset_bottom += StrafeHUD_DrawVerticalAngle(text_offset_bottom); draw_beginBoldFont(); - text_offset_bottom += StrafeHUD_drawStartSpeed(speed, text_offset_bottom); - text_offset_top += StrafeHUD_drawStrafeEfficiency(strafe_ratio, text_offset_top); - text_offset_top += StrafeHUD_drawJumpHeight(strafeplayer, real_onground, swimming, text_offset_top); + text_offset_bottom += StrafeHUD_DrawStartSpeed(speed, text_offset_bottom); + text_offset_top += StrafeHUD_DrawStrafeEfficiency(strafe_ratio, text_offset_top); + text_offset_top += StrafeHUD_DrawJumpHeight(strafeplayer, real_onground, swimming, text_offset_top); draw_endBoldFont(); StrafeHUD_Sonar(strafe_ratio, StrafeHUD_UpdateSonarSound()); diff --git a/qcsrc/client/hud/panel/strafehud/core.qc b/qcsrc/client/hud/panel/strafehud/core.qc index 3f54129f1..7f4137233 100644 --- a/qcsrc/client/hud/panel/strafehud/core.qc +++ b/qcsrc/client/hud/panel/strafehud/core.qc @@ -83,7 +83,7 @@ void StrafeHUD_DrawStrafeMeter( overturn_startangle += shiftangle; // draw left acceleration zone - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( accelzone_left_startangle, accelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, @@ -91,7 +91,7 @@ void StrafeHUD_DrawStrafeMeter( true, hudangle); if(autocvar_hud_panel_strafehud_bar_preaccel) - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( preaccelzone_left_startangle, preaccelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, @@ -99,7 +99,7 @@ void StrafeHUD_DrawStrafeMeter( true, hudangle); // draw right acceleration zone - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( accelzone_right_startangle, accelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, @@ -107,7 +107,7 @@ void StrafeHUD_DrawStrafeMeter( true, hudangle); if(autocvar_hud_panel_strafehud_bar_preaccel) - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( preaccelzone_right_startangle, preaccelzone_offsetangle, autocvar_hud_panel_strafehud_bar_accel_color, autocvar_hud_panel_strafehud_bar_accel_alpha * panel_fg_alpha, @@ -118,7 +118,7 @@ void StrafeHUD_DrawStrafeMeter( // this is technically incorrect // acceleration decreases at 90 degrees but speed loss happens a little bit after 90 degrees, // however due to sv_airstopaccelerate that's hard to calculate - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( overturn_startangle, overturn_offsetangle, autocvar_hud_panel_strafehud_bar_overturn_color, autocvar_hud_panel_strafehud_bar_overturn_alpha * panel_fg_alpha, @@ -126,7 +126,7 @@ void StrafeHUD_DrawStrafeMeter( true, hudangle); // draw neutral zone - StrafeHUD_drawStrafeHUD( + StrafeHUD_DrawStrafeHUD( neutral_startangle, neutral_offsetangle, autocvar_hud_panel_strafehud_bar_neutral_color, autocvar_hud_panel_strafehud_bar_neutral_alpha * panel_fg_alpha, @@ -145,8 +145,8 @@ void StrafeHUD_DrawAngleIndicator( // bound to HUD area angle = bound(-hudangle / 2, angle, hudangle / 2); - float offset = StrafeHUD_angleToOffset(angle, hudangle); - offset = StrafeHUD_projectOffset(offset, hudangle, false); + float offset = StrafeHUD_AngleToOffset(angle, hudangle); + offset = StrafeHUD_ProjectOffset(offset, hudangle, false); StrafeHUD_DrawAngleIndicatorLine(line_size, offset, num_dashes, color, alpha); @@ -184,13 +184,13 @@ void StrafeHUD_DrawAngleIndicatorArrow(float size, float offset, vector line_siz if(top) { - StrafeHUD_drawStrafeArrow( + StrafeHUD_DrawStrafeArrow( panel_pos + eY * ((panel_size.y - line_size.y) / 2) + eX * offset, size, color, alpha * panel_fg_alpha, true, line_size.x); } else { - StrafeHUD_drawStrafeArrow( + StrafeHUD_DrawStrafeArrow( panel_pos + eY * ((panel_size.y - line_size.y) / 2 + line_size.y) + eX * offset, size, color, alpha * panel_fg_alpha, false, line_size.x); } diff --git a/qcsrc/client/hud/panel/strafehud/core.qh b/qcsrc/client/hud/panel/strafehud/core.qh index 944ed426d..272b08840 100644 --- a/qcsrc/client/hud/panel/strafehud/core.qh +++ b/qcsrc/client/hud/panel/strafehud/core.qh @@ -1,8 +1,8 @@ #pragma once #include "../strafehud.qh" +void StrafeHUD_DrawStrafeMeter(float, float, float, float, bool, float); void StrafeHUD_DrawAngleIndicator(float, vector, float, int, bool, bool, vector, float, float); void StrafeHUD_DrawAngleIndicatorLine(vector, float, int, vector, float); void StrafeHUD_DrawAngleIndicatorArrow(float, float, vector, vector, float, bool); void StrafeHUD_DrawDirectionIndicator(int, bool, bool); -void StrafeHUD_DrawStrafeMeter(float, float, float, float, bool, float); diff --git a/qcsrc/client/hud/panel/strafehud/draw.qc b/qcsrc/client/hud/panel/strafehud/draw.qc index 6c6793548..9f94a1bc0 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qc +++ b/qcsrc/client/hud/panel/strafehud/draw.qc @@ -3,10 +3,10 @@ #include // functions to make hud elements align perfectly in the hud area -void StrafeHUD_drawStrafeHUD(float startangle, float offsetangle, vector color, float alpha, int type, int gradientType, bool projectWidth, float range) +void StrafeHUD_DrawStrafeHUD(float startangle, float offsetangle, vector color, float alpha, int type, int gradientType, bool projectWidth, float range) { - float offset = StrafeHUD_angleToOffset(startangle % 360, range); - float width = StrafeHUD_angleToWidth(offsetangle, range); + float offset = StrafeHUD_AngleToOffset(startangle % 360, range); + float width = StrafeHUD_AngleToWidth(offsetangle, range); float mirror_offset; float mirror_width; @@ -51,9 +51,9 @@ void StrafeHUD_drawStrafeHUD(float startangle, float offsetangle, vector color, float original_offset = offset; if(projectWidth && size.x > 0) - size.x = StrafeHUD_projectWidth(offset, size.x, range); + size.x = StrafeHUD_ProjectWidth(offset, size.x, range); - offset = StrafeHUD_projectOffset(offset, range, false); + offset = StrafeHUD_ProjectOffset(offset, range, false); if(mirror_offset < 0) { @@ -73,9 +73,9 @@ void StrafeHUD_drawStrafeHUD(float startangle, float offsetangle, vector color, float original_mirror_offset = mirror_offset; if(projectWidth && mirror_size.x > 0) - mirror_size.x = StrafeHUD_projectWidth(mirror_offset, mirror_size.x, range); + mirror_size.x = StrafeHUD_ProjectWidth(mirror_offset, mirror_size.x, range); - mirror_offset = StrafeHUD_projectOffset(mirror_offset, range, false); + mirror_offset = StrafeHUD_ProjectOffset(mirror_offset, range, false); switch(type) { @@ -129,31 +129,20 @@ void StrafeHUD_drawStrafeHUD(float startangle, float offsetangle, vector color, gradient_mirror_offset = 0; } - StrafeHUD_drawGradient( + StrafeHUD_DrawGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, mirror_size, original_width, mirror_offset, original_mirror_offset, alpha, gradient_mirror_offset, gradientType, range); - StrafeHUD_drawGradient( + StrafeHUD_DrawGradient( color, autocvar_hud_panel_strafehud_bar_neutral_color, size, original_width, offset, original_offset, alpha, gradient_offset, gradientType, range); } } -vector StrafeHUD_mixColors(vector color1, vector color2, float ratio) -{ - vector mixedColor; - if(ratio <= 0) return color1; - if(ratio >= 1) return color2; - mixedColor.x = color1.x + (color2.x - color1.x) * ratio; - mixedColor.y = color1.y + (color2.y - color1.y) * ratio; - mixedColor.z = color1.z + (color2.z - color1.z) * ratio; - return mixedColor; -} - // FIXME: this is very bad for performance, there should be a better way to draw gradients -void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradientOffset, int gradientType, float range) +void StrafeHUD_DrawGradient(vector color1, vector color2, vector size, float original_width, float offset, float original_offset, float alpha, float gradientOffset, int gradientType, float range) { float color_ratio, alpha1, alpha2; vector segment_size = size; @@ -167,7 +156,7 @@ void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float ori segment_size.x = min(size.x - i, 1); // each gradient segment is 1 unit wide except if there is less than 1 unit of gradient remaining segment_offset = offset + i; ratio_offset = segment_offset + segment_size.x / 2; - ratio_offset = StrafeHUD_projectOffset(ratio_offset, range, true); + ratio_offset = StrafeHUD_ProjectOffset(ratio_offset, range, true); ratio_offset += gradientOffset; ratio = (ratio_offset - original_offset) / original_width * (gradientType == STRAFEHUD_GRADIENT_BOTH ? 2 : 1); if(ratio > 1) ratio = 2 - ratio; @@ -181,14 +170,14 @@ void StrafeHUD_drawGradient(vector color1, vector color2, vector size, float ori drawfill( panel_pos + eX * segment_offset, segment_size, - StrafeHUD_mixColors(color1, color2, ratio), + StrafeHUD_MixColors(color1, color2, ratio), alpha_ratio, DRAWFLAG_NORMAL); } } // draw the strafe arrows (inspired by drawspritearrow() in common/mutators/mutator/waypoints/waypointsprites.qc) -void StrafeHUD_drawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped, float connection_width) +void StrafeHUD_DrawStrafeArrow(vector origin, float size, vector color, float alpha, bool flipped, float connection_width) { origin = HUD_Shift(origin); float width = HUD_ScaleX(size * 2 + connection_width); @@ -210,7 +199,7 @@ void StrafeHUD_drawStrafeArrow(vector origin, float size, vector color, float al } // draw a fading text indicator above or below the strafe meter, return true if something was displayed -bool StrafeHUD_drawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, float offset, int position) +bool StrafeHUD_DrawTextIndicator(string text, float height, vector color, float fadetime, float lasttime, float offset, int position) { if((height <= 0) || (lasttime <= 0) || (fadetime <= 0) || ((time - lasttime) >= fadetime)) return false; diff --git a/qcsrc/client/hud/panel/strafehud/draw.qh b/qcsrc/client/hud/panel/strafehud/draw.qh index 3c7d5b973..1f366a20f 100644 --- a/qcsrc/client/hud/panel/strafehud/draw.qh +++ b/qcsrc/client/hud/panel/strafehud/draw.qh @@ -1,8 +1,7 @@ #pragma once #include "../strafehud.qh" -void StrafeHUD_drawStrafeHUD(float, float, vector, float, int, int, bool, float); -void StrafeHUD_drawGradient(vector, vector, vector, float, float, float, float, float, int, float); -void StrafeHUD_drawStrafeArrow(vector, float, vector, float, bool, float); -bool StrafeHUD_drawTextIndicator(string, float, vector, float, float, float, int); -vector StrafeHUD_mixColors(vector, vector, float); +void StrafeHUD_DrawStrafeHUD(float, float, vector, float, int, int, bool, float); +void StrafeHUD_DrawGradient(vector, vector, vector, float, float, float, float, float, int, float); +void StrafeHUD_DrawStrafeArrow(vector, float, vector, float, bool, float); +bool StrafeHUD_DrawTextIndicator(string, float, vector, float, float, float, int); diff --git a/qcsrc/client/hud/panel/strafehud/extra.qc b/qcsrc/client/hud/panel/strafehud/extra.qc index 2a52e56a0..3ac37027b 100644 --- a/qcsrc/client/hud/panel/strafehud/extra.qc +++ b/qcsrc/client/hud/panel/strafehud/extra.qc @@ -81,7 +81,7 @@ float StrafeHUD_DrawSlickDetector(entity e, bool onslick) } // vertical angle for weapon jumps -float StrafeHUD_drawVerticalAngle(float text_offset_bottom) +float StrafeHUD_DrawVerticalAngle(float text_offset_bottom) { if(autocvar_hud_panel_strafehud_vangle) { @@ -89,7 +89,7 @@ float StrafeHUD_drawVerticalAngle(float text_offset_bottom) float vangle_height = autocvar_hud_panel_strafehud_vangle_size * panel_size.y; string vangle_text = strcat(ftos_decimals(vangle, 2), "°"); - bool was_drawn = StrafeHUD_drawTextIndicator( + bool was_drawn = StrafeHUD_DrawTextIndicator( vangle_text, vangle_height, autocvar_hud_panel_strafehud_vangle_color, 1, time, text_offset_bottom, STRAFEHUD_TEXT_BOTTOM); @@ -162,9 +162,9 @@ string StrafeHUD_UpdateSonarSound() // show height achieved by a single jump // FIXME: checking z position differences is unreliable (warpzones, teleporter, kill, etc), use velocity to calculate jump height instead // FIXME: move capturing the jump height value out of the HUD -float StrafeHUD_drawJumpHeight(entity e, bool onground, bool swimming, float text_offset_top) +float StrafeHUD_DrawJumpHeight(entity e, bool onground, bool swimming, float text_offset_top) { - float length_conversion_factor = GetLengthUnitFactor(autocvar_hud_speed_unit); + float length_conversion_factor = StrafeHUD_GetLengthUnitFactor(autocvar_hud_speed_unit); 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 @@ -193,9 +193,9 @@ float StrafeHUD_drawJumpHeight(entity e, bool onground, bool swimming, float tex float jumpheight_height = autocvar_hud_panel_strafehud_jumpheight_size * panel_size.y; string jumpheight_text = ftos_decimals(jumpheight * length_conversion_factor, length_decimals); if(autocvar_hud_panel_strafehud_unit_show) - jumpheight_text = strcat(jumpheight_text, GetLengthUnit(autocvar_hud_speed_unit)); + jumpheight_text = strcat(jumpheight_text, StrafeHUD_GetLengthUnit(autocvar_hud_speed_unit)); - bool was_drawn = StrafeHUD_drawTextIndicator( + bool was_drawn = StrafeHUD_DrawTextIndicator( jumpheight_text, jumpheight_height, autocvar_hud_panel_strafehud_jumpheight_color, autocvar_hud_panel_strafehud_jumpheight_fade, @@ -209,7 +209,7 @@ float StrafeHUD_drawJumpHeight(entity e, bool onground, bool swimming, float tex } // strafe efficiency -float StrafeHUD_drawStrafeEfficiency(float strafe_ratio, float text_offset_top) +float StrafeHUD_DrawStrafeEfficiency(float strafe_ratio, float text_offset_top) { { if(autocvar_hud_panel_strafehud_strafeefficiency) @@ -218,7 +218,7 @@ float StrafeHUD_drawStrafeEfficiency(float strafe_ratio, float text_offset_top) string strafeeff_text = strcat(ftos_decimals(strafe_ratio * 100, 2), "%"); vector strafeeff_color = '1 1 1' - (strafe_ratio > 0 ? '1 0 1' : '0 1 1') * fabs(strafe_ratio); - bool was_drawn = StrafeHUD_drawTextIndicator( + bool was_drawn = StrafeHUD_DrawTextIndicator( strafeeff_text, strafeeff_height, strafeeff_color, 1, time, text_offset_top, STRAFEHUD_TEXT_TOP); @@ -233,7 +233,7 @@ float StrafeHUD_drawStrafeEfficiency(float strafe_ratio, float text_offset_top) // show speed when crossing the start trigger // FIXME: move capturing the race start speed value out of the HUD -float StrafeHUD_drawStartSpeed(float speed, float text_offset_bottom) +float StrafeHUD_DrawStartSpeed(float speed, float text_offset_bottom) { static float startspeed = 0, starttime = 0; // displayed value and timestamp for fade out @@ -255,7 +255,7 @@ float StrafeHUD_drawStartSpeed(float speed, float text_offset_bottom) if(autocvar_hud_panel_strafehud_unit_show) startspeed_text = strcat(startspeed_text, GetSpeedUnit(autocvar_hud_speed_unit)); - bool was_drawn = StrafeHUD_drawTextIndicator( + bool was_drawn = StrafeHUD_DrawTextIndicator( startspeed_text, startspeed_height, autocvar_hud_panel_strafehud_startspeed_color, autocvar_hud_panel_strafehud_startspeed_fade, diff --git a/qcsrc/client/hud/panel/strafehud/extra.qh b/qcsrc/client/hud/panel/strafehud/extra.qh index 6129f235f..eab553e78 100644 --- a/qcsrc/client/hud/panel/strafehud/extra.qh +++ b/qcsrc/client/hud/panel/strafehud/extra.qh @@ -1,10 +1,10 @@ #pragma once #include "../strafehud.qh" -float StrafeHUD_drawJumpHeight(entity, bool, bool, float); -float StrafeHUD_drawStrafeEfficiency(float, float); -float StrafeHUD_drawStartSpeed(float, float); -float StrafeHUD_drawVerticalAngle(float); +float StrafeHUD_DrawSlickDetector(entity, bool); +float StrafeHUD_DrawVerticalAngle(float); void StrafeHUD_Sonar(float, string); string StrafeHUD_UpdateSonarSound(); -float StrafeHUD_DrawSlickDetector(entity, bool); +float StrafeHUD_DrawJumpHeight(entity, bool, bool, float); +float StrafeHUD_DrawStrafeEfficiency(float, float); +float StrafeHUD_DrawStartSpeed(float, float); diff --git a/qcsrc/client/hud/panel/strafehud/util.qc b/qcsrc/client/hud/panel/strafehud/util.qc index 51dc60b8f..02adbdbc2 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qc +++ b/qcsrc/client/hud/panel/strafehud/util.qc @@ -4,17 +4,17 @@ #include #include -float StrafeHUD_angleToWidth(float angle, float range) +float StrafeHUD_AngleToWidth(float angle, float range) { return angle / range * panel_size.x; } -float StrafeHUD_angleToOffset(float angle, float range) +float StrafeHUD_AngleToOffset(float angle, float range) { - return StrafeHUD_angleToWidth(angle, range) + panel_size.x / 2; + return StrafeHUD_AngleToWidth(angle, range) + panel_size.x / 2; } -float StrafeHUD_project(float ratio, float range, bool reverse) +float StrafeHUD_Project(float ratio, float range, bool reverse) { range *= DEG2RAD / 2; switch(autocvar_hud_panel_strafehud_projection) @@ -50,27 +50,27 @@ float StrafeHUD_project(float ratio, float range, bool reverse) return ratio; } -float StrafeHUD_projectOffset(float offset, float range, bool reverse) +float StrafeHUD_ProjectOffset(float offset, float range, bool reverse) { if(autocvar_hud_panel_strafehud_projection == STRAFEHUD_PROJECTION_LINEAR) return offset; float ratio = (offset - (panel_size.x / 2)) / (panel_size.x / 2); - ratio = StrafeHUD_project(ratio, range, reverse); + ratio = StrafeHUD_Project(ratio, range, reverse); offset = ratio * (panel_size.x / 2) + (panel_size.x / 2); return offset; } -float StrafeHUD_projectWidth(float offset, float width, float range) +float StrafeHUD_ProjectWidth(float offset, float width, float range) { if(autocvar_hud_panel_strafehud_projection == STRAFEHUD_PROJECTION_LINEAR) return width; - return StrafeHUD_projectOffset(offset + width, range, false) - StrafeHUD_projectOffset(offset, range, false); + return StrafeHUD_ProjectOffset(offset + width, range, false) - StrafeHUD_ProjectOffset(offset, range, false); } // length unit conversion (km and miles are only included to match the GetSpeedUnit* functions) -float GetLengthUnitFactor(int length_unit) +float StrafeHUD_GetLengthUnitFactor(int length_unit) { switch(length_unit) { @@ -83,7 +83,7 @@ float GetLengthUnitFactor(int length_unit) } } -string GetLengthUnit(int length_unit) +string StrafeHUD_GetLengthUnit(int length_unit) { switch(length_unit) { @@ -98,7 +98,7 @@ string GetLengthUnit(int length_unit) } // check the player waterlevel without affecting the player entity, this way we can fetch waterlevel even if client prediction is disabled -float DetectWaterLevel(entity e) +float StrafeHUD_DetermineWaterLevel(entity e) { // store old values void old_contentstransition(int, int) = e.contentstransition; @@ -118,7 +118,7 @@ float DetectWaterLevel(entity e) } // determine frametime -float DetectFrameTime() +float StrafeHUD_DetermineFrameTime() { static float dt_update = 0; static int dt_time = 0; @@ -152,7 +152,7 @@ float DetectFrameTime() } // determine player wishdir -float DetectWishAngle(vector movement, int keys, bool islocal) +float StrafeHUD_DetermineWishAngle(vector movement, int keys, bool islocal) { float wishangle; if(islocal) // if entity is local player @@ -203,7 +203,7 @@ float DetectWishAngle(vector movement, int keys, bool islocal) return wishangle; } -float StrafeHUD_determineHudAngle(float range_minangle) +float StrafeHUD_DetermineHudAngle(float range_minangle) { float hudangle; if(isnan(autocvar_hud_panel_strafehud_range)) @@ -244,7 +244,7 @@ float StrafeHUD_determineHudAngle(float range_minangle) } // determine whether the player is strafing left or right -float StrafeHUD_determineDirection(float angle, float wishangle, float antiflicker_angle) +float StrafeHUD_DetermineDirection(float angle, float wishangle, float antiflicker_angle) { if(wishangle > 0) { @@ -266,7 +266,7 @@ float StrafeHUD_determineDirection(float angle, float wishangle, float antiflick } // try to ignore if track_canjump is enabled, does not work in spectator mode if spectated player uses +jetpack or cl_movement_track_canjump -bool DetectJumpHeld(entity e, int keys, bool islocal) +bool StrafeHUD_DetermineJumpHeld(entity e, int keys, bool islocal) { if(islocal) { @@ -281,3 +281,14 @@ bool DetectJumpHeld(entity e, int keys, bool islocal) return false; } + +vector StrafeHUD_MixColors(vector color1, vector color2, float ratio) +{ + vector mixedColor; + if(ratio <= 0) return color1; + if(ratio >= 1) return color2; + mixedColor.x = color1.x + (color2.x - color1.x) * ratio; + mixedColor.y = color1.y + (color2.y - color1.y) * ratio; + mixedColor.z = color1.z + (color2.z - color1.z) * ratio; + return mixedColor; +} diff --git a/qcsrc/client/hud/panel/strafehud/util.qh b/qcsrc/client/hud/panel/strafehud/util.qh index ebe5b1ee5..b8963bebd 100644 --- a/qcsrc/client/hud/panel/strafehud/util.qh +++ b/qcsrc/client/hud/panel/strafehud/util.qh @@ -1,16 +1,17 @@ #pragma once #include "../strafehud.qh" -float GetLengthUnitFactor(int); -string GetLengthUnit(int); -float StrafeHUD_project(float, float, bool); -float StrafeHUD_projectOffset(float, float, bool); -float StrafeHUD_projectWidth(float, float, float); -float StrafeHUD_angleToWidth(float, float); -float StrafeHUD_angleToOffset(float, float); -float DetectWaterLevel(entity); -float DetectFrameTime(); -float DetectWishAngle(vector, int, bool); -float StrafeHUD_determineHudAngle(float); -float StrafeHUD_determineDirection(float, float, float); -bool DetectJumpHeld(entity, int, bool); +float StrafeHUD_AngleToWidth(float, float); +float StrafeHUD_AngleToOffset(float, float); +float StrafeHUD_Project(float, float, bool); +float StrafeHUD_ProjectOffset(float, float, bool); +float StrafeHUD_ProjectWidth(float, float, float); +float StrafeHUD_GetLengthUnitFactor(int); +string StrafeHUD_GetLengthUnit(int); +float StrafeHUD_DetermineWaterLevel(entity); +float StrafeHUD_DetermineFrameTime(); +float StrafeHUD_DetermineWishAngle(vector, int, bool); +float StrafeHUD_DetermineHudAngle(float); +float StrafeHUD_DetermineDirection(float, float, float); +bool StrafeHUD_DetermineJumpHeld(entity, int, bool); +vector StrafeHUD_MixColors(vector, vector, float); -- 2.39.2