Inside3D!
     

Engine Side Footsteps

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials
View previous topic :: View next topic  
Author Message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Mon Jan 04, 2010 8:18 pm    Post subject: Engine Side Footsteps Reply with quote

description: quick and dirty footstep sounds engine tutorial.
---------------------------------------------------------------------------------
purpose: adds footstep sounds to local gameplay.
---------------------------------------------------------------------------------
future expansion: different sounds for different surfaces and different speeds.
---------------------------------------------------------------------------------
First thing we need to do is precache the sound effects internally in the engine.

Open up cl_tent.c

near the top of the file look for the other sound effects precaches
and add these under sfx_t *cl_sfx_r_exp3,

Code:

sfx_t      *cl_sfx_step1;
sfx_t      *cl_sfx_step2;
sfx_t      *cl_sfx_step3;
sfx_t      *cl_sfx_step4;


scroll down and find void CL_InitTEnts (void)
and add these precaches to be initialized.
Code:

   cl_sfx_step1      = S_PrecacheSound ("misc/step1.wav");   
   cl_sfx_step2      = S_PrecacheSound ("misc/step2.wav");   
   cl_sfx_step3      = S_PrecacheSound ("misc/step3.wav");      
   cl_sfx_step4      = S_PrecacheSound ("misc/step4.wav");   


NOTE: you are going to have to find your own .wav files for the sounds and put them in quake/id1/sound/misc

okay now open up cl_main.c

near the top around all the other cvar_t definitions add,

Code:

cvar_t   cl_footsteps      = {"cl_footsteps", "0", true};


now look for CL_Init and register the variable,

Code:

     Cvar_RegisterVariable (&cl_footsteps);   


Scroll back to the top of the file in cl_main.c and add this code block prior to CL_RelinkEntities,

Code:

void CL_Footsteps(entity_t   *ent, int frame)
{
   extern   sfx_t      *cl_sfx_step1;
   extern   sfx_t      *cl_sfx_step2;
   extern   sfx_t      *cl_sfx_step3;
   extern   sfx_t      *cl_sfx_step4;

   if (ent->steptime > cl.time)//Timer to sync with player animations
      return;

   if (ent != &cl_entities[cl.viewentity])//check if it's our player
      return; //only play our OWN footsteps! no multiplayer hax!
   
   if (TruePointContents(ent->origin) != CONTENTS_EMPTY)// if in water etc.. no sound
      return;

   if (frame == 2 || frame == 5 ||   frame == 7 || frame == 10)//check for run frames
   {
      vec3_t   dest, forward, right,up;
      trace_t   trace;
      float f;
      int   i,e;
      entity_t *p;

      AngleVectors (ent->angles, forward, right, up);
      
      VectorMA (ent->origin, -32, up, dest);//trace down
         
      memset (&trace, 0, sizeof(trace_t));

      trace.fraction = 1;

      SV_RecursiveHullCheck(cl.worldmodel->hulls, 0, 0, 1, ent->origin, dest, &trace);

      if (trace.fraction == 1) //if we didnt hit anything solid  dont make a sound
      {         
              ent->steptime = cl.time + 0.1;//since the player model animates at 10 frames per sec, no need to come back here until time + 1/10...
         return;
      }
      
      f = (rand()%4)+1;

      e = (int)cl.viewentity;//emit the sound at our location
      
      if (f == 1)
         S_StartSound(e, 0, cl_sfx_step1, ent->origin, 0.40f, 1.0f);
      else if (f == 2)
         S_StartSound(e, 0, cl_sfx_step2, ent->origin, 0.40f, 1.0f);
      else if (f == 3)
         S_StartSound(e, 0, cl_sfx_step3, ent->origin, 0.40f, 1.0f);
      else
         S_StartSound(e, 0, cl_sfx_step4, ent->origin, 0.40f, 1.0f);
      
      ent->steptime = cl.time + 0.3;
   }
}


now scroll down into CL_RelinkEntites and add this bit of code before ent->forcelink = true;

Code:

      if (cl_footsteps.value)
         CL_Footsteps(ent,ent->frame);


one last thing we need to do is add a timer to make the sound, so open up render.h and find the entity_s definition and add
to the end, like this
Code:

   double   steptime;
} entity_t;
Back to top
View user's profile Send private message
Team Xlink



Joined: 25 Jun 2009
Posts: 320

PostPosted: Mon Jan 04, 2010 8:40 pm    Post subject: Reply with quote

This is a very good tutorial and has much use to avoid tricky qc code. It allows you to play have sounds for footsteps in all mods. Thank you.

I am still intrigued by your mention of the future expansion's different footsteps for different surfaces, this would be great.

For example your running in a shallow puddle of water so you want to hear the small splash sounds, then you come up to a middle surface it then plays the ting sounds, so on and so fourth.

EDIT: Does anyone have any good sound files for this? My sound files aren't that good.
_________________
Anonymous wrote:
if it works, it works. if it doesn't, HAHAHA!
Back to top
View user's profile Send private message
Downsider



Joined: 16 Sep 2008
Posts: 478

PostPosted: Mon Jan 04, 2010 9:56 pm    Post subject: Reply with quote

I'm pretty sure that when you trace against a face in the engine you can grab its texture name directly from the information returned, which could easily be your solution to getting surface-specific sounds.
Back to top
View user's profile Send private message
Baker



Joined: 14 Mar 2006
Posts: 1538

PostPosted: Mon Jan 04, 2010 9:58 pm    Post subject: Re: Engine Side Footsteps Reply with quote

Is there a way to query what texture a player is walking on (Surface flags) like in Half-Life?

For instance, to play a different wav if the texture begins with "stone_" or "metal_".
Back to top
View user's profile Send private message
goldenboy



Joined: 05 Sep 2008
Posts: 310
Location: Kiel

PostPosted: Mon Jan 04, 2010 10:23 pm    Post subject: Reply with quote

Some of the multiplayer types argue that footsteps are bad, or cheating.

Also, mods will want to use their own footstep sounds, plus monster footsteps, like RemakeQuake does.

It's not really hard to do in QC - I think this should be left to individual mods. See RMQ source.

I would get pissed if an engine "overwrote" my carefully selected and randomized footstep sounds.

Edit: It would be nice, however, if the engine provided surface detection which could then be used by the footstep QC code.
_________________
ReMakeQuake
The Realm of Blog Magic
Back to top
View user's profile Send private message
r00k



Joined: 13 Nov 2004
Posts: 483

PostPosted: Mon Jan 04, 2010 10:50 pm    Post subject: Reply with quote

Actually this doesnt provide a hack for multiplayer at all because it only plays your own footsteps. Also this shouldnt piss off modders cause it doesnt change monsters footsteps and the player footstep sounds can be copied to /sounds/misc. I think i would map out areas based on the origin, like how .locs are used. have an .fsm (footstep materail) file defined. That way at runtime im just comparing location to array not traceline collision detection.

It can be expanded to have custom monster sounds. The only real benefit of this is adding footsteps to mods that dont have them.

I think you are in your right that if your mod supports footsteps there should be a SVC_ trigger or ruleset or atleast you can stuffcmd to the client "cl_footstep 0\n", that way it will use your media/code instead.


Last edited by r00k on Mon Jan 04, 2010 11:02 pm; edited 2 times in total
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Mon Jan 04, 2010 10:54 pm    Post subject: Re: Engine Side Footsteps Reply with quote

Baker wrote:
Is there a way to query what texture a player is walking on (Surface flags) like in Half-Life?

For instance, to play a different wav if the texture begins with "stone_" or "metal_".

R_LightPoint will give you it. Very Happy

I'm in two minds though about doing this via QC in preference to the engine. A part of me wants to agree bigtime, but another part of me says that the engine has access to so much more info than QC does, and that doing it via the engine gives players the option to switch footsteps off by a cvar if they find them annoying. And players are the most important thing at the end of the day, aren't they?

I reckon the engine wins this one so far as I'm concerned. Perhaps a good meet-in-the-middle option might be to make this footstep code extensible via QC (it would need to move to server-side for that, but shouldn't need a new protocol as the standard server-side sound spawning should work fine).

Say let QC control the volume, the sounds used, etc. Provide some new builtins and we're done.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
goldenboy



Joined: 05 Sep 2008
Posts: 310
Location: Kiel

PostPosted: Tue Jan 05, 2010 1:41 am    Post subject: Reply with quote

Yes, QC / the mod needs to control the sounds used and how they are used. There can be default sounds that the engine would supply, but as soon as a mod brings its own sound files along, control should shift to the mod.

RMQ uses much more than 4 footstep sound files, too. So that would be a possible clash. Requiring mods to provide exactly n footstep sounds is problematic. The engine should only offer an interface to the mod.

An engine that played the crappy hipnotic footsteps instead of the RMQ ones would make me want to shoot somebody.

Finally, disabling footstep sounds should be done by the mod, too, possibly via an impulse.
_________________
ReMakeQuake
The Realm of Blog Magic
Back to top
View user's profile Send private message
Teiman



Joined: 03 Jun 2007
Posts: 309

PostPosted: Fri Jan 08, 2010 4:18 pm    Post subject: Reply with quote

Telejano has footsteps builtin, I even have different sounds for different mosters.

Is a nice feature, and really adds to the game.
Back to top
View user's profile Send private message
mh



Joined: 12 Jan 2008
Posts: 909

PostPosted: Fri Jan 08, 2010 4:20 pm    Post subject: Reply with quote

goldenboy wrote:
Finally, disabling footstep sounds should be done by the mod, too, possibly via an impulse.
So long as it doesn't override what the player wants I'd agree.
_________________
DirectQ Engine - New release 1.8.666a, 9th August 2010
MHQuake Blog (General)
Direct3D 8 Quake Engines
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> Programming Tutorials All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group