Problem
createBroadPhaseEcsSystem (src/physics/systems/broad-phase-ecs-system.ts or equivalent) performs a brute-force all-pairs AABB overlap test — a nested loop over every entity against every other entity. There is no spatial partitioning (grid, BVH, sweep-and-prune, etc).
Impact
Broad-phase cost grows quadratically with body count, so simulations will start dropping frames well before reaching even a few hundred dynamic bodies. This caps the scale of anything built with the physics module (crowds, particle-like rigid bodies, destructible terrain debris, etc).
Suggested fix
Introduce a spatial partitioning structure for the broad phase — a uniform/spatial hash grid is usually the simplest fit for a 2D engine like this, but a sweep-and-prune or BVH would also work. Should reduce average-case broad-phase cost to roughly O(n) for typically-distributed scenes while keeping the existing narrow-phase (SAT) and solver untouched.
Acceptance criteria
Problem
createBroadPhaseEcsSystem(src/physics/systems/broad-phase-ecs-system.tsor equivalent) performs a brute-force all-pairs AABB overlap test — a nested loop over every entity against every other entity. There is no spatial partitioning (grid, BVH, sweep-and-prune, etc).Impact
Broad-phase cost grows quadratically with body count, so simulations will start dropping frames well before reaching even a few hundred dynamic bodies. This caps the scale of anything built with the physics module (crowds, particle-like rigid bodies, destructible terrain debris, etc).
Suggested fix
Introduce a spatial partitioning structure for the broad phase — a uniform/spatial hash grid is usually the simplest fit for a 2D engine like this, but a sweep-and-prune or BVH would also work. Should reduce average-case broad-phase cost to roughly O(n) for typically-distributed scenes while keeping the existing narrow-phase (SAT) and solver untouched.
Acceptance criteria
stress-testdemo) shows improved frame time at high body counts