Box2DPhysicsSystem Class
Fixed-update system that drives Box2D simulation. Each step:
1. Tears down bodies for disabled entities (flushing their contact state).
2. Flushes contact/sensor state for bodies whose simulation was disabled this tick.
3. Syncs dirty PhysicsBodyComponent data → Box2D bodies/shapes.
4. Applies lightweight filter updates for layer/mask-only changes on live bodies.
5. Applies lightweight body-type changes via B2.BodySetType (no full rebuild).
6. Applies lightweight material updates (friction, restitution, hit-events) on live bodies.
7. Applies GravityOverride forces to dynamic bodies.
8. Pushes ECS transforms for kinematic bodies into Box2D (derives linear + angular velocity from displacement).
9. Syncs joint components → Box2D joints.
10. Installs or removes the system collision filter only when at least one body or sub-shape
has a ShouldCollide or
ShouldCollide predicate.
11. Steps the Box2D world.
12. Reads back body positions/rotations into ECS transforms.
13. Dispatches collision, sensor, hit, and sleep/wake events.
14. Checks joint break thresholds and fires OnBreak as needed.
public sealed class Box2DPhysicsSystem : Brine2D.ECS.Systems.FixedUpdateSystemBase, System.IDisposable
Inheritance System.Object → FixedUpdateSystemBase → Box2DPhysicsSystem
Implements System.IDisposable
| Methods | |
|---|---|
| DispatchSleepWakeEvents() | Polls awake state for all bodies that were sleeping after the previous step. Box2D only fires body move events for bodies that actually moved, so OnBodyWake would be delayed by one tick if we relied solely on move events to detect waking. Polling here ensures the event fires the same tick the body transitions to awake. |