1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 18:45:38 +00:00

Merge branch 'rainloop' into 'master'

Support playing ambient and rain weather SFX at the same time (bug #7761)

Closes #7761

See merge request OpenMW/openmw!3738
This commit is contained in:
psi29a 2024-01-08 07:59:55 +00:00
commit 7019405278
4 changed files with 52 additions and 19 deletions

View file

@ -123,6 +123,7 @@
Bug #7724: Guards don't help vs werewolves Bug #7724: Guards don't help vs werewolves
Bug #7742: Governing attribute training limit should use the modified attribute Bug #7742: Governing attribute training limit should use the modified attribute
Bug #7758: Water walking is not taken into account to compute path cost on the water Bug #7758: Water walking is not taken into account to compute path cost on the water
Bug #7761: Rain and ambient loop sounds are mutually exclusive
Feature #2566: Handle NAM9 records for manual cell references Feature #2566: Handle NAM9 records for manual cell references
Feature #3537: Shader-based water ripples Feature #3537: Shader-based water ripples
Feature #5173: Support for NiFogProperty Feature #5173: Support for NiFogProperty

View file

@ -65,6 +65,7 @@ namespace MWRender
bool mIsStorm; bool mIsStorm;
ESM::RefId mAmbientLoopSoundID; ESM::RefId mAmbientLoopSoundID;
ESM::RefId mRainLoopSoundID;
float mAmbientSoundVolume; float mAmbientSoundVolume;
std::string mParticleEffect; std::string mParticleEffect;

View file

@ -195,21 +195,19 @@ namespace MWWorld
mThunderSoundID[3] mThunderSoundID[3]
= ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_3")); = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Thunder_Sound_ID_3"));
// TODO: support weathers that have both "Ambient Loop Sound ID" and "Rain Loop Sound ID", need to play both
// sounds at the same time.
if (!mRainEffect.empty()) // NOTE: in vanilla, the weathers with rain seem to be hardcoded; changing if (!mRainEffect.empty()) // NOTE: in vanilla, the weathers with rain seem to be hardcoded; changing
// Using_Precip has no effect // Using_Precip has no effect
{ {
mAmbientLoopSoundID mRainLoopSoundID
= ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Rain_Loop_Sound_ID")); = ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Rain_Loop_Sound_ID"));
if (mAmbientLoopSoundID.empty()) // default to "rain" if not set if (mRainLoopSoundID.empty()) // default to "rain" if not set
mAmbientLoopSoundID = ESM::RefId::stringRefId("rain"); mRainLoopSoundID = ESM::RefId::stringRefId("rain");
else if (mRainLoopSoundID == "None")
mRainLoopSoundID = ESM::RefId();
} }
else
mAmbientLoopSoundID
= ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Ambient_Loop_Sound_ID"));
mAmbientLoopSoundID
= ESM::RefId::stringRefId(Fallback::Map::getString("Weather_" + name + "_Ambient_Loop_Sound_ID"));
if (mAmbientLoopSoundID == "None") if (mAmbientLoopSoundID == "None")
mAmbientLoopSoundID = ESM::RefId(); mAmbientLoopSoundID = ESM::RefId();
} }
@ -552,8 +550,6 @@ namespace MWWorld
, mQueuedWeather(0) , mQueuedWeather(0)
, mRegions() , mRegions()
, mResult() , mResult()
, mAmbientSound(nullptr)
, mPlayingSoundID()
{ {
mTimeSettings.mNightStart = mSunsetTime + mSunsetDuration; mTimeSettings.mNightStart = mSunsetTime + mSunsetDuration;
mTimeSettings.mNightEnd = mSunriseTime; mTimeSettings.mNightEnd = mSunriseTime;
@ -794,24 +790,52 @@ namespace MWWorld
mRendering.getSkyManager()->setWeather(mResult); mRendering.getSkyManager()->setWeather(mResult);
// Play sounds // Play sounds
if (mPlayingSoundID != mResult.mAmbientLoopSoundID) if (mPlayingAmbientSoundID != mResult.mAmbientLoopSoundID)
{ {
stopSounds(); if (mAmbientSound)
{
MWBase::Environment::get().getSoundManager()->stopSound(mAmbientSound);
mAmbientSound = nullptr;
}
if (!mResult.mAmbientLoopSoundID.empty()) if (!mResult.mAmbientLoopSoundID.empty())
mAmbientSound = MWBase::Environment::get().getSoundManager()->playSound(mResult.mAmbientLoopSoundID, mAmbientSound = MWBase::Environment::get().getSoundManager()->playSound(mResult.mAmbientLoopSoundID,
mResult.mAmbientSoundVolume, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::Loop); mResult.mAmbientSoundVolume, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::Loop);
mPlayingSoundID = mResult.mAmbientLoopSoundID; mPlayingAmbientSoundID = mResult.mAmbientLoopSoundID;
} }
else if (mAmbientSound) else if (mAmbientSound)
mAmbientSound->setVolume(mResult.mAmbientSoundVolume); mAmbientSound->setVolume(mResult.mAmbientSoundVolume);
if (mPlayingRainSoundID != mResult.mRainLoopSoundID)
{
if (mRainSound)
{
MWBase::Environment::get().getSoundManager()->stopSound(mRainSound);
mRainSound = nullptr;
}
if (!mResult.mRainLoopSoundID.empty())
mRainSound = MWBase::Environment::get().getSoundManager()->playSound(mResult.mRainLoopSoundID,
mResult.mAmbientSoundVolume, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::Loop);
mPlayingRainSoundID = mResult.mRainLoopSoundID;
}
else if (mRainSound)
mRainSound->setVolume(mResult.mAmbientSoundVolume);
} }
void WeatherManager::stopSounds() void WeatherManager::stopSounds()
{ {
if (mAmbientSound) if (mAmbientSound)
{
MWBase::Environment::get().getSoundManager()->stopSound(mAmbientSound); MWBase::Environment::get().getSoundManager()->stopSound(mAmbientSound);
mAmbientSound = nullptr; mAmbientSound = nullptr;
mPlayingSoundID = ESM::RefId(); }
mPlayingAmbientSoundID = ESM::RefId();
if (mRainSound)
{
MWBase::Environment::get().getSoundManager()->stopSound(mRainSound);
mRainSound = nullptr;
}
mPlayingRainSoundID = ESM::RefId();
} }
float WeatherManager::getWindSpeed() const float WeatherManager::getWindSpeed() const
@ -1118,6 +1142,7 @@ namespace MWWorld
mResult.mCloudSpeed = current.mCloudSpeed; mResult.mCloudSpeed = current.mCloudSpeed;
mResult.mGlareView = current.mGlareView; mResult.mGlareView = current.mGlareView;
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID; mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
mResult.mRainLoopSoundID = current.mRainLoopSoundID;
mResult.mAmbientSoundVolume = 1.f; mResult.mAmbientSoundVolume = 1.f;
mResult.mPrecipitationAlpha = 1.f; mResult.mPrecipitationAlpha = 1.f;
@ -1237,6 +1262,7 @@ namespace MWWorld
mResult.mAmbientSoundVolume = 1.f - factor / threshold; mResult.mAmbientSoundVolume = 1.f - factor / threshold;
mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume; mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume;
mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID; mResult.mAmbientLoopSoundID = current.mAmbientLoopSoundID;
mResult.mRainLoopSoundID = current.mRainLoopSoundID;
mResult.mRainDiameter = current.mRainDiameter; mResult.mRainDiameter = current.mRainDiameter;
mResult.mRainMinHeight = current.mRainMinHeight; mResult.mRainMinHeight = current.mRainMinHeight;
mResult.mRainMaxHeight = current.mRainMaxHeight; mResult.mRainMaxHeight = current.mRainMaxHeight;
@ -1252,6 +1278,7 @@ namespace MWWorld
mResult.mAmbientSoundVolume = (factor - threshold) / (1 - threshold); mResult.mAmbientSoundVolume = (factor - threshold) / (1 - threshold);
mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume; mResult.mPrecipitationAlpha = mResult.mAmbientSoundVolume;
mResult.mAmbientLoopSoundID = other.mAmbientLoopSoundID; mResult.mAmbientLoopSoundID = other.mAmbientLoopSoundID;
mResult.mRainLoopSoundID = other.mRainLoopSoundID;
mResult.mRainDiameter = other.mRainDiameter; mResult.mRainDiameter = other.mRainDiameter;
mResult.mRainMinHeight = other.mRainMinHeight; mResult.mRainMinHeight = other.mRainMinHeight;

