4#ifndef PARTICLESYSTEM_H
5#define PARTICLESYSTEM_H
18#include <QtQuick/QQuickItem>
19#include <QElapsedTimer>
21#include <QVarLengthArray>
25#include <private/qquicksprite_p.h>
26#include <QAbstractAnimation>
27#include <QtQml/qqml.h>
28#include <private/qv4util_p.h>
29#include <private/qv4global_p.h>
30#include <private/qv4staticvalue_p.h>
31#include <private/qtquickparticlesglobal_p.h>
35template<
class T,
int Prealloc>
48 for (
int i = 0;
i < this->
size(); ++
i) {
49 if (this->
at(
i) == element) {
73 QSet<QQuickParticleData*>
data;
86 bool isEmpty()
const {
return m_end == 0; }
88 QSet<QQuickParticleData*> pop();
101 QVector<QQuickParticleDataHeapNode>
m_data;
102 QHash<int,int> m_lookups;
114 int oldSize = isUnused.size();
115 isUnused.resize(newSize,
true);
116 if (newSize > oldSize) {
117 if (firstUnused == UINT_MAX) {
118 firstUnused = oldSize;
120 firstUnused = std::min(firstUnused,
unsigned(oldSize));
122 }
else if (firstUnused >=
unsigned(newSize)) {
123 firstUnused = UINT_MAX;
129 isUnused.setBit(
index);
130 firstUnused = std::min(firstUnused,
unsigned(
index));
135 {
return allocated; }
137 bool hasUnusedEntries()
const
138 {
return firstUnused != UINT_MAX; }
142 if (hasUnusedEntries()) {
143 int nextFree = firstUnused;
144 isUnused.clearBit(firstUnused);
145 firstUnused = isUnused.findNext(firstUnused,
true,
false);
146 if (firstUnused >=
unsigned(isUnused.size())) {
147 firstUnused = UINT_MAX;
158 unsigned firstUnused = UINT_MAX;
164 enum { InvalidID = -1, DefaultGroupID = 0 };
179 void setSize(
int newSize);
182 QQuickParticleVarLengthArray<QQuickParticlePainter*, 4>
painters;
185 QVector<QQuickParticleData*>
data;
203 QVector<QQuickParticleData*> m_latestAliveParticles;
243 int systemIndex = -1;
266 float rotationVelocity = 0;
270 float frameDuration = 1;
272 float frameCount = 1;
277 float animHeight = 1;
302 static inline constexpr float EPSILON() noexcept {
return 0.001f; }
305static_assert(std::is_trivially_copyable_v<QQuickParticleData>);
306static_assert(std::is_trivially_destructible_v<QQuickParticleData>);
312 Q_PROPERTY(
bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged)
328 return particleCount;
331 static const int maxLife = 600000;
342 void stop(){setRunning(
false);}
343 void restart(){setRunning(
false);setRunning(
true);}
348 void setRunning(
bool arg);
349 void setPaused(
bool arg);
356 void componentComplete()
override;
359 void emittersChanged();
362 void particleStateChange(
int idx);
368 int groupId,
bool respectLimits =
true,
int sysIdx = -1,
372 int nextSystemIndex();
383 QVarLengthArray<QQuickParticleGroupData*, 32>
groupData;
403 static void statePropertyRedirect(QQmlListProperty<QObject> *prop,
QObject *
value);
416 void searchNextFreeGroupId();
420 void postProcessEmitters();
421 void initializeSystem();
423 QList<QPointer<QQuickParticleEmitter> > m_emitters;
424 QList<QPointer<QQuickParticleAffector> > m_affectors;
425 QList<QPointer<QQuickParticlePainter> > m_painters;
426 QList<QPointer<QQuickParticlePainter> > m_syncList;
427 QList<QQuickParticleGroup*> m_groups;
429 QSet<int> m_reusableIndexes;
430 bool m_componentComplete;
462 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
464 float vx = (this->vx +
t * this->
ax) - t *
ax;
465 float ex = this->
x + this->vx *
t + 0.5f * this->ax * t_sq;
466 float x = ex -
t *
vx - 0.5f * t_sq *
ax;
475 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
477 float evx =
vx -
t * this->
ax;
478 float ex = this->
x + this->vx *
t + 0.5f * this->ax * t_sq;
479 float x = ex -
t * evx - 0.5f * t_sq * this->
ax;
487 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
489 this->x =
x -
t * this->
vx - 0.5f * t_sq * this->
ax;
494 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
496 float vy = (this->vy +
t * this->
ay) - t *
ay;
497 float ey = this->
y + this->vy *
t + 0.5f * this->ay * t_sq;
498 float y = ey -
t *
vy - 0.5f * t_sq *
ay;
507 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
509 float evy =
vy -
t * this->
ay;
510 float ey = this->
y + this->vy *
t + 0.5f * this->ay * t_sq;
511 float y = ey -
t*evy - 0.5f * t_sq * this->
ay;
519 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
521 this->y =
y -
t * this->
vy - 0.5f * t_sq * this->
ay;
526 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
528 return this->
x + this->
vx * t + 0.5f * this->
ax * t_sq;
533 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
534 return this->
vx + t * this->
ax;
539 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
541 return y +
vy *
t + 0.5f *
ay * t_sq;
546 float t = (particleSystem->
timeInt / 1000.0f) - this->t;
561 float st = (system->
timeInt / 1000.0f);
574 if (!particleSystem ||
lifeSpan == 0.0f)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setInstantaneousVY(float vy, QQuickParticleSystem *particleSystem)
void setInstantaneousVX(float vx, QQuickParticleSystem *particleSystem)
float curY(QQuickParticleSystem *particleSystem) const
void setInstantaneousX(float x, QQuickParticleSystem *particleSystem)
void setInstantaneousAY(float ay, QQuickParticleSystem *particleSystem)
void setInstantaneousAX(float ax, QQuickParticleSystem *particleSystem)
float curVY(QQuickParticleSystem *particleSystem) const
void setInstantaneousY(float y, QQuickParticleSystem *particleSystem)
float curAX(QQuickParticleSystem *) const
bool stillAlive(QQuickParticleSystem *particleSystem) const
float curAY(QQuickParticleSystem *) const
float curVX(QQuickParticleSystem *particleSystem) const
static constexpr float EPSILON() noexcept
bool alive(QQuickParticleSystem *particleSystem) const
float curX(QQuickParticleSystem *particleSystem) const
float lifeLeft(QQuickParticleSystem *particleSystem) const
float curSize(QQuickParticleSystem *particleSystem) const
QVector< QQuickParticleData * > data
QQuickParticleVarLengthArray< QQuickParticlePainter *, 4 > painters
QQuickParticleDataHeap dataHeap
QQuickParticleSystemAnimation(QQuickParticleSystem *system)
void updateCurrentTime(int t) override
This pure virtual function is called every time the animation's currentTime changes.
int duration() const override
This pure virtual function returns the duration of the animation, and defines for how long QAbstractA...
QQuickStochasticEngine * stateEngine
void runningChanged(bool arg)
QVarLengthArray< QQuickParticleGroupData *, 32 > groupData
QQuickParticleSystemAnimation * m_animation
virtual int duration() const
QHash< QString, int > groupIds
void pausedChanged(bool arg)
QVector< QQuickParticleData * > bySysIdx
void updateCurrentTime(int currentTime)
void emptyChanged(bool arg)
QSet< QQuickParticleData * > needsReset
void insert(const T &element)
bool removeOne(const T &element)
\macro QT_RESTRICTED_CAST_FROM_ASCII
constexpr size_type size() const noexcept
void remove(qsizetype i, qsizetype n=1)
bool contains(const AT &t) const
cache insert(employee->id(), employee)
Combined button and popup list for selecting options.
static int grow(QLayoutStruct &ls, int delta)
static Q_CONSTINIT QBasicAtomicInt running
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
Engine * createEngine(QGeoServiceProviderPrivate *)
static bool contains(const QJsonArray &haystack, unsigned needle)
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLdouble GLdouble GLdouble GLdouble top
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define QML_NAMED_ELEMENT(NAME)
#define QML_ADDED_IN_VERSION(MAJOR, MINOR)
static double currentTime()
QSet< QQuickParticleData * > data