Added SoundSource::operator= and called it from Sound::operator=
Signed-off-by: Jan Haller <bromeon@gmail.com>
This commit is contained in:
parent
0c9ce3bef3
commit
2d1fab374f
@ -240,6 +240,16 @@ public:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
float getAttenuation() const;
|
float getAttenuation() const;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Overload of assignment operator
|
||||||
|
///
|
||||||
|
/// \param right Instance to assign
|
||||||
|
///
|
||||||
|
/// \return Reference to self
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SoundSource& operator =(const SoundSource& right);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
@ -157,7 +157,11 @@ Sound::Status Sound::getStatus() const
|
|||||||
Sound& Sound::operator =(const Sound& right)
|
Sound& Sound::operator =(const Sound& right)
|
||||||
{
|
{
|
||||||
// Here we don't use the copy-and-swap idiom, because it would mess up
|
// Here we don't use the copy-and-swap idiom, because it would mess up
|
||||||
// the list of sound instances contained in the buffers
|
// the list of sound instances contained in the buffers and unnecessarily
|
||||||
|
// destroy/create OpenAL sound sources
|
||||||
|
|
||||||
|
// Delegate to base class, which copies all the sound attributes
|
||||||
|
SoundSource::operator=(right);
|
||||||
|
|
||||||
// Detach the sound instance from the previous buffer (if any)
|
// Detach the sound instance from the previous buffer (if any)
|
||||||
if (m_buffer)
|
if (m_buffer)
|
||||||
@ -167,16 +171,10 @@ Sound& Sound::operator =(const Sound& right)
|
|||||||
m_buffer = NULL;
|
m_buffer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the sound attributes
|
// Copy the remaining sound attributes
|
||||||
if (right.m_buffer)
|
if (right.m_buffer)
|
||||||
setBuffer(*right.m_buffer);
|
setBuffer(*right.m_buffer);
|
||||||
setLoop(right.getLoop());
|
setLoop(right.getLoop());
|
||||||
setPitch(right.getPitch());
|
|
||||||
setVolume(right.getVolume());
|
|
||||||
setPosition(right.getPosition());
|
|
||||||
setRelativeToListener(right.isRelativeToListener());
|
|
||||||
setMinDistance(right.getMinDistance());
|
|
||||||
setAttenuation(right.getAttenuation());
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ void SoundSource::setVolume(float volume)
|
|||||||
alCheck(alSourcef(m_source, AL_GAIN, volume * 0.01f));
|
alCheck(alSourcef(m_source, AL_GAIN, volume * 0.01f));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void SoundSource::setPosition(float x, float y, float z)
|
void SoundSource::setPosition(float x, float y, float z)
|
||||||
{
|
{
|
||||||
@ -170,6 +171,24 @@ float SoundSource::getAttenuation() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
SoundSource& SoundSource::operator =(const SoundSource& right)
|
||||||
|
{
|
||||||
|
// Leave m_source untouched -- it's not necessary to destroy and
|
||||||
|
// recreate the OpenAL sound source, hence no copy-and-swap idiom
|
||||||
|
|
||||||
|
// Assign the sound attributes
|
||||||
|
setPitch(right.getPitch());
|
||||||
|
setVolume(right.getVolume());
|
||||||
|
setPosition(right.getPosition());
|
||||||
|
setRelativeToListener(right.isRelativeToListener());
|
||||||
|
setMinDistance(right.getMinDistance());
|
||||||
|
setAttenuation(right.getAttenuation());
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SoundSource::Status SoundSource::getStatus() const
|
SoundSource::Status SoundSource::getStatus() const
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user