diff options
-rw-r--r-- | examples/declarative/particles/affectors/gravity.qml | 8 | ||||
-rw-r--r-- | examples/declarative/particles/affectors/move.qml | 13 | ||||
-rw-r--r-- | src/declarative/particles/particles.pri | 6 | ||||
-rw-r--r-- | src/declarative/particles/qsgcustomaffector.cpp | 93 | ||||
-rw-r--r-- | src/declarative/particles/qsgcustomaffector_p.h | 90 | ||||
-rw-r--r-- | src/declarative/particles/qsggravity.cpp | 2 | ||||
-rw-r--r-- | src/declarative/particles/qsgmove.cpp | 131 | ||||
-rw-r--r-- | src/declarative/particles/qsgmove_p.h | 155 | ||||
-rw-r--r-- | src/declarative/particles/qsgparticleaffector.cpp | 12 | ||||
-rw-r--r-- | src/declarative/particles/qsgparticleaffector_p.h | 10 | ||||
-rw-r--r-- | src/declarative/particles/qsgparticlesmodule.cpp | 2 | ||||
-rw-r--r-- | tests/auto/particles/qsgcustomaffector/data/move.qml | 74 | ||||
-rw-r--r-- | tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp | 27 |
13 files changed, 307 insertions, 316 deletions
diff --git a/examples/declarative/particles/affectors/gravity.qml b/examples/declarative/particles/affectors/gravity.qml index 47710e6306..dc55324f3a 100644 --- a/examples/declarative/particles/affectors/gravity.qml +++ b/examples/declarative/particles/affectors/gravity.qml @@ -82,12 +82,10 @@ Item { } ParticleSystem { id: sys } - Move { + Gravity { system: sys - acceleration: AngleDirection { - angle: ground.rotation + 90 - magnitude: 32 - } + acceleration: 32 + angle: ground.rotation + 90 } Emitter { system: sys diff --git a/examples/declarative/particles/affectors/move.qml b/examples/declarative/particles/affectors/move.qml index 93ff37bd74..bdeab335ad 100644 --- a/examples/declarative/particles/affectors/move.qml +++ b/examples/declarative/particles/affectors/move.qml @@ -66,12 +66,11 @@ Rectangle { height: 80 } - Move { + Affector { groups: ["A"] x: 120 width: 80 height: 80 - relative: true once: true position: PointDirection { x: 120; } } @@ -96,13 +95,12 @@ Rectangle { height: 10 } - Move { + Affector { groups: ["B"] x: 120 y: 240 width: 80 height: 80 - relative: true once: true speed: AngleDirection { angleVariation:360; magnitude: 72 } } @@ -123,18 +121,19 @@ Rectangle { size: 32 sizeVariation: 8 speed: PointDirection{ x: 80; xVariation: 10 } + acceleration: PointDirection { y: 10; x: 20; } width: 80 height: 80 } - Move { + Affector { groups: ["C"] x: 120 y: 400 width: 80 - height: 80 - relative: true + height: 120 once: true + relative: false acceleration: PointDirection { y: -80; } } diff --git a/src/declarative/particles/particles.pri b/src/declarative/particles/particles.pri index 4663c17981..b35cb8a614 100644 --- a/src/declarative/particles/particles.pri +++ b/src/declarative/particles/particles.pri @@ -28,8 +28,7 @@ HEADERS += \ $$PWD/qsgv8particledata_p.h \ $$PWD/qsgrectangleextruder_p.h \ $$PWD/qsgparticlegroup_p.h \ - $$PWD/qsggroupgoal_p.h \ - $$PWD/qsgmove_p.h + $$PWD/qsggroupgoal_p.h SOURCES += \ $$PWD/qsgangledirection.cpp \ @@ -61,8 +60,7 @@ SOURCES += \ $$PWD/qsgv8particledata.cpp \ $$PWD/qsgrectangleextruder.cpp \ $$PWD/qsgparticlegroup.cpp \ - $$PWD/qsggroupgoal.cpp \ - $$PWD/qsgmove.cpp + $$PWD/qsggroupgoal.cpp RESOURCES += \ $$PWD/particles.qrc diff --git a/src/declarative/particles/qsgcustomaffector.cpp b/src/declarative/particles/qsgcustomaffector.cpp index 28b220d45c..e8a1507e99 100644 --- a/src/declarative/particles/qsgcustomaffector.cpp +++ b/src/declarative/particles/qsgcustomaffector.cpp @@ -46,7 +46,7 @@ #include <QDebug> QT_BEGIN_NAMESPACE -//TODO: Move docs (and inherit) to real base when docs can propagate +//TODO: Move docs (and inheritence) to real base when docs can propagate. Currently this pretends to be the base class! /*! \qmlsignal QtQuick.Particles2::Affector::affectParticles(Array particles, real dt) @@ -59,8 +59,44 @@ QT_BEGIN_NAMESPACE Note that JS is slower to execute, so it is not recommended to use this in high-volume particle systems. */ + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::position + + Affected particles will have their position set to this direction, + relative to the ParticleSystem. When interpreting directions as points, + imagine it as an arrow with the base at the 0,0 of the ParticleSystem and the + tip at where the specified position will be. +*/ + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::speed + + Affected particles will have their speed set to this direction. +*/ + + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::acceleration + + Affected particles will have their acceleration set to this direction. +*/ + + +/*! + \qmlproperty bool QtQuick.Particles2::Affector::relative + + Whether the affected particles have their existing position/speed/acceleration added + to the new one. + + Default is true. +*/ QSGCustomAffector::QSGCustomAffector(QQuickItem *parent) : QSGParticleAffector(parent) + , m_position(&m_nullVector) + , m_speed(&m_nullVector) + , m_acceleration(&m_nullVector) + , m_relative(true) { } @@ -90,6 +126,9 @@ void QSGCustomAffector::affectSystem(qreal dt) if (toAffect.isEmpty()) return; + if (m_onceOff) + dt = 1.0; + v8::HandleScope handle_scope; v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); v8::Handle<v8::Array> array = v8::Array::New(toAffect.size()); @@ -97,6 +136,7 @@ void QSGCustomAffector::affectSystem(qreal dt) array->Set(i, toAffect[i]->v8Value().toHandle()); if (dt >= simulationCutoff || dt <= simulationDelta) { + affectProperties(toAffect, dt); emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); } else { int realTime = m_system->timeInt; @@ -104,10 +144,12 @@ void QSGCustomAffector::affectSystem(qreal dt) while (dt > simulationDelta) { m_system->timeInt += simulationDelta * 1000.0; dt -= simulationDelta; + affectProperties(toAffect, simulationDelta); emit affectParticles(QDeclarativeV8Handle::fromHandle(array), simulationDelta); } m_system->timeInt = realTime; if (dt > 0.0) { + affectProperties(toAffect, dt); emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); } } @@ -117,4 +159,53 @@ void QSGCustomAffector::affectSystem(qreal dt) postAffect(d); } +bool QSGCustomAffector::affectParticle(QSGParticleData *d, qreal dt) +{ + //This does the property based affecting, called by superclass if signal isn't hooked up. + bool changed = false; + QPointF curPos(d->curX(), d->curY()); + + if (m_acceleration != &m_nullVector){ + QPointF pos = m_acceleration->sample(curPos); + if (m_relative) { + pos *= dt; + pos += QPointF(d->curAX(), d->curAY()); + } + d->setInstantaneousAX(pos.x()); + d->setInstantaneousAY(pos.y()); + changed = true; + } + + if (m_speed != &m_nullVector){ + QPointF pos = m_speed->sample(curPos); + if (m_relative) { + pos *= dt; + pos += QPointF(d->curVX(), d->curVY()); + } + d->setInstantaneousVX(pos.x()); + d->setInstantaneousVY(pos.y()); + changed = true; + } + + if (m_position != &m_nullVector){ + QPointF pos = m_position->sample(curPos); + if (m_relative) { + pos *= dt; + pos += curPos; + } + d->setInstantaneousX(pos.x()); + d->setInstantaneousY(pos.y()); + changed = true; + } + + return changed; +} + +void QSGCustomAffector::affectProperties(const QList<QSGParticleData*> particles, qreal dt) +{ + foreach (QSGParticleData* d, particles) + if ( affectParticle(d, dt) ) + d->update = 1.0; +} + QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgcustomaffector_p.h b/src/declarative/particles/qsgcustomaffector_p.h index 679034e602..ed711b6c95 100644 --- a/src/declarative/particles/qsgcustomaffector_p.h +++ b/src/declarative/particles/qsgcustomaffector_p.h @@ -46,6 +46,7 @@ #include "qsgparticlesystem_p.h" #include "qsgparticleextruder_p.h" #include "qsgparticleaffector_p.h" +#include "qsgdirection_p.h" QT_BEGIN_HEADER @@ -56,17 +57,106 @@ QT_MODULE(Declarative) class QSGCustomAffector : public QSGParticleAffector { Q_OBJECT + Q_PROPERTY(bool relative READ relative WRITE setRelative NOTIFY relativeChanged) + Q_PROPERTY(QSGDirection *position READ position WRITE setPosition NOTIFY positionChanged RESET positionReset) + Q_PROPERTY(QSGDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged RESET speedReset) + Q_PROPERTY(QSGDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged RESET accelerationReset) public: explicit QSGCustomAffector(QQuickItem *parent = 0); virtual void affectSystem(qreal dt); + QSGDirection * position() const + { + return m_position; + } + + QSGDirection * speed() const + { + return m_speed; + } + + QSGDirection * acceleration() const + { + return m_acceleration; + } + + void positionReset() + { + m_position = &m_nullVector; + } + + void speedReset() + { + m_speed = &m_nullVector; + } + + void accelerationReset() + { + m_acceleration = &m_nullVector; + } + + bool relative() const + { + return m_relative; + } + + signals: void affectParticles(QDeclarativeV8Handle particles, qreal dt); + + void positionChanged(QSGDirection * arg); + + void speedChanged(QSGDirection * arg); + + void accelerationChanged(QSGDirection * arg); + + void relativeChanged(bool arg); + public slots: + void setPosition(QSGDirection * arg) + { + if (m_position != arg) { + m_position = arg; + emit positionChanged(arg); + } + } + + void setSpeed(QSGDirection * arg) + { + if (m_speed != arg) { + m_speed = arg; + emit speedChanged(arg); + } + } + + void setAcceleration(QSGDirection * arg) + { + if (m_acceleration != arg) { + m_acceleration = arg; + emit accelerationChanged(arg); + } + } + + void setRelative(bool arg) + { + if (m_relative != arg) { + m_relative = arg; + emit relativeChanged(arg); + } + } + protected: bool isAffectConnected(); + virtual bool affectParticle(QSGParticleData *d, qreal dt); private: + void affectProperties(const QList<QSGParticleData*> particles, qreal dt); + QSGDirection * m_position; + QSGDirection * m_speed; + QSGDirection * m_acceleration; + + QSGDirection m_nullVector; + bool m_relative; }; QT_END_NAMESPACE diff --git a/src/declarative/particles/qsggravity.cpp b/src/declarative/particles/qsggravity.cpp index 2967f7a307..8f6b221387 100644 --- a/src/declarative/particles/qsggravity.cpp +++ b/src/declarative/particles/qsggravity.cpp @@ -78,8 +78,6 @@ QSGGravityAffector::QSGGravityAffector(QQuickItem *parent) : connect(this, SIGNAL(angleChanged(qreal)), this, SLOT(recalc())); recalc(); - qWarning() << "Gravity has been deprecated. Use Move instead." - << "The difference is that you can specify the acceleration with a StochasticDirection instead of just an angle/magnitude pair"; } void QSGGravityAffector::recalc() diff --git a/src/declarative/particles/qsgmove.cpp b/src/declarative/particles/qsgmove.cpp deleted file mode 100644 index 9f13fad093..0000000000 --- a/src/declarative/particles/qsgmove.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the Declarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qsgmove_p.h" -#include <cmath> -QT_BEGIN_NAMESPACE -const qreal CONV = 0.017453292520444443; -/*! - \qmlclass Move QSGMoveAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Move element allows you to set a new position, speed or acceleration on particles - - You'll often want to set the 'once' property to true for efficiency in the case where you just - want to set the parameter. Otherwise, the parameter will be needlessly set to the same thing - every simulation cycle. -*/ - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Move::position - - Affected particles will have their position set to this direction, - relative to the ParticleSystem. When interpreting directions as points, - imagine it as an arrow with the base at the 0,0 of the ParticleSystem and the - tip at where the specified position will be. -*/ - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Move::speed - - Affected particles will have their speed set to this direction. -*/ - - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Move::acceleration - - Affected particles will have their acceleration set to this direction. -*/ - - -/*! - \qmlproperty bool QtQuick.Particles2::Move::relative - - Whether the affected particles have their existing position/speed/acceleration added - to the new one. -*/ - -QSGMoveAffector::QSGMoveAffector(QQuickItem *parent) - : QSGParticleAffector(parent) - , m_position(&m_nullVector) - , m_speed(&m_nullVector) - , m_acceleration(&m_nullVector) - , m_relative(false) -{ -} - -bool QSGMoveAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - Q_UNUSED(dt); - bool changed = false; - QPointF curPos(d->curX(), d->curY()); - - if (m_position != &m_nullVector){ - QPointF pos = m_position->sample(curPos); - if (m_relative) - pos += curPos; - d->setInstantaneousX(pos.x()); - d->setInstantaneousY(pos.y()); - changed = true; - } - - if (m_speed != &m_nullVector){ - QPointF pos = m_speed->sample(curPos); - if (m_relative) - pos += QPointF(d->curVX(), d->curVY()); - d->setInstantaneousVX(pos.x()); - d->setInstantaneousVY(pos.y()); - changed = true; - } - - if (m_acceleration != &m_nullVector){ - QPointF pos = m_acceleration->sample(curPos); - if (m_relative) - pos += QPointF(d->curAX(), d->curAY()); - d->setInstantaneousAX(pos.x()); - d->setInstantaneousAY(pos.y()); - changed = true; - } - - return changed; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgmove_p.h b/src/declarative/particles/qsgmove_p.h deleted file mode 100644 index 4ff5239357..0000000000 --- a/src/declarative/particles/qsgmove_p.h +++ /dev/null @@ -1,155 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the Declarative module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef MOVEAFFECTOR_H -#define MOVEAFFECTOR_H -#include "qsgparticleaffector_p.h" -#include "qsgdirection_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGMoveAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(bool relative READ relative WRITE setRelative NOTIFY relativeChanged) - Q_PROPERTY(QSGDirection *position READ position WRITE setPosition NOTIFY positionChanged RESET positionReset) - Q_PROPERTY(QSGDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged RESET speedReset) - Q_PROPERTY(QSGDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged RESET accelerationReset) - -public: - explicit QSGMoveAffector(QQuickItem *parent = 0); - QSGDirection * position() const - { - return m_position; - } - - QSGDirection * speed() const - { - return m_speed; - } - - QSGDirection * acceleration() const - { - return m_acceleration; - } - - void positionReset() - { - m_position = &m_nullVector; - } - - void speedReset() - { - m_speed = &m_nullVector; - } - - void accelerationReset() - { - m_acceleration = &m_nullVector; - } - - bool relative() const - { - return m_relative; - } - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -signals: - void positionChanged(QSGDirection * arg); - - void speedChanged(QSGDirection * arg); - - void accelerationChanged(QSGDirection * arg); - - void relativeChanged(bool arg); - -public slots: - void setPosition(QSGDirection * arg) - { - if (m_position != arg) { - m_position = arg; - emit positionChanged(arg); - } - } - - void setSpeed(QSGDirection * arg) - { - if (m_speed != arg) { - m_speed = arg; - emit speedChanged(arg); - } - } - - void setAcceleration(QSGDirection * arg) - { - if (m_acceleration != arg) { - m_acceleration = arg; - emit accelerationChanged(arg); - } - } - - void setRelative(bool arg) - { - if (m_relative != arg) { - m_relative = arg; - emit relativeChanged(arg); - } - } - -private slots: -private: - QSGDirection * m_position; - QSGDirection * m_speed; - QSGDirection * m_acceleration; - - QSGDirection m_nullVector; - bool m_relative; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // MOVEAFFECTOR_H diff --git a/src/declarative/particles/qsgparticleaffector.cpp b/src/declarative/particles/qsgparticleaffector.cpp index e31f8ff89c..9d633aa900 100644 --- a/src/declarative/particles/qsgparticleaffector.cpp +++ b/src/declarative/particles/qsgparticleaffector.cpp @@ -99,7 +99,9 @@ QT_BEGIN_NAMESPACE /*! \qmlproperty bool QtQuick.Particles2::Affector::once If once is set to true, this affector will only affect each particle - once in their lifetimes. + once in their lifetimes. If the affector normally simulates a continuous + effect over time, then it will simulate the effect of one second of time + the one instant it affects the particle. Default value is false. */ @@ -137,8 +139,8 @@ QT_BEGIN_NAMESPACE x,y is the particles current position. */ QSGParticleAffector::QSGParticleAffector(QQuickItem *parent) : - QQuickItem(parent), m_needsReset(false), m_ignoresTime(false), m_system(0), m_enabled(true) - , m_updateIntSet(false), m_shape(new QSGParticleExtruder(this)) + QQuickItem(parent), m_needsReset(false), m_ignoresTime(false), m_onceOff(false), m_enabled(true) + , m_system(0), m_updateIntSet(false), m_shape(new QSGParticleExtruder(this)) { } @@ -196,7 +198,7 @@ void QSGParticleAffector::postAffect(QSGParticleData* d) } const qreal QSGParticleAffector::simulationDelta = 0.020; -const qreal QSGParticleAffector::simulationCutoff = 1.000; +const qreal QSGParticleAffector::simulationCutoff = 1.000;//If this goes above 1.0, then m_once behaviour needs special codepath void QSGParticleAffector::affectSystem(qreal dt) { @@ -205,6 +207,8 @@ void QSGParticleAffector::affectSystem(qreal dt) //If not reimplemented, calls affectParticle per particle //But only on particles in targeted system/area updateOffsets();//### Needed if an ancestor is transformed. + if (m_onceOff) + dt = 1.0; foreach (QSGParticleGroupData* gd, m_system->groupData) { if (activeGroup(m_system->groupData.key(gd))) { foreach (QSGParticleData* d, gd->data) { diff --git a/src/declarative/particles/qsgparticleaffector_p.h b/src/declarative/particles/qsgparticleaffector_p.h index 10c1cf095a..b7fef2e226 100644 --- a/src/declarative/particles/qsgparticleaffector_p.h +++ b/src/declarative/particles/qsgparticleaffector_p.h @@ -169,14 +169,16 @@ public slots: protected: friend class QSGParticleSystem; virtual bool affectParticle(QSGParticleData *d, qreal dt); - bool m_needsReset;//### What is this really saving? - bool m_ignoresTime; + bool m_needsReset:1;//### What is this really saving? + bool m_ignoresTime:1; + bool m_onceOff:1; + bool m_enabled:1; + QSGParticleSystem* m_system; QStringList m_groups; bool activeGroup(int g); bool shouldAffect(QSGParticleData* datum);//Call to do the logic on whether it is affecting that datum void postAffect(QSGParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal) - bool m_enabled; virtual void componentComplete(); QPointF m_offset; bool isAffectedConnected(); @@ -187,8 +189,6 @@ private: QSet<QPair<int, int> > m_onceOffed; bool m_updateIntSet; - bool m_onceOff; - QSGParticleExtruder* m_shape; QStringList m_whenCollidingWith; diff --git a/src/declarative/particles/qsgparticlesmodule.cpp b/src/declarative/particles/qsgparticlesmodule.cpp index 6e170b1e1c..f9a457bce1 100644 --- a/src/declarative/particles/qsgparticlesmodule.cpp +++ b/src/declarative/particles/qsgparticlesmodule.cpp @@ -68,7 +68,6 @@ #include "qsgrectangleextruder_p.h" #include "qsgparticlegroup_p.h" #include "qsggroupgoal_p.h" -#include "qsgmove_p.h" QT_BEGIN_NAMESPACE @@ -105,7 +104,6 @@ void QSGParticlesModule::defineModule() qmlRegisterType<QSGSpriteGoalAffector>(uri, 2, 0, "SpriteGoal"); qmlRegisterType<QSGGroupGoalAffector>(uri, 2, 0, "GroupGoal"); qmlRegisterType<QSGTurbulenceAffector>(uri, 2, 0 , "Turbulence"); - qmlRegisterType<QSGMoveAffector>(uri, 2, 0, "Move"); //Exposed just for completeness qmlRegisterUncreatableType<QSGParticleAffector>(uri, 2, 0, "ParticleAffector", diff --git a/tests/auto/particles/qsgcustomaffector/data/move.qml b/tests/auto/particles/qsgcustomaffector/data/move.qml new file mode 100644 index 0000000000..f3d651c502 --- /dev/null +++ b/tests/auto/particles/qsgcustomaffector/data/move.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + + Affector { + once: false + relative: false + position: PointDirection { x: 50; y: 50; } + speed: PointDirection { x: 50; y: 50; } + acceleration: PointDirection { x: 50; y: 50; } + } + } +} diff --git a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp index d49f6cb908..91aa971eb7 100644 --- a/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp +++ b/tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp @@ -52,6 +52,7 @@ public: private slots: void test_basic(); + void test_move(); }; tst_qsgcustomaffector::tst_qsgcustomaffector() @@ -83,6 +84,32 @@ void tst_qsgcustomaffector::test_basic() } } +void tst_qsgcustomaffector::test_move() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/move.qml", 600); + QSGParticleSystem* system = view->rootObject()->findChild<QSGParticleSystem*>("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QSGParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + if (!d->stillAlive()) + continue; //parameters no longer get set once you die + + QVERIFY(myFuzzyCompare(d->curX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curY(), 50.0)); + QVERIFY(myFuzzyCompare(d->curVX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curVY(), 50.0)); + QVERIFY(myFuzzyCompare(d->curAX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curAY(), 50.0)); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + QTEST_MAIN(tst_qsgcustomaffector); #include "tst_qsgcustomaffector.moc" |