castle-web-cli 0.4.239 → 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 +163 -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 +6 -3
- package/dist/init.js +24 -2
- package/dist/platformDoc.js +2 -1
- package/dist/playPagePolicy.js +5 -1
- package/dist/resetLeaderboards.d.ts +8 -1
- package/dist/resetLeaderboards.js +43 -8
- package/dist/save-deck.d.ts +32 -2
- package/dist/save-deck.js +240 -39
- package/kits/base/CLAUDE.md +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +174 -6
- package/kits/base/sdk/analytics.d.ts +8 -0
- package/kits/base/sdk/analytics.js +92 -0
- package/kits/base/sdk/castle.d.ts +5 -1
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +48 -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 +168 -26
- package/kits/base/sdk/reconnectBudget.d.ts +6 -0
- package/kits/base/sdk/reconnectBudget.js +41 -1
- 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/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/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 +473 -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/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 +72 -51
- 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 +205 -25
- 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 +35 -3
- 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/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 +851 -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/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/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 +427 -54
- package/kits/hub-game/docs/analytics.md +16 -2
- 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 +79 -0
- 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-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 +119 -0
- package/kits/hub-game/scripts/test-hub-trip.mjs +240 -4
- 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-loading-cover.mjs +67 -1
- package/kits/hub-game/scripts/test-manifest.mjs +27 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +54 -5
- 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-role-client.mjs +2 -1
- 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-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 +68 -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 +340 -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 +36 -2
- package/kits/hub-game/tools/hubScene/validate-manifest.mjs +10 -2
- 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
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { animationDt } from './animationBudget';
|
|
2
|
+
import { modelCacheVisitReady } from './modelcachegate';
|
|
2
3
|
// The three.js side of the kit: renderer, lighting rig, ground, and per-actor
|
|
3
4
|
// nodes built from Shape components. Values follow the vase reference rig --
|
|
4
5
|
// hemisphere + ambient + one tuned shadow-casting directional, PCFSoft shadows,
|
|
@@ -30,12 +31,14 @@ import { fitOrbitLens, giveBackOrbitLens } from './orbitlens.js';
|
|
|
30
31
|
import { fitViewRange, giveBackViewRange } from './viewrange.js';
|
|
31
32
|
import { renderWithSky, leaveSky, skyHorizonColor } from './sky.js';
|
|
32
33
|
import { holdShadowFade, renderShadowFaded, dropShadowFade } from './shadowfade.js';
|
|
34
|
+
import { groundHalf } from './groundsize.js';
|
|
33
35
|
import { readLoadKey, actorMayWait, makeModelLoad, loadSummary, nearModelKeys,
|
|
34
36
|
consumerRegistryVersion, rememberModelConsumer, modelConsumerChanged } from './squarefirst.js';
|
|
35
37
|
export { ensureActorModel, prepareModelConsumers } from './modelready.js';
|
|
36
38
|
import {
|
|
37
39
|
takeModel,
|
|
38
40
|
releaseModel,
|
|
41
|
+
disposeParkedModels,
|
|
39
42
|
copyModel,
|
|
40
43
|
isStaticModel,
|
|
41
44
|
dropEmptyGroups,
|
|
@@ -140,6 +143,10 @@ export function makeWorld3D(canvas, options = {}) {
|
|
|
140
143
|
debugLines,
|
|
141
144
|
ground,
|
|
142
145
|
grid,
|
|
146
|
+
// A kit that sleeps actors asks the world for these rather than importing
|
|
147
|
+
// them, so the same kit on an older engine finds none and skips prewarm.
|
|
148
|
+
prewarmSleepingModels(runtime, options) { return prewarmSleepingModels(this, runtime, options); },
|
|
149
|
+
needsSleepingModelPrewarm(runtime) { return needsSleepingModelPrewarm(this, runtime); },
|
|
143
150
|
};
|
|
144
151
|
}
|
|
145
152
|
|
|
@@ -216,8 +223,9 @@ function dressGround(world, setting, sprites) {
|
|
|
216
223
|
if (sig === world.groundSig) return;
|
|
217
224
|
// Also callable outside an actor pass: the old material runs listeners.
|
|
218
225
|
outsideCall(world, () => {
|
|
226
|
+
const size = sizeGround(world, setting);
|
|
219
227
|
const tile = setting?.tile > 0 ? setting.tile : 2;
|
|
220
|
-
const repeat = [
|
|
228
|
+
const repeat = [size / tile, size / tile];
|
|
221
229
|
const texture = setting?.art ? resolveArtTexture(setting.art, sprites, repeat) : null;
|
|
222
230
|
world.groundSig = sig;
|
|
223
231
|
const material = new THREE.MeshStandardMaterial({
|
|
@@ -236,6 +244,22 @@ function dressGround(world, setting, sprites) {
|
|
|
236
244
|
});
|
|
237
245
|
}
|
|
238
246
|
|
|
247
|
+
// Draw the ground plane, and its line grid, `ground.half` each way from the
|
|
248
|
+
// origin; returns its width. A scene without the key keeps the 60 m plane
|
|
249
|
+
// `addGround` made, untouched.
|
|
250
|
+
function sizeGround(world, setting) {
|
|
251
|
+
const half = groundHalf(setting);
|
|
252
|
+
if (half !== (world.groundHalf ?? null)) {
|
|
253
|
+
const size = half === null ? GROUND_SIZE : half * 2;
|
|
254
|
+
world.groundHalf = half;
|
|
255
|
+
world.ground.geometry.dispose();
|
|
256
|
+
world.ground.geometry = new THREE.PlaneGeometry(size, size);
|
|
257
|
+
world.grid.geometry?.dispose();
|
|
258
|
+
world.grid.geometry = new THREE.GridHelper(size, Math.round(size), 0x505050, 0x505050).geometry;
|
|
259
|
+
}
|
|
260
|
+
return half === null ? GROUND_SIZE : half * 2;
|
|
261
|
+
}
|
|
262
|
+
|
|
239
263
|
// The signature suffix for an actor's Model component: the model file's text
|
|
240
264
|
// plus the readiness/identity of any art it references, and the same for every
|
|
241
265
|
// model it references.
|
|
@@ -302,7 +326,7 @@ function attachEmptyActor(world, id, entry) {
|
|
|
302
326
|
// for a static model in the player, a place among that model's instances.
|
|
303
327
|
function addModelRig(world, entry, model, modelComponent, key, { sprites, files, drops, actor, wait }) {
|
|
304
328
|
const file = modelComponent.file;
|
|
305
|
-
|
|
329
|
+
key = builtAs(drops, key);
|
|
306
330
|
entry.modelKey = key;
|
|
307
331
|
const load = world.modelLoadPass;
|
|
308
332
|
if (!wait && load && world.modelLoad === load && !load.restMarked && !world.instanceModels &&
|
|
@@ -323,7 +347,11 @@ function addModelRig(world, entry, model, modelComponent, key, { sprites, files,
|
|
|
323
347
|
return;
|
|
324
348
|
}
|
|
325
349
|
const build = () => buildModelNode(model, sprites, files, file, [file], { optimize: true });
|
|
326
|
-
const
|
|
350
|
+
const buildAsScene = world.bakesLookLater ? () => buildBakingLater(world, key, build) : build;
|
|
351
|
+
const template = takeModel(world.models, key, world.modelCache && !world.staticActorsOff
|
|
352
|
+
? () => world.modelCache.template(key, file, model, sprites, files, drops, build,
|
|
353
|
+
world.bakesLookLater ? (make, restore) => buildBakingLater(world, key, make, restore) : null)
|
|
354
|
+
: buildAsScene);
|
|
327
355
|
if (wait) {
|
|
328
356
|
// Building may call consumer code. A cancelled wait never owns a user.
|
|
329
357
|
if (entry.modelWait !== wait || world.modelLoad !== wait.load || world.disposed) {
|
|
@@ -653,15 +681,16 @@ function builtAs(drops, sig) {
|
|
|
653
681
|
|
|
654
682
|
// `build`, for a scene that asked for its models' look to be baked after they
|
|
655
683
|
// are drawn (lookbake.js): the baking is queued on the world as this model's.
|
|
656
|
-
function buildBakingLater(world, key, build) {
|
|
684
|
+
function buildBakingLater(world, key, build, restoreTemplate = false) {
|
|
657
685
|
if (world.disposed === true) return build();
|
|
658
686
|
world.lookBake ??= makeLookBake();
|
|
659
|
-
return bakingLater(world.lookBake, key, build);
|
|
687
|
+
return bakingLater(world.lookBake, key, build, restoreTemplate);
|
|
660
688
|
}
|
|
661
689
|
|
|
662
690
|
// Removes an actor's node. A shared model build is given back rather than
|
|
663
691
|
// disposed, since other actors may still draw it.
|
|
664
|
-
function releaseActorNode(world, entry) {
|
|
692
|
+
function releaseActorNode(world, entry, park = false) {
|
|
693
|
+
if (world.disposed) park = false;
|
|
665
694
|
const waiting = entry.modelWait;
|
|
666
695
|
if (waiting) forgetModelWait(waiting);
|
|
667
696
|
if (world.frozenStatics) {
|
|
@@ -684,7 +713,153 @@ function releaseActorNode(world, entry) {
|
|
|
684
713
|
world.instances.delete(entry.modelKey);
|
|
685
714
|
}
|
|
686
715
|
}
|
|
687
|
-
releaseModel(world.models, entry.modelKey, disposeNode);
|
|
716
|
+
releaseModel(world.models, entry.modelKey, disposeNode, park);
|
|
717
|
+
if (park) world.hasParkedModels = true;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function actorIsSleeping(runtime, actor) {
|
|
721
|
+
return actor && runtime.getActor?.(actor.id) === actor && runtime.isActorSleeping?.(actor) === true;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
function hasSleepingActors(runtime) {
|
|
725
|
+
if (runtime.sleepingActorCount !== undefined) return runtime.sleepingActorCount > 0;
|
|
726
|
+
// Older imported runtimes have no revision/count. They can still park safely.
|
|
727
|
+
if (!runtime.isActorSleeping) return false;
|
|
728
|
+
for (const actor of runtime.actors?.values() ?? []) if (actorIsSleeping(runtime, actor)) return true;
|
|
729
|
+
return false;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function clearSleepingModels(world) {
|
|
733
|
+
world.sleepingModelPrune = undefined;
|
|
734
|
+
world.sleepingModelPrewarm = undefined;
|
|
735
|
+
if (!world.hasParkedModels) return;
|
|
736
|
+
world.hasParkedModels = false;
|
|
737
|
+
disposeParkedModels(world.models, disposeNode);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function prewarmStillCurrent(world, runtime, state) {
|
|
741
|
+
if (!state || state.runtime !== runtime || state.data !== runtime.data ||
|
|
742
|
+
state.sleepVersion !== runtime.sleepVersion || state.drops !== (runtime.dropsEmptyParts === true) ||
|
|
743
|
+
state.later !== (runtime.bakesLookLater === true) ||
|
|
744
|
+
!readsTheSame(state, runtime.sprites, runtime.files)) return false;
|
|
745
|
+
for (let i = 0; i < state.actors.length; i++) {
|
|
746
|
+
const item = state.actors[i];
|
|
747
|
+
if (!actorIsSleeping(runtime, item.actor) || item.file !== item.actor.components.Model?.file ||
|
|
748
|
+
(state.done && item.key && !world.models.has(item.key))) return false;
|
|
749
|
+
}
|
|
750
|
+
if (runtime.sleepVersion === undefined) {
|
|
751
|
+
// Older runtimes lack a revision. Existing identities above plus a count
|
|
752
|
+
// catch both replacements and new sleepers without recreating the queue.
|
|
753
|
+
let count = 0;
|
|
754
|
+
for (const actor of runtime.actors.values()) if (actorIsSleeping(runtime, actor)) count++;
|
|
755
|
+
if (count !== state.actors.length) return false;
|
|
756
|
+
}
|
|
757
|
+
return true;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
// Cheap completion check for frame policies: no new signatures, arrays or
|
|
761
|
+
// templates while a completed sleep set and its referenced assets stay put.
|
|
762
|
+
export function needsSleepingModelPrewarm(world, runtime) {
|
|
763
|
+
if (!world || world.disposed || world.modelLoadClearing || !hasSleepingActors(runtime)) return false;
|
|
764
|
+
const load = world.modelLoad;
|
|
765
|
+
if (load && (load.runtime !== runtime || load.data !== runtime.data || !load.restMarked)) return false;
|
|
766
|
+
if (runtime.data?.engine?.load && !load && readLoadKey(runtime.data)) return false;
|
|
767
|
+
const state = world.sleepingModelPrewarm;
|
|
768
|
+
return !prewarmStillCurrent(world, runtime, state) || !state.done;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
// A woken actor acquires its parked template during sync, not when its sleep
|
|
772
|
+
// flag changes. Prune only after that opportunity, using a current sleep set.
|
|
773
|
+
function pruneSleepingModels(world, runtime) {
|
|
774
|
+
const pending = world.sleepingModelPrune;
|
|
775
|
+
if (!pending?.size) return;
|
|
776
|
+
const state = world.sleepingModelPrewarm;
|
|
777
|
+
// Changes since the queue rebuild need a fresh key set. Keep the candidates
|
|
778
|
+
// for the next prewarm + sync rather than risk disposing a sleeper's build.
|
|
779
|
+
if (!prewarmStillCurrent(world, runtime, state)) return;
|
|
780
|
+
world.sleepingModelPrune = undefined;
|
|
781
|
+
for (const key of pending) {
|
|
782
|
+
const entry = world.models.get(key);
|
|
783
|
+
if (!entry || entry.users !== 0 || state.keys.has(key)) continue;
|
|
784
|
+
world.models.delete(key);
|
|
785
|
+
disposeNode(entry.template);
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
const prewarmNow = () => performance.now();
|
|
790
|
+
|
|
791
|
+
// Build only shared templates, with no actor node or instance acquired. The
|
|
792
|
+
// key, empty-part variant and deferred look baking match addModelRig exactly.
|
|
793
|
+
// Initial engine.load work owns the build budget until load:rest-built.
|
|
794
|
+
export function prewarmSleepingModels(world, runtime, { budgetMs = 4, now = prewarmNow } = {}) {
|
|
795
|
+
if ((world.modelCache || runtime.data?.engine?.modelCache) && !modelCacheVisitReady(world, runtime)) return 0;
|
|
796
|
+
if (!needsSleepingModelPrewarm(world, runtime)) return 0;
|
|
797
|
+
const started = now();
|
|
798
|
+
let state = world.sleepingModelPrewarm;
|
|
799
|
+
if (!prewarmStillCurrent(world, runtime, state)) {
|
|
800
|
+
const actors = [];
|
|
801
|
+
const origin = world.camera?.position;
|
|
802
|
+
const drops = runtime.dropsEmptyParts === true;
|
|
803
|
+
const fileReads = [], artReads = [];
|
|
804
|
+
const files = recordReads(runtime.files, fileReads);
|
|
805
|
+
const sprites = recordReads(runtime.sprites, artReads);
|
|
806
|
+
const keys = new Set(), byFile = new Map();
|
|
807
|
+
for (const actor of runtime.actors.values()) {
|
|
808
|
+
if (!actorIsSleeping(runtime, actor)) continue;
|
|
809
|
+
const file = actor.components.Model?.file;
|
|
810
|
+
if (file && !byFile.has(file)) {
|
|
811
|
+
// A template's signature depends on the file, not its placement.
|
|
812
|
+
// Read each shared model once, including sleepers beyond this slice.
|
|
813
|
+
byFile.set(file, parseModelCached(files[file])
|
|
814
|
+
? builtAs(drops, `${file}|${actorModelSig(actor, sprites, files)}`) : null);
|
|
815
|
+
}
|
|
816
|
+
const key = byFile.get(file) ?? null;
|
|
817
|
+
if (key) keys.add(key);
|
|
818
|
+
const t = actor.components.Transform;
|
|
819
|
+
actors.push({ actor, file, key,
|
|
820
|
+
distance: t && origin ? (t.x - origin.x) ** 2 + (t.z - origin.z) ** 2 : 0 });
|
|
821
|
+
}
|
|
822
|
+
actors.sort((a, b) => a.distance - b.distance);
|
|
823
|
+
state = world.sleepingModelPrewarm = { runtime, data: runtime.data,
|
|
824
|
+
sleepVersion: runtime.sleepVersion, drops,
|
|
825
|
+
later: runtime.bakesLookLater === true, look: lookIsEnabled(),
|
|
826
|
+
actors, keys, index: 0, done: false, fileReads, artReads: withReadiness(artReads) };
|
|
827
|
+
// Record obsolete parked keys, but give newly woken actors a renderer
|
|
828
|
+
// sync to acquire their templates before disposing any unused candidates.
|
|
829
|
+
for (const [key, entry] of world.models) {
|
|
830
|
+
if (entry.users !== 0 || keys.has(key)) continue;
|
|
831
|
+
(world.sleepingModelPrune ??= new Set()).add(key);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
const fileReads = state.fileReads;
|
|
835
|
+
const artReads = [];
|
|
836
|
+
const files = recordReads(runtime.files, fileReads);
|
|
837
|
+
const sprites = recordReads(runtime.sprites, artReads);
|
|
838
|
+
let built = 0;
|
|
839
|
+
while (state.index < state.actors.length) {
|
|
840
|
+
const item = state.actors[state.index++];
|
|
841
|
+
const { actor, file, key } = item;
|
|
842
|
+
if (key && actorIsSleeping(runtime, actor)) {
|
|
843
|
+
const model = parseModelCached(files?.[file]);
|
|
844
|
+
if (model) {
|
|
845
|
+
if (!world.models.has(key)) {
|
|
846
|
+
const build = () => buildModelNode(model, sprites, files, file, [file], { optimize: true });
|
|
847
|
+
const template = world.modelCache && !world.staticActorsOff
|
|
848
|
+
? world.modelCache.template(key, file, model, sprites, files, state.drops, build,
|
|
849
|
+
state.later ? (make, restore) => buildBakingLater(world, key, make, restore) : null, state.later)
|
|
850
|
+
: state.later ? buildBakingLater(world, key, build) : build();
|
|
851
|
+
if (state.drops) withoutEmptyParts(template, model);
|
|
852
|
+
world.models.set(key, { template, users: 0 });
|
|
853
|
+
world.hasParkedModels = true;
|
|
854
|
+
built++;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (now() - started >= budgetMs) break;
|
|
859
|
+
}
|
|
860
|
+
state.artReads.push(...withReadiness(artReads));
|
|
861
|
+
state.done = state.index === state.actors.length;
|
|
862
|
+
return built;
|
|
688
863
|
}
|
|
689
864
|
|
|
690
865
|
const DEG = Math.PI / 180;
|
|
@@ -695,6 +870,7 @@ const DEG = Math.PI / 180;
|
|
|
695
870
|
// degrees.
|
|
696
871
|
// Worlds that never asked do not enter any empty-node lifecycle helpers.
|
|
697
872
|
export function syncActors(world, runtime, sprites, dt = 0) {
|
|
873
|
+
if ((world.modelCache || runtime.data?.engine?.modelCache) && !modelCacheVisitReady(world, runtime)) return;
|
|
698
874
|
if (world.modelLoadClearing) return;
|
|
699
875
|
// The empty-node lifecycle can deliberately reject a reentrant sync. It
|
|
700
876
|
// must not become the load queue's first completed actor pass either.
|
|
@@ -727,7 +903,13 @@ export function syncActors(world, runtime, sprites, dt = 0) {
|
|
|
727
903
|
}
|
|
728
904
|
|
|
729
905
|
function syncActorPass(world, runtime, sprites, dt) {
|
|
906
|
+
let synced = false;
|
|
730
907
|
try {
|
|
908
|
+
if (world.sleepingModelRuntime !== runtime || world.sleepingModelData !== runtime.data) {
|
|
909
|
+
clearSleepingModels(world);
|
|
910
|
+
world.sleepingModelRuntime = runtime;
|
|
911
|
+
world.sleepingModelData = runtime.data;
|
|
912
|
+
}
|
|
731
913
|
if (world.frozenStatics && (world.frozenStatics.owner !== runtime.frozenActors || world.disposed || world.staticActorsOff || world.instanceModels)) {
|
|
732
914
|
world.frozenStatics.dispose();
|
|
733
915
|
delete world.frozenStatics;
|
|
@@ -736,7 +918,7 @@ function syncActorPass(world, runtime, sprites, dt) {
|
|
|
736
918
|
const state = world.emptyNodes;
|
|
737
919
|
if (world.disposed || world.emptyNodesBlocked || (world.emptyPass && state !== world.emptyPass)) return;
|
|
738
920
|
if (state && state.runtime === runtime) {
|
|
739
|
-
syncActorsWithEmptyNodes(world, runtime, sprites, dt, state);
|
|
921
|
+
synced = syncActorsWithEmptyNodes(world, runtime, sprites, dt, state) === true;
|
|
740
922
|
return;
|
|
741
923
|
}
|
|
742
924
|
}
|
|
@@ -745,6 +927,7 @@ function syncActorPass(world, runtime, sprites, dt) {
|
|
|
745
927
|
// seen in and out by the world's keeper (`syncActorsKept`, below).
|
|
746
928
|
if (world.stillKeeper || runtime.keepsStaticActors === true) {
|
|
747
929
|
syncActorsKept(world, runtime, sprites, dt);
|
|
930
|
+
synced = true;
|
|
748
931
|
return;
|
|
749
932
|
}
|
|
750
933
|
// Every other pass is counted while it runs, and that is all: nothing on a
|
|
@@ -754,11 +937,15 @@ function syncActorPass(world, runtime, sprites, dt) {
|
|
|
754
937
|
world.unkept = (world.unkept ?? 0) + 1;
|
|
755
938
|
try {
|
|
756
939
|
syncActorsAsEver(world, runtime, sprites, dt);
|
|
940
|
+
synced = true;
|
|
757
941
|
} finally {
|
|
758
942
|
world.unkept -= 1;
|
|
759
943
|
}
|
|
760
944
|
} catch (error) {
|
|
761
945
|
if (error !== EMPTY_PASS_ABORTED) throw error;
|
|
946
|
+
} finally {
|
|
947
|
+
if (world.hasParkedModels && !hasSleepingActors(runtime)) clearSleepingModels(world);
|
|
948
|
+
else if (synced && !world.syncDepth && !world.unkept) pruneSleepingModels(world, runtime);
|
|
762
949
|
}
|
|
763
950
|
}
|
|
764
951
|
|
|
@@ -778,6 +965,7 @@ function syncActorsWithEmptyNodes(world, runtime, sprites, dt, state) {
|
|
|
778
965
|
try { syncActorsAsEver(world, runtime, sprites, dt, placeEmptyActor); }
|
|
779
966
|
finally { world.unkept -= 1; }
|
|
780
967
|
}
|
|
968
|
+
return true;
|
|
781
969
|
} catch (error) {
|
|
782
970
|
if (error !== EMPTY_PASS_ABORTED) throw error;
|
|
783
971
|
} finally {
|
|
@@ -837,7 +1025,7 @@ function syncActorsAsEver(world, runtime, sprites, dt, place = placeActor) {
|
|
|
837
1025
|
}
|
|
838
1026
|
for (const [id, entry] of world.nodes) {
|
|
839
1027
|
if (seen.has(id)) continue;
|
|
840
|
-
releaseActorNode(world, entry);
|
|
1028
|
+
releaseActorNode(world, entry, actorIsSleeping(runtime, entry.actor));
|
|
841
1029
|
if (world.emptyPass) checkEmptyPass(world);
|
|
842
1030
|
world.nodes.delete(id);
|
|
843
1031
|
}
|
|
@@ -857,6 +1045,7 @@ function syncActorsAsEver(world, runtime, sprites, dt, place = placeActor) {
|
|
|
857
1045
|
// node only where its actor's signature still matches. A parked scene the
|
|
858
1046
|
// runtime no longer names is released.
|
|
859
1047
|
function swapSceneNodes(world, path, resident) {
|
|
1048
|
+
clearSleepingModels(world);
|
|
860
1049
|
const keep = resident instanceof Set ? resident : new Set();
|
|
861
1050
|
if (world.scenePath !== undefined && keep.has(world.scenePath) && world.scenePath !== path) {
|
|
862
1051
|
const parked = new Map();
|
|
@@ -1058,6 +1247,7 @@ export function disposeWorld(world) {
|
|
|
1058
1247
|
// such a sync writes nothing down; what was written down before goes now,
|
|
1059
1248
|
// and again after the listeners have run, whether or not one throws.
|
|
1060
1249
|
world.disposed = true;
|
|
1250
|
+
if (world.modelCache) { world.modelCache.close(); delete world.modelCache; }
|
|
1061
1251
|
if (world.frozenStatics) {
|
|
1062
1252
|
world.frozenStatics.dispose();
|
|
1063
1253
|
delete world.frozenStatics;
|
|
@@ -1114,6 +1304,8 @@ function disposeNodes(world) {
|
|
|
1114
1304
|
for (const entry of parked.values()) releaseActorNode(world, entry);
|
|
1115
1305
|
}
|
|
1116
1306
|
world.parked.clear();
|
|
1307
|
+
world.sleepingModelRuntime = world.sleepingModelData = undefined;
|
|
1308
|
+
clearSleepingModels(world);
|
|
1117
1309
|
world.renderer.dispose();
|
|
1118
1310
|
} finally {
|
|
1119
1311
|
forgetEverything(world);
|
|
@@ -1278,7 +1470,7 @@ function skippingPass(world, runtime, sprites, dt, started, drops, pass, place =
|
|
|
1278
1470
|
}
|
|
1279
1471
|
// While the pass was alone every actor seen has its node and no node was
|
|
1280
1472
|
// released, so as many nodes as actors seen means no node has lost its actor.
|
|
1281
|
-
if (world.generation !== started || seen.size !== world.nodes.size) releaseUnseen(world, seen);
|
|
1473
|
+
if (world.generation !== started || seen.size !== world.nodes.size) releaseUnseen(world, seen, runtime);
|
|
1282
1474
|
if (world.instances.size > 0) {
|
|
1283
1475
|
leavingTheEngine(world);
|
|
1284
1476
|
aimInstances(world.camera);
|
|
@@ -1319,6 +1511,7 @@ function placeActor(world, actor, t, sprites, files, started, drops) {
|
|
|
1319
1511
|
const alone = world.generation === started;
|
|
1320
1512
|
const entry = started === undefined ? ensureActorNode(world, actor, sprites, files, drops)
|
|
1321
1513
|
: alone ? nodeFor(world, actor, sprites, files, drops) : nodeAsMain(world, actor, sprites, files, drops);
|
|
1514
|
+
entry.actor = actor;
|
|
1322
1515
|
const node = entry.node;
|
|
1323
1516
|
node.position.set(t.x, t.y, t.z);
|
|
1324
1517
|
const quat = actor.runtime?.quat;
|
|
@@ -1337,6 +1530,7 @@ function placeEmptyActor(world, actor, transform, sprites, files, started, drops
|
|
|
1337
1530
|
const found = started === undefined ? ensureActorNode(world, actor, sprites, files, drops)
|
|
1338
1531
|
: world.generation === started ? nodeFor(world, actor, sprites, files, drops)
|
|
1339
1532
|
: nodeAsMain(world, actor, sprites, files, drops);
|
|
1533
|
+
found.actor = actor;
|
|
1340
1534
|
checkEmptyPass(world);
|
|
1341
1535
|
putEmptyActor(found.node, transform, actor.runtime?.quat,
|
|
1342
1536
|
world.generation === started ? snapshotOf(world, found) : null);
|
|
@@ -1363,20 +1557,20 @@ function putEmptyActor(node, t, quat, snapshot = null) {
|
|
|
1363
1557
|
if (detached && (moved || !Object.is(q.x, x) || !Object.is(q.y, y) || !Object.is(q.z, z) || !Object.is(q.w, w))) updateEmptyNode(node);
|
|
1364
1558
|
}
|
|
1365
1559
|
|
|
1366
|
-
function releaseUnseen(world, seen) {
|
|
1560
|
+
function releaseUnseen(world, seen, runtime) {
|
|
1367
1561
|
for (const [id, entry] of world.nodes) {
|
|
1368
1562
|
if (seen.has(id)) continue;
|
|
1369
|
-
releaseNode(world, entry);
|
|
1563
|
+
releaseNode(world, entry, actorIsSleeping(runtime, entry.actor));
|
|
1370
1564
|
if (world.emptyPass) checkEmptyPass(world);
|
|
1371
1565
|
world.nodes.delete(id);
|
|
1372
1566
|
}
|
|
1373
1567
|
}
|
|
1374
1568
|
|
|
1375
1569
|
// `releaseActorNode`, from a skipping pass.
|
|
1376
|
-
function releaseNode(world, entry) {
|
|
1570
|
+
function releaseNode(world, entry, park = false) {
|
|
1377
1571
|
leavingTheEngine(world);
|
|
1378
1572
|
entry.node.computedFrom = null;
|
|
1379
|
-
releaseActorNode(world, entry);
|
|
1573
|
+
releaseActorNode(world, entry, park);
|
|
1380
1574
|
}
|
|
1381
1575
|
|
|
1382
1576
|
// The signature suffix for a Model component's file: `actorModelSig`'s, for an
|
|
@@ -1786,7 +1980,7 @@ function syncFrozenActors(world, runtime, sprites, dt, place) {
|
|
|
1786
1980
|
if (runtime.getActor(actor.id) !== actor || runtime.isActorSleeping(actor) || !t) {
|
|
1787
1981
|
if (runtime.getActor(actor.id) && runtime.getActor(actor.id) !== actor) { state.forget(actor); continue; }
|
|
1788
1982
|
const entry = world.nodes.get(actor.id);
|
|
1789
|
-
if (entry) { releaseNode(world, entry); world.nodes.delete(actor.id); }
|
|
1983
|
+
if (entry) { releaseNode(world, entry, actorIsSleeping(runtime, actor)); world.nodes.delete(actor.id); }
|
|
1790
1984
|
state.forget(actor);
|
|
1791
1985
|
continue;
|
|
1792
1986
|
}
|
|
@@ -1809,7 +2003,7 @@ function syncFrozenActors(world, runtime, sprites, dt, place) {
|
|
|
1809
2003
|
// from another scene. Reconcile that baseline once, as the full pass does.
|
|
1810
2004
|
if (state.reconcileNodes) {
|
|
1811
2005
|
const seen = new Set(runtime.getActors().filter(actor => actor.components.Transform).map(actor => actor.id));
|
|
1812
|
-
releaseUnseen(world, seen);
|
|
2006
|
+
releaseUnseen(world, seen, runtime);
|
|
1813
2007
|
if (world.frozenStatics !== state) return;
|
|
1814
2008
|
state.reconcileNodes = false;
|
|
1815
2009
|
}
|
|
@@ -1958,7 +2152,7 @@ function settledPass(world, runtime, sprites, dt, started, drops, place) {
|
|
|
1958
2152
|
if (world.generation !== started || seen.size + skipped !== world.nodes.size) {
|
|
1959
2153
|
// A still actor passed over is still the runtime's, and keeps its node.
|
|
1960
2154
|
for (const actor of still) seen.add(actor.id);
|
|
1961
|
-
releaseUnseen(world, seen);
|
|
2155
|
+
releaseUnseen(world, seen, runtime);
|
|
1962
2156
|
}
|
|
1963
2157
|
if (world.instances.size > 0) {
|
|
1964
2158
|
leavingTheEngine(world);
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
"scripts": {
|
|
6
6
|
"restart": "castle-web restart .",
|
|
7
7
|
"screenshot": "castle-web screenshot .",
|
|
8
|
-
"
|
|
8
|
+
"test:wall-slide": "node scripts/test-wall-slide.mjs",
|
|
9
|
+
"check": "eslint . && jscpd && npm run test:wall-slide && node scripts/test-rapier-gz.mjs && node scripts/test-ground-half.mjs && node scripts/test-memory-profile.mjs && node scripts/test-model-parse-cache.mjs && node scripts/test-sleeping-models.mjs && node scripts/test-static-actors.mjs && node scripts/test-frozen-statics.mjs && node scripts/test-frozen-nested.mjs && node scripts/test-frozen-statics-legacy-physics2d.mjs && node scripts/test-skip-empty-nodes.mjs && node scripts/test-view-range.mjs && node scripts/test-look-bake.mjs && node scripts/test-template-cache.mjs && node scripts/test-template-cache-minified.mjs && node scripts/test-model-cache.mjs && node scripts/test-square-first.mjs && node --input-type=module -e \"const { bundleProject } = await import('castle-web-cli/dist/bundle.js'); await bundleProject('.');\""
|
|
9
10
|
},
|
|
10
11
|
"jscpd": {
|
|
11
12
|
"path": [
|
|
@@ -87,10 +87,50 @@ function hoverSteadily(phys, actor, t, dims) {
|
|
|
87
87
|
function pullSteadily(phys, actor) {
|
|
88
88
|
phys.addForce(actor, { x: 0, y: -14 * phys.mass(actor), z: 0 });
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
// Clip the requested walk against at most two nearby wall planes. A second
|
|
91
|
+
// plane that sends the tangent back into the first is a closed corner.
|
|
92
|
+
// Keep the tangent's length: projecting must not speed up a diagonal walk.
|
|
93
|
+
function slideMove(phys, actor, move) {
|
|
94
|
+
const wanted = move;
|
|
95
|
+
let first = null;
|
|
96
|
+
let excludeCollider;
|
|
97
|
+
for (let i = 0; i < 2; i += 1) {
|
|
98
|
+
const length = Math.hypot(move.x, move.z);
|
|
99
|
+
if (length < 1e-6)
|
|
100
|
+
return { x: 0, z: 0 };
|
|
101
|
+
const hit = phys.castWalkWall(actor, { x: move.x / length, y: 0, z: move.z / length }, 0.12, excludeCollider);
|
|
102
|
+
const n = hit?.normal;
|
|
103
|
+
// castWalkWall resolves convex-edge support normals to surface faces:
|
|
104
|
+
// adjoining boxes in a straight wall do not supply a second wall plane.
|
|
105
|
+
// Floors and slopes keep their existing drive; only near-vertical faces.
|
|
106
|
+
if (!n || Math.abs(n.y) > 0.2)
|
|
107
|
+
break;
|
|
108
|
+
const horizontal = Math.hypot(n.x, n.z);
|
|
109
|
+
if (horizontal < 1e-6)
|
|
110
|
+
break;
|
|
111
|
+
const normal = { x: n.x / horizontal, z: n.z / horizontal };
|
|
112
|
+
const into = move.x * normal.x + move.z * normal.z;
|
|
113
|
+
if (into >= -1e-6)
|
|
114
|
+
break;
|
|
115
|
+
// Reproject the original request on the second plane. Projecting the
|
|
116
|
+
// first tangent again can create an unwanted escape along the corner
|
|
117
|
+
// (and drift from tiny errors in Rapier's sweep normals).
|
|
118
|
+
const amount = wanted.x * normal.x + wanted.z * normal.z;
|
|
119
|
+
move = { x: wanted.x - amount * normal.x, z: wanted.z - amount * normal.z };
|
|
120
|
+
if (first && move.x * first.x + move.z * first.z < -1e-6)
|
|
121
|
+
return { x: 0, z: 0 };
|
|
122
|
+
first = normal;
|
|
123
|
+
excludeCollider = hit.colliderHandle;
|
|
124
|
+
}
|
|
125
|
+
return move;
|
|
126
|
+
}
|
|
127
|
+
function applyMove(phys, actor, move, speed, grounded, dt, scene) {
|
|
91
128
|
const mass = phys.mass(actor);
|
|
92
129
|
const vel = phys.getVelocity(actor);
|
|
93
130
|
if (move) {
|
|
131
|
+
if (scene.data?.engine?.player?.slideOnWalls === true && grounded && vel.y <= 1) {
|
|
132
|
+
move = slideMove(phys, actor, move);
|
|
133
|
+
}
|
|
94
134
|
const factor = Math.min(1, dt * 14) * (grounded ? 1 : 0.3);
|
|
95
135
|
phys.applyImpulse(actor, {
|
|
96
136
|
x: (move.x * speed - vel.x) * mass * factor,
|
|
@@ -471,7 +511,7 @@ function updateOrbiting(actor, scene, props, dt) {
|
|
|
471
511
|
scene.playerDrive.step(actor, phys, { keys: scene.keys, stick: scene.moveInput, grounded }, dt);
|
|
472
512
|
}
|
|
473
513
|
else {
|
|
474
|
-
applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt);
|
|
514
|
+
applyMove(phys, actor, driveOrbiting(scene, per, rt, props, dt), props.speed, grounded, dt, scene);
|
|
475
515
|
t.rotationY = rt.facing / DEG;
|
|
476
516
|
jumpOrbiting(phys, actor, scene, rt, grounded, props.jumpSpeed, dt);
|
|
477
517
|
}
|
|
@@ -1170,7 +1210,7 @@ class Player {
|
|
|
1170
1210
|
z: -Math.cos(per.camAngle) * drive.forward,
|
|
1171
1211
|
}
|
|
1172
1212
|
: null;
|
|
1173
|
-
applyMove(phys, actor, move, this.props.speed, grounded, dt);
|
|
1213
|
+
applyMove(phys, actor, move, this.props.speed, grounded, dt, scene);
|
|
1174
1214
|
t.rotationY = rt.facing / DEG;
|
|
1175
1215
|
// Jump: Space on keyboard, or a short tap anywhere on the canvas (which
|
|
1176
1216
|
// works while another finger drives the drag stick). A tap is buffered
|
|
@@ -12,15 +12,25 @@
|
|
|
12
12
|
// instead (render/sheet.js), saved as `<name>-motion.png`.
|
|
13
13
|
//
|
|
14
14
|
// The pixels come from the playtest service, the one a task agent uses. The
|
|
15
|
-
// script builds a scratch deck in
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
15
|
+
// script builds a scratch deck -- the page in `render/` plus links to this
|
|
16
|
+
// deck's imports and node_modules -- serves it on a free port, and stops that
|
|
17
|
+
// serve when done. A playtest takes at most six screenshots, so each covers two
|
|
18
|
+
// models of three pages, pressing `n` between pages. The pages are joined side
|
|
19
|
+
// by side here.
|
|
20
|
+
//
|
|
21
|
+
// The scratch deck lives in the OS temp dir, one per deck
|
|
22
|
+
// (`<tmpdir>/castle-render/<hash of the deck's path>/sheet-deck`), never inside
|
|
23
|
+
// the deck: a cloud sandbox's checkpoint of the deck refuses its links, so every
|
|
24
|
+
// save failed while one sat in `.castle/render/`. In a sandbox the temp dir is
|
|
25
|
+
// another filesystem; links across it are fine, a rename across it is not, and
|
|
26
|
+
// nothing here renames. A scratch deck an older version left in the deck is
|
|
27
|
+
// removed on start.
|
|
20
28
|
|
|
21
29
|
import { spawn } from 'node:child_process';
|
|
30
|
+
import { createHash } from 'node:crypto';
|
|
22
31
|
import * as fs from 'node:fs';
|
|
23
32
|
import * as net from 'node:net';
|
|
33
|
+
import * as os from 'node:os';
|
|
24
34
|
import * as path from 'node:path';
|
|
25
35
|
import { fileURLToPath } from 'node:url';
|
|
26
36
|
import * as zlib from 'node:zlib';
|
|
@@ -28,7 +38,16 @@ import * as zlib from 'node:zlib';
|
|
|
28
38
|
const KIT_RENDER_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), 'render');
|
|
29
39
|
const DECK = process.cwd();
|
|
30
40
|
const WORK = path.join(DECK, '.castle', 'render');
|
|
31
|
-
|
|
41
|
+
// Stable per deck, so a kept serve (CASTLE_RENDER_KEEP=1) is found again and
|
|
42
|
+
// renders of the same deck share its start lock. Both paths are real paths:
|
|
43
|
+
// macOS's temp dir is behind a link, and vite resolves served files through
|
|
44
|
+
// links, so the serve's root should be the path its own files resolve to.
|
|
45
|
+
const SCRATCH = path.join(
|
|
46
|
+
fs.realpathSync(os.tmpdir()),
|
|
47
|
+
'castle-render',
|
|
48
|
+
createHash('sha256').update(fs.realpathSync(DECK)).digest('hex').slice(0, 12)
|
|
49
|
+
);
|
|
50
|
+
const SHEET_DECK = path.join(SCRATCH, 'sheet-deck');
|
|
32
51
|
|
|
33
52
|
// The deck's package.json sets this to the command its other scripts use.
|
|
34
53
|
const CLI = (process.env.CASTLE_WEB_CLI || 'castle-web').trim().split(/\s+/);
|
|
@@ -195,7 +214,36 @@ function copyText(from, to) {
|
|
|
195
214
|
fs.writeFileSync(to, fs.readFileSync(from));
|
|
196
215
|
}
|
|
197
216
|
|
|
217
|
+
// Older versions built the scratch deck at `.castle/render/sheet-deck/`. It
|
|
218
|
+
// holds only links and copies, and the links point back into this deck, so they
|
|
219
|
+
// are unlinked first and never followed.
|
|
220
|
+
function removeOldSheetDeck() {
|
|
221
|
+
const old = path.join(WORK, 'sheet-deck');
|
|
222
|
+
const unlinkLinks = (dir) => {
|
|
223
|
+
let entries;
|
|
224
|
+
try {
|
|
225
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
226
|
+
} catch {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
for (const entry of entries) {
|
|
230
|
+
const at = path.join(dir, entry.name);
|
|
231
|
+
if (entry.isSymbolicLink()) {
|
|
232
|
+
// Another render of this deck may have taken it already.
|
|
233
|
+
fs.rmSync(at, { force: true });
|
|
234
|
+
} else if (entry.isDirectory()) {
|
|
235
|
+
unlinkLinks(at);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
if (fs.lstatSync(old, { throwIfNoEntry: false })?.isDirectory()) {
|
|
240
|
+
unlinkLinks(old);
|
|
241
|
+
}
|
|
242
|
+
fs.rmSync(old, { recursive: true, force: true });
|
|
243
|
+
}
|
|
244
|
+
|
|
198
245
|
function writeSheetDeck() {
|
|
246
|
+
removeOldSheetDeck();
|
|
199
247
|
fs.mkdirSync(SHEET_DECK, { recursive: true });
|
|
200
248
|
for (const name of ['index.html', 'sheet.js', 'filmstrip.js']) {
|
|
201
249
|
copyText(path.join(KIT_RENDER_DIR, name), path.join(SHEET_DECK, name));
|
|
@@ -269,8 +317,8 @@ async function runningServe() {
|
|
|
269
317
|
|
|
270
318
|
// Renders in the same deck at the same time take turns starting its serve.
|
|
271
319
|
async function withStartLock(start) {
|
|
272
|
-
const lock = path.join(
|
|
273
|
-
fs.mkdirSync(
|
|
320
|
+
const lock = path.join(SCRATCH, 'serve.lock');
|
|
321
|
+
fs.mkdirSync(SCRATCH, { recursive: true });
|
|
274
322
|
for (;;) {
|
|
275
323
|
try {
|
|
276
324
|
fs.mkdirSync(lock);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { deflateSync, inflateSync } from 'three/examples/jsm/libs/fflate.module.js';
|
|
2
|
+
|
|
3
|
+
// Alter otherwise valid entries, preserving framing and compressed payloads.
|
|
4
|
+
export function changeTemplate(bytes, change) {
|
|
5
|
+
const view = new DataView(bytes);
|
|
6
|
+
const header = JSON.parse(new TextDecoder().decode(new Uint8Array(bytes, 16, view.getUint32(8, true))));
|
|
7
|
+
const stored = new Uint8Array(bytes, Math.ceil((16 + view.getUint32(8, true)) / 8) * 8);
|
|
8
|
+
const payload = header.payloadCodec === 'deflate' ? inflateSync(stored) : stored.slice();
|
|
9
|
+
change(header, payload);
|
|
10
|
+
header.payloadCodec = 'deflate';
|
|
11
|
+
const compressed = deflateSync(payload, { level: 1 });
|
|
12
|
+
const json = new TextEncoder().encode(JSON.stringify(header));
|
|
13
|
+
const start = Math.ceil((16 + json.length) / 8) * 8;
|
|
14
|
+
const result = new ArrayBuffer(start + compressed.length);
|
|
15
|
+
const prefix = new DataView(result);
|
|
16
|
+
[view.getUint32(0, true), view.getUint32(4, true), json.length, compressed.length].forEach((value, index) => prefix.setUint32(index * 4, value, true));
|
|
17
|
+
new Uint8Array(result, 16, json.length).set(json);
|
|
18
|
+
new Uint8Array(result, start).set(compressed);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function templateArray(attribute, payload) {
|
|
23
|
+
const [, , offset, count, storage] = attribute.array;
|
|
24
|
+
return new globalThis[storage](payload.buffer, payload.byteOffset + offset, count);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function templateGroups(start, count, materialIndex = 0) {
|
|
28
|
+
return ['list', [['object', [['start', start], ['count', count], ['materialIndex', materialIndex]]]]];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function outOfRangeIndex(header, payload) {
|
|
32
|
+
const geometry = header.geometries[0];
|
|
33
|
+
const position = geometry.attributes.find(([key]) => key === 'position')[1];
|
|
34
|
+
if (!geometry.index) geometry.index = { ...position, type: 'BufferAttribute', itemSize: 1, normalized: false,
|
|
35
|
+
array: ['array', 'Uint32Array', position.array[2], 3, 'Uint32Array', 1000000] };
|
|
36
|
+
templateArray(geometry.index, payload)[0] = position.array[3] / position.itemSize;
|
|
37
|
+
}
|