Batch update changes together, when possible

Certain OpenAL implementations, including Rapture3D, Creative's hardware
drivers, and more recent versions of OpenAL Soft, can batch together changes so
that they all occur at once, avoiding potential discontinuities with one sound
being changed before another, or the listeenr being changed before sounds are.

On other implementaitons, this is a no-op and maintains existing behavior.
This commit is contained in:
Chris Robinson 2015-11-24 20:37:38 -08:00
parent ea70b0baee
commit 669b7a2295
4 changed files with 23 additions and 0 deletions

View file

@ -970,6 +970,17 @@ MWBase::SoundPtr OpenAL_Output::streamSound3D(DecoderPtr decoder, const osg::Vec
}
void OpenAL_Output::startUpdate()
{
alcSuspendContext(alcGetCurrentContext());
}
void OpenAL_Output::finishUpdate()
{
alcProcessContext(alcGetCurrentContext());
}
void OpenAL_Output::updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env)
{
mPos = pos;

View file

@ -51,6 +51,9 @@ namespace MWSound
virtual MWBase::SoundPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags);
virtual void startUpdate();
virtual void finishUpdate();
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env);
virtual void pauseSounds(int types);

View file

@ -39,6 +39,9 @@ namespace MWSound
virtual MWBase::SoundPtr streamSound3D(DecoderPtr decoder, const osg::Vec3f &pos,
float vol, float basevol, float pitch, float min, float max, int flags) = 0;
virtual void startUpdate() = 0;
virtual void finishUpdate() = 0;
virtual void updateListener(const osg::Vec3f &pos, const osg::Vec3f &atdir, const osg::Vec3f &updir, Environment env) = 0;
virtual void pauseSounds(int types) = 0;

View file

@ -803,6 +803,7 @@ namespace MWSound
mUnderwaterSound.reset();
}
mOutput->startUpdate();
mOutput->updateListener(
mListenerPos,
mListenerDir,
@ -848,6 +849,7 @@ namespace MWSound
else
++sayiter;
}
mOutput->finishUpdate();
}
bool SoundManager::updateSound(MWBase::SoundPtr sound, const MWWorld::Ptr& ptr, float duration)
@ -905,6 +907,9 @@ namespace MWSound
mFootstepsVolume = Settings::Manager::getFloat("footsteps volume", "Sound");
mVoiceVolume = Settings::Manager::getFloat("voice volume", "Sound");
if(!mOutput->isInitialized())
return;
mOutput->startUpdate();
SoundMap::iterator snditer = mActiveSounds.begin();
for(;snditer != mActiveSounds.end();++snditer)
{
@ -928,6 +933,7 @@ namespace MWSound
mMusic->mBaseVolume = volumeFromType(mMusic->getPlayType());
mMusic->update();
}
mOutput->finishUpdate();
}
void SoundManager::setListenerPosDir(const osg::Vec3f &pos, const osg::Vec3f &dir, const osg::Vec3f &up)