Add velocity/distance based footsteps

This commit is contained in:
Ricardo Luís Vaz Silva 2024-10-20 22:16:46 -03:00
parent 7b59642844
commit d07d08ce9f
4 changed files with 82 additions and 30 deletions

View file

@ -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)
DEFINE_FIELD(FTerrainDef, StepSound)
DEFINE_FIELD(FTerrainDef, StepDistance)
DEFINE_FIELD(FTerrainDef, StepDistanceMinVel)

View file

@ -119,6 +119,8 @@ struct FTerrainDef
double Friction;
double MoveFactor;
FSoundID StepSound;
double StepDistance;
double StepDistanceMinVel;
};
extern TArray<FSplashDef> Splashes;

View file

@ -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(Delay > 0 && (footstepCounter % Delay == 0))
{
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);
}
//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);
if((player.cmd.buttons ^ player.oldbuttons) & BT_RUN)
{ // zero out counters when starting/stopping a run
footstepCounter = 0;
footstepLength = Ground.StepDistance;
}
footstepCounter = (footstepCounter + 1) % (Delay * 2);
if(Ground.StepDistance > 0)
{ // distance-based terrain
footstepCounter = 0;
double moveVel = vel.xy.length();
if(moveVel > Ground.StepDistanceMinVel)
{
footstepLength += moveVel;
while(footstepLength > Ground.StepDistance)
{
footstepLength -= Ground.StepDistance;
DoFootstep(Ground);
}
}
else
{
footstepLength = Ground.StepDistance;
}
}
else if(Delay > 0)
{ // delay-based terrain
footstepLength = 0;
if(footstepCounter % Delay == 0)
{
DoFootstep(Ground);
}
footstepCounter = (footstepCounter + 1) % Delay;
}
}
else
{
footstepCounter = 0;
footstepLength = Ground.StepDistance;
footstepFoot = false;
}
}

View file

@ -614,6 +614,8 @@ struct TerrainDef native
native double Friction;
native double MoveFactor;
native Sound StepSound;
native double StepDistance;
native double StepDistanceMinVel;
};
enum EPickStart