| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/particles/qquickparticleemitter.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | #include "qquickparticleemitter_p.h" | - | ||||||||||||||||||||||||
| 41 | #include <private/qqmlengine_p.h> | - | ||||||||||||||||||||||||
| 42 | #include <private/qqmlglobal_p.h> | - | ||||||||||||||||||||||||
| 43 | #include <QRandomGenerator> | - | ||||||||||||||||||||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||
| 46 | - | |||||||||||||||||||||||||
| 47 | /*! | - | ||||||||||||||||||||||||
| 48 | \qmltype Emitter | - | ||||||||||||||||||||||||
| 49 | \instantiates QQuickParticleEmitter | - | ||||||||||||||||||||||||
| 50 | \inqmlmodule QtQuick.Particles | - | ||||||||||||||||||||||||
| 51 | \brief Emits logical particles. | - | ||||||||||||||||||||||||
| 52 | \ingroup qtquick-particles | - | ||||||||||||||||||||||||
| 53 | - | |||||||||||||||||||||||||
| 54 | This element emits logical particles into the ParticleSystem, with the | - | ||||||||||||||||||||||||
| 55 | given starting attributes. | - | ||||||||||||||||||||||||
| 56 | - | |||||||||||||||||||||||||
| 57 | Note that logical particles are not | - | ||||||||||||||||||||||||
| 58 | automatically rendered, you will need to have one or more | - | ||||||||||||||||||||||||
| 59 | ParticlePainter elements visualizing them. | - | ||||||||||||||||||||||||
| 60 | - | |||||||||||||||||||||||||
| 61 | Note that the given starting attributes can be modified at any point | - | ||||||||||||||||||||||||
| 62 | in the particle's lifetime by any Affector element in the same | - | ||||||||||||||||||||||||
| 63 | ParticleSystem. This includes attributes like lifespan. | - | ||||||||||||||||||||||||
| 64 | */ | - | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | - | |||||||||||||||||||||||||
| 67 | /*! | - | ||||||||||||||||||||||||
| 68 | \qmlproperty ParticleSystem QtQuick.Particles::Emitter::system | - | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | This is the Particle system that the Emitter will emit into. | - | ||||||||||||||||||||||||
| 71 | This can be omitted if the Emitter is a direct child of the ParticleSystem | - | ||||||||||||||||||||||||
| 72 | */ | - | ||||||||||||||||||||||||
| 73 | /*! | - | ||||||||||||||||||||||||
| 74 | \qmlproperty string QtQuick.Particles::Emitter::group | - | ||||||||||||||||||||||||
| 75 | - | |||||||||||||||||||||||||
| 76 | This is the logical particle group which it will emit into. | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | Default value is "" (empty string). | - | ||||||||||||||||||||||||
| 79 | */ | - | ||||||||||||||||||||||||
| 80 | /*! | - | ||||||||||||||||||||||||
| 81 | \qmlproperty Shape QtQuick.Particles::Emitter::shape | - | ||||||||||||||||||||||||
| 82 | - | |||||||||||||||||||||||||
| 83 | This shape is applied with the size of the Emitter. Particles will be emitted | - | ||||||||||||||||||||||||
| 84 | randomly from any area covered by the shape. | - | ||||||||||||||||||||||||
| 85 | - | |||||||||||||||||||||||||
| 86 | The default shape is a filled in rectangle, which corresponds to the full bounding | - | ||||||||||||||||||||||||
| 87 | box of the Emitter. | - | ||||||||||||||||||||||||
| 88 | */ | - | ||||||||||||||||||||||||
| 89 | /*! | - | ||||||||||||||||||||||||
| 90 | \qmlproperty bool QtQuick.Particles::Emitter::enabled | - | ||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | If set to false, the emitter will cease emissions until it is set to true. | - | ||||||||||||||||||||||||
| 93 | - | |||||||||||||||||||||||||
| 94 | Default value is true. | - | ||||||||||||||||||||||||
| 95 | */ | - | ||||||||||||||||||||||||
| 96 | /*! | - | ||||||||||||||||||||||||
| 97 | \qmlproperty real QtQuick.Particles::Emitter::emitRate | - | ||||||||||||||||||||||||
| 98 | - | |||||||||||||||||||||||||
| 99 | Number of particles emitted per second. | - | ||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | Default value is 10 particles per second. | - | ||||||||||||||||||||||||
| 102 | */ | - | ||||||||||||||||||||||||
| 103 | /*! | - | ||||||||||||||||||||||||
| 104 | \qmlproperty int QtQuick.Particles::Emitter::lifeSpan | - | ||||||||||||||||||||||||
| 105 | - | |||||||||||||||||||||||||
| 106 | The time in milliseconds each emitted particle should last for. | - | ||||||||||||||||||||||||
| 107 | - | |||||||||||||||||||||||||
| 108 | If you do not want particles to automatically die after a time, for example if | - | ||||||||||||||||||||||||
| 109 | you wish to dispose of them manually, set lifeSpan to Emitter.InfiniteLife. | - | ||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | lifeSpans greater than or equal to 600000 (10 minutes) will be treated as infinite. | - | ||||||||||||||||||||||||
| 112 | Particles with lifeSpans less than or equal to 0 will start out dead. | - | ||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||
| 114 | Default value is 1000 (one second). | - | ||||||||||||||||||||||||
| 115 | */ | - | ||||||||||||||||||||||||
| 116 | /*! | - | ||||||||||||||||||||||||
| 117 | \qmlproperty int QtQuick.Particles::Emitter::lifeSpanVariation | - | ||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | Particle lifespans will vary by up to this much in either direction. | - | ||||||||||||||||||||||||
| 120 | - | |||||||||||||||||||||||||
| 121 | Default value is 0. | - | ||||||||||||||||||||||||
| 122 | */ | - | ||||||||||||||||||||||||
| 123 | - | |||||||||||||||||||||||||
| 124 | /*! | - | ||||||||||||||||||||||||
| 125 | \qmlproperty int QtQuick.Particles::Emitter::maximumEmitted | - | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | The maximum number of particles at a time that this emitter will have alive. | - | ||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | This can be set as a performance optimization (when using burst and pulse) or | - | ||||||||||||||||||||||||
| 130 | to stagger emissions. | - | ||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | If this is set to a number below zero, then there is no maximum limit on the number | - | ||||||||||||||||||||||||
| 133 | of particles this emitter can have alive. | - | ||||||||||||||||||||||||
| 134 | - | |||||||||||||||||||||||||
| 135 | The default value is -1. | - | ||||||||||||||||||||||||
| 136 | */ | - | ||||||||||||||||||||||||
| 137 | /*! | - | ||||||||||||||||||||||||
| 138 | \qmlproperty int QtQuick.Particles::Emitter::startTime | - | ||||||||||||||||||||||||
| 139 | - | |||||||||||||||||||||||||
| 140 | If this value is set when the emitter is loaded, then it will emit particles from the | - | ||||||||||||||||||||||||
| 141 | past, up to startTime milliseconds ago. These will simulate as if they were emitted then, | - | ||||||||||||||||||||||||
| 142 | but will not have any affectors applied to them. Affectors will take effect from the present time. | - | ||||||||||||||||||||||||
| 143 | */ | - | ||||||||||||||||||||||||
| 144 | /*! | - | ||||||||||||||||||||||||
| 145 | \qmlproperty real QtQuick.Particles::Emitter::size | - | ||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | The size in pixels of the particles at the start of their life. | - | ||||||||||||||||||||||||
| 148 | - | |||||||||||||||||||||||||
| 149 | Default value is 16. | - | ||||||||||||||||||||||||
| 150 | */ | - | ||||||||||||||||||||||||
| 151 | /*! | - | ||||||||||||||||||||||||
| 152 | \qmlproperty real QtQuick.Particles::Emitter::endSize | - | ||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||
| 154 | The size in pixels of the particles at the end of their life. Size will | - | ||||||||||||||||||||||||
| 155 | be linearly interpolated during the life of the particle from this value and | - | ||||||||||||||||||||||||
| 156 | size. If endSize is -1, then the size of the particle will remain constant at | - | ||||||||||||||||||||||||
| 157 | the starting size. | - | ||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | Default value is -1. | - | ||||||||||||||||||||||||
| 160 | */ | - | ||||||||||||||||||||||||
| 161 | /*! | - | ||||||||||||||||||||||||
| 162 | \qmlproperty real QtQuick.Particles::Emitter::sizeVariation | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | The size of a particle can vary by this much up or down from size/endSize. The same | - | ||||||||||||||||||||||||
| 165 | random addition is made to both size and endSize for a single particle. | - | ||||||||||||||||||||||||
| 166 | - | |||||||||||||||||||||||||
| 167 | Default value is 0. | - | ||||||||||||||||||||||||
| 168 | */ | - | ||||||||||||||||||||||||
| 169 | /*! | - | ||||||||||||||||||||||||
| 170 | \qmlproperty StochasticDirection QtQuick.Particles::Emitter::velocity | - | ||||||||||||||||||||||||
| 171 | - | |||||||||||||||||||||||||
| 172 | The starting velocity of the particles emitted. | - | ||||||||||||||||||||||||
| 173 | */ | - | ||||||||||||||||||||||||
| 174 | /*! | - | ||||||||||||||||||||||||
| 175 | \qmlproperty StochasticDirection QtQuick.Particles::Emitter::acceleration | - | ||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | The starting acceleraton of the particles emitted. | - | ||||||||||||||||||||||||
| 178 | */ | - | ||||||||||||||||||||||||
| 179 | /*! | - | ||||||||||||||||||||||||
| 180 | \qmlproperty qreal QtQuick.Particles::Emitter::velocityFromMovement | - | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | If this value is non-zero, then any movement of the emitter will provide additional | - | ||||||||||||||||||||||||
| 183 | starting velocity to the particles based on the movement. The additional vector will be the | - | ||||||||||||||||||||||||
| 184 | same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters | - | ||||||||||||||||||||||||
| 185 | movement multiplied by velocityFromMovement. | - | ||||||||||||||||||||||||
| 186 | - | |||||||||||||||||||||||||
| 187 | Default value is 0. | - | ||||||||||||||||||||||||
| 188 | */ | - | ||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||
| 190 | /*! | - | ||||||||||||||||||||||||
| 191 | \qmlsignal QtQuick.Particles::Emitter::emitParticles(Array particles) | - | ||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||
| 193 | This signal is emitted when particles are emitted. particles is a JavaScript | - | ||||||||||||||||||||||||
| 194 | array of Particle objects. You can modify particle attributes directly within the handler. | - | ||||||||||||||||||||||||
| 195 | - | |||||||||||||||||||||||||
| 196 | Note that JavaScript is slower to execute, so it is not recommended to use this in | - | ||||||||||||||||||||||||
| 197 | high-volume particle systems. | - | ||||||||||||||||||||||||
| 198 | - | |||||||||||||||||||||||||
| 199 | The corresponding handler is \c onEmitParticles. | - | ||||||||||||||||||||||||
| 200 | */ | - | ||||||||||||||||||||||||
| 201 | - | |||||||||||||||||||||||||
| 202 | /*! \qmlmethod QtQuick.Particles::Emitter::burst(int count) | - | ||||||||||||||||||||||||
| 203 | - | |||||||||||||||||||||||||
| 204 | Emits count particles from this emitter immediately. | - | ||||||||||||||||||||||||
| 205 | */ | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | /*! \qmlmethod QtQuick.Particles::Emitter::burst(int count, int x, int y) | - | ||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||
| 209 | Emits count particles from this emitter immediately. The particles are emitted | - | ||||||||||||||||||||||||
| 210 | as if the Emitter was positioned at x,y but all other properties are the same. | - | ||||||||||||||||||||||||
| 211 | */ | - | ||||||||||||||||||||||||
| 212 | - | |||||||||||||||||||||||||
| 213 | /*! \qmlmethod QtQuick.Particles::Emitter::pulse(int duration) | - | ||||||||||||||||||||||||
| 214 | - | |||||||||||||||||||||||||
| 215 | If the emitter is not enabled, enables it for duration milliseconds and then switches | - | ||||||||||||||||||||||||
| 216 | it back off. | - | ||||||||||||||||||||||||
| 217 | */ | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | QQuickParticleEmitter::QQuickParticleEmitter(QQuickItem *parent) : | - | ||||||||||||||||||||||||
| 220 | QQuickItem(parent) | - | ||||||||||||||||||||||||
| 221 | , m_particlesPerSecond(10) | - | ||||||||||||||||||||||||
| 222 | , m_particleDuration(1000) | - | ||||||||||||||||||||||||
| 223 | , m_particleDurationVariation(0) | - | ||||||||||||||||||||||||
| 224 | , m_enabled(true) | - | ||||||||||||||||||||||||
| 225 | , m_system(nullptr) | - | ||||||||||||||||||||||||
| 226 | , m_extruder(nullptr) | - | ||||||||||||||||||||||||
| 227 | , m_defaultExtruder(nullptr) | - | ||||||||||||||||||||||||
| 228 | , m_velocity(&m_nullVector) | - | ||||||||||||||||||||||||
| 229 | , m_acceleration(&m_nullVector) | - | ||||||||||||||||||||||||
| 230 | , m_particleSize(16) | - | ||||||||||||||||||||||||
| 231 | , m_particleEndSize(-1) | - | ||||||||||||||||||||||||
| 232 | , m_particleSizeVariation(0) | - | ||||||||||||||||||||||||
| 233 | , m_startTime(0) | - | ||||||||||||||||||||||||
| 234 | , m_overwrite(true) | - | ||||||||||||||||||||||||
| 235 | , m_pulseLeft(0) | - | ||||||||||||||||||||||||
| 236 | , m_maxParticleCount(-1) | - | ||||||||||||||||||||||||
| 237 | , m_velocity_from_movement(0) | - | ||||||||||||||||||||||||
| 238 | , m_reset_last(true) | - | ||||||||||||||||||||||||
| 239 | , m_last_timestamp(-1) | - | ||||||||||||||||||||||||
| 240 | , m_last_emission(0) | - | ||||||||||||||||||||||||
| 241 | , m_groupIdNeedRecalculation(false) | - | ||||||||||||||||||||||||
| 242 | , m_groupId(QQuickParticleGroupData::DefaultGroupID) | - | ||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||
| 244 | { | - | ||||||||||||||||||||||||
| 245 | //TODO: Reset velocity/acc back to null vector? Or allow null pointer? | - | ||||||||||||||||||||||||
| 246 | connect(this, SIGNAL(particlesPerSecondChanged(qreal)), | - | ||||||||||||||||||||||||
| 247 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 248 | connect(this, SIGNAL(particleDurationChanged(int)), | - | ||||||||||||||||||||||||
| 249 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 250 | } executed 284 times by 24 tests: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | QQuickParticleEmitter::~QQuickParticleEmitter() | - | ||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||
| 254 | if (m_defaultExtruder)
| 68-216 | ||||||||||||||||||||||||
| 255 | delete m_defaultExtruder; executed 68 times by 19 tests: delete m_defaultExtruder;Executed by:
| 68 | ||||||||||||||||||||||||
| 256 | } executed 284 times by 24 tests: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | bool QQuickParticleEmitter::isEmitConnected() | - | ||||||||||||||||||||||||
| 259 | { | - | ||||||||||||||||||||||||
| 260 | IS_SIGNAL_CONNECTED(this, QQuickParticleEmitter, emitParticles, (QQmlV4Handle)); executed 25085 times by 23 tests: return QObjectPrivate::get(sender)->isSignalConnected(signalIdx);Executed by:
| 25085 | ||||||||||||||||||||||||
| 261 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||
| 263 | void QQuickParticleEmitter::reclaculateGroupId() const | - | ||||||||||||||||||||||||
| 264 | { | - | ||||||||||||||||||||||||
| 265 | if (!m_system) {
| 0-524 | ||||||||||||||||||||||||
| 266 | m_groupId = QQuickParticleGroupData::InvalidID; | - | ||||||||||||||||||||||||
| 267 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 268 | } | - | ||||||||||||||||||||||||
| 269 | m_groupId = m_system->groupIds.value(group(), QQuickParticleGroupData::InvalidID); | - | ||||||||||||||||||||||||
| 270 | m_groupIdNeedRecalculation = m_groupId == QQuickParticleGroupData::InvalidID; | - | ||||||||||||||||||||||||
| 271 | } executed 524 times by 24 tests: end of blockExecuted by:
| 524 | ||||||||||||||||||||||||
| 272 | - | |||||||||||||||||||||||||
| 273 | void QQuickParticleEmitter::componentComplete() | - | ||||||||||||||||||||||||
| 274 | { | - | ||||||||||||||||||||||||
| 275 | if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
| 8-168 | ||||||||||||||||||||||||
| 276 | setSystem(qobject_cast<QQuickParticleSystem*>(parentItem())); executed 160 times by 24 tests: setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));Executed by:
| 160 | ||||||||||||||||||||||||
| 277 | if (m_system)
| 8-276 | ||||||||||||||||||||||||
| 278 | m_system->finishRegisteringParticleEmitter(this); executed 276 times by 24 tests: m_system->finishRegisteringParticleEmitter(this);Executed by:
| 276 | ||||||||||||||||||||||||
| 279 | QQuickItem::componentComplete(); | - | ||||||||||||||||||||||||
| 280 | } executed 284 times by 24 tests: end of blockExecuted by:
| 284 | ||||||||||||||||||||||||
| 281 | - | |||||||||||||||||||||||||
| 282 | void QQuickParticleEmitter::setEnabled(bool arg) | - | ||||||||||||||||||||||||
| 283 | { | - | ||||||||||||||||||||||||
| 284 | if (m_enabled != arg) {
| 22-64 | ||||||||||||||||||||||||
| 285 | m_enabled = arg; | - | ||||||||||||||||||||||||
| 286 | emit enabledChanged(arg); | - | ||||||||||||||||||||||||
| 287 | } executed 64 times by 1 test: end of blockExecuted by:
| 64 | ||||||||||||||||||||||||
| 288 | } executed 86 times by 1 test: end of blockExecuted by:
| 86 | ||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | QQuickParticleExtruder* QQuickParticleEmitter::effectiveExtruder() | - | ||||||||||||||||||||||||
| 292 | { | - | ||||||||||||||||||||||||
| 293 | if (m_extruder)
| 8480-41968 | ||||||||||||||||||||||||
| 294 | return m_extruder; executed 8480 times by 4 tests: return m_extruder;Executed by:
| 8480 | ||||||||||||||||||||||||
| 295 | if (!m_defaultExtruder)
| 68-41900 | ||||||||||||||||||||||||
| 296 | m_defaultExtruder = new QQuickParticleExtruder; executed 68 times by 19 tests: m_defaultExtruder = new QQuickParticleExtruder;Executed by:
| 68 | ||||||||||||||||||||||||
| 297 | return m_defaultExtruder; executed 41968 times by 19 tests: return m_defaultExtruder;Executed by:
| 41968 | ||||||||||||||||||||||||
| 298 | } | - | ||||||||||||||||||||||||
| 299 | - | |||||||||||||||||||||||||
| 300 | void QQuickParticleEmitter::pulse(int milliseconds) | - | ||||||||||||||||||||||||
| 301 | { | - | ||||||||||||||||||||||||
| 302 | if (!m_enabled)
| 0-4 | ||||||||||||||||||||||||
| 303 | m_pulseLeft = milliseconds; executed 4 times by 1 test: m_pulseLeft = milliseconds;Executed by:
| 4 | ||||||||||||||||||||||||
| 304 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||
| 306 | void QQuickParticleEmitter::burst(int num) | - | ||||||||||||||||||||||||
| 307 | { | - | ||||||||||||||||||||||||
| 308 | m_burstQueue << qMakePair(num, QPointF(x(), y())); | - | ||||||||||||||||||||||||
| 309 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||
| 310 | - | |||||||||||||||||||||||||
| 311 | void QQuickParticleEmitter::burst(int num, qreal x, qreal y) | - | ||||||||||||||||||||||||
| 312 | { | - | ||||||||||||||||||||||||
| 313 | m_burstQueue << qMakePair(num, QPointF(x, y)); | - | ||||||||||||||||||||||||
| 314 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 315 | - | |||||||||||||||||||||||||
| 316 | void QQuickParticleEmitter::setMaxParticleCount(int arg) | - | ||||||||||||||||||||||||
| 317 | { | - | ||||||||||||||||||||||||
| 318 | if (m_maxParticleCount != arg) {
| 0-22 | ||||||||||||||||||||||||
| 319 | if (arg < 0 && m_maxParticleCount >= 0){
| 0-22 | ||||||||||||||||||||||||
| 320 | connect(this, SIGNAL(particlesPerSecondChanged(qreal)), | - | ||||||||||||||||||||||||
| 321 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 322 | connect(this, SIGNAL(particleDurationChanged(int)), | - | ||||||||||||||||||||||||
| 323 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 324 | }else if (arg >= 0 && m_maxParticleCount < 0){ never executed: end of block
| 0-22 | ||||||||||||||||||||||||
| 325 | disconnect(this, SIGNAL(particlesPerSecondChanged(qreal)), | - | ||||||||||||||||||||||||
| 326 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 327 | disconnect(this, SIGNAL(particleDurationChanged(int)), | - | ||||||||||||||||||||||||
| 328 | this, SIGNAL(particleCountChanged())); | - | ||||||||||||||||||||||||
| 329 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 330 | m_overwrite = arg < 0; | - | ||||||||||||||||||||||||
| 331 | m_maxParticleCount = arg; | - | ||||||||||||||||||||||||
| 332 | emit maximumEmittedChanged(arg); | - | ||||||||||||||||||||||||
| 333 | emit particleCountChanged(); | - | ||||||||||||||||||||||||
| 334 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 335 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | void QQuickParticleEmitter::setVelocityFromMovement(qreal t) | - | ||||||||||||||||||||||||
| 338 | { | - | ||||||||||||||||||||||||
| 339 | if (t == m_velocity_from_movement)
| 0-22 | ||||||||||||||||||||||||
| 340 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 341 | m_velocity_from_movement = t; | - | ||||||||||||||||||||||||
| 342 | emit velocityFromMovementChanged(); | - | ||||||||||||||||||||||||
| 343 | } executed 22 times by 1 test: end of blockExecuted by:
| 22 | ||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | void QQuickParticleEmitter::reset() | - | ||||||||||||||||||||||||
| 346 | { | - | ||||||||||||||||||||||||
| 347 | m_reset_last = true; | - | ||||||||||||||||||||||||
| 348 | } executed 472 times by 24 tests: end of blockExecuted by:
| 472 | ||||||||||||||||||||||||
| 349 | - | |||||||||||||||||||||||||
| 350 | void QQuickParticleEmitter::emitWindow(int timeStamp) | - | ||||||||||||||||||||||||
| 351 | { | - | ||||||||||||||||||||||||
| 352 | if (m_system == nullptr)
| 0-3235 | ||||||||||||||||||||||||
| 353 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 354 | if ((!m_enabled || m_particlesPerSecond <= 0)&& !m_pulseLeft && m_burstQueue.isEmpty()){
| 0-3235 | ||||||||||||||||||||||||
| 355 | m_reset_last = true; | - | ||||||||||||||||||||||||
| 356 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 357 | } | - | ||||||||||||||||||||||||
| 358 | - | |||||||||||||||||||||||||
| 359 | if (m_reset_last) {
| 82-3153 | ||||||||||||||||||||||||
| 360 | m_last_emitter = m_last_last_emitter = QPointF(x(), y()); | - | ||||||||||||||||||||||||
| 361 | if (m_last_timestamp == -1)
| 0-82 | ||||||||||||||||||||||||
| 362 | m_last_timestamp = (timeStamp - m_startTime)/1000.; executed 82 times by 23 tests: m_last_timestamp = (timeStamp - m_startTime)/1000.;Executed by:
| 82 | ||||||||||||||||||||||||
| 363 | else | - | ||||||||||||||||||||||||
| 364 | m_last_timestamp = timeStamp/1000.; never executed: m_last_timestamp = timeStamp/1000.; | 0 | ||||||||||||||||||||||||
| 365 | m_last_emission = m_last_timestamp; | - | ||||||||||||||||||||||||
| 366 | m_reset_last = false; | - | ||||||||||||||||||||||||
| 367 | m_emitCap = -1; | - | ||||||||||||||||||||||||
| 368 | } executed 82 times by 23 tests: end of blockExecuted by:
| 82 | ||||||||||||||||||||||||
| 369 | - | |||||||||||||||||||||||||
| 370 | if (m_pulseLeft){
| 0-3235 | ||||||||||||||||||||||||
| 371 | m_pulseLeft -= timeStamp - m_last_timestamp * 1000.; | - | ||||||||||||||||||||||||
| 372 | if (m_pulseLeft < 0){
| 0 | ||||||||||||||||||||||||
| 373 | if (!m_enabled)
| 0 | ||||||||||||||||||||||||
| 374 | timeStamp += m_pulseLeft; never executed: timeStamp += m_pulseLeft; | 0 | ||||||||||||||||||||||||
| 375 | m_pulseLeft = 0; | - | ||||||||||||||||||||||||
| 376 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 377 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 378 | qreal time = timeStamp / 1000.; | - | ||||||||||||||||||||||||
| 379 | qreal particleRatio = 1. / m_particlesPerSecond; | - | ||||||||||||||||||||||||
| 380 | qreal pt = m_last_emission; | - | ||||||||||||||||||||||||
| 381 | qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0; | - | ||||||||||||||||||||||||
| 382 | if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now
| 0-3235 | ||||||||||||||||||||||||
| 383 | pt = time - maxLife; never executed: pt = time - maxLife; | 0 | ||||||||||||||||||||||||
| 384 | - | |||||||||||||||||||||||||
| 385 | qreal opt = pt; // original particle time | - | ||||||||||||||||||||||||
| 386 | qreal dt = time - m_last_timestamp; // timestamp delta... | - | ||||||||||||||||||||||||
| 387 | if (!dt)
| 82-3153 | ||||||||||||||||||||||||
| 388 | dt = 0.000001; executed 82 times by 23 tests: dt = 0.000001;Executed by:
| 82 | ||||||||||||||||||||||||
| 389 | - | |||||||||||||||||||||||||
| 390 | // emitter difference since last... | - | ||||||||||||||||||||||||
| 391 | qreal dex = (x() - m_last_emitter.x()); | - | ||||||||||||||||||||||||
| 392 | qreal dey = (y() - m_last_emitter.y()); | - | ||||||||||||||||||||||||
| 393 | - | |||||||||||||||||||||||||
| 394 | qreal ax = (m_last_last_emitter.x() + m_last_emitter.x()) / 2; | - | ||||||||||||||||||||||||
| 395 | qreal bx = m_last_emitter.x(); | - | ||||||||||||||||||||||||
| 396 | qreal cx = (x() + m_last_emitter.x()) / 2; | - | ||||||||||||||||||||||||
| 397 | qreal ay = (m_last_last_emitter.y() + m_last_emitter.y()) / 2; | - | ||||||||||||||||||||||||
| 398 | qreal by = m_last_emitter.y(); | - | ||||||||||||||||||||||||
| 399 | qreal cy = (y() + m_last_emitter.y()) / 2; | - | ||||||||||||||||||||||||
| 400 | - | |||||||||||||||||||||||||
| 401 | qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize;
| 0-3235 | ||||||||||||||||||||||||
| 402 | qreal emitter_x_offset = m_last_emitter.x() - x(); | - | ||||||||||||||||||||||||
| 403 | qreal emitter_y_offset = m_last_emitter.y() - y(); | - | ||||||||||||||||||||||||
| 404 | if (!m_burstQueue.isEmpty() && !m_pulseLeft && !m_enabled)//'outside time' emissions only
| 0-3235 | ||||||||||||||||||||||||
| 405 | pt = time; never executed: pt = time; | 0 | ||||||||||||||||||||||||
| 406 | - | |||||||||||||||||||||||||
| 407 | QList<QQuickParticleData*> toEmit; | - | ||||||||||||||||||||||||
| 408 | - | |||||||||||||||||||||||||
| 409 | while ((pt < time && m_emitCap) || !m_burstQueue.isEmpty()) {
| 0-50448 | ||||||||||||||||||||||||
| 410 | //int pos = m_last_particle % m_particle_count; | - | ||||||||||||||||||||||||
| 411 | QQuickParticleData* datum = m_system->newDatum(m_system->groupIds[m_group], !m_overwrite); | - | ||||||||||||||||||||||||
| 412 | if (datum){//actually emit(otherwise we've been asked to skip this one)
| 0-50448 | ||||||||||||||||||||||||
| 413 | qreal t = 1 - (pt - opt) / dt; | - | ||||||||||||||||||||||||
| 414 | qreal vx = | - | ||||||||||||||||||||||||
| 415 | - 2 * ax * (1 - t) | - | ||||||||||||||||||||||||
| 416 | + 2 * bx * (1 - 2 * t) | - | ||||||||||||||||||||||||
| 417 | + 2 * cx * t; | - | ||||||||||||||||||||||||
| 418 | qreal vy = | - | ||||||||||||||||||||||||
| 419 | - 2 * ay * (1 - t) | - | ||||||||||||||||||||||||
| 420 | + 2 * by * (1 - 2 * t) | - | ||||||||||||||||||||||||
| 421 | + 2 * cy * t; | - | ||||||||||||||||||||||||
| 422 | - | |||||||||||||||||||||||||
| 423 | - | |||||||||||||||||||||||||
| 424 | // Particle timestamp | - | ||||||||||||||||||||||||
| 425 | datum->t = pt; | - | ||||||||||||||||||||||||
| 426 | datum->lifeSpan = | - | ||||||||||||||||||||||||
| 427 | (m_particleDuration | - | ||||||||||||||||||||||||
| 428 | + (QRandomGenerator::global()->bounded((m_particleDurationVariation*2) + 1) - m_particleDurationVariation)) | - | ||||||||||||||||||||||||
| 429 | / 1000.0; | - | ||||||||||||||||||||||||
| 430 | - | |||||||||||||||||||||||||
| 431 | if (datum->lifeSpan >= m_system->maxLife){
| 0-50448 | ||||||||||||||||||||||||
| 432 | datum->lifeSpan = m_system->maxLife; | - | ||||||||||||||||||||||||
| 433 | if (m_emitCap == -1)
| 0 | ||||||||||||||||||||||||
| 434 | m_emitCap = particleCount(); never executed: m_emitCap = particleCount(); | 0 | ||||||||||||||||||||||||
| 435 | m_emitCap--;//emitCap keeps us from reemitting 'infinite' particles after their life. Unless you reset the emitter. | - | ||||||||||||||||||||||||
| 436 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 437 | - | |||||||||||||||||||||||||
| 438 | // Particle position | - | ||||||||||||||||||||||||
| 439 | QRectF boundsRect; | - | ||||||||||||||||||||||||
| 440 | if (!m_burstQueue.isEmpty()){
| 0-50448 | ||||||||||||||||||||||||
| 441 | boundsRect = QRectF(m_burstQueue.first().second.x() - x(), m_burstQueue.first().second.y() - y(), | - | ||||||||||||||||||||||||
| 442 | width(), height()); | - | ||||||||||||||||||||||||
| 443 | } else { never executed: end of block | 0 | ||||||||||||||||||||||||
| 444 | boundsRect = QRectF(emitter_x_offset + dex * (pt - opt) / dt, emitter_y_offset + dey * (pt - opt) / dt | - | ||||||||||||||||||||||||
| 445 | , width(), height()); | - | ||||||||||||||||||||||||
| 446 | } executed 50448 times by 23 tests: end of blockExecuted by:
| 50448 | ||||||||||||||||||||||||
| 447 | QPointF newPos = effectiveExtruder()->extrude(boundsRect); | - | ||||||||||||||||||||||||
| 448 | datum->x = newPos.x(); | - | ||||||||||||||||||||||||
| 449 | datum->y = newPos.y(); | - | ||||||||||||||||||||||||
| 450 | - | |||||||||||||||||||||||||
| 451 | // Particle velocity | - | ||||||||||||||||||||||||
| 452 | const QPointF &velocity = m_velocity->sample(newPos); | - | ||||||||||||||||||||||||
| 453 | datum->vx = velocity.x() | - | ||||||||||||||||||||||||
| 454 | + m_velocity_from_movement * vx; | - | ||||||||||||||||||||||||
| 455 | datum->vy = velocity.y() | - | ||||||||||||||||||||||||
| 456 | + m_velocity_from_movement * vy; | - | ||||||||||||||||||||||||
| 457 | - | |||||||||||||||||||||||||
| 458 | // Particle acceleration | - | ||||||||||||||||||||||||
| 459 | const QPointF &accel = m_acceleration->sample(newPos); | - | ||||||||||||||||||||||||
| 460 | datum->ax = accel.x(); | - | ||||||||||||||||||||||||
| 461 | datum->ay = accel.y(); | - | ||||||||||||||||||||||||
| 462 | - | |||||||||||||||||||||||||
| 463 | // Particle size | - | ||||||||||||||||||||||||
| 464 | float sizeVariation = -m_particleSizeVariation | - | ||||||||||||||||||||||||
| 465 | + QRandomGenerator::global()->bounded(m_particleSizeVariation * 2); | - | ||||||||||||||||||||||||
| 466 | - | |||||||||||||||||||||||||
| 467 | float size = qMax((qreal)0.0 , m_particleSize + sizeVariation); | - | ||||||||||||||||||||||||
| 468 | float endSize = qMax((qreal)0.0 , sizeAtEnd + sizeVariation); | - | ||||||||||||||||||||||||
| 469 | - | |||||||||||||||||||||||||
| 470 | datum->size = size;// * float(m_emitting); | - | ||||||||||||||||||||||||
| 471 | datum->endSize = endSize;// * float(m_emitting); | - | ||||||||||||||||||||||||
| 472 | - | |||||||||||||||||||||||||
| 473 | toEmit << datum; | - | ||||||||||||||||||||||||
| 474 | } executed 50448 times by 23 tests: end of blockExecuted by:
| 50448 | ||||||||||||||||||||||||
| 475 | if (m_burstQueue.isEmpty()){
| 0-50448 | ||||||||||||||||||||||||
| 476 | pt += particleRatio; | - | ||||||||||||||||||||||||
| 477 | }else{ executed 50448 times by 23 tests: end of blockExecuted by:
| 50448 | ||||||||||||||||||||||||
| 478 | m_burstQueue.first().first--; | - | ||||||||||||||||||||||||
| 479 | if (m_burstQueue.first().first <= 0)
| 0 | ||||||||||||||||||||||||
| 480 | m_burstQueue.pop_front(); never executed: m_burstQueue.pop_front(); | 0 | ||||||||||||||||||||||||
| 481 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 482 | } | - | ||||||||||||||||||||||||
| 483 | - | |||||||||||||||||||||||||
| 484 | foreach (QQuickParticleData* d, toEmit)
| 0-53683 | ||||||||||||||||||||||||
| 485 | m_system->emitParticle(d, this); executed 50448 times by 23 tests: m_system->emitParticle(d, this);Executed by:
| 50448 | ||||||||||||||||||||||||
| 486 | - | |||||||||||||||||||||||||
| 487 | if (isEmitConnected()) {
| 0-3235 | ||||||||||||||||||||||||
| 488 | QQmlEngine *qmlEngine = ::qmlEngine(this); | - | ||||||||||||||||||||||||
| 489 | QV4::ExecutionEngine *v4 = qmlEngine->handle(); | - | ||||||||||||||||||||||||
| 490 | QV4::Scope scope(v4); | - | ||||||||||||||||||||||||
| 491 | - | |||||||||||||||||||||||||
| 492 | //Done after emitParticle so that the Painter::load is done first, this allows you to customize its static variables | - | ||||||||||||||||||||||||
| 493 | //We then don't need to request another reload, because the first reload isn't scheduled until we get back to the render thread | - | ||||||||||||||||||||||||
| 494 | QV4::ScopedArrayObject array(scope, v4->newArrayObject(toEmit.size())); | - | ||||||||||||||||||||||||
| 495 | QV4::ScopedValue v(scope); | - | ||||||||||||||||||||||||
| 496 | for (int i=0; i<toEmit.size(); i++)
| 0 | ||||||||||||||||||||||||
| 497 | array->put(i, (v = toEmit[i]->v4Value(m_system))); never executed: array->put(i, (v = toEmit[i]->v4Value(m_system))); | 0 | ||||||||||||||||||||||||
| 498 | - | |||||||||||||||||||||||||
| 499 | emitParticles(QQmlV4Handle(array));//A chance for arbitrary JS changes | - | ||||||||||||||||||||||||
| 500 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 501 | - | |||||||||||||||||||||||||
| 502 | m_last_emission = pt; | - | ||||||||||||||||||||||||
| 503 | - | |||||||||||||||||||||||||
| 504 | m_last_last_last_emitter = m_last_last_emitter; | - | ||||||||||||||||||||||||
| 505 | m_last_last_emitter = m_last_emitter; | - | ||||||||||||||||||||||||
| 506 | m_last_emitter = QPointF(x(), y()); | - | ||||||||||||||||||||||||
| 507 | m_last_timestamp = time; | - | ||||||||||||||||||||||||
| 508 | } executed 3235 times by 23 tests: end of blockExecuted by:
| 3235 | ||||||||||||||||||||||||
| 509 | - | |||||||||||||||||||||||||
| 510 | - | |||||||||||||||||||||||||
| 511 | QT_END_NAMESPACE | - | ||||||||||||||||||||||||
| 512 | - | |||||||||||||||||||||||||
| 513 | #include "moc_qquickparticleemitter_p.cpp" | - | ||||||||||||||||||||||||
| Source code | Switch to Preprocessed file |