1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-22 12:39:59 +00:00

Use enums for blockers IDs instead of strings

This commit is contained in:
Andrei Kortunov 2020-04-05 18:10:05 +04:00
parent 2254256db9
commit e444766901
4 changed files with 26 additions and 18 deletions

View File

@ -14,6 +14,14 @@ namespace MWWorld
namespace MWSound namespace MWSound
{ {
// Each entry excepts of MaxCount should be used only in one place
enum BlockerType
{
VideoPlayback,
MaxCount
};
class Sound; class Sound;
class Stream; class Stream;
struct Sound_Decoder; struct Sound_Decoder;
@ -168,10 +176,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(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. ///< 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. ///< Resumes all previously paused sounds.
virtual void pausePlayback() = 0; virtual void pausePlayback() = 0;

View File

@ -1893,9 +1893,10 @@ namespace MWGui
setCursorVisible(false); setCursorVisible(false);
if (mVideoWidget->hasAudioStream()) if (mVideoWidget->hasAudioStream())
MWBase::Environment::get().getSoundManager()->pauseSounds("Video", MWBase::Environment::get().getSoundManager()->pauseSounds(MWSound::VideoPlayback,
~MWSound::Type::Movie & MWSound::Type::Mask ~MWSound::Type::Movie & MWSound::Type::Mask
); );
osg::Timer frameTimer; osg::Timer frameTimer;
while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest()) while (mVideoWidget->update() && !MWBase::Environment::get().getStateManager()->hasQuitRequest())
{ {
@ -1927,7 +1928,7 @@ namespace MWGui
} }
mVideoWidget->stop(); mVideoWidget->stop();
MWBase::Environment::get().getSoundManager()->resumeSounds("Video"); MWBase::Environment::get().getSoundManager()->resumeSounds(MWSound::VideoPlayback);
setKeyFocusWidget(oldKeyFocus); setKeyFocusWidget(oldKeyFocus);

View File

@ -857,30 +857,29 @@ namespace MWSound
return false; return false;
} }
void SoundManager::pauseSounds(const std::string& blockerId, int types) void SoundManager::pauseSounds(BlockerType blocker, int types)
{ {
if(mOutput->isInitialized()) if(mOutput->isInitialized())
{ {
auto found = mPausedSoundTypes.find(blockerId); if (mPausedSoundTypes[blocker] != 0)
if (found != mPausedSoundTypes.end() && found->second != types) resumeSounds(blocker);
resumeSounds(blockerId);
types = types & Type::Mask; types = types & Type::Mask;
mOutput->pauseSounds(types); mOutput->pauseSounds(types);
mPausedSoundTypes[blockerId] = types; mPausedSoundTypes[blocker] = types;
} }
} }
void SoundManager::resumeSounds(const std::string& blockerId) void SoundManager::resumeSounds(BlockerType blocker)
{ {
if(mOutput->isInitialized()) if(mOutput->isInitialized())
{ {
mPausedSoundTypes.erase(blockerId); mPausedSoundTypes[blocker] = 0;
int types = int(Type::Mask); int types = int(Type::Mask);
for (auto& blocker : mPausedSoundTypes) for (int currentBlocker = 0; currentBlocker < BlockerType::MaxCount; currentBlocker++)
{ {
if (blocker.first != blockerId) if (currentBlocker != blocker)
types &= ~blocker.second; types &= ~mPausedSoundTypes[currentBlocker];
} }
mOutput->resumeSounds(types); mOutput->resumeSounds(types);
@ -1425,7 +1424,7 @@ namespace MWSound
mUnusedStreams.push_back(sound); mUnusedStreams.push_back(sound);
} }
mActiveTracks.clear(); mActiveTracks.clear();
mPausedSoundTypes.clear();
mPlaybackPaused = false; mPlaybackPaused = false;
std::fill(std::begin(mPausedSoundTypes), std::end(mPausedSoundTypes), 0);
} }
} }

View File

@ -107,7 +107,7 @@ namespace MWSound
osg::Vec3f mListenerDir; osg::Vec3f mListenerDir;
osg::Vec3f mListenerUp; osg::Vec3f mListenerUp;
std::unordered_map<std::string, int> mPausedSoundTypes; int mPausedSoundTypes[BlockerType::MaxCount] = {};
Sound *mUnderwaterSound; Sound *mUnderwaterSound;
Sound *mNearWaterSound; Sound *mNearWaterSound;
@ -245,10 +245,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(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. ///< 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. ///< Resumes all previously paused sounds.
virtual void pausePlayback(); virtual void pausePlayback();