From 0fc2680098ef85641f47978539488dfeefcc975d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Vald=C3=A9s?= Date: Thu, 27 Feb 2020 20:03:16 +0100 Subject: [PATCH] Made the rng persist from frame to frame, so particles don't spawn in the same place every time --- src/renderer/cursor_renderer/cursor_vfx.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/renderer/cursor_renderer/cursor_vfx.rs b/src/renderer/cursor_renderer/cursor_vfx.rs index 35882e8..faebbed 100644 --- a/src/renderer/cursor_renderer/cursor_vfx.rs +++ b/src/renderer/cursor_renderer/cursor_vfx.rs @@ -179,6 +179,7 @@ pub struct ParticleTrail { particles: Vec, previous_cursor_dest: Point, trail_mode: TrailMode, + rng: RngState, } impl ParticleTrail { @@ -187,6 +188,7 @@ impl ParticleTrail { particles: vec![], previous_cursor_dest: Point::new(0.0, 0.0), trail_mode: trail_mode.clone(), + rng: RngState::new(), } } @@ -236,8 +238,6 @@ impl CursorVfx for ParticleTrail { let prev_p = self.previous_cursor_dest; - let mut rng = RngState::new(); - for i in 0..particle_count { let t = i as f32 / (particle_count as f32); @@ -246,9 +246,9 @@ impl CursorVfx for ParticleTrail { let phase = t * 60.0; // TODO -- Hardcoded spiral curl Point::new(phase.sin(), phase.cos()) * 20.0 // TODO -- Hardcoded spiral outward speed } - TrailMode::Torpedo => rng.rand_dir_normalized() * 10.0, // TODO -- Hardcoded particle speed + TrailMode::Torpedo => self.rng.rand_dir_normalized() * 10.0, // TODO -- Hardcoded particle speed TrailMode::PixieDust => { - let base_dir = rng.rand_dir_normalized(); + let base_dir = self.rng.rand_dir_normalized(); let dir = Point::new(base_dir.x * 0.5, 0.4 + base_dir.y.abs()); dir * 30.0 // TODO -- hardcoded particle speed } @@ -259,7 +259,7 @@ impl CursorVfx for ParticleTrail { // Distribute particles along the travel distance, with a random offset to make it // look random - let pos = prev_p + travel * rng.next_f32(); + let pos = prev_p + travel * self.rng.next_f32(); self.add_particle(pos, speed, t * settings.vfx_particle_lifetime); }