Game Development Reference
In-Depth Information
7.
Registration methods are needed to maintain the FActiveSources container.
Their implementations can be found in the following code:
void clAudioThread::RegisterSource( clAudioSource* Src )
{
LMutex Lock(&FMutex );
8.
Don't add the same audio source multiple times:
auto i = std::find( FActiveSources.begin(),
FActiveSources.end(), Src );
if ( i != FActiveSources.end() ) return;
FActiveSources.push_back( Src );
}
void clAudioThread::UnRegisterSource( clAudioSource* Src )
{
LMutex Lock(&FMutex );
9. Just ind the source and erase it:
auto i = std::find( FActiveSources.begin(),
FActiveSources.end(), Src );
if ( i != FActiveSources.end() ) FActiveSources.erase( i );
}
The full implementation of this new clAudioThread class can be found in the sound/
Audio.cpp and sound/Audio.h iles in the example 1_Game .
How it works…
To take advantage of the new AudioThread class, audio sources must register themselves.
We extend the constructor and the destructor of the clAudioSource class to perform
RAII registration ( http://en.wikipedia.org/wiki/Resource_Acquisition_Is_
Initialization ):
clAudioSource::clAudioSource()
{
g_Audio.RegisterSource( this );
}
clAudioSource::~clAudioSource()
{
g_Audio.UnRegisterSource( this );
}
 
Search WWH ::




Custom Search