diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2026-08-25 00:41:17 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2026-08-25 00:41:17 -0700 |
| commit | da01c6e887d6865f0ad75c8dfe68bbad702afb99 (patch) | |
| tree | 113163d6dde8ed0e5ffa8c073ca46b46ed82319a /src | |
| parent | a779011b9048cdda04887c77e20ee8936f332a7a (diff) | |
tweaks
Diffstat (limited to 'src')
| -rw-r--r-- | src/content/entities/entity_bullet_emitter.rs | 6 | ||||
| -rw-r--r-- | src/content/vfx/mod.rs | 2 | ||||
| -rw-r--r-- | src/renderer/mod.rs | 2 | ||||
| -rw-r--r-- | src/sim/lib/force.rs | 6 | ||||
| -rw-r--r-- | src/sim/sim_manager/mod.rs | 4 |
5 files changed, 13 insertions, 7 deletions
diff --git a/src/content/entities/entity_bullet_emitter.rs b/src/content/entities/entity_bullet_emitter.rs index 3788dd9..7cb24a6 100644 --- a/src/content/entities/entity_bullet_emitter.rs +++ b/src/content/entities/entity_bullet_emitter.rs @@ -32,12 +32,12 @@ impl EntityBehaviour for BulletEmitterEntityBehaviour { self.shot_timer -= delta_time; if self.shot_timer <= 0.0 { - apply_bullet(ctx, from, target, 70); + let stopped_at = apply_bullet(ctx, from, target, 70); // 0.1 seconds to travel 200 cells - let lifetime = (target - from).length() / 1000.0; + let lifetime = (stopped_at - from).length() / 1000.0; ctx.vfx_writer.write_vfx_line(VfxLine::new( from, - target, + stopped_at, 1.3, VfxMaterialId::Tracer, lifetime, diff --git a/src/content/vfx/mod.rs b/src/content/vfx/mod.rs index 8843bf1..c02bea6 100644 --- a/src/content/vfx/mod.rs +++ b/src/content/vfx/mod.rs @@ -13,7 +13,7 @@ pub struct VfxMaterialDef { static MATERIALS: [VfxMaterialDef; 1] = [VfxMaterialDef { name: "Tracer", color: (0xFF, 0xAA, 0xAA, 0xFF), - length: 15.0, + length: 10.0, }]; impl VfxMaterialId { diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index c1b156e..133c132 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -867,7 +867,7 @@ impl RendererState { { puffin::profile_scope!("Upload entity cells"); // TODO optimize, this is very inefficient, just build it per frame with positions and skip the lookup? - self.renderer_rb_entities.drain(); + self.renderer_rb_entities.clear(); for entity in sim.entities.values() { // TODO add "needs texture update"? if let Some(cells) = &entity.data.cells { diff --git a/src/sim/lib/force.rs b/src/sim/lib/force.rs index d461589..e3150c0 100644 --- a/src/sim/lib/force.rs +++ b/src/sim/lib/force.rs @@ -100,12 +100,13 @@ pub fn apply_explosion( // TODO profile packing entity ID into cells? // TODO sink power in a radius around the impact // might improve performance by a lot if we don't have to raycast for hit entities -pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { +pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) -> Vec2 { let dda = AwDda::new(from, to); let mut p = power as i32; let dir = (to - from).normalize(); + let mut stopped_at = to; for collision in dda { if let Some(cell) = ctx .cell_manager @@ -124,6 +125,7 @@ pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { p -= m.density as i32; if p <= 0 { + stopped_at = collision.as_vec2(); break; } @@ -145,4 +147,6 @@ pub fn apply_bullet(ctx: &mut SimCtx, from: Vec2, to: Vec2, power: u32) { } } } + + stopped_at } diff --git a/src/sim/sim_manager/mod.rs b/src/sim/sim_manager/mod.rs index 8cb5eb3..8849a1d 100644 --- a/src/sim/sim_manager/mod.rs +++ b/src/sim/sim_manager/mod.rs @@ -276,8 +276,10 @@ impl SimManager { self.cell_manager = CellManager::from_default_size(); } if input_manager.pressed(Input::ClearEntities) { - let entities: Vec<EntityId> = self.entities.drain().map(|(id, _)| id).collect(); + // TODO drain doesn't work here? + let entities: Vec<EntityId> = self.entities.keys().cloned().collect(); entities.iter().for_each(|&id| self.destroy_entity(id)); + self.entities.clear(); } if input_manager.pressed(Input::ClearParticles) { self.particle_manager.particles = Vec::new(); |
