From 3b4479df44dbacd94b61bbe16087ec3219e97c1f Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Sat, 15 Nov 2008 01:01:04 +0000 Subject: [PATCH] - Removed GC barriers from the sound channels. If we must, we can always do it the old way and scan every channel to see if it matches an actor/ entchannel pair. - Fixed: S_RelinkSounds() did not move the SoundChans bitfield to the new actor. - Fixed: Stolen channels could be kept around by the high-level channels indefinitely. SVN r1289 (trunk) --- docs/rh-log.txt | 7 +++++++ src/s_sound.cpp | 13 ++++++++++--- src/s_sound.h | 3 +-- src/sound/fmodsound.cpp | 23 +++++++++++++++++------ src/sound/fmodsound.h | 2 +- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index bc7aaa6d2..4ad81a943 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,11 @@ November 14, 2008 +- Removed GC barriers from the sound channels. If we must, we can always + do it the old way and scan every channel to see if it matches an actor/ + entchannel pair. +- Fixed: S_RelinkSounds() did not move the SoundChans bitfield to the new + actor. +- Fixed: Stolen channels could be kept around by the high-level channels + indefinitely. - Fixed: AMageStaffFX2::IsOkayToAttack() / A_MStaffAttack aimed at friendlies. - Added kill count awareness to A_ChangeFlag. - P_NightmareRespawn() now clears the MTF_AMBUSH flag, so respawned monsters diff --git a/src/s_sound.cpp b/src/s_sound.cpp index 106b54981..8147d3d3f 100644 --- a/src/s_sound.cpp +++ b/src/s_sound.cpp @@ -1057,7 +1057,7 @@ static FSoundChan *S_StartSound(AActor *actor, const sector_t *sec, const FPolyO chan->SourceType = type; switch (type) { - case SOURCE_Actor: chan->Actor = actor; actor->SoundChans |= 1 << channel; GC::WriteBarrier(actor); break; + case SOURCE_Actor: chan->Actor = actor; actor->SoundChans |= 1 << channel; break; case SOURCE_Sector: chan->Sector = sec; break; case SOURCE_Polyobj: chan->Poly = poly; break; case SOURCE_Unattached: chan->Point[0] = pt->X; chan->Point[1] = pt->Y; chan->Point[2] = pt->Z; break; @@ -1497,7 +1497,6 @@ void S_RelinkSound (AActor *from, AActor *to) if (to != NULL) { chan->Actor = to; - GC::WriteBarrier(to); } else if (!(chan->ChanFlags & CHAN_LOOP)) { @@ -1509,11 +1508,15 @@ void S_RelinkSound (AActor *from, AActor *to) } else { - chan->Actor = NULL; S_StopChannel(chan); } } } + if (to != NULL) + { + to->SoundChans = from->SoundChans; + } + from->SoundChans = 0; } //========================================================================== @@ -1698,6 +1701,10 @@ void S_RestoreEvictedChannel(FSoundChan *chan) } } } + else if (chan->SysChannel == NULL && (chan->ChanFlags & (CHAN_FORGETTABLE | CHAN_LOOP)) == CHAN_FORGETTABLE) + { + S_ReturnChannel(chan); + } } //========================================================================== diff --git a/src/s_sound.h b/src/s_sound.h index 2aa9e5839..70238b889 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -178,10 +178,9 @@ struct FSoundChan : public FISoundChannel SBYTE Priority; SWORD NearLimit; BYTE SourceType; - TObjPtr Actor; union { - //AActor *Actor; // Used for position and velocity. + AActor *Actor; // Used for position and velocity. const sector_t *Sector; // Sector for area sounds. const FPolyObj *Poly; // Polyobject sound source. float Point[3]; // Sound is not attached to any source. diff --git a/src/sound/fmodsound.cpp b/src/sound/fmodsound.cpp index 2626e672c..994753ae5 100644 --- a/src/sound/fmodsound.cpp +++ b/src/sound/fmodsound.cpp @@ -1367,7 +1367,11 @@ FISoundChannel *FMODSoundRenderer::StartSound(SoundHandle sfx, float vol, int pi chan->setFrequency(freq); } chan->setVolume(vol); - HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq); + if (!HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq)) + { + chan->stop(); + return NULL; + } chan->setPaused(false); return CommonChannelSetup(chan, reuse_chan); } @@ -1461,7 +1465,11 @@ FISoundChannel *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener * chan->set3DAttributes((FMOD_VECTOR *)&pos[0], (FMOD_VECTOR *)&vel[0]); chan->set3DSpread(snd_3dspread); } - HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq); + if (!HandleChannelDelay(chan, reuse_chan, !!(flags & SNDF_ABSTIME), freq)) + { + chan->stop(); + return NULL; + } chan->setPaused(false); FISoundChannel *schan = CommonChannelSetup(chan, reuse_chan); schan->Rolloff = *rolloff; @@ -1477,12 +1485,14 @@ FISoundChannel *FMODSoundRenderer::StartSound3D(SoundHandle sfx, SoundListener * // // FMODSoundRenderer :: HandleChannelDelay // -// If the sound is restarting, seek it to its proper place. -// Otherwise, record its starting time. +// If the sound is restarting, seek it to its proper place. Returns false +// if the sound would have ended. +// +// Otherwise, record its starting time, and return true. // //========================================================================== -void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const +bool FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const { if (reuse_chan != NULL) { // Sound is being restarted, so seek it to the position @@ -1506,7 +1516,7 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FISoundChannel * QWORD difftime = nowtime.AsOne - reuse_chan->StartTime.AsOne; if (difftime > 0) { - chan->setPosition((unsigned int)(difftime / OutputRate), FMOD_TIMEUNIT_MS); + return chan->setPosition((unsigned int)(difftime / OutputRate), FMOD_TIMEUNIT_MS) == FMOD_OK; } } } @@ -1514,6 +1524,7 @@ void FMODSoundRenderer::HandleChannelDelay(FMOD::Channel *chan, FISoundChannel * { chan->setDelay(FMOD_DELAYTYPE_DSPCLOCK_START, DSPClock.Hi, DSPClock.Lo); } + return true; } //========================================================================== diff --git a/src/sound/fmodsound.h b/src/sound/fmodsound.h index 96340869c..21649d217 100644 --- a/src/sound/fmodsound.h +++ b/src/sound/fmodsound.h @@ -68,7 +68,7 @@ private: static FMOD_RESULT F_CALLBACK ChannelCallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, void *data1, void *data2); static float F_CALLBACK RolloffCallback(FMOD_CHANNEL *channel, float distance); - void HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const; + bool HandleChannelDelay(FMOD::Channel *chan, FISoundChannel *reuse_chan, bool abstime, float freq) const; FISoundChannel *CommonChannelSetup(FMOD::Channel *chan, FISoundChannel *reuse_chan) const; FMOD_MODE SetChanHeadSettings(SoundListener *listener, FMOD::Channel *chan, const FVector3 &pos, bool areasound, FMOD_MODE oldmode) const;