mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-08-18 06:55:48 +03:00
Added GetFreeSound to tSoundManager.
This commit is contained in:
@@ -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() )
|
||||
|
||||
Reference in New Issue
Block a user