5#include <QtQuick/qsgnode.h>
9#include <private/qquickspriteengine_p.h>
10#include <private/qquicksprite_p.h>
15#include <private/qqmlengine_p.h>
16#include <private/qqmlglobal_p.h>
17#include <private/qqmlvaluetypewrapper_p.h>
176 m_data.reserve(1000);
180void QQuickParticleDataHeap::grow()
194 m_data[m_lookups[
time]].data <<
data;
197 if (m_end == (1 << m_size))
199 m_data[m_end].time =
time;
200 m_data[m_end].data.clear();
201 m_data[m_end].data.insert(
data);
209 return m_data[0].time;
215 return QSet<QQuickParticleData*> ();
216 QSet<QQuickParticleData*>
ret = m_data[0].data;
221 m_data[0] = m_data[--m_end];
238 for (
int i=0;
i<m_end;
i++)
239 if (m_data[
i].
data.contains(
d))
244void QQuickParticleDataHeap::swap(
int a,
int b)
247 m_data[
a] = m_data[
b];
249 m_lookups[m_data[
a].time] =
a;
253void QQuickParticleDataHeap::bubbleUp(
int idx)
257 int parent = (idx-1)/2;
258 if (m_data[idx].
time < m_data[parent].
time) {
264void QQuickParticleDataHeap::bubbleDown(
int idx)
266 int left = idx*2 + 1;
270 int right = idx*2 + 2;
275 if (m_data[idx].
time > m_data[lesser].
time) {
302 if (newSize == m_size)
305 data.resize(newSize);
307 for (
int i=m_size;
i<newSize;
i++) {
312 int delta = newSize - m_size;
315 p->setCount(
p->count() + delta);
336 while (
freeList.hasUnusedEntries()) {
338 if (
data[idx]->stillAlive(m_system)) {
347 int oldSize = m_size;
356 m_latestAliveParticles.clear();
360 if (!datum->stillAlive(m_system)) {
363 m_latestAliveParticles.push_back(datum);
368 for (
auto particle : m_latestAliveParticles)
377 if (
d->lifeSpan*1000 < m_system->
maxLife) {
380 int extend = 2 * m_system->
maxLife / 3;
382 d->extendLife(m_system->
maxLife / 3000.0, m_system);
395 <<
"Pos: " <<
x <<
"," <<
y
396 <<
"Vel: " <<
vx <<
"," <<
vy
397 <<
"Acc: " <<
ax <<
"," <<
ay
399 <<
"Time: " <<
t <<
"," <<
lifeSpan <<
";" << (particleSystem->
timeInt / 1000.0) ;
433 m_componentComplete(
false),
446void QQuickParticleSystem::initGroups()
448 m_reusableIndexes.
clear();
456 for (
auto e :
std::as_const(m_emitters)) {
457 e->reclaculateGroupId();
460 p->recalculateGroupIds();
471 qDebug() <<
"Registering Painter" <<
p <<
"to" <<
this;
473 m_painters << QPointer<QQuickParticlePainter>(
p);
482 qDebug() <<
"Registering Emitter" << e <<
"to" <<
this;
483 m_emitters << QPointer<QQuickParticleEmitter>(e);
489 this, &QQuickParticleSystem::emittersChanged);
491 this, &QQuickParticleSystem::emittersChanged);
492 if (m_componentComplete)
500 qDebug() <<
"Registering Affector" <<
a <<
"to" <<
this;
502 m_affectors << QPointer<QQuickParticleAffector>(
a);
508 qDebug() <<
"Registering Group" <<
g <<
"to" <<
this;
509 m_groups << QPointer<QQuickParticleGroup>(
g);
526 if (m_paused !=
arg) {
557 a->setParentItem(sys);
564 fe->setParentItem(sys);
565 fe->setFollow(
group->name());
578 p->setParentItem(sys);
583 qWarning() <<
value <<
" was placed inside a particle system state but cannot be taken into the particle system. It will be lost.";
598 searchNextFreeGroupId();
604void QQuickParticleSystem::searchNextFreeGroupId()
618 m_componentComplete =
true;
625 if (!m_componentComplete)
666 if (!m_componentComplete || !
painter)
670 sg->painters.removeOne(
painter);
674 if (
painter->groups().isEmpty()) {
691void QQuickParticleSystem::emittersChanged()
693 if (!m_componentComplete)
696 QVector<int> previousSizes;
697 QVector<int> newSizes;
706 for (
int i = 0;
i < m_emitters.
size(); ) {
732 postProcessEmitters();
735void QQuickParticleSystem::postProcessEmitters()
745 a->m_updateIntSet =
true;
759 if (!m_componentComplete)
763 const int groupId = e->
groupId();
778 postProcessEmitters();
781void QQuickParticleSystem::createEngine()
783 if (!m_componentComplete)
786 qDebug() <<
"Resetting Existing Sprite Engine...";
801 if (m_groups.
size()) {
804 QList<QQuickParticleGroup*> newList;
809 if (existing->name() ==
name) {
816 newList.back()->setName(
name);
820 QList<QQuickStochasticState*>
states;
831 this, &QQuickParticleSystem::particleStateChange);
841void QQuickParticleSystem::particleStateChange(
int idx)
848 if (!
d || newGIdx ==
d->groupId)
863 if (!m_reusableIndexes.
isEmpty()) {
864 int ret = *(m_reusableIndexes.
begin());
868 if (m_nextIndex >=
bySysIdx.size()) {
874 return m_nextIndex++;
878 int groupId,
bool respectLimits,
int sysIndex,
890 const int retainedIndex =
ret->index;
891 const int retainedGroupId =
ret->groupId;
892 const int retainedSystemIndex =
ret->systemIndex;
894 ret->index = retainedIndex;
895 ret->groupId = retainedGroupId;
896 ret->systemIndex = retainedSystemIndex;
899 if (sysIndex == -1) {
900 if (
ret->systemIndex == -1)
903 if (
ret->systemIndex != -1) {
906 m_reusableIndexes <<
ret->systemIndex;
909 ret->systemIndex = sysIndex;
924 QTransform t = particleEmitter->itemTransform(
this, &okay);
927 t.map(pd->
x, pd->
y, &tx, &
ty);
941 if (
a &&
a->m_needsReset)
964 bool oldClear = m_empty;
967 m_empty = gd->recycle() && m_empty;
980 if (oldClear != m_empty)
990 p->performPendingCommits();
997#include "moc_qquickparticlesystem_p.cpp"
State state
state of the animation.
void resume()
Resumes the animation after it was paused.
void stop()
Stops the animation.
void start(QAbstractAnimation::DeletionPolicy policy=KeepWhenStopped)
Starts the animation.
void pause()
Pauses the animation.
key_iterator keyEnd() const noexcept
bool remove(const Key &key)
Removes the item that has the key from the hash.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
key_iterator keyBegin() const noexcept
Key key(const T &value) const noexcept
void clear() noexcept(std::is_nothrow_destructible< Node >::value)
Removes all items from the hash and frees up all memory used by it.
iterator insert(const Key &key, const T &value)
Inserts a new item with the key and a value of value.
qsizetype size() const noexcept
bool isEmpty() const noexcept
void removeAt(qsizetype i)
const_reference at(qsizetype i) const noexcept
qsizetype removeAll(const AT &t)
void reserve(qsizetype size)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
void setParentItem(QQuickItem *parent)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
QSet< QQuickParticleData * > pop()
void insertTimed(QQuickParticleData *data, int time)
void insert(QQuickParticleData *data)
bool contains(QQuickParticleData *)
QQuickParticleGroupData::ID groupId
float curY(QQuickParticleSystem *particleSystem) const
void extendLife(float time, QQuickParticleSystem *particleSystem)
float curVY(QQuickParticleSystem *particleSystem) const
bool stillAlive(QQuickParticleSystem *particleSystem) const
void debugDump(QQuickParticleSystem *particleSystem) const
float curVX(QQuickParticleSystem *particleSystem) const
QQuickV4ParticleData v4Value(QQuickParticleSystem *particleSystem)
float curX(QQuickParticleSystem *particleSystem) const
int particleCount() const
void groupChanged(const QString &arg)
void setSystem(QQuickParticleSystem *arg)
void setGroup(const QString &arg)
void particleCountChanged()
QQuickParticleGroupData::ID groupId() const
void prepareRecycler(QQuickParticleData *d)
QQuickParticleData * newDatum(bool respectsLimits)
QQuickParticleVarLengthArray< QQuickParticlePainter *, 4 > painters
QQuickParticleGroupData(const QString &name, QQuickParticleSystem *sys)
QQuickParticleDataHeap dataHeap
~QQuickParticleGroupData()
void kill(QQuickParticleData *d)
void setSize(int newSize)
void groupsChanged(const QStringList &arg)
void registerParticleEmitter(QQuickParticleEmitter *e)
QQuickStochasticEngine * stateEngine
QQuickParticleData * newDatum(int groupId, bool respectLimits=true, int sysIdx=-1, const QQuickParticleData *cloneFrom=nullptr)
void runningChanged(bool arg)
void finishRegisteringParticleEmitter(QQuickParticleEmitter *e)
int registerParticleGroupData(const QString &name, QQuickParticleGroupData *pgd)
void registerParticlePainter(QQuickParticlePainter *p)
void emitParticle(QQuickParticleData *p, QQuickParticleEmitter *particleEmitter)
QVarLengthArray< QQuickParticleGroupData *, 32 > groupData
QQuickParticleSystem(QQuickItem *parent=nullptr)
QQuickParticleSystemAnimation * m_animation
void registerParticleGroup(QQuickParticleGroup *g)
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
void setRunning(bool arg)
static void stateRedirect(QQuickParticleGroup *group, QQuickParticleSystem *sys, QObject *value)
QHash< QString, int > groupIds
void pausedChanged(bool arg)
QVector< QQuickParticleData * > bySysIdx
static void statePropertyRedirect(QQmlListProperty< QObject > *prop, QObject *value)
void finishNewDatum(QQuickParticleData *)
void registerParticleAffector(QQuickParticleAffector *a)
void updateCurrentTime(int currentTime)
void moveGroups(QQuickParticleData *d, int newGIdx)
void emptyChanged(bool arg)
int systemSync(QQuickParticlePainter *p)
QSet< QQuickParticleData * > needsReset
void stateChanged(int idx)
void start(int index=0, int state=0)
QList< QQuickStochasticState * > m_states
uint updateSprites(uint time)
int curState(int index=0) const
bool remove(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
constexpr size_type size() const noexcept
void push_back(const T &t)
qDeleteAll(list.begin(), list.end())
QSet< QString >::iterator it
Combined button and popup list for selecting options.
QList< QString > QStringList
Constructs a string list that contains the given string, str.
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
int qRound(qfloat16 d) noexcept
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
#define DEFINE_BOOL_CONFIG_OPTION(name, var)
static QT_BEGIN_NAMESPACE int roundedTime(qreal a)
A system which includes particle painter, emitter, and affector types.
static double elapsed(qint64 after, qint64 before)
static double currentTime()
bool contains(const AT &t) const noexcept