summaryrefslogtreecommitdiff
path: root/src/sim/sim_manager/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim/sim_manager/mod.rs')
-rw-r--r--src/sim/sim_manager/mod.rs49
1 files changed, 46 insertions, 3 deletions
diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs
index b2441ef..9ae66be 100644
--- a/src/sim/sim_manager/mod.rs
+++ b/src/sim/sim_manager/mod.rs
@@ -1,6 +1,7 @@
use std::time::Instant;
use fxhash::FxHashMap;
+use glam::Vec2;
use rand::random_range;
use crate::{
@@ -11,7 +12,7 @@ use crate::{
cell::Cell,
cell_manager::manager::CellManager,
entity::{Entity, EntityDef, EntityId},
- particle_manager::ParticleManager,
+ particle_manager::{ParticleManager, particle::Particle},
rb_manager::RbManager,
sim_manager::utils::{
process_entity_update_result, read_back_entities_from_world, write_entities_to_world,
@@ -97,9 +98,41 @@ impl SimManager {
}
}
+ pub fn atomize_entity(&mut self, id: EntityId) {
+ if let Some(entity) = self.entities.get(&id)
+ && let Some(cells) = &entity.data.cells
+ {
+ // TODO these unwraps exist because we don't have separate entity position from rb
+ let rb = self
+ .rb_manager
+ .physics_manager
+ .world
+ .bodies
+ .get(entity.data.rb_h.unwrap())
+ .unwrap();
+
+ for x in 0..cells.size.x {
+ for y in 0..cells.size.y {
+ let r = rb.position().transform_vector(
+ Vec2::new(x as f32, y as f32) - (cells.size / 2).as_vec2(),
+ );
+ self.particle_manager.particles.push(Particle::new(
+ rb.translation() + r,
+ rb.linvel(),
+ cells.cells[(x + y * cells.size.x) as usize].material,
+ 3.0,
+ 0.1,
+ ))
+ }
+ }
+
+ self.destroy_entity(id);
+ }
+ }
+
fn cell_update(&mut self, config: &Config, input_manager: &InputManager, delta_time: f32) {
// before we tick, write all the entities into the sim world
- let cells_written_by_entity = write_entities_to_world(self);
+ let written_entities_scope = write_entities_to_world(self);
// --TEST DRAWING--
if input_manager.lmb_held || input_manager.rmb_held {
@@ -136,6 +169,16 @@ impl SimManager {
}
}
+ if input_manager.pressed(Input::Action2) {
+ if let Some(entity_id) = written_entities_scope
+ .get_entity_id_at_position(input_manager.world_mouse_pos.round().as_ivec2())
+ {
+ self.atomize_entity(entity_id);
+ }
+ }
+
+ // TEST ATOMIZATION
+
// tick
self.cell_manager.tick(config.use_threading);
@@ -157,7 +200,7 @@ impl SimManager {
}
// after we tick, remove the written entity cells and update the entities
- read_back_entities_from_world(self, cells_written_by_entity);
+ read_back_entities_from_world(self, written_entities_scope);
}
fn physics_update(&mut self, input_manager: &InputManager, delta_time: f32) {