From 899d464b0df6811d0a0c544d30da31807b1fdc8a Mon Sep 17 00:00:00 2001 From: scrawl <720642+scrawl@users.noreply.github.com> Date: Sat, 10 Feb 2018 23:14:41 +0000 Subject: [PATCH] Cap the rain emitter's frame time (Fixes #4314) --- apps/openmw/mwrender/sky.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwrender/sky.cpp b/apps/openmw/mwrender/sky.cpp index 6c599fc3f..2e4329f69 100644 --- a/apps/openmw/mwrender/sky.cpp +++ b/apps/openmw/mwrender/sky.cpp @@ -1203,6 +1203,18 @@ void SkyManager::create() mCreated = true; } +class RainCounter : public osgParticle::ConstantRateCounter +{ +public: + virtual int numParticlesToCreate(double dt) const + { + // limit dt to avoid large particle emissions if there are jumps in the simulation time + // 0.2 seconds is the same cap as used in Engine's frame loop + dt = std::min(dt, 0.2); + return ConstantRateCounter::numParticlesToCreate(dt); + } +}; + class RainShooter : public osgParticle::Shooter { public: @@ -1473,7 +1485,7 @@ void SkyManager::createRain() placer->setZRange(300, 300); emitter->setPlacer(placer); - osg::ref_ptr counter (new osgParticle::ConstantRateCounter); + osg::ref_ptr counter (new RainCounter); counter->setNumberOfParticlesPerSecondToCreate(600.0); emitter->setCounter(counter);