diff options
Diffstat (limited to 'src/sim')
| -rw-r--r-- | src/sim/entity/mod.rs | 10 | ||||
| -rw-r--r-- | src/sim/sim_manager/utils.rs | 18 |
2 files changed, 26 insertions, 2 deletions
diff --git a/src/sim/entity/mod.rs b/src/sim/entity/mod.rs index fda0a79..3f262cb 100644 --- a/src/sim/entity/mod.rs +++ b/src/sim/entity/mod.rs @@ -162,6 +162,16 @@ impl<'a> EntityUpdateCtx<'a> { } impl EntityData { + pub fn _linvel(&self, rb_manager: &RbManager) -> Option<Vec2> { + self.rb_h.and_then(|rb_h| { + rb_manager + .physics_manager + .world + .bodies + .get(rb_h) + .map(|rb| rb.linvel()) + }) + } pub fn _transform(&self, rb_manager: &RbManager) -> Option<(Vec2, (f32, f32))> { self.rb_h.and_then(|rb_h| { rb_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!! |
