diff options
Diffstat (limited to 'src/particles/qquickcustomaffector.cpp')
-rw-r--r-- | src/particles/qquickcustomaffector.cpp | 86 |
1 files changed, 24 insertions, 62 deletions
diff --git a/src/particles/qquickcustomaffector.cpp b/src/particles/qquickcustomaffector.cpp index c447ff440e..2ba7b4c536 100644 --- a/src/particles/qquickcustomaffector.cpp +++ b/src/particles/qquickcustomaffector.cpp @@ -1,62 +1,28 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qquickcustomaffector_p.h" -#include <private/qqmlengine_p.h> + +#include <private/qquickv4particledata_p.h> #include <private/qqmlglobal_p.h> -#include <private/qjsvalue_p.h> -#include <QQmlEngine> -#include <QDebug> + +#include <QtCore/qdebug.h> + QT_BEGIN_NAMESPACE //TODO: Move docs (and inheritence) to real base when docs can propagate. Currently this pretends to be the base class! /*! \qmlsignal QtQuick.Particles::Affector::affectParticles(Array particles, real dt) - This signal is emitted when particles are selected to be affected. particles contains - an array of particle objects which can be directly manipulated. + This signal is emitted when particles are selected to be affected. + \a particles is an array of particle objects which can be directly + manipulated. - dt is the time since the last time it was affected. Use dt to normalize - trajectory manipulations to real time. + \a dt is the time since the last time it was affected. Use \a dt to + normalize trajectory manipulations to real time. - Note that JavaScript is slower to execute, so it is not recommended to use this in - high-volume particle systems. + \note JavaScript is slower to execute, so it is not recommended to use + this in high-volume particle systems. */ /*! @@ -101,7 +67,9 @@ QQuickCustomAffector::QQuickCustomAffector(QQuickItem *parent) : bool QQuickCustomAffector::isAffectConnected() { - IS_SIGNAL_CONNECTED(this, QQuickCustomAffector, affectParticles, (const QJSValue &, qreal)); + IS_SIGNAL_CONNECTED( + this, QQuickCustomAffector, affectParticles, + (const QList<QQuickV4ParticleData> &, qreal)); } void QQuickCustomAffector::affectSystem(qreal dt) @@ -120,7 +88,7 @@ void QQuickCustomAffector::affectSystem(qreal dt) updateOffsets(); QList<QQuickParticleData*> toAffect; - for (const QQuickParticleGroupData *gd : qAsConst(m_system->groupData)) { + for (const QQuickParticleGroupData *gd : std::as_const(m_system->groupData)) { if (activeGroup(gd->index)) { for (QQuickParticleData *d : gd->data) { if (shouldAffect(d)) { @@ -134,7 +102,7 @@ void QQuickCustomAffector::affectSystem(qreal dt) return; if (justAffected) { - for (const QQuickParticleData *d : qAsConst(toAffect)) {//Not postAffect to avoid saying the particle changed + for (const QQuickParticleData *d : std::as_const(toAffect)) {//Not postAffect to avoid saying the particle changed if (m_onceOff) m_onceOffed << qMakePair(d->groupId, d->index); emit affected(d->curX(m_system), d->curY(m_system)); @@ -145,19 +113,13 @@ void QQuickCustomAffector::affectSystem(qreal dt) if (m_onceOff) dt = 1.0; - QQmlEngine *qmlEngine = ::qmlEngine(this); - QV4::ExecutionEngine *v4 = qmlEngine->handle(); - - QV4::Scope scope(v4); - QV4::ScopedArrayObject array(scope, v4->newArrayObject(toAffect.size())); - QV4::ScopedValue v(scope); - for (int i=0; i<toAffect.size(); i++) - array->put(i, (v = toAffect[i]->v4Value(m_system))); + QList<QQuickV4ParticleData> particles; + particles.reserve(toAffect.size()); + for (QQuickParticleData *data: std::as_const(toAffect)) + particles.push_back(data->v4Value(m_system)); const auto doAffect = [&](qreal dt) { affectProperties(toAffect, dt); - QJSValue particles; - QJSValuePrivate::setValue(&particles, array); emit affectParticles(particles, dt); }; @@ -176,7 +138,7 @@ void QQuickCustomAffector::affectSystem(qreal dt) doAffect(dt); } - for (QQuickParticleData *d : qAsConst(toAffect)) + for (QQuickParticleData *d : std::as_const(toAffect)) if (d->update == 1.0) postAffect(d); } |