refactor(simulation): address PR #72 review suggestions

- Hoshe #3: replace O(n²) Vec scan in fallback NPC assignment with
  BTreeSet; prevent same NPC assigned to two roles in one triangle
- Hoshe #4: add From impls for RoleId, TriangleId, StableId, and
  TriangleCrisisEventWire — eliminate fragile .0 access on newtypes
- Hoshe #5: consolidate near-identical unit tests with integration
  counterparts — keep only unique tests in #[cfg(test)] module
- Tyre #3: replace O(N*M) scan in apply_resolve_triangle with
  BTreeMap<TriangleId, Entity> index for O(1) per-command lookup
- Tyre #4: document &mut World on generate_intra_template_triangles
- Observer snapshot uses TriangleCrisisEventWire::from instead of
  manual field mapping

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-25 23:35:23 +01:00
co-authored by Claude Opus 4.6
parent 3a555a2eeb
commit d808d95659
4 changed files with 92 additions and 502 deletions
+1 -10
View File
@@ -393,16 +393,7 @@ pub fn compute_observer_snapshot(
let triangle_crisis_events = crisis_queue
.drain()
.into_iter()
.map(|e| TriangleCrisisEventWire {
triangle_id: e.triangle_id.0,
role_assignments: e
.role_assignments
.into_iter()
.map(|(role, sid)| (role.0, sid.0))
.collect(),
trigger_npc_id: e.trigger_npc.0,
tick: e.tick,
})
.map(TriangleCrisisEventWire::from)
.collect();
buffer.snapshot = Some(ObserverSnapshot {