Add an update flag to Custom Affectors
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 25 Aug 2011 01:55:23 +0000 (11:55 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 30 Aug 2011 07:43:46 +0000 (09:43 +0200)
Slight optimization, as it doesn't have to reload the vertex buffer on
every particle every tick now.

Change-Id: I272ec79bfc80c00a1f08de4d81059d0e0b36fb29
Reviewed-on: http://codereview.qt.nokia.com/3543
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/declarative/particles/qsgparticleaffector.cpp
src/declarative/particles/qsgparticlesystem_p.h
src/declarative/particles/qsgv8particledata.cpp

index 4cb3e49..3313106 100644 (file)
@@ -42,6 +42,7 @@
 #include "qsgparticleaffector_p.h"
 #include <QDebug>
 QT_BEGIN_NAMESPACE
+
 /*!
     \qmlclass Affector QSGParticleAffector
     \inqmlmodule QtQuick.Particles 2
@@ -159,8 +160,10 @@ void QSGParticleAffector::affectSystem(qreal dt)
                 if ((m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index)))
                         || !d->stillAlive())
                     continue;
-                //Need to have previous location for affected. if signal || shape might be faster?
-                QPointF curPos = QPointF(d->curX(), d->curY());
+                //Need to have previous location for affected anyways
+                QPointF curPos;
+                if (m_signal || (width() && height()))
+                    curPos = QPointF(d->curX(), d->curY());
                 if (width() == 0 || height() == 0
                         || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()),curPos)){
                     if (m_collisionParticles.isEmpty() || isColliding(d)){
@@ -181,8 +184,9 @@ void QSGParticleAffector::affectSystem(qreal dt)
 bool QSGParticleAffector::affectParticle(QSGParticleData *d, qreal dt)
 {
     if (isAffectConnected()){
+        d->update = 0.0;
         emit affectParticle(d->v8Value(), dt);
-        return true;
+        return d->update == 1.0;
     }
     return m_signal;//If signalling, then we always 'null affect' it.
 }
index 9f4020d..abb7f52 100644 (file)
@@ -202,6 +202,7 @@ public:
     float r;
     QSGItem* delegate;
     int modelIndex;
+    float update;//Used by custom affectors
 
     void debugDump();
     bool stillAlive();
index b3ff482..72c0b7c 100644 (file)
@@ -150,6 +150,7 @@ FLOAT_GETTER_AND_SETTER(frameDuration)
 FLOAT_GETTER_AND_SETTER(frameCount)
 FLOAT_GETTER_AND_SETTER(animT)
 FLOAT_GETTER_AND_SETTER(r)
+FLOAT_GETTER_AND_SETTER(update)
 FAKE_FLOAT_GETTER_AND_SETTER(curX, curX, setInstantaneousX)
 FAKE_FLOAT_GETTER_AND_SETTER(curVX, curVX, setInstantaneousVX)
 FAKE_FLOAT_GETTER_AND_SETTER(curAX, curAX, setInstantaneousAX)
@@ -157,7 +158,7 @@ FAKE_FLOAT_GETTER_AND_SETTER(curY, curY, setInstantaneousY)
 FAKE_FLOAT_GETTER_AND_SETTER(curVY, curVY, setInstantaneousVY)
 FAKE_FLOAT_GETTER_AND_SETTER(curAY, curAY, setInstantaneousAY)
 
-//TODO: Non-floats (color) and special floats (curX) once basic floats are working well
+//TODO: Non-floats (color, update?) once floats are working well
 
 QV8ParticleDataDeletable::QV8ParticleDataDeletable(QV8Engine *engine)
 {
@@ -189,6 +190,7 @@ QV8ParticleDataDeletable::QV8ParticleDataDeletable(QV8Engine *engine)
     FLOAT_REGISTER_ACCESSOR(ft, engine, frameCount);
     FLOAT_REGISTER_ACCESSOR(ft, engine, animT);
     FLOAT_REGISTER_ACCESSOR(ft, engine, r);
+    FLOAT_REGISTER_ACCESSOR(ft, engine, update);
     FLOAT_REGISTER_ACCESSOR(ft, engine, curX);
     FLOAT_REGISTER_ACCESSOR(ft, engine, curVX);
     FLOAT_REGISTER_ACCESSOR(ft, engine, curAX);