Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickspritegoal.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5#include <private/qquickspriteengine_p.h>
6#include <private/qquicksprite_p.h>
8#include <QDebug>
9
11
48 m_goalIdx(-1),
49 m_lastEngine(nullptr),
50 m_jump(false),
51 m_systemStates(false),
52 m_notUsingEngine(false)
53{
54 m_ignoresTime = true;
55}
56
57void QQuickSpriteGoalAffector::updateStateIndex(QQuickStochasticEngine* e)
58{
59 if (m_systemStates){
60 m_goalIdx = m_system->groupIds[m_goalState];
61 }else{
62 m_lastEngine = e;
63 for (int i=0; i<e->stateCount(); i++){
64 if (e->state(i)->name() == m_goalState){
65 m_goalIdx = i;
66 return;
67 }
68 }
69 m_goalIdx = -1;//Can't find it
70 }
71}
72
74{
75 if (m_goalState != arg) {
76 m_goalState = arg;
78 if (m_goalState.isEmpty())
79 m_goalIdx = -1;
80 else
81 m_goalIdx = -2;
82 }
83}
84
86{
87 Q_UNUSED(dt);
89 if (!m_systemStates){
90 //TODO: Affect all engines
91 for (QQuickParticlePainter *p : m_system->groupData[d->groupId]->painters) {
92 if (qobject_cast<QQuickImageParticle*>(p))
93 engine = qobject_cast<QQuickImageParticle*>(p)->spriteEngine();
94 }
95 } else {
97 if (!engine)
98 m_notUsingEngine = true;
99 }
100 if (!engine && !m_notUsingEngine)
101 return false;
102
103 if (m_goalIdx == -2 || engine != m_lastEngine)
104 updateStateIndex(engine);
105 int index = d->index;
106 if (m_systemStates)
107 index = d->systemIndex;
108 if (m_notUsingEngine){//systemStates && no stochastic states defined. So cut out the engine
109 //TODO: It's possible to move to a group that is intermediate and not used by painters or emitters - but right now that will redirect to the default group
110 m_system->moveGroups(d, m_goalIdx);
111 }else if (engine->curState(index) != m_goalIdx){
112 engine->setGoal(m_goalIdx, index, m_jump);
113 return true; //Doesn't affect particle data, but necessary for onceOff
114 }
115 return false;
116}
117
119
120#include "moc_qquickspritegoal_p.cpp"
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QQuickParticleSystem * m_system
QQuickStochasticEngine * stateEngine
QVarLengthArray< QQuickParticleGroupData *, 32 > groupData
QHash< QString, int > groupIds
void moveGroups(QQuickParticleData *d, int newGIdx)
void setGoalState(const QString &arg)
void goalStateChanged(const QString &arg)
bool affectParticle(QQuickParticleData *d, qreal dt) override
QQuickSpriteGoalAffector(QQuickItem *parent=nullptr)
\qmltype SpriteGoal \instantiates QQuickSpriteGoalAffector \inqmlmodule QtQuick.Particles\inherits Af...
QQuickStochasticState * state(int idx) const
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
Definition qstring.h:192
Combined button and popup list for selecting options.
GLuint index
[2]
GLfloat GLfloat p
[1]
SSL_CTX int void * arg
#define emit
#define Q_UNUSED(x)
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QJSEngine engine
[0]