View file

@ -156,9 +156,11 @@ namespace MWWorld
float FogOffset; float FogOffset;
} mDL; } mDL;
// Sound effect // Sound effects
// This is used for Blight, Ashstorm and Blizzard (Bloodmoon) // This is used for Blight, Ashstorm and Blizzard (Bloodmoon)
ESM::RefId mAmbientLoopSoundID; ESM::RefId mAmbientLoopSoundID;
// This is used for Rain and Thunderstorm
ESM::RefId mRainLoopSoundID;
// Is this an ash storm / blight storm? If so, the following will happen: // Is this an ash storm / blight storm? If so, the following will happen:
// - The particles and clouds will be oriented so they appear to come from the Red Mountain. // - The particles and clouds will be oriented so they appear to come from the Red Mountain.
@ -369,8 +371,10 @@ namespace MWWorld
std::map<ESM::RefId, RegionWeather> mRegions; std::map<ESM::RefId, RegionWeather> mRegions;
MWRender::WeatherResult mResult; MWRender::WeatherResult mResult;
MWBase::Sound* mAmbientSound; MWBase::Sound* mAmbientSound{ nullptr };
ESM::RefId mPlayingSoundID; ESM::RefId mPlayingAmbientSoundID;
MWBase::Sound* mRainSound{ nullptr };
ESM::RefId mPlayingRainSoundID;
void addWeather( void addWeather(
const std::string& name, float dlFactor, float dlOffset, const std::string& particleEffect = ""); const std::string& name, float dlFactor, float dlOffset, const std::string& particleEffect = "");