Only simulate if particle was alive
authorAlan Alpert <alan.alpert@nokia.com>
Wed, 2 Nov 2011 03:46:01 +0000 (13:46 +1000)
committerQt by Nokia <qt-info@nokia.com>
Wed, 2 Nov 2011 22:56:47 +0000 (23:56 +0100)
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>
src/declarative/particles/qquickparticleaffector.cpp
src/declarative/particles/qquickparticlesystem.cpp
src/declarative/particles/qquickparticlesystem_p.h

index f50efc5..5bfc699 100644 (file)
@@ -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;
index 767e1b9..613587a 100644 (file)
@@ -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)
index 6e35f0b..87f2f2a 100644 (file)
@@ -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