Merge branch 'sound_mapping' into 'master'

Use a separate lookup for sound files

See merge request OpenMW/openmw!3358
macos_ci_fix
psi29a 1 year ago
commit ef69ec4adf

@ -64,8 +64,14 @@ namespace MWSound
Sound_Buffer* SoundBufferPool::lookup(std::string_view fileName) const
{
auto soundId = ESM::RefId::stringRefId(fileName);
return lookup(soundId);
const auto it = mBufferFileNameMap.find(std::string(fileName));
if (it != mBufferFileNameMap.end())
{
Sound_Buffer* sfx = it->second;
if (sfx->getHandle() != nullptr)
return sfx;
}
return nullptr;
}
Sound_Buffer* SoundBufferPool::loadSfx(Sound_Buffer* sfx)
@ -116,11 +122,9 @@ namespace MWSound
Sound_Buffer* SoundBufferPool::load(std::string_view fileName)
{
auto soundId = ESM::RefId::stringRefId(fileName);
Sound_Buffer* sfx;
const auto it = mBufferNameMap.find(soundId);
if (it != mBufferNameMap.end())
const auto it = mBufferFileNameMap.find(std::string(fileName));
if (it != mBufferFileNameMap.end())
sfx = it->second;
else
{
@ -138,6 +142,9 @@ namespace MWSound
mOutput->unloadSound(sfx.mHandle);
sfx.mHandle = nullptr;
}
mBufferFileNameMap.clear();
mBufferNameMap.clear();
mUnusedBuffers.clear();
}
@ -155,7 +162,7 @@ namespace MWSound
Sound_Buffer& sfx = mSoundBuffers.emplace_back(fileName, volume, min, max);
mBufferNameMap.emplace(ESM::RefId::stringRefId(fileName), &sfx);
mBufferFileNameMap.emplace(fileName, &sfx);
return &sfx;
}

@ -104,6 +104,7 @@ namespace MWSound
Sound_Output* mOutput;
std::deque<Sound_Buffer> mSoundBuffers;
std::unordered_map<ESM::RefId, Sound_Buffer*> mBufferNameMap;
std::unordered_map<std::string, Sound_Buffer*> mBufferFileNameMap;
std::size_t mBufferCacheMax;
std::size_t mBufferCacheMin;
std::size_t mBufferCacheSize = 0;

@ -534,6 +534,9 @@ namespace MWSound
return nullptr;
std::string normalizedName = VFS::Path::normalizeFilename(fileName);
if (!mVFS->exists(normalizedName))
return nullptr;
Sound_Buffer* sfx = mSoundBuffers.load(normalizedName);
if (!sfx)
return nullptr;
@ -630,6 +633,9 @@ namespace MWSound
// Look up the sound
std::string normalizedName = VFS::Path::normalizeFilename(fileName);
if (!mVFS->exists(normalizedName))
return nullptr;
Sound_Buffer* sfx = mSoundBuffers.load(normalizedName);
if (!sfx)
return nullptr;
@ -705,9 +711,15 @@ namespace MWSound
void SoundManager::stopSound3D(const MWWorld::ConstPtr& ptr, std::string_view fileName)
{
if (!mOutput->isInitialized())
return;
std::string normalizedName = VFS::Path::normalizeFilename(fileName);
auto soundId = ESM::RefId::stringRefId(normalizedName);
stopSound3D(ptr, soundId);
Sound_Buffer* sfx = mSoundBuffers.lookup(normalizedName);
if (!sfx)
return;
stopSound(sfx, ptr);
}
void SoundManager::stopSound3D(const MWWorld::ConstPtr& ptr)
@ -769,8 +781,21 @@ namespace MWSound
bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr& ptr, std::string_view fileName) const
{
std::string normalizedName = VFS::Path::normalizeFilename(fileName);
auto soundId = ESM::RefId::stringRefId(normalizedName);
return getSoundPlaying(ptr, soundId);
SoundMap::const_iterator snditer = mActiveSounds.find(ptr.mRef);
if (snditer != mActiveSounds.end())
{
Sound_Buffer* sfx = mSoundBuffers.lookup(normalizedName);
if (!sfx)
return false;
return std::find_if(snditer->second.mList.cbegin(), snditer->second.mList.cend(),
[this, sfx](const SoundBufferRefPair& snd) -> bool {
return snd.second == sfx && mOutput->isSoundPlaying(snd.first.get());
})
!= snditer->second.mList.cend();
}
return false;
}
bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr& ptr, const ESM::RefId& soundId) const
@ -779,6 +804,9 @@ namespace MWSound
if (snditer != mActiveSounds.end())
{
Sound_Buffer* sfx = mSoundBuffers.lookup(soundId);
if (!sfx)
return false;
return std::find_if(snditer->second.mList.cbegin(), snditer->second.mList.cend(),
[this, sfx](const SoundBufferRefPair& snd) -> bool {
return snd.second == sfx && mOutput->isSoundPlaying(snd.first.get());

Loading…
Cancel
Save