Handle setMasterVolume in sfx thread.

This commit is contained in:
hiker 2014-10-21 08:28:41 +11:00
parent a09c1346b7
commit c7d7e17ff9
6 changed files with 50 additions and 35 deletions

View File

@ -55,6 +55,8 @@ public:
virtual void reallySetSpeed(float factor) {}
virtual void setVolume(float gain) {}
virtual void reallySetVolume(float gain) {}
virtual void setMasterVolume(float gain) {}
virtual void reallySetMasterVolumeNow(float gain) {}
virtual SFXStatus getStatus() { return SFX_STOPPED; }
virtual void onSoundEnabledBack() {}
virtual void setRolloff(float rolloff) {}

View File

@ -52,31 +52,32 @@ public:
virtual ~SFXBase() {}
/** Late creation, if SFX was initially disabled */
virtual bool init() = 0;
virtual bool isLooped() = 0;
virtual void updatePlayingSFX(float dt) = 0;
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 void play() = 0;
virtual void reallyPlayNow() = 0;
virtual void stop() = 0;
virtual void reallyStopNow() = 0;
virtual void pause() = 0;
virtual void reallyPauseNow() = 0;
virtual void resume() = 0;
virtual void reallyResumeNow() = 0;
virtual void deleteSFX() = 0;
virtual void setSpeed(float factor) = 0;
virtual void reallySetSpeed(float factor) = 0;
virtual void setVolume(float gain) = 0;
virtual void reallySetVolume(float gain) = 0;
virtual void setMasterVolume(float gain) = 0;
virtual void onSoundEnabledBack() = 0;
virtual void setRolloff(float rolloff) = 0;
virtual const SFXBuffer* getBuffer() const = 0;
virtual SFXStatus getStatus() = 0;
virtual bool init() = 0;
virtual bool isLooped() = 0;
virtual void updatePlayingSFX(float dt) = 0;
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 void play() = 0;
virtual void reallyPlayNow() = 0;
virtual void stop() = 0;
virtual void reallyStopNow() = 0;
virtual void pause() = 0;
virtual void reallyPauseNow() = 0;
virtual void resume() = 0;
virtual void reallyResumeNow() = 0;
virtual void deleteSFX() = 0;
virtual void setSpeed(float factor) = 0;
virtual void reallySetSpeed(float factor) = 0;
virtual void setVolume(float gain) = 0;
virtual void reallySetVolume(float gain) = 0;
virtual void setMasterVolume(float gain) = 0;
virtual void reallySetMasterVolumeNow(float gain) = 0;
virtual void onSoundEnabledBack() = 0;
virtual void setRolloff(float rolloff) = 0;
virtual const SFXBuffer* getBuffer() const = 0;
virtual SFXStatus getStatus() = 0;
}; // SFXBase

View File

@ -287,6 +287,9 @@ void* SFXManager::mainLoop(void *obj)
current->m_parameter); break;
case SFX_VOLUME: current->m_sfx->reallySetVolume(
current->m_parameter.getX()); break;
case SFX_MASTER_VOLUME:
current->m_sfx->reallySetMasterVolumeNow(
current->m_parameter.getX()); break;
case SFX_LOOP: current->m_sfx->reallySetLoop(
current->m_parameter.getX()!=0); break;
case SFX_DELETE: {

View File

@ -72,6 +72,7 @@ public:
SFX_SPEED,
SFX_POSITION,
SFX_VOLUME,
SFX_MASTER_VOLUME,
SFX_LOOP,
SFX_LISTENER,
SFX_UPDATE,

View File

@ -208,24 +208,31 @@ void SFXOpenAL::reallySetVolume(float gain)
} // reallySetVolume
//-----------------------------------------------------------------------------
/** Schedules setting of the master volume.
* \param gain Gain value.
*/
void SFXOpenAL::setMasterVolume(float gain)
{
// This needs to be called even if sfx are disabled atm, so only exit
// in case that the sfx could not be loaded in the first place.
if(m_status==SFX_UNKNOWN) return;
SFXManager::get()->queue(SFXManager::SFX_MASTER_VOLUME, this, gain);
} // setMasterVolume
//-----------------------------------------------------------------------------
/** Sets the master volume.
* \param gain Master volume.
*/
void SFXOpenAL::reallySetMasterVolumeNow(float gain)
{
m_master_gain = gain;
if(m_status==SFX_UNKNOWN) return;
if(m_status==SFX_NOT_INITIALISED)
{
init();
if(m_status==SFX_UNKNOWN)
return;
}
if(m_status==SFX_UNKNOWN || m_status == SFX_NOT_INITIALISED) return;
alSourcef(m_sound_source, AL_GAIN,
(m_gain < 0.0f ? m_default_gain : m_gain) * m_master_gain);
SFXManager::checkError("setting volume");
} //setMasterVolume
} // reallySetMasterVolumeNow
//-----------------------------------------------------------------------------
/** Loops this sound effect.

View File

@ -100,6 +100,7 @@ public:
virtual void setVolume(float gain);
virtual void reallySetVolume(float gain);
virtual void setMasterVolume(float gain);
virtual void reallySetMasterVolumeNow(float gain);
virtual void onSoundEnabledBack();
virtual void setRolloff(float rolloff);
// ------------------------------------------------------------------------