]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Cleanup common_physics code
authorotta8634 <k9wolf@pm.me>
Wed, 25 Sep 2024 04:47:19 +0000 (12:47 +0800)
committerotta8634 <k9wolf@pm.me>
Wed, 25 Sep 2024 04:47:19 +0000 (12:47 +0800)
Relocated some more pieces of code to it
Removed unnecessary cvars duplicating common_physics code things

qcsrc/client/hud/common_physics.qc
qcsrc/client/hud/common_physics.qh
qcsrc/client/hud/panel/physics.qc
qcsrc/client/hud/panel/strafehud.qc

index 816703fdc1bf4b5c9e99a6ba16f707f6aca97845..41bdec95e72ac04903f51d6cdfbdc7752929ae07 100644 (file)
@@ -5,8 +5,8 @@
 #include <common/physics/movetypes/movetypes.qh>
 
 // non-local players
-#include <common/animdecide.qh> // anim_implicit_state
-#include <common/ent_cs.qh> // CSQCModel_server2csqc()
+#include <common/animdecide.qh> // for anim_implicit_state
+#include <common/ent_cs.qh> // 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)
        {
index 37d574aaeb7862ef3283711adffbb9f3dcf9353d..89f1dccca74fd5665dda7341cbe84e15f5aba24a 100644 (file)
@@ -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();
 
index f2133fb72bc87b18bce60225fec68a94d2a931ee..6d04610201177488209120835d030634a4a97b9e 100644 (file)
@@ -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?
index ad302f310fd25a341546c857fafeac47fef2d7e4..38e182bae986e450e1661d1b09f27161c4b19c78 100644 (file)
@@ -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