diff options
author | Ferenc Arn <tagcup@yahoo.com> | 2017-02-27 15:12:58 -0600 |
---|---|---|
committer | Ferenc Arn <tagcup@yahoo.com> | 2017-02-27 15:36:17 -0600 |
commit | 67ef529113d59540a640659f0cce9adc0136ffb3 (patch) | |
tree | b351068814cbd90a63cf827a96180dc621814014 | |
parent | 6fb164b34470fe4ad4719f3807def33574e6151a (diff) |
Use the common PRNG in 2D particles code.
Replaces the custom PRNG used by 2D particles code with a wrapper for the PRNG located under core/math.
-rw-r--r-- | scene/2d/particles_2d.cpp | 24 | ||||
-rw-r--r-- | scene/2d/particles_2d.h | 2 |
2 files changed, 7 insertions, 19 deletions
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp index 88682c7278..2b39fefe03 100644 --- a/scene/2d/particles_2d.cpp +++ b/scene/2d/particles_2d.cpp @@ -228,21 +228,9 @@ ParticleAttractor2D::ParticleAttractor2D() { /****************************************/ -_FORCE_INLINE_ static float _rand_from_seed(uint32_t *seed) { - - uint32_t k; - uint32_t s = (*seed); - if (s == 0) - s = 0x12345987; - k = s / 127773; - s = 16807 * (s - k * 127773) - 2836 * k; - if (s < 0) - s += 2147483647; - (*seed) = s; - - float v=((float)((*seed) & 0xFFFFF))/(float)0xFFFFF; - v=v*2.0-1.0; - return v; +_FORCE_INLINE_ static float _rand_from_seed(uint64_t *seed) { + uint32_t r = Math::rand_from_seed(seed); + return 2.0f * (float)r / (float)Math::RANDOM_MAX - 1.0f; } void Particles2D::_process_particles(float p_delta) { @@ -349,7 +337,7 @@ void Particles2D::_process_particles(float p_delta) { } } p.seed=Math::rand() % 12345678; - uint32_t rand_seed=p.seed*(i+1); + uint64_t rand_seed=p.seed*(i+1); float angle = Math::deg2rad(param[PARAM_DIRECTION]+_rand_from_seed(&rand_seed)*param[PARAM_SPREAD]); @@ -378,7 +366,7 @@ void Particles2D::_process_particles(float p_delta) { if (!p.active) continue; - uint32_t rand_seed=p.seed*(i+1); + uint64_t rand_seed=p.seed*(i+1); Vector2 force; @@ -537,7 +525,7 @@ void Particles2D::_notification(int p_what) { else ptime=(1.0-ptime)+time_pos; - uint32_t rand_seed=p.seed*(i+1); + uint64_t rand_seed=p.seed*(i+1); Color color; diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h index a12683f376..c6ababe3be 100644 --- a/scene/2d/particles_2d.h +++ b/scene/2d/particles_2d.h @@ -127,7 +127,7 @@ private: Vector2 velocity; float rot; float frame; - uint32_t seed; + uint64_t seed; Particle() { active=false; seed=123465789; rot=0; frame=0;} }; |