Merge pull request #2948 from elsid/rm_sound_local_static

Replace SoundManager local static variables by fields
This commit is contained in:
Bret Curtis 2020-07-02 23:26:25 +02:00 committed by GitHub
commit 4dbc0a34ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 10 deletions

View File

@ -32,6 +32,8 @@ namespace MWSound
{ {
namespace namespace
{ {
constexpr float sMinUpdateInterval = 1.0f / 30.0f;
WaterSoundUpdaterSettings makeWaterSoundUpdaterSettings() WaterSoundUpdaterSettings makeWaterSoundUpdaterSettings()
{ {
WaterSoundUpdaterSettings settings; WaterSoundUpdaterSettings settings;
@ -885,7 +887,6 @@ namespace MWSound
void SoundManager::updateWaterSound(float /*duration*/) void SoundManager::updateWaterSound(float /*duration*/)
{ {
static const ESM::Cell *LastCell;
MWBase::World* world = MWBase::Environment::get().getWorld(); MWBase::World* world = MWBase::Environment::get().getWorld();
const MWWorld::ConstPtr player = world->getPlayerPtr(); const MWWorld::ConstPtr player = world->getPlayerPtr();
const ESM::Cell *curcell = player.getCell()->getCell(); const ESM::Cell *curcell = player.getCell()->getCell();
@ -903,9 +904,9 @@ namespace MWSound
bool soundIdChanged = false; bool soundIdChanged = false;
Sound_Buffer *sfx = lookupSound(update.mId); Sound_Buffer *sfx = lookupSound(update.mId);
if(LastCell != curcell) if (mLastCell != curcell)
{ {
LastCell = curcell; mLastCell = curcell;
SoundMap::const_iterator snditer = mActiveSounds.find(MWWorld::Ptr()); SoundMap::const_iterator snditer = mActiveSounds.find(MWWorld::Ptr());
if(snditer != mActiveSounds.end()) if(snditer != mActiveSounds.end())
{ {
@ -930,7 +931,7 @@ namespace MWSound
} }
else if (update.mVolume > 0.0f) else if (update.mVolume > 0.0f)
{ {
LastCell = curcell; mLastCell = curcell;
mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop); mNearWaterSound = playSound(update.mId, update.mVolume, 1.0f, Type::Sfx, PlayMode::Loop);
} }
} }
@ -946,13 +947,11 @@ namespace MWSound
mSaySoundsQueue.erase(queuesayiter++); mSaySoundsQueue.erase(queuesayiter++);
} }
static float timePassed = 0.0; mTimePassed += duration;
if (mTimePassed < sMinUpdateInterval)
timePassed += duration;
if(timePassed < (1.0f/30.0f))
return; return;
duration = timePassed; duration = mTimePassed;
timePassed = 0.0f; mTimePassed = 0.0f;
// Make sure music is still playing // Make sure music is still playing
if(!isMusicPlaying() && !mCurrentPlaylist.empty()) if(!isMusicPlaying() && !mCurrentPlaylist.empty())

View File

@ -27,6 +27,7 @@ namespace VFS
namespace ESM namespace ESM
{ {
struct Sound; struct Sound;
struct Cell;
} }
namespace MWSound namespace MWSound
@ -114,6 +115,10 @@ namespace MWSound
RegionSoundSelector mRegionSoundSelector; RegionSoundSelector mRegionSoundSelector;
float mTimePassed = 0;
const ESM::Cell *mLastCell = nullptr;
Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound); Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound);
Sound_Buffer *lookupSound(const std::string &soundId) const; Sound_Buffer *lookupSound(const std::string &soundId) const;