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
qquickparticleaffector.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
4#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
5
7#include <QDebug>
8#include <private/qqmlglobal_p.h>
10
14
101 QQuickItem(parent), m_needsReset(false), m_ignoresTime(false), m_onceOff(false), m_enabled(true)
102 , m_system(nullptr), m_updateIntSet(false), m_shape(new QQuickParticleExtruder(this))
103{
104}
105
110
111
113{
114 if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
115 setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));
117}
118
120 if (!m_system)
121 return false;
122
123 if (m_updateIntSet){ //This can occur before group ids are properly assigned, but that resets the flag
124 m_groupIds.clear();
125 foreach (const QString &p, m_groups)
126 m_groupIds << m_system->groupIds[p];
127 m_updateIntSet = false;
128 }
129 return m_groupIds.isEmpty() || m_groupIds.contains(g);
130}
131
133{
134 if (!d)
135 return false;
136 if (!m_system)
137 return false;
138
139 if (activeGroup(d->groupId)){
140 if ((m_onceOff && m_onceOffed.contains(qMakePair(d->groupId, d->index)))
141 || !d->stillAlive(m_system))
142 return false;
143 //Need to have previous location for affected anyways
144 if (width() == 0 || height() == 0
145 || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()), QPointF(d->curX(m_system), d->curY(m_system)))){
146 if (m_whenCollidingWith.isEmpty() || isColliding(d)){
147 return true;
148 }
149 }
150 }
151 return false;
152
153}
154
156{
157 if (!m_system)
158 return;
159
161 if (m_onceOff)
162 m_onceOffed << qMakePair(d->groupId, d->index);
164 emit affected(d->curX(m_system), d->curY(m_system));
165}
166
168const qreal QQuickParticleAffector::simulationCutoff = 1.000;//If this goes above 1.0, then m_once behaviour needs special codepath
169
171{
172 if (!m_enabled)
173 return;
174 if (!m_system)
175 return;
176
177 //If not reimplemented, calls affectParticle per particle
178 //But only on particles in targeted system/area
179 updateOffsets();//### Needed if an ancestor is transformed.
180 if (m_onceOff)
181 dt = 1.0;
182 for (QQuickParticleGroupData* gd : std::as_const(m_system->groupData)) {
183 if (activeGroup(gd->index)) {
184 for (QQuickParticleData* d : std::as_const(gd->data)) {
185 if (shouldAffect(d)) {
186 bool affected = false;
187 qreal myDt = dt;
188 if (!m_ignoresTime && myDt < simulationCutoff) {
189 int realTime = m_system->timeInt;
190 m_system->timeInt -= myDt * 1000.0;
191 while (myDt > simulationDelta) {
192 m_system->timeInt += simulationDelta * 1000.0;
193 if (d->alive(m_system))//Only affect during the parts it was alive for
195 myDt -= simulationDelta;
196 }
197 m_system->timeInt = realTime;
198 }
199 if (myDt > 0.0)
200 affected = affectParticle(d, myDt) || affected;
201 if (affected)
202 postAffect(d);
203 }
204 }
205 }
206 }
207}
208
213
215{//TODO: This, among other ones, should be restructured so they don't all need to remember to call the superclass
216 if (m_onceOff)
217 if (activeGroup(pd->groupId))
219}
220
226
227bool QQuickParticleAffector::isColliding(QQuickParticleData *d) const
228{
229 if (!m_system)
230 return false;
231
232 qreal myCurX = d->curX(m_system);
233 qreal myCurY = d->curY(m_system);
234 qreal myCurSize = d->curSize(m_system) / 2;
235 foreach (const QString &group, m_whenCollidingWith){
237 if (!other->stillAlive(m_system))
238 continue;
239 qreal otherCurX = other->curX(m_system);
240 qreal otherCurY = other->curY(m_system);
241 qreal otherCurSize = other->curSize(m_system) / 2;
242 if ((myCurX + myCurSize > otherCurX - otherCurSize
243 && myCurX - myCurSize < otherCurX + otherCurSize)
244 && (myCurY + myCurSize > otherCurY - otherCurSize
245 && myCurY - myCurSize < otherCurY + otherCurSize))
246 return true;
247 }
248 }
249 return false;
250}
251
253
254#include "moc_qquickparticleaffector_p.cpp"
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
Q_INVOKABLE QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in item's coordinate system to the equivalent point within this item's coordinat...
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
QQuickItem * parentItem() const
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
virtual void reset(QQuickParticleData *)
virtual void affectSystem(qreal dt)
void setSystem(QQuickParticleSystem *arg)
virtual bool affectParticle(QQuickParticleData *d, qreal dt)
void postAffect(QQuickParticleData *datum)
QQuickParticleSystem * m_system
bool shouldAffect(QQuickParticleData *datum)
QSet< QPair< int, int > > m_onceOffed
void componentComplete() override
\reimp Derived classes should call the base class method before adding their own actions to perform a...
QQuickParticleAffector(QQuickItem *parent=nullptr)
Applies alterations to the attributes of logical particles at any point in their lifetime.
void affected(qreal x, qreal y)
QQuickParticleGroupData::ID groupId
virtual bool contains(const QRectF &bounds, const QPointF &point)
QVarLengthArray< QQuickParticleGroupData *, 32 > groupData
QHash< QString, int > groupIds
QSet< QQuickParticleData * > needsReset
\inmodule QtCore\reentrant
Definition qrect.h:484
bool remove(const T &value)
Definition qset.h:63
bool isEmpty() const
Definition qset.h:52
void clear()
Definition qset.h:61
bool contains(const T &value) const
Definition qset.h:71
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
T * data() noexcept
#define this
Definition dialogs.cpp:9
Combined button and popup list for selecting options.
GLint GLsizei width
GLboolean GLuint group
GLboolean GLboolean g
GLfloat GLfloat p
[1]
QT_BEGIN_NAMESPACE constexpr decltype(auto) qMakePair(T1 &&value1, T2 &&value2) noexcept(noexcept(std::make_pair(std::forward< T1 >(value1), std::forward< T2 >(value2))))
Definition qpair.h:19
#define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments)
#define emit
double qreal
Definition qtypes.h:187
QObject::connect nullptr
QSharedPointer< T > other(t)
[5]