chore(physics): post-19.5 housekeeping — physicLabel + ignoreGravity deprecation#1451
Merged
Conversation
…deprecation Three related cleanups against the merged 19.5 PhysicsAdapter API. physicLabel — adapter identity exposed via world.physic - `world.physic` used to always be `"builtin"` (or `"none"`) regardless of which adapter was wired in. User code that wanted to branch on the active physics had to import the concrete adapter class and `instanceof` it. New optional `PhysicsAdapter.physicLabel` field declares the adapter's short identifier — set to `"builtin"` on BuiltinAdapter and `"matter"` on MatterAdapter. `Application.resolvePhysicSetting` now reads the label and assigns it to `world.physic` so `app.world.physic === "matter"` works for branching without an import. Falls back to `"builtin"` for adapters predating the field. World.step gate fix - `if (this.physic === "builtin")` was acting as an "is physics enabled?" flag — worked previously only because the string was always `"builtin"` for any non-`"none"` case. Under the new labelling that comparison would have stopped stepping the simulation for non-builtin adapters. Now reads `if (this.physic !== "none")`. Other `=== "builtin"` checks in World (addBody/removeBody, quadtree refresh) are genuinely builtin-specific — they read honestly under the new labelling and stay unchanged. Body.ignoreGravity deprecation - Legacy boolean field that only BuiltinAdapter reads; MatterAdapter silently ignores it. Portable equivalent is `gravityScale = 0` (or `bodyDef.gravityScale = 0` / `body.setGravityScale(0)`). JSDoc now marks the field `@deprecated since 19.5.0` and points to the portable replacement. Both call sites keep the dual check for backward compat with code that sets `ignoreGravity = true` directly, with a comment flagging the redundancy. Body.update's falling/jumping state machine now also gates on `gravityScale !== 0` so floating bodies (constructed with `gravityScale: 0`) no longer get marked "falling" on side-on collisions — was a latent bug. CHANGELOG: added two new entries under 19.5 Fixed + one under Changed. Verified: - pnpm lint: exit 0 - pnpm test: 3486 passed, 12 skipped - pnpm --filter melonjs build: clean - pnpm --filter @melonjs/matter-adapter build: clean Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Post-19.5 housekeeping that exposes adapter identity through world.physic, fixes the World.step gate so it works under any adapter (not just builtin), and deprecates Body.ignoreGravity in favor of the portable gravityScale = 0.
Changes:
- Add optional
PhysicsAdapter.physicLabel, set to"builtin"onBuiltinAdapterand"matter"onMatterAdapter;Application.resolvePhysicSettingpropagates it toworld.physicwith a"builtin"fallback. - Change
World.stepgate fromphysic === "builtin"tophysic !== "none"so the simulation steps under any adapter. - JSDoc-deprecate
Body.ignoreGravity(recommendinggravityScale = 0) and extendBody.update's falling/jumping gate to also checkgravityScale !== 0.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/melonjs/src/physics/adapter.ts | Adds optional physicLabel to the PhysicsAdapter interface with usage docs. |
| packages/melonjs/src/physics/builtin/builtin-adapter.js | Declares physicLabel = "builtin" on the default adapter. |
| packages/melonjs/src/physics/world.js | Updates step gate to physic !== "none"; expands JSDoc on world.physic. |
| packages/melonjs/src/physics/builtin/body.js | Marks ignoreGravity @deprecated; gates falling-state update on gravityScale !== 0 too. |
| packages/melonjs/src/application/application.ts | Resolves legacyString from adapter.physicLabel with "builtin" fallback. |
| packages/matter-adapter/src/index.ts | Declares physicLabel = "matter" on MatterAdapter. |
| packages/melonjs/CHANGELOG.md | Documents the three housekeeping items under 19.5 Fixed/Changed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Folds three follow-ups into the housekeeping PR:
1. Documentation & Examples CI: build matter-adapter before examples.
The doc workflow built melonjs + debug-plugin + tiled-inflate-plugin
+ spine-plugin then `pnpm -F examples build`. Examples now import
from `@melonjs/matter-adapter` (platformer-matter + pool-matter)
and the workflow can't resolve the package without a prior build.
Failed once on master after the 19.5 merge; added the missing
`pnpm -F @melonjs/matter-adapter build` step.
2. Test coverage for `physicLabel` propagation:
- custom adapter with explicit `physicLabel` ⇒ world.physic
reflects it
- adapter predating the field (physicLabel undefined) ⇒ falls
back to "builtin"
3. Naming cleanups:
- `resolvePhysicSetting` returns `{ adapter, physicLabel }` (was
`{ adapter, legacyString }`). The variable is no longer a legacy
flag; it is the identifier.
- `ApplicationSettings.physic` JSDoc now lists all accepted shapes
and points at `physicLabel` for the user-facing branching pattern.
- Application constructor's `world.physic = …` comment rewritten
to match the new semantics.
Verified:
- pnpm lint: exit 0
- pnpm test: 3488 passed (2 new), 12 skipped
- both melonjs + matter-adapter builds clean
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Three related cleanups against the merged 19.5 PhysicsAdapter API (#1450).
1.
physicLabel— adapter identity exposed viaworld.physicworld.physicused to always be"builtin"(or"none") regardless of which adapter was wired in. Code that wanted to branch on the active physics had to import the concrete class andinstanceofit.New optional
PhysicsAdapter.physicLabelfield declares the adapter's short identifier:BuiltinAdapter.physicLabel = "builtin"MatterAdapter.physicLabel = "matter"Application.resolvePhysicSettingreads it and assigns toworld.physic, so user code can now branch on the value without imports:Falls back to
"builtin"for adapters predating the field — existing third-party adapters keep working.2.
World.stepgate fixThe conditional in
World.stepwas acting as an "is physics enabled?" flag:This worked previously only because
world.physicwas always"builtin"for any non-"none"case. Under the new labelling that comparison would have stopped stepping the simulation for matter and any third-party adapter. Now readsthis.physic !== "none".The other
=== "builtin"checks inWorld(addBody/removeBody's Body Set, the quadtree refresh inupdate) are genuinely builtin-specific — they read honestly under the new labelling and stay unchanged.3.
Body.ignoreGravitydeprecationLegacy boolean field that only BuiltinAdapter reads; MatterAdapter silently ignores it. Portable equivalent is
gravityScale = 0(orbodyDef.gravityScale = 0/body.setGravityScale(0)), which works on every adapter.@deprecated since 19.5.0and points at the portable replacement.BuiltinAdapter.applyGravity,Body.updatefalling-state machine) keep the dual check for backward compat —ignoreGravity = truestill works on builtin.Body.update's falling/jumping state machine now also gates ongravityScale !== 0so floating bodies (constructed withgravityScale: 0) no longer get markedfallingon a side-on collision. Latent bug surfaced while reviewing the deprecation.Test plan
pnpm lint: exit 0pnpm test: 3486 passed, 12 skipped (no behavior change)pnpm --filter melonjs build: cleanpnpm --filter @melonjs/matter-adapter build: cleanapp.world.physic === "matter"evaluates true at runtime under matterCHANGELOG
Two new bullets under 19.5 Fixed and one under Changed.
🤖 Generated with Claude Code