castle-web-cli 0.4.232 → 0.4.233
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +5 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/decor.js +509 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +82 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +74 -4
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,845 @@
|
|
|
1
|
+
// Real scene runtime and actor sync; importing static-scenery installs the
|
|
2
|
+
// same Node resolver and browser/rapier stubs the existing kit tests use.
|
|
3
|
+
// SKIP_EMPTY_BASELINE=<original world3d.js> also compares the pre-change
|
|
4
|
+
// implementation frame for frame (used when validating this change).
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import { performance } from 'node:perf_hooks';
|
|
8
|
+
import * as THREE from 'three';
|
|
9
|
+
import { makeWorld } from './test-static-passes.mjs';
|
|
10
|
+
await import('./test-static-scenery.mjs');
|
|
11
|
+
const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
|
|
12
|
+
const { syncActors, syncGround, updatePhysicsDebug, resizeWorld, renderWorld, disposeWorld } = await import('../engine3d/world3d.js');
|
|
13
|
+
const { drawn } = await import('./test-drop-empty-parts.mjs');
|
|
14
|
+
const { prepareEmptyNodes, forgetEmptyNodes, loadEmptyScene } = await import('../engine3d/emptynodes.js');
|
|
15
|
+
const { isFrozen } = await import('../engine3d/actornode.js');
|
|
16
|
+
const { setLookEnabled } = await import('../engine3d/look.js');
|
|
17
|
+
const { makeLevers, classify } = await import('../../hub-game/code/client/tiers.js');
|
|
18
|
+
|
|
19
|
+
let checks = 0;
|
|
20
|
+
function equal(a, b, message) {
|
|
21
|
+
checks++;
|
|
22
|
+
assert.deepEqual(a, b, message);
|
|
23
|
+
}
|
|
24
|
+
const MODEL = 'models/box.pxmodel';
|
|
25
|
+
const NOTHING = 'models/nothing.pxmodel';
|
|
26
|
+
const files = {
|
|
27
|
+
[MODEL]: JSON.stringify({ format: 'pxmodel', look: false, parts: [{ id: 'box', kind: 'box', size: [1, 1, 1], color: '#8899aa' }] }),
|
|
28
|
+
[NOTHING]: JSON.stringify({ format: 'pxmodel', look: false, parts: [] }),
|
|
29
|
+
};
|
|
30
|
+
function actor(id, components = {}) {
|
|
31
|
+
return { id, static: true, components: { Transform: { x: 3, y: 2, z: -4, rotationX: 0, rotationY: 30, rotationZ: 0 }, ...components } };
|
|
32
|
+
}
|
|
33
|
+
const shape = () => ({ kind: 'box', width: 1, height: 2, depth: 1, color: '#8899aa' });
|
|
34
|
+
function cast() {
|
|
35
|
+
return [actor('marker'), actor('missing', { Model: { file: 'missing.pxmodel' } }), actor('invalid', { Model: { file: 'invalid.pxmodel' } }),
|
|
36
|
+
actor('shape', { Shape: shape() }), actor('model', { Model: { file: MODEL } }), actor('nothing', { Model: { file: NOTHING } })];
|
|
37
|
+
}
|
|
38
|
+
function side(engine = {}, actors = cast(), sync = syncActors) {
|
|
39
|
+
const table = { ...files, 'invalid.pxmodel': 'not json' };
|
|
40
|
+
const data = { name: 'Square', engine, ground: { color: '#445566' }, actors };
|
|
41
|
+
const runtime = new SceneRuntime(data, [], {}, table, 'scenes/main.scene');
|
|
42
|
+
const world = makeWorld();
|
|
43
|
+
runtime.three = world;
|
|
44
|
+
if (runtime.skipsEmptyNodes) prepareEmptyNodes(world, runtime);
|
|
45
|
+
return { world, runtime, sync };
|
|
46
|
+
}
|
|
47
|
+
// Mirrors Scene3DPlayer: runtime.load resets the old mode; only the player
|
|
48
|
+
// arms the completed new scene, never a system afterLoad or an actor sync.
|
|
49
|
+
function load(s, data) {
|
|
50
|
+
if (s.world.emptyNodesOwned) loadEmptyScene(s.world, s.runtime, runtime => runtime.load(data));
|
|
51
|
+
else s.runtime.load(data);
|
|
52
|
+
if (s.runtime.skipsEmptyNodes) prepareEmptyNodes(s.world, s.runtime);
|
|
53
|
+
}
|
|
54
|
+
function frame(s) {
|
|
55
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
56
|
+
// Builds and model replacements classify at the next sync boundary.
|
|
57
|
+
if (s.world.emptyNodes?.dirty.size) s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
58
|
+
s.world.scene.updateMatrixWorld();
|
|
59
|
+
}
|
|
60
|
+
function attached(s, id) { return s.world.nodes.get(id).node.parent === s.world.scene; }
|
|
61
|
+
function tree(node) {
|
|
62
|
+
return [node.type, node.userData.actorId ?? null, node.children.map(tree)];
|
|
63
|
+
}
|
|
64
|
+
function state(s) {
|
|
65
|
+
return {
|
|
66
|
+
tree: tree(s.world.scene),
|
|
67
|
+
drawn: drawn(s.world),
|
|
68
|
+
entries: [...s.world.nodes].map(([id, e]) => ({ id, keys: Object.keys(e), sig: e.sig, children: e.node.children.length,
|
|
69
|
+
attached: e.node.parent === s.world.scene, matrix: e.node.matrixWorld.toArray(), parts: [...(e.node.userData.modelParts?.keys() ?? [])] })),
|
|
70
|
+
models: [...s.world.models].map(([key, e]) => [key, e.users]),
|
|
71
|
+
objects: Object.keys(s.world),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
let baseline = null;
|
|
75
|
+
if (process.env.SKIP_EMPTY_BASELINE) {
|
|
76
|
+
let source = fs.readFileSync(process.env.SKIP_EMPTY_BASELINE, 'utf8');
|
|
77
|
+
source = source.replace(/from (['"])(\.\/[^'"]+|@imports\/castle.physics-2d\/[^'"]+)\1/g, (_all, quote, spec) => {
|
|
78
|
+
let url = spec.startsWith('./') ? new URL(spec, new URL('../engine3d/world3d.js', import.meta.url)) :
|
|
79
|
+
new URL('../../physics-2d/' + spec.slice('@imports/castle.physics-2d/'.length), import.meta.url);
|
|
80
|
+
if (!url.pathname.endsWith('.js')) url = new URL(url.href + '.js');
|
|
81
|
+
return `from ${quote}${url.href}${quote}`;
|
|
82
|
+
});
|
|
83
|
+
source = source.replace(/from (['"])(three[^'"]*)\1/g, (_all, quote, spec) => `from ${quote}${import.meta.resolve(spec)}${quote}`);
|
|
84
|
+
baseline = (await import(`data:text/javascript,${encodeURIComponent(source)}`)).syncActors;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let MainSceneRuntime = SceneRuntime;
|
|
88
|
+
if (process.env.SKIP_EMPTY_RUNTIME_BASELINE) {
|
|
89
|
+
const source = fs.readFileSync(process.env.SKIP_EMPTY_RUNTIME_BASELINE, 'utf8').replace(
|
|
90
|
+
/from (['"])(\.\/[^'"]+)\1/g, (_all, quote, spec) => {
|
|
91
|
+
let url = new URL(spec, new URL('../../physics-2d/engine/scene.js', import.meta.url));
|
|
92
|
+
if (!url.pathname.endsWith('.js')) url = new URL(url.href + '.js');
|
|
93
|
+
return `from ${quote}${url.href}${quote}`;
|
|
94
|
+
});
|
|
95
|
+
MainSceneRuntime = (await import(`data:text/javascript,${encodeURIComponent(source)}`)).SceneRuntime;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Invariant 1 / review P1: the player never prepares a keyless runtime.
|
|
99
|
+
// Compare systems/listeners and own method descriptors with a runtime/world
|
|
100
|
+
// that has never gone through the feature's player load boundary (main).
|
|
101
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
102
|
+
const plain = side(mode);
|
|
103
|
+
const reference = new MainSceneRuntime(plain.runtime.data, [], {}, files, 'scenes/main.scene');
|
|
104
|
+
equal(reference.systems.length, 0, 'pre-feature runtime has zero systems');
|
|
105
|
+
equal(plain.runtime.systems.length, reference.systems.length, 'keyless systems equal main (zero)');
|
|
106
|
+
equal(plain.world.scene._listeners, makeWorld().scene._listeners, 'keyless scene listener count equals main');
|
|
107
|
+
equal(Object.hasOwn(plain.world.scene, 'dispatchEvent'), false);
|
|
108
|
+
equal(plain.world.emptyNodes, undefined, 'keyless allocates no mode record');
|
|
109
|
+
let getterCalls = 0;
|
|
110
|
+
Object.defineProperty(plain.runtime, 'skipsEmptyNodes', { configurable: true, get() { getterCalls++; return false; } });
|
|
111
|
+
frame(plain);
|
|
112
|
+
plain.runtime.update(1 / 60);
|
|
113
|
+
equal(getterCalls, 0, 'keyless sync/update never reads runtime.skipsEmptyNodes');
|
|
114
|
+
delete plain.runtime.skipsEmptyNodes;
|
|
115
|
+
for (const { node } of plain.world.nodes.values()) {
|
|
116
|
+
equal(node._listeners, undefined);
|
|
117
|
+
equal(Object.hasOwn(node, 'dispatchEvent'), false);
|
|
118
|
+
}
|
|
119
|
+
// A keyless -> keyed load arms only at the player boundary, after actors
|
|
120
|
+
// and config are complete. Syncs cannot arm before it or after reset.
|
|
121
|
+
plain.runtime.load({ ...plain.runtime.data, engine: { ...mode, skipEmptyNodes: true } });
|
|
122
|
+
plain.sync(plain.world, plain.runtime, {});
|
|
123
|
+
equal(plain.runtime.systems.length, 0);
|
|
124
|
+
equal(plain.world.emptyNodes, undefined);
|
|
125
|
+
prepareEmptyNodes(plain.world, plain.runtime);
|
|
126
|
+
equal(plain.runtime.systems.length, 1);
|
|
127
|
+
frame(plain);
|
|
128
|
+
disposeWorld(plain.world);
|
|
129
|
+
equal(Object.hasOwn(plain.world.scene, 'dispatchEvent'), false);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Invariant 2: the player guards the whole load, including a system reset
|
|
133
|
+
// registered BEFORE the empty-node system. No callback can sync or re-arm.
|
|
134
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
135
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
136
|
+
frame(s);
|
|
137
|
+
let called = 0;
|
|
138
|
+
s.runtime.systems.unshift({ reset() {
|
|
139
|
+
called++;
|
|
140
|
+
equal(s.world.emptyNodes, undefined, 'mode left before any load reset callback');
|
|
141
|
+
s.sync(s.world, s.runtime, {});
|
|
142
|
+
prepareEmptyNodes(s.world, s.runtime);
|
|
143
|
+
equal(s.world.emptyNodes, undefined, 'entire load remains guarded');
|
|
144
|
+
} });
|
|
145
|
+
load(s, { ...s.runtime.data, engine: { ...mode, skipEmptyNodes: true } });
|
|
146
|
+
equal(called, 1);
|
|
147
|
+
equal(s.world.emptyNodes.runtime, s.runtime, 'complete keyed load re-arms at the latch');
|
|
148
|
+
frame(s);
|
|
149
|
+
equal(attached(s, 'marker'), false);
|
|
150
|
+
disposeWorld(s.world);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Invariants 2 and 3: drain callbacks can invalidate a pass with a new
|
|
154
|
+
// keyed load too. Even an explicit load-boundary call inside that callback
|
|
155
|
+
// cannot re-arm the mode around the outer pass.
|
|
156
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
157
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
158
|
+
frame(s);
|
|
159
|
+
const node = s.world.nodes.get('marker').node;
|
|
160
|
+
const oldState = s.world.emptyNodes;
|
|
161
|
+
let transforms = 0;
|
|
162
|
+
const set = node.position.set;
|
|
163
|
+
node.position.set = function (...args) { transforms++; return set.apply(this, args); };
|
|
164
|
+
node.addEventListener('added', () => {
|
|
165
|
+
load(s, { ...s.runtime.data, engine: { ...mode, skipEmptyNodes: true } });
|
|
166
|
+
s.sync(s.world, s.runtime, {});
|
|
167
|
+
equal(s.world.emptyNodes, undefined, 'listener cannot re-arm keyed load around a pass');
|
|
168
|
+
});
|
|
169
|
+
node.add(new THREE.Group());
|
|
170
|
+
s.sync(s.world, s.runtime, {});
|
|
171
|
+
equal(transforms, 0, 'invalidated drain aborts before placing actors');
|
|
172
|
+
equal(oldState.depth, 0, 'invalidated pass unwinds');
|
|
173
|
+
prepareEmptyNodes(s.world, s.runtime);
|
|
174
|
+
assert.notEqual(s.world.emptyNodes, oldState);
|
|
175
|
+
checks++;
|
|
176
|
+
disposeWorld(s.world);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Invariant 3: a scene childadded listener disposes during construction,
|
|
180
|
+
// before the new actor's placement. The building node must be owned already
|
|
181
|
+
// so disposal can remove it, and no later actor may be built.
|
|
182
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
183
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
184
|
+
frame(s);
|
|
185
|
+
s.runtime.spawnActor(actor('new-empty'));
|
|
186
|
+
s.world.scene.addEventListener('childadded', event => {
|
|
187
|
+
if (event.child.userData.actorId === 'new-empty') disposeWorld(s.world);
|
|
188
|
+
});
|
|
189
|
+
s.sync(s.world, s.runtime, {});
|
|
190
|
+
equal(s.world.nodes.size, 0, 'construction listener disposal clears every actor');
|
|
191
|
+
equal(s.world.scene.children.filter(n => n.userData.actorId).length, 0, 'no orphan attached after construction disposal');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Invariant 3: parked nodes are owned before restoration too; an added
|
|
195
|
+
// listener disposing the returning scene must leave no orphan actor.
|
|
196
|
+
{
|
|
197
|
+
const s = side({ skipEmptyNodes: true });
|
|
198
|
+
frame(s);
|
|
199
|
+
s.runtime.residentScenes = new Set(['scenes/main.scene']);
|
|
200
|
+
s.runtime.scenePath = 'scenes/away.scene';
|
|
201
|
+
load(s, { engine: { skipEmptyNodes: true }, actors: [actor('away')] });
|
|
202
|
+
frame(s);
|
|
203
|
+
const node = s.world.parked.get('scenes/main.scene').get('marker').node;
|
|
204
|
+
node.addEventListener('added', () => disposeWorld(s.world));
|
|
205
|
+
s.runtime.scenePath = 'scenes/main.scene';
|
|
206
|
+
load(s, { engine: { skipEmptyNodes: true }, actors: cast() });
|
|
207
|
+
s.sync(s.world, s.runtime, {});
|
|
208
|
+
equal(s.world.nodes.size, 0);
|
|
209
|
+
equal(s.world.parked.size, 0);
|
|
210
|
+
equal(s.world.scene.children.filter(n => n.userData.actorId).length, 0, 'parked restore disposal leaves no attached actor');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Invariant 3 also covers the ground-height consumer callback used by model
|
|
214
|
+
// animation: stop after its FIRST invocation, before querying or posing again.
|
|
215
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
216
|
+
const s = side({ ...mode, skipEmptyNodes: true }, [actor('walker', { Model: { file: 'walker.pxmodel' } })]);
|
|
217
|
+
s.runtime.files['walker.pxmodel'] = fs.readFileSync(new URL('../models/player.pxmodel', import.meta.url), 'utf8');
|
|
218
|
+
frame(s);
|
|
219
|
+
let calls = 0;
|
|
220
|
+
s.world.scene.userData.groundHeight = () => { calls++; disposeWorld(s.world); return 0; };
|
|
221
|
+
s.runtime.touch('walker');
|
|
222
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
223
|
+
equal(calls, 1, 'disposed animation never makes a second consumer call');
|
|
224
|
+
equal(s.world.nodes.size, 0);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// A deck groundHeight callback can sync the ground. Its disposal listener
|
|
228
|
+
// loads a new scene while an empty-node pass is active: the deck must regain
|
|
229
|
+
// control normally, and the outer pass must still abort before another call.
|
|
230
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
231
|
+
const s = side({ ...mode, skipEmptyNodes: true }, [actor('walker', { Model: { file: 'walker.pxmodel' } })]);
|
|
232
|
+
s.runtime.files['walker.pxmodel'] = fs.readFileSync(new URL('../models/player.pxmodel', import.meta.url), 'utf8');
|
|
233
|
+
frame(s);
|
|
234
|
+
let calls = 0, returned = 0, loads = 0;
|
|
235
|
+
const oldState = s.world.emptyNodes;
|
|
236
|
+
const material = s.world.ground.material;
|
|
237
|
+
material.addEventListener('dispose', () => {
|
|
238
|
+
loads++;
|
|
239
|
+
load(s, { engine: {}, actors: [actor('next')] });
|
|
240
|
+
});
|
|
241
|
+
s.world.scene.userData.groundHeight = () => {
|
|
242
|
+
calls++;
|
|
243
|
+
syncGround(s.world, { color: '#aabbcc' }, {});
|
|
244
|
+
returned++;
|
|
245
|
+
return 0;
|
|
246
|
+
};
|
|
247
|
+
s.runtime.touch('walker');
|
|
248
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
249
|
+
equal([calls, returned, loads], [1, 1, 1], 'abort never reaches the deck callback');
|
|
250
|
+
equal(s.world.ground.material, material, 'invalidated ground sync stops before replacing material');
|
|
251
|
+
equal(s.world.nodes.has('next'), false, 'outer pass stops before placing the new scene');
|
|
252
|
+
equal(oldState.depth, 0, 'outer pass unwinds after the deck callback returns');
|
|
253
|
+
delete s.world.scene.userData.groundHeight;
|
|
254
|
+
disposeWorld(s.world);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// All public world operations contain the private abort, and still propagate
|
|
258
|
+
// real consumer errors. Inject at the callback each boundary already runs.
|
|
259
|
+
{
|
|
260
|
+
const { EMPTY_PASS_ABORTED } = await import('../engine3d/emptynodes.js');
|
|
261
|
+
const operations = [
|
|
262
|
+
(s, fail) => { s.world.debugLines = { geometry: { dispose: fail } }; updatePhysicsDebug(s.world, { vertices: new Float32Array(), colors: new Float32Array() }); },
|
|
263
|
+
(s, fail) => { s.world.renderer.setSize = fail; resizeWorld(s.world, 10, 10); },
|
|
264
|
+
(s, fail) => { s.world.composer = { render: fail }; renderWorld(s.world); },
|
|
265
|
+
(s, fail) => { s.world.renderer.dispose = fail; disposeWorld(s.world); },
|
|
266
|
+
(s, fail) => { s.world.groundSig = undefined; s.world.ground.material.dispose = fail; syncGround(s.world, {}, {}); },
|
|
267
|
+
(s, fail) => { s.runtime.getActors = fail; s.sync(s.world, s.runtime, {}); },
|
|
268
|
+
];
|
|
269
|
+
for (const operation of operations) {
|
|
270
|
+
assert.doesNotThrow(() => operation(side(), () => { throw EMPTY_PASS_ABORTED; }));
|
|
271
|
+
const failure = new Error('consumer failure');
|
|
272
|
+
assert.throws(() => operation(side(), () => { throw failure; }), error => error === failure);
|
|
273
|
+
checks += 2;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Invariant 6: keyed and keyless ordinary actors share one loop, with the
|
|
278
|
+
// same placement parameter already used by skipping/static passes.
|
|
279
|
+
{
|
|
280
|
+
const source = fs.readFileSync(new URL('../engine3d/world3d.js', import.meta.url), 'utf8');
|
|
281
|
+
equal(source.includes('syncEmptyActorsAsEver'), false, 'no copied ordinary pass');
|
|
282
|
+
assert.match(source, /function syncActorsAsEver\(world, runtime, sprites, dt, place = placeActor\)/);
|
|
283
|
+
assert.match(source, /syncActorsAsEver\(world, runtime, sprites, dt, placeEmptyActor\)/);
|
|
284
|
+
checks += 2;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// No key / false / original sync have the same graph, signatures, caches and
|
|
288
|
+
// world fields frame for frame, across ordinary, skipping and static paths.
|
|
289
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
290
|
+
const sides = [side(mode), side({ ...mode, skipEmptyNodes: false })];
|
|
291
|
+
if (baseline) sides.push(side(mode, cast(), baseline));
|
|
292
|
+
for (let i = 0; i < 75; i++) {
|
|
293
|
+
for (const s of sides) {
|
|
294
|
+
if (i % 7 === 0) {
|
|
295
|
+
s.runtime.touch('marker');
|
|
296
|
+
s.runtime.getActor('marker').components.Transform.x += 1;
|
|
297
|
+
}
|
|
298
|
+
if (i === 20 || i === 40) {
|
|
299
|
+
s.runtime.touch('missing');
|
|
300
|
+
const c = s.runtime.getActor('missing').components;
|
|
301
|
+
if (i === 20) c.Shape = shape(); else delete c.Shape;
|
|
302
|
+
}
|
|
303
|
+
if (i === 50) load(s, { ...s.runtime.data, engine: mode });
|
|
304
|
+
frame(s);
|
|
305
|
+
for (const entry of s.world.nodes.values()) equal(entry.node._listeners, undefined, 'no new node listeners without the key');
|
|
306
|
+
}
|
|
307
|
+
for (const s of sides.slice(1)) equal(state(s), state(sides[0]), `keyless mode ${JSON.stringify(mode)}, frame ${i}`);
|
|
308
|
+
}
|
|
309
|
+
for (const s of sides) disposeWorld(s.world);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
313
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
314
|
+
for (let i = 0; i < 5; i++) frame(s); // Includes settled static passes.
|
|
315
|
+
equal(s.world.nodes.size, 6);
|
|
316
|
+
for (const id of ['marker', 'missing', 'invalid']) equal(attached(s, id), false, id);
|
|
317
|
+
for (const id of ['shape', 'model', 'nothing']) equal(attached(s, id), true, id);
|
|
318
|
+
const node = s.world.nodes.get('marker').node;
|
|
319
|
+
if (mode.staticActors) {
|
|
320
|
+
equal(isFrozen(node), true, 'empty static node reaches the frozen path');
|
|
321
|
+
const frozenChild = new THREE.Group();
|
|
322
|
+
frozenChild.position.x = 2;
|
|
323
|
+
node.add(frozenChild);
|
|
324
|
+
frame(s);
|
|
325
|
+
equal(attached(s, 'marker'), true, 'attachment to a frozen empty node appears');
|
|
326
|
+
frame(s);
|
|
327
|
+
equal(frozenChild.matrixWorld.toArray(), new THREE.Matrix4().multiplyMatrices(node.matrixWorld, frozenChild.matrix).toArray());
|
|
328
|
+
node.remove(frozenChild);
|
|
329
|
+
frame(s);
|
|
330
|
+
equal(attached(s, 'marker'), false);
|
|
331
|
+
frame(s);
|
|
332
|
+
}
|
|
333
|
+
equal(node.matrixWorld.toArray(), new THREE.Matrix4().compose(node.position, node.quaternion, node.scale).toArray());
|
|
334
|
+
equal(node.getWorldPosition(new THREE.Vector3()).toArray(), [3, 2, -4]);
|
|
335
|
+
s.runtime.touch('marker');
|
|
336
|
+
s.runtime.getActor('marker').components.Transform.x = 17;
|
|
337
|
+
s.runtime.getActor('marker').components.Transform.rotationY = 90;
|
|
338
|
+
s.sync(s.world, s.runtime, {});
|
|
339
|
+
equal(node.matrixWorld.elements[12], 17, 'matrix current before rendering');
|
|
340
|
+
node.updateMatrixWorld(true);
|
|
341
|
+
equal(node.matrixWorld.toArray(), new THREE.Matrix4().compose(node.position, node.quaternion, node.scale).toArray());
|
|
342
|
+
|
|
343
|
+
const child = new THREE.Group();
|
|
344
|
+
child.position.set(2, 1, 0);
|
|
345
|
+
node.add(child);
|
|
346
|
+
frame(s);
|
|
347
|
+
equal(attached(s, 'marker'), true, 'external attachment appears at the next sync');
|
|
348
|
+
frame(s);
|
|
349
|
+
equal(child.getWorldPosition(new THREE.Vector3()).toArray().map(n => Math.round(n)), [17, 3, -6]);
|
|
350
|
+
node.remove(child);
|
|
351
|
+
frame(s);
|
|
352
|
+
equal(attached(s, 'marker'), false, 'last child removal detaches at the next sync');
|
|
353
|
+
// A Low -> High restore of an empty node must not defeat the key.
|
|
354
|
+
s.world.scene.add(node);
|
|
355
|
+
frame(s);
|
|
356
|
+
equal(node.parent, null);
|
|
357
|
+
|
|
358
|
+
for (const component of ['Model', 'Shape']) {
|
|
359
|
+
s.runtime.touch('marker');
|
|
360
|
+
s.runtime.getActor('marker').components[component] = component === 'Model' ? { file: MODEL } : shape();
|
|
361
|
+
frame(s);
|
|
362
|
+
equal(attached(s, 'marker'), true, `gains ${component}`);
|
|
363
|
+
s.runtime.touch('marker');
|
|
364
|
+
delete s.runtime.getActor('marker').components[component];
|
|
365
|
+
frame(s);
|
|
366
|
+
equal(attached(s, 'marker'), false, `loses ${component}`);
|
|
367
|
+
}
|
|
368
|
+
// A missing model file arriving, then becoming invalid again.
|
|
369
|
+
s.runtime.files['missing.pxmodel'] = files[MODEL];
|
|
370
|
+
frame(s);
|
|
371
|
+
equal(attached(s, 'missing'), true);
|
|
372
|
+
s.runtime.files['missing.pxmodel'] = 'invalid';
|
|
373
|
+
frame(s);
|
|
374
|
+
equal(attached(s, 'missing'), false);
|
|
375
|
+
setLookEnabled(false); frame(s); setLookEnabled(true); frame(s);
|
|
376
|
+
equal(attached(s, 'missing'), false, 'look signature changes still leave empty nodes out');
|
|
377
|
+
|
|
378
|
+
s.runtime.spawnActor(actor('spawn-empty'));
|
|
379
|
+
s.runtime.spawnActor(actor('spawn-model', { Model: { file: MODEL } }));
|
|
380
|
+
frame(s);
|
|
381
|
+
equal(attached(s, 'spawn-empty'), false, 'spawned empty actor remains an entry without a scene object');
|
|
382
|
+
equal(attached(s, 'spawn-model'), true, 'spawned model appears');
|
|
383
|
+
s.runtime.getActor('spawn-empty').components.Shape = shape();
|
|
384
|
+
frame(s);
|
|
385
|
+
equal(attached(s, 'spawn-empty'), true, 'spawned empty actor gains a Shape');
|
|
386
|
+
s.runtime.despawnActor('spawn-empty');
|
|
387
|
+
s.runtime.despawnActor('spawn-model');
|
|
388
|
+
frame(s);
|
|
389
|
+
|
|
390
|
+
// Low classifications and real bounds, including empty scenery and NPCs.
|
|
391
|
+
const lv = makeLevers();
|
|
392
|
+
s.runtime.readFromFile = () => s.runtime.data;
|
|
393
|
+
lv.apply(s.world, s.runtime, 0);
|
|
394
|
+
equal(classify(s.runtime.getActor('marker').components), 'decor');
|
|
395
|
+
equal(attached(s, 'model'), false, 'Low hides drawn decor');
|
|
396
|
+
equal(attached(s, 'marker'), false, 'Low keeps empty decor detached');
|
|
397
|
+
frame(s);
|
|
398
|
+
equal(attached(s, 'model'), false, 'engine does not restore Low-hidden drawables');
|
|
399
|
+
lv.restore(s.world);
|
|
400
|
+
frame(s);
|
|
401
|
+
equal(attached(s, 'model'), true);
|
|
402
|
+
equal(attached(s, 'marker'), false);
|
|
403
|
+
|
|
404
|
+
// Key off and on in the same scene: restore empty roots without rebuilding
|
|
405
|
+
// nodes or changing their signature/cache keys. The editor always opts out.
|
|
406
|
+
const old = s.world.nodes.get('marker');
|
|
407
|
+
load(s, { ...s.runtime.data, engine: mode });
|
|
408
|
+
equal(attached(s, 'marker'), true, 'load gives nodes back before a keyless frame');
|
|
409
|
+
equal(s.world.emptyNodes, undefined, 'load drops all empty-node bookkeeping');
|
|
410
|
+
frame(s);
|
|
411
|
+
equal(s.world.nodes.get('marker'), old);
|
|
412
|
+
equal(attached(s, 'marker'), true);
|
|
413
|
+
load(s, { ...s.runtime.data, engine: { ...mode, skipEmptyNodes: true } });
|
|
414
|
+
frame(s);
|
|
415
|
+
equal(attached(s, 'marker'), false);
|
|
416
|
+
s.world.skipEmptyNodesOff = true;
|
|
417
|
+
forgetEmptyNodes(s.world, true);
|
|
418
|
+
frame(s);
|
|
419
|
+
equal(attached(s, 'marker'), true, 'editor keeps empty actors');
|
|
420
|
+
delete s.world.skipEmptyNodesOff;
|
|
421
|
+
prepareEmptyNodes(s.world, s.runtime);
|
|
422
|
+
frame(s);
|
|
423
|
+
|
|
424
|
+
// Parked scenes cannot attach themselves, even if a child is added away.
|
|
425
|
+
s.runtime.residentScenes = new Set(['scenes/main.scene']);
|
|
426
|
+
s.runtime.scenePath = 'scenes/away.scene';
|
|
427
|
+
load(s, { name: 'Away', engine: { skipEmptyNodes: true }, actors: [actor('away')] });
|
|
428
|
+
frame(s);
|
|
429
|
+
const parked = s.world.parked.get('scenes/main.scene').get('marker').node;
|
|
430
|
+
parked.add(child);
|
|
431
|
+
equal(parked.parent, null, 'parked scene stays parked');
|
|
432
|
+
s.runtime.scenePath = 'scenes/main.scene';
|
|
433
|
+
load(s, { name: 'Back', engine: { ...mode, skipEmptyNodes: true }, actors: cast() });
|
|
434
|
+
frame(s);
|
|
435
|
+
equal(attached(s, 'marker'), true, 'return with an attachment');
|
|
436
|
+
parked.remove(child);
|
|
437
|
+
frame(s);
|
|
438
|
+
equal(attached(s, 'marker'), false);
|
|
439
|
+
s.runtime.despawnActor('marker');
|
|
440
|
+
frame(s);
|
|
441
|
+
equal(s.world.nodes.has('marker'), false, 'releaseUnseen');
|
|
442
|
+
parked.add(child);
|
|
443
|
+
equal(parked.parent, null, 'released node cannot resurrect itself');
|
|
444
|
+
const released = s.world.nodes.get('missing').node;
|
|
445
|
+
disposeWorld(s.world);
|
|
446
|
+
equal(s.world.nodes.size, 0);
|
|
447
|
+
equal(s.world.parked.size, 0);
|
|
448
|
+
equal(s.world.models.size, 0);
|
|
449
|
+
released.add(new THREE.Group());
|
|
450
|
+
equal(released.parent, null, 'disposed node cannot resurrect itself');
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Real Low bounds for detached empty scenery, and NPC distance hiding.
|
|
454
|
+
const lowActors = [actor('near-static', { Solid: {} }), actor('far-static', { Solid: {} }),
|
|
455
|
+
actor('near-npc', { HubNpc: {} }), actor('far-npc', { HubNpc: {} })];
|
|
456
|
+
for (const a of lowActors) a.components.Transform.x = a.id.startsWith('far') ? 100 : 0;
|
|
457
|
+
const low = side({ skipEmptyNodes: true }, lowActors);
|
|
458
|
+
low.runtime.readFromFile = () => low.runtime.data;
|
|
459
|
+
frame(low);
|
|
460
|
+
const levers = makeLevers();
|
|
461
|
+
levers.apply(low.world, low.runtime, 0);
|
|
462
|
+
equal(levers.hidden, 2, 'far static and NPC classified using detached positions/bounds');
|
|
463
|
+
const npc = low.world.nodes.get('far-npc').node;
|
|
464
|
+
npc.add(new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial()));
|
|
465
|
+
frame(low);
|
|
466
|
+
equal(attached(low, 'far-npc'), true, 'an empty node can gain a consumer body');
|
|
467
|
+
levers.apply(low.world, low.runtime, 1);
|
|
468
|
+
equal(attached(low, 'far-npc'), false, 'Low notices attachment of an empty far NPC');
|
|
469
|
+
frame(low);
|
|
470
|
+
equal(attached(low, 'far-npc'), false, 'sync respects tier removal');
|
|
471
|
+
levers.restore(low.world);
|
|
472
|
+
frame(low);
|
|
473
|
+
equal(attached(low, 'far-npc'), true, 'High restores consumer body');
|
|
474
|
+
equal(attached(low, 'far-static'), false, 'High leaves empty scenery detached');
|
|
475
|
+
disposeWorld(low.world);
|
|
476
|
+
|
|
477
|
+
// Disposal, throws and a keyless nested sync from attachment callbacks cannot
|
|
478
|
+
// leave live listeners belonging to the former mode.
|
|
479
|
+
for (const action of ['keyless', 'dispose', 'throw']) {
|
|
480
|
+
const s = side({ skipEmptyNodes: true });
|
|
481
|
+
frame(s);
|
|
482
|
+
const node = s.world.nodes.get('marker').node;
|
|
483
|
+
const onAdded = () => {
|
|
484
|
+
node.removeEventListener('added', onAdded);
|
|
485
|
+
if (action === 'dispose') disposeWorld(s.world);
|
|
486
|
+
else if (action === 'keyless') {
|
|
487
|
+
load(s, { ...s.runtime.data, engine: {} });
|
|
488
|
+
frame(s);
|
|
489
|
+
} else throw new Error('consumer callback');
|
|
490
|
+
};
|
|
491
|
+
node.addEventListener('added', onAdded);
|
|
492
|
+
node.add(new THREE.Group());
|
|
493
|
+
if (action === 'throw') assert.throws(() => frame(s), /consumer callback/);
|
|
494
|
+
else frame(s);
|
|
495
|
+
if (action === 'dispose') {
|
|
496
|
+
equal(s.world.nodes.size, 0, 'drain disposal aborts before placement rebuilds nodes');
|
|
497
|
+
equal(node.parent, null, 'drain disposal leaves actor detached');
|
|
498
|
+
equal(s.world.emptyNodes, undefined);
|
|
499
|
+
}
|
|
500
|
+
if (action === 'keyless') {
|
|
501
|
+
node.clear();
|
|
502
|
+
frame(s);
|
|
503
|
+
equal(attached(s, 'marker'), true, 'nested keyless sync drops old listeners');
|
|
504
|
+
}
|
|
505
|
+
disposeWorld(s.world);
|
|
506
|
+
node.add(new THREE.Group());
|
|
507
|
+
equal(node.parent, null, 'disposed attachment callback cannot resurrect node');
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// Invariant 2: cleanup callbacks see the old keyed config, but cannot re-enter the mode.
|
|
511
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
512
|
+
for (const action of ['load', 'reset', 'dispose']) {
|
|
513
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
514
|
+
frame(s);
|
|
515
|
+
const node = s.world.nodes.get('marker').node;
|
|
516
|
+
let called = 0;
|
|
517
|
+
node.addEventListener('added', () => {
|
|
518
|
+
called++;
|
|
519
|
+
s.sync(s.world, s.runtime, {});
|
|
520
|
+
prepareEmptyNodes(s.world, s.runtime);
|
|
521
|
+
equal(s.world.emptyNodes, undefined, 'cleanup sync/load boundary cannot re-enter mode');
|
|
522
|
+
});
|
|
523
|
+
if (action === 'load') load(s, { ...s.runtime.data, engine: mode });
|
|
524
|
+
else if (action === 'reset') for (const system of s.runtime.systems) system.reset?.(s.runtime);
|
|
525
|
+
else s.runtime.dispose();
|
|
526
|
+
equal(called, 1, `${action}: restore listener ran`);
|
|
527
|
+
equal(s.world.emptyNodes, undefined);
|
|
528
|
+
s.sync(s.world, s.runtime, {});
|
|
529
|
+
equal(attached(s, 'marker'), true, `${action}: feature stays off after cleanup`);
|
|
530
|
+
equal(s.world.emptyNodes, undefined);
|
|
531
|
+
disposeWorld(s.world);
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Invariant 5: placement owns detached matrices: changed Euler/physics poses update
|
|
536
|
+
// immediately, and unchanged ordinary/skipping/static poses do no matrix work.
|
|
537
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
538
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
539
|
+
for (let i = 0; i < 6; i++) frame(s);
|
|
540
|
+
const node = s.world.nodes.get('marker').node;
|
|
541
|
+
const a = s.runtime.getActor('marker');
|
|
542
|
+
const original = node.updateMatrixWorld;
|
|
543
|
+
let updates = 0;
|
|
544
|
+
node.updateMatrixWorld = function (...args) { updates++; return original.apply(this, args); };
|
|
545
|
+
for (let i = 0; i < 5; i++) s.sync(s.world, s.runtime, {});
|
|
546
|
+
equal(updates, 0, 'unchanged detached actor has zero matrix calls');
|
|
547
|
+
s.runtime.touch(a);
|
|
548
|
+
a.components.Transform.z = 25;
|
|
549
|
+
a.runtime.quat = { x: 0, y: 0, z: 1, w: 0 };
|
|
550
|
+
s.sync(s.world, s.runtime, {});
|
|
551
|
+
equal(node.matrixWorld.toArray(), new THREE.Matrix4().compose(node.position, node.quaternion, node.scale).toArray(), 'physics quaternion current before rendering');
|
|
552
|
+
for (let i = 0; i < 6; i++) frame(s);
|
|
553
|
+
const settled = node.updateMatrixWorld;
|
|
554
|
+
updates = 0;
|
|
555
|
+
node.updateMatrixWorld = function (...args) { updates++; return settled.apply(this, args); };
|
|
556
|
+
for (let i = 0; i < 5; i++) s.sync(s.world, s.runtime, {});
|
|
557
|
+
equal(updates, 0, 'unchanged physics quaternion has zero matrix calls');
|
|
558
|
+
disposeWorld(s.world);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// Invariant 5: no pose interception, including methods direct consumers commonly use.
|
|
562
|
+
{
|
|
563
|
+
const s = side({ skipEmptyNodes: true });
|
|
564
|
+
frame(s);
|
|
565
|
+
const node = s.world.nodes.get('marker').node;
|
|
566
|
+
for (const vector of [node.position, node.quaternion, node.rotation, node.scale]) {
|
|
567
|
+
equal(Object.hasOwn(vector, 'set'), false);
|
|
568
|
+
}
|
|
569
|
+
// Once it has a child and reattaches, all normal three.js pose APIs work.
|
|
570
|
+
node.add(new THREE.Group());
|
|
571
|
+
s.sync(s.world, s.runtime, {});
|
|
572
|
+
node.scale.x = 2;
|
|
573
|
+
node.scale.setScalar(3);
|
|
574
|
+
node.scale.multiplyScalar(2);
|
|
575
|
+
s.world.scene.updateMatrixWorld();
|
|
576
|
+
equal(node.matrixWorld.toArray(), new THREE.Matrix4().compose(node.position, node.quaternion, node.scale).toArray());
|
|
577
|
+
disposeWorld(s.world);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Later listeners must see three.js's original singleton event fields.
|
|
581
|
+
{
|
|
582
|
+
const s = side({ skipEmptyNodes: true });
|
|
583
|
+
frame(s);
|
|
584
|
+
const node = s.world.nodes.get('marker').node;
|
|
585
|
+
const child = new THREE.Group();
|
|
586
|
+
let additions = 0, removals = 0;
|
|
587
|
+
node.addEventListener('childadded', event => {
|
|
588
|
+
equal(event.child, child);
|
|
589
|
+
s.sync(s.world, s.runtime, {});
|
|
590
|
+
equal(node.parent, null, 'sync inside childadded cannot drain');
|
|
591
|
+
equal(s.world.emptyNodes.depth, 0, 'dispatch does not enter an actor pass');
|
|
592
|
+
});
|
|
593
|
+
node.addEventListener('childadded', event => { equal(event.child, child); additions++; });
|
|
594
|
+
node.addEventListener('childremoved', event => {
|
|
595
|
+
s.sync(s.world, s.runtime, {});
|
|
596
|
+
equal(node.parent, s.world.scene, 'sync inside childremoved cannot drain');
|
|
597
|
+
equal(event.child, child);
|
|
598
|
+
});
|
|
599
|
+
node.addEventListener('childremoved', event => { equal(event.child, child); removals++; });
|
|
600
|
+
node.add(child);
|
|
601
|
+
equal(attached(s, 'marker'), false, 'dispatch only queues attachment');
|
|
602
|
+
frame(s);
|
|
603
|
+
equal(attached(s, 'marker'), true);
|
|
604
|
+
node.remove(child);
|
|
605
|
+
equal(attached(s, 'marker'), true, 'dispatch only queues detachment');
|
|
606
|
+
frame(s);
|
|
607
|
+
equal(attached(s, 'marker'), false);
|
|
608
|
+
equal([additions, removals], [1, 1]);
|
|
609
|
+
disposeWorld(s.world);
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// Invariant 4 / review P2: exceptions from either child event unwind our
|
|
613
|
+
// dispatch depth, even though three.js leaves its singleton target non-null.
|
|
614
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
615
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
616
|
+
frame(s);
|
|
617
|
+
const node = s.world.nodes.get('marker').node;
|
|
618
|
+
const child = new THREE.Group();
|
|
619
|
+
for (const event of ['childadded', 'childremoved']) {
|
|
620
|
+
const fail = () => {
|
|
621
|
+
s.sync(s.world, s.runtime, {});
|
|
622
|
+
throw new Error('child listener threw');
|
|
623
|
+
};
|
|
624
|
+
node.addEventListener(event, fail);
|
|
625
|
+
assert.throws(() => event === 'childadded' ? node.add(child) : node.remove(child), /child listener threw/);
|
|
626
|
+
node.removeEventListener(event, fail);
|
|
627
|
+
equal(s.world.emptyNodes.dispatchDepth, 0, 'throw unwinds dispatch depth');
|
|
628
|
+
s.sync(s.world, s.runtime, {});
|
|
629
|
+
equal(attached(s, 'marker'), event === 'childadded', 'recovery in one frame');
|
|
630
|
+
}
|
|
631
|
+
disposeWorld(s.world);
|
|
632
|
+
for (const method of ['dispatchEvent', 'add', 'remove']) equal(Object.hasOwn(node, method), false, 'dispose restores event methods');
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// Invariant 4: three dispatches a child's added/removed BEFORE notifying
|
|
636
|
+
// its parent. Syncs there also defer, and throws still leave the parent dirty.
|
|
637
|
+
for (const event of ['added', 'removed']) {
|
|
638
|
+
const s = side({ skipEmptyNodes: true });
|
|
639
|
+
frame(s);
|
|
640
|
+
const node = s.world.nodes.get('marker').node;
|
|
641
|
+
const child = new THREE.Group();
|
|
642
|
+
if (event === 'removed') { node.add(child); frame(s); }
|
|
643
|
+
let calls = 0;
|
|
644
|
+
child.addEventListener(event, () => {
|
|
645
|
+
calls++;
|
|
646
|
+
s.sync(s.world, s.runtime, {});
|
|
647
|
+
equal(attached(s, 'marker'), event === 'removed', 'child dispatch cannot drain or place');
|
|
648
|
+
throw new Error('child own listener threw');
|
|
649
|
+
});
|
|
650
|
+
assert.throws(() => event === 'added' ? node.add(child) : node.remove(child), /child own listener threw/);
|
|
651
|
+
equal(calls, 1);
|
|
652
|
+
equal(s.world.emptyNodes.dispatchDepth, 0);
|
|
653
|
+
s.sync(s.world, s.runtime, {});
|
|
654
|
+
equal(attached(s, 'marker'), event === 'added', 'child own throw recovers in one frame');
|
|
655
|
+
disposeWorld(s.world);
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// A throw midway through draining must keep the unvisited dirty entries.
|
|
659
|
+
{
|
|
660
|
+
const s = side({ skipEmptyNodes: true });
|
|
661
|
+
frame(s);
|
|
662
|
+
const first = s.world.nodes.get('marker').node;
|
|
663
|
+
const last = s.world.nodes.get('invalid').node;
|
|
664
|
+
const fail = () => { throw new Error('drain listener threw'); };
|
|
665
|
+
first.addEventListener('added', fail);
|
|
666
|
+
first.add(new THREE.Group());
|
|
667
|
+
last.add(new THREE.Group());
|
|
668
|
+
assert.throws(() => s.sync(s.world, s.runtime, {}), /drain listener threw/);
|
|
669
|
+
first.removeEventListener('added', fail);
|
|
670
|
+
equal(s.world.emptyNodes.dispatchDepth, 0);
|
|
671
|
+
s.sync(s.world, s.runtime, {});
|
|
672
|
+
equal(attached(s, 'invalid'), true, 'unvisited dirty node recovers in one frame');
|
|
673
|
+
disposeWorld(s.world);
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// Low-hidden drawables belong to tiers, not the empty-node matrix queue.
|
|
677
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
678
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
679
|
+
frame(s);
|
|
680
|
+
s.runtime.readFromFile = () => s.runtime.data;
|
|
681
|
+
const tiers = makeLevers();
|
|
682
|
+
tiers.apply(s.world, s.runtime, 0);
|
|
683
|
+
const node = s.world.nodes.get('shape').node;
|
|
684
|
+
let updates = 0;
|
|
685
|
+
const update = node.updateMatrixWorld;
|
|
686
|
+
node.updateMatrixWorld = function (...args) { updates++; return update.apply(this, args); };
|
|
687
|
+
for (let i = 0; i < 5; i++) frame(s);
|
|
688
|
+
equal(updates, 0, 'Low-hidden Shape receives no matrix calls');
|
|
689
|
+
disposeWorld(s.world);
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
const drop = side({ skipEmptyNodes: true, dropEmptyParts: true });
|
|
693
|
+
frame(drop);
|
|
694
|
+
equal(attached(drop, 'nothing'), false, 'model reduced to no rig is detached');
|
|
695
|
+
disposeWorld(drop.world);
|
|
696
|
+
for (const value of [false, 1, 'true', null]) {
|
|
697
|
+
const s = side({ skipEmptyNodes: value }); frame(s);
|
|
698
|
+
equal(s.runtime.skipsEmptyNodes, false, 'only true opts in');
|
|
699
|
+
equal(attached(s, 'marker'), true);
|
|
700
|
+
disposeWorld(s.world);
|
|
701
|
+
}
|
|
702
|
+
const moved = side({ skipEmptyNodes: true });
|
|
703
|
+
frame(moved);
|
|
704
|
+
moved.world.scene.position.x = 5;
|
|
705
|
+
frame(moved);
|
|
706
|
+
equal(attached(moved, 'marker'), true, 'nonidentity scene retains parent');
|
|
707
|
+
equal(moved.world.nodes.get('marker').node.getWorldPosition(new THREE.Vector3()).x, 8);
|
|
708
|
+
moved.world.scene.position.x = 0;
|
|
709
|
+
frame(moved);
|
|
710
|
+
equal(attached(moved, 'marker'), false);
|
|
711
|
+
disposeWorld(moved.world);
|
|
712
|
+
|
|
713
|
+
// Removal callbacks can invalidate the identity cached at drain entry.
|
|
714
|
+
// Restore both the node just removed and roots detached earlier in this pass
|
|
715
|
+
// or an earlier frame, before placement/rendering in this same sync.
|
|
716
|
+
for (const mode of [{}, { skipUnchangedActors: true }, { skipUnchangedActors: true, staticActors: true }]) {
|
|
717
|
+
for (const event of ['removed', 'childremoved']) {
|
|
718
|
+
for (const settled of [false, true]) {
|
|
719
|
+
const s = side({ ...mode, skipEmptyNodes: true });
|
|
720
|
+
// Build without draining, or settle first and make one root empty again.
|
|
721
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
722
|
+
const node = s.world.nodes.get('invalid').node;
|
|
723
|
+
if (settled) {
|
|
724
|
+
frame(s);
|
|
725
|
+
const child = new THREE.Group();
|
|
726
|
+
node.add(child);
|
|
727
|
+
frame(s);
|
|
728
|
+
node.remove(child);
|
|
729
|
+
}
|
|
730
|
+
let callbacks = 0;
|
|
731
|
+
const target = event === 'removed' ? node : s.world.scene;
|
|
732
|
+
target.addEventListener(event, event => {
|
|
733
|
+
if (event.child && event.child !== node) return;
|
|
734
|
+
callbacks++;
|
|
735
|
+
s.world.scene.position.x = 5;
|
|
736
|
+
});
|
|
737
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
738
|
+
equal(callbacks, 1, 'removal listener moves scene during drain');
|
|
739
|
+
s.world.scene.updateMatrixWorld();
|
|
740
|
+
for (const { node: root } of s.world.nodes.values()) {
|
|
741
|
+
equal(root.parent, s.world.scene, 'nonidentity scene restores every root in the same sync');
|
|
742
|
+
equal(root.emptyDetached, undefined);
|
|
743
|
+
equal(root.matrixWorld.elements[12], 8, 'same-frame world matrix includes listener scene transform');
|
|
744
|
+
}
|
|
745
|
+
disposeWorld(s.world);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// A hub-square fixture: 229 empty anchors, 100 drawn actors. Count every
|
|
751
|
+
// object visited by scene traversal, not just direct children or draw calls.
|
|
752
|
+
const fixture = Array.from({ length: 329 }, (_, i) => actor(`square-${i}`, i < 229 ? {} : { Shape: shape() }));
|
|
753
|
+
function count(s) { let n = 0; s.world.scene.traverse(() => n++); return n; }
|
|
754
|
+
const plain = side({}, fixture);
|
|
755
|
+
const keyed = side({ skipEmptyNodes: true }, fixture);
|
|
756
|
+
frame(plain); frame(keyed);
|
|
757
|
+
equal(count(plain) - count(keyed), 229);
|
|
758
|
+
equal(drawn(plain.world), drawn(keyed.world), 'all drawn geometry/materials/world matrices remain equal');
|
|
759
|
+
console.log(`skip-empty-nodes: ${checks} checks; keyless frame equivalence${baseline ? ' against pre-change world3d' : ''}; square scene objects ${count(plain)} -> ${count(keyed)} (229 removed)`);
|
|
760
|
+
disposeWorld(plain.world); disposeWorld(keyed.world);
|
|
761
|
+
|
|
762
|
+
// Deterministic per-frame cost, including sync's map visits and render's
|
|
763
|
+
// actor matrix calls. Instrument outside the measured frame after settling.
|
|
764
|
+
function cost(s) {
|
|
765
|
+
const nodes = s.world.nodes;
|
|
766
|
+
let visits = 0, matrices = 0, weakLookups = 0;
|
|
767
|
+
const originals = new Map();
|
|
768
|
+
for (const entry of nodes.values()) {
|
|
769
|
+
const node = entry.node;
|
|
770
|
+
const update = node.updateMatrixWorld;
|
|
771
|
+
const own = Object.hasOwn(node, 'updateMatrixWorld');
|
|
772
|
+
originals.set(node, { update, own });
|
|
773
|
+
node.updateMatrixWorld = function (...args) { matrices++; return update.apply(this, args); };
|
|
774
|
+
}
|
|
775
|
+
const get = nodes.get, values = nodes.values, iterator = nodes[Symbol.iterator];
|
|
776
|
+
nodes.get = function (key) { visits++; return get.call(this, key); };
|
|
777
|
+
nodes.values = function* () { for (const entry of values.call(this)) { visits++; yield entry; } };
|
|
778
|
+
nodes[Symbol.iterator] = function* () { for (const entry of iterator.call(this)) { visits++; yield entry; } };
|
|
779
|
+
const weakGet = WeakMap.prototype.get, weakHas = WeakMap.prototype.has;
|
|
780
|
+
WeakMap.prototype.get = function (key) { weakLookups++; return weakGet.call(this, key); };
|
|
781
|
+
WeakMap.prototype.has = function (key) { weakLookups++; return weakHas.call(this, key); };
|
|
782
|
+
try { s.sync(s.world, s.runtime, {}); s.world.scene.updateMatrixWorld(); } finally {
|
|
783
|
+
WeakMap.prototype.get = weakGet; WeakMap.prototype.has = weakHas;
|
|
784
|
+
delete nodes.get; delete nodes.values; delete nodes[Symbol.iterator];
|
|
785
|
+
for (const [node, { update, own }] of originals) {
|
|
786
|
+
if (own) node.updateMatrixWorld = update; else delete node.updateMatrixWorld;
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
return { visits, matrices, weakLookups };
|
|
790
|
+
}
|
|
791
|
+
const big = Array.from({ length: 6000 }, (_, i) => actor(`cost-${i}`, i < 4200 ? {} : { Shape: shape() }));
|
|
792
|
+
for (const [name, mode] of [['ordinary', {}], ['skipping', { skipUnchangedActors: true }],
|
|
793
|
+
['settled static', { skipUnchangedActors: true, staticActors: true }]]) {
|
|
794
|
+
const off = side(mode, big), on = side({ ...mode, skipEmptyNodes: true }, big);
|
|
795
|
+
const original = baseline ? side(mode, big, baseline) : null;
|
|
796
|
+
for (let i = 0; i < 6; i++) { frame(off); frame(on); if (original) frame(original); }
|
|
797
|
+
// Any accidental whole-map scan in the empty-node keeper is a failure.
|
|
798
|
+
const records = on.world.emptyNodes.records;
|
|
799
|
+
for (const method of ['values', 'keys', 'entries', 'forEach', Symbol.iterator]) {
|
|
800
|
+
records[method] = () => { throw new Error('settled frame scanned empty-node records'); };
|
|
801
|
+
}
|
|
802
|
+
Object.defineProperty(off.world, 'emptyNodes', { configurable: true, get() { throw new Error('keyless frame accessed empty-node state'); } });
|
|
803
|
+
let getterCalls = 0, ownershipReads = 0;
|
|
804
|
+
Object.defineProperty(off.runtime, 'skipsEmptyNodes', { configurable: true, get() { getterCalls++; return false; } });
|
|
805
|
+
Object.defineProperty(off.world, 'emptyNodesOwned', { configurable: true, get() { ownershipReads++; return undefined; } });
|
|
806
|
+
off.runtime.update(1 / 60);
|
|
807
|
+
const keyless = cost(off), keyed = cost(on);
|
|
808
|
+
equal(getterCalls, 0, `${name}: keyless update/sync never calls the runtime getter`);
|
|
809
|
+
equal(ownershipReads, 1, `${name}: keyless sync reads lifecycle ownership only once`);
|
|
810
|
+
delete off.runtime.skipsEmptyNodes;
|
|
811
|
+
delete off.world.emptyNodesOwned;
|
|
812
|
+
delete off.world.emptyNodes;
|
|
813
|
+
assert.ok(keyed.visits <= keyless.visits, `${name}: keyed node visits exceed keyless`);
|
|
814
|
+
assert.ok(keyed.matrices < keyless.matrices, `${name}: keyed matrix calls must be lower`);
|
|
815
|
+
if (original) equal(keyless, cost(original), `${name}: no extra keyless work versus original`);
|
|
816
|
+
for (const method of ['values', 'keys', 'entries', 'forEach', Symbol.iterator]) delete records[method];
|
|
817
|
+
console.log(`skip-empty-nodes cost (${name}, 6000 actors): keyless ${JSON.stringify(keyless)}; keyed ${JSON.stringify(keyed)}`);
|
|
818
|
+
// Report wall-clock timings only: scheduling/GC noise on a loaded CI host
|
|
819
|
+
// cannot be a correctness failure. The deterministic counts above enforce
|
|
820
|
+
// the per-frame cost. Time sync + three.js matrix work and alternate
|
|
821
|
+
// order across warmed samples to distribute GC/scheduling noise equally.
|
|
822
|
+
function sample(s, frames = 80, workload = 'sync + matrices') {
|
|
823
|
+
const start = performance.now();
|
|
824
|
+
for (let i = 0; i < frames; i++) {
|
|
825
|
+
if (workload !== 'sync + matrices') s.runtime.update(1 / 60);
|
|
826
|
+
if (workload !== 'runtime.update only') {
|
|
827
|
+
s.sync(s.world, s.runtime, {}, 1 / 60);
|
|
828
|
+
s.world.scene.updateMatrixWorld();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return (performance.now() - start) / frames;
|
|
832
|
+
}
|
|
833
|
+
for (const workload of ['sync + matrices', 'runtime.update only', 'runtime.update + sync + matrices']) {
|
|
834
|
+
sample(off, 150, workload); sample(on, 150, workload);
|
|
835
|
+
const offMs = [], onMs = [];
|
|
836
|
+
for (let i = 0; i < 9; i++) {
|
|
837
|
+
if (i % 2) { onMs.push(sample(on, 80, workload)); offMs.push(sample(off, 80, workload)); }
|
|
838
|
+
else { offMs.push(sample(off, 80, workload)); onMs.push(sample(on, 80, workload)); }
|
|
839
|
+
}
|
|
840
|
+
const median = values => [...values].sort((a, b) => a - b)[Math.floor(values.length / 2)];
|
|
841
|
+
const keylessMs = median(offMs), keyedMs = median(onMs);
|
|
842
|
+
console.log(`skip-empty-nodes timing (${name}, ${workload}, 6000 actors / 4200 empty, ms/frame): keyless ${keylessMs.toFixed(3)}; keyed ${keyedMs.toFixed(3)}; ratio ${(keyedMs / keylessMs).toFixed(3)}; samples ${JSON.stringify({ keyless: offMs.map(n => +n.toFixed(3)), keyed: onMs.map(n => +n.toFixed(3)) })}`);
|
|
843
|
+
}
|
|
844
|
+
disposeWorld(off.world); disposeWorld(on.world); if (original) disposeWorld(original.world);
|
|
845
|
+
}
|