From 1ce296aa7f0e73e5b72d29ba1141602fbbc728f7 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 24 Oct 2020 18:54:46 +0200 Subject: [PATCH 1/2] Use fallback values for region sounds and fix probability --- apps/openmw/mwsound/regionsoundselector.cpp | 16 ++++++++++++---- apps/openmw/mwsound/regionsoundselector.hpp | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwsound/regionsoundselector.cpp b/apps/openmw/mwsound/regionsoundselector.cpp index ac5f66721d..55afd6ab65 100644 --- a/apps/openmw/mwsound/regionsoundselector.cpp +++ b/apps/openmw/mwsound/regionsoundselector.cpp @@ -1,5 +1,6 @@ #include "regionsoundselector.hpp" +#include #include #include @@ -18,6 +19,12 @@ namespace MWSound } } + RegionSoundSelector::RegionSoundSelector() + { + mMinTimeBetweenSounds = Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"); + mMaxTimeBetweenSounds = Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds"); + } + boost::optional RegionSoundSelector::getNextRandom(float duration, const std::string& regionName, const MWBase::World& world) { @@ -27,9 +34,7 @@ namespace MWSound return {}; const float a = Misc::Rng::rollClosedProbability(); - // NOTE: We should use the "Minimum Time Between Environmental Sounds" and - // "Maximum Time Between Environmental Sounds" fallback settings here. - mTimeToNextEnvSound = 5.0f * a + 15.0f * (1.0f - a); + mTimeToNextEnvSound = mMinTimeBetweenSounds + (mMaxTimeBetweenSounds - mMinTimeBetweenSounds) * a; mTimePassed = 0; if (mLastRegionName != regionName) @@ -50,7 +55,7 @@ namespace MWSound return {}; } - const int r = Misc::Rng::rollDice(mSumChance); + const int r = Misc::Rng::rollDice(std::max(mSumChance, 100)); int pos = 0; const auto isSelected = [&] (const ESM::Region::SoundRef& sound) @@ -66,6 +71,9 @@ namespace MWSound if (it == region->mSoundList.end()) return {}; + // TODO + // mTimeToNextEnvSound += soundDuration + return it->mSound; } } diff --git a/apps/openmw/mwsound/regionsoundselector.hpp b/apps/openmw/mwsound/regionsoundselector.hpp index 00a2d5ca85..13510a0f67 100644 --- a/apps/openmw/mwsound/regionsoundselector.hpp +++ b/apps/openmw/mwsound/regionsoundselector.hpp @@ -18,11 +18,15 @@ namespace MWSound boost::optional getNextRandom(float duration, const std::string& regionName, const MWBase::World& world); + RegionSoundSelector(); + private: float mTimeToNextEnvSound = 0.0f; int mSumChance = 0; std::string mLastRegionName; float mTimePassed = 0.0; + float mMinTimeBetweenSounds; + float mMaxTimeBetweenSounds; }; } From eebb320916f1a96aa02576487c478063ab09d2c1 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 25 Oct 2020 12:20:14 +0100 Subject: [PATCH 2/2] Wait for the previous sound to stop --- CHANGELOG.md | 1 + apps/openmw/mwsound/regionsoundselector.cpp | 10 +++------- apps/openmw/mwsound/soundmanagerimp.cpp | 4 +++- apps/openmw/mwsound/soundmanagerimp.hpp | 2 ++ 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3c5fe5578..0d51322078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,7 @@ Bug #5639: Tooltips cover Messageboxes Bug #5644: Summon effects running on the player during game initialization cause crashes 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 #2386: Distant Statics in the form of Object Paging Feature #2404: Levelled List can not be placed into a container diff --git a/apps/openmw/mwsound/regionsoundselector.cpp b/apps/openmw/mwsound/regionsoundselector.cpp index 55afd6ab65..df2125e6dc 100644 --- a/apps/openmw/mwsound/regionsoundselector.cpp +++ b/apps/openmw/mwsound/regionsoundselector.cpp @@ -20,10 +20,9 @@ namespace MWSound } RegionSoundSelector::RegionSoundSelector() - { - mMinTimeBetweenSounds = Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds"); - mMaxTimeBetweenSounds = Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds"); - } + : mMinTimeBetweenSounds(Fallback::Map::getFloat("Weather_Minimum_Time_Between_Environmental_Sounds")) + , mMaxTimeBetweenSounds(Fallback::Map::getFloat("Weather_Maximum_Time_Between_Environmental_Sounds")) + {} boost::optional RegionSoundSelector::getNextRandom(float duration, const std::string& regionName, const MWBase::World& world) @@ -71,9 +70,6 @@ namespace MWSound if (it == region->mSoundList.end()) return {}; - // TODO - // mTimeToNextEnvSound += soundDuration - return it->mSound; } } diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 17aa184a77..d33b3d26e0 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -895,9 +895,11 @@ namespace MWSound if (!cell->isExterior()) return; + if (mCurrentRegionSound && mOutput->isSoundPlaying(mCurrentRegionSound)) + return; 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() diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 37b099c027..0c82528b52 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -120,6 +120,8 @@ namespace MWSound const ESM::Cell *mLastCell = nullptr; + Sound* mCurrentRegionSound; + Sound_Buffer *insertSound(const std::string &soundId, const ESM::Sound *sound); Sound_Buffer *lookupSound(const std::string &soundId) const;