Support for per-type sound blockers

pull/2749/head
Andrei Kortunov 5 years ago
parent bb7c2ac630
commit 3d6fd2818f

@ -168,10 +168,10 @@ namespace MWBase
///< Is the given sound currently playing on the given object? ///< 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 /// If you want to check if sound played with playSound is playing, use empty Ptr
virtual void pauseSounds(int types=static_cast<int>(Type::Mask)) = 0; virtual void pauseSounds(const std::string& blockerId, int types=int(Type::Mask)) = 0;
///< Pauses all currently playing sounds, including music. ///< Pauses all currently playing sounds, including music.
virtual void resumeSounds(int types=static_cast<int>(Type::Mask)) = 0; virtual void resumeSounds(const std::string& blockerId) = 0;
///< Resumes all previously paused sounds. ///< Resumes all previously paused sounds.
virtual void update(float duration) = 0; virtual void update(float duration) = 0;

@ -1893,7 +1893,7 @@ namespace MWGui
setCursorVisible(false); setCursorVisible(false);
if (mVideoWidget->hasAudioStream()) if (mVideoWidget->hasAudioStream())
MWBase::Environment::get().getSoundManager()->pauseSounds( MWBase::Environment::get().getSoundManager()->pauseSounds("Video",
~MWSound::Type::Movie & MWSound::Type::Mask ~MWSound::Type::Movie & MWSound::Type::Mask
); );
osg::Timer frameTimer; osg::Timer frameTimer;
@ -1921,7 +1921,7 @@ namespace MWGui
} }
mVideoWidget->stop(); mVideoWidget->stop();
MWBase::Environment::get().getSoundManager()->resumeSounds(); MWBase::Environment::get().getSoundManager()->resumeSounds("Video");
setKeyFocusWidget(oldKeyFocus); setKeyFocusWidget(oldKeyFocus);

@ -50,7 +50,6 @@ namespace MWSound
, mListenerPos(0,0,0) , mListenerPos(0,0,0)
, mListenerDir(1,0,0) , mListenerDir(1,0,0)
, mListenerUp(0,0,1) , mListenerUp(0,0,1)
, mPausedSoundTypes(0)
, mUnderwaterSound(nullptr) , mUnderwaterSound(nullptr)
, mNearWaterSound(nullptr) , mNearWaterSound(nullptr)
{ {
@ -858,27 +857,36 @@ namespace MWSound
} }
void SoundManager::pauseSounds(int types) void SoundManager::pauseSounds(const std::string& blockerId, int types)
{ {
if(mOutput->isInitialized()) if(mOutput->isInitialized())
{ {
auto found = mPausedSoundTypes.find(blockerId);
if (found != mPausedSoundTypes.end() && found->second != types)
resumeSounds(blockerId);
types = types & Type::Mask; types = types & Type::Mask;
mOutput->pauseSounds(types); mOutput->pauseSounds(types);
mPausedSoundTypes |= types; mPausedSoundTypes[blockerId] = types;
} }
} }
void SoundManager::resumeSounds(int types) void SoundManager::resumeSounds(const std::string& blockerId)
{ {
if(mOutput->isInitialized()) if(mOutput->isInitialized())
{ {
types = types & Type::Mask & mPausedSoundTypes; mPausedSoundTypes.erase(blockerId);
int types = int(Type::Mask);
for (auto& blocker : mPausedSoundTypes)
{
if (blocker.first != blockerId)
types &= ~blocker.second;
}
mOutput->resumeSounds(types); mOutput->resumeSounds(types);
mPausedSoundTypes &= ~types;
} }
} }
void SoundManager::updateRegionSound(float duration) void SoundManager::updateRegionSound(float duration)
{ {
static float sTimeToNextEnvSound = 0.0f; static float sTimeToNextEnvSound = 0.0f;
@ -1399,5 +1407,6 @@ namespace MWSound
mUnusedStreams.push_back(sound); mUnusedStreams.push_back(sound);
} }
mActiveTracks.clear(); mActiveTracks.clear();
mPausedSoundTypes.clear();
} }
} }

@ -107,7 +107,7 @@ namespace MWSound
osg::Vec3f mListenerDir; osg::Vec3f mListenerDir;
osg::Vec3f mListenerUp; osg::Vec3f mListenerUp;
int mPausedSoundTypes; std::unordered_map<std::string, int> mPausedSoundTypes;
Sound *mUnderwaterSound; Sound *mUnderwaterSound;
Sound *mNearWaterSound; Sound *mNearWaterSound;
@ -244,10 +244,10 @@ namespace MWSound
virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const; virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const;
///< Is the given sound currently playing on the given object? ///< Is the given sound currently playing on the given object?
virtual void pauseSounds(int types); virtual void pauseSounds(const std::string& blockerId, int types=int(Type::Mask));
///< Pauses all currently playing sounds, including music. ///< Pauses all currently playing sounds, including music.
virtual void resumeSounds(int types); virtual void resumeSounds(const std::string& blockerId);
///< Resumes all previously paused sounds. ///< Resumes all previously paused sounds.
virtual void update(float duration); virtual void update(float duration);

Loading…
Cancel
Save