From 6e5e02365c025e0c3229779f978349b7e085bbfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 20 Oct 2024 18:57:00 -0300 Subject: [PATCH 1/4] time footsteps with duration of movement, not with actor age --- wadsrc/static/zscript/actors/player/player.zs | 58 ++++++++++++------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index bba3d668cf0..c7da5e634ce 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -1728,39 +1728,55 @@ class PlayerPawn : Actor // //--------------------------------------------------------------------------- + int footstepCounter; + virtual void MakeFootsteps() { - if (pos.z > floorz) return; + if(pos.z > floorz) return; let Ground = GetFloorTerrain(); - let cmd = player.cmd; - if (Ground && (cmd.forwardMove != 0 || cmd.sideMove != 0)) + if(Ground && (player.cmd.forwardMove != 0 || player.cmd.sideMove != 0)) { - bool Running = (cmd.buttons & BT_RUN); //Holding down run key, or it's toggled. - int Delay = !Running ? Ground.WalkStepTics : Ground.RunStepTics; - - if (Delay <= 0 || GetAge() % Delay != 0) return; + int Delay = (player.cmd.buttons & BT_RUN) ? Ground.RunStepTics : Ground.WalkStepTics; - Sound Step = Ground.StepSound; + if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN) footstepCounter = 0; // zero out counter when starting/stopping a run - //Generic foot-agnostic sound takes precedence. - if (!Step) + if(Delay > 0 && (footstepCounter % Delay == 0)) { - //Apparently most people walk with their right foot first, so assume that here. - if (GetAge() % (Delay*2) == 0) - Step = Ground.LeftStepSound; - else - Step = Ground.RightStepSound; - } + Sound Step = Ground.StepSound; + + //Generic foot-agnostic sound takes precedence. + if(!Step) + { + //Apparently most people walk with their right foot first, so assume that here. + if (footstepCounter == 0) + { + Step = Ground.LeftStepSound; + } + else + { + Step = Ground.RightStepSound; + } + } + + if(Step) + { + A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume); + } - if (Step) - A_StartSound (Step,flags:CHANF_OVERLAP,volume:Ground.StepVolume); + //Steps make splashes regardless. + bool Heavy = (Mass >= 200) ? 0 : THW_SMALL; //Big player makes big splash. + HitWater(CurSector, (Pos.XY, CurSector.FloorPlane.ZatPoint(Pos.XY)), true, false, flags: Heavy | THW_NOVEL); + } - //Steps make splashes regardless. - bool Heavy = Mass >= 200 ? 0 : THW_SMALL; //Big player makes big splash. - HitWater (CurSector,(Pos.XY,CurSector.FloorPlane.ZatPoint(Pos.XY)),True,False,flags:Heavy|THW_NOVEL); + footstepCounter = (footstepCounter + 1) % (Delay * 2); } + else + { + footstepCounter = 0; + } + } //--------------------------------------------------------------------------- From 069d50f4c997ba78eb742f4c759e9285ef77b945 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 20 Oct 2024 21:42:17 -0300 Subject: [PATCH 2/4] make sure WalkStepTics and RunStepTics read ints, not floats --- src/gamedata/p_terrain.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/gamedata/p_terrain.cpp b/src/gamedata/p_terrain.cpp index 7aa3f8a4f3e..dfdb6e80141 100644 --- a/src/gamedata/p_terrain.cpp +++ b/src/gamedata/p_terrain.cpp @@ -96,7 +96,6 @@ enum EGenericType GEN_Splash, GEN_Float, GEN_Double, - GEN_Time, GEN_Bool, GEN_Int, GEN_Custom, @@ -217,8 +216,8 @@ static FGenericParse TerrainParser[] = { GEN_Int, {myoffsetof(FTerrainDef, DamageTimeMask)} }, { GEN_Double, {myoffsetof(FTerrainDef, FootClip)} }, { GEN_Float, {myoffsetof(FTerrainDef, StepVolume)} }, - { GEN_Time, {myoffsetof(FTerrainDef, WalkStepTics)} }, - { GEN_Time, {myoffsetof(FTerrainDef, RunStepTics)} }, + { GEN_Int, {myoffsetof(FTerrainDef, WalkStepTics)} }, + { GEN_Int, {myoffsetof(FTerrainDef, RunStepTics)} }, { GEN_Sound, {myoffsetof(FTerrainDef, LeftStepSound)} }, { GEN_Sound, {myoffsetof(FTerrainDef, RightStepSound)} }, { GEN_Bool, {myoffsetof(FTerrainDef, IsLiquid)} }, @@ -600,11 +599,6 @@ static void GenericParse (FScanner &sc, FGenericParse *parser, const char **keyw SET_FIELD(double, sc.Float); break; - case GEN_Time: - sc.MustGetFloat (); - SET_FIELD (int, (int)(sc.Float)); - break; - case GEN_Bool: SET_FIELD (bool, true); break; From 7094f20b165f5cef5275902ee443531e537dfd91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 20 Oct 2024 22:16:46 -0300 Subject: [PATCH 3/4] Add velocity/distance based footsteps --- src/gamedata/p_terrain.cpp | 8 +- src/gamedata/p_terrain.h | 2 + wadsrc/static/zscript/actors/player/player.zs | 82 ++++++++++++++----- wadsrc/static/zscript/doombase.zs | 2 + 4 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/gamedata/p_terrain.cpp b/src/gamedata/p_terrain.cpp index dfdb6e80141..0bb11237fbb 100644 --- a/src/gamedata/p_terrain.cpp +++ b/src/gamedata/p_terrain.cpp @@ -188,6 +188,8 @@ static const char *TerrainKeywords[] = "allowprotection", "damageonland", "stepsounds", + "stepdistance", + "stepdistanceminvel", NULL }; @@ -225,6 +227,8 @@ static FGenericParse TerrainParser[] = { GEN_Bool, {myoffsetof(FTerrainDef, AllowProtection)} }, { GEN_Bool, {myoffsetof(FTerrainDef, DamageOnLand)} }, { GEN_Sound, {myoffsetof(FTerrainDef, StepSound)} }, + { GEN_Double, {myoffsetof(FTerrainDef, StepDistance)} }, + { GEN_Double, {myoffsetof(FTerrainDef, StepDistanceMinVel)} }, }; @@ -744,4 +748,6 @@ DEFINE_FIELD(FTerrainDef, AllowProtection) DEFINE_FIELD(FTerrainDef, DamageOnLand) DEFINE_FIELD(FTerrainDef, Friction) DEFINE_FIELD(FTerrainDef, MoveFactor) -DEFINE_FIELD(FTerrainDef, StepSound) \ No newline at end of file +DEFINE_FIELD(FTerrainDef, StepSound) +DEFINE_FIELD(FTerrainDef, StepDistance) +DEFINE_FIELD(FTerrainDef, StepDistanceMinVel) \ No newline at end of file diff --git a/src/gamedata/p_terrain.h b/src/gamedata/p_terrain.h index c581ca3fd4a..6890a38cf97 100644 --- a/src/gamedata/p_terrain.h +++ b/src/gamedata/p_terrain.h @@ -119,6 +119,8 @@ struct FTerrainDef double Friction; double MoveFactor; FSoundID StepSound; + double StepDistance; + double StepDistanceMinVel; }; extern TArray Splashes; diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index c7da5e634ce..746ad806a52 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -1729,6 +1729,38 @@ class PlayerPawn : Actor //--------------------------------------------------------------------------- int footstepCounter; + double footstepLength; + bool footstepFoot; + + void DoFootstep(TerrainDef Ground) + { + Sound Step = Ground.StepSound; + + //Generic foot-agnostic sound takes precedence. + if(!Step) + { + //Apparently most people walk with their right foot first, so assume that here. + if (!footstepFoot) + { + Step = Ground.LeftStepSound; + } + else + { + Step = Ground.RightStepSound; + } + + footstepFoot = !footstepFoot; + } + + if(Step) + { + A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume); + } + + //Steps make splashes regardless. + bool Heavy = (Mass >= 200) ? 0 : THW_SMALL; //Big player makes big splash. + HitWater(CurSector, (Pos.XY, CurSector.FloorPlane.ZatPoint(Pos.XY)), true, false, flags: Heavy | THW_NOVEL); + } virtual void MakeFootsteps() { @@ -1740,41 +1772,51 @@ class PlayerPawn : Actor { int Delay = (player.cmd.buttons & BT_RUN) ? Ground.RunStepTics : Ground.WalkStepTics; - if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN) footstepCounter = 0; // zero out counter when starting/stopping a run + if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN) + { // zero out counters when starting/stopping a run + footstepCounter = 0; + footstepLength = Ground.StepDistance; + } - if(Delay > 0 && (footstepCounter % Delay == 0)) - { - Sound Step = Ground.StepSound; + if(Ground.StepDistance > 0) + { // distance-based terrain + footstepCounter = 0; - //Generic foot-agnostic sound takes precedence. - if(!Step) + double moveVel = vel.xy.length(); + + if(moveVel > Ground.StepDistanceMinVel) { - //Apparently most people walk with their right foot first, so assume that here. - if (footstepCounter == 0) - { - Step = Ground.LeftStepSound; - } - else + footstepLength += moveVel; + + while(footstepLength > Ground.StepDistance) { - Step = Ground.RightStepSound; + footstepLength -= Ground.StepDistance; + DoFootstep(Ground); } } - - if(Step) + else { - A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume); + footstepLength = Ground.StepDistance; } - //Steps make splashes regardless. - bool Heavy = (Mass >= 200) ? 0 : THW_SMALL; //Big player makes big splash. - HitWater(CurSector, (Pos.XY, CurSector.FloorPlane.ZatPoint(Pos.XY)), true, false, flags: Heavy | THW_NOVEL); } + else if(Delay > 0) + { // delay-based terrain + footstepLength = 0; + + if(footstepCounter % Delay == 0) + { + DoFootstep(Ground); + } - footstepCounter = (footstepCounter + 1) % (Delay * 2); + footstepCounter = (footstepCounter + 1) % Delay; + } } else { footstepCounter = 0; + footstepLength = Ground.StepDistance; + footstepFoot = false; } } diff --git a/wadsrc/static/zscript/doombase.zs b/wadsrc/static/zscript/doombase.zs index 2d88d01d0e5..7751e76cf68 100644 --- a/wadsrc/static/zscript/doombase.zs +++ b/wadsrc/static/zscript/doombase.zs @@ -614,6 +614,8 @@ struct TerrainDef native native double Friction; native double MoveFactor; native Sound StepSound; + native double StepDistance; + native double StepDistanceMinVel; }; enum EPickStart From 68dc14100900e0722ce988f9b9c810880e0fdfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Lu=C3=ADs=20Vaz=20Silva?= Date: Sun, 20 Oct 2024 22:17:16 -0300 Subject: [PATCH 4/4] add CVar to control footstep volume --- src/common/audio/sound/i_sound.cpp | 3 +++ wadsrc/static/zscript/actors/player/player.zs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/audio/sound/i_sound.cpp b/src/common/audio/sound/i_sound.cpp index dda757e8d78..4ca119b0b1d 100644 --- a/src/common/audio/sound/i_sound.cpp +++ b/src/common/audio/sound/i_sound.cpp @@ -62,6 +62,9 @@ CUSTOM_CVAR(Int, snd_samplerate, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, snd_buffersize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) CVAR(Int, snd_hrtf, -1, CVAR_ARCHIVE | CVAR_GLOBALCONFIG) +CVAR(Float, snd_footstepvolume, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) + + #if !defined(NO_OPENAL) #define DEF_BACKEND "openal" #else diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 746ad806a52..b320b62534e 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -1754,7 +1754,7 @@ class PlayerPawn : Actor if(Step) { - A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume); + A_StartSound(Step, flags: CHANF_OVERLAP, volume: Ground.StepVolume * snd_footstepvolume); } //Steps make splashes regardless.