Handle looping in sfx thread.

This commit is contained in:
hiker 2014-10-16 16:57:12 +11:00
parent c61b7d632d
commit a18766e3e6
6 changed files with 15 additions and 1 deletions

View File

@ -37,6 +37,7 @@ public:
virtual bool init() { return true; }
virtual void setLoop(bool status) {}
virtual void reallySetLoop(bool status) {}
virtual void setPosition(const Vec3 &p) {}
virtual void reallySetPosition(const Vec3 &p) {}
virtual void play() {}

View File

@ -56,6 +56,7 @@ public:
virtual void setPosition(const Vec3 &p) = 0;
virtual void reallySetPosition(const Vec3 &p) = 0;
virtual void setLoop(bool status) = 0;
virtual void reallySetLoop(bool status) = 0;
virtual bool isPlaying() = 0;
virtual void play() = 0;
virtual void reallyPlayNow() = 0;

View File

@ -286,6 +286,8 @@ void* SFXManager::mainLoop(void *obj)
current->m_parameter); break;
case SFX_VOLUME: current->m_sfx->reallySetVolume(
current->m_parameter.getX()); break;
case SFX_LOOP: current->m_sfx->reallySetLoop(
current->m_parameter.getX()!=0); break;
case SFX_DELETE: {
current->m_sfx->reallyStopNow();
me->deleteSFX(current->m_sfx); break;

View File

@ -70,6 +70,7 @@ public:
SFX_SPEED,
SFX_POSITION,
SFX_VOLUME,
SFX_LOOP,
SFX_LISTENER,
SFX_UPDATE_MUSIC,
SFX_EXIT,

View File

@ -207,6 +207,14 @@ void SFXOpenAL::setMasterVolume(float gain)
/** Loops this sound effect.
*/
void SFXOpenAL::setLoop(bool status)
{
SFXManager::get()->queue(SFXManager::SFX_LOOP, this, status ? 1.0f : 0.0f);
} // setLoop
//-----------------------------------------------------------------------------
/** Loops this sound effect.
*/
void SFXOpenAL::reallySetLoop(bool status)
{
m_loop = status;
@ -214,7 +222,7 @@ void SFXOpenAL::setLoop(bool status)
alSourcei(m_sound_source, AL_LOOPING, status ? AL_TRUE : AL_FALSE);
SFXManager::checkError("looping");
} // loop
} // reallySetLoop
//-----------------------------------------------------------------------------
/** Queues a stop for this effect to the sound manager.

View File

@ -85,6 +85,7 @@ public:
virtual void play();
virtual void reallyPlayNow();
virtual void setLoop(bool status);
virtual void reallySetLoop(bool status);
virtual bool isPlaying();
virtual void stop();
virtual void reallyStopNow();