Skip to content

feat(physics)!: free body construction + world.add/attach (B1, D1+D2)#156

Merged
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b1-physics-ctor
Jun 22, 2026
Merged

feat(physics)!: free body construction + world.add/attach (B1, D1+D2)#156
Exoridus merged 1 commit into
mainfrom
feat/v0.14-b1-physics-ctor

Conversation

@Exoridus

Copy link
Copy Markdown
Owner

B1 — Physics construction idiom (v0.14 wave 1, D1+D2)

Bodies/colliders are now constructed freely and joined to the world, matching the engine's new Sprite() + addChild() idiom — the original v0.14 trigger (D1/D2 from 00-refactor-spec).

const body = new PhysicsBody({ type: 'kinematic', position: new Vector(200, 400),
  colliders: [new Collider({ shape: new BoxShape(120, 16) })] });
world.add(body);
body.addCollider(new Collider({ shape: new CircleShape(8), offset: new Vector(60, 0) }));

const b2 = world.attach(sprite, { type: 'dynamic', shape: new CircleShape(16) });
  • world.add(body) assigns ids + registers colliders + aggregates mass; id is -1/unattached until then; double-add throws. Solver-critical ordering (link → single mass recompute over the full set → synchronise → register) preserved exactly from the old per-collider path. Id allocation stays synchronous; only the body-list push is deferred (event-callback-safe, as before).
  • world.attach(node, def) convenience: body + collider + bind in one call.
  • PhysicsBody.createCollider -> addCollider(Collider | ColliderOptions).
  • Removed createBody/createStaticCollider/StaticColliderOptions.

8 test files migrated; new tests cover free construction, double-add throw, attach moving a node.

BREAKING

new PhysicsBody(options) + world.add(body); createBody/createStaticCollider/StaticColliderOptions/createCollider removed.

Verification (local, all green)

physics typecheck · full test suite (3354 passed, incl. full solver/dynamics matrix) · lint:packages · format:check

Bodies and colliders are now constructed freely and joined to the world, matching
the engine's `new Sprite()` + `addChild()` idiom instead of world factories.

- `new PhysicsBody({ type, position, colliders: [...] })` + `world.add(body)`.
  Ids are assigned and colliders registered on `add()` (id `-1` / unattached
  until then; `add()` throws on double-add). The mass model is aggregated once
  over the full collider set and world geometry synchronised before registration
  — the same order the old per-collider create path used, so the solver never
  sees a stale centre of mass.
- `world.attach(node, { type, shape, ... })`: body + collider + bind in one call
  (Physics→Core binding direction unchanged).
- `PhysicsBody.createCollider(options)` -> `addCollider(Collider | ColliderOptions)`.
- Removed `world.createBody`/`world.createStaticCollider` (+ `StaticColliderOptions`);
  static bodies become `new PhysicsBody({ type: 'static', colliders: [...] })`.

id allocation stays synchronous and only the body-list push is deferred, keeping
the event-callback-safe semantics of the old factory. 8 test files migrated; new
tests cover free construction, double-add throwing, and attach moving a node.

BREAKING CHANGE: PhysicsBody is constructed with `new PhysicsBody(options)` (no
owner/id args) and added via `world.add(body)`. `world.createBody`,
`world.createStaticCollider`, `StaticColliderOptions` and
`PhysicsBody.createCollider` are removed (use `world.add`/`world.attach` and
`PhysicsBody.addCollider`).
@Exoridus Exoridus merged commit e9bb93a into main Jun 22, 2026
12 checks passed
@Exoridus Exoridus deleted the feat/v0.14-b1-physics-ctor branch June 22, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant