diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 15:00:35 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 15:00:35 -0700 |
| commit | 1a515237afb7ad09353a65f5fbc6e98a7c29ce8e (patch) | |
| tree | 48cd4b4bcf8f8e357811f905f22607838d7c1f96 /src/sim/particle_sim | |
| parent | 6350e4ffca8ce1e46465284ef3d7559e0f40229b (diff) | |
sim manager refactor
Diffstat (limited to 'src/sim/particle_sim')
| -rw-r--r-- | src/sim/particle_sim/mod.rs | 85 | ||||
| -rw-r--r-- | src/sim/particle_sim/particle.rs | 21 |
2 files changed, 0 insertions, 106 deletions
diff --git a/src/sim/particle_sim/mod.rs b/src/sim/particle_sim/mod.rs deleted file mode 100644 index 84a728a..0000000 --- a/src/sim/particle_sim/mod.rs +++ /dev/null @@ -1,85 +0,0 @@ -use crate::{ - config::PIXELS_TO_METRES, - sim::{ - cell::{cell::Cell, materials::MaterialForm}, - cell_sim::world::World, - lib::ray::AwDda, - particle_sim::particle::Particle, - }, -}; - -pub mod particle; - -pub struct ParticleManager { - pub particles: Vec<Particle>, -} - -const PARTICLE_GRAVITY: f32 = 9.81 * PIXELS_TO_METRES; - -impl ParticleManager { - pub fn particle_tick(&mut self, world: &mut World, delta_time: f32) { - puffin::profile_function!(); - let mut i = 0; - 'outer: while i < self.particles.len() { - let p = &mut self.particles[i]; - - p.life -= delta_time; - if p.life <= 0.0 { - self.particles.swap_remove(i); - continue 'outer; - } - - p.velocity.y += PARTICLE_GRAVITY * delta_time; - let dt_velocity = p.velocity * delta_time; - - let mut dda = AwDda::new(p.position, p.position + dt_velocity); - - if let Some(mut prev) = dda.next() { - if let Some(cell) = world.get_cell_from_game_position(prev.x, prev.y) - && [ - MaterialForm::Solid, - MaterialForm::Powder, - MaterialForm::Liquid, - ] - .contains(&cell.material.def().form) - { - // the particle is already inside a collider, we should just kill it - self.particles.swap_remove(i); - continue 'outer; - } - - for next in dda { - if let Some(cell) = world.get_cell_from_game_position(next.x, next.y) - && [ - MaterialForm::Solid, - MaterialForm::Powder, - MaterialForm::Liquid, - ] - .contains(&cell.material.def().form) - { - // write ourselves to the board - world.set_cell_from_game_position( - prev.x, - prev.y, - Cell::from_material(p.material), - false, - ); - self.particles.swap_remove(i); - continue 'outer; - } - prev = next; - } - } - - // no collision, just move - p.position += dt_velocity; - i += 1; - } - } - - pub fn new() -> Self { - ParticleManager { - particles: Vec::new(), - } - } -} diff --git a/src/sim/particle_sim/particle.rs b/src/sim/particle_sim/particle.rs deleted file mode 100644 index cc7dd28..0000000 --- a/src/sim/particle_sim/particle.rs +++ /dev/null @@ -1,21 +0,0 @@ -use glam::Vec2; - -use crate::sim::cell::materials::MaterialId; - -pub struct Particle { - pub position: Vec2, - pub velocity: Vec2, - pub material: MaterialId, - pub life: f32, -} - -impl Particle { - pub fn new(position: Vec2, velocity: Vec2, material: MaterialId, life: f32) -> Self { - Particle { - position, - velocity, - material, - life, - } - } -} |
