From 9418a6856e17bf68e97b4936cd2e88f8ccd9b558 Mon Sep 17 00:00:00 2001 From: driAn Date: Thu, 24 Jul 2008 22:05:50 +0000 Subject: [PATCH] proper sound relocation on camera-change, fixes stuff like local pain sounds git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2208 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/sound.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/source/src/sound.cpp b/source/src/sound.cpp index 22aceefb..f270e0bc 100644 --- a/source/src/sound.cpp +++ b/source/src/sound.cpp @@ -794,7 +794,7 @@ struct location : sourceowner p = d; e = NULL; - if(p==camera1) src->sourcerelative(true); + src->sourcerelative(p==camera1); } void attachtoworldobj(const vec *v) @@ -836,9 +836,7 @@ struct location : sourceowner { if(stale) return; - int s = src->state(); - - switch(s) + switch(src->state()) { case AL_PLAYING: updatepos(); @@ -898,21 +896,34 @@ struct locvector : vector delete loc; } - // give owner's locations a static position - void detachfromplayer(playerent *owner) + // reattach the owner again to his sound locations, + // can convert (previously) dynamic to static positions + void reattachphysent(physent *owner, bool staticpos) { if(!owner) return; loopv(*this) { location *l = buf[i]; if(!l || l->p != owner) continue; - l->attachtoworldobj(&l->p->o); + + if(staticpos) l->attachtoworldobj(&owner->o); // static reference + else l->attachtoworldobj(owner); // dynamic reference } } // update stuff, remove stale data void updatelocations() { + // check if camera carrier changed + static physent *lastcamera = NULL; + if(lastcamera!=camera1) + { + // reassign locations that depend on the previous camera carrier, position them correctly + if(lastcamera!=NULL) reattachphysent(lastcamera, false); + lastcamera = camera1; + } + + // update all locations loopv(*this) { location *l = buf[i]; @@ -1359,7 +1370,7 @@ COMMAND(voicecom, ARG_2STR); void detachsounds(playerent *owner) { - locations.detachfromplayer(owner); + locations.reattachphysent(owner, true); // make all dependent locations static } void soundtest()