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,600 @@
|
|
|
1
|
+
// Real template builds and world lifecycle; the SDK bridge alone is fake.
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import { changeTemplate, outOfRangeIndex, templateGroups } from './template-cache-fixtures.mjs';
|
|
5
|
+
import { createHash, webcrypto } from 'node:crypto';
|
|
6
|
+
import { makeWorld } from './test-static-passes.mjs';
|
|
7
|
+
import { files, freshModel } from './look-baseline.mjs';
|
|
8
|
+
|
|
9
|
+
const { syncActors, renderWorld, disposeWorld } = await import('../engine3d/world3d.js');
|
|
10
|
+
const { preloadModelCache, readModelCacheKey, readModelCacheBlob, boundModelCache,
|
|
11
|
+
MODEL_CACHE_DEFAULT_BYTES, MODEL_CACHE_MAX_BYTES } = await import('../engine3d/modelcache.js');
|
|
12
|
+
const { serializeTemplate, serializeTemplateAsync, deserializeTemplate, templateCacheKey, TEMPLATE_CACHE_VERSION } = await import('../engine3d/templatecache.js');
|
|
13
|
+
const { beginTemplateCapture, endTemplateCapture } = await import('../engine3d/kithooks.js');
|
|
14
|
+
const kitHooks = await import('../engine3d/kithooks.js');
|
|
15
|
+
const { buildModelNode } = await import('../engine3d/pxmodel.js');
|
|
16
|
+
const { makeLookBake, stepLookBake } = await import('../engine3d/lookbake.js');
|
|
17
|
+
const { bakingLater } = await import('../engine3d/look.js');
|
|
18
|
+
await import('./test-static-scenery.mjs');
|
|
19
|
+
const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
|
|
20
|
+
const { drawn } = await import('./test-drop-empty-parts.mjs');
|
|
21
|
+
|
|
22
|
+
let checks = 0;
|
|
23
|
+
function equal(a, b, why) { checks++; assert.deepEqual(a, b, why); }
|
|
24
|
+
function capture(build) { beginTemplateCapture(); try { return build(); } finally { endTemplateCapture(); } }
|
|
25
|
+
const digest = 'kit-content-a';
|
|
26
|
+
const scene = 'scenes/cache.scene';
|
|
27
|
+
const pause = () => new Promise((resolve) => setTimeout(resolve, 0));
|
|
28
|
+
function fakeCache() {
|
|
29
|
+
const entries = new Map();
|
|
30
|
+
const calls = [];
|
|
31
|
+
return { entries, calls,
|
|
32
|
+
async getBinary(key) { calls.push(['binary', key]); return entries.get(key)?.slice(0) ?? null; },
|
|
33
|
+
async getText(key) { calls.push(['text', key]); return entries.get(key) ?? null; },
|
|
34
|
+
async set(key, value) { calls.push(['set', key]); entries.set(key, value instanceof ArrayBuffer ? structuredClone(value, { transfer: [value] }) : value); },
|
|
35
|
+
async remove(key) { calls.push(['remove', key]); entries.delete(key); },
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function placing(id, file, x = 0) {
|
|
39
|
+
return { id, runtime: {}, static: true, components: {
|
|
40
|
+
Transform: { x, y: 0, z: 0, rotationX: 0, rotationY: 0, rotationZ: 0 }, Model: { file, scale: 1, yOffset: 0 },
|
|
41
|
+
} };
|
|
42
|
+
}
|
|
43
|
+
function side(engine = {}, paths = ['models/rock.pxmodel'], table = files, path = scene) {
|
|
44
|
+
const data = { engine, ground: { none: true }, actors: paths.map((file, n) => placing(`a${n}`, file, n * 3)) };
|
|
45
|
+
const runtime = new SceneRuntime(data, [], {}, { ...table }, path);
|
|
46
|
+
const world = makeWorld();
|
|
47
|
+
world.composer = { render() { world.scene.updateMatrixWorld(true); } };
|
|
48
|
+
world.renderer = { dispose() {}, render() {} };
|
|
49
|
+
runtime.three = world;
|
|
50
|
+
return { world, runtime };
|
|
51
|
+
}
|
|
52
|
+
function frame(s) {
|
|
53
|
+
syncActors(s.world, s.runtime, s.runtime.sprites, 0);
|
|
54
|
+
renderWorld(s.world, s.runtime);
|
|
55
|
+
s.world.modelCache?.afterFrame();
|
|
56
|
+
}
|
|
57
|
+
function close(s) { s.runtime.dispose(); disposeWorld(s.world); equal(s.world.models.size, 0, 'release/dispose clears templates'); }
|
|
58
|
+
async function preload(s, localCache, options = {}) {
|
|
59
|
+
await preloadModelCache(s.world, s.runtime, { localCache, digest, settleMs: 0, ...options });
|
|
60
|
+
}
|
|
61
|
+
async function flush(s) {
|
|
62
|
+
s.world.modelCache.afterFrame();
|
|
63
|
+
await s.world.modelCache.flush();
|
|
64
|
+
}
|
|
65
|
+
function normalBytes(path) {
|
|
66
|
+
const model = freshModel(path);
|
|
67
|
+
const root = capture(() => buildModelNode(model.parsed, {}, model.files, path, [path], { optimize: true }));
|
|
68
|
+
const result = serializeTemplate(root);
|
|
69
|
+
const { disposeNode } = normalBytes;
|
|
70
|
+
disposeNode(root);
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
normalBytes.disposeNode = (await import('../engine3d/materials.js')).disposeNode;
|
|
74
|
+
|
|
75
|
+
// Browser code defines the build, including inline single-file documents and
|
|
76
|
+
// content-addressed chunk URLs. No source glob or custom Node loader is needed.
|
|
77
|
+
const { digestModelCacheScripts, makeModelCacheBuildDigest } = await import('../engine3d/modelcachedigest.js');
|
|
78
|
+
const { REVISION } = await import('three');
|
|
79
|
+
const chunk = (hash) => `https://cdn.example/cauldron-chunks/${hash}.js`;
|
|
80
|
+
const scripts = [{ src: '', textContent: 'const deck = 1;' }, { src: chunk('a'.repeat(64)), textContent: '' }];
|
|
81
|
+
let hashes = 0;
|
|
82
|
+
const environment = { document: { scripts }, TextEncoder, crypto: { subtle: {
|
|
83
|
+
digest(algorithm, input) {
|
|
84
|
+
hashes++;
|
|
85
|
+
equal(algorithm, 'SHA-256', 'native SHA-256');
|
|
86
|
+
return webcrypto.subtle.digest(algorithm, input);
|
|
87
|
+
},
|
|
88
|
+
} } };
|
|
89
|
+
const actualDigest = await digestModelCacheScripts(environment);
|
|
90
|
+
const expectedDigest = createHash('sha256').update(JSON.stringify([TEMPLATE_CACHE_VERSION, REVISION,
|
|
91
|
+
['inline:const deck = 1;', `src:${chunk('a'.repeat(64))}`]])).digest('hex').slice(0, 16);
|
|
92
|
+
equal(actualDigest, expectedDigest, 'hash covers frame scripts, codec version and Three revision');
|
|
93
|
+
equal(await digestModelCacheScripts(environment), actualDigest, 'same scripts give the same digest');
|
|
94
|
+
for (const changed of [
|
|
95
|
+
[{ ...scripts[0], textContent: 'const deck = 2;' }, scripts[1]],
|
|
96
|
+
[scripts[0], { ...scripts[1], src: chunk('b'.repeat(64)) }],
|
|
97
|
+
[...scripts].reverse(), [...scripts, { src: '', textContent: 'new code' }],
|
|
98
|
+
]) equal(await digestModelCacheScripts({ ...environment, document: { scripts: changed } }) === actualDigest, false, 'any script/code order change invalidates');
|
|
99
|
+
const memoized = makeModelCacheBuildDigest(environment);
|
|
100
|
+
const beforeHashes = hashes;
|
|
101
|
+
const firstDigest = memoized();
|
|
102
|
+
equal(memoized() === firstDigest, true, 'concurrent preload shares the hash promise');
|
|
103
|
+
equal(await firstDigest, actualDigest, 'memoized digest');
|
|
104
|
+
equal(await memoized(), actualDigest, 'later scene shares the page digest');
|
|
105
|
+
equal(hashes - beforeHashes, 1, 'one native hash per page');
|
|
106
|
+
for (const missing of [
|
|
107
|
+
{ document: undefined }, { document: {} }, { TextEncoder: undefined },
|
|
108
|
+
{ crypto: undefined }, { crypto: {} }, { crypto: { subtle: {} } },
|
|
109
|
+
{ crypto: { subtle: { digest() { throw new Error('unavailable'); } } } },
|
|
110
|
+
{ crypto: { subtle: { async digest() { throw new Error('unavailable'); } } } },
|
|
111
|
+
]) equal(await digestModelCacheScripts({ ...environment, ...missing }), null, 'missing/failed digest refuses caching');
|
|
112
|
+
|
|
113
|
+
const unhashed = { digest: null, reason: 'unhashed script' };
|
|
114
|
+
for (const src of [
|
|
115
|
+
'http://localhost:5757/main.jsx', 'https://cdn.example/modules/main.js',
|
|
116
|
+
`https://cdn.example/main.js?sha256=${'a'.repeat(64)}`, chunk('a'.repeat(63)), chunk('a'.repeat(65)),
|
|
117
|
+
`https://cdn.example/prefix-${'a'.repeat(64)}.js`, 'blob:https://cdn.example/code', 'https://%',
|
|
118
|
+
]) {
|
|
119
|
+
const before = hashes;
|
|
120
|
+
equal(await digestModelCacheScripts({ ...environment, document: { scripts: [{ src }] } }), unhashed, 'unhashed external code disables caching');
|
|
121
|
+
equal(hashes, before, 'unhashed code is rejected before native hashing');
|
|
122
|
+
}
|
|
123
|
+
assert.equal(typeof await digestModelCacheScripts({ ...environment, document: { scripts: [scripts[0]] } }), 'string'); checks++;
|
|
124
|
+
|
|
125
|
+
// Invalid means off. Off/editor worlds touch neither bridge nor capture state.
|
|
126
|
+
const control = side(); frame(control);
|
|
127
|
+
const controlDrawn = drawn(control.world); close(control);
|
|
128
|
+
for (const key of [undefined, null, false, true, 123, [], { maxBytes: 0 }, { maxBytes: -1 }, { maxBytes: 1.5 }, { maxBytes: Infinity }, { maxBytes: MODEL_CACHE_MAX_BYTES + 1 }, { unexpected: 1 }]) {
|
|
129
|
+
equal(readModelCacheKey({ engine: { modelCache: key } }), null, 'invalid key off');
|
|
130
|
+
const local = fakeCache();
|
|
131
|
+
const s = side(key === undefined ? {} : { modelCache: key });
|
|
132
|
+
equal(preloadModelCache(s.world, s.runtime, { localCache: local, digest }), null, 'invalid key does not start IO');
|
|
133
|
+
frame(s);
|
|
134
|
+
equal(local.calls.length, 0, 'no storage calls');
|
|
135
|
+
equal(drawn(s.world), controlDrawn, 'key off/invalid has identical drawn nodes');
|
|
136
|
+
equal(Object.hasOwn(s.world, 'modelCacheReport'), false, 'no off report');
|
|
137
|
+
equal(kitHooks.templateCaptureActive, false, 'no capture left on');
|
|
138
|
+
close(s);
|
|
139
|
+
}
|
|
140
|
+
equal(readModelCacheKey({ engine: { modelCache: {} } }), MODEL_CACHE_DEFAULT_BYTES, '8 MiB default');
|
|
141
|
+
equal(readModelCacheKey({ engine: { modelCache: { maxBytes: MODEL_CACHE_MAX_BYTES } } }), MODEL_CACHE_MAX_BYTES, '16 MiB accepted');
|
|
142
|
+
{
|
|
143
|
+
const local = fakeCache(), s = side({ modelCache: {} });
|
|
144
|
+
s.world.staticActorsOff = true;
|
|
145
|
+
equal(preloadModelCache(s.world, s.runtime, { localCache: local, digest }), null, 'editor excluded');
|
|
146
|
+
frame(s); equal(local.calls, [], 'editor no IO'); close(s);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Use the real default page digest with a fake browser missing crypto. Its
|
|
150
|
+
// unavailable result is memoized; this visit never reaches the fake bridge or
|
|
151
|
+
// captures hook recipes, and still builds the same nodes as ordinary play.
|
|
152
|
+
{
|
|
153
|
+
const saved = ['document', 'crypto'].map((name) => [name, Object.getOwnPropertyDescriptor(globalThis, name)]);
|
|
154
|
+
Object.defineProperty(globalThis, 'document', { configurable: true, value: { scripts } });
|
|
155
|
+
Object.defineProperty(globalThis, 'crypto', { configurable: true, value: undefined });
|
|
156
|
+
const store = fakeCache(), s = side({ modelCache: {} });
|
|
157
|
+
try {
|
|
158
|
+
await preloadModelCache(s.world, s.runtime, { localCache: store });
|
|
159
|
+
frame(s);
|
|
160
|
+
equal(s.world.modelCacheReport.digest, 'unavailable', 'missing crypto reports why caching is off');
|
|
161
|
+
equal(drawn(s.world), controlDrawn, 'digest failure keeps ordinary model output');
|
|
162
|
+
equal(serializeTemplate(s.world.models.values().next().value.template).reason, 'hooks not captured', 'digest failure builds without capture');
|
|
163
|
+
equal(kitHooks.templateCaptureActive, false, 'digest failure leaves capture off');
|
|
164
|
+
equal(store.calls, [], 'digest failure makes zero LocalCache calls');
|
|
165
|
+
} finally {
|
|
166
|
+
close(s);
|
|
167
|
+
for (const [name, descriptor] of saved) {
|
|
168
|
+
if (descriptor) Object.defineProperty(globalThis, name, descriptor);
|
|
169
|
+
else delete globalThis[name];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// Unhashed dev/module scripts report the reason and never touch LocalCache.
|
|
174
|
+
{
|
|
175
|
+
const store = fakeCache(), s = side({ modelCache: {} });
|
|
176
|
+
const unavailable = makeModelCacheBuildDigest({ ...environment,
|
|
177
|
+
document: { scripts: [{ src: 'http://localhost:5757/main.jsx' }] } });
|
|
178
|
+
await preload(s, store, { digest: unavailable() }); frame(s);
|
|
179
|
+
equal(s.world.modelCacheReport.digest, 'unavailable', 'unhashed external script turns caching off');
|
|
180
|
+
equal(s.world.modelCacheReport.reason, 'unhashed script', 'unhashed script reason reported');
|
|
181
|
+
equal(store.calls, [], 'unhashed script makes no LocalCache calls');
|
|
182
|
+
equal(drawn(s.world), controlDrawn, 'unhashed script builds normally');
|
|
183
|
+
close(s);
|
|
184
|
+
}
|
|
185
|
+
// Native content identity enables a real miss/store/hit visit.
|
|
186
|
+
{
|
|
187
|
+
const store = fakeCache();
|
|
188
|
+
for (const visit of [0, 1]) {
|
|
189
|
+
const s = side({ modelCache: {} });
|
|
190
|
+
await preload(s, store, { digest: memoized() }); frame(s); await flush(s);
|
|
191
|
+
equal(s.world.modelCacheReport.hits, visit, 'inline and SHA-256-addressed scripts enable caching');
|
|
192
|
+
equal(s.world.modelCache.digest, actualDigest, 'native digest names the stored blob');
|
|
193
|
+
close(s);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
// Native hashing itself shares the preload deadline. Late hashes must not
|
|
197
|
+
// start any LocalCache read, enable capture or replace this visit's fallback.
|
|
198
|
+
{
|
|
199
|
+
let resolve;
|
|
200
|
+
const pending = new Promise((done) => { resolve = done; });
|
|
201
|
+
const store = fakeCache(), s = side({ modelCache: {} });
|
|
202
|
+
await preload(s, store, { digest: pending, timeoutMs: 5 });
|
|
203
|
+
frame(s);
|
|
204
|
+
equal(drawn(s.world), controlDrawn, 'digest timeout builds normally');
|
|
205
|
+
equal(store.calls, [], 'digest timeout makes zero LocalCache calls');
|
|
206
|
+
resolve(actualDigest); await pause();
|
|
207
|
+
equal(store.calls, [], 'late digest ignored');
|
|
208
|
+
equal(Object.hasOwn(s.world.modelCache, 'pending'), false, 'late digest leaves ordinary fallback');
|
|
209
|
+
close(s);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Every kit model plus reference fixtures: first visit stores only representable
|
|
213
|
+
// templates; second visit verifies every hit byte-for-byte against a fresh build.
|
|
214
|
+
const paths = Object.keys(files).sort();
|
|
215
|
+
const eligible = paths.filter((path) => normalBytes(path).bytes);
|
|
216
|
+
let yields = 0;
|
|
217
|
+
const local = fakeCache();
|
|
218
|
+
const first = side({ modelCache: {} }, paths);
|
|
219
|
+
await preload(first, local, { pause: async () => { yields++; await pause(); } });
|
|
220
|
+
equal(first.world.modelCacheReport.hits, 0, 'cold read');
|
|
221
|
+
equal(Object.hasOwn(first.world.modelCacheReport, 'verified'), false, 'verification fields absent when off');
|
|
222
|
+
frame(first);
|
|
223
|
+
equal(local.calls.filter(([kind]) => kind === 'set').length, 0, 'no first-frame writes');
|
|
224
|
+
await flush(first);
|
|
225
|
+
equal(first.world.modelCacheReport.misses, paths.length, 'one miss per template');
|
|
226
|
+
equal(first.world.modelCacheReport.stored, eligible.length, 'art/Shape refusals do not enter storage');
|
|
227
|
+
assert.ok(yields > eligible.length, 'settled blob writing yields within templates');
|
|
228
|
+
checks++;
|
|
229
|
+
const blobKey = first.world.modelCache.blobKey;
|
|
230
|
+
const indexKey = first.world.modelCache.indexKey;
|
|
231
|
+
const stored = readModelCacheBlob(local.entries.get(blobKey), scene, digest);
|
|
232
|
+
equal(stored.size, eligible.length, 'one scene blob contains templates');
|
|
233
|
+
for (const path of eligible) {
|
|
234
|
+
const key = templateCacheKey(files[path], path, { models: files, sprites: {}, optimize: true });
|
|
235
|
+
equal(Buffer.from(stored.get(key)), Buffer.from(normalBytes(path).bytes), `${path}: stored bytes equal fresh build`);
|
|
236
|
+
}
|
|
237
|
+
const firstReport = { ...first.world.modelCacheReport };
|
|
238
|
+
close(first);
|
|
239
|
+
|
|
240
|
+
globalThis.__castleModelCacheVerify = true;
|
|
241
|
+
const second = side({ modelCache: {} }, paths);
|
|
242
|
+
const beforeCalls = local.calls.length;
|
|
243
|
+
await preload(second, local);
|
|
244
|
+
frame(second);
|
|
245
|
+
equal(second.world.modelCacheReport.hits, eligible.length, 'second visit hits every stored model');
|
|
246
|
+
equal(second.world.modelCacheReport.verified, eligible.length, 'every hit independently rebuilt');
|
|
247
|
+
equal(second.world.modelCacheReport.mismatches, [], 'fresh and cached bytes identical');
|
|
248
|
+
equal(local.calls.slice(beforeCalls).filter(([kind]) => kind === 'binary').length, 1, 'one binary read per scene, never per model');
|
|
249
|
+
equal(local.calls.slice(beforeCalls).filter(([kind]) => kind === 'text').length, 1, 'one small index read');
|
|
250
|
+
const warmReport = { ...second.world.modelCacheReport };
|
|
251
|
+
await flush(second); close(second);
|
|
252
|
+
delete globalThis.__castleModelCacheVerify;
|
|
253
|
+
|
|
254
|
+
// A gameplay edit after the first frame must never become the next build.
|
|
255
|
+
{
|
|
256
|
+
const store = fakeCache();
|
|
257
|
+
const cold = side({ modelCache: {} });
|
|
258
|
+
await preload(cold, store); frame(cold);
|
|
259
|
+
const template = cold.world.models.values().next().value.template;
|
|
260
|
+
const frozen = cold.world.modelCache.pending.values().next().value.slice(0);
|
|
261
|
+
let actorMesh;
|
|
262
|
+
cold.world.nodes.get('a0').node.traverse((node) => { if (node.isMesh && !node.userData.lookOutline) actorMesh ??= node; });
|
|
263
|
+
const color = actorMesh.material.color.getHex();
|
|
264
|
+
const position = actorMesh.geometry.attributes.position.array[0];
|
|
265
|
+
let shared = false;
|
|
266
|
+
template.traverse((node) => { if (node.material === actorMesh.material && node.geometry === actorMesh.geometry) shared = true; });
|
|
267
|
+
equal(shared, true, 'repro edits material and geometry shared with the template');
|
|
268
|
+
actorMesh.material.color.set('#ff00ff');
|
|
269
|
+
actorMesh.geometry.attributes.position.array[0] += 11;
|
|
270
|
+
await flush(cold);
|
|
271
|
+
equal(Buffer.from(cold.world.modelCache.entries.values().next().value), Buffer.from(frozen), 'flush writes construction bytes despite live tint/vertex changes');
|
|
272
|
+
close(cold);
|
|
273
|
+
const warm = side({ modelCache: {} });
|
|
274
|
+
await preload(warm, store); frame(warm);
|
|
275
|
+
let mesh;
|
|
276
|
+
warm.world.nodes.get('a0').node.traverse((node) => { if (node.isMesh && !node.userData.lookOutline) mesh ??= node; });
|
|
277
|
+
equal(warm.world.modelCacheReport.hits, 1, 'repro reopens from the cache');
|
|
278
|
+
equal(mesh.material.color.getHex(), color, 'reopen starts with the authored color');
|
|
279
|
+
equal(mesh.geometry.attributes.position.array[0], position, 'reopen starts with the authored vertices');
|
|
280
|
+
close(warm);
|
|
281
|
+
}
|
|
282
|
+
// Deferred misses are frozen and written before baking. A reopened hit starts
|
|
283
|
+
// unbaked, uses the playing world's normal queue, then equals a fresh build.
|
|
284
|
+
{
|
|
285
|
+
const file = 'models/cart.pxmodel';
|
|
286
|
+
const model = freshModel(file);
|
|
287
|
+
const store = fakeCache();
|
|
288
|
+
const engine = { modelCache: {}, look: { bake: 'deferred' } };
|
|
289
|
+
const cold = side(engine, [file], model.files);
|
|
290
|
+
await preload(cold, store); frame(cold);
|
|
291
|
+
equal(cold.world.lookBake.pending > 0, true, 'cold cart still waits for its deferred bake');
|
|
292
|
+
const frozen = cold.world.modelCache.pending.values().next().value.slice(0);
|
|
293
|
+
let mesh;
|
|
294
|
+
cold.world.nodes.get('a0').node.traverse((node) => { if (node.isMesh && !node.userData.lookOutline) mesh ??= node; });
|
|
295
|
+
mesh.material.color.set('#ff00ff');
|
|
296
|
+
await flush(cold);
|
|
297
|
+
equal(cold.world.modelCacheReport.stored, 1, 'unbaked template stored without waiting for a bake');
|
|
298
|
+
equal(cold.world.lookBake.pending > 0, true, 'flush never advances the look bake');
|
|
299
|
+
equal(Buffer.from(cold.world.modelCache.entries.values().next().value), Buffer.from(frozen), 'unbaked stored bytes ignore gameplay tint');
|
|
300
|
+
close(cold);
|
|
301
|
+
const warm = side(engine, [file], model.files);
|
|
302
|
+
await preload(warm, store); frame(warm);
|
|
303
|
+
equal(warm.world.modelCacheReport.hits, 1, 'deferred cart reopens as a hit');
|
|
304
|
+
equal(warm.world.lookBake.pending > 0, true, 'hit queues its normal deferred bake');
|
|
305
|
+
const queue = makeLookBake();
|
|
306
|
+
const fresh = capture(() => bakingLater(queue, file, () => buildModelNode(model.parsed, {}, model.files, file, [file], { optimize: true })));
|
|
307
|
+
queue.now = warm.world.lookBake.now = () => 0;
|
|
308
|
+
while (queue.pending) stepLookBake(queue);
|
|
309
|
+
while (warm.world.lookBake.pending) stepLookBake(warm.world.lookBake);
|
|
310
|
+
const hit = warm.world.models.values().next().value.template;
|
|
311
|
+
equal(Buffer.from(serializeTemplate(hit).bytes), Buffer.from(serializeTemplate(fresh).bytes), 'actual playing hit plus bake equals a fresh build plus bake byte-for-byte');
|
|
312
|
+
normalBytes.disposeNode(fresh); close(warm);
|
|
313
|
+
}
|
|
314
|
+
// Same-page revisit: replay must reuse the builder's weak AO cache at once,
|
|
315
|
+
// including the parsed identities of referenced models, before the first draw.
|
|
316
|
+
function occlusionBytes(root) {
|
|
317
|
+
const result = [];
|
|
318
|
+
root.traverse((node) => {
|
|
319
|
+
if (!node.isMesh || node.userData.lookOutline) return;
|
|
320
|
+
const attribute = node.geometry.getAttribute('lookOcclusion');
|
|
321
|
+
result.push(attribute ? Buffer.from(new Uint8Array(attribute.array.buffer, attribute.array.byteOffset, attribute.array.byteLength)) : null);
|
|
322
|
+
});
|
|
323
|
+
return result;
|
|
324
|
+
}
|
|
325
|
+
for (const file of ['models/tree.pxmodel', 'models/cart.pxmodel']) {
|
|
326
|
+
const model = freshModel(file);
|
|
327
|
+
const store = fakeCache();
|
|
328
|
+
const engine = { modelCache: {}, look: { bake: 'deferred' } };
|
|
329
|
+
const cold = side(engine, [file], model.files);
|
|
330
|
+
await preload(cold, store); frame(cold);
|
|
331
|
+
cold.world.lookBake.now = () => 0;
|
|
332
|
+
while (cold.world.lookBake.pending) stepLookBake(cold.world.lookBake);
|
|
333
|
+
const baked = occlusionBytes(cold.world.nodes.get('a0').node);
|
|
334
|
+
equal(baked.some((bytes) => bytes && new Float32Array(bytes.buffer, bytes.byteOffset, bytes.length / 4).some((value) => value < 1)), true, `${file}: repro has genuinely occluded vertices`);
|
|
335
|
+
await flush(cold); close(cold);
|
|
336
|
+
const warm = side(engine, [file], model.files);
|
|
337
|
+
await preload(warm, store); frame(warm);
|
|
338
|
+
equal(warm.world.modelCacheReport.hits, 1, `${file}: same-page reopen is a hit`);
|
|
339
|
+
const normal = side({ look: { bake: 'deferred' } }, [file], model.files); frame(normal);
|
|
340
|
+
const first = occlusionBytes(normal.world.nodes.get('a0').node);
|
|
341
|
+
equal(first, baked, `${file}: normal rebuild immediately reuses cached AO`);
|
|
342
|
+
equal(occlusionBytes(warm.world.nodes.get('a0').node), first, `${file}: hit AO equals a normal rebuild on the first frame`);
|
|
343
|
+
equal(warm.world.lookBake.pending, normal.world.lookBake.pending, `${file}: only the work a rebuild defers is queued`);
|
|
344
|
+
warm.world.lookBake.now = normal.world.lookBake.now = () => 0;
|
|
345
|
+
while (warm.world.lookBake.pending) stepLookBake(warm.world.lookBake);
|
|
346
|
+
while (normal.world.lookBake.pending) stepLookBake(normal.world.lookBake);
|
|
347
|
+
equal(occlusionBytes(warm.world.nodes.get('a0').node), occlusionBytes(normal.world.nodes.get('a0').node), `${file}: AO still equals a normal rebuild after baking`);
|
|
348
|
+
close(warm); close(normal);
|
|
349
|
+
}
|
|
350
|
+
// Shape-valid framing is insufficient. Reject malformed geometry before any
|
|
351
|
+
// copy escapes, drop the entry, then persist only a fresh construction result.
|
|
352
|
+
for (const corrupt of [
|
|
353
|
+
(header) => { header.geometries[0].attributes.find(([key]) => key === 'position')[1].itemSize = 1; },
|
|
354
|
+
outOfRangeIndex,
|
|
355
|
+
(header) => { const geometry = header.geometries[0]; geometry.groups = templateGroups(0, (geometry.index?.array[3] ?? geometry.attributes.find(([key]) => key === 'position')[1].array[3] / 3) + 1); },
|
|
356
|
+
]) {
|
|
357
|
+
const store = fakeCache(), cold = side({ modelCache: {} });
|
|
358
|
+
await preload(cold, store); frame(cold); await flush(cold);
|
|
359
|
+
const key = cold.world.modelCache.entries.keys().next().value;
|
|
360
|
+
const bad = changeTemplate(cold.world.modelCache.entries.get(key), corrupt);
|
|
361
|
+
cold.world.modelCache.entries.set(key, bad); cold.world.modelCache.dirty = true;
|
|
362
|
+
await flush(cold); close(cold);
|
|
363
|
+
const warm = side({ modelCache: {} });
|
|
364
|
+
await preload(warm, store); frame(warm);
|
|
365
|
+
equal(warm.world.modelCacheReport.hits, 0, 'bad geometry is a miss');
|
|
366
|
+
equal(warm.world.modelCacheReport.misses, 1, 'bad geometry builds normally');
|
|
367
|
+
equal(warm.world.modelCache.entries.has(key), false, 'bad geometry removed before the next write');
|
|
368
|
+
equal(drawn(warm.world), controlDrawn, 'malformed entry never changes play output');
|
|
369
|
+
await flush(warm);
|
|
370
|
+
const persisted = readModelCacheBlob(store.entries.get(warm.world.modelCache.blobKey), scene, digest).get(key);
|
|
371
|
+
equal(Buffer.from(persisted), Buffer.from(normalBytes('models/rock.pxmodel').bytes), 'bad entry cleared from storage and replaced by fresh bytes');
|
|
372
|
+
close(warm);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// A corrupt individual template is dropped even when the normal replacement is
|
|
376
|
+
// refused; its bytes cannot linger under an unrelated good model's write.
|
|
377
|
+
{
|
|
378
|
+
const store = fakeCache();
|
|
379
|
+
const s = side({ modelCache: {} });
|
|
380
|
+
await preload(s, store); frame(s); await flush(s);
|
|
381
|
+
const key = s.world.modelCache.entries.keys().next().value;
|
|
382
|
+
s.world.modelCache.entries.set(key, new ArrayBuffer(16));
|
|
383
|
+
s.world.modelCache.dirty = true;
|
|
384
|
+
await flush(s); close(s);
|
|
385
|
+
const next = side({ modelCache: {} });
|
|
386
|
+
await preload(next, store); frame(next);
|
|
387
|
+
equal(next.world.modelCacheReport.hits, 0, 'corrupt miss');
|
|
388
|
+
equal(next.world.modelCacheReport.misses, 1, 'corrupt fallback built');
|
|
389
|
+
await flush(next);
|
|
390
|
+
assert.ok(deserializeTemplate(next.world.modelCache.entries.get(key))); checks++;
|
|
391
|
+
close(next);
|
|
392
|
+
}
|
|
393
|
+
// Verification detects valid bytes filed under the wrong model key and uses
|
|
394
|
+
// the normal build. A refused replacement also removes corrupt art bytes.
|
|
395
|
+
{
|
|
396
|
+
const store = fakeCache();
|
|
397
|
+
const s = side({ modelCache: {} });
|
|
398
|
+
await preload(s, store); frame(s); await flush(s);
|
|
399
|
+
const rockKey = s.world.modelCache.entries.keys().next().value;
|
|
400
|
+
const artKey = templateCacheKey(files['models/player.pxmodel'], 'models/player.pxmodel', { models: files, sprites: {}, optimize: true });
|
|
401
|
+
s.world.modelCache.entries.set(rockKey, normalBytes('models/tree.pxmodel').bytes);
|
|
402
|
+
s.world.modelCache.entries.set(artKey, new ArrayBuffer(16));
|
|
403
|
+
s.world.modelCache.dirty = true;
|
|
404
|
+
await flush(s); close(s);
|
|
405
|
+
globalThis.__castleModelCacheVerify = true;
|
|
406
|
+
const next = side({ modelCache: {} }, ['models/rock.pxmodel', 'models/player.pxmodel']);
|
|
407
|
+
await preload(next, store); frame(next);
|
|
408
|
+
equal(next.world.modelCacheReport.mismatches, [rockKey], 'mismatch key recorded');
|
|
409
|
+
equal(next.world.modelCacheReport.hits, 0, 'wrong valid template rejected');
|
|
410
|
+
await flush(next);
|
|
411
|
+
equal(next.world.modelCache.entries.has(artKey), false, 'corrupt refused replacement removed');
|
|
412
|
+
equal(Buffer.from(next.world.modelCache.entries.get(rockKey)), Buffer.from(normalBytes('models/rock.pxmodel').bytes), 'mismatch replaced by normal build');
|
|
413
|
+
close(next); delete globalThis.__castleModelCacheVerify;
|
|
414
|
+
}
|
|
415
|
+
// Digest changes remove the previous binary entry and advance the index.
|
|
416
|
+
{
|
|
417
|
+
const old = local.entries.get(indexKey);
|
|
418
|
+
const s = side({ modelCache: {} });
|
|
419
|
+
await preload(s, local, { digest: 'kit-content-b' });
|
|
420
|
+
equal(local.entries.has(old), false, 'old kit blob removed');
|
|
421
|
+
frame(s); await flush(s);
|
|
422
|
+
equal(local.entries.get(indexKey), s.world.modelCache.blobKey, 'index advanced');
|
|
423
|
+
close(s);
|
|
424
|
+
}
|
|
425
|
+
// Budget includes headers; LRU keeps the most recently used template.
|
|
426
|
+
{
|
|
427
|
+
const entries = new Map([['template:6:a', new ArrayBuffer(500)], ['template:6:b', new ArrayBuffer(500)], ['template:6:c', new ArrayBuffer(500)]]);
|
|
428
|
+
const recent = entries.get('template:6:a'); entries.delete('template:6:a'); entries.set('template:6:a', recent);
|
|
429
|
+
const bounded = boundModelCache(entries, scene, digest, 800);
|
|
430
|
+
equal([...entries.keys()], ['template:6:a'], 'least recently used removed first');
|
|
431
|
+
assert.ok(bounded.size <= 800); checks++;
|
|
432
|
+
const s = side({ modelCache: { maxBytes: 1 } });
|
|
433
|
+
await preload(s, local); frame(s); await flush(s);
|
|
434
|
+
equal(s.world.modelCacheReport.bytes, 0, 'too small budget stores nothing'); close(s);
|
|
435
|
+
}
|
|
436
|
+
// Persisted budget and last-used order, exercised through the real bridge blob.
|
|
437
|
+
{
|
|
438
|
+
const paths = ['models/rock.pxmodel', 'models/tree.pxmodel', 'models/barrel.pxmodel'];
|
|
439
|
+
const sizes = paths.map((path) => normalBytes(path).bytes.byteLength);
|
|
440
|
+
const maxBytes = sizes[1] + sizes[2] + 512;
|
|
441
|
+
const store = fakeCache();
|
|
442
|
+
const s = side({ modelCache: { maxBytes } }, paths);
|
|
443
|
+
await preload(s, store); frame(s); await flush(s);
|
|
444
|
+
equal(s.world.modelCacheReport.stored, 2, 'budget evicts oldest template');
|
|
445
|
+
assert.ok(s.world.modelCacheReport.bytes <= maxBytes); checks++;
|
|
446
|
+
const treeKey = templateCacheKey(files[paths[1]], paths[1], { models: files, optimize: true });
|
|
447
|
+
const barrelKey = templateCacheKey(files[paths[2]], paths[2], { models: files, optimize: true });
|
|
448
|
+
equal([...s.world.modelCache.entries.keys()], [treeKey, barrelKey], 'persisted LRU order');
|
|
449
|
+
close(s);
|
|
450
|
+
const next = side({ modelCache: { maxBytes } }, [paths[1]]);
|
|
451
|
+
await preload(next, store); frame(next); await flush(next);
|
|
452
|
+
equal([...next.world.modelCache.entries.keys()], [barrelKey, treeKey], 'hit moves model to most recent');
|
|
453
|
+
close(next);
|
|
454
|
+
}
|
|
455
|
+
// Timeout starts play as all miss and never adopts a late result.
|
|
456
|
+
{
|
|
457
|
+
let resolve;
|
|
458
|
+
const late = new Promise((done) => { resolve = done; });
|
|
459
|
+
const store = fakeCache();
|
|
460
|
+
store.getBinary = async (key) => { store.calls.push(['binary', key]); return late; };
|
|
461
|
+
const s = side({ modelCache: {} });
|
|
462
|
+
await preload(s, store, { timeoutMs: 5, settleMs: 60000 });
|
|
463
|
+
equal(s.world.modelCache.ready, true, 'timeout opens sync gate');
|
|
464
|
+
frame(s); equal(s.world.modelCacheReport.misses, 1, 'timeout all miss');
|
|
465
|
+
resolve(local.entries.get(blobKey)); await pause();
|
|
466
|
+
equal(s.world.modelCache.entries?.size ?? 0, 0, 'late template read ignored');
|
|
467
|
+
close(s);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// The production mount gate starts no update/sync before preload; a closed
|
|
471
|
+
// mount cannot start a late loop. No DOM or WebGL is involved in this check.
|
|
472
|
+
{
|
|
473
|
+
const source = fs.readFileSync(new URL('../engine3d/playerRun.js', import.meta.url), 'utf8');
|
|
474
|
+
const begin = source.indexOf('function startLoopAfterModelCache(');
|
|
475
|
+
const end = source.indexOf('function attachInput(', begin);
|
|
476
|
+
let starts = 0, stops = 0;
|
|
477
|
+
const start = new Function('preloadModelCache', 'startLoop', `${source.slice(begin, end)}; return startLoopAfterModelCache;`)(
|
|
478
|
+
preloadModelCache, (runtime, world) => {
|
|
479
|
+
equal(world.modelCache.ready, true, 'mount waits for preload');
|
|
480
|
+
starts++; syncActors(world, runtime, runtime.sprites, 0);
|
|
481
|
+
return () => { stops++; };
|
|
482
|
+
});
|
|
483
|
+
for (const unmountEarly of [false, true]) {
|
|
484
|
+
let resolve;
|
|
485
|
+
const store = fakeCache();
|
|
486
|
+
store.getBinary = () => new Promise((done) => { resolve = done; });
|
|
487
|
+
const s = side({ modelCache: {} });
|
|
488
|
+
const ready = preloadModelCache(s.world, s.runtime, { localCache: store, digest });
|
|
489
|
+
const stop = start(s.runtime, s.world);
|
|
490
|
+
equal(s.world.models.size, 0, 'mount has no model before preload');
|
|
491
|
+
// Let the lazy module and bridge invocation run, then close or resolve it.
|
|
492
|
+
while (!resolve) await pause();
|
|
493
|
+
if (unmountEarly) stop();
|
|
494
|
+
resolve(null); await ready; await pause();
|
|
495
|
+
equal(s.world.models.size, unmountEarly ? 0 : 1, 'only a live mount synchronizes');
|
|
496
|
+
if (!unmountEarly) stop();
|
|
497
|
+
close(s);
|
|
498
|
+
}
|
|
499
|
+
equal([starts, stops], [1, 1], 'one live loop, no loop after unmount');
|
|
500
|
+
}
|
|
501
|
+
// A scene switch invalidates the old visit and gates direct syncActors calls.
|
|
502
|
+
{
|
|
503
|
+
const store = fakeCache();
|
|
504
|
+
const s = side({ modelCache: {} });
|
|
505
|
+
await preload(s, store); frame(s); await flush(s);
|
|
506
|
+
const prior = s.world.modelCache;
|
|
507
|
+
let resolve;
|
|
508
|
+
store.getBinary = (key) => { store.calls.push(['binary', key]); return new Promise((done) => { resolve = done; }); };
|
|
509
|
+
s.runtime.load({ engine: { modelCache: {} }, ground: { none: true }, actors: [placing('next', 'models/barrel.pxmodel')] });
|
|
510
|
+
s.runtime.scenePath = 'scenes/next.scene';
|
|
511
|
+
const ready = preloadModelCache(s.world, s.runtime, { localCache: store, digest });
|
|
512
|
+
const oldSize = s.world.models.size;
|
|
513
|
+
syncActors(s.world, s.runtime, {}, 0);
|
|
514
|
+
equal(s.world.models.size, oldSize, 'new scene direct sync blocked before preload');
|
|
515
|
+
equal(prior.closed, true, 'previous visit closed');
|
|
516
|
+
while (!resolve) await pause();
|
|
517
|
+
resolve(null); await ready;
|
|
518
|
+
frame(s);
|
|
519
|
+
equal(s.world.modelCache.scene, 'scenes/next.scene', 'scene-specific blob key');
|
|
520
|
+
equal(s.world.nodes.has('next'), true, 'new scene builds after preload');
|
|
521
|
+
equal(s.world.modelCacheReport.misses, 1, 'new report belongs to new visit');
|
|
522
|
+
s.runtime.load({ engine: {}, ground: { none: true }, actors: [] });
|
|
523
|
+
frame(s);
|
|
524
|
+
equal(Object.hasOwn(s.world, 'modelCacheReport'), false, 'switching key off removes report');
|
|
525
|
+
close(s);
|
|
526
|
+
}
|
|
527
|
+
// SDK writes may silently store nothing; the next visit simply misses again.
|
|
528
|
+
{
|
|
529
|
+
const store = fakeCache(); store.set = async () => {};
|
|
530
|
+
for (let visit = 0; visit < 2; visit++) {
|
|
531
|
+
const s = side({ modelCache: {} }); await preload(s, store); frame(s); await flush(s);
|
|
532
|
+
equal(s.world.modelCacheReport.misses, 1, 'ignored set keeps normal build fallback'); close(s);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Real engine.load waits and deferred look bake, with pruning and instancing.
|
|
537
|
+
let interplays = 0;
|
|
538
|
+
for (const drops of [false, true]) for (const later of [false, true]) for (const instanced of [false, true]) {
|
|
539
|
+
const engine = { modelCache: {}, load: { first: ['a0'], sliceMs: 8, horizon: 0 },
|
|
540
|
+
dropEmptyParts: drops, ...(later ? { look: { bake: 'deferred' } } : {}) };
|
|
541
|
+
const store = fakeCache();
|
|
542
|
+
const paths = ['models/rock.pxmodel', 'models/tree.pxmodel', 'models/barrel.pxmodel'];
|
|
543
|
+
for (const visit of [0, 1]) {
|
|
544
|
+
if (visit) globalThis.__castleModelCacheVerify = true;
|
|
545
|
+
const s = side(engine, paths);
|
|
546
|
+
s.world.instanceModels = instanced;
|
|
547
|
+
await preload(s, store);
|
|
548
|
+
frame(s);
|
|
549
|
+
if (!instanced) assert.ok(s.world.modelLoad.deferredKeys.size > 0, 'far load models wait');
|
|
550
|
+
if (s.world.lookBake?.pending) {
|
|
551
|
+
await flush(s);
|
|
552
|
+
if (!s.world.modelLoad?.restMarked) equal(store.calls.filter(([kind]) => kind === 'set').length, visit ? 2 : 0, 'writes still wait for engine.load to settle');
|
|
553
|
+
s.world.lookBake.now = () => 0;
|
|
554
|
+
}
|
|
555
|
+
if (s.world.modelLoad) s.world.modelLoad.now = () => 0;
|
|
556
|
+
for (let n = 0; n < 50 && (!s.world.modelLoad?.restMarked || s.world.lookBake?.pending); n++) frame(s);
|
|
557
|
+
assert.ok(s.world.modelLoad.restMarked, 'load settled');
|
|
558
|
+
if (visit) {
|
|
559
|
+
equal(s.world.modelCacheReport.hits, paths.length, `loaded templates hit (drops=${drops}, later=${later}, instances=${instanced}): ${JSON.stringify(s.world.modelCacheReport)}`);
|
|
560
|
+
equal(s.world.modelCacheReport.mismatches, [], 'load/drop/instance/deferred cache bytes equal fresh build');
|
|
561
|
+
equal(s.world.modelCacheReport.verified, paths.length, 'every interplay hit verified');
|
|
562
|
+
equal(s.world.lookBake?.pending ?? 0, 0, 'normal deferred work settled on hits too');
|
|
563
|
+
}
|
|
564
|
+
await flush(s);
|
|
565
|
+
equal(s.world.modelCacheReport.stored, paths.length, 'complete templates stored after load');
|
|
566
|
+
close(s);
|
|
567
|
+
}
|
|
568
|
+
delete globalThis.__castleModelCacheVerify;
|
|
569
|
+
interplays++;
|
|
570
|
+
}
|
|
571
|
+
// The hub's existing Low policy omits surface bakes; proof builds use the
|
|
572
|
+
// same policy without queueing anything on the playing world.
|
|
573
|
+
{
|
|
574
|
+
const store = fakeCache();
|
|
575
|
+
for (const visit of [0, 1]) {
|
|
576
|
+
if (visit) globalThis.__castleModelCacheVerify = true;
|
|
577
|
+
const s = side({ modelCache: {}, look: { bake: 'deferred' } }, ['models/tree.pxmodel']);
|
|
578
|
+
s.world.lookBake = makeLookBake();
|
|
579
|
+
s.world.lookBake.skipSurfaceBakes = true;
|
|
580
|
+
await preload(s, store); frame(s); await flush(s);
|
|
581
|
+
if (visit) {
|
|
582
|
+
equal(s.world.modelCacheReport.hits, 1, 'Low hit');
|
|
583
|
+
equal(s.world.modelCacheReport.mismatches, [], 'Low bytes verified against its own build policy');
|
|
584
|
+
equal(s.world.lookBake.pending, 0, 'Low has no surface work to queue');
|
|
585
|
+
}
|
|
586
|
+
close(s);
|
|
587
|
+
}
|
|
588
|
+
delete globalThis.__castleModelCacheVerify;
|
|
589
|
+
}
|
|
590
|
+
// Async codec and sync proof bytes must use identical compression boundaries.
|
|
591
|
+
{
|
|
592
|
+
const model = freshModel('models/cart.pxmodel');
|
|
593
|
+
const root = capture(() => buildModelNode(model.parsed, {}, model.files, 'models/cart.pxmodel', ['models/cart.pxmodel'], { optimize: true }));
|
|
594
|
+
let turns = 0;
|
|
595
|
+
const asyncBytes = await serializeTemplateAsync(root, { pause: async () => { turns++; await pause(); } });
|
|
596
|
+
equal(Buffer.from(asyncBytes.bytes), Buffer.from(serializeTemplate(root).bytes), 'cooperative and sync encoding byte-identical');
|
|
597
|
+
assert.ok(turns > 0); checks++;
|
|
598
|
+
normalBytes.disposeNode(root);
|
|
599
|
+
}
|
|
600
|
+
console.log(`model cache: ${checks} checks, ${paths.length} kit/fixture models (${eligible.length} stored and independently verified), ${interplays} load/look/drop/instance combinations; ${yields} blob-write yields; ${firstReport.bytes} bytes; read ${firstReport.readMs.toFixed(2)} ms, warm decode ${warmReport.decodeMs.toFixed(2)} ms; script digest ${actualDigest}`);
|
|
@@ -448,6 +448,7 @@ const scenarios = {
|
|
|
448
448
|
const end = source.indexOf('\n}', start) + 2;
|
|
449
449
|
let marked = 0;
|
|
450
450
|
const install = runInNewContext(`(${source.slice(start, end)})`, {
|
|
451
|
+
templateCaptureActive: false,
|
|
451
452
|
markKitHooks(...args) {
|
|
452
453
|
marked += 1;
|
|
453
454
|
assert.ok(args.slice(1).every((arg) => typeof arg === 'function'), `${file}: plain hook arguments only`);
|