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);
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;
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
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;
}
}
- float dt = DetectFrameTime();
+ float dt = StrafeHUD_DetermineFrameTime();
maxaccel *= dt * movespeed;
float bestspeed = max(movespeed - maxaccel, 0); // target speed to gain maximum acceleration
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
{
}
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));
}
{
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)
}
}
- 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());
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,
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,
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,
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,
// 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,
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,
// 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);
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);
}
#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);
#include <client/draw.qh>
// 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;
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)
{
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)
{
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;
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;
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);
}
// 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;
#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);
}
// 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)
{
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);
// 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
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,
}
// 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)
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);
// 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
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,
#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);
#include <common/physics/player.qh>
#include <common/physics/movetypes/movetypes.qh>
-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)
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)
{
}
}
-string GetLengthUnit(int length_unit)
+string StrafeHUD_GetLengthUnit(int length_unit)
{
switch(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;
}
// determine frametime
-float DetectFrameTime()
+float StrafeHUD_DetermineFrameTime()
{
static float dt_update = 0;
static int dt_time = 0;
}
// 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
return wishangle;
}
-float StrafeHUD_determineHudAngle(float range_minangle)
+float StrafeHUD_DetermineHudAngle(float range_minangle)
{
float hudangle;
if(isnan(autocvar_hud_panel_strafehud_range))
}
// 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)
{
}
// 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)
{
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;
+}
#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);