From: otta8634 Date: Wed, 25 Sep 2024 04:47:19 +0000 (+0800) Subject: Cleanup common_physics code X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=384dea470d2aa02634ebb53d2d6d68974278ba53;p=xonotic%2Fxonotic-data.pk3dir.git Cleanup common_physics code Relocated some more pieces of code to it Removed unnecessary cvars duplicating common_physics code things --- diff --git a/qcsrc/client/hud/common_physics.qc b/qcsrc/client/hud/common_physics.qc index 816703fdc..41bdec95e 100644 --- a/qcsrc/client/hud/common_physics.qc +++ b/qcsrc/client/hud/common_physics.qc @@ -5,8 +5,8 @@ #include // non-local players -#include // anim_implicit_state -#include // CSQCModel_server2csqc() +#include // for anim_implicit_state +#include // for CSQCModel_server2csqc() void HUD_Physics_Init() { @@ -66,44 +66,47 @@ 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; + + 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); // 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; + 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); // 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; + + if(!airstopaccel) + airstopaccel = 1; // values of 0 are equivalent to 1 if(onground) { diff --git a/qcsrc/client/hud/common_physics.qh b/qcsrc/client/hud/common_physics.qh index 37d574aae..89f1dccca 100644 --- a/qcsrc/client/hud/common_physics.qh +++ b/qcsrc/client/hud/common_physics.qh @@ -1,8 +1,9 @@ #pragma once -// Shared by panel/strafehud.qc and panel/physics.qc, since hud some elements require the same variables/calculations +// Shared by panel/strafehud.qc and panel/physics.qc, since some hud elements require the same variables/calculations // All PHYS_* macro calls are localised here // All csqcplayer related calls are also localised here +// These variables are all recomputed every time HUD_Main is called, since they could change during any frame void HUD_Physics_Init(); diff --git a/qcsrc/client/hud/panel/physics.qc b/qcsrc/client/hud/panel/physics.qc index f2133fb72..6d0461020 100644 --- a/qcsrc/client/hud/panel/physics.qc +++ b/qcsrc/client/hud/panel/physics.qc @@ -170,7 +170,7 @@ void HUD_Physics() } else { - if(vel_phys.z > prev_vel_z && jumpheld && !onground && !swimming && alive_player) + if(vel_phys.z > prev_vel_z && jumpheld && !real_onground && !swimming && alive_player) { //NOTE: this includes some situations where the player doesn't explicitly jump (e.g. jumppad, weapon kb) //excluding them would be difficult. maybe they can be left in? diff --git a/qcsrc/client/hud/panel/strafehud.qc b/qcsrc/client/hud/panel/strafehud.qc index ad302f310..38e182bae 100644 --- a/qcsrc/client/hud/panel/strafehud.qc +++ b/qcsrc/client/hud/panel/strafehud.qc @@ -436,9 +436,6 @@ void HUD_StrafeHUD() direction = STRAFEHUD_DIRECTION_NONE; } - if(airstopaccel == 0) - airstopaccel = 1; // values of 0 are equivalent to 1 - // best angle to strafe at if(immobile) { @@ -545,8 +542,7 @@ void HUD_StrafeHUD() bool wturn_check = autocvar_hud_panel_strafehud_wturn && !immobile && wturn_valid; if(wturn_check) { - float wturn_power = aircontrol_power; - if(wturn_power == 2) + if(aircontrol_power == 2) { float wturn_a = 32 * aircontrol * dt; float wturn_V = 1 - (wturn_a * wturn_a) / (speed * speed); @@ -556,9 +552,9 @@ void HUD_StrafeHUD() wturn_bestangle = ACOS_SQRT2_3_DEG; real_wturn_bestangle = wturn_bestangle; } - else if(!autocvar_hud_panel_strafehud_wturn_proper && wturn_power >= 0) + else if(!autocvar_hud_panel_strafehud_wturn_proper && aircontrol_power >= 0) { - wturn_bestangle = acos(sqrt(wturn_power / (wturn_power + 1))) * RAD2DEG; + wturn_bestangle = acos(sqrt(aircontrol_power / (aircontrol_power + 1))) * RAD2DEG; real_wturn_bestangle = wturn_bestangle; } else