castle-web-cli 0.4.238 → 0.4.240
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.js +5 -1
- package/dist/api.d.ts +20 -0
- package/dist/api.js +57 -0
- package/dist/bundle.d.ts +38 -1
- package/dist/bundle.js +309 -13
- package/dist/castle-host/host.js +218 -11
- package/dist/castleJson.d.ts +10 -0
- package/dist/castleJson.js +46 -2
- package/dist/check.js +5 -2
- package/dist/devSessionServer.js +4 -1
- package/dist/devSessionStorage.d.ts +1 -0
- package/dist/devSessionStorage.js +32 -7
- package/dist/importOrder.d.ts +2 -0
- package/dist/importOrder.js +29 -0
- package/dist/index.js +22 -3
- package/dist/init.js +24 -2
- package/dist/multiplayerDoc.d.ts +1 -1
- package/dist/multiplayerDoc.js +9 -0
- package/dist/platformDoc.js +4 -2
- package/dist/playPagePolicy.d.ts +1 -0
- package/dist/playPagePolicy.js +12 -3
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/roomLogs.d.ts +39 -0
- package/dist/roomLogs.js +166 -0
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +2 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +240 -8
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +8 -2
- package/kits/base/sdk/castle.js +3 -0
- package/kits/base/sdk/commands.d.ts +79 -0
- package/kits/base/sdk/commands.js +1 -0
- package/kits/base/sdk/debugConsole.d.ts +17 -0
- package/kits/base/sdk/debugConsole.js +154 -0
- package/kits/base/sdk/experiments.js +24 -1
- package/kits/base/sdk/hostRetry.d.ts +7 -0
- package/kits/base/sdk/hostRetry.js +57 -0
- package/kits/base/sdk/hub.d.ts +20 -2
- package/kits/base/sdk/hub.js +99 -13
- package/kits/base/sdk/multiplayer.d.ts +2 -0
- package/kits/base/sdk/multiplayer.js +198 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- package/kits/base/sdk/rooms.d.ts +11 -0
- package/kits/base/sdk/rooms.js +22 -0
- package/kits/base/sdk/runtime.js +36 -19
- package/kits/base/sdk/server/hub.d.ts +19 -0
- package/kits/base/sdk/server/hub.js +12 -0
- package/kits/base/sdk/server/platformHandle.d.ts +1 -0
- package/kits/base/sdk/server/wrapper.d.ts +1 -1
- package/kits/base/sdk/server/wrapper.js +26 -1
- package/kits/base/sdk/store.d.ts +8 -2
- package/kits/base/sdk/store.js +5 -1
- package/kits/base/sdk/transport.d.ts +2 -1
- package/kits/base/sdk/transport.js +35 -0
- package/kits/hub-game/CLAUDE.md +66 -19
- package/kits/hub-game/castle.json +4 -4
- package/kits/hub-game/code/client/act.js +9 -6
- package/kits/hub-game/code/client/actCore.js +26 -6
- package/kits/hub-game/code/client/actGateLog.js +36 -0
- package/kits/hub-game/code/client/actionOverflow.js +29 -8
- package/kits/hub-game/code/client/actionRailSurface.js +186 -0
- package/kits/hub-game/code/client/actionRailTree.js +173 -0
- package/kits/hub-game/code/client/askSurface.js +85 -0
- package/kits/hub-game/code/client/askTree.js +51 -0
- package/kits/hub-game/code/client/attention.js +31 -6
- package/kits/hub-game/code/client/ballot.js +42 -5
- package/kits/hub-game/code/client/ballotSurface.js +115 -0
- package/kits/hub-game/code/client/ballotTree.js +180 -0
- package/kits/hub-game/code/client/catchingUp.js +19 -0
- package/kits/hub-game/code/client/celebrate.js +66 -0
- package/kits/hub-game/code/client/chrome.js +474 -53
- package/kits/hub-game/code/client/companion.js +93 -23
- package/kits/hub-game/code/client/companionDress.js +1 -1
- package/kits/hub-game/code/client/cornerSurface.js +106 -0
- package/kits/hub-game/code/client/cornerTree.js +83 -0
- package/kits/hub-game/code/client/decor.js +20 -11
- package/kits/hub-game/code/client/deviceStorage.js +121 -0
- package/kits/hub-game/code/client/disguise.js +23 -0
- package/kits/hub-game/code/client/disguiseDraw.js +87 -0
- package/kits/hub-game/code/client/dockSurface.js +206 -0
- package/kits/hub-game/code/client/dockTree.js +232 -0
- package/kits/hub-game/code/client/earned.js +29 -0
- package/kits/hub-game/code/client/emoteSurface.js +188 -0
- package/kits/hub-game/code/client/emoteTree.js +264 -0
- package/kits/hub-game/code/client/farAvatars.js +4 -3
- package/kits/hub-game/code/client/fpsTelemetry.js +3 -1
- package/kits/hub-game/code/client/grab.js +121 -50
- package/kits/hub-game/code/client/holdShow.js +19 -0
- package/kits/hub-game/code/client/hookLayer.js +96 -12
- package/kits/hub-game/code/client/hubControls.js +7 -1
- package/kits/hub-game/code/client/hudSurface.js +11 -3
- package/kits/hub-game/code/client/hudTree.js +7 -4
- package/kits/hub-game/code/client/idle.js +21 -3
- package/kits/hub-game/code/client/invites.js +24 -3
- package/kits/hub-game/code/client/keys.js +15 -0
- package/kits/hub-game/code/client/labelsNear.js +8 -1
- package/kits/hub-game/code/client/layoutCache.js +57 -8
- package/kits/hub-game/code/client/loadingCover.js +53 -4
- package/kits/hub-game/code/client/menuIcons.js +15 -0
- package/kits/hub-game/code/client/menuRows.js +8 -2
- package/kits/hub-game/code/client/menuSurface.js +102 -0
- package/kits/hub-game/code/client/menuTree.js +135 -0
- package/kits/hub-game/code/client/modelLook.js +41 -0
- package/kits/hub-game/code/client/pickerSurface.js +152 -0
- package/kits/hub-game/code/client/pickerTree.js +163 -0
- package/kits/hub-game/code/client/pushVisit.js +4 -2
- package/kits/hub-game/code/client/quality.js +188 -29
- package/kits/hub-game/code/client/qualityEntry.js +10 -1
- package/kits/hub-game/code/client/quickChatSurface.js +222 -0
- package/kits/hub-game/code/client/quickChatTree.js +201 -0
- package/kits/hub-game/code/client/rehello.js +75 -0
- package/kits/hub-game/code/client/renderVisibility.js +17 -0
- package/kits/hub-game/code/client/replay.js +118 -0
- package/kits/hub-game/code/client/role.js +3 -0
- package/kits/hub-game/code/client/safeLayout.js +441 -56
- package/kits/hub-game/code/client/safeStyle.js +13 -10
- package/kits/hub-game/code/client/say.js +2 -0
- package/kits/hub-game/code/client/soundSurface.js +77 -0
- package/kits/hub-game/code/client/soundTree.js +74 -0
- package/kits/hub-game/code/client/soundscape.js +12 -9
- package/kits/hub-game/code/client/soundscapeCues.js +1 -1
- package/kits/hub-game/code/client/state.js +67 -1
- package/kits/hub-game/code/client/stuckSurface.js +76 -0
- package/kits/hub-game/code/client/stuckTree.js +67 -0
- package/kits/hub-game/code/client/talk.js +42 -12
- package/kits/hub-game/code/client/talkTree.js +4 -2
- package/kits/hub-game/code/client/textAskSurface.js +147 -0
- package/kits/hub-game/code/client/textAskTree.js +67 -0
- package/kits/hub-game/code/client/tiers.js +252 -27
- package/kits/hub-game/code/client/together.js +4 -1
- package/kits/hub-game/code/client/uiDom.js +86 -8
- package/kits/hub-game/code/client/uiTree.js +33 -4
- package/kits/hub-game/code/client/vehicle.js +75 -52
- package/kits/hub-game/code/client/weakestTier.js +75 -31
- package/kits/hub-game/code/client/wear.js +159 -5
- package/kits/hub-game/code/client/worldLabels.js +215 -26
- package/kits/hub-game/code/companionSpec.js +4 -2
- package/kits/hub-game/code/server/act.js +3 -0
- package/kits/hub-game/code/server/actGate.js +83 -0
- package/kits/hub-game/code/server/actions.js +71 -15
- package/kits/hub-game/code/server/actors.js +20 -5
- package/kits/hub-game/code/server/analytics.js +40 -15
- package/kits/hub-game/code/server/ask.js +39 -3
- package/kits/hub-game/code/server/ballot.js +167 -4
- package/kits/hub-game/code/server/celebrate.js +64 -0
- package/kits/hub-game/code/server/companion.js +17 -2
- package/kits/hub-game/code/server/decor.js +11 -2
- package/kits/hub-game/code/server/disguise.js +63 -0
- package/kits/hub-game/code/server/doorAnalytics.js +2 -5
- package/kits/hub-game/code/server/earned.js +6 -2
- package/kits/hub-game/code/server/friendBests.js +13 -4
- package/kits/hub-game/code/server/friendsAmong.js +67 -8
- package/kits/hub-game/code/server/grab.js +12 -2
- package/kits/hub-game/code/server/heldOffers.js +142 -0
- package/kits/hub-game/code/server/holdShow.js +98 -0
- package/kits/hub-game/code/server/hub.js +854 -45
- package/kits/hub-game/code/server/idle.js +110 -9
- package/kits/hub-game/code/server/index.js +9 -0
- package/kits/hub-game/code/server/labels.js +13 -3
- package/kits/hub-game/code/server/loadAbandon.js +2 -5
- package/kits/hub-game/code/server/manifest.js +94 -6
- package/kits/hub-game/code/server/menu.js +26 -3
- package/kits/hub-game/code/server/npcs.js +55 -9
- package/kits/hub-game/code/server/observe.js +67 -6
- package/kits/hub-game/code/server/players.js +8 -1
- package/kits/hub-game/code/server/replay.js +135 -0
- package/kits/hub-game/code/server/storageLimit.js +4 -1
- package/kits/hub-game/code/server/townDay.js +74 -0
- package/kits/hub-game/code/server/trackQueue.js +29 -0
- package/kits/hub-game/code/server/vehicle.js +3 -0
- package/kits/hub-game/code/server/vis.js +26 -4
- package/kits/hub-game/code/server/wallet.js +677 -0
- package/kits/hub-game/code/server/wear.js +13 -3
- package/kits/hub-game/code/server/writerLease.js +191 -0
- package/kits/hub-game/code/shared/act.js +1 -1
- package/kits/hub-game/code/shared/expression.js +6 -0
- package/kits/hub-game/code/shared/replay.js +37 -0
- package/kits/hub-game/code/systems/hub.js +437 -57
- package/kits/hub-game/docs/analytics.md +20 -3
- package/kits/hub-game/docs/contract.md +942 -99
- package/kits/hub-game/docs/home-pieces.md +5 -6
- package/kits/hub-game/docs/observed-progress.md +49 -1
- package/kits/hub-game/docs/vehicle-preset.md +23 -0
- package/kits/hub-game/index.html +1 -0
- package/kits/hub-game/models/hats/baker-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/bat-clip.pxmodel +3 -3
- package/kits/hub-game/models/hats/beekeeper.pxmodel +3 -3
- package/kits/hub-game/models/hats/cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/captain.pxmodel +3 -3
- package/kits/hub-game/models/hats/chef-toque.pxmodel +3 -3
- package/kits/hub-game/models/hats/crooked-top.pxmodel +3 -3
- package/kits/hub-game/models/hats/delivery-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/fire-helmet.pxmodel +3 -3
- package/kits/hub-game/models/hats/flower-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/foam-crown.pxmodel +3 -3
- package/kits/hub-game/models/hats/hard-hat.pxmodel +3 -3
- package/kits/hub-game/models/hats/lantern.pxmodel +3 -3
- package/kits/hub-game/models/hats/laurel.pxmodel +3 -3
- package/kits/hub-game/models/hats/lighthouse.pxmodel +3 -3
- package/kits/hub-game/models/hats/nurse-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/police-cap.pxmodel +3 -3
- package/kits/hub-game/models/hats/sailor.pxmodel +3 -3
- package/kits/hub-game/models/hats/souwester.pxmodel +3 -3
- package/kits/hub-game/models/hats/straw.pxmodel +3 -3
- package/kits/hub-game/models/hats/sunflower.pxmodel +3 -3
- package/kits/hub-game/models/hats/sweatband.pxmodel +3 -3
- package/kits/hub-game/models/hats/teacher-beret.pxmodel +3 -3
- package/kits/hub-game/models/hats/witch.pxmodel +3 -3
- package/kits/hub-game/models/hold-show/daisy.pxmodel +231 -0
- package/kits/hub-game/models/hold-show/moonflower.pxmodel +171 -0
- package/kits/hub-game/models/hold-show/rose.pxmodel +191 -0
- package/kits/hub-game/models/hold-show/square/daisy.pxmodel +233 -0
- package/kits/hub-game/models/hold-show/square/moonflower.pxmodel +173 -0
- package/kits/hub-game/models/hold-show/square/rose.pxmodel +193 -0
- package/kits/hub-game/models/hold-show/square/sunflower.pxmodel +313 -0
- package/kits/hub-game/models/hold-show/square/tulip.pxmodel +133 -0
- package/kits/hub-game/models/hold-show/sunflower.pxmodel +311 -0
- package/kits/hub-game/models/hold-show/tulip.pxmodel +131 -0
- package/kits/hub-game/package-lock.json +3 -3
- package/kits/hub-game/package.json +4 -3
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +1 -0
- package/kits/hub-game/scripts/fixtures/hud-surface.json +12 -12
- package/kits/hub-game/scripts/fixtures/talk-surface.json +8 -8
- package/kits/hub-game/scripts/gen-hats.mjs +1 -1
- package/kits/hub-game/scripts/gen-hold-show.mjs +27 -0
- package/kits/hub-game/scripts/pack.mjs +89 -23
- package/kits/hub-game/scripts/test-act-client.mjs +5 -0
- package/kits/hub-game/scripts/test-act-core.mjs +32 -0
- package/kits/hub-game/scripts/test-act-gate.mjs +186 -0
- package/kits/hub-game/scripts/test-action-rail-crowded-dom.mjs +7 -1
- package/kits/hub-game/scripts/test-action-rail-default-dom.mjs +102 -0
- package/kits/hub-game/scripts/test-action-rail-never-silent-dom.mjs +50 -0
- package/kits/hub-game/scripts/test-action-rail-surface.mjs +368 -0
- package/kits/hub-game/scripts/test-action-rail-town-jobs-dom.mjs +118 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +5 -3
- package/kits/hub-game/scripts/test-actions.mjs +24 -0
- package/kits/hub-game/scripts/test-actors.mjs +19 -0
- package/kits/hub-game/scripts/test-again-corner-dom.mjs +59 -0
- package/kits/hub-game/scripts/test-analytics.mjs +80 -1
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +25 -8
- package/kits/hub-game/scripts/test-ask-client.mjs +9 -0
- package/kits/hub-game/scripts/test-ask-surface.mjs +188 -0
- package/kits/hub-game/scripts/test-attention.mjs +43 -1
- package/kits/hub-game/scripts/test-ballot-sheet-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-ballot-surface.mjs +276 -0
- package/kits/hub-game/scripts/test-ballot.mjs +420 -3
- package/kits/hub-game/scripts/test-ban-join.mjs +1 -1
- package/kits/hub-game/scripts/test-celebrate-client.mjs +62 -0
- package/kits/hub-game/scripts/test-celebrate.mjs +116 -0
- package/kits/hub-game/scripts/test-chat.mjs +73 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +203 -21
- package/kits/hub-game/scripts/test-companion.mjs +110 -3
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +57 -10
- package/kits/hub-game/scripts/test-corner-surface.mjs +268 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +59 -3
- package/kits/hub-game/scripts/test-decor.mjs +27 -0
- package/kits/hub-game/scripts/test-device-class.mjs +4 -1
- package/kits/hub-game/scripts/test-disguise-client.mjs +281 -0
- package/kits/hub-game/scripts/test-disguise.mjs +176 -0
- package/kits/hub-game/scripts/test-dock-surface.mjs +404 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +1 -1
- package/kits/hub-game/scripts/test-door-stay-client.mjs +602 -0
- package/kits/hub-game/scripts/test-door-stay.mjs +613 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +119 -0
- package/kits/hub-game/scripts/test-emote-surface.mjs +616 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +39 -4
- package/kits/hub-game/scripts/test-friend-bests.mjs +38 -12
- package/kits/hub-game/scripts/test-ghost-click-dom.mjs +75 -0
- package/kits/hub-game/scripts/test-grab-client.mjs +29 -2
- package/kits/hub-game/scripts/test-grab-orbit.mjs +260 -11
- package/kits/hub-game/scripts/test-grab.mjs +10 -1
- package/kits/hub-game/scripts/test-hats.mjs +28 -0
- package/kits/hub-game/scripts/test-held-offers.mjs +394 -0
- package/kits/hub-game/scripts/test-high-only.mjs +3 -3
- package/kits/hub-game/scripts/test-hold-show-client.mjs +175 -0
- package/kits/hub-game/scripts/test-hold-show.mjs +355 -0
- package/kits/hub-game/scripts/test-hub-controls.mjs +3 -1
- package/kits/hub-game/scripts/test-hub-idle.mjs +348 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +21 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +147 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +260 -5
- package/kits/hub-game/scripts/test-hud-clear.mjs +83 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +2 -1
- package/kits/hub-game/scripts/test-idle.mjs +160 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +53 -0
- package/kits/hub-game/scripts/test-labels.mjs +11 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +20 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +2 -2
- package/kits/hub-game/scripts/test-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +55 -6
- package/kits/hub-game/scripts/test-menu-surface.mjs +236 -0
- package/kits/hub-game/scripts/test-npcs.mjs +128 -0
- package/kits/hub-game/scripts/test-observed.mjs +171 -3
- package/kits/hub-game/scripts/test-pack.mjs +166 -0
- package/kits/hub-game/scripts/test-picker-surface.mjs +321 -0
- package/kits/hub-game/scripts/test-placeat-server.mjs +395 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
- package/kits/hub-game/scripts/test-pointer-clear-dom.mjs +82 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +184 -6
- package/kits/hub-game/scripts/test-push-visit.mjs +9 -0
- package/kits/hub-game/scripts/test-quality.mjs +312 -9
- package/kits/hub-game/scripts/test-quick-chat-surface.mjs +511 -0
- package/kits/hub-game/scripts/test-rehello.mjs +237 -0
- package/kits/hub-game/scripts/test-rejoin-yaw.mjs +138 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +13 -7
- package/kits/hub-game/scripts/test-relations-refresh.mjs +90 -2
- package/kits/hub-game/scripts/test-replay-client.mjs +110 -0
- package/kits/hub-game/scripts/test-replay.mjs +178 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +13 -0
- package/kits/hub-game/scripts/test-resume-pose-server.mjs +43 -5
- package/kits/hub-game/scripts/test-resync.mjs +13 -0
- package/kits/hub-game/scripts/test-role-client.mjs +10 -3
- package/kits/hub-game/scripts/test-safe-act.mjs +233 -0
- package/kits/hub-game/scripts/test-safe-caption.mjs +364 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +79 -0
- package/kits/hub-game/scripts/test-safe-prompt.mjs +163 -0
- package/kits/hub-game/scripts/test-sound-surface.mjs +256 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +85 -2
- package/kits/hub-game/scripts/test-stuck-surface.mjs +174 -0
- package/kits/hub-game/scripts/test-stuck.mjs +31 -0
- package/kits/hub-game/scripts/test-talk-surface.mjs +23 -6
- package/kits/hub-game/scripts/test-talk-walk-dom.mjs +123 -0
- package/kits/hub-game/scripts/test-text-ask-surface.mjs +273 -0
- package/kits/hub-game/scripts/test-tiers.mjs +453 -3
- package/kits/hub-game/scripts/test-toast-no-row-dom.mjs +71 -0
- package/kits/hub-game/scripts/test-together.mjs +11 -0
- package/kits/hub-game/scripts/test-town-day.mjs +90 -0
- package/kits/hub-game/scripts/test-track-queue.mjs +64 -0
- package/kits/hub-game/scripts/test-try-on.mjs +39 -0
- package/kits/hub-game/scripts/test-ui-dom-dom.mjs +49 -2
- package/kits/hub-game/scripts/test-ui-tree.mjs +28 -0
- package/kits/hub-game/scripts/test-vehicle-client.mjs +77 -1
- package/kits/hub-game/scripts/test-vis.mjs +145 -0
- package/kits/hub-game/scripts/test-wallet.mjs +650 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +135 -1
- package/kits/hub-game/scripts/test-world-labels.mjs +380 -0
- package/kits/hub-game/scripts/test-writer-lease-server.mjs +234 -0
- package/kits/hub-game/scripts/test-writer-lease.mjs +281 -0
- package/kits/hub-game/scripts/writer-storage-fixture.mjs +37 -0
- package/kits/hub-game/tools/hubScene/export.mjs +6 -5
- package/kits/hub-game/tools/hubScene/hubdata.mjs +10 -0
- package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +48 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +21 -3
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/resumeGate.js +49 -2
- package/kits/multiplayer-3d/code/server/ownership.js +25 -6
- package/kits/multiplayer-3d/code/server/world.js +19 -4
- package/kits/multiplayer-3d/code/systems/multiplayer.js +67 -11
- package/kits/multiplayer-3d/package-lock.json +1 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-ground-half.mjs +56 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +54 -3
- package/kits/multiplayer-3d/scripts/test-owned-moves.mjs +190 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +191 -5
- package/kits/multiplayer-3d/scripts/test-resync-reconnect.mjs +68 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +10 -2
- package/kits/physics-3d/CLAUDE.md +14 -0
- package/kits/physics-3d/behaviors/Player.jsx +39 -3
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-model-cache.md +109 -0
- package/kits/physics-3d/docs/engine-player.md +76 -0
- package/kits/physics-3d/docs/engine-skip-work.md +16 -0
- package/kits/physics-3d/docs/pxmodel-format.md +5 -1
- package/kits/physics-3d/engine3d/gait.js +16 -8
- package/kits/physics-3d/engine3d/groundsize.js +23 -0
- package/kits/physics-3d/engine3d/kithooks.js +50 -0
- package/kits/physics-3d/engine3d/look.js +110 -17
- package/kits/physics-3d/engine3d/lookbake.js +19 -1
- package/kits/physics-3d/engine3d/materialpresets.js +3 -2
- package/kits/physics-3d/engine3d/modelcache.js +280 -0
- package/kits/physics-3d/engine3d/modelcachedigest.js +37 -0
- package/kits/physics-3d/engine3d/modelcachegate.js +69 -0
- package/kits/physics-3d/engine3d/modelrefs.js +13 -0
- package/kits/physics-3d/engine3d/optimize.js +20 -9
- package/kits/physics-3d/engine3d/playerRun.js +26 -1
- package/kits/physics-3d/engine3d/pxmodel.js +7 -3
- package/kits/physics-3d/engine3d/templatecache.js +722 -0
- package/kits/physics-3d/engine3d/world3d.js +211 -17
- package/kits/physics-3d/package-lock.json +1 -1
- package/kits/physics-3d/package.json +2 -1
- package/kits/physics-3d/play/behaviors/Player.js +43 -3
- package/kits/physics-3d/scripts/render.mjs +56 -8
- package/kits/physics-3d/scripts/template-cache-fixtures.mjs +37 -0
- package/kits/physics-3d/scripts/template-cache-v1-bytes.json +49 -0
- package/kits/physics-3d/scripts/test-gait.mjs +53 -9
- package/kits/physics-3d/scripts/test-ground-half.mjs +120 -0
- package/kits/physics-3d/scripts/test-model-cache.mjs +600 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1 -0
- package/kits/physics-3d/scripts/test-sleeping-models.mjs +384 -0
- package/kits/physics-3d/scripts/test-template-cache-minified.mjs +106 -0
- package/kits/physics-3d/scripts/test-template-cache.mjs +519 -0
- package/kits/physics-3d/scripts/test-wall-slide.mjs +272 -0
- package/kits/physics-3d/systems/physics3d.js +51 -2
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +3 -0
- package/package.json +2 -2
- package/vendor/three/examples/jsm/libs/fflate.module.js +2672 -0
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
// Focused, renderer-free template round trips, including the shader closures.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { changeTemplate, templateArray, templateGroups } from './template-cache-fixtures.mjs';
|
|
5
|
+
import { register } from 'node:module';
|
|
6
|
+
import * as THREE from 'three';
|
|
7
|
+
import { deflateSync, inflateSync } from 'three/examples/jsm/libs/fflate.module.js';
|
|
8
|
+
|
|
9
|
+
const hooks = `
|
|
10
|
+
import { existsSync } from 'node:fs';
|
|
11
|
+
import { fileURLToPath } from 'node:url';
|
|
12
|
+
export async function resolve(specifier, context, next) {
|
|
13
|
+
const parent = context.parentURL ?? '';
|
|
14
|
+
if (specifier.startsWith('@imports/castle.physics-2d/')) {
|
|
15
|
+
specifier = parent.replace(/\\/kits\\/.*/, '/kits/physics-2d/') + specifier.slice(27);
|
|
16
|
+
}
|
|
17
|
+
if ((specifier.startsWith('.') || specifier.startsWith('file:')) && parent.includes('/kits/') && !/\\.(m?js|jsx|json)$/.test(specifier)) {
|
|
18
|
+
const base = new URL(specifier, parent).href;
|
|
19
|
+
for (const ext of ['.js', '.jsx']) if (existsSync(fileURLToPath(base + ext))) return next(base + ext, context);
|
|
20
|
+
}
|
|
21
|
+
return next(specifier, context);
|
|
22
|
+
}`;
|
|
23
|
+
register(`data:text/javascript,${encodeURIComponent(hooks)}`);
|
|
24
|
+
const { buildModelNode, parseModelCached } = await import('../engine3d/pxmodel.js');
|
|
25
|
+
const { serializeTemplate, deserializeTemplate, templateCacheKey, TEMPLATE_CACHE_VERSION, TEMPLATE_CACHE_MAX_PAYLOAD } = await import('../engine3d/templatecache.js');
|
|
26
|
+
const { setLookEnabled } = await import('../engine3d/look.js');
|
|
27
|
+
const { bakingLater } = await import('../engine3d/look.js');
|
|
28
|
+
const { makeLookBake, stepLookBake } = await import('../engine3d/lookbake.js');
|
|
29
|
+
const { copyModel, dropEmptyGroups } = await import('../engine3d/optimize.js');
|
|
30
|
+
const { files, freshModel, CART, MIXED } = await import('./look-baseline.mjs');
|
|
31
|
+
const { beginTemplateCapture, endTemplateCapture } = await import('../engine3d/kithooks.js');
|
|
32
|
+
const kitHooks = await import('../engine3d/kithooks.js');
|
|
33
|
+
// Measured bytes from the original phase-1 codec, same models and build options.
|
|
34
|
+
const beforeBytes = JSON.parse(fs.readFileSync(new URL('./template-cache-v1-bytes.json', import.meta.url), 'utf8'));
|
|
35
|
+
function capture(build) {
|
|
36
|
+
beginTemplateCapture();
|
|
37
|
+
try {
|
|
38
|
+
return build();
|
|
39
|
+
} finally {
|
|
40
|
+
endTemplateCapture();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const fields = ['name', 'visible', 'castShadow', 'receiveShadow', 'renderOrder', 'frustumCulled', 'matrixAutoUpdate', 'matrixWorldAutoUpdate', 'matrixWorldNeedsUpdate'];
|
|
46
|
+
const runtimeMaterial = new Set(['id', 'uuid', 'version', '_listeners', 'onBeforeCompile', 'customProgramCacheKey', 'onBeforeRender']);
|
|
47
|
+
function nodesOf(root) {
|
|
48
|
+
const nodes = [];
|
|
49
|
+
root.traverse((node) => nodes.push(node));
|
|
50
|
+
return nodes;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function attribute(attribute) {
|
|
54
|
+
if (!attribute) return null;
|
|
55
|
+
return {
|
|
56
|
+
type: attribute.constructor.name, itemSize: attribute.itemSize, normalized: attribute.normalized,
|
|
57
|
+
name: attribute.name, usage: attribute.usage, gpuType: attribute.gpuType,
|
|
58
|
+
meshPerAttribute: attribute.meshPerAttribute,
|
|
59
|
+
arrayType: attribute.array.constructor.name,
|
|
60
|
+
bytes: Buffer.from(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function geometry(geometry) {
|
|
65
|
+
return {
|
|
66
|
+
class: geometry.constructor.name, type: geometry.type, name: geometry.name, parameters: geometry.parameters, morphTargetsRelative: geometry.morphTargetsRelative,
|
|
67
|
+
attributes: Object.fromEntries(Object.entries(geometry.attributes).map(([key, value]) => [key, attribute(value)])),
|
|
68
|
+
index: attribute(geometry.index), groups: geometry.groups, drawRange: geometry.drawRange,
|
|
69
|
+
userData: geometry.userData, box: geometry.boundingBox, sphere: geometry.boundingSphere,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function material(material) {
|
|
74
|
+
const lib = material.isMeshBasicMaterial ? THREE.ShaderLib.basic : THREE.ShaderLib.physical;
|
|
75
|
+
const shader = { vertexShader: lib.vertexShader, fragmentShader: lib.fragmentShader, uniforms: {} };
|
|
76
|
+
material.onBeforeCompile(shader, {});
|
|
77
|
+
// Exercise the outline's draw callback and its shared uniform objects.
|
|
78
|
+
material.onBeforeRender({ getCurrentViewport: (out) => out.set(0, 0, 100, 1800), getPixelRatio: () => 2 });
|
|
79
|
+
return {
|
|
80
|
+
type: material.constructor.name,
|
|
81
|
+
props: Object.fromEntries(Object.entries(material).filter(([key]) => !runtimeMaterial.has(key))),
|
|
82
|
+
key: material.customProgramCacheKey(), shader,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function equalTrees(before, after, what) {
|
|
87
|
+
assert.ok(after, `${what}: decoded`);
|
|
88
|
+
const a = nodesOf(before);
|
|
89
|
+
const b = nodesOf(after);
|
|
90
|
+
const indices = new Map(a.map((node, index) => [node, index]));
|
|
91
|
+
const decodedIndices = new Map(b.map((node, index) => [node, index]));
|
|
92
|
+
const geometryIds = new Map();
|
|
93
|
+
const materialIds = new Map();
|
|
94
|
+
const reverseGeometries = new Map();
|
|
95
|
+
const reverseMaterials = new Map();
|
|
96
|
+
const arrayIds = new Map();
|
|
97
|
+
const reverseArrays = new Map();
|
|
98
|
+
const shared = (source, decoded, forward, reverse) => {
|
|
99
|
+
if (forward.has(source)) assert.equal(decoded, forward.get(source), `${what}: sharing retained`);
|
|
100
|
+
if (reverse.has(decoded)) assert.equal(source, reverse.get(decoded), `${what}: distinct resources retained`);
|
|
101
|
+
forward.set(source, decoded);
|
|
102
|
+
reverse.set(decoded, source);
|
|
103
|
+
};
|
|
104
|
+
const data = (value, ids) => {
|
|
105
|
+
if (ids.has(value)) return { node: ids.get(value) };
|
|
106
|
+
if (value?.isObject3D) return { detached: value.userData.partId, position: value.position.toArray(), quaternion: value.quaternion.toArray(), scale: value.scale.toArray(), children: value.children.map((node) => data(node, ids)) };
|
|
107
|
+
if (value instanceof Map) return { map: [...value].map(([key, entry]) => [key, data(entry, ids)]) };
|
|
108
|
+
if (Array.isArray(value)) return value.map((entry) => data(entry, ids));
|
|
109
|
+
if (value && Object.getPrototypeOf(value) === Object.prototype) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, data(entry, ids)]));
|
|
110
|
+
return value;
|
|
111
|
+
};
|
|
112
|
+
assert.equal(a.length, b.length, `${what}: node count`);
|
|
113
|
+
a.forEach((node, index) => {
|
|
114
|
+
const decoded = b[index];
|
|
115
|
+
const label = `${what}: node ${index}`;
|
|
116
|
+
assert.equal(node.constructor.name, decoded.constructor.name, `${label} class`);
|
|
117
|
+
assert.equal(node.type, decoded.type, `${label} type`);
|
|
118
|
+
assert.deepEqual(node.children.map((child) => indices.get(child)), decoded.children.map((child) => decodedIndices.get(child)), `${label} children`);
|
|
119
|
+
for (const field of fields) assert.deepEqual(decoded[field], node[field], `${label} ${field}`);
|
|
120
|
+
for (const field of ['position', 'quaternion', 'scale', 'up', 'matrix', 'matrixWorld']) assert.deepEqual(decoded[field].toArray(), node[field].toArray(), `${label} ${field}`);
|
|
121
|
+
assert.deepEqual(decoded.rotation.toArray(), node.rotation.toArray(), `${label} Euler angles`);
|
|
122
|
+
assert.equal(decoded.layers.mask, node.layers.mask);
|
|
123
|
+
assert.deepEqual(data(decoded.userData, decodedIndices), data(node.userData, indices), `${label} userData`);
|
|
124
|
+
if (node.userData.modelParts) {
|
|
125
|
+
assert.ok(decoded.userData.modelParts instanceof Map);
|
|
126
|
+
for (const [id, part] of decoded.userData.modelParts) assert.equal(part.userData.partId, id);
|
|
127
|
+
}
|
|
128
|
+
assert.equal(decoded.raycast.toString(), node.raycast.toString(), `${label}: raycast behavior`);
|
|
129
|
+
if (node.userData.lookOutline && (node.constructor.name === 'OutlineMesh' || Object.hasOwn(node, 'raycast'))) {
|
|
130
|
+
const hits = [];
|
|
131
|
+
decoded.raycast({}, hits);
|
|
132
|
+
assert.deepEqual(hits, [], `${label}: outlines cannot be picked`);
|
|
133
|
+
}
|
|
134
|
+
if (!node.isMesh) return;
|
|
135
|
+
shared(node.geometry, decoded.geometry, geometryIds, reverseGeometries);
|
|
136
|
+
const attributes = Object.entries(node.geometry.attributes).map(([key, value]) => [value, decoded.geometry.attributes[key]]);
|
|
137
|
+
attributes.push([node.geometry.index, decoded.geometry.index]);
|
|
138
|
+
if (node.isInstancedMesh) attributes.push([node.instanceMatrix, decoded.instanceMatrix], [node.instanceColor, decoded.instanceColor]);
|
|
139
|
+
for (const [source, target] of attributes) if (source) shared(source.array, target.array, arrayIds, reverseArrays);
|
|
140
|
+
assert.deepEqual(geometry(decoded.geometry), geometry(node.geometry), `${label} geometry`);
|
|
141
|
+
assert.equal(Array.isArray(node.material), Array.isArray(decoded.material));
|
|
142
|
+
const sourceMaterials = [node.material].flat();
|
|
143
|
+
const decodedMaterials = [decoded.material].flat();
|
|
144
|
+
assert.equal(sourceMaterials.length, decodedMaterials.length);
|
|
145
|
+
sourceMaterials.forEach((source, at) => {
|
|
146
|
+
shared(source, decodedMaterials[at], materialIds, reverseMaterials);
|
|
147
|
+
assert.deepEqual(material(decodedMaterials[at]), material(source), `${label} material ${at}`);
|
|
148
|
+
});
|
|
149
|
+
if (node.isInstancedMesh) {
|
|
150
|
+
assert.equal(decoded.count, node.count);
|
|
151
|
+
assert.deepEqual(attribute(decoded.instanceMatrix), attribute(node.instanceMatrix), `${label} instance matrix`);
|
|
152
|
+
assert.deepEqual(attribute(decoded.instanceColor), attribute(node.instanceColor), `${label} instance color`);
|
|
153
|
+
assert.deepEqual(decoded.boundingBox, node.boundingBox);
|
|
154
|
+
assert.deepEqual(decoded.boundingSphere, node.boundingSphere);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function roundTrip(root, what) {
|
|
160
|
+
const { bytes, reason } = serializeTemplate(root);
|
|
161
|
+
assert.ok(bytes, `${what}: refused (${reason})`);
|
|
162
|
+
const decoded = deserializeTemplate(bytes);
|
|
163
|
+
equalTrees(root, decoded, what);
|
|
164
|
+
// Restored hooks can themselves be serialized, including their ordering.
|
|
165
|
+
const again = serializeTemplate(decoded);
|
|
166
|
+
assert.ok(again.bytes, `${what}: reserialize (${again.reason})`);
|
|
167
|
+
return { bytes, decoded };
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function edgeCases() {
|
|
171
|
+
const root = new THREE.Group();
|
|
172
|
+
root.name = 'exact';
|
|
173
|
+
root.rotation.set(8 * Math.PI + 0.17, -0.2, 0.4, 'ZYX');
|
|
174
|
+
root.position.set(-1.25, 2, 3);
|
|
175
|
+
root.matrixAutoUpdate = false;
|
|
176
|
+
root.matrix.makeTranslation(4, 5, 6);
|
|
177
|
+
const shape = new THREE.BufferGeometry();
|
|
178
|
+
shape.setAttribute('position', new THREE.BufferAttribute(new Float32Array([0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0]), 3));
|
|
179
|
+
shape.setAttribute('custom', new THREE.InstancedBufferAttribute(new Uint16Array([1, 2, 3, 4]), 1, true, 2));
|
|
180
|
+
shape.setIndex(new THREE.BufferAttribute(new Uint32Array([0, 1, 2]), 1));
|
|
181
|
+
shape.setAttribute('samePositions', new THREE.BufferAttribute(shape.attributes.position.array, 3));
|
|
182
|
+
const typedPositions = new THREE.Float32BufferAttribute(shape.attributes.position.array, 3);
|
|
183
|
+
typedPositions.array = shape.attributes.position.array;
|
|
184
|
+
shape.setAttribute('typedPositions', typedPositions);
|
|
185
|
+
shape.setAttribute('equalPositions', new THREE.BufferAttribute(shape.attributes.position.array.slice(), 3));
|
|
186
|
+
shape.setAttribute('wideIntegers', new THREE.BufferAttribute(new Uint32Array([65536, 0, 0xffffffff, 1]), 1));
|
|
187
|
+
// Preserve distinct NaN bit patterns, +0 and -0 exactly through dedupe/deflate.
|
|
188
|
+
shape.setAttribute('floatBits', new THREE.BufferAttribute(new Float32Array(new Uint32Array([0x7fc00001, 0x7fc00002, 0, 0x80000000]).buffer), 1));
|
|
189
|
+
shape.addGroup(0, 3, 1);
|
|
190
|
+
shape.setDrawRange(0, 3);
|
|
191
|
+
shape.computeBoundingBox();
|
|
192
|
+
shape.computeBoundingSphere();
|
|
193
|
+
shape.userData = { branchTips: [new THREE.Vector3(1, 2, 3)], triFaces: [0], nonfinite: [Infinity, NaN, -0], missing: undefined };
|
|
194
|
+
const finish = new THREE.MeshPhysicalMaterial({ color: '#123456', roughness: 0.31, metalness: 0.72, transparent: true, opacity: 0.4, flatShading: true, side: THREE.DoubleSide, emissive: '#345678' });
|
|
195
|
+
const part = new THREE.Group();
|
|
196
|
+
part.userData.partId = 'body';
|
|
197
|
+
part.userData.animation = { parts: ['body'], motion: {}, clips: {} };
|
|
198
|
+
root.userData.modelParts = new Map([['body', part]]);
|
|
199
|
+
root.userData.plain = Object.assign(Object.create(null), { author: 'test' });
|
|
200
|
+
root.add(part);
|
|
201
|
+
part.add(new THREE.Mesh(new THREE.BoxGeometry(1, 2, 3), finish), new THREE.Mesh(shape, [finish, finish]), new THREE.Mesh(shape, finish), new THREE.Mesh(shape.clone(), finish.clone()));
|
|
202
|
+
const otherGeometry = new THREE.BufferGeometry();
|
|
203
|
+
otherGeometry.setAttribute('position', new THREE.BufferAttribute(shape.attributes.position.array, 3));
|
|
204
|
+
part.add(new THREE.Mesh(otherGeometry, finish));
|
|
205
|
+
const instanced = new THREE.InstancedMesh(shape, finish, 3);
|
|
206
|
+
instanced.count = 2;
|
|
207
|
+
instanced.setColorAt(0, new THREE.Color('#ff0000'));
|
|
208
|
+
instanced.setMatrixAt(1, new THREE.Matrix4().makeTranslation(1, 2, 3));
|
|
209
|
+
instanced.computeBoundingBox();
|
|
210
|
+
instanced.computeBoundingSphere();
|
|
211
|
+
root.add(instanced);
|
|
212
|
+
const restored = roundTrip(root, 'typed metadata, arrays, transforms, material arrays and sharing').decoded;
|
|
213
|
+
const decodedShape = nodesOf(restored).find((node) => node.geometry?.attributes.samePositions)?.geometry;
|
|
214
|
+
assert.equal(decodedShape.attributes.position.array, decodedShape.attributes.samePositions.array, 'same source array stays shared');
|
|
215
|
+
assert.equal(decodedShape.attributes.position.array, decodedShape.attributes.typedPositions.array, 'typed subclasses preserve shared arrays');
|
|
216
|
+
assert.notEqual(decodedShape.attributes.position.array, decodedShape.attributes.equalPositions.array, 'dedupe storage does not merge distinct arrays');
|
|
217
|
+
decodedShape.attributes.equalPositions.array[0] = 99;
|
|
218
|
+
assert.equal(decodedShape.attributes.position.array[0], 0, 'mutating one decoded attribute leaves the other intact');
|
|
219
|
+
decodedShape.attributes.samePositions.array[0] = 7;
|
|
220
|
+
assert.equal(decodedShape.attributes.position.array[0], 7, 'mutating one alias updates the shared array');
|
|
221
|
+
const plain = new THREE.Group();
|
|
222
|
+
const empty = serializeTemplate(plain).bytes;
|
|
223
|
+
assert.equal(deserializeTemplate(empty.slice(0, -1)), null);
|
|
224
|
+
assert.equal(deserializeTemplate(new ArrayBuffer(0)), null);
|
|
225
|
+
const mismatch = empty.slice(0);
|
|
226
|
+
new DataView(mismatch).setUint32(4, 999, true);
|
|
227
|
+
assert.equal(deserializeTemplate(mismatch), null);
|
|
228
|
+
// A syntactically valid header with an invalid graph must also miss.
|
|
229
|
+
const malformed = (change) => {
|
|
230
|
+
const view = new DataView(empty);
|
|
231
|
+
const header = JSON.parse(new TextDecoder().decode(new Uint8Array(empty, 16, view.getUint32(8, true))));
|
|
232
|
+
change(header);
|
|
233
|
+
const json = new TextEncoder().encode(JSON.stringify(header));
|
|
234
|
+
const start = Math.ceil((16 + json.length) / 8) * 8;
|
|
235
|
+
const stored = new Uint8Array(empty, Math.ceil((16 + view.getUint32(8, true)) / 8) * 8);
|
|
236
|
+
const bytes = new ArrayBuffer(start + stored.length);
|
|
237
|
+
const prefix = new DataView(bytes);
|
|
238
|
+
[view.getUint32(0, true), TEMPLATE_CACHE_VERSION, json.length, stored.length].forEach((n, i) => prefix.setUint32(i * 4, n, true));
|
|
239
|
+
new Uint8Array(bytes, 16, json.length).set(json);
|
|
240
|
+
new Uint8Array(bytes, start).set(stored);
|
|
241
|
+
return bytes;
|
|
242
|
+
};
|
|
243
|
+
assert.equal(deserializeTemplate(malformed((header) => { header.revision = 'unknown'; })), null);
|
|
244
|
+
assert.equal(deserializeTemplate(malformed((header) => { header.tree[0].children = [0]; })), null);
|
|
245
|
+
assert.equal(deserializeTemplate(malformed((header) => { header.tree[0].position = ['array', 'Float64Array', 0, 100000]; })), null);
|
|
246
|
+
assert.equal(deserializeTemplate(malformed((header) => { header.tree[0].rotation = ['three', 'NoSuchClass', []]; })), null);
|
|
247
|
+
const refused = (reason) => assert.equal(serializeTemplate(root).reason, reason);
|
|
248
|
+
finish.map = new THREE.Texture();
|
|
249
|
+
refused('texture');
|
|
250
|
+
finish.map = null;
|
|
251
|
+
finish.onBeforeCompile = () => {};
|
|
252
|
+
refused('hooks not captured');
|
|
253
|
+
delete finish.onBeforeCompile;
|
|
254
|
+
root.userData.cycle = root.userData;
|
|
255
|
+
assert.match(serializeTemplate(root).reason, /cycle/);
|
|
256
|
+
delete root.userData.cycle;
|
|
257
|
+
shape.setAttribute('interleaved', new THREE.InterleavedBufferAttribute(new THREE.InterleavedBuffer(new Float32Array(6), 2), 2, 0));
|
|
258
|
+
refused('attribute');
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// Construct hostile entries with valid header structure; cap checks must happen
|
|
262
|
+
// before allocations from untrusted lengths, and a fixed out must never grow.
|
|
263
|
+
function decompressionChecks() {
|
|
264
|
+
const bytes = serializeTemplate(new THREE.Group()).bytes;
|
|
265
|
+
const view = new DataView(bytes);
|
|
266
|
+
const header = JSON.parse(new TextDecoder().decode(new Uint8Array(bytes, 16, view.getUint32(8, true))));
|
|
267
|
+
const stored = new Uint8Array(bytes, Math.ceil((16 + view.getUint32(8, true)) / 8) * 8);
|
|
268
|
+
const entry = (changes, payload) => {
|
|
269
|
+
const json = new TextEncoder().encode(JSON.stringify({ ...header, ...changes }));
|
|
270
|
+
const start = Math.ceil((16 + json.length) / 8) * 8;
|
|
271
|
+
const altered = new ArrayBuffer(start + payload.length);
|
|
272
|
+
const prefix = new DataView(altered);
|
|
273
|
+
[view.getUint32(0, true), TEMPLATE_CACHE_VERSION, json.length, payload.length].forEach((n, i) => prefix.setUint32(i * 4, n, true));
|
|
274
|
+
new Uint8Array(altered, 16, json.length).set(json);
|
|
275
|
+
new Uint8Array(altered, start).set(payload);
|
|
276
|
+
return altered;
|
|
277
|
+
};
|
|
278
|
+
assert.equal(TEMPLATE_CACHE_MAX_PAYLOAD, 16 * 1024 * 1024);
|
|
279
|
+
for (const payloadLength of [TEMPLATE_CACHE_MAX_PAYLOAD + 1, -1, 1.5, null]) {
|
|
280
|
+
assert.equal(deserializeTemplate(entry({ payloadLength }, stored)), null);
|
|
281
|
+
}
|
|
282
|
+
const expanded = new Uint8Array(4 * 1024 * 1024);
|
|
283
|
+
const hostile = entry({ payloadLength: 1, payloadCodec: 'deflate' }, deflateSync(expanded, { level: 1 }));
|
|
284
|
+
const NativeUint8Array = globalThis.Uint8Array;
|
|
285
|
+
const allocated = [];
|
|
286
|
+
// fflate's imported Uint8Array alias remains native; this observes the exact
|
|
287
|
+
// output buffer our codec passes to it, without instrumenting its internals.
|
|
288
|
+
globalThis.Uint8Array = new Proxy(NativeUint8Array, {
|
|
289
|
+
construct(target, args, newTarget) {
|
|
290
|
+
const array = Reflect.construct(target, args, newTarget);
|
|
291
|
+
if (typeof args[0] === 'number') allocated.push(array);
|
|
292
|
+
return array;
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
const start = performance.now();
|
|
296
|
+
try {
|
|
297
|
+
assert.equal(deserializeTemplate(hostile), null);
|
|
298
|
+
} finally {
|
|
299
|
+
globalThis.Uint8Array = NativeUint8Array;
|
|
300
|
+
}
|
|
301
|
+
assert.equal(allocated.length, 1, 'exactly one bounded output allocation');
|
|
302
|
+
assert.equal(allocated[0].byteLength, 1, '4 MiB expansion gets only a one-byte output buffer');
|
|
303
|
+
assert.ok(performance.now() - start < 2000, 'hostile expansion completes promptly');
|
|
304
|
+
// A valid prefix must also be rejected if fflate would silently truncate
|
|
305
|
+
// extra output. Checking only the returned (clamped) length would accept it.
|
|
306
|
+
const valid = header.payloadCodec === 'deflate' ? inflateSync(stored) : stored;
|
|
307
|
+
expanded.set(valid);
|
|
308
|
+
assert.equal(deserializeTemplate(entry({ payloadCodec: 'deflate' }, deflateSync(expanded, { level: 1 }))), null);
|
|
309
|
+
assert.equal(deserializeTemplate(entry({ payloadLength: valid.length + 1, payloadCodec: 'deflate' }, deflateSync(valid))), null);
|
|
310
|
+
// An empty compressed payload makes fflate hand back the zero-filled out
|
|
311
|
+
// buffer as is; that is not a payload of the declared length.
|
|
312
|
+
assert.equal(deserializeTemplate(entry({ payloadLength: valid.length, payloadCodec: 'deflate' }, new Uint8Array(0))), null);
|
|
313
|
+
console.log('decompression: 16 MiB cap; 4 MiB hostile expansion refused with exactly 1 byte allocated for output; overflow, short output and empty input refused');
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function artChecks() {
|
|
317
|
+
const file = 'models/art.pxmodel';
|
|
318
|
+
const refFile = 'imports/lib/models/art.pxmodel';
|
|
319
|
+
const ref = 'drawings/art.sprite';
|
|
320
|
+
const sprites = { [ref]: { kind: 'image', ready: false } };
|
|
321
|
+
const variants = [ref, { ref }, { front: ref, sides: { ref } }];
|
|
322
|
+
for (const art of variants) {
|
|
323
|
+
// No look/hook is necessary for the refusal: missing art still requests it.
|
|
324
|
+
const text = JSON.stringify({ format: 'pxmodel', look: false, parts: [{ id: 'box', art }] });
|
|
325
|
+
const model = parseModelCached(text);
|
|
326
|
+
for (const available of [{}, sprites]) {
|
|
327
|
+
const root = capture(() => buildModelNode(model, available, {}, file, [file], { optimize: true }));
|
|
328
|
+
assert.equal(serializeTemplate(root).reason, 'art', 'missing/loading direct art refuses');
|
|
329
|
+
dispose(root);
|
|
330
|
+
}
|
|
331
|
+
const outerText = JSON.stringify({ format: 'pxmodel', parts: [{ id: 'ref', kind: 'model', src: `@${refFile}` }] });
|
|
332
|
+
const models = { [refFile]: text };
|
|
333
|
+
const outer = capture(() => buildModelNode(parseModelCached(outerText), {}, models, file, [file], { optimize: true }));
|
|
334
|
+
assert.equal(serializeTemplate(outer).reason, 'art', 'referenced art refuses even after cloning/merging');
|
|
335
|
+
dispose(outer);
|
|
336
|
+
const missing = templateCacheKey(text, file, { sprites: {} });
|
|
337
|
+
const loading = templateCacheKey(text, file, { sprites });
|
|
338
|
+
const nestedLoading = templateCacheKey(outerText, file, { models, sprites });
|
|
339
|
+
assert.notEqual(missing, loading, 'direct art identity changes key');
|
|
340
|
+
assert.notEqual(templateCacheKey(outerText, file, { models, sprites: {} }), nestedLoading, 'referenced art identity changes key');
|
|
341
|
+
sprites[ref].ready = true;
|
|
342
|
+
assert.notEqual(templateCacheKey(text, file, { sprites }), loading, 'direct art readiness changes key');
|
|
343
|
+
assert.notEqual(templateCacheKey(outerText, file, { models, sprites }), nestedLoading, 'referenced art readiness changes key');
|
|
344
|
+
sprites[ref] = { kind: 'image', ready: false };
|
|
345
|
+
assert.notEqual(templateCacheKey(text, file, { sprites }), loading, 'replacement art changes key');
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
function keys() {
|
|
350
|
+
const text = JSON.stringify({ format: 'pxmodel', parts: [{ id: 'ref', kind: 'model', src: 'models/a.pxmodel' }] });
|
|
351
|
+
const options = { models: { 'models/a.pxmodel': files['models/rock.pxmodel'] }, optimize: true };
|
|
352
|
+
const key = templateCacheKey(text, 'models/main.pxmodel', options);
|
|
353
|
+
assert.equal(templateCacheKey(text, 'models/main.pxmodel', options), key);
|
|
354
|
+
for (const change of [{ optimize: false }, { budget: 123 }, { budget: Infinity }, { budget: NaN }, { dropEmptyParts: true }, { bakesLookLater: true }, { skipSurfaceBakes: true }, { artSignature: 'changed' }, { models: {} }, { models: { 'models/a.pxmodel': `${files['models/rock.pxmodel']} ` } }]) {
|
|
355
|
+
assert.notEqual(templateCacheKey(text, 'models/main.pxmodel', { ...options, ...change }), key);
|
|
356
|
+
}
|
|
357
|
+
assert.notEqual(templateCacheKey(`${text} `, 'models/main.pxmodel', options), key);
|
|
358
|
+
assert.notEqual(templateCacheKey(text, 'imports/test/models/main.pxmodel', options), key);
|
|
359
|
+
setLookEnabled(false);
|
|
360
|
+
assert.notEqual(templateCacheKey(text, 'models/main.pxmodel', options), key);
|
|
361
|
+
setLookEnabled(true);
|
|
362
|
+
const nested = JSON.stringify({ format: 'pxmodel', parts: [{ id: 'nested', kind: 'model', src: '@imports/lib/models/b.pxmodel' }] });
|
|
363
|
+
const models = { 'models/a.pxmodel': nested, 'imports/lib/models/b.pxmodel': files['models/rock.pxmodel'] };
|
|
364
|
+
const before = templateCacheKey(text, '', { models });
|
|
365
|
+
models['imports/lib/models/b.pxmodel'] += ' ';
|
|
366
|
+
assert.notEqual(templateCacheKey(text, '', { models }), before);
|
|
367
|
+
// Cycles/depth use the same resolver and guards as the builder.
|
|
368
|
+
assert.equal(typeof templateCacheKey(text, '', { models: { 'models/a.pxmodel': text } }), 'string');
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function dispose(root) {
|
|
372
|
+
const geometries = new Set();
|
|
373
|
+
const materials = new Set();
|
|
374
|
+
root.traverse((node) => {
|
|
375
|
+
if (node.geometry) geometries.add(node.geometry);
|
|
376
|
+
for (const material of [node.material].flat()) if (material) materials.add(material);
|
|
377
|
+
});
|
|
378
|
+
geometries.forEach((geometry) => geometry.dispose());
|
|
379
|
+
materials.forEach((material) => material.dispose());
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
function captureChecks() {
|
|
383
|
+
assert.equal(kitHooks.templateCaptureActive, false);
|
|
384
|
+
const path = 'models/rock.pxmodel';
|
|
385
|
+
const build = () => {
|
|
386
|
+
const model = freshModel(path);
|
|
387
|
+
return buildModelNode(model.parsed, {}, model.files, path, [path], { optimize: true });
|
|
388
|
+
};
|
|
389
|
+
const uncaptured = build();
|
|
390
|
+
assert.equal(serializeTemplate(uncaptured).reason, 'hooks not captured');
|
|
391
|
+
// Activating capture later cannot recover closures from a prior normal build.
|
|
392
|
+
capture(() => assert.equal(serializeTemplate(uncaptured).reason, 'hooks not captured'));
|
|
393
|
+
dispose(uncaptured);
|
|
394
|
+
const root = capture(() => {
|
|
395
|
+
const nested = capture(build);
|
|
396
|
+
assert.equal(kitHooks.templateCaptureActive, true, 'inner capture leaves outer active');
|
|
397
|
+
return nested;
|
|
398
|
+
});
|
|
399
|
+
assert.equal(kitHooks.templateCaptureActive, false);
|
|
400
|
+
roundTrip(root, 'nested capture');
|
|
401
|
+
dispose(root);
|
|
402
|
+
assert.throws(() => capture(() => { throw new Error('build failed'); }), /build failed/);
|
|
403
|
+
assert.equal(kitHooks.templateCaptureActive, false, 'throw releases capture');
|
|
404
|
+
assert.throws(() => endTemplateCapture(), /no template capture active/);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function geometryChecks() {
|
|
408
|
+
const shape = new THREE.BoxGeometry();
|
|
409
|
+
const vertices = shape.attributes.position.count;
|
|
410
|
+
for (const [name, size] of [['color', 4], ['partFinish', 2], ['lookOutlineNormal', 3], ['lookOutlineReach', 1], ['lookOcclusion', 1]]) {
|
|
411
|
+
shape.setAttribute(name, new THREE.BufferAttribute(new Float32Array(vertices * size), size));
|
|
412
|
+
}
|
|
413
|
+
shape.computeBoundingBox(); shape.computeBoundingSphere();
|
|
414
|
+
const root = new THREE.Mesh(shape, Array.from({ length: 6 }, () => new THREE.MeshStandardMaterial()));
|
|
415
|
+
const bytes = serializeTemplate(root).bytes;
|
|
416
|
+
assert.ok(deserializeTemplate(bytes), 'valid geometry and RGBA colors accepted');
|
|
417
|
+
const bad = (mutate) => assert.equal(deserializeTemplate(changeTemplate(bytes, mutate)), null);
|
|
418
|
+
let checks = 0;
|
|
419
|
+
for (const [name, sizes] of [['position', [0, 1, 2, 4, 5, 1.5]], ['normal', [1]], ['uv', [3]], ['color', [2]],
|
|
420
|
+
['partFinish', [1]], ['lookOutlineNormal', [1]], ['lookOutlineReach', [2]], ['lookOcclusion', [2]]]) {
|
|
421
|
+
for (const size of sizes) {
|
|
422
|
+
bad((header) => { header.geometries[0].attributes.find(([key]) => key === name)[1].itemSize = size; });
|
|
423
|
+
checks++;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
bad((header) => { header.geometries[0].attributes.find(([key]) => key === 'normal')[1].array[3] -= 3; }); checks++;
|
|
427
|
+
bad((header) => { header.geometries[0].attributes.find(([key]) => key === 'normal')[1].array[3] -= 1; }); checks++;
|
|
428
|
+
bad((header, payload) => { templateArray(header.geometries[0].index, payload)[0] = vertices; }); checks++;
|
|
429
|
+
bad((header) => { header.geometries[0].groups = templateGroups(0, shape.index.count + 1); }); checks++;
|
|
430
|
+
bad((header) => { header.geometries[0].groups = templateGroups(-1, 3); }); checks++;
|
|
431
|
+
bad((header) => { header.geometries[0].groups = templateGroups(0, 3, 6); }); checks++;
|
|
432
|
+
bad((header) => { header.geometries[0].attributes.push(header.geometries[0].attributes[0]); }); checks++;
|
|
433
|
+
bad((header) => { header.geometries[0].attributes[0][0] = '__proto__'; }); checks++;
|
|
434
|
+
bad((header) => { header.geometries[0].box = ['list', [['three', 'Vector3', ['list', [1, 0, 0]]], ['three', 'Vector3', ['list', [0, 0, 0]]]]]; }); checks++;
|
|
435
|
+
bad((header) => { header.geometries[0].box = ['list', [['three', 'Vector3', ['list', [['number', '-Infinity', false], 0, 0]]], ['three', 'Vector3', ['list', [0, 0, 0]]]]]; }); checks++;
|
|
436
|
+
bad((header) => { header.geometries[0].sphere = ['list', [['three', 'Vector3', ['list', [0, 0, 0]]], ['number', 'Infinity', false]]]; }); checks++;
|
|
437
|
+
bad((header) => { header.geometries[0].sphere = ['list', [['three', 'Vector3', ['list', [0, 0, 0]]], -1]]; }); checks++;
|
|
438
|
+
dispose(root);
|
|
439
|
+
console.log(`geometry validation: ${checks} malformed entries refused (attribute shapes/counts, indices, groups/materials and bounds)`);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
geometryChecks();
|
|
443
|
+
captureChecks();
|
|
444
|
+
edgeCases();
|
|
445
|
+
decompressionChecks();
|
|
446
|
+
artChecks();
|
|
447
|
+
keys();
|
|
448
|
+
const total = { models: 0, refused: 0, build: 0, serialize: 0, deserialize: 0, bytes: 0, before: 0 };
|
|
449
|
+
const refusals = [];
|
|
450
|
+
const began = performance.now();
|
|
451
|
+
console.log('model | build ms | serialize ms | deserialize ms | bytes before | bytes after');
|
|
452
|
+
for (const path of Object.keys(files).sort()) {
|
|
453
|
+
const model = freshModel(path);
|
|
454
|
+
const start = performance.now();
|
|
455
|
+
const root = capture(() => buildModelNode(model.parsed, {}, model.files, path, [path], { optimize: true }));
|
|
456
|
+
const built = performance.now();
|
|
457
|
+
const { bytes, reason } = serializeTemplate(root);
|
|
458
|
+
const serialized = performance.now();
|
|
459
|
+
total.models++;
|
|
460
|
+
assert.ok(Object.hasOwn(beforeBytes, path), `${path}: baseline exists`);
|
|
461
|
+
total.before += beforeBytes[path] ?? 0;
|
|
462
|
+
total.build += built - start;
|
|
463
|
+
total.serialize += serialized - built;
|
|
464
|
+
if (!bytes) {
|
|
465
|
+
total.refused++;
|
|
466
|
+
refusals.push({ path, reason });
|
|
467
|
+
console.log(`${path} | ${(built - start).toFixed(2)} | ${(serialized - built).toFixed(2)} | REFUSED: ${reason}`);
|
|
468
|
+
dispose(root);
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const decoded = deserializeTemplate(bytes);
|
|
472
|
+
const restored = performance.now();
|
|
473
|
+
total.deserialize += restored - serialized;
|
|
474
|
+
total.bytes += bytes.byteLength;
|
|
475
|
+
equalTrees(root, decoded, path);
|
|
476
|
+
equalTrees(copyModel(root), copyModel(decoded), `${path}: actor copy`);
|
|
477
|
+
if (path === CART || path === MIXED) {
|
|
478
|
+
const sourceCopy = copyModel(root);
|
|
479
|
+
const decodedCopy = copyModel(decoded);
|
|
480
|
+
dropEmptyGroups(sourceCopy, model.parsed);
|
|
481
|
+
dropEmptyGroups(decodedCopy, model.parsed);
|
|
482
|
+
equalTrees(sourceCopy, decodedCopy, `${path}: empty parts dropped`);
|
|
483
|
+
}
|
|
484
|
+
console.log(`${path} | ${(built - start).toFixed(2)} | ${(serialized - built).toFixed(2)} | ${(restored - serialized).toFixed(2)} | ${beforeBytes[path]} | ${bytes.byteLength}`);
|
|
485
|
+
dispose(root);
|
|
486
|
+
dispose(decoded);
|
|
487
|
+
}
|
|
488
|
+
// Every representable model replays pristine deferred work, never a generator.
|
|
489
|
+
let deferred = 0;
|
|
490
|
+
for (const path of Object.keys(files).sort()) {
|
|
491
|
+
if (refusals.some((refused) => refused.path === path)) continue;
|
|
492
|
+
const queue = makeLookBake();
|
|
493
|
+
const model = freshModel(path);
|
|
494
|
+
const root = capture(() => bakingLater(queue, path, () => buildModelNode(model.parsed, {}, model.files, path, [path], { optimize: true })));
|
|
495
|
+
const { bytes, reason } = serializeTemplate(root);
|
|
496
|
+
assert.ok(bytes, `${path}: pristine deferred work serializes (${reason})`);
|
|
497
|
+
const restored = deserializeTemplate(bytes);
|
|
498
|
+
assert.ok(restored, `${path}: unbaked template decodes`);
|
|
499
|
+
assert.deepEqual(Buffer.from(serializeTemplate(restored).bytes), Buffer.from(bytes), `${path}: unbaked bytes preserved`);
|
|
500
|
+
const replay = makeLookBake();
|
|
501
|
+
bakingLater(replay, path, () => restored, true);
|
|
502
|
+
assert.equal(replay.pending, queue.pending, `${path}: same tasks restored to the normal queue`);
|
|
503
|
+
queue.now = replay.now = () => 0;
|
|
504
|
+
while (queue.pending) stepLookBake(queue);
|
|
505
|
+
while (replay.pending) stepLookBake(replay);
|
|
506
|
+
equalTrees(root, restored, `${path}: replayed deferred bake`);
|
|
507
|
+
assert.deepEqual(Buffer.from(serializeTemplate(root).bytes), Buffer.from(serializeTemplate(restored).bytes), `${path}: baked bytes equal`);
|
|
508
|
+
dispose(root); dispose(restored); deferred++;
|
|
509
|
+
}
|
|
510
|
+
console.log(`deferred templates: ${deferred} unbaked round trips and completed bakes byte-identical`);
|
|
511
|
+
console.log(`TOTAL | ${total.build.toFixed(2)} | ${total.serialize.toFixed(2)} | ${total.deserialize.toFixed(2)} | ${total.before} -> ${total.bytes} bytes (${(100 * (1 - total.bytes / total.before)).toFixed(1)}% smaller); ${total.models} models, ${total.refused} refused; wall ${(performance.now() - began).toFixed(2)} ms`);
|
|
512
|
+
console.log(`Refusals: ${JSON.stringify(refusals)}`);
|
|
513
|
+
assert.ok(total.refused / total.models <= 0.1, 'more than 10% of models refused');
|
|
514
|
+
// Also enforce the rate for shipped models independently of synthetic fixtures.
|
|
515
|
+
const shipped = Object.keys(files).filter((path) => fs.existsSync(new URL(`../${path}`, import.meta.url)));
|
|
516
|
+
assert.ok(refusals.filter(({ path }) => shipped.includes(path)).length / shipped.length <= 0.1);
|
|
517
|
+
|
|
518
|
+
assert.ok(total.bytes < total.before * 0.7, 'lossless encoding saves at least 30% on kit fixtures');
|
|
519
|
+
assert.equal(kitHooks.templateCaptureActive, false, 'test leaves capture off');
|