Skip to content

refactor: standardize Layer on class fields with grouped ordering#8649

Merged
willeastcott merged 7 commits into
mainfrom
refactor/layer-class-fields
Apr 24, 2026
Merged

refactor: standardize Layer on class fields with grouped ordering#8649
willeastcott merged 7 commits into
mainfrom
refactor/layer-class-fields

Conversation

@willeastcott
Copy link
Copy Markdown
Contributor

@willeastcott willeastcott commented Apr 24, 2026

Summary

  • Standardizes Layer on class fields: every instance property is declared at the top of the class body with JSDoc and a default value (where appropriate), so the constructor no longer mixes class-field declarations with property initialization.
  • Reorders the class fields into labelled logical groups (identity, enabled state & ref counting, sorting, clear flags, enable/disable callbacks, mesh instances & shadow casters, lights, cameras, gsplat, composition / shader versioning, profiler).
  • Slims the constructor down to option-driven / runtime-only work: id allocation via layerCounter, copying values from options, and the initial onEnable() invocation.
  • Drops the dead if (options.renderTarget) { this.renderTarget = options.renderTarget; } block from the constructor. Layer#renderTarget is already registered as a removed property via _removedClassProperty(Layer, 'renderTarget') in src/deprecated/deprecated.js, and nothing in the engine reads layer.renderTarget, so the block only ever hit the deprecation setter and had no useful effect. The _removedClassProperty entry itself stays for engine v2 cleanup.

No behavioral changes.

The // #if _PROFILER guard now wraps only the five profiler fields.

Test plan

  • npm run build succeeds (class-field + // #if _PROFILER preprocessing).
  • npm test passes.
  • Manually verify a scene with multiple layers (including one created with explicit id, one disabled, and one with onEnable/onDisable) renders identically to main.

Declares every `Layer` instance property as a class field with JSDoc and
sensible defaults, and reorders them into labelled logical groups
(identity, enabled state, sorting, render target & clear flags,
callbacks, mesh instances, lights, cameras, gsplat, composition, and
profiler). The constructor is slimmed down to only option-driven /
runtime initialization. No behavioral changes.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors Layer to standardize instance properties as top-of-class fields with grouped ordering, keeping the constructor focused on option-driven initialization and runtime work.

Changes:

  • Promotes and groups Layer instance properties into ordered class fields with JSDoc and defaults where applicable.
  • Simplifies the constructor to primarily handle id allocation, option copying, and initial onEnable() call.
  • Narrows the // #if _PROFILER guard to only wrap profiler-related fields and adds a JSDoc @import for RenderTarget.

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

Comment thread src/scene/layer.js Outdated
Comment thread src/scene/layer.js
Comment thread src/scene/layer.js
…ation

Declaring `renderTarget` as a class field installs an own property on
every Layer instance, which shadows the `_removedClassProperty(Layer,
'renderTarget')` accessor on the prototype and silences the
"has been removed" warning. Drop the class-field declaration (and the
now-unused `@import { RenderTarget }`) and document the reason inline
so future refactors don't re-introduce the issue. The conditional
`this.renderTarget = options.renderTarget` in the constructor is
unchanged and now correctly falls through to the deprecation setter.

Made-with: Cursor
The comment explaining why `renderTarget` is deliberately not a class
field is more discoverable next to the actual `this.renderTarget =
options.renderTarget` assignment in the constructor than in the class
body. No behavioral change.

Made-with: Cursor
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.


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

Comment thread src/scene/layer.js Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 1 out of 1 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.

`Layer#renderTarget` is registered as a removed property in
`src/deprecated/deprecated.js` via `_removedClassProperty(Layer, 'renderTarget')`,
and nothing in the engine (src, examples, scripts, tests) ever reads
`layer.renderTarget`. The ctor block

    if (options.renderTarget) {
        this.renderTarget = options.renderTarget;
    }

therefore only ever hit the deprecation setter (logging an error and
discarding the value) and had no useful effect. Remove the block and the
now-orphaned explanatory comment. The `_removedClassProperty` entry in
`deprecated.js` stays for engine v2 cleanup, per maintainer request.

Made-with: Cursor
@willeastcott willeastcott merged commit aa8ef62 into main Apr 24, 2026
8 checks passed
@willeastcott willeastcott deleted the refactor/layer-class-fields branch April 24, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants