From e39e1cf8eba568d2d074153b9a6029d6fcd0409f Mon Sep 17 00:00:00 2001 From: driAn Date: Sat, 24 Nov 2007 13:31:39 +0000 Subject: [PATCH] footstep sound channel freeing git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1439 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/sound.cpp | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/source/src/sound.cpp b/source/src/sound.cpp index 2df280f5..3c5083ff 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -264,6 +264,8 @@ void checkmapsounds() } VAR(footsteps, 0, 1, 1); +VAR(footstepradius, 0, 16, 25); +VAR(footstepalign, 5, 15, 4000); int findsoundloc(int sound, physent *p) { @@ -273,14 +275,31 @@ int findsoundloc(int sound, physent *p) void checkplayerloopsounds() { - if(footsteps) + if(findsoundloc(S_FOOTSTEPS, player1) == -1) playsound(S_FOOTSTEPS, player1); + loopv(players) { - if(findsoundloc(S_FOOTSTEPS, player1) == -1) playsound(S_FOOTSTEPS, player1); - loopv(players) + playerent *p = players[i]; + if(!p) continue; + + int idx = findsoundloc(S_FOOTSTEPS, p); + bool inuse = (idx >= 0 && soundlocs[idx].inuse); + + if(camera1->o.dist(p->o) < footstepradius && footsteps) { - playerent *p = players[i]; - if(!p) continue; - if(findsoundloc(S_FOOTSTEPS, p) == -1) playsound(S_FOOTSTEPS, p); + if(!inuse) // start sound + { + // sync to model animation + int basetime = -((int)(size_t)p&0xFFF); + int time = lastmillis-basetime; + int speed = 1860/p->maxspeed; + // TODO: share with model code + if(time%speed < footstepalign) playsound(S_FOOTSTEPS, p); + } + } + else if(inuse) // stop sound + { + Mix_HaltChannel(idx); + soundlocs[idx].sleep(); } } }