From b03afd99c069869cfa33edf5d191762cd5a6be8a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Thu, 25 Aug 2011 11:55:23 +1000 Subject: [PATCH] Add an update flag to Custom Affectors 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 Reviewed-by: Martin Jones --- src/declarative/particles/qsgparticleaffector.cpp | 10 +++++++--- src/declarative/particles/qsgparticlesystem_p.h | 1 + src/declarative/particles/qsgv8particledata.cpp | 4 +++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/declarative/particles/qsgparticleaffector.cpp b/src/declarative/particles/qsgparticleaffector.cpp index 4cb3e49..3313106 100644 --- a/src/declarative/particles/qsgparticleaffector.cpp +++ b/src/declarative/particles/qsgparticleaffector.cpp @@ -42,6 +42,7 @@ #include "qsgparticleaffector_p.h" #include 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. } diff --git a/src/declarative/particles/qsgparticlesystem_p.h b/src/declarative/particles/qsgparticlesystem_p.h index 9f4020d..abb7f52 100644 --- a/src/declarative/particles/qsgparticlesystem_p.h +++ b/src/declarative/particles/qsgparticlesystem_p.h @@ -202,6 +202,7 @@ public: float r; QSGItem* delegate; int modelIndex; + float update;//Used by custom affectors void debugDump(); bool stillAlive(); diff --git a/src/declarative/particles/qsgv8particledata.cpp b/src/declarative/particles/qsgv8particledata.cpp index b3ff482..72c0b7c 100644 --- a/src/declarative/particles/qsgv8particledata.cpp +++ b/src/declarative/particles/qsgv8particledata.cpp @@ -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); -- 2.7.4