From 8fd71fe4ad8e8a6aaa8d1e71abfb3db16e9fd0bd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 4 Nov 2018 12:42:34 +0100 Subject: [PATCH] fix rain delay when exiting water When the particle system updates its internal state noting that it's been culled, it stops emitting any further particles. Prevent it from having that knowledge. v2: Fix off-by-one-frame error following review by @AnyOldName3 --- CHANGELOG.md | 1 + apps/openmw/mwrender/sky.cpp | 19 +++++++++++++++++-- apps/openmw/mwrender/sky.hpp | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d50c96ef4..7880bb2a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.46.0 ------ + Bug #4540: Rain delay when exiting water Feature #2229: Improve pathfinding AI Feature #3442: Default values for fallbacks from ini file Task #4686: Upgrade media decoder to a more current FFmpeg API diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index d6a0b9f01..0ea0905a6 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -401,11 +401,15 @@ public: { } - virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + bool isUnderwater() { osg::Vec3f eyePoint = mCameraRelativeTransform->getLastEyePoint(); + return mEnabled && eyePoint.z() < mWaterLevel; + } - if (mEnabled && eyePoint.z() < mWaterLevel) + virtual void operator()(osg::Node* node, osg::NodeVisitor* nv) + { + if (isUnderwater()) return; traverse(node, nv); @@ -1575,6 +1579,8 @@ void SkyManager::update(float duration) mRainIntensityUniform->set((float) mWeatherAlpha); } + switchUnderwaterRain(); + if (mIsStorm) { osg::Quat quat; @@ -1626,6 +1632,15 @@ void SkyManager::updateRainParameters() } } +void SkyManager::switchUnderwaterRain() +{ + if (!mRainParticleSystem) + return; + + bool freeze = mUnderwaterSwitch->isUnderwater(); + mRainParticleSystem->setFrozen(freeze); +} + void SkyManager::setWeather(const WeatherResult& weather) { if (!mCreated) return; diff --git a/apps/openmw/mwrender/sky.hpp b/apps/openmw/mwrender/sky.hpp index a9345cdb4..e70f16521 100644 --- a/apps/openmw/mwrender/sky.hpp +++ b/apps/openmw/mwrender/sky.hpp @@ -180,6 +180,7 @@ namespace MWRender void createRain(); void destroyRain(); + void switchUnderwaterRain(); void updateRainParameters(); Resource::SceneManager* mSceneManager;