Use enums for blockers IDs instead of strings

pull/2749/head
Andrei Kortunov 5 years ago
parent 2254256db9
commit e444766901

@ -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;

@ -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);

@ -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);
}
}

@ -107,7 +107,7 @@ namespace MWSound
osg::Vec3f mListenerDir;
osg::Vec3f mListenerUp;
std::unordered_map<std::string, int> 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();

Loading…
Cancel
Save