From 003bc5d88abcdbb4e09f23840c9b4d8a12c818c7 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Tue, 1 Nov 2022 19:54:56 -0700 Subject: [PATCH] Removal of Footsteps_Update outside of NSClientPlayer. Mods now have the full ability to override steps within the player class. Method name subject to change. --- src/server/defs.h | 1 - src/server/footsteps.h | 3 +- src/server/footsteps.qc | 107 ----------------------------------- src/shared/NSClientPlayer.h | 2 + src/shared/NSClientPlayer.qc | 85 ++++++++++++++++++++++++++++ src/shared/NSEntity.qc | 1 + src/shared/player_pmove.qc | 3 + 7 files changed, 92 insertions(+), 110 deletions(-) diff --git a/src/server/defs.h b/src/server/defs.h index 48839ea9..b3b0efb5 100644 --- a/src/server/defs.h +++ b/src/server/defs.h @@ -94,7 +94,6 @@ var bool autocvar_mp_flashlight = true; void FX_Impact(impactType_t, vector, vector); void FX_Explosion(vector); void FX_GibHuman(vector vecOrigin, vector vecDir, float flForce); -void Footsteps_Update(void); void TraceAttack_FireBullets(int, vector, int, vector, int); #ifdef BULLETPENETRATION diff --git a/src/server/footsteps.h b/src/server/footsteps.h index 253c991e..bda334f4 100644 --- a/src/server/footsteps.h +++ b/src/server/footsteps.h @@ -14,5 +14,4 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -void Footsteps_Init(void); -void Footsteps_Update(void); +void Footsteps_Init(void); \ No newline at end of file diff --git a/src/server/footsteps.qc b/src/server/footsteps.qc index a5579aec..cfa67eb7 100644 --- a/src/server/footsteps.qc +++ b/src/server/footsteps.qc @@ -25,110 +25,3 @@ void Footsteps_Init(void) { } - -/* -================= -Footsteps_HLBSP - -Footstep code for BSP version 30, which uses an external materials.txt -to specify materials. -================= -*/ -void -Footsteps_HLBSP(NSClientPlayer target) -{ - string mat_name = ""; - string tex_name = ""; - string sound = ""; - - //tracebox(target.origin, PHY_HULL_MIN, PHY_HULL_MAX, target.origin + [0,0,-48], MOVE_NORMAL, target); - traceline(target.origin + target.view_ofs, target.origin + [0,0,-48], FALSE, target); - tex_name = getsurfacetexture(trace_ent, getsurfacenearpoint(trace_ent, trace_endpos)); - - if (!(target.flags & FL_ONGROUND)) { - return; - } else if (target.flags & FL_ONLADDER) { - mat_name = "step_ladder"; - - if (target.step) - Sound_Play(target, CHAN_BODY, sprintf("%s.left", mat_name)); - else - Sound_Play(target, CHAN_BODY, sprintf("%s.right", mat_name)); - - return; - } - - if (target.step) { - Sound_Play(target, CHAN_BODY, - SurfData_GetInfo(SurfData_TexToSurfData(tex_name), SURFDATA_SND_STEPLEFT)); - } else { - Sound_Play(target, CHAN_BODY, - SurfData_GetInfo(SurfData_TexToSurfData(tex_name), SURFDATA_SND_STEPRIGHT)); - } - -} - -/* -================= -Footsteps_Update - -Run every frame for each player, plays material based footsteps -================= -*/ -void -Footsteps_Update(void) -{ - NSClientPlayer pl; - - /* mp_footsteps is only available in MP matches */ - if (Util_IsSingleplayer() == false) - if (autocvar(mp_footsteps, 1) == 0) - return; - - if (self.classname != "player") - return; - - pl = (NSClientPlayer)self; - - if (pl.movetype == MOVETYPE_WALK) { - if ((pl.velocity[0] == 0 && pl.velocity[1] == 0) || pl.step_time > time) - return; - - if (pl.waterlevel == 1) { - if (pl.step) - Sound_Play(pl, CHAN_BODY, "step_slosh.left"); - else - Sound_Play(pl, CHAN_BODY, "step_slosh.right"); - - pl.step_time = time + 0.35f; - } else if (pl.waterlevel == 2) { - if (pl.step) - Sound_Play(pl, CHAN_BODY, "step_wade.left"); - else - Sound_Play(pl, CHAN_BODY, "step_wade.right"); - - pl.step_time = time + 1.0f; - } else if (pl.waterlevel == 3) { - if (pl.step) - Sound_Play(pl, CHAN_BODY, "step_swim.left"); - else - Sound_Play(pl, CHAN_BODY, "step_swim.right"); - - pl.step_time = time + 2.0f; - } else { - /* make it so we step once we land */ - if (!(pl.flags & FL_ONGROUND) && !(pl.flags & FL_ONLADDER)) { - pl.step_time = 0.0f; - return; - } - } - - /* the footsteps call might overwrite this later */ - pl.step_time = time + 0.35; - - Footsteps_HLBSP(pl); - - /* switch between feet */ - pl.step = 1 - pl.step; - } -} diff --git a/src/shared/NSClientPlayer.h b/src/shared/NSClientPlayer.h index d850cafe..7626dcb8 100644 --- a/src/shared/NSClientPlayer.h +++ b/src/shared/NSClientPlayer.h @@ -143,6 +143,8 @@ NSClientPlayer:NSClientSpectator virtual void(void) InputUse_Down; virtual void(void) InputUse_Up; #endif + + virtual void Footsteps_Update(void); }; /* all potential SendFlags bits we can possibly send */ diff --git a/src/shared/NSClientPlayer.qc b/src/shared/NSClientPlayer.qc index 4af1d838..8273ac46 100644 --- a/src/shared/NSClientPlayer.qc +++ b/src/shared/NSClientPlayer.qc @@ -1024,3 +1024,88 @@ NSClientPlayer::InputUse_Up(void) } } #endif + +void +NSClientPlayer::Footsteps_Update(void) +{ +#ifdef SERVER + string mat_name = ""; + string tex_name = ""; + string sound = ""; + + /* mp_footsteps is only available in MP matches */ + if (Util_IsSingleplayer() == false) + if (autocvar(mp_footsteps, 1) == 0) + return; + + if (movetype != MOVETYPE_WALK) + return; + + if ((velocity[0] == 0 && velocity[1] == 0) || step_time > time) + return; + + if (waterlevel == 1) { + if (step) + StartSoundDef("step_slosh.left", CHAN_BODY, true); + else + StartSoundDef("step_slosh.right", CHAN_BODY, true); + + step_time = time + 0.35f; + } else if (waterlevel == 2) { + if (step) + StartSoundDef("step_wade.left", CHAN_BODY, true); + else + StartSoundDef("step_wade.right", CHAN_BODY, true); + + step_time = time + 1.0f; + } else if (waterlevel == 3) { + if (step) + StartSoundDef("step_swim.left", CHAN_BODY, true); + else + StartSoundDef("step_swim.right", CHAN_BODY, true); + + step_time = time + 2.0f; + } else { + /* make it so we step once we land */ + if (!(flags & FL_ONGROUND) && !(flags & FL_ONLADDER)) { + step_time = 0.0f; + return; + } + } + + /* the footsteps call might overwrite this later */ + step_time = time + 0.35; + + //tracebox(origin, PHY_HULL_MIN, PHY_HULL_MAX, origin + [0,0,-48], MOVE_NORMAL, target); + traceline(origin + view_ofs, origin + [0,0,-48], FALSE, this); + tex_name = getsurfacetexture(trace_ent, getsurfacenearpoint(trace_ent, trace_endpos)); + + if (!(flags & FL_ONGROUND)) { + return; + } else if (flags & FL_ONLADDER) { + if (step) + StartSoundDef("step_ladder.left", CHAN_BODY, true); + else + StartSoundDef("step_ladder.right", CHAN_BODY, true); + + /* switch between feet */ + step = 1 - step; + return; + } + + if (step) { + StartSoundDef( + SurfData_GetInfo(SurfData_TexToSurfData(tex_name), SURFDATA_SND_STEPLEFT), + CHAN_BODY, + true); + } else { + StartSoundDef( + SurfData_GetInfo(SurfData_TexToSurfData(tex_name), SURFDATA_SND_STEPRIGHT), + CHAN_BODY, + true); + } + + /* switch between feet */ + step = 1 - step; +#endif +} diff --git a/src/shared/NSEntity.qc b/src/shared/NSEntity.qc index fd579324..3a9c51d3 100644 --- a/src/shared/NSEntity.qc +++ b/src/shared/NSEntity.qc @@ -1104,6 +1104,7 @@ NSEntity::StartSound(string strSample, float channel, float flags, bool broadcas bool NSEntity::StartSoundDef(string strSample, float channel, bool broadcast) { + NSLog("StartSoundDef: %s %d %d", strSample, channel, broadcast); Sound_Play(this, channel, strSample); return (true); } diff --git a/src/shared/player_pmove.qc b/src/shared/player_pmove.qc index 51b784b7..6b8022cc 100644 --- a/src/shared/player_pmove.qc +++ b/src/shared/player_pmove.qc @@ -385,6 +385,9 @@ NSClientPlayer::Physics_Run(void) /* give us a chance to manipulate input_ globals before running physics */ Physics_InputPreMove(); + /* handle footsteps */ + Footsteps_Update(); + /* handle drowning and other environmental factors */ Physics_WaterMove();