summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKai Stevenson <kai@kaistevenson.com>2026-08-23 17:53:46 -0700
committerKai Stevenson <kai@kaistevenson.com>2026-08-23 17:53:46 -0700
commit3c5b52c742a86dfb86238bad3bfc375bf12fc518 (patch)
tree93455692eb47164b1f7a96bf931fd10cf66e1959 /src
parent1e0ad48c47f0c4b3c2eadc19d65e20123b931023 (diff)
profiling, tweaks
Diffstat (limited to 'src')
-rw-r--r--src/main.rs6
-rw-r--r--src/sim/cell_manager/chunk.rs14
-rw-r--r--src/sim/rb_manager/mod.rs7
-rw-r--r--src/sim/sim_manager/mod.rs21
-rw-r--r--src/sim/sim_manager/utils.rs26
5 files changed, 50 insertions, 24 deletions
diff --git a/src/main.rs b/src/main.rs
index 967484f..81b5ee6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -186,12 +186,6 @@ impl ApplicationHandler for App {
let size = window.inner_size();
self.camera = Some(Camera::new((size.width as i32, size.height as i32)));
-
- // let surface = SurfaceTexture::new(size.width, size.height, window_ref);
-
- // let mut pixels = Pixels::new(PIXEL_BUFFER_WIDTH, PIXEL_BUFFER_HEIGHT, surface).unwrap();
-
- // pixels.set_scaling_mode(ScalingMode::Fill);
}
fn window_event(
diff --git a/src/sim/cell_manager/chunk.rs b/src/sim/cell_manager/chunk.rs
index f077233..cb31c3b 100644
--- a/src/sim/cell_manager/chunk.rs
+++ b/src/sim/cell_manager/chunk.rs
@@ -37,12 +37,14 @@ impl Chunk {
needs_texture_update: true,
};
- for x in 0..CHUNK_SIZE {
- c.set_cell_at_local_position(
- x as u8,
- CHUNK_SIZE as u8 - 1,
- Cell::from_material(MaterialId::Steel),
- );
+ for dy in 1..5 {
+ for x in 0..CHUNK_SIZE {
+ c.set_cell_at_local_position(
+ x as u8,
+ CHUNK_SIZE as u8 - dy,
+ Cell::from_material(MaterialId::Steel),
+ );
+ }
}
c
diff --git a/src/sim/rb_manager/mod.rs b/src/sim/rb_manager/mod.rs
index 2d95eb7..1a2abbf 100644
--- a/src/sim/rb_manager/mod.rs
+++ b/src/sim/rb_manager/mod.rs
@@ -118,8 +118,13 @@ impl RbManager {
marchable: &impl Marchable,
minimum_verts: Option<u32>,
) -> geometry::ColliderBuilder {
+ puffin::profile_function!();
let (vertices, indices) = RbManager::polyline_from_marchable(marchable, minimum_verts);
- geometry::ColliderBuilder::convex_decomposition(&vertices, &indices)
+ {
+ puffin::profile_scope!("Convex decomposition");
+ // TODO there are some pathological cases here that are taking 5ms+
+ geometry::ColliderBuilder::convex_decomposition(&vertices, &indices)
+ }
}
pub fn upsert_chunk_collider(&mut self, cx: i32, cy: i32, chunk: &Chunk) {
diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs
index 89ae528..8fab9cf 100644
--- a/src/sim/sim_manager/mod.rs
+++ b/src/sim/sim_manager/mod.rs
@@ -5,9 +5,10 @@ use fxhash::FxHashMap;
use crate::{
Config, InputManager,
config::{PHYSICS_DELTA_TIME, PHYSICS_FPS, SIM_FPS},
+ input::Input,
sim::{
cell_manager::manager::CellManager,
- entity::{Entity, EntityDef, EntityId, EntityUpdateResult},
+ entity::{Entity, EntityDef, EntityId},
particle_manager::ParticleManager,
rb_manager::RbManager,
sim_manager::utils::{
@@ -163,6 +164,24 @@ impl SimManager {
}
pub fn update(&mut self, config: &Config, input_manager: &InputManager, delta_time: f32) {
+ // handle sim controls
+ if input_manager.pressed(Input::Pause) {
+ self.paused = !self.paused;
+ }
+ if input_manager.pressed(Input::Step) {
+ self.ignore_pause_next_tick = true;
+ }
+ if input_manager.pressed(Input::ClearGrid) {
+ self.cell_manager = CellManager::from_default_size();
+ }
+ if input_manager.pressed(Input::ClearEntities) {
+ let entities: Vec<EntityId> = self.entities.drain().map(|(id, _)| id).collect();
+ entities.iter().for_each(|&id| self.destroy_entity(id));
+ }
+ if input_manager.pressed(Input::ClearParticles) {
+ self.particle_manager.particles = Vec::new();
+ }
+
let now = Instant::now();
let secs_since_last_cell_update = (now - self.last_cell_update).as_secs_f32();
let expected_secs_since_last_cell_update = 1.0 / SIM_FPS as f32;
diff --git a/src/sim/sim_manager/utils.rs b/src/sim/sim_manager/utils.rs
index e77f30a..f30e9a0 100644
--- a/src/sim/sim_manager/utils.rs
+++ b/src/sim/sim_manager/utils.rs
@@ -68,6 +68,7 @@ pub fn write_entities_to_world(
sim: &mut SimManager,
// (entity_x, entity_y, cell_x, cell_y)
) -> Vec<(EntityId, Vec<(u8, u8, i32, i32)>)> {
+ puffin::profile_function!();
// TODO optimize
let entity_ids: Vec<EntityId> = sim.entities.keys().copied().collect();
let mut cells_written_by_entity: Vec<(EntityId, Vec<(u8, u8, i32, i32)>)> = Vec::new();
@@ -85,6 +86,7 @@ pub fn read_back_entities_from_world(
sim: &mut SimManager,
cells_written_by_entity: Vec<(EntityId, Vec<(u8, u8, i32, i32)>)>,
) {
+ puffin::profile_function!();
for (entity_id, cells_written) in cells_written_by_entity {
let mut entity = sim.entities.get_mut(&entity_id);
let mut should_update_entity = false;
@@ -115,19 +117,23 @@ pub fn read_back_entities_from_world(
if let Some(entity) = &mut entity
&& should_update_entity
{
+ puffin::profile_scope!("Recompute collider");
if let Some(new_collider) = entity.compute_collider() {
- sim.rb_manager
- .physics_manager
- .world
- .remove_collider(entity.data.collider_h.unwrap());
+ {
+ puffin::profile_scope!("Upsert collider");
+ sim.rb_manager
+ .physics_manager
+ .world
+ .remove_collider(entity.data.collider_h.unwrap());
- let new_handle = sim
- .rb_manager
- .physics_manager
- .world
- .insert_collider(new_collider, Some(entity.data.rb_h.unwrap()));
+ let new_handle = sim
+ .rb_manager
+ .physics_manager
+ .world
+ .insert_collider(new_collider, Some(entity.data.rb_h.unwrap()));
- entity.data.collider_h = Some(new_handle);
+ entity.data.collider_h = Some(new_handle);
+ }
}
}
}