From fa63973b6aca84bff4adc7009a3d15e04da10e08 Mon Sep 17 00:00:00 2001 From: otta8634 Date: Tue, 1 Oct 2024 00:36:06 +0800 Subject: [PATCH] Change some common_physics vars to constants Most were only used once --- qcsrc/client/hud/common_physics.qc | 51 +++++++++++------------------ qcsrc/client/hud/common_physics.qh | 30 +++++++++-------- qcsrc/client/hud/panel/strafehud.qc | 4 +-- 3 files changed, 37 insertions(+), 48 deletions(-) diff --git a/qcsrc/client/hud/common_physics.qc b/qcsrc/client/hud/common_physics.qc index 41bdec95e..ed2c151eb 100644 --- a/qcsrc/client/hud/common_physics.qc +++ b/qcsrc/client/hud/common_physics.qc @@ -66,45 +66,32 @@ void HUD_Physics_Init() } // doesn't get changed by ground timeout and isn't affected by jump input - real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR); + real_onground = islocal ? IS_ONGROUND(strafeplayer) : !(strafeplayer.anim_implicit_state & ANIMIMPLICITSTATE_INAIR); // doesn't get changed by ground timeout - real_onslick = false; + real_onslick = false; // if jump is held assume we are in air, avoids flickering of the hud when hitting the ground - onground = (real_onground && !jumpheld); - onslick = real_onslick; + onground = (real_onground && !jumpheld); + onslick = real_onslick; // the hud will not work well while swimming - swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING; + swimming = strafe_waterlevel >= WATERLEVEL_SWIMMING; // use local csqcmodel entity for this even when spectating, flickers too much otherwise - vel_phys = csqcplayer.velocity; - speed_phys = vlen(vec2(vel_phys)); - speed3d_phys = vlen(vel_phys); - immobile = speed_phys <= 0; - - maxspeed_ground = PHYS_MAXSPEED(strafeplayer); - maxspeed_air = PHYS_MAXAIRSPEED(strafeplayer); - maxspeed_airstrafe = PHYS_MAXAIRSTRAFESPEED(strafeplayer); - maxaccel_ground = PHYS_ACCELERATE(strafeplayer); - maxaccel_air = PHYS_AIRACCELERATE(strafeplayer); - maxaccel_airstrafe = PHYS_AIRSTRAFEACCELERATE(strafeplayer); + vel_phys = csqcplayer.velocity; + speed_phys = vlen(vec2(vel_phys)); + speed3d_phys = vlen(vel_phys); + immobile = speed_phys <= 0; + // only the local csqcplayer entity contains this information even when spectating - maxspeed_mod = IS_DUCKED(csqcplayer) ? .5 : 1; - maxspeed_phys = onground ? maxspeed_ground : maxspeed_air; - maxspeed = maxspeed_phys * maxspeed_mod; - maxaccel_phys = onground ? maxaccel_ground : maxaccel_air; - maxaccel = maxaccel_phys; - stopspeed = PHYS_STOPSPEED(strafeplayer); - airstopaccel = PHYS_AIRSTOPACCELERATE(strafeplayer); - aircontrol = PHYS_AIRCONTROL(strafeplayer); - aircontrol_backwards = PHYS_AIRCONTROL_BACKWARDS(strafeplayer) == 1; - aircontrol_power = PHYS_AIRCONTROL_POWER(strafeplayer); - aircontrol_penalty = PHYS_AIRCONTROL_PENALTY(strafeplayer); - airaccel_qw = PHYS_AIRACCEL_QW(strafeplayer) == 1; - friction_phys = PHYS_FRICTION(strafeplayer); + maxspeed_mod = IS_DUCKED(csqcplayer) ? .5 : 1; + maxspeed_phys = onground ? maxspeed_ground : maxspeed_air; + maxspeed = maxspeed_phys * maxspeed_mod; + maxaccel_phys = onground ? maxaccel_ground : maxaccel_air; + maxaccel = maxaccel_phys; // change the range from 0° - 360° to -180° - 180° to match how view_angle represents angles - vel_angle = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0); - view_angle = PHYS_INPUT_ANGLES(strafeplayer).y; + vel_angle = vectoangles(strafeplayer.velocity).y - (vectoangles(strafeplayer.velocity).y > 180 ? 360 : 0); + view_angle = PHYS_INPUT_ANGLES(strafeplayer).y; + airstopaccel = PHYS_AIRSTOPACCELERATE(strafeplayer); if(!airstopaccel) airstopaccel = 1; // values of 0 are equivalent to 1 @@ -130,6 +117,6 @@ void HUD_Physics_Init() onground_lasttime = 0; } - strafefriction = onslick ? PHYS_FRICTION_SLICK(strafeplayer) : friction_phys; + strafefriction = onslick ? friction_slick : friction_phys; alive_player = (!IS_DEAD(strafeplayer) && IS_PLAYER(strafeplayer)); } diff --git a/qcsrc/client/hud/common_physics.qh b/qcsrc/client/hud/common_physics.qh index 89f1dccca..517a0a99b 100644 --- a/qcsrc/client/hud/common_physics.qh +++ b/qcsrc/client/hud/common_physics.qh @@ -25,28 +25,30 @@ vector vel_phys; // NOTE: physics hud previously did this: vector vel = (csqcpla float speed_phys; float speed3d_phys; bool immobile; -float maxspeed_ground; -float maxspeed_air; -float maxspeed_airstrafe; -float maxaccel_ground; -float maxaccel_air; -float maxaccel_airstrafe; float maxspeed_mod; float maxspeed_phys; float maxspeed; float maxaccel_phys; float maxaccel; -float stopspeed; -float airstopaccel; -float aircontrol; -bool aircontrol_backwards; -float aircontrol_power; -float aircontrol_penalty; -bool airaccel_qw; -float friction_phys; float vel_angle; float view_angle; +float airstopaccel; float onground_lasttime = 0; bool onslick_last = false; float strafefriction; bool alive_player; + +#define maxspeed_ground PHYS_MAXSPEED(strafeplayer) +#define maxspeed_air PHYS_MAXAIRSPEED(strafeplayer) +#define maxspeed_airstrafe PHYS_MAXAIRSTRAFESPEED(strafeplayer) +#define maxaccel_ground PHYS_ACCELERATE(strafeplayer) +#define maxaccel_air PHYS_AIRACCELERATE(strafeplayer) +#define maxaccel_airstrafe PHYS_AIRSTRAFEACCELERATE(strafeplayer) +#define stopspeed PHYS_STOPSPEED(strafeplayer) +#define aircontrol PHYS_AIRCONTROL(strafeplayer) +#define aircontrol_backwards PHYS_AIRCONTROL_BACKWARDS(strafeplayer) +#define aircontrol_power PHYS_AIRCONTROL_POWER(strafeplayer) +#define aircontrol_penalty PHYS_AIRCONTROL_PENALTY(strafeplayer) +#define airaccel_qw PHYS_AIRACCEL_QW(strafeplayer) +#define friction_phys PHYS_FRICTION(strafeplayer) +#define friction_slick PHYS_FRICTION_SLICK(strafeplayer) diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index 38e182bae..b2c74730a 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -537,8 +537,8 @@ void HUD_StrafeHUD() * ... so the angle will only be shown with hud_panel_strafehud_wturn_proper 0 * this doesn't have support for sv_aircontrol_sideways == 1 */ - bool wturning = !onground && wishangle == 0 && (keys_fwd == STRAFEHUD_KEYS_FORWARD || (aircontrol_backwards && keys_fwd == STRAFEHUD_KEYS_BACKWARD)); - bool wturn_valid = aircontrol && aircontrol_penalty == 0 && (airaccel_qw || autocvar_hud_panel_strafehud_wturn_unrestricted == 1); + bool wturning = !onground && wishangle == 0 && (keys_fwd == STRAFEHUD_KEYS_FORWARD || (aircontrol_backwards == 1 && keys_fwd == STRAFEHUD_KEYS_BACKWARD)); + bool wturn_valid = aircontrol && aircontrol_penalty == 0 && (airaccel_qw == 1 || autocvar_hud_panel_strafehud_wturn_unrestricted == 1); bool wturn_check = autocvar_hud_panel_strafehud_wturn && !immobile && wturn_valid; if(wturn_check) { -- 2.39.2