Properly test for sfx disabled, and only schedule events if sfx

are enabled. Fixes #1629.
This commit is contained in:
hiker 2014-10-18 12:11:02 +11:00
parent df5635e90f
commit 3082267eb4
2 changed files with 12 additions and 17 deletions

View File

@ -650,6 +650,7 @@ void SFXManager::deleteSFX(SFXBase *sfx)
*/ */
void SFXManager::pauseAll() void SFXManager::pauseAll()
{ {
if (!sfxAllowed()) return;
queue(SFX_PAUSE_ALL); queue(SFX_PAUSE_ALL);
} // pauseAll } // pauseAll
@ -674,6 +675,8 @@ void SFXManager::reallyPauseAllNow()
*/ */
void SFXManager::resumeAll() void SFXManager::resumeAll()
{ {
// ignore unpausing if sound is disabled
if (!sfxAllowed()) return;
queue(SFX_RESUME_ALL); queue(SFX_RESUME_ALL);
} // resumeAll } // resumeAll
@ -682,9 +685,6 @@ void SFXManager::resumeAll()
*/ */
void SFXManager::reallyResumeAllNow() void SFXManager::reallyResumeAllNow()
{ {
// ignore unpausing if sound is disabled
if (!sfxAllowed()) return;
m_all_sfx.lock(); m_all_sfx.lock();
for (std::vector<SFXBase*>::iterator i =m_all_sfx.getData().begin(); for (std::vector<SFXBase*>::iterator i =m_all_sfx.getData().begin();
i!=m_all_sfx.getData().end(); i++) i!=m_all_sfx.getData().end(); i++)

View File

@ -150,7 +150,7 @@ SFXBase::SFXStatus SFXOpenAL::getStatus()
*/ */
void SFXOpenAL::setSpeed(float factor) void SFXOpenAL::setSpeed(float factor)
{ {
if(m_status==SFX_UNKNOWN) return; if(m_status==SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
assert(!isnan(factor)); assert(!isnan(factor));
SFXManager::get()->queue(SFXManager::SFX_SPEED, this, factor); SFXManager::get()->queue(SFXManager::SFX_SPEED, this, factor);
} // setSpeed } // setSpeed
@ -179,7 +179,7 @@ void SFXOpenAL::reallySetSpeed(float factor)
*/ */
void SFXOpenAL::setVolume(float gain) void SFXOpenAL::setVolume(float gain)
{ {
if(m_status==SFX_UNKNOWN) return; if(m_status==SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
assert(!isnan(gain)) ; assert(!isnan(gain)) ;
SFXManager::get()->queue(SFXManager::SFX_VOLUME, this, gain); SFXManager::get()->queue(SFXManager::SFX_VOLUME, this, gain);
} // setVolume } // setVolume
@ -215,6 +215,7 @@ void SFXOpenAL::setMasterVolume(float gain)
*/ */
void SFXOpenAL::setLoop(bool status) void SFXOpenAL::setLoop(bool status)
{ {
if (m_status == SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
SFXManager::get()->queue(SFXManager::SFX_LOOP, this, status ? 1.0f : 0.0f); SFXManager::get()->queue(SFXManager::SFX_LOOP, this, status ? 1.0f : 0.0f);
} // setLoop } // setLoop
@ -225,8 +226,6 @@ void SFXOpenAL::reallySetLoop(bool status)
{ {
m_loop = status; m_loop = status;
if(m_status==SFX_UNKNOWN) return;
alSourcei(m_sound_source, AL_LOOPING, status ? AL_TRUE : AL_FALSE); alSourcei(m_sound_source, AL_LOOPING, status ? AL_TRUE : AL_FALSE);
SFXManager::checkError("looping"); SFXManager::checkError("looping");
} // reallySetLoop } // reallySetLoop
@ -236,6 +235,7 @@ void SFXOpenAL::reallySetLoop(bool status)
*/ */
void SFXOpenAL::stop() void SFXOpenAL::stop()
{ {
if (m_status == SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
SFXManager::get()->queue(SFXManager::SFX_STOP, this); SFXManager::get()->queue(SFXManager::SFX_STOP, this);
} // stop } // stop
@ -244,8 +244,6 @@ void SFXOpenAL::stop()
*/ */
void SFXOpenAL::reallyStopNow() void SFXOpenAL::reallyStopNow()
{ {
if(m_status==SFX_UNKNOWN) return;
m_status = SFX_STOPPED; m_status = SFX_STOPPED;
m_loop = false; m_loop = false;
alSourcei(m_sound_source, AL_LOOPING, AL_FALSE); alSourcei(m_sound_source, AL_LOOPING, AL_FALSE);
@ -258,6 +256,7 @@ void SFXOpenAL::reallyStopNow()
*/ */
void SFXOpenAL::pause() void SFXOpenAL::pause()
{ {
if (m_status != SFX_PLAYING || !SFXManager::get()->sfxAllowed()) return;
SFXManager::get()->queue(SFXManager::SFX_PAUSE, this); SFXManager::get()->queue(SFXManager::SFX_PAUSE, this);
} // pause } // pause
@ -267,11 +266,6 @@ void SFXOpenAL::pause()
*/ */
void SFXOpenAL::reallyPauseNow() void SFXOpenAL::reallyPauseNow()
{ {
// This updates the status, i.e. potentially switches from
// playing to stopped.
getStatus();
if(m_status!=SFX_PLAYING) return;
m_status = SFX_PAUSED; m_status = SFX_PAUSED;
alSourcePause(m_sound_source); alSourcePause(m_sound_source);
SFXManager::checkError("pausing"); SFXManager::checkError("pausing");
@ -282,6 +276,7 @@ void SFXOpenAL::reallyPauseNow()
*/ */
void SFXOpenAL::resume() void SFXOpenAL::resume()
{ {
if (m_status != SFX_PLAYING || !SFXManager::get()->sfxAllowed()) return;
SFXManager::get()->queue(SFXManager::SFX_RESUME, this); SFXManager::get()->queue(SFXManager::SFX_RESUME, this);
} // resume } // resume
@ -290,8 +285,6 @@ void SFXOpenAL::resume()
*/ */
void SFXOpenAL::reallyResumeNow() void SFXOpenAL::reallyResumeNow()
{ {
// Will init the sfx (lazy) if necessary.
getStatus();
if(m_status==SFX_PAUSED) if(m_status==SFX_PAUSED)
{ {
alSourcePlay(m_sound_source); alSourcePlay(m_sound_source);
@ -306,6 +299,8 @@ void SFXOpenAL::reallyResumeNow()
*/ */
void SFXOpenAL::play() void SFXOpenAL::play()
{ {
if (m_status == SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
if(m_status==SFX_STOPPED) if(m_status==SFX_STOPPED)
m_play_time = 0.0f; m_play_time = 0.0f;
@ -343,7 +338,7 @@ void SFXOpenAL::reallyPlayNow()
*/ */
void SFXOpenAL::setPosition(const Vec3 &position) void SFXOpenAL::setPosition(const Vec3 &position)
{ {
if (m_status == SFX_UNKNOWN) return; if (m_status == SFX_UNKNOWN || !SFXManager::get()->sfxAllowed()) return;
SFXManager::get()->queue(SFXManager::SFX_POSITION, this, position); SFXManager::get()->queue(SFXManager::SFX_POSITION, this, position);
} // setPosition } // setPosition