From 3f7de64e2e8acb6328925c7270391b90ec800208 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Thu, 27 Aug 2026 21:17:18 -0700 Subject: naive splashing --- src/sim/sim_manager/utils.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/sim/sim_manager') 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!! -- cgit v1.3.1