From b2476dcd53f0dea1e9eb38df5add3a771d64c4a1 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 24 Oct 2017 20:48:50 -0700 Subject: Revert "Use QRandomGenerator instead of q?rand" This reverts commit 8a7b80ebea1fa30d892028e34696890d3321e816. Let's just leave qtquick1 with the old qrand API. Change-Id: Icaa86fc7b54d4b368c0efffd14f0b39b77f17d30 Reviewed-by: Lars Knoll --- examples/declarative/demos/minehunt/minehunt.cpp | 7 ++++--- src/imports/particles/qdeclarativeparticles.cpp | 24 ++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/examples/declarative/demos/minehunt/minehunt.cpp b/examples/declarative/demos/minehunt/minehunt.cpp index 2ef4a9be..d9237eee 100644 --- a/examples/declarative/demos/minehunt/minehunt.cpp +++ b/examples/declarative/demos/minehunt/minehunt.cpp @@ -32,7 +32,7 @@ ****************************************************************************/ #include -#include +#include #include #include "minehunt.h" @@ -63,6 +63,7 @@ MinehuntGame::MinehuntGame() : numCols(9), numRows(9), playing(true), won(false) { setObjectName("mainObject"); + srand(QTime(0,0,0).secsTo(QTime::currentTime())); //initialize array for(int ii = 0; ii < numRows * numCols; ++ii) { @@ -82,8 +83,8 @@ void MinehuntGame::setBoard() int mines = nMines; remaining = numRows*numCols-mines; while ( mines ) { - int col = QRandomGenerator::bounded(numCols); - int row = QRandomGenerator::bounded(numRows); + int col = int((double(rand()) / double(RAND_MAX)) * numCols); + int row = int((double(rand()) / double(RAND_MAX)) * numRows); TileData* t = tile( row, col ); diff --git a/src/imports/particles/qdeclarativeparticles.cpp b/src/imports/particles/qdeclarativeparticles.cpp index 1bd6c8e0..0f5ee97d 100644 --- a/src/imports/particles/qdeclarativeparticles.cpp +++ b/src/imports/particles/qdeclarativeparticles.cpp @@ -38,12 +38,12 @@ #include #include -#include #include #include #include +#include #include #ifndef M_PI @@ -311,7 +311,7 @@ void QDeclarativeParticleMotionWander::advance(QDeclarativeParticle &p, int inte qreal xdiff = p.x_velocity - d->x_targetV; if ((xdiff > d->x_peak && d->x_var > 0.0) || (xdiff < -d->x_peak && d->x_var < 0.0)) { d->x_var = -d->x_var; - d->x_peak = _xvariance + _xvariance * QRandomGenerator::getReal(); + d->x_peak = _xvariance + _xvariance * qreal(qrand()) / RAND_MAX; } p.x_velocity += d->x_var * interval; } @@ -321,7 +321,7 @@ void QDeclarativeParticleMotionWander::advance(QDeclarativeParticle &p, int inte qreal ydiff = p.y_velocity - d->y_targetV; if ((ydiff > d->y_peak && d->y_var > 0.0) || (ydiff < -d->y_peak && d->y_var < 0.0)) { d->y_var = -d->y_var; - d->y_peak = _yvariance + _yvariance * QRandomGenerator::getReal(); + d->y_peak = _yvariance + _yvariance * qreal(qrand()) / RAND_MAX; } p.y_velocity += d->y_var * interval; } @@ -338,8 +338,8 @@ void QDeclarativeParticleMotionWander::created(QDeclarativeParticle &p) d->y_targetV = p.y_velocity; d->x_peak = _xvariance; d->y_peak = _yvariance; - d->x_var = _pace * QRandomGenerator::getReal() / 1000.0; - d->y_var = _pace * QRandomGenerator::getReal() / 1000.0; + d->x_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; + d->y_var = _pace * qreal(qrand()) / RAND_MAX / 1000.0; } } @@ -504,7 +504,7 @@ void QDeclarativeParticlesPrivate::tick(int time) if (emissionRate != -1){ qreal variance = 1.; if (emissionVariance > 0.){ - variance += QRandomGenerator::getReal() * emissionVariance * (QRandomGenerator::bounded(2)?-1.:1.); + variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); } qreal emission = emissionRate * (qreal(interval)/1000.); emission = emission * variance + emissionCarry; @@ -526,7 +526,7 @@ void QDeclarativeParticlesPrivate::tick(int time) }else{ qreal variance = 1.; if (emissionVariance > 0.){ - variance += QRandomGenerator::getReal() * emissionVariance * (QRandomGenerator::bounded(2)?-1.:1.); + variance += (qreal(qrand())/RAND_MAX) * emissionVariance * (qrand()%2?-1.:1.); } qreal workingEmission = bursts[i].second * (qreal(interval)/1000.); workingEmission *= variance; @@ -555,11 +555,11 @@ void QDeclarativeParticlesPrivate::createParticle(int time) { Q_Q(QDeclarativeParticles); QDeclarativeParticle p(time); - p.x = q->x() + q->width() * QRandomGenerator::getReal() - image.width()/2.0; - p.y = q->y() + q->height() * QRandomGenerator::getReal() - image.height()/2.0; + p.x = q->x() + q->width() * qreal(qrand()) / RAND_MAX - image.width()/2.0; + p.y = q->y() + q->height() * qreal(qrand()) / RAND_MAX - image.height()/2.0; p.lifeSpan = lifeSpan; if (lifeSpanDev) - p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * QRandomGenerator::getReal()); + p.lifeSpan += int(lifeSpanDev/2 - lifeSpanDev * qreal(qrand()) / RAND_MAX); p.fadeOutAge = p.lifeSpan - fadeOutDur; if (fadeInDur == 0.) { p.state= QDeclarativeParticle::Solid; @@ -567,12 +567,12 @@ void QDeclarativeParticlesPrivate::createParticle(int time) } qreal a = angle; if (angleDev) - a += angleDev/2 - angleDev * QRandomGenerator::getReal(); + a += angleDev/2 - angleDev * qreal(qrand()) / RAND_MAX; if (a > M_PI) a = a - 2 * M_PI; qreal v = velocity; if (velocityDev) - v += velocityDev/2 - velocityDev * QRandomGenerator::getReal(); + v += velocityDev/2 - velocityDev * qreal(qrand()) / RAND_MAX; p.x_velocity = v * fastCos(a); p.y_velocity = v * fastSin(a); particles.append(p); -- cgit v1.2.3