aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/particles/qsgparticleaffector.cpp
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-09-20 10:46:34 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-20 07:22:35 +0200
commit4588034490d53759a9b6cf2e225113b4035e9dfa (patch)
tree4ea5f3bf61fa64429d818cddbfac02f770cee861 /src/declarative/particles/qsgparticleaffector.cpp
parent014fd8c01f305f05eafcee5a7789d6bf74048974 (diff)
Refactor QSGParticleAffector internals
Putting more of the logic in protected subroutines makes it a lot easier for subclasses to reimplement affectSystem. Change-Id: I07f6553228064f1c9b68c6f55628b12b5c78013b Reviewed-on: http://codereview.qt-project.org/5172 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative/particles/qsgparticleaffector.cpp')
-rw-r--r--src/declarative/particles/qsgparticleaffector.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/declarative/particles/qsgparticleaffector.cpp b/src/declarative/particles/qsgparticleaffector.cpp
index 7cb4869f3e..ac2d0ab8a0 100644
--- a/src/declarative/particles/qsgparticleaffector.cpp
+++ b/src/declarative/particles/qsgparticleaffector.cpp
@@ -150,41 +150,48 @@ bool QSGParticleAffector::activeGroup(int g) {
return m_groupIds.isEmpty() || m_groupIds.contains(g);
}
+bool QSGParticleAffector::shouldAffect(QSGParticleData* d)
+{
+ if (!d)
+ return false;
+ if (activeGroup(d->group)){
+ if ((m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index)))
+ || !d->stillAlive())
+ return false;
+ //Need to have previous location for affected anyways
+ if (width() == 0 || height() == 0
+ || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()), QPointF(d->curX(), d->curY()))){
+ if (m_whenCollidingWith.isEmpty() || isColliding(d)){
+ return true;
+ }
+ }
+ }
+ return false;
+
+}
+
+void QSGParticleAffector::postAffect(QSGParticleData* d)
+{
+ m_system->m_needsReset << d;
+ if (m_onceOff)
+ m_onceOffed << qMakePair(d->group, d->index);
+ if (isAffectedConnected())
+ emit affected(d->curX(), d->curY());
+}
+
void QSGParticleAffector::affectSystem(qreal dt)
{
if (!m_enabled)
return;
//If not reimplemented, calls affect particle per particle
//But only on particles in targeted system/area
- bool affectedConnected = isAffectedConnected();
updateOffsets();//### Needed if an ancestor is transformed.
- foreach (QSGParticleGroupData* gd, m_system->m_groupData){
- foreach (QSGParticleData* d, gd->data){
- if (!d)
- continue;
- if (activeGroup(d->group)){
- if ((m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index)))
- || !d->stillAlive())
- continue;
- //Need to have previous location for affected anyways
- QPointF curPos;
- if (affectedConnected || (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_whenCollidingWith.isEmpty() || isColliding(d)){
- if (affectParticle(d, dt)){
- m_system->m_needsReset << d;
- if (m_onceOff)
- m_onceOffed << qMakePair(d->group, d->index);
- if (affectedConnected)
- emit affected(curPos.x(), curPos.y());
- }
- }
- }
- }
- }
- }
+ foreach (QSGParticleGroupData* gd, m_system->m_groupData)
+ if (activeGroup(m_system->m_groupData.key(gd)))
+ foreach (QSGParticleData* d, gd->data)
+ if (shouldAffect(d))
+ if (affectParticle(d, dt))
+ postAffect(d);
}
bool QSGParticleAffector::affectParticle(QSGParticleData *, qreal )