diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-03-03 14:54:31 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-03-04 13:54:50 +0000 |
commit | 5a9734c0d071b7490b3ef7edf5f080786dc89f79 (patch) | |
tree | ef8d18707d2f65df718ea785745d079ff3558fb8 /src/particles/qquickitemparticle.cpp | |
parent | 554566788f585caaef14d929cee6557ad929e06e (diff) |
Particles: reduce excessive hash accesses to a more passable level.
By caching the group id in the particle emitter, and groups in the
painter.
Test case: samegame, 1 player, click 1 set of 3 stones, quit.
QQuickParticleSystem::emittersChanged(), before patch:
- 64M instr. inclusive
- 145,880 calls to findNode (29M instr.)
after:
- 21M instr. inclusive
- 0 calls to findNode
- 25 calls to QQuickParticlePainter::recalculateGroupIds (9800 instr.
inclusive).
Change-Id: I4aba9d50100513c6b7cdd230e30b3aecaf84485a
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/particles/qquickitemparticle.cpp')
-rw-r--r-- | src/particles/qquickitemparticle.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/src/particles/qquickitemparticle.cpp b/src/particles/qquickitemparticle.cpp index 4cd8ee9db8..ba6c6f915d 100644 --- a/src/particles/qquickitemparticle.cpp +++ b/src/particles/qquickitemparticle.cpp @@ -231,10 +231,10 @@ void QQuickItemParticle::reset() // delete all managed items which had their logical particles cleared // but leave it alone if the logical particle is maintained QSet<QQuickItem*> lost = QSet<QQuickItem*>::fromList(m_managed); - foreach (const QString group, m_groups){ - int gIdx = m_system->groupIds[group]; - foreach (QQuickParticleData* d, m_system->groupData[gIdx]->data) - lost.remove(d->delegate); + for (auto groupId : groupIds()) { + for (QQuickParticleData* d : qAsConst(m_system->groupData[groupId]->data)) { + lost.remove(d->delegate); + } } m_deletables.append(lost.toList()); //TODO: This doesn't yet handle calling detach on taken particles in the system reset case @@ -249,11 +249,12 @@ QSGNode* QQuickItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d) m_pleaseReset = false; //Refill loadables, delayed here so as to only happen once per frame max //### Constant resetting might lead to m_loadables never being populated when tick() occurs - foreach (const QString group, m_groups){ - int gIdx = m_system->groupIds[group]; - foreach (QQuickParticleData* d, m_system->groupData[gIdx]->data) - if (!d->delegate && d->t != -1 && d->stillAlive()) + for (auto groupId : groupIds()) { + for (QQuickParticleData* d : qAsConst(m_system->groupData[groupId]->data)) { + if (!d->delegate && d->t != -1 && d->stillAlive()) { m_loadables << d; + } + } } } prepareNextFrame(); @@ -276,31 +277,26 @@ void QQuickItemParticle::prepareNextFrame() return; //TODO: Size, better fade? - foreach (const QString &str, m_groups){ - const int gIdx = m_system->groupIds[str]; - const QVector<QQuickParticleData*> dataVector = m_system->groupData[gIdx]->data; - const int count = dataVector.size(); - - for (int i=0; i<count; i++){ - QQuickParticleData* data = dataVector.at(i); + for (auto groupId : groupIds()) { + for (QQuickParticleData* data : qAsConst(m_system->groupData[groupId]->data)) { QQuickItem* item = data->delegate; if (!item) continue; - qreal t = ((timeStamp/1000.0) - data->t) / data->lifeSpan; + float t = ((timeStamp / 1000.0f) - data->t) / data->lifeSpan; if (m_stasis.contains(item)) { data->t += dt;//Stasis effect continue; } - if (t >= 1.0){//Usually happens from load + if (t >= 1.0f){//Usually happens from load m_deletables << item; data->delegate = 0; }else{//Fade data->delegate->setVisible(true); if (m_fade){ - qreal o = 1.; - if (t<0.2) - o = t*5; - if (t>0.8) + float o = 1.f; + if (t <0.2f) + o = t * 5; + if (t > 0.8f) o = (1-t)*5; item->setOpacity(o); } |