Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Delay-based footsteps, and add velocity/distance based footsteps (and a CVar to control footstep volume) #2775

Merged
merged 4 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/audio/sound/i_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions src/gamedata/p_terrain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ enum EGenericType
GEN_Splash,
GEN_Float,
GEN_Double,
GEN_Time,
GEN_Bool,
GEN_Int,
GEN_Custom,
Expand Down Expand Up @@ -189,6 +188,8 @@ static const char *TerrainKeywords[] =
"allowprotection",
"damageonland",
"stepsounds",
"stepdistance",
"stepdistanceminvel",
NULL
};

Expand Down Expand Up @@ -217,15 +218,17 @@ 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)} },
{ GEN_Custom, {(size_t)ParseFriction} },
{ 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)} },
};


Expand Down Expand Up @@ -600,11 +603,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;
Expand Down Expand Up @@ -750,4 +748,6 @@ DEFINE_FIELD(FTerrainDef, AllowProtection)
DEFINE_FIELD(FTerrainDef, DamageOnLand)
DEFINE_FIELD(FTerrainDef, Friction)
DEFINE_FIELD(FTerrainDef, MoveFactor)
DEFINE_FIELD(FTerrainDef, StepSound)
DEFINE_FIELD(FTerrainDef, StepSound)
DEFINE_FIELD(FTerrainDef, StepDistance)
DEFINE_FIELD(FTerrainDef, StepDistanceMinVel)
2 changes: 2 additions & 0 deletions src/gamedata/p_terrain.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ struct FTerrainDef
double Friction;
double MoveFactor;
FSoundID StepSound;
double StepDistance;
double StepDistanceMinVel;
};

extern TArray<FSplashDef> Splashes;
Expand Down
98 changes: 78 additions & 20 deletions wadsrc/static/zscript/actors/player/player.zs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,39 +1728,97 @@ 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 * snd_footstepvolume);
}

//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()
{
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;
int Delay = (player.cmd.buttons & BT_RUN) ? Ground.RunStepTics : Ground.WalkStepTics;

if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN)
{ // zero out counters when starting/stopping a run
footstepCounter = 0;
footstepLength = Ground.StepDistance;
}

if (Delay <= 0 || GetAge() % Delay != 0) return;
if(Ground.StepDistance > 0)
{ // distance-based terrain
footstepCounter = 0;

Sound Step = Ground.StepSound;
double moveVel = vel.xy.length();

//Generic foot-agnostic sound takes precedence.
if (!Step)
{
//Apparently most people walk with their right foot first, so assume that here.
if (GetAge() % (Delay*2) == 0)
Step = Ground.LeftStepSound;
if(moveVel > Ground.StepDistanceMinVel)
{
footstepLength += moveVel;

while(footstepLength > Ground.StepDistance)
{
footstepLength -= Ground.StepDistance;
DoFootstep(Ground);
}
}
else
Step = Ground.RightStepSound;
}
{
footstepLength = Ground.StepDistance;
}

if (Step)
A_StartSound (Step,flags:CHANF_OVERLAP,volume:Ground.StepVolume);
}
else if(Delay > 0)
{ // delay-based terrain
footstepLength = 0;

if(footstepCounter % Delay == 0)
{
DoFootstep(Ground);
}

//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;
}
}
else
{
footstepCounter = 0;
footstepLength = Ground.StepDistance;
footstepFoot = false;
}

}

//---------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions wadsrc/static/zscript/doombase.zs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ struct TerrainDef native
native double Friction;
native double MoveFactor;
native Sound StepSound;
native double StepDistance;
native double StepDistanceMinVel;
};

enum EPickStart
Expand Down