1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:53:51 +00:00

Prepare all Sound_Buffers when retrieving the first one

This commit is contained in:
Chris Robinson 2017-09-16 03:48:41 -07:00
parent 4b448c74d2
commit 5c53ee42a1

View file

@ -185,9 +185,23 @@ namespace MWSound
// minRange, and maxRange), and ensure it's ready for use. // minRange, and maxRange), and ensure it's ready for use.
Sound_Buffer *SoundManager::loadSound(const std::string &soundId) Sound_Buffer *SoundManager::loadSound(const std::string &soundId)
{ {
#ifdef __GNUC__
#define LIKELY(x) __builtin_expect((bool)(x), true)
#define UNLIKELY(x) __builtin_expect((bool)(x), false)
#else
#define LIKELY(x) (bool)(x)
#define UNLIKELY(x) (bool)(x)
#endif
if(UNLIKELY(mBufferNameMap.empty()))
{
MWBase::World *world = MWBase::Environment::get().getWorld();
for(const ESM::Sound &sound : world->getStore().get<ESM::Sound>())
insertSound(Misc::StringUtils::lowerCase(sound.mId), &sound);
}
Sound_Buffer *sfx; Sound_Buffer *sfx;
NameBufferMap::const_iterator snd = mBufferNameMap.find(soundId); NameBufferMap::const_iterator snd = mBufferNameMap.find(soundId);
if(snd != mBufferNameMap.end()) if(LIKELY(snd != mBufferNameMap.end()))
sfx = snd->second; sfx = snd->second;
else else
{ {
@ -196,6 +210,8 @@ namespace MWSound
if(!sound) return nullptr; if(!sound) return nullptr;
sfx = insertSound(soundId, sound); sfx = insertSound(soundId, sound);
} }
#undef LIKELY
#undef UNLIKELY
if(!sfx->mHandle) if(!sfx->mHandle)
{ {