summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-02-28 08:17:02 +0100
committerGitHub <noreply@github.com>2017-02-28 08:17:02 +0100
commit0f8c6dd3822c38b8145f08265abb9eba479f4d15 (patch)
tree6d66a14c876c919041bfd3c58b1aac6fc4ea7184
parent8d7879e09a85aa8953f265366bb50d089a7c1d02 (diff)
parent67ef529113d59540a640659f0cce9adc0136ffb3 (diff)
downloadredot-engine-0f8c6dd3822c38b8145f08265abb9eba479f4d15.tar.gz
Merge pull request #7904 from tagcup/use_math_prng
Use the common PRNG in 2D particles code.
-rw-r--r--scene/2d/particles_2d.cpp24
-rw-r--r--scene/2d/particles_2d.h2
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;}
};