give each RageSound instance a unique ID
This commit is contained in:
@@ -75,8 +75,8 @@ RageSound::RageSound()
|
||||
playing = false;
|
||||
databuf.reserve(internal_buffer_size);
|
||||
|
||||
/* Register ourselves, so we receive Update()s. */
|
||||
SOUNDMAN->all_sounds.insert(this);
|
||||
/* Register ourself, so we have a unique ID and receive Update()s. */
|
||||
ID = SOUNDMAN->RegisterSound( this );
|
||||
}
|
||||
|
||||
RageSound::~RageSound()
|
||||
@@ -88,10 +88,8 @@ RageSound::~RageSound()
|
||||
|
||||
Unload();
|
||||
|
||||
/* Unregister ourselves. */
|
||||
SOUNDMAN->lock.Lock();
|
||||
SOUNDMAN->all_sounds.erase(this);
|
||||
SOUNDMAN->lock.Unlock();
|
||||
/* Unregister ourself. */
|
||||
SOUNDMAN->UnregisterSound( this );
|
||||
}
|
||||
|
||||
RageSound::RageSound(const RageSound &cpy):
|
||||
@@ -114,8 +112,9 @@ RageSound::RageSound(const RageSound &cpy):
|
||||
* copy this down here. */
|
||||
m_sFilePath = cpy.m_sFilePath;
|
||||
|
||||
/* Register ourselves, so we receive Update()s. */
|
||||
SOUNDMAN->all_sounds.insert(this);
|
||||
/* Register ourselves, so we receive Update()s. We have a different ID than
|
||||
* our parent. */
|
||||
ID = SOUNDMAN->RegisterSound( this );
|
||||
}
|
||||
|
||||
void RageSound::Unload()
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
virtual int GetSampleRate() const = 0;
|
||||
virtual RageTimer GetStartTime() const { return RageZeroTimer; }
|
||||
virtual float GetVolume() const = 0;
|
||||
virtual int GetID() const = 0;
|
||||
virtual CString GetLoadedFilePath() const = 0;
|
||||
};
|
||||
|
||||
@@ -106,6 +107,7 @@ public:
|
||||
float GetPlaybackRate() const;
|
||||
RageTimer GetStartTime() const;
|
||||
float GetVolume() const;
|
||||
int GetID() const { return ID; }
|
||||
void SetParams( const RageSoundParams &p );
|
||||
const RageSoundParams &GetParams() const { return m_Param; }
|
||||
|
||||
@@ -152,6 +154,9 @@ private:
|
||||
int64_t stopped_position;
|
||||
bool playing;
|
||||
|
||||
/* Unique ID number for this instance of RageSound. */
|
||||
int ID;
|
||||
|
||||
CString error;
|
||||
|
||||
int64_t GetPositionSecondsInternal( bool *approximate=NULL ) const;
|
||||
|
||||
@@ -88,6 +88,23 @@ void RageSoundManager::Update(float delta)
|
||||
driver->Update(delta);
|
||||
}
|
||||
|
||||
/* Register the given sound, and return a unique ID. */
|
||||
int RageSoundManager::RegisterSound( RageSound *p )
|
||||
{
|
||||
LockMut(lock);
|
||||
|
||||
all_sounds.insert( p );
|
||||
|
||||
static int iID = 0;
|
||||
return ++iID;
|
||||
}
|
||||
|
||||
void RageSoundManager::UnregisterSound( RageSound *p )
|
||||
{
|
||||
LockMut(lock);
|
||||
all_sounds.erase( p );
|
||||
}
|
||||
|
||||
float RageSoundManager::GetPlayLatency() const
|
||||
{
|
||||
return driver->GetPlayLatency();
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
void StartMixing( RageSoundBase *snd ); /* used by RageSound */
|
||||
void StopMixing( RageSoundBase *snd ); /* used by RageSound */
|
||||
int64_t GetPosition( const RageSoundBase *snd ) const; /* used by RageSound */
|
||||
int RegisterSound( RageSound *p ); /* used by RageSound */
|
||||
void UnregisterSound( RageSound *p ); /* used by RageSound */
|
||||
float GetPlayLatency() const;
|
||||
int GetDriverSampleRate( int rate ) const;
|
||||
const set<RageSound *> &GetPlayingSounds() const { return playing_sounds; }
|
||||
|
||||
Reference in New Issue
Block a user