aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickparticlesystem.cpp
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2023-09-22 21:27:49 +0200
committerUlf Hermann <ulf.hermann@qt.io>2023-10-19 09:30:57 +0200
commitdd40ba76835b6f0a229492086e84e22b3dad3bb1 (patch)
tree6aec7013fed2a12603e5d059774b17e4228cfbea /src/particles/qquickparticlesystem.cpp
parentc85695369c065d3735dc58d7e50c901c20f4bb35 (diff)
Particles: Simplify QQuickParticleData
There is no need for the custom lifecycle methods. Change-Id: I13d78518366e888b9f38f8c73060f963897e53be Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Shawn Rutledge (away) <shawn.rutledge@qt.io>
Diffstat (limited to 'src/particles/qquickparticlesystem.cpp')
-rw-r--r--src/particles/qquickparticlesystem.cpp118
1 files changed, 18 insertions, 100 deletions
diff --git a/src/particles/qquickparticlesystem.cpp b/src/particles/qquickparticlesystem.cpp
index 003cea4da6..1d0f5fb56d 100644
--- a/src/particles/qquickparticlesystem.cpp
+++ b/src/particles/qquickparticlesystem.cpp
@@ -385,101 +385,6 @@ void QQuickParticleGroupData::prepareRecycler(QQuickParticleData* d)
}
}
-QQuickParticleData::QQuickParticleData()
- : index(0)
- , systemIndex(-1)
- , groupId(0)
- , colorOwner(nullptr)
- , rotationOwner(nullptr)
- , deformationOwner(nullptr)
- , animationOwner(nullptr)
-{
- x = 0;
- y = 0;
- t = -1;
- lifeSpan = 0;
- size = 0;
- endSize = 0;
- vx = 0;
- vy = 0;
- ax = 0;
- ay = 0;
- xx = 1;
- xy = 0;
- yx = 0;
- yy = 1;
- rotation = 0;
- rotationVelocity = 0;
- autoRotate = 0;
- animIdx = 0;
- frameDuration = 1;
- frameAt = -1;
- frameCount = 1;
- animT = -1;
- animX = 0;
- animY = 0;
- animWidth = 1;
- animHeight = 1;
- color.r = 255;
- color.g = 255;
- color.b = 255;
- color.a = 255;
- delegate = nullptr;
-}
-
-QQuickParticleData::QQuickParticleData(const QQuickParticleData &other)
-{
- *this = other;
-}
-
-QQuickParticleData &QQuickParticleData::operator=(const QQuickParticleData &other)
-{
- clone(other);
-
- groupId = other.groupId;
- index = other.index;
- systemIndex = other.systemIndex;
- // Lazily initialized
-
- return *this;
-}
-
-void QQuickParticleData::clone(const QQuickParticleData& other)
-{
- x = other.x;
- y = other.y;
- t = other.t;
- lifeSpan = other.lifeSpan;
- size = other.size;
- endSize = other.endSize;
- vx = other.vx;
- vy = other.vy;
- ax = other.ax;
- ay = other.ay;
- xx = other.xx;
- xy = other.xy;
- yx = other.yx;
- yy = other.yy;
- rotation = other.rotation;
- rotationVelocity = other.rotationVelocity;
- autoRotate = other.autoRotate;
- animIdx = other.animIdx;
- frameDuration = other.frameDuration;
- frameCount = other.frameCount;
- animT = other.animT;
- animX = other.animX;
- animY = other.animY;
- animWidth = other.animWidth;
- animHeight = other.animHeight;
- color = other.color;
- delegate = other.delegate;
-
- colorOwner = other.colorOwner;
- rotationOwner = other.rotationOwner;
- deformationOwner = other.deformationOwner;
- animationOwner = other.animationOwner;
-}
-
QQuickV4ParticleData QQuickParticleData::v4Value(QQuickParticleSystem *particleSystem)
{
return QQuickV4ParticleData(this, particleSystem);
@@ -944,11 +849,10 @@ void QQuickParticleSystem::moveGroups(QQuickParticleData *d, int newGIdx)
if (!d || newGIdx == d->groupId)
return;
- QQuickParticleData* pd = newDatum(newGIdx, false, d->systemIndex);
+ QQuickParticleData *pd = newDatum(newGIdx, false, d->systemIndex, d);
if (!pd)
return;
- pd->clone(*d);
finishNewDatum(pd);
d->systemIndex = -1;
@@ -971,14 +875,28 @@ int QQuickParticleSystem::nextSystemIndex()
return m_nextIndex++;
}
-QQuickParticleData* QQuickParticleSystem::newDatum(int groupId, bool respectLimits, int sysIndex)
+QQuickParticleData *QQuickParticleSystem::newDatum(
+ int groupId, bool respectLimits, int sysIndex,
+ const QQuickParticleData *cloneFrom)
{
Q_ASSERT(groupId < groupData.size());//XXX shouldn't really be an assert
- QQuickParticleData* ret = groupData[groupId]->newDatum(respectLimits);
- if (!ret) {
+ QQuickParticleData *ret = groupData[groupId]->newDatum(respectLimits);
+ if (!ret)
return nullptr;
+
+ if (cloneFrom) {
+ // We need to retain the "identity" information of the new particle data since it may be
+ // "recycled" and still be tracked.
+ const int retainedIndex = ret->index;
+ const int retainedGroupId = ret->groupId;
+ const int retainedSystemIndex = ret->systemIndex;
+ *ret = *cloneFrom;
+ ret->index = retainedIndex;
+ ret->groupId = retainedGroupId;
+ ret->systemIndex = retainedSystemIndex;
}
+
if (sysIndex == -1) {
if (ret->systemIndex == -1)
ret->systemIndex = nextSystemIndex();