colorVariation: 0.1
color: "#2060160f"
}
- SpriteGoal {
+ GroupGoal {
whenCollidingWith: ["lit"]
goalState: "lighting"
jump: true
- systemStates: true
}
}
ParticleGroup {
sizeVariation: 2
endSize: 0
speed: PointDirection { y:-100; yVariation: 4; xVariation: 4 }
- SpriteGoal {
+ GroupGoal {
groups: ["unlit"]
goalState: "lit"
jump: true
- systemStates: true
system: particles
x: -15
y: -55
}
}
//Click to enflame
- SpriteGoal {//TODO: Aux emiiters in the state definition (which allows the occasional ball to spontaneously combust)
+ GroupGoal {
groups: ["unlit"]
goalState: "lighting"
jump: true
- systemStates: true
enabled: ma.pressed
width: 18
height: 18
QT_MODULE(Declarative)
class QSGSprite;
-class QSGStochasticState : public QObject //For internal use
+class Q_AUTOTEST_EXPORT QSGStochasticState : public QObject //For internal use
{
Q_OBJECT
Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
friend class QSGStochasticEngine;
};
-class QSGStochasticEngine : public QObject
+class Q_AUTOTEST_EXPORT QSGStochasticEngine : public QObject
{
Q_OBJECT
//TODO: Optimize single state case?
$$PWD/qsgcumulativedirection_p.h \
$$PWD/qsgv8particledata_p.h \
$$PWD/qsgrectangleextruder_p.h \
- $$PWD/qsgparticlegroup_p.h
+ $$PWD/qsgparticlegroup_p.h \
+ $$PWD/qsggroupgoal_p.h
SOURCES += \
$$PWD/qsgangledirection.cpp \
$$PWD/qsgcumulativedirection.cpp \
$$PWD/qsgv8particledata.cpp \
$$PWD/qsgrectangleextruder.cpp \
- $$PWD/qsgparticlegroup.cpp
+ $$PWD/qsgparticlegroup.cpp \
+ $$PWD/qsggroupgoal.cpp
RESOURCES += \
$$PWD/particles.qrc
--- /dev/null
+/****************************************************************************
+**
+** 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 "qsggroupgoal_p.h"
+#include "private/qsgspriteengine_p.h"
+#include "private/qsgsprite_p.h"
+#include "qsgimageparticle_p.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmlclass GroupGoal QSGGroupGoalAffector
+ \inqmlmodule QtQuick.Particles 2
+ \inherits Affector
+ \brief The GroupGoal Affector allows you to change the state of a group of a particle.
+
+*/
+/*!
+ \qmlproperty string QtQuick.Particles2::GroupGoal::goalState
+
+ The name of the group which the affected particles should move to.
+
+ Groups can have defined durations and transitions between them, setting goalState
+ will cause it to disregard any path weightings (including 0) and head down the path
+ which will reach the goalState quickest. It will pass through intermediate groups
+ on that path for their respective durations.
+*/
+/*!
+ \qmlproperty bool QtQuick.Particles2::GroupGoal::jump
+
+ If true, affected particles will jump directly to the target group instead of taking the
+ the shortest valid path to get there. They will also not finish their current state,
+ but immediately move to the beginning of the goal state.
+
+ Default is false.
+*/
+
+QSGGroupGoalAffector::QSGGroupGoalAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_jump(false)
+{
+}
+
+void QSGGroupGoalAffector::setGoalState(QString arg)
+{
+ if (m_goalState != arg) {
+ m_goalState = arg;
+ emit goalStateChanged(arg);
+ }
+}
+
+bool QSGGroupGoalAffector::affectParticle(QSGParticleData *d, qreal dt)
+{
+ Q_UNUSED(dt);
+ QSGStochasticEngine *engine = m_system->stateEngine;
+ bool notUsingEngine = false;
+ if (!engine)
+ notUsingEngine = true;
+
+ int index = d->systemIndex;
+ int goalIdx = m_system->groupIds[m_goalState];
+ if (notUsingEngine){//no stochastic states defined. So cut out the engine
+ //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
+ m_system->moveGroups(d, goalIdx);
+ return true;
+ }else if (engine->curState(index) != goalIdx){
+ engine->setGoal(goalIdx, index, m_jump);
+ return true;
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
--- /dev/null
+/****************************************************************************
+**
+** 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 GROUPGOALAFFECTOR_H
+#define GROUPGOALAFFECTOR_H
+#include "qsgparticleaffector_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGStochasticEngine;
+
+class QSGGroupGoalAffector : public QSGParticleAffector
+{
+ Q_OBJECT
+ Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged)
+ Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged)
+public:
+ explicit QSGGroupGoalAffector(QSGItem *parent = 0);
+
+ QString goalState() const
+ {
+ return m_goalState;
+ }
+
+ bool jump() const
+ {
+ return m_jump;
+ }
+
+protected:
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
+
+signals:
+
+ void goalStateChanged(QString arg);
+
+ void jumpChanged(bool arg);
+
+public slots:
+
+ void setGoalState(QString arg);
+
+ void setJump(bool arg)
+ {
+ if (m_jump != arg) {
+ m_jump = arg;
+ emit jumpChanged(arg);
+ }
+ }
+
+private:
+ QString m_goalState;
+ bool m_jump;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // GROUPGOALAFFECTOR_H
#include "qsgcustomaffector_p.h"
#include "qsgrectangleextruder_p.h"
#include "qsgparticlegroup_p.h"
+#include "qsggroupgoal_p.h"
QT_BEGIN_NAMESPACE
qmlRegisterType<QSGGravityAffector>(uri, 2, 0, "Gravity");
qmlRegisterType<QSGAgeAffector>(uri, 2, 0, "Age");
qmlRegisterType<QSGSpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
+ qmlRegisterType<QSGGroupGoalAffector>(uri, 2, 0, "GroupGoal");
qmlRegisterType<QSGTurbulenceAffector>(uri, 2, 0 , "Turbulence");
qmlRegisterType<QSGTargetAffector>(uri, 2, 0 , "Target");
\qmlclass SpriteGoal QSGSpriteGoalAffector
\inqmlmodule QtQuick.Particles 2
\inherits Affector
- \brief The SpriteGoal Affector allows you to change the state of a sprite or group of a particle.
+ \brief The SpriteGoal Affector allows you to change the state of a sprite particle.
*/
/*!
\qmlproperty string QtQuick.Particles2::SpriteGoal::goalState
+
+ The name of the Sprite which the affected particles should move to.
+
+ Sprite states have defined durations and transitions between them, setting goalState
+ will cause it to disregard any path weightings (including 0) and head down the path
+ which will reach the goalState quickest. It will pass through intermediate states
+ on that path.
*/
/*!
\qmlproperty bool QtQuick.Particles2::SpriteGoal::jump
+
+ If true, affected sprites will jump directly to the goal state instead of taking the
+ the shortest valid path to get there. They will also not finish their current state,
+ but immediately move to the beginning of the goal state.
+
+ Default is false.
*/
/*!
\qmlproperty bool QtQuick.Particles2::SpriteGoal::systemStates
+
+ deprecated, use GroupGoal instead
*/
QSGSpriteGoalAffector::QSGSpriteGoalAffector(QSGItem *parent) :
m_system->moveGroups(d, m_goalIdx);
}else if (engine->curState(index) != m_goalIdx){
engine->setGoal(m_goalIdx, index, m_jump);
- emit affected(QPointF(d->curX(), d->curY()));//###Expensive if unconnected? Move to Affector?
return true; //Doesn't affect particle data, but necessary for onceOff
}
return false;
#ifndef SPRITEGOALAFFECTOR_H
#define SPRITEGOALAFFECTOR_H
#include "qsgparticleaffector_p.h"
+#include <QtDeclarative/qdeclarativeinfo.h>
QT_BEGIN_HEADER
void jumpChanged(bool arg);
- void affected(const QPointF &pos);
void systemStatesChanged(bool arg);
public slots:
void setSystemStates(bool arg)
{
if (m_systemStates != arg) {
+ //TODO: GroupGoal was added (and this deprecated) Oct 4 - remove it in a few weeks.
+ qmlInfo(this) << "systemStates is deprecated and will be removed soon. Use GroupGoal instead.";
m_systemStates = arg;
emit systemStatesChanged(arg);
}