aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickparticlepainter.cpp
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@digia.com>2016-03-03 14:54:31 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-03-04 13:54:50 +0000
commit5a9734c0d071b7490b3ef7edf5f080786dc89f79 (patch)
treeef8d18707d2f65df718ea785745d079ff3558fb8 /src/particles/qquickparticlepainter.cpp
parent554566788f585caaef14d929cee6557ad929e06e (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/qquickparticlepainter.cpp')
-rw-r--r--src/particles/qquickparticlepainter.cpp46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/particles/qquickparticlepainter.cpp b/src/particles/qquickparticlepainter.cpp
index 134689713d..556d137fd4 100644
--- a/src/particles/qquickparticlepainter.cpp
+++ b/src/particles/qquickparticlepainter.cpp
@@ -64,9 +64,13 @@ QT_BEGIN_NAMESPACE
If empty, it will paint the default particle group ("").
*/
-QQuickParticlePainter::QQuickParticlePainter(QQuickItem *parent) :
- QQuickItem(parent),
- m_system(0), m_count(0), m_pleaseReset(true), m_window(0)
+QQuickParticlePainter::QQuickParticlePainter(QQuickItem *parent)
+ : QQuickItem(parent)
+ , m_system(0)
+ , m_count(0)
+ , m_pleaseReset(true)
+ , m_window(0)
+ , m_groupIdsNeedRecalculation(false)
{
}
@@ -89,11 +93,32 @@ void QQuickParticlePainter::componentComplete()
QQuickItem::componentComplete();
}
+void QQuickParticlePainter::recalculateGroupIds() const
+{
+ if (!m_system) {
+ m_groupIds.clear();
+ return;
+ }
+
+ m_groupIdsNeedRecalculation = false;
+ m_groupIds.clear();
+
+ for (const QString &str : groups()) {
+ QQuickParticleGroupData::ID groupId = m_system->groupIds.value(str, QQuickParticleGroupData::InvalidID);
+ if (groupId == QQuickParticleGroupData::InvalidID) {
+ // invalid data, not finished setting up, or whatever. Fallback: do not cache.
+ m_groupIdsNeedRecalculation = true;
+ } else {
+ m_groupIds.append(groupId);
+ }
+ }
+}
void QQuickParticlePainter::setSystem(QQuickParticleSystem *arg)
{
if (m_system != arg) {
m_system = arg;
+ m_groupIdsNeedRecalculation = true;
if (m_system){
m_system->registerParticlePainter(this);
reset();
@@ -102,6 +127,16 @@ void QQuickParticlePainter::setSystem(QQuickParticleSystem *arg)
}
}
+void QQuickParticlePainter::setGroups(const QStringList &arg)
+{
+ if (m_groups != arg) {
+ m_groups = arg;
+ m_groupIdsNeedRecalculation = true;
+ //Note: The system watches this as it has to recalc things when groups change. It will request a reset if necessary
+ Q_EMIT groupsChanged(arg);
+ }
+}
+
void QQuickParticlePainter::load(QQuickParticleData* d)
{
initialize(d->group, d->index);
@@ -133,11 +168,6 @@ void QQuickParticlePainter::setCount(int c)//### TODO: some resizeing so that pa
reset();
}
-int QQuickParticlePainter::count()
-{
- return m_count;
-}
-
void QQuickParticlePainter::calcSystemOffset(bool resetPending)
{
if (!m_system || !parentItem())