From 3fa1e7ebafc090727eb7da1410b44de863c74bd9 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 28 Jun 2020 13:49:05 +0200 Subject: [PATCH 1/2] Make time passed SoundManager field --- apps/openmw/mwsound/soundmanagerimp.cpp | 12 ++++++------ apps/openmw/mwsound/soundmanagerimp.hpp | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index a1eb59bac5..42c8d9065a 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -32,6 +32,8 @@ namespace MWSound { namespace { + constexpr float sMinUpdateInterval = 1.0f / 30.0f; + WaterSoundUpdaterSettings makeWaterSoundUpdaterSettings() { WaterSoundUpdaterSettings settings; @@ -946,13 +948,11 @@ namespace MWSound mSaySoundsQueue.erase(queuesayiter++); } - static float timePassed = 0.0; - - timePassed += duration; - if(timePassed < (1.0f/30.0f)) + mTimePassed += duration; + if (mTimePassed < sMinUpdateInterval) return; - duration = timePassed; - timePassed = 0.0f; + duration = mTimePassed; + mTimePassed = 0.0f; // Make sure music is still playing if(!isMusicPlaying() && !mCurrentPlaylist.empty()) diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index c79f9abe57..b3d43dc88c 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -114,6 +114,8 @@ namespace MWSound RegionSoundSelector mRegionSoundSelector; + float mTimePassed = 0; + Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound); Sound_Buffer *lookupSound(const std::string &soundId) const; From 6ab1a1f9073ac4fed68ad4b034818dcd8f036dc7 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 28 Jun 2020 14:52:50 +0200 Subject: [PATCH 2/2] Make last cell a field of SoundManager and initialize --- apps/openmw/mwsound/soundmanagerimp.cpp | 7 +++---- apps/openmw/mwsound/soundmanagerimp.hpp | 3 +++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 42c8d9065a..be7c68e64d 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -887,7 +887,6 @@ namespace MWSound void SoundManager::updateWaterSound(float /*duration*/) { - static const ESM::Cell *LastCell; MWBase::World* world = MWBase::Environment::get().getWorld(); const MWWorld::ConstPtr player = world->getPlayerPtr(); const ESM::Cell *curcell = player.getCell()->getCell(); @@ -905,9 +904,9 @@ namespace MWSound bool soundIdChanged = false; Sound_Buffer *sfx = lookupSound(update.mId); - if(LastCell != curcell) + if (mLastCell != curcell) { - LastCell = curcell; + mLastCell = curcell; SoundMap::const_iterator snditer = mActiveSounds.find(MWWorld::Ptr()); if(snditer != mActiveSounds.end()) { @@ -932,7 +931,7 @@ namespace MWSound } else if (update.mVolume > 0.0f) { - LastCell = curcell; + mLastCell = curcell; mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop); } } diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index b3d43dc88c..85aa0a3864 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -27,6 +27,7 @@ namespace VFS namespace ESM { struct Sound; + struct Cell; } namespace MWSound @@ -116,6 +117,8 @@ namespace MWSound float mTimePassed = 0; + const ESM::Cell *mLastCell = nullptr; + Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound); Sound_Buffer *lookupSound(const std::string &soundId) const;