From 50cfcde8abd7667880cab4eb051070b533fad73b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Mon, 23 Sep 2019 16:28:49 -0400 Subject: [PATCH] Code style cleanup pass through plAudioSystem.cpp. --- .../PubUtilLib/plAudio/plAudioSystem.cpp | 528 ++++++++---------- 1 file changed, 238 insertions(+), 290 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp index 98f2399678..4267654682 100644 --- a/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp +++ b/Sources/Plasma/PubUtilLib/plAudio/plAudioSystem.cpp @@ -87,77 +87,69 @@ class plSoftSoundNode { public: const plKey fSoundKey; - float fRank; + float fRank; - plSoftSoundNode *fNext; - plSoftSoundNode **fPrev; + plSoftSoundNode* fNext; + plSoftSoundNode** fPrev; - plSoftSoundNode *fSortNext; - plSoftSoundNode **fSortPrev; + plSoftSoundNode* fSortNext; + plSoftSoundNode** fSortPrev; plSoftSoundNode(const plKey& s) : fSoundKey(s), fNext(), fPrev(), fSortNext(), fSortPrev() { } ~plSoftSoundNode() { Unlink(); } - void Link( plSoftSoundNode **prev ) + void Link(plSoftSoundNode** prev) { fNext = *prev; fPrev = prev; - if( fNext != nil ) + if (fNext) fNext->fPrev = &fNext; *prev = this; } - void Unlink( void ) + void Unlink() { - if( fPrev != nil ) - { + if (fPrev) { *fPrev = fNext; - if( fNext ) + if (fNext) fNext->fPrev = fPrev; - fPrev = nil; - fNext = nil; + fPrev = nullptr; + fNext = nullptr; } } - void SortedLink( plSoftSoundNode **prev, float rank ) + void SortedLink(plSoftSoundNode** prev, float rank) { fRank = rank; fSortNext = *prev; fSortPrev = prev; - if( fSortNext != nil ) + if (fSortNext) fSortNext->fSortPrev = &fSortNext; *prev = this; } // Larger values are first in the list - void AddToSortedLink( plSoftSoundNode *toAdd, float rank ) + void AddToSortedLink(plSoftSoundNode* toAdd, float rank) { - if( fRank > rank ) - { - if( fSortNext != nil ) - fSortNext->AddToSortedLink( toAdd, rank ); + if (fRank > rank) { + if (fSortNext) + fSortNext->AddToSortedLink(toAdd, rank); else - { - toAdd->SortedLink( &fSortNext, rank ); - } - } - else - { + toAdd->SortedLink(&fSortNext, rank); + } else { // Cute trick here... - toAdd->SortedLink( fSortPrev, rank ); + toAdd->SortedLink(fSortPrev, rank); } } - void BootSourceOff( void ) + void BootSourceOff( void ) { - plSound *sound = plSound::ConvertNoRef( fSoundKey->ObjectIsLoaded() ); - if( sound != nil ) - { + plSound* sound = plSound::ConvertNoRef(fSoundKey->ObjectIsLoaded()); + if (sound) sound->ForceUnregisterFromAudioSys(); - } } }; @@ -411,15 +403,28 @@ void plAudioSystem::Shutdown() void plAudioSystem::SetDistanceModel(int i) { - switch(i) - { - case 0: alDistanceModel(AL_NONE); break; - case 1: alDistanceModel(AL_INVERSE_DISTANCE ); break; - case 2: alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); break; - case 3: alDistanceModel(AL_LINEAR_DISTANCE ); break; - case 4: alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED ); break; - case 5: alDistanceModel(AL_EXPONENT_DISTANCE ); break; - case 6: alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED); break; + switch(i) { + case 0: + alDistanceModel(AL_NONE); + break; + case 1: + alDistanceModel(AL_INVERSE_DISTANCE ); + break; + case 2: + alDistanceModel(AL_INVERSE_DISTANCE_CLAMPED); + break; + case 3: + alDistanceModel(AL_LINEAR_DISTANCE ); + break; + case 4: + alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED ); + break; + case 5: + alDistanceModel(AL_EXPONENT_DISTANCE ); + break; + case 6: + alDistanceModel(AL_EXPONENT_DISTANCE_CLAMPED); + break; } } @@ -430,7 +435,7 @@ void plAudioSystem::SetMaxNumberOfActiveSounds() int maxNumSounds = 24; // Keep this to a reasonable amount based on the users hardware, since we want the sounds to be played in hardware - if (maxNumSounds > fMaxNumSources && fMaxNumSources != 0 ) + if (maxNumSounds > fMaxNumSources && fMaxNumSources != 0) maxNumSounds = fMaxNumSources / 2; // Allow a certain number of sounds based on a user specified setting. @@ -461,13 +466,12 @@ void plAudioSystem::SetListenerOrientation(const hsVector3& view, const hsVector alListenerfv(AL_ORIENTATION, orientation); } -void plAudioSystem::SetActive( bool b ) +void plAudioSystem::SetActive(bool b) { fActive = b; - if( fActive ) - { + if (fActive) { // Clear to send activate message (if listener not inited yet, delay until then) - plgDispatch::MsgSend( new plAudioSysMsg( plAudioSysMsg::kActivate ) ); + plgDispatch::MsgSend(new plAudioSysMsg(plAudioSysMsg::kActivate)); } } @@ -479,40 +483,34 @@ void plAudioSystem::SetActive( bool b ) // need to be recalced, just resorted. void plAudioSystem::RegisterSoftSound(const plKey& soundKey) { - plSoftSoundNode *node = new plSoftSoundNode( soundKey ); - node->Link( &fSoftRegionSounds ); + plSoftSoundNode *node = new plSoftSoundNode(soundKey); + node->Link(&fSoftRegionSounds); - fCurrDebugSound = nil; - plSound::SetCurrDebugPlate( nil ); + fCurrDebugSound = nullptr; + plSound::SetCurrDebugPlate(nullptr); } //// IUnregisterSoftSound //////////////////////////////////////////////////// void plAudioSystem::UnregisterSoftSound(const plKey& soundKey) { - plSoftSoundNode *node; - for( node = fActiveSofts; node != nil; node = node->fNext ) - { - if( node->fSoundKey == soundKey ) - { + for (plSoftSoundNode* node = fActiveSofts; node; node = node->fNext ) { + if (node->fSoundKey == soundKey) { delete node; return; } } - for( node = fSoftRegionSounds; node != nil; node = node->fNext ) - { - if( node->fSoundKey == soundKey ) - { + for (plSoftSoundNode* node = fSoftRegionSounds; node; node = node->fNext) { + if( node->fSoundKey == soundKey ) { delete node; return; } } // We might have unregistered it ourselves on destruction, so don't bother - - fCurrDebugSound = nil; - plSound::SetCurrDebugPlate( nil ); + fCurrDebugSound = nullptr; + plSound::SetCurrDebugPlate(nullptr); } //// IUpdateSoftSounds /////////////////////////////////////////////////////// @@ -543,140 +541,123 @@ void plAudioSystem::UnregisterSoftSound(const plKey& soundKey) // full strength, we divide the soft volume ranks by the distSquared, thus // giving us a reasonable approximation at a good rank... -void plAudioSystem::IUpdateSoftSounds( const hsPoint3 &newPosition ) +void plAudioSystem::IUpdateSoftSounds(const hsPoint3 &newPosition) { - plSoftSoundNode *node, *myNode; - float distSquared, rank; - plSoftSoundNode *sortedList = nil; - int32_t i; - + plSoftSoundNode* myNode; + float distSquared, rank; + plSoftSoundNode *sortedList = nullptr; + int32_t i; + plProfile_BeginTiming(SoundSoftUpdate); - + // Check the sounds the listener is already inside of. If we moved out, stop sound, else // just change attenuation - for( node = fActiveSofts; node != nil; ) - { - plSound *sound = plSound::ConvertNoRef( node->fSoundKey->ObjectIsLoaded() ); + for (plSoftSoundNode* node = fActiveSofts; node; ) { + plSound* sound = plSound::ConvertNoRef( node->fSoundKey->ObjectIsLoaded() ); bool notActive = false; - if(sound) + if (sound) sound->Update(); - + // Quick checks for not-active - if( sound == nil ) + if (!sound) notActive = true; - else if( !sound->IsWithinRange( newPosition, &distSquared ) ) + else if(!sound->IsWithinRange(newPosition, &distSquared)) notActive = true; - else if(sound->GetPriority() > plgAudioSys::GetPriorityCutoff()) + else if (sound->GetPriority() > plgAudioSys::GetPriorityCutoff()) notActive = true; if(plgAudioSys::fMutedStateChange) - { sound->SetMuted(plgAudioSys::fMuted); - } - - if( !notActive ) - { - /// Our initial guess is that it's enabled... + + if (!notActive) { + // Our initial guess is that it's enabled... sound->CalcSoftVolume( true, distSquared ); rank = sound->GetVolumeRank(); - if( rank <= 0.f ) + if (rank <= 0.f) { notActive = true; - else - { - /// Queue up in our sorted list... - if( sortedList == nil ) - node->SortedLink( &sortedList, (10.0f - sound->GetPriority()) * rank ); + } else { + // Queue up in our sorted list... + if (!sortedList) + node->SortedLink(&sortedList, (10.0f - sound->GetPriority()) * rank); else - sortedList->AddToSortedLink( node, (10.0f - sound->GetPriority()) * rank ); - /// Still in radius, so consider it still "active". + sortedList->AddToSortedLink(node, (10.0f - sound->GetPriority()) * rank); + // Still in radius, so consider it still "active". node = node->fNext; } } - if( notActive ) - { - /// Moved out of range of the sound--stop the sound entirely and move it to our - /// yeah-they're-registered-but-not-active list + if (notActive) { + // Moved out of range of the sound--stop the sound entirely and move it to our + // yeah-they're-registered-but-not-active list myNode = node; node = node->fNext; myNode->Unlink(); - myNode->Link( &fSoftRegionSounds ); + myNode->Link(&fSoftRegionSounds); - /// We know this sound won't be enabled, so skip the Calc() call - if( sound != nil ) - sound->UpdateSoftVolume( false ); + // We know this sound won't be enabled, so skip the Calc() call + if (sound) + sound->UpdateSoftVolume(false); } } - + // Now check remaining sounds to see if the listener moved into them - for( node = fSoftRegionSounds; node != nil; ) - { - if( !fListenerInit ) - { + for (plSoftSoundNode* node = fSoftRegionSounds; node;) { + if (!fListenerInit) { node = node->fNext; continue; } - - plSound *sound = plSound::ConvertNoRef( node->fSoundKey->ObjectIsLoaded() ); - if( !sound || sound->GetPriority() > plgAudioSys::GetPriorityCutoff() ) - { + + plSound* sound = plSound::ConvertNoRef(node->fSoundKey->ObjectIsLoaded()); + if(!sound || sound->GetPriority() > plgAudioSys::GetPriorityCutoff()) { node = node->fNext; continue; } sound->Update(); - if(plgAudioSys::fMutedStateChange) - { + if (plgAudioSys::fMutedStateChange) sound->SetMuted(plgAudioSys::fMuted); - } - - if( sound->IsWithinRange( newPosition, &distSquared ) ) - { - /// Our initial guess is that it's enabled... - sound->CalcSoftVolume( true, distSquared ); + + if (sound->IsWithinRange(newPosition, &distSquared)) { + // Our initial guess is that it's enabled... + sound->CalcSoftVolume(true, distSquared); rank = sound->GetVolumeRank(); - if( rank > 0.f ) - { - /// We just moved into its range, so move it to our active list and start the sucker + if (rank > 0.f) { + // We just moved into its range, so move it to our active list and start the sucker myNode = node; node = node->fNext; myNode->Unlink(); - myNode->Link( &fActiveSofts ); + myNode->Link(&fActiveSofts); - /// Queue up in our sorted list... - if( sortedList == nil ) - myNode->SortedLink( &sortedList, (10.0f - sound->GetPriority()) * rank ); + // Queue up in our sorted list... + if (!sortedList) + myNode->SortedLink(&sortedList, (10.0f - sound->GetPriority()) * rank); else sortedList->AddToSortedLink( myNode, (10.0f - sound->GetPriority()) * rank ); - } - else - { - /// Do NOT notify sound, since we were outside of its range and still are + } else { + // Do NOT notify sound, since we were outside of its range and still are // (but if we're playing, we shouldn't be, so better update) - if( sound->IsPlaying() ) - sound->UpdateSoftVolume( false ); + if (sound->IsPlaying()) + sound->UpdateSoftVolume(false); node = node->fNext; } - } - else - { - /// Do NOT notify sound, since we were outside of its range and still are - node = node->fNext; + } else { + // Do NOT notify sound, since we were outside of its range and still are + node = node->fNext; sound->Disable(); // ensure that dist attenuation is set to zero so we don't accidentally play } } plgAudioSys::fMutedStateChange = false; - /// Go through sorted list, enabling only the first n sounds and disabling the rest + // Go through sorted list, enabling only the first n sounds and disabling the rest // DEBUG: Create a screen-only statusLog to display which sounds are what - if( fDebugActiveSoundDisplay == nil ) - fDebugActiveSoundDisplay = plStatusLogMgr::GetInstance().CreateStatusLog( 32, "Active Sounds", plStatusLog::kDontWriteFile | plStatusLog::kDeleteForMe | plStatusLog::kFilledBackground ); + if (!fDebugActiveSoundDisplay ) + fDebugActiveSoundDisplay = plStatusLogMgr::GetInstance().CreateStatusLog(32, "Active Sounds", plStatusLog::kDontWriteFile | plStatusLog::kDeleteForMe | plStatusLog::kFilledBackground); fDebugActiveSoundDisplay->Clear(); - if(fDisplayNumBuffers) + if (fDisplayNumBuffers) fDebugActiveSoundDisplay->AddLineF(0xffffffff, "Num Buffers: %d", plDSoundBuffer::GetNumBuffers() ); fDebugActiveSoundDisplay->AddLine("Not streamed", plStatusLog::kGreen); fDebugActiveSoundDisplay->AddLine("Disk streamed", plStatusLog::kYellow); @@ -684,213 +665,187 @@ void plAudioSystem::IUpdateSoftSounds( const hsPoint3 &newPosition ) fDebugActiveSoundDisplay->AddLine("Ogg streamed", plStatusLog::kRed); fDebugActiveSoundDisplay->AddLine("Incidentals", 0xff00ffff); fDebugActiveSoundDisplay->AddLine("--------------------"); - - for( i = 0; sortedList != nil && i < fMaxNumSounds; sortedList = sortedList->fSortNext ) - { - plSound *sound = plSound::ConvertNoRef( sortedList->fSoundKey->GetObjectPtr() ); - if(!sound) continue; - + + for (i = 0; sortedList && i < fMaxNumSounds; sortedList = sortedList->fSortNext) { + plSound* sound = plSound::ConvertNoRef(sortedList->fSoundKey->GetObjectPtr()); + if (!sound) + continue; + /// Notify sound that it really is still enabled sound->UpdateSoftVolume( true ); - + uint32_t color = plStatusLog::kGreen; - switch (sound->GetStreamType()) - { - case plSound::kStreamFromDisk: color = plStatusLog::kYellow; break; - case plSound::kStreamFromRAM: color = plStatusLog::kWhite; break; - case plSound::kStreamCompressed: color = plStatusLog::kRed; break; - default: break; + switch (sound->GetStreamType()) { + case plSound::kStreamFromDisk: + color = plStatusLog::kYellow; + break; + case plSound::kStreamFromRAM: + color = plStatusLog::kWhite; + break; + case plSound::kStreamCompressed: + color = plStatusLog::kRed; + break; } - if(sound->GetType() == plgAudioSys::kVoice) color = 0xffff8800; - if(sound->IsPropertySet(plSound::kPropIncidental)) color = 0xff00ffff; - - if( fUsingEAX && sound->GetEAXSettings().IsEnabled() ) - { + + if(sound->GetType() == plgAudioSys::kVoice) + color = 0xffff8800; + if(sound->IsPropertySet(plSound::kPropIncidental)) + color = 0xff00ffff; + + if (fUsingEAX && sound->GetEAXSettings().IsEnabled()) { fDebugActiveSoundDisplay->AddLineF( - color, + color, "%d %1.2f %1.2f (%d occ) %s", - sound->GetPriority(), - sortedList->fRank, - sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, - sound->GetEAXSettings().GetCurrSofts().GetOcclusion(), + sound->GetPriority(), + sortedList->fRank, + sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, + sound->GetEAXSettings().GetCurrSofts().GetOcclusion(), sound->GetKeyName().c_str() ); - } - else - { + } else { fDebugActiveSoundDisplay->AddLineF( - color, - "%d %1.2f %1.2f %s", - sound->GetPriority(), - sortedList->fRank, - sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, + color, + "%d %1.2f %1.2f %s", + sound->GetPriority(), + sortedList->fRank, + sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, sound->GetKeyName().c_str() ); } i++; } - for( ; sortedList != nil; sortedList = sortedList->fSortNext, i++ ) + for (; sortedList; sortedList = sortedList->fSortNext, i++) { - plSound *sound = plSound::ConvertNoRef( sortedList->fSoundKey->GetObjectPtr() ); - if(!sound) continue; + plSound* sound = plSound::ConvertNoRef(sortedList->fSoundKey->GetObjectPtr()); + if(!sound) + continue; - /// These unlucky sounds don't get to play (yet). Also, be extra mean - /// and pretend we're updating for "the first time", which will force them to - /// stop immediately + // These unlucky sounds don't get to play (yet). Also, be extra mean + // and pretend we're updating for "the first time", which will force them to + // stop immediately // Update: since being extra mean can incur a nasty performance hit when sounds hover back and // forth around the fMaxNumSounds mark, we have a "slop" allowance: i.e. sounds that we're going // to say shouldn't be playing but we'll let them play for a bit anyway just in case they raise // in priority. So only be mean to the sounds outside this slop range - sound->UpdateSoftVolume( false, ( i < fMaxNumSounds + fNumSoundsSlop ) ? false : true ); + sound->UpdateSoftVolume(false, (i < fMaxNumSounds + fNumSoundsSlop) ? false : true); fDebugActiveSoundDisplay->AddLineF( 0xff808080, - "%d %1.2f %s", - sound->GetPriority(), - sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, + "%d %1.2f %s", + sound->GetPriority(), + sound->GetVolume() ? sound->GetVolumeRank() / sound->GetVolume() : 0, sound->GetKeyName().c_str() ); } - + plProfile_EndTiming(SoundSoftUpdate); } -void plAudioSystem::NextDebugSound( void ) +void plAudioSystem::NextDebugSound() { - plSoftSoundNode *node; - - if( fCurrDebugSound == nil ) - fCurrDebugSound = ( fSoftRegionSounds == nil ) ? fActiveSofts : fSoftRegionSounds; - else - { - node = fCurrDebugSound; + if (!fCurrDebugSound) { + fCurrDebugSound = (!fSoftRegionSounds) ? fActiveSofts : fSoftRegionSounds; + } else { + plSoftSoundNode* node = fCurrDebugSound; fCurrDebugSound = fCurrDebugSound->fNext; - if( fCurrDebugSound == nil ) - { + if (!fCurrDebugSound) { // Trace back to find which list we were in - for( fCurrDebugSound = fSoftRegionSounds; fCurrDebugSound != nil; fCurrDebugSound = fCurrDebugSound->fNext ) - { - if( fCurrDebugSound == node ) // Was in first list, move to 2nd - { - fCurrDebugSound = fActiveSofts; + for (fCurrDebugSound = fSoftRegionSounds; fCurrDebugSound; fCurrDebugSound = fCurrDebugSound->fNext) { + // Was in first list, move to 2nd + if( fCurrDebugSound == node ) { + fCurrDebugSound = fActiveSofts; break; } } - // else Must've been in 2nd list, so keep nil + // else Must've been in 2nd list, so keep null } } - if( fCurrDebugSound != nil ) - plSound::SetCurrDebugPlate( fCurrDebugSound->fSoundKey ); + if (fCurrDebugSound) + plSound::SetCurrDebugPlate(fCurrDebugSound->fSoundKey); else - plSound::SetCurrDebugPlate( nil ); + plSound::SetCurrDebugPlate(nullptr); } void plAudioSystem::SetFadeLength(float lengthSec) { fFadeLength = lengthSec; } - + bool plAudioSystem::MsgReceive(plMessage* msg) { - if(plTimeMsg *time = plTimeMsg::ConvertNoRef( msg ) ) - { - if(!plgAudioSys::IsMuted()) - { + if (plTimeMsg* time = plTimeMsg::ConvertNoRef(msg)) { + if(!plgAudioSys::IsMuted()) { double currTime = hsTimer::GetSeconds(); - if(fStartFade == 0) - { + if (fStartFade == 0) { plStatusLog::AddLineS("audio.log", "Starting Fade %f", currTime); } - if((currTime - fStartFade) > fFadeLength) - { + if ((currTime - fStartFade) > fFadeLength) { fStartFade = 0; - plgDispatch::Dispatch()->UnRegisterForExactType( plTimeMsg::Index(), GetKey() ); + plgDispatch::Dispatch()->UnRegisterForExactType(plTimeMsg::Index(), GetKey()); plStatusLog::AddLineS("audio.log", "Stopping Fade %f", currTime); - plgAudioSys::SetGlobalFadeVolume( 1.0 ); - } - else - { - plgAudioSys::SetGlobalFadeVolume( (float)((currTime-fStartFade) / fFadeLength) ); + plgAudioSys::SetGlobalFadeVolume(1.0); + } else { + plgAudioSys::SetGlobalFadeVolume((float)((currTime-fStartFade) / fFadeLength)); } } return true; } - - if (plAudioSysMsg* pASMsg = plAudioSysMsg::ConvertNoRef( msg )) - { - if (pASMsg->GetAudFlag() == plAudioSysMsg::kPing && fListenerInit) - { - plAudioSysMsg* pMsg = new plAudioSysMsg( plAudioSysMsg::kActivate ); - pMsg->AddReceiver( pASMsg->GetSender() ); + + if (plAudioSysMsg* pASMsg = plAudioSysMsg::ConvertNoRef(msg)) { + if (pASMsg->GetAudFlag() == plAudioSysMsg::kPing && fListenerInit) { + plAudioSysMsg* pMsg = new plAudioSysMsg(plAudioSysMsg::kActivate); + pMsg->AddReceiver(pASMsg->GetSender()); pMsg->SetBCastFlag(plMessage::kBCastByExactType, false); - plgDispatch::MsgSend( pMsg ); + plgDispatch::MsgSend(pMsg); return true; - } - else if (pASMsg->GetAudFlag() == plAudioSysMsg::kSetVol) - { + } else if (pASMsg->GetAudFlag() == plAudioSysMsg::kSetVol) { return true; - } - else if( pASMsg->GetAudFlag() == plAudioSysMsg::kDestroy ) - { - if( fWaitingForShutdown ) + } else if(pASMsg->GetAudFlag() == plAudioSysMsg::kDestroy) { + if (fWaitingForShutdown) Shutdown(); return true; - } - else if( pASMsg->GetAudFlag() == plAudioSysMsg::kUnmuteAll ) - { - if( !pASMsg->HasBCastFlag( plMessage::kBCastByExactType ) ) - plgAudioSys::SetMuted( false ); + } else if( pASMsg->GetAudFlag() == plAudioSysMsg::kUnmuteAll) { + if (!pASMsg->HasBCastFlag(plMessage::kBCastByExactType)) + plgAudioSys::SetMuted(false); return true; } } - - if(plRenderMsg* pRMsg = plRenderMsg::ConvertNoRef( msg )) - { - //if( fListener ) + + if (plRenderMsg* pRMsg = plRenderMsg::ConvertNoRef( msg )) { + //if (fListener) { plProfile_BeginLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); - if(hsTimer::GetMilliSeconds() - fLastUpdateTimeMs > UPDATE_TIME_MS) - { - IUpdateSoftSounds( fCurrListenerPos ); + if (hsTimer::GetMilliSeconds() - fLastUpdateTimeMs > UPDATE_TIME_MS) { + IUpdateSoftSounds(fCurrListenerPos); - if( fUsingEAX ) - { + if (fUsingEAX) { plProfile_BeginTiming(SoundEAXUpdate); - plEAXListener::GetInstance().ProcessMods( fEAXRegions ); + plEAXListener::GetInstance().ProcessMods(fEAXRegions); plProfile_EndTiming(SoundEAXUpdate); } } plProfile_EndLap(AudioUpdate, this->GetKey()->GetUoid().GetObjectName().c_str()); } - return true; } - if(plGenRefMsg *refMsg = plGenRefMsg::ConvertNoRef( msg )) - { - if( refMsg->GetContext() & ( plRefMsg::kOnCreate | plRefMsg::kOnRequest | plRefMsg::kOnReplace ) ) - { + if (plGenRefMsg* refMsg = plGenRefMsg::ConvertNoRef(msg)) { + if (refMsg->GetContext() & (plRefMsg::kOnCreate | plRefMsg::kOnRequest | plRefMsg::kOnReplace)) { fEAXRegions.insert(plEAXListenerMod::ConvertNoRef(refMsg->GetRef())); plEAXListener::GetInstance().ClearProcessCache(); - } - else if( refMsg->GetContext() & ( plRefMsg::kOnRemove | plRefMsg::kOnDestroy ) ) - { + } else if (refMsg->GetContext() & ( plRefMsg::kOnRemove | plRefMsg::kOnDestroy)) { fEAXRegions.erase(plEAXListenerMod::ConvertNoRef(refMsg->GetRef())); plEAXListener::GetInstance().ClearProcessCache(); } return true; } - if(plAgeLoadedMsg *pALMsg = plAgeLoadedMsg::ConvertNoRef(msg)) - { - if(!pALMsg->fLoaded) - { + if (plAgeLoadedMsg* pALMsg = plAgeLoadedMsg::ConvertNoRef(msg)) { + if(!pALMsg->fLoaded) { fLastPos = fCurrListenerPos; fListenerInit = false; - } - else - { + } else { fListenerInit = true; } } @@ -1022,7 +977,7 @@ void plgAudioSys::Init() SetGlobalFadeVolume(0.0f); if (fDelayedActivate) - Activate( true ); + Activate(true); } void plgAudioSys::SetActive(bool b) @@ -1035,7 +990,7 @@ void plgAudioSys::SetMuted( bool b ) fMuted = b; fMutedStateChange = true; - if(fMuted) + if (fMuted) SetGlobalFadeVolume(0.0f); else SetGlobalFadeVolume(1.0); @@ -1044,16 +999,15 @@ void plgAudioSys::SetMuted( bool b ) void plgAudioSys::EnableEAX( bool b ) { fEnableEAX = b; - if( fActive ) + if (fActive) Restart(); } -void plgAudioSys::Restart( void ) +void plgAudioSys::Restart() { - if( fSys ) - { + if( fSys ) { fSys->fRestartOnDestruct = true; - Activate( false ); + Activate(false); fRestarting = true; } } @@ -1076,15 +1030,12 @@ void plgAudioSys::Shutdown() { Activate( false ); if( fSys ) - { fSys->UnRegisterAs( kAudioSystem_KEY ); - } } void plgAudioSys::Activate(bool b) { - if( fSys == nil ) - { + if (!fSys) { fDelayedActivate = true; return; } @@ -1093,39 +1044,36 @@ void plgAudioSys::Activate(bool b) return; if (!fActive) return; - if( b ) - { + if (b) { plStatusLog::AddLineS( "audio.log", plStatusLog::kBlue, "ASYS: -- Attempting audio system init --" ); - if( !fSys->Init() ) - { + if (!fSys->Init()) { // Cannot init audio system. Don't activate return; } fInit = true; fSys->SetActive( true ); - if( !IsMuted() ) - { - SetMuted( true ); - plAudioSysMsg *msg = new plAudioSysMsg( plAudioSysMsg::kUnmuteAll ); - msg->SetTimeStamp( hsTimer::GetSysSeconds() ); - msg->AddReceiver( fSys->GetKey() ); - msg->SetBCastFlag( plMessage::kBCastByExactType, false ); + if (!IsMuted()) { + SetMuted(true); + plAudioSysMsg* msg = new plAudioSysMsg(plAudioSysMsg::kUnmuteAll); + msg->SetTimeStamp(hsTimer::GetSysSeconds()); + msg->AddReceiver(fSys->GetKey()); + msg->SetBCastFlag(plMessage::kBCastByExactType, false); msg->Send(); } return; } - fSys->SetActive( false ); + fSys->SetActive(false); - plStatusLog::AddLineS( "audio.log", plStatusLog::kBlue, "ASYS: -- Sending deactivate/destroy messages --" ); - plgDispatch::MsgSend( new plAudioSysMsg( plAudioSysMsg::kDeActivate ) ); + plStatusLog::AddLineS("audio.log", plStatusLog::kBlue, "ASYS: -- Sending deactivate/destroy messages --"); + plgDispatch::MsgSend(new plAudioSysMsg(plAudioSysMsg::kDeActivate)); // Send ourselves a shutdown message, so that the deactivates get processed first fSys->fWaitingForShutdown = true; - plAudioSysMsg *msg = new plAudioSysMsg( plAudioSysMsg::kDestroy ); - msg->SetBCastFlag( plMessage::kBCastByExactType, false ); - msg->Send( fSys->GetKey() ); + plAudioSysMsg* msg = new plAudioSysMsg( plAudioSysMsg::kDestroy ); + msg->SetBCastFlag(plMessage::kBCastByExactType, false); + msg->Send(fSys->GetKey()); fInit = false; } @@ -1135,7 +1083,7 @@ void plgAudioSys::SetChannelVolume(ASChannel chan, float vol) fChannelVolumes[chan] = vol; } -void plgAudioSys::SetGlobalFadeVolume(float vol) +void plgAudioSys::SetGlobalFadeVolume(float vol) { if (!fMuted) fGlobalFadeVolume = vol; @@ -1143,12 +1091,12 @@ void plgAudioSys::SetGlobalFadeVolume(float vol) fGlobalFadeVolume = 0; } -float plgAudioSys::GetChannelVolume(ASChannel chan) +float plgAudioSys::GetChannelVolume(ASChannel chan) { return fChannelVolumes[chan]; } -void plgAudioSys::NextDebugSound() +void plgAudioSys::NextDebugSound() { fSys->NextDebugSound(); }