diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index ac3e05ac7..cc933d4bb 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -14,6 +14,14 @@ namespace MWWorld namespace MWSound { + // Each entry excepts of MaxCount should be used only in one place + enum BlockerType + { + VideoPlayback, + + MaxCount + }; + class Sound; class Stream; struct Sound_Decoder; @@ -168,10 +176,10 @@ namespace MWBase ///< Is the given sound currently playing on the given object? /// If you want to check if sound played with playSound is playing, use empty Ptr - virtual void pauseSounds(const std::string& blockerId, int types=int(Type::Mask)) = 0; + virtual void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) = 0; ///< Pauses all currently playing sounds, including music. - virtual void resumeSounds(const std::string& blockerId) = 0; + virtual void resumeSounds(MWSound::BlockerType blocker) = 0; ///< Resumes all previously paused sounds. virtual void pausePlayback() = 0; diff --git a/apps/openmw/mwgui/windowmanagerimp.cpp b/apps/openmw/mwgui/windowmanagerimp.cpp index c6bc06f8f..4f36032e1 100644 --- a/apps/openmw/mwgui/windowmanagerimp.cpp +++ b/apps/openmw/mwgui/windowmanagerimp.cpp @@ -1893,9 +1893,10 @@ namespace MWGui setCursorVisible(false); if (mVideoWidget->hasAudioStream()) - MWBase::Environment::get().getSoundManager()->pauseSounds("Video", + MWBase::Environment::get().getSoundManager()->pauseSounds(MWSound::VideoPlayback, ~MWSound::Type::Movie & MWSound::Type::Mask ); + osg::Timer frameTimer; while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) { @@ -1927,7 +1928,7 @@ namespace MWGui } mVideoWidget->stop(); - MWBase::Environment::get().getSoundManager()->resumeSounds("Video"); + MWBase::Environment::get().getSoundManager()->resumeSounds(MWSound::VideoPlayback); setKeyFocusWidget(oldKeyFocus); diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 8462f0929..eff1cf0fd 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -857,30 +857,29 @@ namespace MWSound return false; } - void SoundManager::pauseSounds(const std::string& blockerId, int types) + void SoundManager::pauseSounds(BlockerType blocker, int types) { if(mOutput->isInitialized()) { - auto found = mPausedSoundTypes.find(blockerId); - if (found != mPausedSoundTypes.end() && found->second != types) - resumeSounds(blockerId); + if (mPausedSoundTypes[blocker] != 0) + resumeSounds(blocker); types = types & Type::Mask; mOutput->pauseSounds(types); - mPausedSoundTypes[blockerId] = types; + mPausedSoundTypes[blocker] = types; } } - void SoundManager::resumeSounds(const std::string& blockerId) + void SoundManager::resumeSounds(BlockerType blocker) { if(mOutput->isInitialized()) { - mPausedSoundTypes.erase(blockerId); + mPausedSoundTypes[blocker] = 0; int types = int(Type::Mask); - for (auto& blocker : mPausedSoundTypes) + for (int currentBlocker = 0; currentBlocker < BlockerType::MaxCount; currentBlocker++) { - if (blocker.first != blockerId) - types &= ~blocker.second; + if (currentBlocker != blocker) + types &= ~mPausedSoundTypes[currentBlocker]; } mOutput->resumeSounds(types); @@ -1425,7 +1424,7 @@ namespace MWSound mUnusedStreams.push_back(sound); } mActiveTracks.clear(); - mPausedSoundTypes.clear(); mPlaybackPaused = false; + std::fill(std::begin(mPausedSoundTypes), std::end(mPausedSoundTypes), 0); } } diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index b2ccc702a..55588d06f 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -107,7 +107,7 @@ namespace MWSound osg::Vec3f mListenerDir; osg::Vec3f mListenerUp; - std::unordered_map mPausedSoundTypes; + int mPausedSoundTypes[BlockerType::MaxCount] = {}; Sound *mUnderwaterSound; Sound *mNearWaterSound; @@ -245,10 +245,10 @@ namespace MWSound virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const; ///< Is the given sound currently playing on the given object? - virtual void pauseSounds(const std::string& blockerId, int types=int(Type::Mask)); + virtual void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)); ///< Pauses all currently playing sounds, including music. - virtual void resumeSounds(const std::string& blockerId); + virtual void resumeSounds(MWSound::BlockerType blocker); ///< Resumes all previously paused sounds. virtual void pausePlayback();