aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@qt.io>2017-09-08 11:04:30 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2017-09-08 11:04:30 +0200
commitbde8c3cd9583ed9f3bdfc36a8699f56db20a6928 (patch)
tree33246b027739aafd72f9f289876f69627537f2b3 /src/particles
parentb63bc868875d7571bc332804f984824cff7c5b78 (diff)
parent685ad676a84bf48602a5da8f7171792686b94a73 (diff)
Merge remote-tracking branch 'origin/dev' into wip/new-backend
Conflicts: src/qml/compiler/qv4isel_moth.cpp src/qml/compiler/qv4jsir.cpp src/qml/jsruntime/qv4mathobject.cpp Change-Id: I426f1f4f0a5302b5bcff021de11766a03fec7637
Diffstat (limited to 'src/particles')
-rw-r--r--src/particles/qquickangledirection.cpp6
-rw-r--r--src/particles/qquickcustomparticle.cpp4
-rw-r--r--src/particles/qquickellipseextruder.cpp6
-rw-r--r--src/particles/qquickimageparticle.cpp13
-rw-r--r--src/particles/qquicklineextruder.cpp6
-rw-r--r--src/particles/qquickmaskextruder.cpp3
-rw-r--r--src/particles/qquickparticleemitter.cpp5
-rw-r--r--src/particles/qquickparticleextruder.cpp6
-rw-r--r--src/particles/qquickpointdirection.cpp6
-rw-r--r--src/particles/qquickrectangleextruder.cpp16
-rw-r--r--src/particles/qquicktargetdirection.cpp7
-rw-r--r--src/particles/qquicktrailemitter.cpp5
-rw-r--r--src/particles/qquickwander.cpp13
13 files changed, 51 insertions, 45 deletions
diff --git a/src/particles/qquickangledirection.cpp b/src/particles/qquickangledirection.cpp
index debf52e49b..11a007ca09 100644
--- a/src/particles/qquickangledirection.cpp
+++ b/src/particles/qquickangledirection.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qquickangledirection_p.h"
-#include <stdlib.h>
+#include <QRandomGenerator>
#include <qmath.h>
QT_BEGIN_NAMESPACE
@@ -108,8 +108,8 @@ QPointF QQuickAngleDirection::sample(const QPointF &from)
{
Q_UNUSED(from);
QPointF ret;
- qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2;
- qreal mag = m_magnitude- m_magnitudeVariation + rand()/float(RAND_MAX) * m_magnitudeVariation * 2;
+ qreal theta = m_angle*CONV - m_angleVariation*CONV + QRandomGenerator::getReal() * m_angleVariation*CONV * 2;
+ qreal mag = m_magnitude- m_magnitudeVariation + QRandomGenerator::getReal() * m_magnitudeVariation * 2;
ret.setX(mag * qCos(theta));
ret.setY(mag * qSin(theta));
return ret;
diff --git a/src/particles/qquickcustomparticle.cpp b/src/particles/qquickcustomparticle.cpp
index a9645461a5..a2bcd91167 100644
--- a/src/particles/qquickcustomparticle.cpp
+++ b/src/particles/qquickcustomparticle.cpp
@@ -38,10 +38,10 @@
****************************************************************************/
#include "qquickcustomparticle_p.h"
+#include <QtCore/qrandom.h>
#include <QtQuick/private/qquickshadereffectmesh_p.h>
#include <QtQuick/private/qsgshadersourcebuilder_p.h>
#include <QtQml/qqmlinfo.h>
-#include <cstdlib>
QT_BEGIN_NAMESPACE
@@ -425,7 +425,7 @@ void QQuickCustomParticle::buildData(QQuickOpenGLShaderEffectNode *rootNode)
void QQuickCustomParticle::initialize(int gIdx, int pIdx)
{
QQuickParticleData* datum = m_system->groupData[gIdx]->data[pIdx];
- datum->r = rand()/(qreal)RAND_MAX;
+ datum->r = QRandomGenerator::getReal();
}
void QQuickCustomParticle::commit(int gIdx, int pIdx)
diff --git a/src/particles/qquickellipseextruder.cpp b/src/particles/qquickellipseextruder.cpp
index bd3a95d684..fbb11b34cc 100644
--- a/src/particles/qquickellipseextruder.cpp
+++ b/src/particles/qquickellipseextruder.cpp
@@ -39,7 +39,7 @@
#include "qquickellipseextruder_p.h"
#include <qmath.h>
-#include <stdlib.h>
+#include <qrandom.h>
QT_BEGIN_NAMESPACE
/*!
@@ -68,8 +68,8 @@ QQuickEllipseExtruder::QQuickEllipseExtruder(QObject *parent) :
QPointF QQuickEllipseExtruder::extrude(const QRectF & r)
{
- qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862;
- qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1;
+ qreal theta = QRandomGenerator::bounded(2 * M_PI);
+ qreal mag = m_fill ? QRandomGenerator::getReal() : 1;
return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * qCos(theta),
r.y() + r.height()/2 + mag * (r.height()/2) * qSin(theta));
}
diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp
index 1b3d2eed6b..8f809176a9 100644
--- a/src/particles/qquickimageparticle.cpp
+++ b/src/particles/qquickimageparticle.cpp
@@ -44,6 +44,7 @@
#include <QtQuick/qsgtexturematerial.h>
#include <QtQuick/qsgtexture.h>
#include <QFile>
+#include <QRandomGenerator>
#include "qquickimageparticle_p.h"
#include "qquickparticleemitter_p.h"
#include <private/qquicksprite_p.h>
@@ -1729,9 +1730,9 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx)
if (!datum->rotationOwner)
datum->rotationOwner = this;
rotation =
- (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV;
+ (m_rotation + (m_rotationVariation - 2*QRandomGenerator::bounded(m_rotationVariation)) ) * CONV;
rotationVelocity =
- (m_rotationVelocity + (m_rotationVelocityVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVelocityVariation) ) * CONV;
+ (m_rotationVelocity + (m_rotationVelocityVariation - 2*QRandomGenerator::bounded(m_rotationVelocityVariation)) ) * CONV;
autoRotate = m_autoRotation?1.0:0.0;
if (datum->rotationOwner == this) {
datum->rotation = rotation;
@@ -1750,10 +1751,10 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx)
if (m_explicitColor) {
if (!datum->colorOwner)
datum->colorOwner = this;
- color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation;
- color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation;
- color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation;
- color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation;
+ color.r = m_color.red() * (1 - redVariation) + QRandomGenerator::bounded(256) * redVariation;
+ color.g = m_color.green() * (1 - greenVariation) + QRandomGenerator::bounded(256) * greenVariation;
+ color.b = m_color.blue() * (1 - blueVariation) + QRandomGenerator::bounded(256) * blueVariation;
+ color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + QRandomGenerator::bounded(256) * m_alphaVariation;
if (datum->colorOwner == this)
datum->color = color;
else
diff --git a/src/particles/qquicklineextruder.cpp b/src/particles/qquicklineextruder.cpp
index 4bcd63543c..6ebd728407 100644
--- a/src/particles/qquicklineextruder.cpp
+++ b/src/particles/qquicklineextruder.cpp
@@ -37,7 +37,7 @@
**
****************************************************************************/
#include "qquicklineextruder_p.h"
-#include <stdlib.h>
+#include <QRandomGenerator>
#include <cmath>
/*!
@@ -69,10 +69,10 @@ QPointF QQuickLineExtruder::extrude(const QRectF &r)
{
qreal x,y;
if (!r.height()){
- x = r.width() * ((qreal)rand())/RAND_MAX;
+ x = r.width() * QRandomGenerator::getReal();
y = 0;
}else{
- y = r.height() * ((qreal)rand())/RAND_MAX;
+ y = r.height() * QRandomGenerator::getReal();
if (!r.width()){
x = 0;
}else{
diff --git a/src/particles/qquickmaskextruder.cpp b/src/particles/qquickmaskextruder.cpp
index 93eaaf1a6f..60c23c55a8 100644
--- a/src/particles/qquickmaskextruder.cpp
+++ b/src/particles/qquickmaskextruder.cpp
@@ -42,6 +42,7 @@
#include <QtQml/qqmlinfo.h>
#include <QImage>
#include <QDebug>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
/*!
\qmltype MaskShape
@@ -102,7 +103,7 @@ QPointF QQuickMaskExtruder::extrude(const QRectF &r)
ensureInitialized(r);
if (!m_mask.count() || m_img.isNull())
return r.topLeft();
- const QPointF p = m_mask[rand() % m_mask.count()];
+ const QPointF p = m_mask[QRandomGenerator::bounded(m_mask.count())];
//### Should random sub-pixel positioning be added?
return p + r.topLeft();
}
diff --git a/src/particles/qquickparticleemitter.cpp b/src/particles/qquickparticleemitter.cpp
index 9bed25dba6..d18250d706 100644
--- a/src/particles/qquickparticleemitter.cpp
+++ b/src/particles/qquickparticleemitter.cpp
@@ -40,6 +40,7 @@
#include "qquickparticleemitter_p.h"
#include <private/qqmlengine_p.h>
#include <private/qqmlglobal_p.h>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
@@ -424,7 +425,7 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
datum->t = pt;
datum->lifeSpan =
(m_particleDuration
- + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation))
+ + (QRandomGenerator::bounded((m_particleDurationVariation*2) + 1) - m_particleDurationVariation))
/ 1000.0;
if (datum->lifeSpan >= m_system->maxLife){
@@ -461,7 +462,7 @@ void QQuickParticleEmitter::emitWindow(int timeStamp)
// Particle size
float sizeVariation = -m_particleSizeVariation
- + rand() / float(RAND_MAX) * m_particleSizeVariation * 2;
+ + QRandomGenerator::bounded(m_particleSizeVariation * 2);
float size = qMax((qreal)0.0 , m_particleSize + sizeVariation);
float endSize = qMax((qreal)0.0 , sizeAtEnd + sizeVariation);
diff --git a/src/particles/qquickparticleextruder.cpp b/src/particles/qquickparticleextruder.cpp
index f1fef58884..74b450921f 100644
--- a/src/particles/qquickparticleextruder.cpp
+++ b/src/particles/qquickparticleextruder.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qquickparticleextruder_p.h"
-#include <stdlib.h>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
@@ -59,8 +59,8 @@ QQuickParticleExtruder::QQuickParticleExtruder(QObject *parent) :
QPointF QQuickParticleExtruder::extrude(const QRectF &rect)
{
- return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
- ((qreal)rand() / RAND_MAX) * rect.height() + rect.y());
+ return QPointF(QRandomGenerator::getReal() * rect.width() + rect.x(),
+ QRandomGenerator::getReal() * rect.height() + rect.y());
}
bool QQuickParticleExtruder::contains(const QRectF &bounds, const QPointF &point)
diff --git a/src/particles/qquickpointdirection.cpp b/src/particles/qquickpointdirection.cpp
index 8d602204b5..7b5c9bada1 100644
--- a/src/particles/qquickpointdirection.cpp
+++ b/src/particles/qquickpointdirection.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qquickpointdirection_p.h"
-#include <stdlib.h>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
@@ -78,8 +78,8 @@ QQuickPointDirection::QQuickPointDirection(QObject *parent) :
QPointF QQuickPointDirection::sample(const QPointF &)
{
QPointF ret;
- ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2);
- ret.setY(m_y - m_yVariation + rand() / float(RAND_MAX) * m_yVariation * 2);
+ ret.setX(m_x - m_xVariation + QRandomGenerator::getReal() * m_xVariation * 2);
+ ret.setY(m_y - m_yVariation + QRandomGenerator::getReal() * m_yVariation * 2);
return ret;
}
diff --git a/src/particles/qquickrectangleextruder.cpp b/src/particles/qquickrectangleextruder.cpp
index cb166f1d50..6474f61630 100644
--- a/src/particles/qquickrectangleextruder.cpp
+++ b/src/particles/qquickrectangleextruder.cpp
@@ -38,7 +38,7 @@
****************************************************************************/
#include "qquickrectangleextruder_p.h"
-#include <stdlib.h>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
@@ -60,21 +60,21 @@ QQuickRectangleExtruder::QQuickRectangleExtruder(QObject *parent) :
QPointF QQuickRectangleExtruder::extrude(const QRectF &rect)
{
if (m_fill)
- return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
- ((qreal)rand() / RAND_MAX) * rect.height() + rect.y());
- int side = rand() % 4;
+ return QPointF(QRandomGenerator::getReal() * rect.width() + rect.x(),
+ QRandomGenerator::getReal() * rect.height() + rect.y());
+ int side = QRandomGenerator::bounded(4);
switch (side){//TODO: Doesn't this overlap the corners?
case 0:
return QPointF(rect.x(),
- ((qreal)rand() / RAND_MAX) * rect.height() + rect.y());
+ QRandomGenerator::getReal() * rect.height() + rect.y());
case 1:
return QPointF(rect.width() + rect.x(),
- ((qreal)rand() / RAND_MAX) * rect.height() + rect.y());
+ QRandomGenerator::getReal() * rect.height() + rect.y());
case 2:
- return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
+ return QPointF(QRandomGenerator::getReal() * rect.width() + rect.x(),
rect.y());
default:
- return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(),
+ return QPointF(QRandomGenerator::getReal() * rect.width() + rect.x(),
rect.height() + rect.y());
}
}
diff --git a/src/particles/qquicktargetdirection.cpp b/src/particles/qquicktargetdirection.cpp
index ee805b4e39..96b78a53b4 100644
--- a/src/particles/qquicktargetdirection.cpp
+++ b/src/particles/qquicktargetdirection.cpp
@@ -41,6 +41,7 @@
#include "qquickparticleemitter_p.h"
#include <cmath>
#include <QDebug>
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
/*!
@@ -117,10 +118,10 @@ QPointF QQuickTargetDirection::sample(const QPointF &from)
targetX = m_targetX;
targetY = m_targetY;
}
- targetX += 0 - from.x() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2;
- targetY += 0 - from.y() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2;
+ targetX += 0 - from.x() - m_targetVariation + QRandomGenerator::getReal() * m_targetVariation*2;
+ targetY += 0 - from.y() - m_targetVariation + QRandomGenerator::getReal() * m_targetVariation*2;
qreal theta = std::atan2(targetY, targetX);
- qreal mag = m_magnitude + rand()/(float)RAND_MAX * m_magnitudeVariation * 2 - m_magnitudeVariation;
+ qreal mag = m_magnitude + QRandomGenerator::getReal() * m_magnitudeVariation * 2 - m_magnitudeVariation;
if (m_proportionalMagnitude)
mag *= std::sqrt(targetX * targetX + targetY * targetY);
ret.setX(mag * std::cos(theta));
diff --git a/src/particles/qquicktrailemitter.cpp b/src/particles/qquicktrailemitter.cpp
index a5bf0e9d21..14075f6b23 100644
--- a/src/particles/qquicktrailemitter.cpp
+++ b/src/particles/qquicktrailemitter.cpp
@@ -40,6 +40,7 @@
#include "qquicktrailemitter_p.h"
#include <private/qqmlengine_p.h>
#include <private/qqmlglobal_p.h>
+#include <QRandomGenerator>
#include <cmath>
QT_BEGIN_NAMESPACE
@@ -207,7 +208,7 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
datum->t = pt;
datum->lifeSpan =
(m_particleDuration
- + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation))
+ + (QRandomGenerator::bounded((m_particleDurationVariation*2) + 1) - m_particleDurationVariation))
/ 1000.0;
// Particle position
@@ -240,7 +241,7 @@ void QQuickTrailEmitter::emitWindow(int timeStamp)
// Particle size
float sizeVariation = -m_particleSizeVariation
- + rand() / float(RAND_MAX) * m_particleSizeVariation * 2;
+ + QRandomGenerator::getReal() * m_particleSizeVariation * 2;
float size = qMax((qreal)0.0, m_particleSize + sizeVariation);
float endSize = qMax((qreal)0.0, sizeAtEnd + sizeVariation);
diff --git a/src/particles/qquickwander.cpp b/src/particles/qquickwander.cpp
index 099b453808..cfdede440b 100644
--- a/src/particles/qquickwander.cpp
+++ b/src/particles/qquickwander.cpp
@@ -39,6 +39,7 @@
#include "qquickwander_p.h"
#include "qquickparticlesystem_p.h"//for ParticlesVertices
+#include <QRandomGenerator>
QT_BEGIN_NAMESPACE
/*!
\qmltype Wander
@@ -102,8 +103,8 @@ WanderData* QQuickWanderAffector::getData(int idx)
d->y_vel = 0;
d->x_peak = m_xVariance;
d->y_peak = m_yVariance;
- d->x_var = m_pace * qreal(qrand()) / RAND_MAX;
- d->y_var = m_pace * qreal(qrand()) / RAND_MAX;
+ d->x_var = m_pace * QRandomGenerator::getReal();
+ d->y_var = m_pace * QRandomGenerator::getReal();
m_wanderData.insert(idx, d);
return d;
@@ -124,7 +125,7 @@ bool QQuickWanderAffector::affectParticle(QQuickParticleData* data, qreal dt)
if (m_xVariance != 0.) {
if ((d->x_vel > d->x_peak && d->x_var > 0.0) || (d->x_vel < -d->x_peak && d->x_var < 0.0)) {
d->x_var = -d->x_var;
- d->x_peak = m_xVariance + m_xVariance * qreal(qrand()) / RAND_MAX;
+ d->x_peak = m_xVariance + m_xVariance * QRandomGenerator::getReal();
}
d->x_vel += d->x_var * dt;
}
@@ -133,7 +134,7 @@ bool QQuickWanderAffector::affectParticle(QQuickParticleData* data, qreal dt)
if (m_yVariance != 0.) {
if ((d->y_vel > d->y_peak && d->y_var > 0.0) || (d->y_vel < -d->y_peak && d->y_var < 0.0)) {
d->y_var = -d->y_var;
- d->y_peak = m_yVariance + m_yVariance * qreal(qrand()) / RAND_MAX;
+ d->y_peak = m_yVariance + m_yVariance * QRandomGenerator::getReal();
}
d->y_vel += d->y_var * dt;
}
@@ -146,8 +147,8 @@ bool QQuickWanderAffector::affectParticle(QQuickParticleData* data, qreal dt)
p->y += dy;
return true;
*/
- qreal dx = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1);
- qreal dy = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1);
+ qreal dx = dt * m_pace * (2 * QRandomGenerator::getReal() - 1);
+ qreal dy = dt * m_pace * (2 * QRandomGenerator::getReal() - 1);
qreal newX, newY;
switch (m_affectedParameter){
case Position: