From 5e465c8b260b1c906809fd288a19780581ae54f0 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 18 Mar 2016 18:27:27 +0300 Subject: Reduce number of rand() calls in Particle::update (cherry picked from M+ commit cc6b5ebf94ad24180a4db69aa87cae07e3c876d2) --- src/particle.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/particle.cpp b/src/particle.cpp index 61290884..40a51888 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -136,9 +136,10 @@ bool Particle::update() if (mRandomness > 0) { - mVelocity.x += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; - mVelocity.y += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; - mVelocity.z += (rand()%mRandomness - rand()%mRandomness) / 1000.0f; + const int rand2 = mRandomness * 2; + mVelocity.x += (rand() % rand2 - mRandomness) / 1000.0f; + mVelocity.y += (rand() % rand2 - mRandomness) / 1000.0f; + mVelocity.z += (rand() % rand2 - mRandomness) / 1000.0f; } mVelocity.z -= mGravity; -- cgit v1.2.3-70-g09d2