Delay custom emitter processing
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 7 Jun 2012 03:23:56 +0000 (13:23 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 25 Jun 2012 05:29:42 +0000 (07:29 +0200)
It now happens after ParticlePainter intialization, so that custom
emitters can affect painter specific parameters like color.

Change-Id: I9a732713108580e57130588c175c69aa854c5b2f
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
examples/particles/emitters/customemitter.qml
src/particles/qquickparticleemitter.cpp
src/particles/qquicktrailemitter.cpp

index 757c836..135b3d7 100644 (file)
@@ -72,7 +72,11 @@ ParticleSystem {
             for (var i=0; i<particles.length; i++) {
                 var particle = particles[i];
                 particle.startSize = Math.max(02,Math.min(492,Math.tan(particle.t/2)*24));
-                var theta = Math.floor(Math.random() * 6.0) / 6.0;
+                var theta = Math.floor(Math.random() * 6.0);
+                particle.red = theta == 0 || theta == 1 || theta == 2 ? 0.2 : 1;
+                particle.green = theta == 2 || theta == 3 || theta == 4 ? 0.2 : 1;
+                particle.blue = theta == 4 || theta == 5 || theta == 0 ? 0.2 : 1;
+                theta /= 6.0;
                 theta *= 2.0*Math.PI;
                 theta += sys.convert(sys.petalRotation);
                 particle.initialVX = petalLength * Math.cos(theta);
@@ -86,7 +90,5 @@ ParticleSystem {
     ImageParticle {
         source: "../images/particle4.png"
         alpha: 0.0
-        redVariation: 0.6
-        color: "white"
     }
 }
index 6e53b09..7db1707 100644 (file)
@@ -472,7 +472,12 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
         }
     }
 
+    foreach (QQuickParticleData* d, toEmit)
+            m_system->emitParticle(d);
+
     if (isEmitConnected()) {
+        //Done after emitParticle so that the Painter::load is done first, this allows you to customize its static variables
+        //We then don't need to request another reload, because the first reload isn't scheduled until we get back to the render thread
         v8::HandleScope handle_scope;
         v8::Context::Scope scope(QQmlEnginePrivate::getV8Engine(qmlEngine(this))->context());
         v8::Handle<v8::Array> array = v8::Array::New(toEmit.size());
@@ -481,8 +486,6 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
 
         emitParticles(QQmlV8Handle::fromHandle(array));//A chance for arbitrary JS changes
     }
-    foreach (QQuickParticleData* d, toEmit)
-            m_system->emitParticle(d);
 
     m_last_emission = pt;
 
index 68b43a0..5f09410 100644 (file)
@@ -118,7 +118,7 @@ QQuickTrailEmitter::QQuickTrailEmitter(QQuickItem *parent) :
     \qmlproperty real QtQuick.Particles2::TrailEmitter::emitRatePerParticle
 */
 /*!
-    \qmlsignal QtQuick.Particles2::TrailEmitter::emitFollowParticles(Array particles, real followed)
+    \qmlsignal QtQuick.Particles2::TrailEmitter::emitFollowParticles(Array particles, QtQuick.Particles2::Particle followed)
 
     This handler is called when particles are emitted from the \a followed particle. \a particles contains an array of particle objects which can be directly manipulated.
 
@@ -264,6 +264,9 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
             }
         }
 
+        foreach (QQuickParticleData* d, toEmit)
+            m_system->emitParticle(d);
+
         if (isEmitConnected() || isEmitFollowConnected()) {
             v8::HandleScope handle_scope;
             v8::Context::Scope scope(QQmlEnginePrivate::getV8Engine(qmlEngine(this))->context());
@@ -276,8 +279,6 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
             else if (isEmitConnected())
                 emitParticles(QQmlV8Handle::fromHandle(array));//A chance for arbitrary JS changes
         }
-        foreach (QQuickParticleData* d, toEmit)
-            m_system->emitParticle(d);
         m_lastEmission[d->index] = pt;
     }