1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 09:23:51 +00:00

Merge branch 'regionsounds' into 'master'

Fix region sounds

See merge request OpenMW/openmw!370
This commit is contained in:
psi29a 2020-10-26 16:29:45 +00:00
commit f6e4c7cb42
5 changed files with 18 additions and 5 deletions

View file

@ -60,6 +60,7 @@
Bug #5639: Tooltips cover Messageboxes Bug #5639: Tooltips cover Messageboxes
Bug #5644: Summon effects running on the player during game initialization cause crashes Bug #5644: Summon effects running on the player during game initialization cause crashes
Bug #5656: Sneaking characters block hits while standing Bug #5656: Sneaking characters block hits while standing
Bug #5661: Region sounds don't play at the right interval
Feature #390: 3rd person look "over the shoulder" Feature #390: 3rd person look "over the shoulder"
Feature #2386: Distant Statics in the form of Object Paging Feature #2386: Distant Statics in the form of Object Paging
Feature #2404: Levelled List can not be placed into a container Feature #2404: Levelled List can not be placed into a container

View file

@ -1,5 +1,6 @@
#include "regionsoundselector.hpp" #include "regionsoundselector.hpp"
#include <components/fallback/fallback.hpp>
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <algorithm> #include <algorithm>
@ -18,6 +19,11 @@ namespace MWSound
} }
} }
RegionSoundSelector::RegionSoundSelector()
: mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"))
, mMaxTimeBetweenSounds(Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds"))
{}
std::optional<std::string> RegionSoundSelector::getNextRandom(float duration, const std::string& regionName, std::optional<std::string> RegionSoundSelector::getNextRandom(float duration, const std::string& regionName,
const MWBase::World& world) const MWBase::World& world)
{ {
@ -27,9 +33,7 @@ namespace MWSound
return {}; return {};
const float a = Misc::Rng::rollClosedProbability(); const float a = Misc::Rng::rollClosedProbability();
// NOTE: We should use the "Minimum Time Between Environmental Sounds" and mTimeToNextEnvSound = mMinTimeBetweenSounds + (mMaxTimeBetweenSounds - mMinTimeBetweenSounds) * a;
// "Maximum Time Between Environmental Sounds" fallback settings here.
mTimeToNextEnvSound = 5.0f * a + 15.0f * (1.0f - a);
mTimePassed = 0; mTimePassed = 0;
if (mLastRegionName != regionName) if (mLastRegionName != regionName)
@ -50,7 +54,7 @@ namespace MWSound
return {}; return {};
} }
const int r = Misc::Rng::rollDice(mSumChance); const int r = Misc::Rng::rollDice(std::max(mSumChance, 100));
int pos = 0; int pos = 0;
const auto isSelected = [&] (const ESM::Region::SoundRef& sound) const auto isSelected = [&] (const ESM::Region::SoundRef& sound)

View file

@ -17,11 +17,15 @@ namespace MWSound
std::optional<std::string> getNextRandom(float duration, const std::string& regionName, std::optional<std::string> getNextRandom(float duration, const std::string& regionName,
const MWBase::World& world); const MWBase::World& world);
RegionSoundSelector();
private: private:
float mTimeToNextEnvSound = 0.0f; float mTimeToNextEnvSound = 0.0f;
int mSumChance = 0; int mSumChance = 0;
std::string mLastRegionName; std::string mLastRegionName;
float mTimePassed = 0.0; float mTimePassed = 0.0;
float mMinTimeBetweenSounds;
float mMaxTimeBetweenSounds;
}; };
} }

View file

@ -895,9 +895,11 @@ namespace MWSound
if (!cell->isExterior()) if (!cell->isExterior())
return; return;
if (mCurrentRegionSound && mOutput->isSoundPlaying(mCurrentRegionSound))
return;
if (const auto next = mRegionSoundSelector.getNextRandom(duration, cell->mRegion, *world)) if (const auto next = mRegionSoundSelector.getNextRandom(duration, cell->mRegion, *world))
playSound(*next, 1.0f, 1.0f); mCurrentRegionSound = playSound(*next, 1.0f, 1.0f);
} }
void SoundManager::updateWaterSound() void SoundManager::updateWaterSound()

View file

@ -120,6 +120,8 @@ namespace MWSound
const ESM::Cell *mLastCell = nullptr; const ESM::Cell *mLastCell = nullptr;
Sound* mCurrentRegionSound;
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;