diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-27 21:17:18 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-27 21:17:18 -0700 |
| commit | 3f7de64e2e8acb6328925c7270391b90ec800208 (patch) | |
| tree | b9c85a8bed93559d6fe7543cd444ca791a79f19c /src/sim/sim_manager/utils.rs | |
| parent | b4d3e5d915195c6a4bef8f115b62656c5aa9d378 (diff) | |
naive splashing
Diffstat (limited to 'src/sim/sim_manager/utils.rs')
| -rw-r--r-- | src/sim/sim_manager/utils.rs | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/sim/sim_manager/utils.rs b/src/sim/sim_manager/utils.rs index d744ec0..0270cce 100644 --- a/src/sim/sim_manager/utils.rs +++ b/src/sim/sim_manager/utils.rs @@ -1,9 +1,10 @@ use glam::{IVec2, Vec2}; +use rand::random_range; use rapier2d::dynamics::RigidBodyBuilder; use crate::{ config::MIN_ENTITY_CELLS, - content::materials::MaterialId, + content::materials::{MaterialForm, MaterialId}, sim::{ cell::Cell, entity::{EntityCells, EntityDef, EntityId, EntityUpdateResult}, @@ -18,6 +19,7 @@ fn write_entity_to_world(sim: &mut SimManager, entity_id: EntityId) -> Vec<(u8, if let Some(entity) = sim.entities.get(&entity_id) && let Some(cells) = &entity.data.cells && let Some((pos, (cos, sin))) = entity.data._transform(&sim.rb_manager) + && let Some(linvel) = entity.data._linvel(&sim.rb_manager) { let (half_size_x, half_size_y) = ((cells.size.x / 2) as f32, (cells.size.y / 2) as f32); // half-extent of the rotated grid's axis-aligned bounding box, plus a cell of margin @@ -36,7 +38,6 @@ fn write_entity_to_world(sim: &mut SimManager, entity_id: EntityId) -> Vec<(u8, if let Some(cur_world_cell) = sim .cell_manager .get_cell_from_game_position(world_x, world_y) - && cur_world_cell.material == MaterialId::Void { // same as shader let d = (world_x as f32 + 0.5 - pos.x, world_y as f32 + 0.5 - pos.y); @@ -55,6 +56,19 @@ fn write_entity_to_world(sim: &mut SimManager, entity_id: EntityId) -> Vec<(u8, continue; } + if cur_world_cell.material.def().form == MaterialForm::Liquid { + sim.particle_manager.particles.push(Particle::new( + Vec2::new(world_x as f32, world_y as f32), + (-linvel / 2.0) + + Vec2::new(random_range(-25.5..25.5), random_range(3.5..12.5)), + cur_world_cell.material, + 3.5, + 0.06, + )) + } else if cur_world_cell.material != MaterialId::Void { + continue; + } + cell.match_parity(sim.cell_manager.seqno); // TODO: OPTIMIZE!! |
