Skip to content

refactor: Clean up vestigial Model plumbing on SpriteComponent#8674

Merged
willeastcott merged 9 commits into
mainfrom
remove-sprite-model
May 3, 2026
Merged

refactor: Clean up vestigial Model plumbing on SpriteComponent#8674
willeastcott merged 9 commits into
mainfrom
remove-sprite-model

Conversation

@willeastcott

@willeastcott willeastcott commented May 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Cleans up SpriteComponent's vestigial Model plumbing, fixes a layer-membership desync against BatchManager, fixes a pre-existing handler-name typo, and aligns the layer-membership API with RenderComponent.

Details

1. Remove unused _model field

SpriteComponent declared a _model = new Model() field and performed bookkeeping on it (setting graph, pushing the mesh instance, nulling it out on destroy), but nothing ever consumed it:

  • The sprite's single mesh instance is created against this._node directly, not _model.graph.
  • The legacy _showModel/_hideModel helpers add/remove [this._meshInstance] to/from layers directly, bypassing _model.meshInstances.
  • BatchManager's sprite path reads node.sprite._meshInstance, not _model.
  • No references to sprite._model or sprite.model exist anywhere (engine, tests, examples, editor, or any downstream repo).

The Model class is legacy; sprite was the one remaining component using it for no functional purpose.

2. Fix _inLayers desync against BatchManager

The legacy removeModelFromLayers() (called by BatchManager when a sprite is absorbed into a batch) removed the mesh instance from layers without clearing the membership flag. This caused two stale-state hazards:

  • When batchGroupId returned to -1, _addToLayers() early-outed because the flag was still true, leaving the sprite invisible.
  • _onLayerAdded would re-add the unbatched mesh to any newly added matching layer, racing the batch.

3. Fix _onLayersChanged handler-name typo

Pre-existing bug: _onLayersChanged was rebinding this.onLayerAdded / this.onLayerRemoved (no underscore) but the actual methods are _onLayerAdded / _onLayerRemoved. Replacing the scene's layers component silently failed to rebind the listeners (and would assert in debug builds).

4. Align layer-membership API with RenderComponent

With the Model plumbing gone, the symbols are renamed and the BatchManager hook is unified with the existing RenderComponent pattern:

Before After
_addedModel (private field) _inLayers (private field)
_showModel() (private method) addToLayers() (@private JSDoc)
_hideModel() (private method) removeFromLayers() (@private JSDoc)
removeModelFromLayers() (undocumented, BatchManager-only) removed

BatchManager._extractSprites now calls node.sprite.removeFromLayers() directly — the same shape it already uses for node.render.removeFromLayers(). Because that path goes through removeFromLayers(), _inLayers stays in sync, the _meshInstance null guard is inherited, and the desync described in (2) is eliminated.

removeModelFromLayers() was undocumented and only ever called by BatchManager (the engine's own internal infrastructure), so it's removed outright rather than carried as a deprecated alias.

ModelComponent and ElementComponent still expose the legacy addModelToLayers / removeModelFromLayers pair; aligning those is left for a follow-up.

5. Minor type annotations

_meshInstance and _autoPlayClip got proper @type annotations (MeshInstance|null and string|null).

Test plan

  • npm run lint — clean.
  • BatchManager + sprite-related tests pass locally.

SpriteComponent declared a _model = new Model() field and performed bookkeeping on it, but nothing ever consumed it. The sprite's single mesh instance is created against _node directly, _showModel/_hideModel use [_meshInstance] directly (not _model.meshInstances), and BatchManager's sprite path reads _meshInstance too. No references to sprite._model or sprite.model exist anywhere.

Co-authored-by: Cursor <cursoragent@cursor.com>
…mponent

Rename private legacy-named state and methods in SpriteComponent to reflect what they actually do (managing mesh instance membership in scene layers): _addedModel -> _inLayers, _showModel -> _addToLayers, _hideModel -> _removeFromLayers. The names were holdovers from when SpriteComponent owned a Model container (removed in #8674).

Co-authored-by: Cursor <cursoragent@cursor.com>
@willeastcott willeastcott changed the title refactor: Remove vestigial _model field from SpriteComponent refactor: Clean up vestigial Model plumbing on SpriteComponent May 3, 2026
@willeastcott willeastcott requested a review from Copilot May 3, 2026 17:39
@willeastcott willeastcott self-assigned this May 3, 2026
@willeastcott willeastcott added the enhancement Request for a new feature label May 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors SpriteComponent to remove legacy Model usage that was no longer functionally used, and renames internal layer-membership helpers to reflect their actual responsibility (adding/removing the sprite mesh instance to/from scene layers).

Changes:

  • Remove the unused Model instance and associated bookkeeping from SpriteComponent.
  • Rename internal layer membership state / helpers (_addedModel_inLayers, _showModel/_hideModel_addToLayers/_removeFromLayers).
  • Update SpriteAnimationClip call sites to use the renamed helpers.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/framework/components/sprite/sprite-animation-clip.js Updates internal calls to the renamed SpriteComponent layer-membership helpers.
src/framework/components/sprite/component.js Removes vestigial Model plumbing, renames private state/methods around layer membership, and updates all internal call sites accordingly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/framework/components/sprite/component.js Outdated
Comment thread src/framework/components/sprite/component.js Outdated
Comment thread src/framework/components/sprite/component.js Outdated
willeastcott and others added 2 commits May 3, 2026 18:47
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
removeModelFromLayers (called by BatchManager when a sprite is absorbed
into a batch) was removing the mesh instance from layers without
clearing the new _inLayers flag. That left two stale-state hazards:

- When batchGroupId was set back to -1, _addToLayers early-outed because
  _inLayers was still true, so the sprite never re-appeared.
- _onLayerAdded would re-add the unbatched mesh instance to any newly
  added matching layer behind the batch's back.

Delegate removeModelFromLayers to _removeFromLayers so the flag (and
the _meshInstance null guard) stay consistent. Also reword a stale
"hide the model" comment.

Co-authored-by: Cursor <cursoragent@cursor.com>
…nent

Renames the internal `_addToLayers` / `_removeFromLayers` to public-but-
private `addToLayers` / `removeFromLayers` (with `@private` JSDoc), and
removes the `removeModelFromLayers` wrapper. BatchManager now calls
`node.sprite.removeFromLayers()` directly, matching the shape it already
uses for `node.render.removeFromLayers()`.

This drops the last vestigial `Model` reference from SpriteComponent and
unifies the convention with RenderComponent, leaving ModelComponent and
ElementComponent (which still use `addModelToLayers` / `removeModelFromLayers`)
as the only outliers - those can be aligned in a follow-up.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/framework/components/sprite/component.js Outdated
Comment thread src/scene/batching/batch-manager.js
- Fix _onLayersChanged binding the wrong handler names. The off/on calls
  referenced `this.onLayerAdded` / `this.onLayerRemoved` but the methods
  are `_onLayerAdded` / `_onLayerRemoved` (matching how onEnable wires
  them up). Replacing the scene's layers component would silently fail
  to rebind the listeners (and assert in debug builds).
- Re-add `removeModelFromLayers()` as a deprecated alias that delegates
  to `removeFromLayers()`, per the engine's API stability rules.
- Type `_autoPlayClip` as `string|null`.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@willeastcott willeastcott merged commit dc9f59d into main May 3, 2026
12 checks passed
@willeastcott willeastcott deleted the remove-sprite-model branch May 3, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Request for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants