diff options
author | Kaj Grönholm <kaj.gronholm@qt.io> | 2020-11-03 10:29:22 +0200 |
---|---|---|
committer | Kaj Grönholm <kaj.gronholm@qt.io> | 2020-11-05 10:00:37 +0200 |
commit | 5fa85ded71f4bd81b6332d8aecda3edd658f7a39 (patch) | |
tree | 96afc61930beab961bbc99e570415744b22b479f /src | |
parent | 43d0eae81e30ae8c8502e68d56c6c8b7e2c30215 (diff) |
Cleanup and optimize particles
Minor improvements while going through the particles sources:
- Reduce getShadowDatum() calls
- Remove unused m_lastLevel, reloadColor(), m_available
m_velocityFromMovement, maximumAlive, m_pending, m_lastT,
m_last_last_last_emitter, modelIndex
- Color4ub structs can be assigned directly
- Fix pri for shaders_ng files
- Other minor refactoring
Task-number: QTBUG-88124
Change-Id: I5768fed9f4b6379a698849c23436fa38169833a4
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/particles/particles.pri | 14 | ||||
-rw-r--r-- | src/particles/qquickgroupgoal.cpp | 6 | ||||
-rw-r--r-- | src/particles/qquickimageparticle.cpp | 59 | ||||
-rw-r--r-- | src/particles/qquickimageparticle_p.h | 2 | ||||
-rw-r--r-- | src/particles/qquickitemparticle_p.h | 1 | ||||
-rw-r--r-- | src/particles/qquickparticleemitter.cpp | 1 | ||||
-rw-r--r-- | src/particles/qquickparticleemitter_p.h | 2 | ||||
-rw-r--r-- | src/particles/qquickparticleextruder_p.h | 4 | ||||
-rw-r--r-- | src/particles/qquickparticlegroup_p.h | 19 | ||||
-rw-r--r-- | src/particles/qquickparticlesystem.cpp | 14 | ||||
-rw-r--r-- | src/particles/qquickparticlesystem_p.h | 14 | ||||
-rw-r--r-- | src/particles/qquicktrailemitter_p.h | 1 | ||||
-rw-r--r-- | src/particles/qquickturbulence.cpp | 2 | ||||
-rw-r--r-- | src/particles/qquickturbulence_p.h | 1 |
14 files changed, 44 insertions, 96 deletions
diff --git a/src/particles/particles.pri b/src/particles/particles.pri index d2164ec258..e3d83c431c 100644 --- a/src/particles/particles.pri +++ b/src/particles/particles.pri @@ -63,10 +63,16 @@ SOURCES += \ $$PWD/qquickgroupgoal.cpp OTHER_FILES += \ - $$PWD/shaders/imageparticle.vert \ - $$PWD/shaders/imageparticle.frag \ - $$PWD/shaders/imageparticle_core.vert \ - $$PWD/shaders/imageparticle_core.frag + $$PWD/shaders_ng/imageparticle_colored.frag.qsb \ + $$PWD/shaders_ng/imageparticle_colored.vert.qsb \ + $$PWD/shaders_ng/imageparticle_deformed.frag.qsb \ + $$PWD/shaders_ng/imageparticle_deformed.vert.qsb \ + $$PWD/shaders_ng/imageparticle_simple.frag.qsb \ + $$PWD/shaders_ng/imageparticle_simple.vert.qsb \ + $$PWD/shaders_ng/imageparticle_sprite.frag.qsb \ + $$PWD/shaders_ng/imageparticle_sprite.vert.qsb \ + $$PWD/shaders_ng/imageparticle_tabled.frag.qsb \ + $$PWD/shaders_ng/imageparticle_tabled.vert.qsb RESOURCES += \ $$PWD/particles.qrc diff --git a/src/particles/qquickgroupgoal.cpp b/src/particles/qquickgroupgoal.cpp index 67356ba8f6..85abf2ff31 100644 --- a/src/particles/qquickgroupgoal.cpp +++ b/src/particles/qquickgroupgoal.cpp @@ -92,13 +92,9 @@ bool QQuickGroupGoalAffector::affectParticle(QQuickParticleData *d, qreal dt) { Q_UNUSED(dt); QQuickStochasticEngine *engine = m_system->stateEngine; - bool notUsingEngine = false; - if (!engine) - notUsingEngine = true; - int index = d->systemIndex; int goalIdx = m_system->groupIds[m_goalState]; - if (notUsingEngine){//no stochastic states defined. So cut out the engine + if (!engine){//no stochastic states defined. So cut out the engine //TODO: It's possible to move to a group that is intermediate and not used by painters or emitters - but right now that will redirect to the default group m_system->moveGroups(d, goalIdx); return true; diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp index 1aa176b1ef..7ba26c4e54 100644 --- a/src/particles/qquickimageparticle.cpp +++ b/src/particles/qquickimageparticle.cpp @@ -701,7 +701,6 @@ QQuickImageParticle::QQuickImageParticle(QQuickItem* parent) , m_explicitAnimation(false) , m_bypassOptimizations(false) , perfLevel(Unknown) - , m_lastLevel(Unknown) , m_debugMode(false) , m_entryEffect(Fade) , m_startedImageLoading(0) @@ -1141,8 +1140,8 @@ QQuickParticleData* QQuickImageParticle::getShadowDatum(QQuickParticleData* datu //Will return datum if the datum is a sentinel or uninitialized, to centralize that one check if (datum->systemIndex == -1) return datum; - QQuickParticleGroupData* gd = m_system->groupData[datum->groupId]; if (!m_shadowData.contains(datum->groupId)) { + QQuickParticleGroupData* gd = m_system->groupData[datum->groupId]; QVector<QQuickParticleData*> data; const int gdSize = gd->size(); data.reserve(gdSize); @@ -1229,7 +1228,7 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node) return; } - if (count() <= 0) + if (m_count <= 0) return; m_debugMode = m_system->m_debugMode; @@ -1492,7 +1491,6 @@ QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *node, UpdatePaintNodeData m_outgoingNode = node; node = nullptr; - m_lastLevel = perfLevel; m_nodes.clear(); m_idxStarts.clear(); @@ -1663,12 +1661,6 @@ void QQuickImageParticle::spriteAdvance(int spriteIdx) datum->animHeight = m_spriteEngine->spriteHeight(spriteIdx); } -void QQuickImageParticle::reloadColor(const Color4ub &c, QQuickParticleData* d) -{ - d->color = c; - //TODO: get index for reload - or make function take an index -} - void QQuickImageParticle::initialize(int gIdx, int pIdx) { Color4ub color; @@ -1732,8 +1724,9 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx) datum->xx = ret.x(); datum->xy = ret.y(); } else { - getShadowDatum(datum)->xx = ret.x(); - getShadowDatum(datum)->xy = ret.y(); + QQuickParticleData* shadow = getShadowDatum(datum); + shadow->xx = ret.x(); + shadow->xy = ret.y(); } } if (m_yVector){ @@ -1742,8 +1735,9 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx) datum->yx = ret.x(); datum->yy = ret.y(); } else { - getShadowDatum(datum)->yx = ret.x(); - getShadowDatum(datum)->yy = ret.y(); + QQuickParticleData* shadow = getShadowDatum(datum); + shadow->yx = ret.x(); + shadow->yy = ret.y(); } } } @@ -1761,9 +1755,10 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx) datum->rotationVelocity = rotationVelocity; datum->autoRotate = autoRotate; } else { - getShadowDatum(datum)->rotation = rotation; - getShadowDatum(datum)->rotationVelocity = rotationVelocity; - getShadowDatum(datum)->autoRotate = autoRotate; + QQuickParticleData* shadow = getShadowDatum(datum); + shadow->rotation = rotation; + shadow->rotationVelocity = rotationVelocity; + shadow->autoRotate = autoRotate; } } Q_FALLTHROUGH(); @@ -1838,15 +1833,9 @@ void QQuickImageParticle::commit(int gIdx, int pIdx) //Sprite-related vertices updated per-frame in spritesUpdate(), not on demand if (m_explicitColor && datum->colorOwner != this) { QQuickParticleData* shadow = getShadowDatum(datum); - spriteVertices[i].color.r = shadow->color.r; - spriteVertices[i].color.g = shadow->color.g; - spriteVertices[i].color.b = shadow->color.b; - spriteVertices[i].color.a = shadow->color.a; + spriteVertices[i].color = shadow->color; } else { - spriteVertices[i].color.r = datum->color.r; - spriteVertices[i].color.g = datum->color.g; - spriteVertices[i].color.b = datum->color.b; - spriteVertices[i].color.a = datum->color.a; + spriteVertices[i].color = datum->color; } } break; @@ -1888,15 +1877,9 @@ void QQuickImageParticle::commit(int gIdx, int pIdx) } if (m_explicitColor && datum->colorOwner != this) { QQuickParticleData* shadow = getShadowDatum(datum); - deformableVertices[i].color.r = shadow->color.r; - deformableVertices[i].color.g = shadow->color.g; - deformableVertices[i].color.b = shadow->color.b; - deformableVertices[i].color.a = shadow->color.a; + deformableVertices[i].color = shadow->color; } else { - deformableVertices[i].color.r = datum->color.r; - deformableVertices[i].color.g = datum->color.g; - deformableVertices[i].color.b = datum->color.b; - deformableVertices[i].color.a = datum->color.a; + deformableVertices[i].color = datum->color; } } break; @@ -1915,15 +1898,9 @@ void QQuickImageParticle::commit(int gIdx, int pIdx) coloredVertices[i].ay = datum->ay; if (m_explicitColor && datum->colorOwner != this) { QQuickParticleData* shadow = getShadowDatum(datum); - coloredVertices[i].color.r = shadow->color.r; - coloredVertices[i].color.g = shadow->color.g; - coloredVertices[i].color.b = shadow->color.b; - coloredVertices[i].color.a = shadow->color.a; + coloredVertices[i].color = shadow->color; } else { - coloredVertices[i].color.r = datum->color.r; - coloredVertices[i].color.g = datum->color.g; - coloredVertices[i].color.b = datum->color.b; - coloredVertices[i].color.a = datum->color.a; + coloredVertices[i].color = datum->color; } } break; diff --git a/src/particles/qquickimageparticle_p.h b/src/particles/qquickimageparticle_p.h index 266054f28e..5399bc068c 100644 --- a/src/particles/qquickimageparticle_p.h +++ b/src/particles/qquickimageparticle_p.h @@ -327,7 +327,6 @@ Q_SIGNALS: void statusChanged(Status arg); public Q_SLOTS: - void reloadColor(const Color4ub &c, QQuickParticleData* d); void setAlphaVariation(qreal arg); void setAlpha(qreal arg); @@ -429,7 +428,6 @@ private: bool m_bypassOptimizations; PerformanceLevel perfLevel; - PerformanceLevel m_lastLevel; bool m_debugMode; template<class Vertex> diff --git a/src/particles/qquickitemparticle_p.h b/src/particles/qquickitemparticle_p.h index fce9e95548..4fe5f9c031 100644 --- a/src/particles/qquickitemparticle_p.h +++ b/src/particles/qquickitemparticle_p.h @@ -114,7 +114,6 @@ private: bool m_fade; QList<QQuickItem*> m_pendingItems; - QList<int> m_available; QSet<QQuickItem*> m_stasis; qreal m_lastT; int m_activeCount; diff --git a/src/particles/qquickparticleemitter.cpp b/src/particles/qquickparticleemitter.cpp index 62bf83994f..625670c4a3 100644 --- a/src/particles/qquickparticleemitter.cpp +++ b/src/particles/qquickparticleemitter.cpp @@ -503,7 +503,6 @@ void QQuickParticleEmitter::emitWindow(int timeStamp) m_last_emission = pt; - m_last_last_last_emitter = m_last_last_emitter; m_last_last_emitter = m_last_emitter; m_last_emitter = QPointF(x(), y()); m_last_timestamp = time; diff --git a/src/particles/qquickparticleemitter_p.h b/src/particles/qquickparticleemitter_p.h index 8c9ca622fb..0455b97d3e 100644 --- a/src/particles/qquickparticleemitter_p.h +++ b/src/particles/qquickparticleemitter_p.h @@ -341,7 +341,6 @@ protected: qreal m_particleEndSize; qreal m_particleSizeVariation; - qreal m_velocityFromMovement; int m_startTime; bool m_overwrite; @@ -359,7 +358,6 @@ protected: QPointF m_last_emitter; QPointF m_last_last_emitter; - QPointF m_last_last_last_emitter; bool isEmitConnected(); diff --git a/src/particles/qquickparticleextruder_p.h b/src/particles/qquickparticleextruder_p.h index 7be0ead245..0249ecd3aa 100644 --- a/src/particles/qquickparticleextruder_p.h +++ b/src/particles/qquickparticleextruder_p.h @@ -70,10 +70,6 @@ public: explicit QQuickParticleExtruder(QObject *parent = 0); virtual QPointF extrude(const QRectF &); virtual bool contains(const QRectF &bounds, const QPointF &point); - -Q_SIGNALS: -public Q_SLOTS: -protected: }; QT_END_NAMESPACE diff --git a/src/particles/qquickparticlegroup_p.h b/src/particles/qquickparticlegroup_p.h index 9b13153a95..6df1e61563 100644 --- a/src/particles/qquickparticlegroup_p.h +++ b/src/particles/qquickparticlegroup_p.h @@ -58,9 +58,6 @@ QT_BEGIN_NAMESPACE class QQuickParticleGroup : public QQuickStochasticState, public QQmlParserStatus { Q_OBJECT - //### Would setting limits per group be useful? Or clutter the API? - //Q_PROPERTY(int maximumAlive READ maximumAlive WRITE setMaximumAlive NOTIFY maximumAliveChanged) - Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) //Intercept children requests and assign to the group & system @@ -75,11 +72,6 @@ public: QQmlListProperty<QObject> particleChildren(); - int maximumAlive() const - { - return m_maximumAlive; - } - QQuickParticleSystem* system() const { return m_system; @@ -87,22 +79,12 @@ public: public Q_SLOTS: - void setMaximumAlive(int arg) - { - if (m_maximumAlive != arg) { - m_maximumAlive = arg; - Q_EMIT maximumAliveChanged(arg); - } - } - void setSystem(QQuickParticleSystem* arg); void delayRedirect(QObject* obj); Q_SIGNALS: - void maximumAliveChanged(int arg); - void systemChanged(QQuickParticleSystem* arg); protected: @@ -113,7 +95,6 @@ private: void performDelayedRedirects(); - int m_maximumAlive; QQuickParticleSystem* m_system; QList<QObject*> m_delayedRedirects; }; diff --git a/src/particles/qquickparticlesystem.cpp b/src/particles/qquickparticlesystem.cpp index 396d6f0a17..9049892c83 100644 --- a/src/particles/qquickparticlesystem.cpp +++ b/src/particles/qquickparticlesystem.cpp @@ -328,7 +328,7 @@ QQuickParticleGroupData::~QQuickParticleGroupData() delete d; } -QString QQuickParticleGroupData::name()//### Worth caching as well? +QString QQuickParticleGroupData::name() const//### Worth caching as well? { return m_system->groupIds.key(index); } @@ -413,9 +413,10 @@ void QQuickParticleGroupData::prepareRecycler(QQuickParticleData* d) if (d->lifeSpan*1000 < m_system->maxLife) { dataHeap.insert(d); } else { - while ((roundedTime(d->t) + 2*m_system->maxLife/3) <= m_system->timeInt) + int extend = 2 * m_system->maxLife / 3; + while ((roundedTime(d->t) + extend) <= m_system->timeInt) d->extendLife(m_system->maxLife / 3000.0, m_system); - dataHeap.insertTimed(d, roundedTime(d->t) + 2*m_system->maxLife/3); + dataHeap.insertTimed(d, roundedTime(d->t) + extend); } } @@ -460,7 +461,6 @@ QQuickParticleData::QQuickParticleData() color.b = 255; color.a = 255; delegate = nullptr; - modelIndex = -1; } QQuickParticleData::~QQuickParticleData() @@ -513,12 +513,8 @@ void QQuickParticleData::clone(const QQuickParticleData& other) animY = other.animY; animWidth = other.animWidth; animHeight = other.animHeight; - color.r = other.color.r; - color.g = other.color.g; - color.b = other.color.b; - color.a = other.color.a; + color = other.color; delegate = other.delegate; - modelIndex = other.modelIndex; colorOwner = other.colorOwner; rotationOwner = other.rotationOwner; diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h index 0269b8a583..8b14b74131 100644 --- a/src/particles/qquickparticlesystem_p.h +++ b/src/particles/qquickparticlesystem_p.h @@ -200,10 +200,12 @@ public: QQuickParticleGroupData(const QString &name, QQuickParticleSystem* sys); ~QQuickParticleGroupData(); - int size() - { return m_size; } + int size() const + { + return m_size; + } - QString name(); + QString name() const; void setSize(int newSize); @@ -321,7 +323,6 @@ public: //Used by ItemParticle QQuickItem* delegate; - int modelIndex; //Used by custom affectors float update; @@ -359,7 +360,10 @@ public: return m_running; } - int count(){ return particleCount; } + int count() const + { + return particleCount; + } static const int maxLife = 600000; diff --git a/src/particles/qquicktrailemitter_p.h b/src/particles/qquicktrailemitter_p.h index bf21b66fb6..6cf2dc0c98 100644 --- a/src/particles/qquicktrailemitter_p.h +++ b/src/particles/qquicktrailemitter_p.h @@ -159,7 +159,6 @@ private Q_SLOTS: void recalcParticlesPerSecond(); private: - QSet<QQuickParticleData*> m_pending; QVector<qreal> m_lastEmission; int m_particlesPerParticlePerSecond; qreal m_lastTimeStamp; diff --git a/src/particles/qquickturbulence.cpp b/src/particles/qquickturbulence.cpp index bc051ef6b7..e066f3efd3 100644 --- a/src/particles/qquickturbulence.cpp +++ b/src/particles/qquickturbulence.cpp @@ -81,7 +81,7 @@ QT_BEGIN_NAMESPACE QQuickTurbulenceAffector::QQuickTurbulenceAffector(QQuickItem *parent) : QQuickParticleAffector(parent), - m_strength(10), m_lastT(0), m_gridSize(0), m_field(nullptr), m_vectorField(nullptr), m_inited(false) + m_strength(10), m_gridSize(0), m_field(nullptr), m_vectorField(nullptr), m_inited(false) { } diff --git a/src/particles/qquickturbulence_p.h b/src/particles/qquickturbulence_p.h index e6204f4f0b..a4aef063de 100644 --- a/src/particles/qquickturbulence_p.h +++ b/src/particles/qquickturbulence_p.h @@ -112,7 +112,6 @@ private: void initializeGrid(); qreal boundsRespectingField(int x, int y); qreal m_strength; - qreal m_lastT; int m_gridSize; qreal** m_field; QPointF** m_vectorField; |