feat(physics)!: free body construction + world.add/attach (B1, D1+D2)#156
Merged
Conversation
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`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 from00-refactor-spec).world.add(body)assigns ids + registers colliders + aggregates mass;idis-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).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/createColliderremoved.Verification (local, all green)
physics typecheck · full test suite (3354 passed, incl. full solver/dynamics matrix) · lint:packages · format:check