diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-11-02 13:46:01 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-02 23:56:47 +0100 |
commit | a06ec0c299a267149d9440ddb935272b0165e464 (patch) | |
tree | c197873a3bcad2171828ef718b7bc0b303639d78 | |
parent | 030b3d1ceca96bfa2a04f761d574887687c666c1 (diff) |
Only simulate if particle was alive
When spliting the simulation into multiple parts, do not simulate for
times before the particle was born. Otherwise huge simulation times lead
to huge effects even on particles with a simulated birth of near the end
of that time.
Change-Id: I7ff507b27bf819dbebd61934b9523b23316b5e80
Reviewed-by: Martin Jones <martin.jones@nokia.com>
-rw-r--r-- | src/declarative/particles/qquickparticleaffector.cpp | 3 | ||||
-rw-r--r-- | src/declarative/particles/qquickparticlesystem.cpp | 8 | ||||
-rw-r--r-- | src/declarative/particles/qquickparticlesystem_p.h | 3 |
3 files changed, 12 insertions, 2 deletions
diff --git a/src/declarative/particles/qquickparticleaffector.cpp b/src/declarative/particles/qquickparticleaffector.cpp index f50efc55e7..5bfc699548 100644 --- a/src/declarative/particles/qquickparticleaffector.cpp +++ b/src/declarative/particles/qquickparticleaffector.cpp @@ -220,7 +220,8 @@ void QQuickParticleAffector::affectSystem(qreal dt) m_system->timeInt -= myDt * 1000.0; while (myDt > simulationDelta) { m_system->timeInt += simulationDelta * 1000.0; - affected = affectParticle(d, simulationDelta) || affected; + if (d->alive())//Only affect during the parts it was alive for + affected = affectParticle(d, simulationDelta) || affected; myDt -= simulationDelta; } m_system->timeInt = realTime; diff --git a/src/declarative/particles/qquickparticlesystem.cpp b/src/declarative/particles/qquickparticlesystem.cpp index 767e1b94cc..613587a46a 100644 --- a/src/declarative/particles/qquickparticlesystem.cpp +++ b/src/declarative/particles/qquickparticlesystem.cpp @@ -580,6 +580,14 @@ bool QQuickParticleData::stillAlive() return (t + lifeSpan - EPSILON) > ((qreal)system->timeInt/1000.0); } +bool QQuickParticleData::alive() +{ + if (!system) + return false; + qreal st = ((qreal)system->timeInt/1000.0); + return (t + EPSILON) < st && (t + lifeSpan - EPSILON) > st; +} + float QQuickParticleData::curSize() { if (!system || !lifeSpan) diff --git a/src/declarative/particles/qquickparticlesystem_p.h b/src/declarative/particles/qquickparticlesystem_p.h index 6e35f0b7b0..87f2f2adce 100644 --- a/src/declarative/particles/qquickparticlesystem_p.h +++ b/src/declarative/particles/qquickparticlesystem_p.h @@ -219,7 +219,8 @@ public: QQuickImageParticle* animationOwner; void debugDump(); - bool stillAlive(); + bool stillAlive();//Only checks end, because usually that's all you need and it's a little faster. + bool alive(); float lifeLeft(); float curSize(); void clone(const QQuickParticleData& other);//Not =, leaves meta-data like index |