diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2011-07-21 12:15:34 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-28 08:39:33 +0200 |
commit | cd6b2696a772fec45bc86521003a597cdd6febee (patch) | |
tree | 6a8232e0873f5f5c3950346f26b561911b1c062e /src/declarative/particles/qsgparticlesystem.cpp | |
parent | e2b5681b1adab83555c7307b05f508d796a1152b (diff) |
Drive ParticleSystem with an animation instead
This will be helpful later, and also keeps the work in the main thread.
Change-Id: Idf4b9e82a40f31a0b70edda731b85b6c853a1dac
Reviewed-on: http://codereview.qt.nokia.com/1909
Reviewed-by: Alan Alpert <alan.alpert@nokia.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src/declarative/particles/qsgparticlesystem.cpp')
-rw-r--r-- | src/declarative/particles/qsgparticlesystem.cpp | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/src/declarative/particles/qsgparticlesystem.cpp b/src/declarative/particles/qsgparticlesystem.cpp index 9ba5c67296..f25172dbda 100644 --- a/src/declarative/particles/qsgparticlesystem.cpp +++ b/src/declarative/particles/qsgparticlesystem.cpp @@ -133,7 +133,7 @@ void QSGParticleDataHeap::insert(QSGParticleData* data) int QSGParticleDataHeap::top() { if (m_end == 0) - return 1e24; + return 1 << 30; return m_data[0].time; } @@ -658,8 +658,8 @@ void QSGParticleSystem::componentComplete() { QSGItem::componentComplete(); m_componentComplete = true; - //if (!m_emitters.isEmpty() && !m_particlePainters.isEmpty()) - reset(); + m_animation = new QSGParticleSystemAnimation(this); + reset();//restarts animation as well } void QSGParticleSystem::reset()//TODO: Needed? Or just in component complete? @@ -667,6 +667,7 @@ void QSGParticleSystem::reset()//TODO: Needed? Or just in component complete? if (!m_componentComplete) return; + m_timeInt = 0; //Clear guarded pointers which have been deleted int cleared = 0; cleared += m_emitters.removeAll(0); @@ -690,8 +691,10 @@ void QSGParticleSystem::reset()//TODO: Needed? Or just in component complete? p->reset(); } - m_timeInt = 0; - m_timestamp.restart();//TODO: Better placement + if (m_animation){ + m_animation->stop(); + m_animation->start(); + } m_initialized = true; } @@ -831,37 +834,41 @@ void QSGParticleSystem::finishNewDatum(QSGParticleData *pd){ p->load(pd); } -qint64 QSGParticleSystem::systemSync(QSGParticlePainter* p) +void QSGParticleSystem::updateCurrentTime( int currentTime ) { if (!m_running) - return 0; + return; if (!m_initialized) - return 0;//error in initialization + return;//error in initialization + + //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time. + qreal dt = m_timeInt / 1000.; + m_timeInt = currentTime + m_startTime; + qreal time = m_timeInt / 1000.; + dt = time - dt; + m_needsReset.clear(); + if (m_spriteEngine) + m_spriteEngine->updateSprites(m_timeInt); - if (m_syncList.isEmpty() || m_syncList.contains(p)){//Need to advance the simulation - m_syncList.clear(); + foreach (QSGParticleEmitter* emitter, m_emitters) + if (emitter) + emitter->emitWindow(m_timeInt); + foreach (QSGParticleAffector* a, m_affectors) + if (a) + a->affectSystem(dt); + foreach (QSGParticleData* d, m_needsReset) + foreach (QSGParticlePainter* p, m_groupData[d->group]->painters) + if (p && d) + p->reload(d); +} - //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time. - qreal dt = m_timeInt / 1000.; - m_timeInt = m_timestamp.elapsed() + m_startTime; - qreal time = m_timeInt / 1000.; - dt = time - dt; - m_needsReset.clear(); - if (m_spriteEngine) - m_spriteEngine->updateSprites(m_timeInt); - - foreach (QSGParticleEmitter* emitter, m_emitters) - if (emitter) - emitter->emitWindow(m_timeInt); - foreach (QSGParticleAffector* a, m_affectors) - if (a) - a->affectSystem(dt); - foreach (QSGParticleData* d, m_needsReset) - foreach (QSGParticlePainter* p, m_groupData[d->group]->painters) - if (p && d) - p->reload(d); - } - m_syncList << p; +int QSGParticleSystem::systemSync(QSGParticlePainter* p) +{ + if (!m_running) + return 0; + if (!m_initialized) + return 0;//error in initialization + p->performPendingCommits(); return m_timeInt; } |