Added GetFreeSound to tSoundManager.

This commit is contained in:
spartanj@gmail.com
2012-01-29 14:50:11 -03:00
parent 938aa3f44a
commit b66eeb7d58

View File

@@ -28,6 +28,8 @@ class tSoundManager {
cSound& operator[] ( const T& id );
cSound& GetFreeSound( const T& id );
~tSoundManager();
private:
typedef struct sSound {
@@ -99,6 +101,29 @@ cSoundBuffer& tSoundManager<T>::GetBuffer( const T& id ) {
return tSounds[id].Buf;
}
template <typename T>
cSound& tSoundManager<T>::GetFreeSound( const T& id ) {
typename std::map<T, sSound>::iterator it = tSounds.find( id );
if ( it != tSounds.end() ) {
sSound * tSound = &it->second;
Uint32 tSize = (Uint32)tSound->Snd.size();
for ( Uint32 i = 0; i < tSize; i++ ) {
// If there is a free slot, use it.
if ( tSound->Snd[i].GetState() != SOUND_PLAYING ) {
return tSound->Snd[i];
}
}
tSound->Snd.push_back( cSound( tSound->Buf ) );
return tSound->Snd[ tSound->Snd.size() - 1 ];
}
return tSounds[0].Snd[0];
}
template <typename T>
cSound& tSoundManager<T>::operator[] ( const T& id ) {
if ( tSounds.find( id ) != tSounds.end() )