aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-03-03 13:00:28 +0100
committerErik Verbruggen <erik.verbruggen@theqtcompany.com>2016-03-08 09:37:51 +0000
commit46204fd5d1362811ae040a4a9cb6cf01c37e77c1 (patch)
tree8b14af8871cb852b599f53862e28c93e57679644
parentec3b4cf7a5de9a4ead73f09c3d7a02421b29f805 (diff)
Particles: make many QQuickParticleData members inlinable.
Calls to these functions often occur in sets of two (x, y) or even more (x, y, vx, vy, etc). By allowing the compiler to inline, it allows for many CSE opportunities. Also, if your compiler is reasonably good, it will also auto-vectorize the operations. Change-Id: I4bffe4826671dd60683b941a569fc6a7b4b34da7 Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
-rw-r--r--src/particles/qquickparticlesystem.cpp103
-rw-r--r--src/particles/qquickparticlesystem_p.h111
2 files changed, 105 insertions, 109 deletions
diff --git a/src/particles/qquickparticlesystem.cpp b/src/particles/qquickparticlesystem.cpp
index f4c9121007..5109375f43 100644
--- a/src/particles/qquickparticlesystem.cpp
+++ b/src/particles/qquickparticlesystem.cpp
@@ -529,95 +529,8 @@ QQmlV4Handle QQuickParticleData::v4Value(QQuickParticleSystem* particleSystem)
v8Datum = new QQuickV4ParticleData(QQmlEnginePrivate::getV8Engine(qmlEngine(particleSystem)), this, particleSystem);
return v8Datum->v4Value();
}
-//sets the x accleration without affecting the instantaneous x velocity or position
-void QQuickParticleData::setInstantaneousAX(qreal ax, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- qreal vx = (this->vx + t*this->ax) - t*ax;
- qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t;
- qreal x = ex - t*vx - 0.5 * t*t*ax;
-
- this->ax = ax;
- this->vx = vx;
- this->x = x;
-}
-
-//sets the x velocity without affecting the instantaneous x postion
-void QQuickParticleData::setInstantaneousVX(qreal vx, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- qreal evx = vx - t*this->ax;
- qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t;
- qreal x = ex - t*evx - 0.5 * t*t*this->ax;
-
- this->vx = evx;
- this->x = x;
-}
-
-//sets the instantaneous x postion
-void QQuickParticleData::setInstantaneousX(qreal x, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- this->x = x - t*this->vx - 0.5 * t*t*this->ax;
-}
-
-//sets the y accleration without affecting the instantaneous y velocity or position
-void QQuickParticleData::setInstantaneousAY(qreal ay, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- qreal vy = (this->vy + t*this->ay) - t*ay;
- qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t;
- qreal y = ey - t*vy - 0.5 * t*t*ay;
-
- this->ay = ay;
- this->vy = vy;
- this->y = y;
-}
-
-//sets the y velocity without affecting the instantaneous y position
-void QQuickParticleData::setInstantaneousVY(qreal vy, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- qreal evy = vy - t*this->ay;
- qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t;
- qreal y = ey - t*evy - 0.5 * t*t*this->ay;
-
- this->vy = evy;
- this->y = y;
-}
-
-//sets the instantaneous Y position
-void QQuickParticleData::setInstantaneousY(qreal y, QQuickParticleSystem* particleSystem)
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- this->y = y - t*this->vy - 0.5 * t*t*this->ay;
-}
-qreal QQuickParticleData::curX(QQuickParticleSystem* particleSystem) const
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- return this->x + this->vx * t + 0.5 * this->ax * t * t;
-}
-
-qreal QQuickParticleData::curVX(QQuickParticleSystem* particleSystem) const
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- return this->vx + t*this->ax;
-}
-
-qreal QQuickParticleData::curY(QQuickParticleSystem* particleSystem) const
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- return y + vy * t + 0.5 * ay * t * t;
-}
-
-qreal QQuickParticleData::curVY(QQuickParticleSystem* particleSystem) const
-{
- qreal t = (particleSystem->timeInt / 1000.0) - this->t;
- return vy + t*ay;
-}
-
-void QQuickParticleData::debugDump(QQuickParticleSystem* particleSystem)
+void QQuickParticleData::debugDump(QQuickParticleSystem* particleSystem) const
{
qDebug() << "Particle" << systemIndex << groupId << "/" << index << stillAlive(particleSystem)
<< "Pos: " << x << "," << y
@@ -627,20 +540,6 @@ void QQuickParticleData::debugDump(QQuickParticleSystem* particleSystem)
<< "Time: " << t << "," <<lifeSpan << ";" << (particleSystem->timeInt / 1000.0) ;
}
-float QQuickParticleData::curSize(QQuickParticleSystem* particleSystem)
-{
- if (!particleSystem || !lifeSpan)
- return 0.0f;
- return size + (endSize - size) * (1 - (lifeLeft(particleSystem) / lifeSpan));
-}
-
-float QQuickParticleData::lifeLeft(QQuickParticleSystem* particleSystem)
-{
- if (!particleSystem)
- return 0.0f;
- return (t + lifeSpan) - (particleSystem->timeInt/1000.0);
-}
-
void QQuickParticleData::extendLife(float time, QQuickParticleSystem* particleSystem)
{
qreal newX = curX(particleSystem);
diff --git a/src/particles/qquickparticlesystem_p.h b/src/particles/qquickparticlesystem_p.h
index 182fc6aed6..3ab5300a80 100644
--- a/src/particles/qquickparticlesystem_p.h
+++ b/src/particles/qquickparticlesystem_p.h
@@ -330,11 +330,12 @@ public:
// 4 bytes wasted
- void debugDump(QQuickParticleSystem *particleSystem);
- bool stillAlive(QQuickParticleSystem *particleSystem);//Only checks end, because usually that's all you need and it's a little faster.
- bool alive(QQuickParticleSystem *particleSystem);
- float lifeLeft(QQuickParticleSystem *particleSystem);
- float curSize(QQuickParticleSystem *particleSystem);
+ void debugDump(QQuickParticleSystem *particleSystem) const;
+ bool stillAlive(QQuickParticleSystem *particleSystem) const; //Only checks end, because usually that's all you need and it's a little faster.
+ bool alive(QQuickParticleSystem *particleSystem) const;
+ float lifeLeft(QQuickParticleSystem *particleSystem) const;
+
+ float curSize(QQuickParticleSystem *particleSystem) const;
void clone(const QQuickParticleData& other);//Not =, leaves meta-data like index
QQmlV4Handle v4Value(QQuickParticleSystem *particleSystem);
void extendLife(float time, QQuickParticleSystem *particleSystem);
@@ -489,14 +490,96 @@ private:
QQuickParticleSystem* m_system;
};
-inline bool QQuickParticleData::stillAlive(QQuickParticleSystem* system)
+inline void QQuickParticleData::setInstantaneousAX(qreal ax, QQuickParticleSystem* particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ qreal vx = (this->vx + t*this->ax) - t*ax;
+ qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t;
+ qreal x = ex - t*vx - 0.5 * t*t*ax;
+
+ this->ax = ax;
+ this->vx = vx;
+ this->x = x;
+}
+
+inline void QQuickParticleData::setInstantaneousVX(qreal vx, QQuickParticleSystem* particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ qreal evx = vx - t*this->ax;
+ qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t;
+ qreal x = ex - t*evx - 0.5 * t*t*this->ax;
+
+ this->vx = evx;
+ this->x = x;
+}
+
+inline void QQuickParticleData::setInstantaneousX(qreal x, QQuickParticleSystem* particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ this->x = x - t*this->vx - 0.5 * t*t*this->ax;
+}
+
+inline void QQuickParticleData::setInstantaneousAY(qreal ay, QQuickParticleSystem* particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ qreal vy = (this->vy + t*this->ay) - t*ay;
+ qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t;
+ qreal y = ey - t*vy - 0.5 * t*t*ay;
+
+ this->ay = ay;
+ this->vy = vy;
+ this->y = y;
+}
+
+inline void QQuickParticleData::setInstantaneousVY(qreal vy, QQuickParticleSystem* particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ qreal evy = vy - t*this->ay;
+ qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t;
+ qreal y = ey - t*evy - 0.5 * t*t*this->ay;
+
+ this->vy = evy;
+ this->y = y;
+}
+
+inline void QQuickParticleData::setInstantaneousY(qreal y, QQuickParticleSystem *particleSystem)
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ this->y = y - t * this->vy - 0.5 * t*t*this->ay;
+}
+
+inline qreal QQuickParticleData::curX(QQuickParticleSystem *particleSystem) const
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ return this->x + this->vx * t + 0.5 * this->ax * t * t;
+}
+
+inline qreal QQuickParticleData::curVX(QQuickParticleSystem *particleSystem) const
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ return this->vx + t*this->ax;
+}
+
+inline qreal QQuickParticleData::curY(QQuickParticleSystem *particleSystem) const
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ return y + vy * t + 0.5 * ay * t * t;
+}
+
+inline qreal QQuickParticleData::curVY(QQuickParticleSystem *particleSystem) const
+{
+ qreal t = (particleSystem->timeInt / 1000.0) - this->t;
+ return vy + t*ay;
+}
+
+inline bool QQuickParticleData::stillAlive(QQuickParticleSystem* system) const
{
if (!system)
return false;
return (t + lifeSpan - EPSILON()) > ((qreal)system->timeInt/1000.0);
}
-inline bool QQuickParticleData::alive(QQuickParticleSystem* system)
+inline bool QQuickParticleData::alive(QQuickParticleSystem* system) const
{
if (!system)
return false;
@@ -504,6 +587,20 @@ inline bool QQuickParticleData::alive(QQuickParticleSystem* system)
return (t + EPSILON()) < st && (t + lifeSpan - EPSILON()) > st;
}
+inline float QQuickParticleData::lifeLeft(QQuickParticleSystem *particleSystem) const
+{
+ if (!particleSystem)
+ return 0.0f;
+ return (t + lifeSpan) - (particleSystem->timeInt/1000.0);
+}
+
+inline float QQuickParticleData::curSize(QQuickParticleSystem *particleSystem) const
+{
+ if (!particleSystem || !lifeSpan)
+ return 0.0f;
+ return size + (endSize - size) * (1 - (lifeLeft(particleSystem) / lifeSpan));
+}
+
QT_END_NAMESPACE
#endif // PARTICLESYSTEM_H