From 540473cbe0c40aeca66259014b0c883ef3544abb Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sun, 12 Feb 2012 02:41:55 +0000 Subject: [PATCH] - Fixed: Sound limiting applied even to sounds that were already playing on the same actor+channel. Since in this case, it's really just restarting the sound, it shouldn't limit it. (Since it's already playing, we know the limit wasn't exceeded when it started playing, so it shouldn't be exceeded if we restart it now.) SVN r3355 (trunk) --- src/s_sound.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 4af92f46e2..726d71ef4e 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -101,7 +101,7 @@ extern float S_GetMusicVolume (const char *music); // PRIVATE FUNCTION PROTOTYPES --------------------------------------------- -static bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range); +static bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range, AActor *actor, int channel); static bool S_IsChannelUsed(AActor *actor, int channel, int *seen); static void S_ActivatePlayList(bool goBack); static void CalcPosVel(FSoundChan *chan, FVector3 *pos, FVector3 *vel); @@ -952,7 +952,7 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO // If this sound doesn't like playing near itself, don't play it if // that's what would happen. - if (near_limit > 0 && S_CheckSoundLimit(sfx, pos, near_limit, limit_range)) + if (near_limit > 0 && S_CheckSoundLimit(sfx, pos, near_limit, limit_range, actor, channel)) { chanflags |= CHAN_EVICTED; } @@ -1157,7 +1157,7 @@ void S_RestartSound(FSoundChan *chan) // If this sound doesn't like playing near itself, don't play it if // that's what would happen. - if (chan->NearLimit > 0 && S_CheckSoundLimit(&S_sfx[chan->SoundID], pos, chan->NearLimit, chan->LimitRange)) + if (chan->NearLimit > 0 && S_CheckSoundLimit(&S_sfx[chan->SoundID], pos, chan->NearLimit, chan->LimitRange, NULL, 0)) { return; } @@ -1389,12 +1389,19 @@ bool S_CheckSingular(int sound_id) // // Limits the number of nearby copies of a sound that can play near // each other. If there are NearLimit instances of this sound already -// playing within 256 units of the new sound, the new sound will not -// start. +// playing within sqrt(limit_range) (typically 256 units) of the new sound, the +// new sound will not start. +// +// If an actor is specified, and it is already playing the same sound on +// the same channel, this sound will not be limited. In this case, we're +// restarting an already playing sound, so there's no need to limit it. +// +// Returns true if the sound should not play. // //========================================================================== -bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range) +bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, float limit_range, + AActor *actor, int channel) { FSoundChan *chan; int count; @@ -1405,6 +1412,12 @@ bool S_CheckSoundLimit(sfxinfo_t *sfx, const FVector3 &pos, int near_limit, floa { FVector3 chanorigin; + if (actor != NULL && chan->EntChannel == channel && + chan->SourceType == SOURCE_Actor && chan->Actor == actor) + { // We are restarting a playing sound. Always let it play. + return false; + } + CalcPosVel(chan, &chanorigin, NULL); if ((chanorigin - pos).LengthSquared() <= limit_range) {