diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 13:54:00 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-22 13:54:00 -0700 |
| commit | 6350e4ffca8ce1e46465284ef3d7559e0f40229b (patch) | |
| tree | 597bd17cc5c86d7271fea5abba4495fb58b4d7c2 /src/sim/particle_sim | |
| parent | 21f6ee0be48f83db3a0052269cfc47ac73dc64f9 (diff) | |
fixes and refactors
Diffstat (limited to 'src/sim/particle_sim')
| -rw-r--r-- | src/sim/particle_sim/mod.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/sim/particle_sim/mod.rs b/src/sim/particle_sim/mod.rs index 4378d25..84a728a 100644 --- a/src/sim/particle_sim/mod.rs +++ b/src/sim/particle_sim/mod.rs @@ -1,12 +1,7 @@ -use glam::{IVec2, Vec2}; - use crate::{ config::PIXELS_TO_METRES, sim::{ - cell::{ - cell::Cell, - materials::{MaterialForm, MaterialId}, - }, + cell::{cell::Cell, materials::MaterialForm}, cell_sim::world::World, lib::ray::AwDda, particle_sim::particle::Particle, @@ -23,6 +18,7 @@ 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]; @@ -36,22 +32,30 @@ impl ParticleManager { p.velocity.y += PARTICLE_GRAVITY * delta_time; let dt_velocity = p.velocity * delta_time; - let mut dda = AwDda::new(p.position, p.position + p.velocity * delta_time); + let mut dda = AwDda::new(p.position, p.position + dt_velocity); - if let Some(prev) = dda.next() { + 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] - .contains(&cell.material.def().form) + && [ + 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 cell in dda.map(|p| world.get_cell_from_game_position(p.x, p.y)) { - if let Some(cell) = cell - && [MaterialForm::Solid, MaterialForm::Powder] - .contains(&cell.material.def().form) + 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( @@ -63,11 +67,12 @@ impl ParticleManager { self.particles.swap_remove(i); continue 'outer; } + prev = next; } } // no collision, just move - p.position = p.position + dt_velocity; + p.position += dt_velocity; i += 1; } } |
