From cc6b5ebf94ad24180a4db69aa87cae07e3c876d2 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. --- src/particle/particle.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/particle/particle.cpp') diff --git a/src/particle/particle.cpp b/src/particle/particle.cpp index 425be6c91..aeb79a1b1 100644 --- a/src/particle/particle.cpp +++ b/src/particle/particle.cpp @@ -160,12 +160,13 @@ void Particle::updateSelf() restrict2 if (mRandomness > 0) { - mVelocity.x += static_cast((rand() % mRandomness - rand() - % mRandomness)) / 1000.0F; - mVelocity.y += static_cast((rand() % mRandomness - rand() - % mRandomness)) / 1000.0F; - mVelocity.z += static_cast((rand() % mRandomness - rand() - % mRandomness)) / 1000.0F; + const int rand2 = mRandomness * 2; + mVelocity.x += static_cast(rand() % rand2 - mRandomness) + / 1000.0F; + mVelocity.y += static_cast(rand() % rand2 - mRandomness) + / 1000.0F; + mVelocity.z += static_cast(rand() % rand2 - mRandomness) + / 1000.0F; } mVelocity.z -= mGravity; -- cgit v1.2.3-60-g2f50