castle-web-cli 0.4.232 → 0.4.234
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-failures.d.ts +8 -0
- package/dist/agent-failures.js +19 -2
- package/dist/agent-prompts.d.ts +1 -1
- package/dist/agent-prompts.js +10 -3
- package/dist/agent.d.ts +64 -3
- package/dist/agent.js +170 -81
- package/dist/api.d.ts +11 -0
- package/dist/api.js +43 -0
- package/dist/bundle.d.ts +64 -0
- package/dist/bundle.js +558 -2
- package/dist/castle-host/host.d.ts +18 -2
- package/dist/castle-host/host.js +844 -39
- package/dist/castleJson.d.ts +23 -2
- package/dist/castleJson.js +46 -2
- package/dist/check.d.ts +3 -1
- package/dist/check.js +20 -3
- package/dist/chunkLoader.d.ts +3 -0
- package/dist/chunkLoader.js +111 -0
- package/dist/devParty.d.ts +26 -0
- package/dist/devParty.js +231 -0
- package/dist/devSaveStorage.js +4 -0
- package/dist/devSessionStorage.js +50 -2
- package/dist/devSocial.d.ts +24 -0
- package/dist/devSocial.js +70 -0
- package/dist/ide.d.ts +2 -0
- package/dist/ide.js +119 -15
- package/dist/importPinMismatch.d.ts +22 -0
- package/dist/importPinMismatch.js +77 -0
- package/dist/importRegression.js +3 -15
- package/dist/imports.d.ts +10 -3
- package/dist/imports.js +88 -20
- package/dist/index.js +11 -4
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +22 -0
- package/dist/routerFences.d.ts +5 -0
- package/dist/routerFences.js +12 -2
- package/dist/save-deck.d.ts +25 -1
- package/dist/save-deck.js +178 -9
- package/dist/serve.js +32 -11
- package/dist/shell/assets/{index-D2tWM896.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/assets/index-MVLfNYd9.css +1 -0
- package/dist/shell/index.html +2 -2
- package/dist/taskSteer.d.ts +13 -0
- package/dist/taskSteer.js +22 -2
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +339 -5
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +176 -1
- package/kits/base/sdk/commands.js +3 -0
- package/kits/base/sdk/display.d.ts +3 -0
- package/kits/base/sdk/display.js +9 -3
- package/kits/base/sdk/hub.d.ts +37 -6
- package/kits/base/sdk/hub.js +63 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +148 -32
- package/kits/base/sdk/multiplayerProtocol.d.ts +2 -0
- package/kits/base/sdk/party.d.ts +23 -0
- package/kits/base/sdk/party.js +91 -0
- package/kits/base/sdk/reconnectBudget.d.ts +23 -0
- package/kits/base/sdk/reconnectBudget.js +96 -0
- package/kits/base/sdk/save.d.ts +38 -1
- package/kits/base/sdk/save.js +81 -7
- package/kits/base/sdk/server/hub.d.ts +117 -0
- package/kits/base/sdk/server/hub.js +119 -2
- package/kits/base/sdk/server/platformHandle.d.ts +43 -1
- package/kits/base/sdk/server/storage.d.ts +17 -0
- package/kits/base/sdk/server/storage.js +65 -3
- package/kits/base/sdk/server/wrapper.d.ts +43 -6
- package/kits/base/sdk/server/wrapper.js +93 -9
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +451 -13
- package/kits/hub-game/README.md +63 -0
- package/kits/hub-game/blueprints/avatar-10.scene +28 -0
- package/kits/hub-game/blueprints/avatar-11.scene +28 -0
- package/kits/hub-game/blueprints/avatar-12.scene +28 -0
- package/kits/hub-game/blueprints/avatar-13.scene +28 -0
- package/kits/hub-game/blueprints/avatar-14.scene +28 -0
- package/kits/hub-game/blueprints/avatar-15.scene +28 -0
- package/kits/hub-game/blueprints/avatar-4.scene +28 -0
- package/kits/hub-game/blueprints/avatar-5.scene +28 -0
- package/kits/hub-game/blueprints/avatar-6.scene +28 -0
- package/kits/hub-game/blueprints/avatar-7.scene +28 -0
- package/kits/hub-game/blueprints/avatar-8.scene +28 -0
- package/kits/hub-game/blueprints/avatar-9.scene +28 -0
- package/kits/hub-game/castle.json +5 -5
- package/kits/hub-game/code/client/act.js +312 -0
- package/kits/hub-game/code/client/actionLayout.js +147 -0
- package/kits/hub-game/code/client/actionOverflow.js +556 -0
- package/kits/hub-game/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +311 -35
- package/kits/hub-game/code/client/avatarCap.js +228 -0
- package/kits/hub-game/code/client/avatarColors.js +70 -0
- package/kits/hub-game/code/client/avatarFaces.js +21 -0
- package/kits/hub-game/code/client/avatarShare.js +253 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +472 -0
- package/kits/hub-game/code/client/build.js +38 -0
- package/kits/hub-game/code/client/chat.js +41 -5
- package/kits/hub-game/code/client/chatModeration.js +5 -0
- package/kits/hub-game/code/client/chrome.js +2144 -160
- package/kits/hub-game/code/client/companion.js +716 -0
- package/kits/hub-game/code/client/companionDress.js +99 -0
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +515 -0
- package/kits/hub-game/code/client/defaultEnvironment.js +194 -0
- package/kits/hub-game/code/client/doorErrors.js +39 -0
- package/kits/hub-game/code/client/earned.js +131 -0
- package/kits/hub-game/code/client/emoteBubble.js +75 -0
- package/kits/hub-game/code/client/fall.js +18 -0
- package/kits/hub-game/code/client/farAvatars.js +233 -0
- package/kits/hub-game/code/client/firstJoin.js +9 -2
- package/kits/hub-game/code/client/fpsTelemetry.js +50 -0
- package/kits/hub-game/code/client/frameBatch.js +5 -0
- package/kits/hub-game/code/client/grab.js +368 -29
- package/kits/hub-game/code/client/hookLayer.js +385 -20
- package/kits/hub-game/code/client/hudCopy.js +51 -0
- package/kits/hub-game/code/client/hudRate.js +20 -0
- package/kits/hub-game/code/client/idle.js +177 -24
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/invites.js +231 -0
- package/kits/hub-game/code/client/joinError.js +9 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +234 -0
- package/kits/hub-game/code/client/landscapeLayout.js +17 -0
- package/kits/hub-game/code/client/layoutCache.js +264 -0
- package/kits/hub-game/code/client/loadTelemetry.js +20 -0
- package/kits/hub-game/code/client/loadingCover.js +148 -0
- package/kits/hub-game/code/client/loadingEntry.js +8 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -0
- package/kits/hub-game/code/client/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- package/kits/hub-game/code/client/pack.js +6 -2
- package/kits/hub-game/code/client/packFormat.js +3 -3
- package/kits/hub-game/code/client/padCueArrival.js +23 -0
- package/kits/hub-game/code/client/padCues.js +112 -0
- package/kits/hub-game/code/client/padOccupancy.js +88 -0
- package/kits/hub-game/code/client/padReadability.js +26 -0
- package/kits/hub-game/code/client/padRings.js +69 -0
- package/kits/hub-game/code/client/pushVisit.js +14 -0
- package/kits/hub-game/code/client/quality.js +205 -0
- package/kits/hub-game/code/client/qualityEntry.js +55 -0
- package/kits/hub-game/code/client/rehello.js +167 -0
- package/kits/hub-game/code/client/safeLayout.js +338 -0
- package/kits/hub-game/code/client/safeStyle.js +42 -0
- package/kits/hub-game/code/client/say.js +12 -3
- package/kits/hub-game/code/client/shot.js +146 -0
- package/kits/hub-game/code/client/shotFit.js +56 -0
- package/kits/hub-game/code/client/signIn.js +28 -0
- package/kits/hub-game/code/client/sound.js +63 -8
- package/kits/hub-game/code/client/soundscape.js +1151 -0
- package/kits/hub-game/code/client/soundscapeActions.js +99 -0
- package/kits/hub-game/code/client/soundscapeAmbience.js +453 -0
- package/kits/hub-game/code/client/soundscapeBaked.js +143 -0
- package/kits/hub-game/code/client/soundscapeBusker.js +217 -0
- package/kits/hub-game/code/client/soundscapeCourt.js +200 -0
- package/kits/hub-game/code/client/soundscapeCrowd.js +331 -0
- package/kits/hub-game/code/client/soundscapeCues.js +362 -0
- package/kits/hub-game/code/client/soundscapeMap.js +181 -0
- package/kits/hub-game/code/client/soundscapeMarket.js +176 -0
- package/kits/hub-game/code/client/soundscapeMusic.js +126 -0
- package/kits/hub-game/code/client/soundscapeMusicEngine.js +460 -0
- package/kits/hub-game/code/client/soundscapeSimlish.js +737 -0
- package/kits/hub-game/code/client/soundscapeSongs.js +127 -0
- package/kits/hub-game/code/client/soundscapeSongsRound3.js +63 -0
- package/kits/hub-game/code/client/soundscapeSynthesis.js +168 -0
- package/kits/hub-game/code/client/soundscapeUi.js +211 -0
- package/kits/hub-game/code/client/soundscapeVoice.js +1209 -0
- package/kits/hub-game/code/client/soundscapeWaves.js +206 -0
- package/kits/hub-game/code/client/spin.js +101 -0
- package/kits/hub-game/code/client/state.js +162 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +714 -59
- package/kits/hub-game/code/client/tiers.js +543 -52
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +39 -2
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/weakestLookBake.js +92 -0
- package/kits/hub-game/code/client/weakestTier.js +295 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +200 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +138 -0
- package/kits/hub-game/code/server/actors.js +11 -2
- package/kits/hub-game/code/server/analytics.js +83 -0
- package/kits/hub-game/code/server/anonymousEntry.js +49 -0
- package/kits/hub-game/code/server/arrivalPose.js +36 -0
- package/kits/hub-game/code/server/ask.js +155 -0
- package/kits/hub-game/code/server/ballot.js +539 -0
- package/kits/hub-game/code/server/cells.js +100 -0
- package/kits/hub-game/code/server/companion.js +107 -0
- package/kits/hub-game/code/server/cues.js +70 -0
- package/kits/hub-game/code/server/decor.js +269 -0
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +478 -0
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +272 -0
- package/kits/hub-game/code/server/history.js +7 -0
- package/kits/hub-game/code/server/hub.js +2510 -95
- package/kits/hub-game/code/server/idle.js +60 -12
- package/kits/hub-game/code/server/index.js +28 -6
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +36 -2
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +586 -7
- package/kits/hub-game/code/server/menu.js +161 -0
- package/kits/hub-game/code/server/npcs.js +1025 -113
- package/kits/hub-game/code/server/observe.js +408 -0
- package/kits/hub-game/code/server/padOccupancy.js +85 -0
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +30 -0
- package/kits/hub-game/code/server/resumePose.js +152 -0
- package/kits/hub-game/code/server/say.js +1 -1
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +123 -0
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +175 -0
- package/kits/hub-game/code/server/wear.js +12 -0
- package/kits/hub-game/code/server/yours.js +59 -0
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/cues.js +9 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/loadStages.js +12 -0
- package/kits/hub-game/code/shared/quality.js +74 -0
- package/kits/hub-game/code/shared/say.js +2 -0
- package/kits/hub-game/code/shared/shot.js +53 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +1753 -202
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +3475 -77
- package/kits/hub-game/docs/home-pieces.md +71 -0
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/models/avatar-10.pxmodel +28 -0
- package/kits/hub-game/models/avatar-11.pxmodel +28 -0
- package/kits/hub-game/models/avatar-12.pxmodel +27 -0
- package/kits/hub-game/models/avatar-13.pxmodel +24 -0
- package/kits/hub-game/models/avatar-14.pxmodel +29 -0
- package/kits/hub-game/models/avatar-15.pxmodel +24 -0
- package/kits/hub-game/models/avatar-4.pxmodel +29 -0
- package/kits/hub-game/models/avatar-5.pxmodel +27 -0
- package/kits/hub-game/models/avatar-6.pxmodel +26 -0
- package/kits/hub-game/models/avatar-7.pxmodel +25 -0
- package/kits/hub-game/models/avatar-8.pxmodel +24 -0
- package/kits/hub-game/models/avatar-9.pxmodel +30 -0
- package/kits/hub-game/models/earned/badge-round.pxmodel +100 -0
- package/kits/hub-game/models/earned/badge-shield.pxmodel +117 -0
- package/kits/hub-game/models/earned/badge-star.pxmodel +87 -0
- package/kits/hub-game/models/earned/belt-plain.pxmodel +72 -0
- package/kits/hub-game/models/earned/held-ball.pxmodel +43 -0
- package/kits/hub-game/models/earned/held-lantern.pxmodel +85 -0
- package/kits/hub-game/models/earned/held-net.pxmodel +57 -0
- package/kits/hub-game/models/earned/held-trophy.pxmodel +109 -0
- package/kits/hub-game/models/earned/pin-round.pxmodel +62 -0
- package/kits/hub-game/models/earned/sash-plain.pxmodel +66 -0
- package/kits/hub-game/models/earned/square/belt-plain.pxmodel +104 -0
- package/kits/hub-game/models/earned/square/sash-plain.pxmodel +98 -0
- package/kits/hub-game/models/hats/bat-clip.pxmodel +206 -0
- package/kits/hub-game/models/hats/beekeeper.pxmodel +149 -0
- package/kits/hub-game/models/hats/cap.pxmodel +162 -0
- package/kits/hub-game/models/hats/captain.pxmodel +178 -0
- package/kits/hub-game/models/hats/crooked-top.pxmodel +172 -0
- package/kits/hub-game/models/hats/flower-crown.pxmodel +451 -0
- package/kits/hub-game/models/hats/foam-crown.pxmodel +179 -0
- package/kits/hub-game/models/hats/lantern.pxmodel +230 -0
- package/kits/hub-game/models/hats/laurel.pxmodel +533 -0
- package/kits/hub-game/models/hats/lighthouse.pxmodel +96 -0
- package/kits/hub-game/models/hats/sailor.pxmodel +141 -0
- package/kits/hub-game/models/hats/souwester.pxmodel +131 -0
- package/kits/hub-game/models/hats/straw.pxmodel +139 -0
- package/kits/hub-game/models/hats/sunflower.pxmodel +406 -0
- package/kits/hub-game/models/hats/sweatband.pxmodel +112 -0
- package/kits/hub-game/models/hats/witch.pxmodel +147 -0
- package/kits/hub-game/package-lock.json +10 -1
- package/kits/hub-game/package.json +6 -2
- package/kits/hub-game/play/player.js +142 -0
- package/kits/hub-game/play/registry.js +47 -0
- package/kits/hub-game/play.jsx +37 -0
- package/kits/hub-game/scripts/check.mjs +117 -16
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +132 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +26 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +123 -0
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +385 -0
- package/kits/hub-game/scripts/fixtures/npc-notes-v1.77.jsonl +4 -0
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -0
- package/kits/hub-game/scripts/gen-avatars.mjs +933 -16
- package/kits/hub-game/scripts/gen-earned.mjs +285 -0
- package/kits/hub-game/scripts/gen-hats.mjs +827 -0
- package/kits/hub-game/scripts/grab.before-orbit.mjs +400 -0
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -0
- package/kits/hub-game/scripts/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-act-client.mjs +186 -0
- package/kits/hub-game/scripts/test-act.mjs +171 -0
- package/kits/hub-game/scripts/test-action-layout.mjs +80 -0
- package/kits/hub-game/scripts/test-action-observers.mjs +46 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +853 -0
- package/kits/hub-game/scripts/test-actions.mjs +298 -0
- package/kits/hub-game/scripts/test-actor-budget.mjs +44 -0
- package/kits/hub-game/scripts/test-actors.mjs +38 -23
- package/kits/hub-game/scripts/test-analytics.mjs +76 -0
- package/kits/hub-game/scripts/test-anonymous-entry.mjs +28 -0
- package/kits/hub-game/scripts/test-arrival-pose-server.mjs +196 -0
- package/kits/hub-game/scripts/test-arrival-pose.mjs +24 -0
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -0
- package/kits/hub-game/scripts/test-ask-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-ask.mjs +269 -0
- package/kits/hub-game/scripts/test-attention.mjs +10 -1
- package/kits/hub-game/scripts/test-avatar-cap.mjs +379 -0
- package/kits/hub-game/scripts/test-avatar-colors.mjs +72 -0
- package/kits/hub-game/scripts/test-avatar-models.mjs +181 -0
- package/kits/hub-game/scripts/test-avatar-share.mjs +318 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +792 -0
- package/kits/hub-game/scripts/test-avatar.mjs +584 -7
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +1008 -0
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +49 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +863 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +216 -0
- package/kits/hub-game/scripts/test-companion-client.mjs +1167 -0
- package/kits/hub-game/scripts/test-companion.mjs +259 -0
- package/kits/hub-game/scripts/test-control-layout-dom.mjs +120 -0
- package/kits/hub-game/scripts/test-crowd-names.mjs +205 -0
- package/kits/hub-game/scripts/test-decor-client.mjs +344 -0
- package/kits/hub-game/scripts/test-decor.mjs +464 -0
- package/kits/hub-game/scripts/test-default-environment-root.mjs +95 -0
- package/kits/hub-game/scripts/test-default-environment.mjs +267 -0
- package/kits/hub-game/scripts/test-door-analytics.mjs +58 -0
- package/kits/hub-game/scripts/test-door-jump.mjs +100 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1224 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-far-avatars.mjs +340 -0
- package/kits/hub-game/scripts/test-fps-telemetry.mjs +112 -0
- package/kits/hub-game/scripts/test-frame-batch.mjs +252 -0
- package/kits/hub-game/scripts/test-fresh-friends.mjs +118 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +961 -0
- package/kits/hub-game/scripts/test-grab.mjs +7 -0
- package/kits/hub-game/scripts/test-hats.mjs +422 -168
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +758 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +1594 -12
- package/kits/hub-game/scripts/test-hud-clear.mjs +484 -57
- package/kits/hub-game/scripts/test-hud-defects-dom.mjs +100 -0
- package/kits/hub-game/scripts/test-hud-rate.mjs +224 -0
- package/kits/hub-game/scripts/test-hud-safe-visibility-dom.mjs +83 -0
- package/kits/hub-game/scripts/test-idle.mjs +427 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +513 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-interest.mjs +15 -0
- package/kits/hub-game/scripts/test-invites-client.mjs +430 -0
- package/kits/hub-game/scripts/test-invites.mjs +109 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +664 -0
- package/kits/hub-game/scripts/test-landscape-layout.mjs +194 -0
- package/kits/hub-game/scripts/test-list-scroll-dom.mjs +49 -0
- package/kits/hub-game/scripts/test-load-abandon.mjs +246 -0
- package/kits/hub-game/scripts/test-loading-cover.mjs +162 -0
- package/kits/hub-game/scripts/test-manifest.mjs +472 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +585 -0
- package/kits/hub-game/scripts/test-menu.mjs +319 -0
- package/kits/hub-game/scripts/test-npcs.mjs +2528 -13
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-observed.mjs +745 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-pad-cues.mjs +304 -0
- package/kits/hub-game/scripts/test-pad-occupancy.mjs +177 -0
- package/kits/hub-game/scripts/test-picker.mjs +541 -0
- package/kits/hub-game/scripts/test-placement-cache.mjs +690 -0
- package/kits/hub-game/scripts/test-progress-reset.mjs +559 -0
- package/kits/hub-game/scripts/test-push-visit.mjs +26 -0
- package/kits/hub-game/scripts/test-quality.mjs +385 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1733 -0
- package/kits/hub-game/scripts/test-relations-among.mjs +222 -0
- package/kits/hub-game/scripts/test-relations-refresh.mjs +188 -0
- package/kits/hub-game/scripts/test-resume-action-order.mjs +598 -0
- package/kits/hub-game/scripts/test-resume-held.mjs +239 -0
- package/kits/hub-game/scripts/test-resume-pose.mjs +142 -0
- package/kits/hub-game/scripts/test-safe-events-dom.mjs +116 -0
- package/kits/hub-game/scripts/test-safe-layout.mjs +330 -0
- package/kits/hub-game/scripts/test-say.mjs +1 -1
- package/kits/hub-game/scripts/test-shot.mjs +901 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5437 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +449 -0
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1904 -0
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +412 -0
- package/kits/hub-game/scripts/test-tiers.mjs +476 -2
- package/kits/hub-game/scripts/test-toast-band.mjs +61 -0
- package/kits/hub-game/scripts/test-try-on.mjs +22 -22
- package/kits/hub-game/scripts/test-vis.mjs +770 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-weakest-tier.mjs +924 -0
- package/kits/hub-game/scripts/test-world-labels.mjs +367 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +210 -0
- package/kits/hub-game/scripts/test-yours.mjs +403 -0
- package/kits/multiplayer-3d/CLAUDE.md +50 -0
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/avatars.js +7 -0
- package/kits/multiplayer-3d/code/client/gait.js +65 -0
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/nameTags.js +59 -4
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/options.js +5 -0
- package/kits/multiplayer-3d/code/server/ownership.js +10 -2
- package/kits/multiplayer-3d/code/server/sceneBodies.js +12 -0
- package/kits/multiplayer-3d/code/server/world.js +7 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +443 -34
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +3 -1
- package/kits/multiplayer-3d/scripts/fixtures/README.md +11 -0
- package/kits/multiplayer-3d/scripts/fixtures/ownership-legacy.json +2 -0
- package/kits/multiplayer-3d/scripts/ownership-harness.mjs +102 -0
- package/kits/multiplayer-3d/scripts/ownership-loader.mjs +46 -0
- package/kits/multiplayer-3d/scripts/ownership-worker.mjs +15 -0
- package/kits/multiplayer-3d/scripts/record-ownership-session.mjs +98 -0
- package/kits/multiplayer-3d/scripts/test-eligible-claims.mjs +167 -0
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-own-name-tag.mjs +247 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +19 -1
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/frozenActors.js +233 -0
- package/kits/physics-2d/engine/scene.js +337 -3
- package/kits/physics-2d/engine/skyKey.js +129 -0
- package/kits/physics-2d/engine/stillClock.js +106 -0
- package/kits/physics-2d/engine/updateBudget.js +21 -0
- package/kits/physics-2d/eslint.config.js +1 -1
- package/kits/physics-2d/play/behaviors/AnalogStick.js +198 -0
- package/kits/physics-2d/play/behaviors/Camera.js +40 -0
- package/kits/physics-2d/play/behaviors/Collider.js +122 -0
- package/kits/physics-2d/play/behaviors/Draggable.js +115 -0
- package/kits/physics-2d/play/behaviors/Goal.js +46 -0
- package/kits/physics-2d/play/behaviors/Joints.js +126 -0
- package/kits/physics-2d/play/behaviors/Layout.js +71 -0
- package/kits/physics-2d/play/behaviors/RigidBody.js +57 -0
- package/kits/physics-2d/play/behaviors/Slingshot.js +142 -0
- package/kits/physics-2d/play/behaviors/SoundPlayer.js +263 -0
- package/kits/physics-2d/play/behaviors/Sprite.js +406 -0
- package/kits/physics-2d/play/behaviors/Style.js +209 -0
- package/kits/physics-2d/play/behaviors/Text.js +85 -0
- package/kits/physics-2d/play/behaviors/Video.js +93 -0
- package/kits/physics-2d/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +42 -529
- package/kits/physics-3d/behaviors/Body.jsx +3 -0
- package/kits/physics-3d/behaviors/Model.jsx +3 -0
- package/kits/physics-3d/behaviors/Player.jsx +661 -87
- package/kits/physics-3d/behaviors/Shape.jsx +3 -0
- package/kits/physics-3d/behaviors/Solid.jsx +3 -0
- package/kits/physics-3d/behaviors/Transform.jsx +3 -0
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/engine-camera.md +542 -0
- package/kits/physics-3d/docs/engine-frame-cap.md +136 -0
- package/kits/physics-3d/docs/engine-load.md +149 -0
- package/kits/physics-3d/docs/engine-look.md +114 -0
- package/kits/physics-3d/docs/engine-shadows.md +372 -0
- package/kits/physics-3d/docs/engine-skip-work.md +187 -0
- package/kits/physics-3d/docs/engine-sky.md +198 -0
- package/kits/physics-3d/docs/engine-static-actors.md +226 -0
- package/kits/physics-3d/docs/engine-view.md +37 -0
- package/kits/physics-3d/docs/pxmodel-format.md +9 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -277
- package/kits/physics-3d/engine3d/actornode.js +87 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -0
- package/kits/physics-3d/engine3d/branches.js +3 -13
- package/kits/physics-3d/engine3d/cage.js +2 -7
- package/kits/physics-3d/engine3d/cageops.js +2 -17
- package/kits/physics-3d/engine3d/dataBehaviors.js +12 -0
- package/kits/physics-3d/engine3d/editorWorld.js +6 -0
- package/kits/physics-3d/engine3d/emptynodes.js +232 -0
- package/kits/physics-3d/engine3d/framecap.js +99 -0
- package/kits/physics-3d/engine3d/frozenphysics.js +140 -0
- package/kits/physics-3d/engine3d/frozenstatics.js +273 -0
- package/kits/physics-3d/engine3d/gait.js +126 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +514 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/modelFiles.js +3 -17
- package/kits/physics-3d/engine3d/modelMath.js +49 -0
- package/kits/physics-3d/engine3d/modelready.js +16 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +106 -21
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +522 -10
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/partgeometry.js +1 -16
- package/kits/physics-3d/engine3d/paths.js +1 -9
- package/kits/physics-3d/engine3d/playTimings.js +50 -0
- package/kits/physics-3d/engine3d/playerRun.js +372 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/rapier.js +27 -0
- package/kits/physics-3d/engine3d/scatter.js +1 -11
- package/kits/physics-3d/engine3d/shadowfade.js +890 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- package/kits/physics-3d/engine3d/squarefirst.js +177 -0
- package/kits/physics-3d/engine3d/stillshadows.js +399 -0
- package/kits/physics-3d/engine3d/sweep.js +1 -25
- package/kits/physics-3d/engine3d/unchanged.js +11 -0
- package/kits/physics-3d/engine3d/viewrange.js +52 -0
- package/kits/physics-3d/engine3d/world3d.js +1253 -76
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +10 -2
- package/kits/physics-3d/package-lock.json +7 -0
- package/kits/physics-3d/package.json +5 -1
- package/kits/physics-3d/play/behaviors/Body.js +31 -0
- package/kits/physics-3d/play/behaviors/Door.js +37 -0
- package/kits/physics-3d/play/behaviors/Lookable.js +16 -0
- package/kits/physics-3d/play/behaviors/Model.js +23 -0
- package/kits/physics-3d/play/behaviors/Pickup.js +46 -0
- package/kits/physics-3d/play/behaviors/Player.js +1204 -0
- package/kits/physics-3d/play/behaviors/Shape.js +47 -0
- package/kits/physics-3d/play/behaviors/Solid.js +16 -0
- package/kits/physics-3d/play/behaviors/Transform.js +29 -0
- package/kits/physics-3d/pnpm-lock.yaml +8 -0
- package/kits/physics-3d/scripts/bench-shadow-fade.mjs +37 -0
- package/kits/physics-3d/scripts/build-rapier-gz.mjs +56 -0
- package/kits/physics-3d/scripts/frozen-statics-fixture.mjs +141 -0
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2613 -82
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +2 -2
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +438 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -0
- package/kits/physics-3d/scripts/test-frozen-nested.mjs +49 -0
- package/kits/physics-3d/scripts/test-frozen-statics-legacy-physics2d.mjs +123 -0
- package/kits/physics-3d/scripts/test-frozen-statics.mjs +434 -0
- package/kits/physics-3d/scripts/test-gait.mjs +387 -0
- package/kits/physics-3d/scripts/test-look-bake.mjs +1056 -0
- package/kits/physics-3d/scripts/test-model-parse-cache.mjs +92 -0
- package/kits/physics-3d/scripts/test-near-shadows.mjs +5 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +2001 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +582 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +657 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -0
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-skip-empty-nodes.mjs +845 -0
- package/kits/physics-3d/scripts/test-sky.mjs +2470 -0
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +10 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2174 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +7 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +419 -9
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/client/connection.js +33 -10
- package/kits/real-time/code/client/gameHooks.js +2 -0
- package/kits/real-time/code/client/joinOverlay.js +9 -4
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +102 -22
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,1056 @@
|
|
|
1
|
+
// `"engine": { "look": { "bake": "deferred" } }` (engine3d/lookbake.js, and
|
|
2
|
+
// Baking later in engine3d/look.js), checked against baking at once:
|
|
3
|
+
//
|
|
4
|
+
// - without the key a model is built as it always was: its occlusion and
|
|
5
|
+
// outline attributes are there when the build returns, its outline hulls
|
|
6
|
+
// are drawn, and the world has no queue and never makes one;
|
|
7
|
+
// - with it, a model comes out in the same shape (the same objects, places,
|
|
8
|
+
// materials, shader defines and program keys), its occlusion all 1 and its
|
|
9
|
+
// hulls there and not drawn; and once the queue has run, every attribute of
|
|
10
|
+
// every geometry holds what baking at once put there, whatever was done to
|
|
11
|
+
// the model in between (moved under another object, its parts turned);
|
|
12
|
+
// - a geometry is baked once, however many meshes, copies or builds share it;
|
|
13
|
+
// - a model released, rebuilt or disposed before its task ran is dropped and
|
|
14
|
+
// never written to, and nothing is left listening to it;
|
|
15
|
+
// - a copy made of a waiting geometry is baked with it, so a mesh given the
|
|
16
|
+
// copy in its place, the first one disposed, ends as it does baked at once;
|
|
17
|
+
// - with `"engine": { "dropEmptyParts": true }` as well, a world ends as one
|
|
18
|
+
// that dropped and baked at once; and a build shared by a scene with the
|
|
19
|
+
// key and one without is whichever was made first;
|
|
20
|
+
// - a frame's baking stops starting steps once the budget is spent, by a
|
|
21
|
+
// clock the test supplies, and the first frame does none; `shown` is true
|
|
22
|
+
// only once a frame has been drawn with nothing pending.
|
|
23
|
+
//
|
|
24
|
+
// Baking later is checked against baking at once, which would pass a change
|
|
25
|
+
// to both. So what baking at once gives is itself held to a number
|
|
26
|
+
// (`BAKED_AT_ONCE`, look-baseline.mjs).
|
|
27
|
+
//
|
|
28
|
+
// Every model the kit ships is built both ways for the game (`optimize`), and
|
|
29
|
+
// the models and templates plain as well. `npm run check` runs it. node scripts/test-look-bake.mjs
|
|
30
|
+
import assert from 'node:assert/strict';
|
|
31
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
32
|
+
import * as THREE from 'three';
|
|
33
|
+
// The models, and the resolver the kit's modules need under node.
|
|
34
|
+
import { CART, MIXED, freshModel, builds, lookBaseline } from './look-baseline.mjs';
|
|
35
|
+
|
|
36
|
+
const { bakingLater, setLookEnabled } = await import('../engine3d/look.js');
|
|
37
|
+
const { makeLookBake, queueLookBake, stepLookBake, orderLookBake, clearLookBake } = await import('../engine3d/lookbake.js');
|
|
38
|
+
const { buildModelNode } = await import('../engine3d/pxmodel.js');
|
|
39
|
+
const { syncActors, renderWorld, disposeWorld } = await import('../engine3d/world3d.js');
|
|
40
|
+
|
|
41
|
+
// What every build baked at once comes to (look-baseline.mjs): each object of
|
|
42
|
+
// each model, its materials and program keys, and the bytes of every
|
|
43
|
+
// attribute. It is the number origin/main gave before there was a way to bake
|
|
44
|
+
// later, and it changes only when what the look bakes into a model is meant
|
|
45
|
+
// to change: then run `node scripts/look-baseline.mjs` and put its number
|
|
46
|
+
// here, in the commit that means it.
|
|
47
|
+
const BAKED_AT_ONCE = 'a7bcbc7167c874e6225964fb420a95750abeb7b87f39a9242622418604f2e411';
|
|
48
|
+
|
|
49
|
+
function build(model, path, optimize, queue) {
|
|
50
|
+
const make = () => buildModelNode(model.parsed, {}, model.files, path, [path], optimize ? { optimize: true } : {});
|
|
51
|
+
return queue ? bakingLater(queue, path, make) : make();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
//
|
|
55
|
+
// What a built model is
|
|
56
|
+
//
|
|
57
|
+
|
|
58
|
+
const meshesOf = (node) => {
|
|
59
|
+
const meshes = [];
|
|
60
|
+
node.traverse((object) => object.isMesh && meshes.push(object));
|
|
61
|
+
return meshes;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// Its shape: every object, where it is, and what it is drawn with, apart from
|
|
65
|
+
// what the baking fills in.
|
|
66
|
+
function shapeOf(node) {
|
|
67
|
+
node.updateMatrixWorld(true);
|
|
68
|
+
const out = [];
|
|
69
|
+
node.traverse((object) => {
|
|
70
|
+
const entry = {
|
|
71
|
+
type: object.type,
|
|
72
|
+
constructor: object.constructor.name,
|
|
73
|
+
visible: object.visible,
|
|
74
|
+
children: object.children.length,
|
|
75
|
+
userData: JSON.stringify(object.userData, (key, value) => (key === 'modelParts' || key === 'animation' ? undefined : value)),
|
|
76
|
+
matrix: [...object.matrixWorld.elements],
|
|
77
|
+
castShadow: object.castShadow,
|
|
78
|
+
};
|
|
79
|
+
if (object.isMesh) {
|
|
80
|
+
entry.count = object.count;
|
|
81
|
+
entry.materials = [object.material].flat().map((material) => ({
|
|
82
|
+
type: material.type,
|
|
83
|
+
defines: JSON.stringify(material.defines ?? null),
|
|
84
|
+
key: material.customProgramCacheKey(),
|
|
85
|
+
side: material.side,
|
|
86
|
+
color: material.color.getHexString(),
|
|
87
|
+
patched: material.userData.lookPatched === true,
|
|
88
|
+
}));
|
|
89
|
+
entry.vertices = object.geometry.getAttribute('position').count;
|
|
90
|
+
}
|
|
91
|
+
out.push(entry);
|
|
92
|
+
});
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// What the baking fills in: every attribute of every geometry, and whether
|
|
97
|
+
// each material is drawn.
|
|
98
|
+
function bakedOf(node) {
|
|
99
|
+
return meshesOf(node).map((mesh) => {
|
|
100
|
+
const attributes = {};
|
|
101
|
+
for (const name of Object.keys(mesh.geometry.attributes).sort()) {
|
|
102
|
+
const attribute = mesh.geometry.attributes[name];
|
|
103
|
+
attributes[name] = { itemSize: attribute.itemSize, array: attribute.array.slice() };
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
outline: mesh.userData.lookOutline === true,
|
|
107
|
+
drawn: [mesh.material].flat().map((material) => material.visible),
|
|
108
|
+
ownClone: [mesh.material].flat().map((material) => Object.hasOwn(material, 'clone')),
|
|
109
|
+
attributes,
|
|
110
|
+
index: mesh.geometry.getIndex()?.array.slice() ?? null,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// `assert.deepEqual` for lists of large things: on a difference it names the
|
|
116
|
+
// first entry and field that differ rather than printing them all.
|
|
117
|
+
function assertSame(actual, expected, what) {
|
|
118
|
+
if (isDeepStrictEqual(actual, expected)) return;
|
|
119
|
+
const names = Array.isArray(expected) ? expected.map((_, at) => at) : Object.keys(expected);
|
|
120
|
+
const at = names.find((name) => !isDeepStrictEqual(actual[name], expected[name]));
|
|
121
|
+
if (at === undefined || typeof expected[at] !== 'object' || ArrayBuffer.isView(expected[at])) assert.fail(`${what} (differs at ${at})`);
|
|
122
|
+
assertSame(actual[at] ?? {}, expected[at], `${what}: ${at}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const listeners = (geometry) => geometry._listeners?.dispose?.length ?? 0;
|
|
126
|
+
|
|
127
|
+
// A clock that moves only when told to.
|
|
128
|
+
function clockFor(queue) {
|
|
129
|
+
const clock = { at: 0 };
|
|
130
|
+
queue.now = () => clock.at;
|
|
131
|
+
return clock;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Runs the queue dry, on a clock that never reaches the budget.
|
|
135
|
+
function drain(queue) {
|
|
136
|
+
clockFor(queue);
|
|
137
|
+
queue.drawn = true;
|
|
138
|
+
for (let frame = 0; queue.pending > 0; frame++) {
|
|
139
|
+
assert.ok(frame < 10, 'the queue runs dry in one frame when the clock stands still');
|
|
140
|
+
stepLookBake(queue);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
//
|
|
145
|
+
// Without the key
|
|
146
|
+
//
|
|
147
|
+
|
|
148
|
+
function atOnce() {
|
|
149
|
+
let hulls = 0;
|
|
150
|
+
let occluded = 0;
|
|
151
|
+
for (const path of [CART, MIXED, 'models/player.pxmodel', 'models/tree.pxmodel']) {
|
|
152
|
+
for (const optimize of [true, false]) {
|
|
153
|
+
const node = build(freshModel(path), path, optimize, null);
|
|
154
|
+
for (const mesh of meshesOf(node)) {
|
|
155
|
+
const geometry = mesh.geometry;
|
|
156
|
+
if (mesh.userData.lookOutline) {
|
|
157
|
+
hulls += 1;
|
|
158
|
+
assert.ok(geometry.getAttribute('lookOutlineNormal') && geometry.getAttribute('lookOutlineReach'), `${path}: a hull has its attributes when the build returns`);
|
|
159
|
+
assert.equal(mesh.material.visible, true, `${path}: and is drawn`);
|
|
160
|
+
assert.ok(!Object.hasOwn(mesh.material, 'clone'), `${path}: its material is a plain one`);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
assert.equal(mesh.userData.lookDone, true);
|
|
164
|
+
const values = geometry.getAttribute('lookOcclusion');
|
|
165
|
+
if (values) {
|
|
166
|
+
occluded += 1;
|
|
167
|
+
assert.ok(values.array.some((value) => value < 1), `${path}: occlusion is baked when the build returns`);
|
|
168
|
+
assert.equal(listeners(geometry), 0, `${path}: nothing listens to a geometry`);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
assert.ok(hulls > 20 && occluded > 20, `hulls and occlusion were looked at (${hulls}, ${occluded})`);
|
|
174
|
+
return hulls + occluded;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//
|
|
178
|
+
// With it: the same model, later
|
|
179
|
+
//
|
|
180
|
+
|
|
181
|
+
// Moves the model as a game does after it is built: under another object, and
|
|
182
|
+
// its parts turned.
|
|
183
|
+
function disturb(node) {
|
|
184
|
+
const holder = new THREE.Group();
|
|
185
|
+
holder.position.set(3, -2, 5);
|
|
186
|
+
holder.rotation.set(0.4, 1.1, -0.3);
|
|
187
|
+
holder.scale.set(2, 0.5, 1.5);
|
|
188
|
+
holder.add(node);
|
|
189
|
+
node.traverse((object) => {
|
|
190
|
+
if (object.isGroup && object !== node) object.rotation.x += 0.7;
|
|
191
|
+
});
|
|
192
|
+
holder.updateMatrixWorld(true);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function laterEqualsAtOnce() {
|
|
196
|
+
let models = 0;
|
|
197
|
+
let waited = 0;
|
|
198
|
+
let occlusions = 0;
|
|
199
|
+
for (const { path, optimize } of builds()) {
|
|
200
|
+
const what = `${path}${optimize ? ' (optimize)' : ''}`;
|
|
201
|
+
const now = build(freshModel(path), path, optimize, null);
|
|
202
|
+
const queue = makeLookBake();
|
|
203
|
+
const later = build(freshModel(path), path, optimize, queue);
|
|
204
|
+
assertSame(shapeOf(later), shapeOf(now), `${what}: built later, it has the shape it has built at once`);
|
|
205
|
+
|
|
206
|
+
// Before the queue runs: nothing baked, nothing of a hull drawn.
|
|
207
|
+
const geometries = new Set(queue.tasks.flatMap((task) => task.geometries));
|
|
208
|
+
assert.equal(geometries.size, queue.tasks.reduce((sum, task) => sum + task.geometries.length, 0), `${what}: a geometry is one task's, once`);
|
|
209
|
+
for (const mesh of meshesOf(later)) {
|
|
210
|
+
const geometry = mesh.geometry;
|
|
211
|
+
if (mesh.userData.lookOutline && !geometry.getAttribute('lookOutlineNormal')) {
|
|
212
|
+
waited += 1;
|
|
213
|
+
assert.ok(geometries.has(geometry), `${what}: a hull without attributes has a task`);
|
|
214
|
+
assert.equal(mesh.material.visible, false, `${what}: and is not drawn`);
|
|
215
|
+
}
|
|
216
|
+
const values = geometry.getAttribute('lookOcclusion');
|
|
217
|
+
if (values && geometries.has(geometry) && values.array.every((value) => value === 1)) waited += 1;
|
|
218
|
+
else if (values) assert.ok(!geometries.has(geometry) || geometry.getAttribute('lookOutlineNormal') === undefined, `${what}: occlusion is all 1 or not waiting`);
|
|
219
|
+
}
|
|
220
|
+
const before = bakedOf(later);
|
|
221
|
+
const counts = countWrites(geometries);
|
|
222
|
+
disturb(later);
|
|
223
|
+
drain(queue);
|
|
224
|
+
assertSame(bakedOf(later), bakedOf(now), `${what}: once the queue has run, every attribute is what baking at once gives`);
|
|
225
|
+
assert.equal(queue.dropped, 0);
|
|
226
|
+
for (const geometry of geometries) {
|
|
227
|
+
assert.equal(listeners(geometry), 0, `${what}: nothing is left listening`);
|
|
228
|
+
assert.ok(!Object.hasOwn(geometry, 'clone'), `${what}: and its clone is the plain one again`);
|
|
229
|
+
const { set, versions } = counts.get(geometry);
|
|
230
|
+
assert.ok((set.lookOutlineNormal ?? 0) <= 1 && (set.lookOutlineReach ?? 0) <= 1, `${what}: outline attributes are set once`);
|
|
231
|
+
assert.equal(set.lookOcclusion ?? 0, 0, `${what}: the occlusion attribute is the one that was there`);
|
|
232
|
+
const values = geometry.getAttribute('lookOcclusion');
|
|
233
|
+
if (values) assert.equal(values.version, versions.lookOcclusion + 1, `${what}: and is marked for upload once`);
|
|
234
|
+
if (values) occlusions += 1;
|
|
235
|
+
}
|
|
236
|
+
if (queue.baked > 0) assert.ok(!isDeepStrictEqual(before, bakedOf(later)), `${what}: the queue changed something`);
|
|
237
|
+
models += 1;
|
|
238
|
+
}
|
|
239
|
+
assert.ok(waited > 200 && occlusions > 200, `occlusion and hulls waited (${waited}, ${occlusions})`);
|
|
240
|
+
return models;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Counts `setAttribute` on each geometry from here on, and notes the version
|
|
244
|
+
// each attribute is at.
|
|
245
|
+
function countWrites(geometries) {
|
|
246
|
+
const counts = new Map();
|
|
247
|
+
for (const geometry of geometries) {
|
|
248
|
+
const set = {};
|
|
249
|
+
const versions = {};
|
|
250
|
+
for (const [name, attribute] of Object.entries(geometry.attributes)) versions[name] = attribute.version;
|
|
251
|
+
const setAttribute = geometry.setAttribute;
|
|
252
|
+
geometry.setAttribute = function (name, attribute) {
|
|
253
|
+
set[name] = (set[name] ?? 0) + 1;
|
|
254
|
+
return setAttribute.call(this, name, attribute);
|
|
255
|
+
};
|
|
256
|
+
counts.set(geometry, { set, versions });
|
|
257
|
+
}
|
|
258
|
+
return counts;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
//
|
|
262
|
+
// Shared geometry
|
|
263
|
+
//
|
|
264
|
+
|
|
265
|
+
function sharedIsBakedOnce() {
|
|
266
|
+
// Two builds of one parsed model: the second reads what the first baked,
|
|
267
|
+
// at once and later alike.
|
|
268
|
+
const occlusionArrays = (node) => [...new Set(meshesOf(node).map((mesh) => mesh.geometry.getAttribute('lookOcclusion')?.array).filter(Boolean))];
|
|
269
|
+
for (const queue of [null, makeLookBake()]) {
|
|
270
|
+
const model = freshModel('models/tree.pxmodel');
|
|
271
|
+
const first = build(model, 'models/tree.pxmodel', true, queue);
|
|
272
|
+
const second = build(model, 'models/tree.pxmodel', true, queue);
|
|
273
|
+
if (queue) {
|
|
274
|
+
assert.equal(queue.pending, 2, 'each build waits');
|
|
275
|
+
drain(queue);
|
|
276
|
+
}
|
|
277
|
+
const arrays = occlusionArrays(first);
|
|
278
|
+
assert.ok(arrays.length > 0);
|
|
279
|
+
assert.deepEqual(occlusionArrays(second).map((array) => arrays.indexOf(array)), arrays.map((_, at) => at), `${queue ? 'later' : 'at once'}: the second build's occlusion is the first's arrays`);
|
|
280
|
+
}
|
|
281
|
+
// A third, built later once the first two have baked, waits for no occlusion.
|
|
282
|
+
const queue = makeLookBake();
|
|
283
|
+
const model = freshModel('models/tree.pxmodel');
|
|
284
|
+
build(model, 'models/tree.pxmodel', true, null);
|
|
285
|
+
const cached = build(model, 'models/tree.pxmodel', true, queue);
|
|
286
|
+
assert.ok(meshesOf(cached).some((mesh) => mesh.geometry.getAttribute('lookOcclusion')?.array.some((value) => value < 1)), 'cached occlusion is there at once');
|
|
287
|
+
|
|
288
|
+
// The cart: mirrored tires become instances, three crates share one build,
|
|
289
|
+
// and each recolored crate has materials of its own, cloned while hidden.
|
|
290
|
+
const cartQueue = makeLookBake();
|
|
291
|
+
const cart = build(freshModel(CART), CART, true, cartQueue);
|
|
292
|
+
const hulls = meshesOf(cart).filter((mesh) => mesh.userData.lookOutline);
|
|
293
|
+
const instanced = hulls.filter((mesh) => mesh.isInstancedMesh);
|
|
294
|
+
const clones = hulls.filter((mesh) => !cartQueue.tasks.some((task) => task.geometries.includes(mesh.geometry)) || Object.hasOwn(mesh.material, 'clone'));
|
|
295
|
+
assert.ok(instanced.length > 0, 'the cart has instanced hulls');
|
|
296
|
+
assert.ok(new Set(hulls.map((mesh) => mesh.material)).size > new Set(hulls.map((mesh) => mesh.geometry)).size, 'and hulls on one geometry with materials of their own');
|
|
297
|
+
assert.ok(clones.length > 0);
|
|
298
|
+
assert.ok(hulls.every((mesh) => mesh.material.visible === false), 'none drawn yet, the recolored copies included');
|
|
299
|
+
drain(cartQueue);
|
|
300
|
+
assert.ok(hulls.every((mesh) => mesh.material.visible === true && !Object.hasOwn(mesh.material, 'clone')), 'all drawn after, and plain materials again');
|
|
301
|
+
assert.ok(hulls.every((mesh) => mesh.geometry.getAttribute('lookOutlineNormal')));
|
|
302
|
+
return hulls.length;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
//
|
|
306
|
+
// Worlds
|
|
307
|
+
//
|
|
308
|
+
|
|
309
|
+
// A world as `makeWorld3D` makes it, without the renderer.
|
|
310
|
+
function makeWorld() {
|
|
311
|
+
const scene = new THREE.Scene();
|
|
312
|
+
const ground = new THREE.Mesh(new THREE.PlaneGeometry(1, 1), new THREE.MeshStandardMaterial());
|
|
313
|
+
const grid = new THREE.Object3D();
|
|
314
|
+
scene.add(ground, grid);
|
|
315
|
+
const world = {
|
|
316
|
+
scene,
|
|
317
|
+
camera: new THREE.PerspectiveCamera(),
|
|
318
|
+
renderer: { dispose() {} },
|
|
319
|
+
composer: { render: () => (world.frames += 1) },
|
|
320
|
+
frames: 0,
|
|
321
|
+
nodes: new Map(),
|
|
322
|
+
scenePath: undefined,
|
|
323
|
+
parked: new Map(),
|
|
324
|
+
models: new Map(),
|
|
325
|
+
skipping: { on: false },
|
|
326
|
+
modelSigs: new Map(),
|
|
327
|
+
sigEpoch: 0,
|
|
328
|
+
syncCount: 0,
|
|
329
|
+
syncDepth: 0,
|
|
330
|
+
generation: 0,
|
|
331
|
+
snapshots: new WeakMap(),
|
|
332
|
+
nearShadows: null,
|
|
333
|
+
bakesLookLater: false,
|
|
334
|
+
lookBake: null,
|
|
335
|
+
instances: new Map(),
|
|
336
|
+
instanceModels: false,
|
|
337
|
+
ground,
|
|
338
|
+
grid,
|
|
339
|
+
};
|
|
340
|
+
return world;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
function makeRuntime(later, path, actors, skip = false) {
|
|
344
|
+
return {
|
|
345
|
+
skipsUnchangedActors: skip,
|
|
346
|
+
bakesLookLater: later,
|
|
347
|
+
scenePath: path,
|
|
348
|
+
data: {},
|
|
349
|
+
files: freshModel(CART).files,
|
|
350
|
+
actors,
|
|
351
|
+
getActors() {
|
|
352
|
+
return [...this.actors];
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const placing = (id, file, x = 0) => ({
|
|
358
|
+
id,
|
|
359
|
+
runtime: {},
|
|
360
|
+
components: {
|
|
361
|
+
Transform: { x, y: 0, z: 0, rotationX: 0, rotationY: 0, rotationZ: 0 },
|
|
362
|
+
Model: { file, scale: 1, yOffset: 0 },
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
const frame = (world, runtime) => {
|
|
367
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
368
|
+
renderWorld(world, runtime);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
const geometriesOf = (world) => new Set([...world.nodes.values()].flatMap((entry) => meshesOf(entry.node).map((mesh) => mesh.geometry)));
|
|
372
|
+
const bakedInWorld = (world) => Object.fromEntries([...world.nodes].map(([id, entry]) => [id, bakedOf(entry.node)]));
|
|
373
|
+
|
|
374
|
+
function worlds() {
|
|
375
|
+
const cast = () => [placing('tree', 'models/tree.pxmodel', 30), placing('cart', CART, 2), placing('cart2', CART, 4), placing('rock', 'models/rock.pxmodel', 9)];
|
|
376
|
+
|
|
377
|
+
// Without the key: no queue, ever, and a frame that draws and returns.
|
|
378
|
+
for (const skip of [false, true]) {
|
|
379
|
+
const plain = makeWorld();
|
|
380
|
+
const runtime = makeRuntime(false, 'scenes/plain.scene', cast(), skip);
|
|
381
|
+
for (let i = 0; i < 3; i++) frame(plain, runtime);
|
|
382
|
+
assert.equal(plain.lookBake, null, 'a world never asked has no queue');
|
|
383
|
+
assert.equal(plain.frames, 3);
|
|
384
|
+
for (const geometry of geometriesOf(plain)) assert.equal(listeners(geometry), 0);
|
|
385
|
+
plain.reference = bakedInWorld(plain);
|
|
386
|
+
if (!skip) worlds.reference = plain.reference;
|
|
387
|
+
else assertSame(plain.reference, worlds.reference, 'skipping, a world without the key');
|
|
388
|
+
disposeWorld(plain);
|
|
389
|
+
assert.equal(plain.lookBake, null);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// With it: the first frame bakes nothing, then the nearest model first, and
|
|
393
|
+
// the world ends as the one without the key.
|
|
394
|
+
for (const skip of [false, true]) {
|
|
395
|
+
const world = makeWorld();
|
|
396
|
+
world.camera.position.set(0, 2, 0);
|
|
397
|
+
const runtime = makeRuntime(true, 'scenes/later.scene', cast(), skip);
|
|
398
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
399
|
+
const queue = world.lookBake;
|
|
400
|
+
assert.ok(queue && queue.pending >= 3, 'the models are waiting');
|
|
401
|
+
assert.equal(queue.shown, false);
|
|
402
|
+
const clock = clockFor(queue);
|
|
403
|
+
// Every step takes a millisecond.
|
|
404
|
+
const stepped = [];
|
|
405
|
+
for (const task of queue.tasks) {
|
|
406
|
+
const steps = task.steps;
|
|
407
|
+
task.steps = { next: () => (stepped.push(task.owner), (clock.at += 1), steps.next()) };
|
|
408
|
+
}
|
|
409
|
+
const owners = queue.tasks.map((task) => task.owner);
|
|
410
|
+
assert.ok(owners[0].startsWith('models/tree'), 'queued in the order built');
|
|
411
|
+
renderWorld(world, runtime);
|
|
412
|
+
assert.deepEqual([queue.ms, stepped.length, world.frames], [0, 0, 1], 'the first frame is drawn and nothing is baked');
|
|
413
|
+
assert.equal(queue.shown, false, 'and it is not the complete picture');
|
|
414
|
+
const pendingAtFirst = queue.pending;
|
|
415
|
+
frame(world, runtime);
|
|
416
|
+
assert.equal(stepped.length, queue.budgetMs, 'the second frame bakes for its budget');
|
|
417
|
+
assert.ok(stepped[0].startsWith(CART), 'the model nearest the camera first');
|
|
418
|
+
assert.equal(queue.ms, queue.budgetMs);
|
|
419
|
+
let frames = 0;
|
|
420
|
+
while (queue.pending > 0) {
|
|
421
|
+
const done = stepped.length;
|
|
422
|
+
frame(world, runtime);
|
|
423
|
+
assert.ok(stepped.length - done <= queue.budgetMs, 'never more than the budget');
|
|
424
|
+
assert.ok((frames += 1) < 2000);
|
|
425
|
+
assert.equal(queue.shown, false, 'no frame is the complete picture while models wait, nor the one that bakes the last');
|
|
426
|
+
}
|
|
427
|
+
const order = stepped.filter((owner, at) => owner !== stepped[at - 1]).map((owner) => owner.split('|')[0]);
|
|
428
|
+
assert.deepEqual(order, [CART, 'models/rock.pxmodel', 'models/tree.pxmodel'], 'nearest first, each task to its end');
|
|
429
|
+
assert.equal(queue.baked, pendingAtFirst);
|
|
430
|
+
assert.equal(queue.dropped, 0);
|
|
431
|
+
assertSame(bakedInWorld(world), worlds.reference, `${skip ? 'skipping, ' : ''}the world ends as the one that baked at once`);
|
|
432
|
+
const spent = queue.ms;
|
|
433
|
+
frame(world, runtime);
|
|
434
|
+
assert.equal(queue.ms, spent, 'an empty queue takes no time');
|
|
435
|
+
assert.equal(queue.shown, true, 'the next frame is drawn with everything baked: the complete picture');
|
|
436
|
+
|
|
437
|
+
// A model placed later: not complete again until a frame is drawn with it baked.
|
|
438
|
+
runtime.actors.push(placing('mixed', MIXED, 12));
|
|
439
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
440
|
+
assert.deepEqual([queue.pending, queue.shown], [1, false], 'a model queued, and the picture is not complete');
|
|
441
|
+
renderWorld(world, runtime);
|
|
442
|
+
assert.deepEqual([queue.pending, queue.shown], [0, false], 'baked after that frame was drawn');
|
|
443
|
+
frame(world, runtime);
|
|
444
|
+
assert.equal(queue.shown, true);
|
|
445
|
+
runtime.actors.pop();
|
|
446
|
+
|
|
447
|
+
// A scene without the key in the same world builds at once.
|
|
448
|
+
const next = makeRuntime(false, 'scenes/next.scene', [placing('barrel', 'models/barrel.pxmodel')], skip);
|
|
449
|
+
frame(world, next);
|
|
450
|
+
assert.equal(world.bakesLookLater, false);
|
|
451
|
+
assert.equal(queue.pending, 0, 'nothing waits for a scene that did not ask');
|
|
452
|
+
assert.ok(meshesOf(world.nodes.get('barrel').node).some((mesh) => mesh.userData.lookOutline && mesh.material.visible));
|
|
453
|
+
disposeWorld(world);
|
|
454
|
+
for (const geometry of geometriesOf(world)) assert.equal(listeners(geometry), 0);
|
|
455
|
+
}
|
|
456
|
+
return 4;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
//
|
|
460
|
+
// With `"engine": { "dropEmptyParts": true }` as well
|
|
461
|
+
//
|
|
462
|
+
|
|
463
|
+
// That key takes the groups that draw nothing out of a shared build when it
|
|
464
|
+
// is first placed, after the look was applied to it and its baking queued.
|
|
465
|
+
// The baking was written down as geometries and matrices, so it holds none of
|
|
466
|
+
// those groups, and a placed copy draws the build's own geometries: with both
|
|
467
|
+
// keys a world ends as one that dropped and baked at once. The build is
|
|
468
|
+
// queued, and looked up for the nearest-first order, under the key the drop
|
|
469
|
+
// gave it.
|
|
470
|
+
function withEmptyPartsDropped() {
|
|
471
|
+
const cast = () => [placing('tree', 'models/tree.pxmodel', 30), placing('cart', CART, 2), placing('cart2', CART, 4), placing('rock', 'models/rock.pxmodel', 9), placing('mixed', MIXED, 14)];
|
|
472
|
+
const dropping = (later, path, skip) => Object.assign(makeRuntime(later, path, cast(), skip), { dropsEmptyParts: true });
|
|
473
|
+
// The shared builds, in the order they were made (a key has its file's text in it, and each world a text of its own).
|
|
474
|
+
const builds = (world) => [...world.models.values()].map((entry) => bakedOf(entry.template));
|
|
475
|
+
const shapes = (world) => Object.fromEntries([...world.nodes].map(([id, entry]) => [id, shapeOf(entry.node)]));
|
|
476
|
+
const objects = (world) => [...world.models.values()].reduce((sum, entry) => sum + shapeOf(entry.template).length, 0);
|
|
477
|
+
let scenes = 0;
|
|
478
|
+
for (const instanced of [false, true]) {
|
|
479
|
+
for (const skip of [false, true]) {
|
|
480
|
+
const what = `dropping empty parts${instanced ? ', instanced' : ''}${skip ? ', skipping' : ''}`;
|
|
481
|
+
const make = () => Object.assign(makeWorld(), { instanceModels: instanced });
|
|
482
|
+
const kept = make();
|
|
483
|
+
frame(kept, makeRuntime(false, 'scenes/kept.scene', cast(), skip));
|
|
484
|
+
const now = make();
|
|
485
|
+
frame(now, dropping(false, 'scenes/drop.scene', skip));
|
|
486
|
+
assert.equal(now.lookBake, null, `${what}: the drop alone makes no queue`);
|
|
487
|
+
assert.ok(objects(now) < objects(kept), `${what}: groups were dropped (${objects(now)} of ${objects(kept)})`);
|
|
488
|
+
assert.ok([...now.models.keys()].every((key) => key.endsWith('|dropEmptyParts')));
|
|
489
|
+
|
|
490
|
+
const world = make();
|
|
491
|
+
world.camera.position.set(0, 2, 0);
|
|
492
|
+
const runtime = dropping(true, 'scenes/drop.scene', skip);
|
|
493
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
494
|
+
const queue = world.lookBake;
|
|
495
|
+
const pending = queue.pending;
|
|
496
|
+
assert.ok(pending >= 4, `${what}: the models wait`);
|
|
497
|
+
assert.ok(queue.tasks.every((task) => world.models.has(task.owner) && task.owner.endsWith('|dropEmptyParts')), `${what}: each task is a build's, by the key the drop gave it`);
|
|
498
|
+
assert.ok([...world.nodes.values()].every((entry) => world.models.has(entry.modelKey)), `${what}: which is the key its actors hold`);
|
|
499
|
+
assertSame(shapes(world), shapes(now), `${what}: built later, the nodes have the shape they have built at once`);
|
|
500
|
+
const waiting = new Set(queue.tasks.flatMap((task) => task.geometries));
|
|
501
|
+
const drawn = new Set([...geometriesOf(world), ...[...world.instances.values()].flatMap((instances) => instances.parts.map((part) => part.source.geometry))]);
|
|
502
|
+
const built = new Set([...world.models.values()].flatMap((entry) => meshesOf(entry.template).map((mesh) => mesh.geometry)));
|
|
503
|
+
assert.ok(drawn.size > 0 && [...drawn].every((geometry) => built.has(geometry)), `${what}: what is placed draws the builds' own geometries`);
|
|
504
|
+
assert.ok([...waiting].every((geometry) => built.has(geometry)), `${what}: and those are what waits`);
|
|
505
|
+
const clock = clockFor(queue);
|
|
506
|
+
const stepped = [];
|
|
507
|
+
for (const task of queue.tasks) {
|
|
508
|
+
const steps = task.steps;
|
|
509
|
+
task.steps = { next: () => (stepped.push(task.owner), (clock.at += 1), steps.next()) };
|
|
510
|
+
}
|
|
511
|
+
for (let frames = 0; !queue.shown; frames++) {
|
|
512
|
+
assert.ok(frames < 4000);
|
|
513
|
+
frame(world, runtime);
|
|
514
|
+
}
|
|
515
|
+
const order = stepped.filter((owner, at) => owner !== stepped[at - 1]).map((owner) => owner.split('|')[0]);
|
|
516
|
+
assert.deepEqual(order, [CART, 'models/rock.pxmodel', MIXED, 'models/tree.pxmodel'], `${what}: nearest first, by the dropped build's key`);
|
|
517
|
+
assert.deepEqual([queue.baked, queue.dropped], [pending, 0]);
|
|
518
|
+
assertSame(builds(world), builds(now), `${what}: every build ends as it does dropped and baked at once`);
|
|
519
|
+
assertSame(bakedInWorld(world), bakedInWorld(now), `${what}: and every placed copy`);
|
|
520
|
+
assertSame(shapes(world), shapes(now), `${what}: in the same shape`);
|
|
521
|
+
for (const geometry of [...waiting, ...drawn]) assert.ok(listeners(geometry) === 0 && !Object.hasOwn(geometry, 'clone'));
|
|
522
|
+
for (const each of [kept, now, world]) disposeWorld(each);
|
|
523
|
+
scenes += 1;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return scenes;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
// One world, two scenes that place the same model, one with the bake key and
|
|
530
|
+
// one without: the shared build is whichever was made first.
|
|
531
|
+
function sharedAcrossScenes() {
|
|
532
|
+
const cast = () => [placing('rock', 'models/rock.pxmodel', 3)];
|
|
533
|
+
const reference = makeWorld();
|
|
534
|
+
frame(reference, makeRuntime(false, 'scenes/s.scene', cast()));
|
|
535
|
+
// Built at once, then a scene that asks: it is baked already, and stays so.
|
|
536
|
+
{
|
|
537
|
+
const world = makeWorld();
|
|
538
|
+
const plain = makeRuntime(false, 'scenes/s.scene', cast());
|
|
539
|
+
frame(world, plain);
|
|
540
|
+
const template = [...world.models.values()][0].template;
|
|
541
|
+
// The same deck: the same files.
|
|
542
|
+
const asked = Object.assign(makeRuntime(true, 'scenes/s.scene', cast()), { files: plain.files });
|
|
543
|
+
frame(world, asked);
|
|
544
|
+
frame(world, asked);
|
|
545
|
+
assert.ok(world.models.size === 1 && [...world.models.values()][0].template === template, 'the build is the one made at once');
|
|
546
|
+
assert.equal(world.lookBake, null, 'and nothing waits');
|
|
547
|
+
assertSame(bakedInWorld(world), bakedInWorld(reference), 'a model baked at once stays baked for a scene that asks');
|
|
548
|
+
disposeWorld(world);
|
|
549
|
+
}
|
|
550
|
+
// Built to bake later, then a scene that does not ask: the build is the
|
|
551
|
+
// same one, still waiting, and its baking goes on under that scene.
|
|
552
|
+
{
|
|
553
|
+
const world = makeWorld();
|
|
554
|
+
const asked = makeRuntime(true, 'scenes/s.scene', cast());
|
|
555
|
+
frame(world, asked);
|
|
556
|
+
const queue = world.lookBake;
|
|
557
|
+
const template = [...world.models.values()][0].template;
|
|
558
|
+
assert.equal(queue.pending, 1);
|
|
559
|
+
const plain = Object.assign(makeRuntime(false, 'scenes/s.scene', cast()), { files: asked.files });
|
|
560
|
+
clockFor(queue);
|
|
561
|
+
frame(world, plain);
|
|
562
|
+
assert.ok(world.models.size === 1 && [...world.models.values()][0].template === template, 'the build is the one that waits');
|
|
563
|
+
for (let frames = 0; !queue.shown; frames++) {
|
|
564
|
+
assert.ok(frames < 10);
|
|
565
|
+
frame(world, plain);
|
|
566
|
+
}
|
|
567
|
+
assert.deepEqual([queue.baked, queue.dropped], [1, 0]);
|
|
568
|
+
assertSame(bakedInWorld(world), bakedInWorld(reference), 'and ends as one baked at once');
|
|
569
|
+
disposeWorld(world);
|
|
570
|
+
}
|
|
571
|
+
disposeWorld(reference);
|
|
572
|
+
return 2;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
//
|
|
576
|
+
// Models that go before their task runs
|
|
577
|
+
//
|
|
578
|
+
|
|
579
|
+
function goneBeforeBaked() {
|
|
580
|
+
const waitingIn = (world, id) => meshesOf(world.nodes.get(id).node).map((mesh) => mesh.geometry);
|
|
581
|
+
const untouched = (geometries, what) => {
|
|
582
|
+
for (const geometry of geometries) {
|
|
583
|
+
assert.equal(listeners(geometry), 0, `${what}: nothing listens to it`);
|
|
584
|
+
assert.ok(!Object.hasOwn(geometry, 'clone'), `${what}: its clone is the plain one`);
|
|
585
|
+
assert.equal(geometry.getAttribute('lookOutlineNormal'), undefined, `${what}: no outline attribute was written`);
|
|
586
|
+
const values = geometry.getAttribute('lookOcclusion');
|
|
587
|
+
if (values) assert.ok(values.array.every((value) => value === 1) && values.version === 0, `${what}: its occlusion was not written`);
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
let scenarios = 0;
|
|
591
|
+
for (const skip of [false, true]) {
|
|
592
|
+
// Removed: the only actor placing the tree goes; the rest still bake.
|
|
593
|
+
{
|
|
594
|
+
const world = makeWorld();
|
|
595
|
+
const runtime = makeRuntime(true, 'scenes/a.scene', [placing('tree', 'models/tree.pxmodel'), placing('rock', 'models/rock.pxmodel', 5)], skip);
|
|
596
|
+
frame(world, runtime);
|
|
597
|
+
const queue = world.lookBake;
|
|
598
|
+
const tree = waitingIn(world, 'tree');
|
|
599
|
+
const before = queue.pending;
|
|
600
|
+
runtime.actors = runtime.actors.filter((actor) => actor.id !== 'tree');
|
|
601
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
602
|
+
assert.equal(queue.pending, before - 1, 'the removed model no longer waits');
|
|
603
|
+
assert.equal(queue.dropped, 1);
|
|
604
|
+
drain(queue);
|
|
605
|
+
untouched(tree, 'a removed model');
|
|
606
|
+
assert.ok(waitingIn(world, 'rock').some((geometry) => geometry.getAttribute('lookOutlineNormal')), 'the rest is baked');
|
|
607
|
+
disposeWorld(world);
|
|
608
|
+
scenarios += 1;
|
|
609
|
+
}
|
|
610
|
+
// Rebuilt: the model's file changes, so its signature does.
|
|
611
|
+
{
|
|
612
|
+
const world = makeWorld();
|
|
613
|
+
const runtime = makeRuntime(true, 'scenes/b.scene', [placing('rock', 'models/rock.pxmodel')], skip);
|
|
614
|
+
frame(world, runtime);
|
|
615
|
+
const queue = world.lookBake;
|
|
616
|
+
const old = waitingIn(world, 'rock');
|
|
617
|
+
const text = runtime.files['models/rock.pxmodel'];
|
|
618
|
+
runtime.files['models/rock.pxmodel'] = text.replace('"parts"', '"triangles": 9000, "parts"');
|
|
619
|
+
assert.notEqual(runtime.files['models/rock.pxmodel'], text);
|
|
620
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
621
|
+
const fresh = waitingIn(world, 'rock');
|
|
622
|
+
assert.ok(fresh.every((geometry) => !old.includes(geometry)), 'the model was rebuilt');
|
|
623
|
+
assert.deepEqual([queue.pending, queue.dropped], [1, 1], 'the new build waits and the old one does not');
|
|
624
|
+
drain(queue);
|
|
625
|
+
untouched(old, 'a rebuilt model');
|
|
626
|
+
assert.ok(fresh.some((geometry) => geometry.getAttribute('lookOutlineNormal')));
|
|
627
|
+
disposeWorld(world);
|
|
628
|
+
scenarios += 1;
|
|
629
|
+
}
|
|
630
|
+
// The look switched off: every model is rebuilt plain. What still waits
|
|
631
|
+
// is what a plain build bakes at once too: the outline attributes of
|
|
632
|
+
// merged parts (optimize.js), which nothing then draws.
|
|
633
|
+
{
|
|
634
|
+
const world = makeWorld();
|
|
635
|
+
const runtime = makeRuntime(true, 'scenes/c.scene', [placing('tree', 'models/tree.pxmodel'), placing('cart', CART, 3)], skip);
|
|
636
|
+
frame(world, runtime);
|
|
637
|
+
const queue = world.lookBake;
|
|
638
|
+
const old = [...geometriesOf(world)];
|
|
639
|
+
setLookEnabled(false);
|
|
640
|
+
try {
|
|
641
|
+
const waiting = queue.tasks.slice();
|
|
642
|
+
frame(world, runtime);
|
|
643
|
+
assert.ok(waiting.every((task) => !queue.tasks.includes(task)), 'what waited with the look on waits no more');
|
|
644
|
+
assert.equal(queue.dropped, waiting.length);
|
|
645
|
+
const plain = [...world.nodes.values()].flatMap((entry) => meshesOf(entry.node));
|
|
646
|
+
assert.ok(plain.every((mesh) => !mesh.userData.lookOutline && !mesh.geometry.getAttribute('lookOcclusion')), 'no hulls and no occlusion with the look off');
|
|
647
|
+
drain(queue);
|
|
648
|
+
untouched(old, 'a model built before the look went off');
|
|
649
|
+
} finally {
|
|
650
|
+
setLookEnabled(true);
|
|
651
|
+
}
|
|
652
|
+
syncActors(world, runtime, {}, 1 / 60);
|
|
653
|
+
assert.ok(queue.pending >= 2, 'on again, the models wait again');
|
|
654
|
+
disposeWorld(world);
|
|
655
|
+
scenarios += 1;
|
|
656
|
+
}
|
|
657
|
+
// Disposed: in the middle of a task.
|
|
658
|
+
{
|
|
659
|
+
const world = makeWorld();
|
|
660
|
+
const runtime = makeRuntime(true, 'scenes/d.scene', [placing('cart', CART), placing('tree', 'models/tree.pxmodel', 6)], skip);
|
|
661
|
+
frame(world, runtime);
|
|
662
|
+
const queue = world.lookBake;
|
|
663
|
+
const clock = clockFor(queue);
|
|
664
|
+
const first = queue.tasks[0];
|
|
665
|
+
const steps = first.steps;
|
|
666
|
+
first.steps = { next: () => ((clock.at += queue.budgetMs), steps.next()) };
|
|
667
|
+
frame(world, runtime);
|
|
668
|
+
assert.ok(first.started && queue.tasks.includes(first), 'a task is under way');
|
|
669
|
+
const all = [...geometriesOf(world)];
|
|
670
|
+
const pending = queue.pending;
|
|
671
|
+
disposeWorld(world);
|
|
672
|
+
assert.deepEqual([queue.pending, queue.dropped, queue.baked], [0, pending, 0]);
|
|
673
|
+
for (const geometry of all) assert.equal(listeners(geometry), 0, 'nothing listens after a dispose');
|
|
674
|
+
const written = all.filter((geometry) => geometry.getAttribute('lookOutlineNormal')).length;
|
|
675
|
+
renderWorld(world, runtime);
|
|
676
|
+
stepLookBake(queue);
|
|
677
|
+
// Nor by the task that was under way, were it run on to its end.
|
|
678
|
+
const versions = all.map((geometry) => geometry.getAttribute('lookOcclusion')?.version);
|
|
679
|
+
for (let step = steps.next(); !step.done; step = steps.next());
|
|
680
|
+
assert.equal(all.filter((geometry) => geometry.getAttribute('lookOutlineNormal')).length, written, 'and nothing is written after it');
|
|
681
|
+
assert.deepEqual(all.map((geometry) => geometry.getAttribute('lookOcclusion')?.version), versions);
|
|
682
|
+
scenarios += 1;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
// One geometry of a model disposed, by a deck: the others still bake.
|
|
686
|
+
{
|
|
687
|
+
const queue = makeLookBake();
|
|
688
|
+
const node = build(freshModel(MIXED), MIXED, false, queue);
|
|
689
|
+
const waiting = queue.tasks[0].geometries;
|
|
690
|
+
assert.ok(waiting.length >= 3);
|
|
691
|
+
waiting[0].dispose();
|
|
692
|
+
assert.equal(queue.pending, 1);
|
|
693
|
+
drain(queue);
|
|
694
|
+
untouched([waiting[0]], 'a disposed geometry');
|
|
695
|
+
assert.ok(waiting.slice(1).every((geometry) => listeners(geometry) === 0));
|
|
696
|
+
assert.ok(meshesOf(node).some((mesh) => mesh.geometry !== waiting[0] && mesh.geometry.getAttribute('lookOutlineNormal')));
|
|
697
|
+
assert.deepEqual([queue.baked, queue.dropped], [1, 0]);
|
|
698
|
+
scenarios += 1;
|
|
699
|
+
}
|
|
700
|
+
return scenarios;
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
//
|
|
704
|
+
// Geometries replaced before their task runs
|
|
705
|
+
//
|
|
706
|
+
|
|
707
|
+
// What a deck does to give a mesh a geometry of its own: a copy takes the
|
|
708
|
+
// place of each geometry, on the mesh and on its outline hull, and the first
|
|
709
|
+
// one is disposed. Returns the geometries replaced.
|
|
710
|
+
function replaceWithCopies(node) {
|
|
711
|
+
const copies = new Map();
|
|
712
|
+
for (const mesh of meshesOf(node)) {
|
|
713
|
+
if (!copies.has(mesh.geometry)) copies.set(mesh.geometry, mesh.geometry.clone());
|
|
714
|
+
mesh.geometry = copies.get(mesh.geometry);
|
|
715
|
+
}
|
|
716
|
+
for (const geometry of copies.keys()) geometry.dispose();
|
|
717
|
+
return [...copies.keys()];
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// The rule lookbake.js states: when a task ends as baked, every geometry in
|
|
721
|
+
// it that is not disposed holds the whole of the baking, whenever a copy was
|
|
722
|
+
// made and whatever it was made from. Asserted as it stands, over every time
|
|
723
|
+
// a copy can be made by every state of what it is made from, for the first
|
|
724
|
+
// geometry the task outlines and the last. `task.gone` is what was disposed.
|
|
725
|
+
function copiesWhenever() {
|
|
726
|
+
const STAGES = ['lookOcclusion', 'lookOutlineNormal', 'lookOutlineReach'];
|
|
727
|
+
const reference = bakedOf(build(freshModel(MIXED), MIXED, false, null));
|
|
728
|
+
// A build, its one task, and a step of it at a time.
|
|
729
|
+
const start = () => {
|
|
730
|
+
const queue = makeLookBake();
|
|
731
|
+
const node = build(freshModel(MIXED), MIXED, false, queue);
|
|
732
|
+
const [task] = queue.tasks;
|
|
733
|
+
assert.equal(queue.pending, 1);
|
|
734
|
+
const clock = clockFor(queue);
|
|
735
|
+
const steps = task.steps;
|
|
736
|
+
task.steps = { next: () => ((clock.at += queue.budgetMs), steps.next()) };
|
|
737
|
+
queue.drawn = true;
|
|
738
|
+
const meshes = meshesOf(node);
|
|
739
|
+
// Each of the task's own geometries, and what baking at once gives it.
|
|
740
|
+
const expected = new Map(task.geometries.map((geometry) => [geometry, reference[meshes.findIndex((mesh) => mesh.geometry === geometry)].attributes]));
|
|
741
|
+
return { queue, task, expected, own: [...task.geometries] };
|
|
742
|
+
};
|
|
743
|
+
const holdsAll = (geometry, expected) => STAGES.every((name) => isDeepStrictEqual(geometry.getAttribute(name)?.array, expected[name]?.array));
|
|
744
|
+
|
|
745
|
+
// When each stage lands, by the step: the occlusion of them all at once,
|
|
746
|
+
// then each geometry's outline.
|
|
747
|
+
const dry = start();
|
|
748
|
+
const landed = { occlusion: 0, outline: new Map() };
|
|
749
|
+
for (let step = 1; dry.queue.pending > 0; step++) {
|
|
750
|
+
stepLookBake(dry.queue);
|
|
751
|
+
if (!landed.occlusion && dry.own.some((geometry) => geometry.getAttribute('lookOcclusion')?.version > 0)) landed.occlusion = step;
|
|
752
|
+
dry.own.forEach((geometry, at) => geometry.getAttribute('lookOutlineNormal') && !landed.outline.has(at) && landed.outline.set(at, step));
|
|
753
|
+
}
|
|
754
|
+
// The first has occlusion as well; the last, of this model, an outline only.
|
|
755
|
+
const [first] = landed.outline.keys();
|
|
756
|
+
const last = [...landed.outline.keys()].at(-1);
|
|
757
|
+
const total = Math.max(...landed.outline.values());
|
|
758
|
+
assert.ok(dry.own[first].getAttribute('lookOcclusion').array.some((value) => value < 1));
|
|
759
|
+
assert.ok(landed.occlusion > 2 && landed.outline.get(first) > landed.occlusion + 1 && landed.outline.get(last) > landed.outline.get(first) + 1 && total >= landed.outline.get(last));
|
|
760
|
+
// When the copy is made: the task is stepped until this is so. `own` is
|
|
761
|
+
// what the task was queued with, `gone` what of it was disposed.
|
|
762
|
+
const outlined = [...landed.outline.keys()];
|
|
763
|
+
const hasOutline = (own, gone) => (at) => gone.has(own[at]) || own[at].getAttribute('lookOutlineNormal') !== undefined;
|
|
764
|
+
const times = {
|
|
765
|
+
'before the task begins': () => true,
|
|
766
|
+
'between two steps of the occlusion': (own, gone, steps) => steps === 2,
|
|
767
|
+
'the occlusion landed, between two steps of an outline': (own) => own.some((geometry) => geometry.getAttribute('lookOcclusion')?.version > 0),
|
|
768
|
+
'an outline landed': (own, gone) => outlined.some((at) => !gone.has(own[at]) && hasOutline(own, gone)(at)),
|
|
769
|
+
'every outline landed, a step from the end': (own, gone) => outlined.every(hasOutline(own, gone)),
|
|
770
|
+
};
|
|
771
|
+
// What the copy is made from: the geometry or a copy of it, as it is or
|
|
772
|
+
// disposed at the start, before anything was written to it.
|
|
773
|
+
const sources = {
|
|
774
|
+
'the geometry': (geometry) => geometry,
|
|
775
|
+
'the geometry, disposed': (geometry) => (geometry.dispose(), geometry),
|
|
776
|
+
'a copy': (geometry) => geometry.clone(),
|
|
777
|
+
'a copy, disposed': (geometry) => {
|
|
778
|
+
const copy = geometry.clone();
|
|
779
|
+
copy.dispose();
|
|
780
|
+
return copy;
|
|
781
|
+
},
|
|
782
|
+
'a copy of a disposed copy, the geometry disposed': (geometry) => {
|
|
783
|
+
const copy = geometry.clone();
|
|
784
|
+
copy.dispose();
|
|
785
|
+
geometry.dispose();
|
|
786
|
+
return copy.clone();
|
|
787
|
+
},
|
|
788
|
+
};
|
|
789
|
+
let cases = 0;
|
|
790
|
+
for (const at of [first, last]) {
|
|
791
|
+
for (const [when, reached] of Object.entries(times)) {
|
|
792
|
+
for (const [from, makeSource] of Object.entries(sources)) {
|
|
793
|
+
const what = `a copy made of ${from}, ${when}`;
|
|
794
|
+
const { queue, task, expected, own } = start();
|
|
795
|
+
const disposed = task.gone;
|
|
796
|
+
const source = makeSource(own[at]);
|
|
797
|
+
for (let steps = 0; !reached(own, disposed, steps); steps++) {
|
|
798
|
+
assert.equal(queue.pending, 1, `${what}: the task is over before then`);
|
|
799
|
+
stepLookBake(queue);
|
|
800
|
+
}
|
|
801
|
+
assert.equal(queue.pending, 1, `${what}: the task is not over`);
|
|
802
|
+
const copy = source.clone();
|
|
803
|
+
const again = copy.clone();
|
|
804
|
+
drain(queue);
|
|
805
|
+
assert.deepEqual([queue.baked, queue.dropped], [1, 0], `${what}: the task baked`);
|
|
806
|
+
// Every geometry of the task: what it was queued with and every copy.
|
|
807
|
+
const all = task.geometries;
|
|
808
|
+
assert.ok([...own, copy, again].every((geometry) => all.includes(geometry)) && all.length >= own.length + 2, `${what}: the copies are the task's`);
|
|
809
|
+
for (const geometry of all) {
|
|
810
|
+
const root = own.includes(geometry) ? geometry : own[at];
|
|
811
|
+
assert.equal(listeners(geometry), 0, `${what}: nothing listens`);
|
|
812
|
+
assert.ok(!Object.hasOwn(geometry, 'clone'), `${what}: clone is the plain one`);
|
|
813
|
+
if (disposed.has(geometry)) continue;
|
|
814
|
+
assert.ok(holdsAll(geometry, expected.get(root)), `${what}: a geometry not disposed holds the whole of the baking`);
|
|
815
|
+
}
|
|
816
|
+
assert.ok(!disposed.has(copy) && !disposed.has(again));
|
|
817
|
+
cases += 1;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
assert.equal(cases, 50);
|
|
822
|
+
return cases;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// A `clone` taken hold of while the geometry waited and called after its
|
|
826
|
+
// task ended, however it ended, is the plain `clone`.
|
|
827
|
+
function cloneKeptHoldOf() {
|
|
828
|
+
const endings = {
|
|
829
|
+
baked: (queue) => drain(queue),
|
|
830
|
+
dropped: (queue, geometries) => geometries.forEach((geometry) => geometry.dispose()),
|
|
831
|
+
cleared: (queue) => clearLookBake(queue),
|
|
832
|
+
};
|
|
833
|
+
for (const [ending, end] of Object.entries(endings)) {
|
|
834
|
+
const queue = makeLookBake();
|
|
835
|
+
const node = build(freshModel(MIXED), MIXED, false, queue);
|
|
836
|
+
const geometry = meshesOf(node).find((mesh) => mesh.userData.lookOutline).geometry;
|
|
837
|
+
const bound = geometry.clone.bind(geometry);
|
|
838
|
+
const loose = geometry.clone;
|
|
839
|
+
assert.ok(Object.hasOwn(geometry, 'clone'));
|
|
840
|
+
end(queue, [...queue.tasks[0].geometries]);
|
|
841
|
+
assert.deepEqual([queue.pending, queue.baked + queue.dropped], [0, 1], `${ending}: the task is over`);
|
|
842
|
+
for (const copy of [bound(), loose.call(geometry), geometry.clone()]) {
|
|
843
|
+
assert.ok(!Object.hasOwn(copy, 'clone') && listeners(copy) === 0, `${ending}: a copy made after is a plain one`);
|
|
844
|
+
assert.deepEqual(Object.keys(copy.attributes).sort(), Object.keys(geometry.attributes).sort());
|
|
845
|
+
for (const [name, attribute] of Object.entries(geometry.attributes)) {
|
|
846
|
+
assert.deepEqual(copy.getAttribute(name).array, attribute.array, `${ending}: with what the geometry holds (${name})`);
|
|
847
|
+
assert.notEqual(copy.getAttribute(name).array, attribute.array);
|
|
848
|
+
}
|
|
849
|
+
assert.deepEqual(copy.getIndex()?.array, geometry.getIndex()?.array);
|
|
850
|
+
}
|
|
851
|
+
assert.equal(geometry.getAttribute('lookOutlineNormal') !== undefined, ending === 'baked');
|
|
852
|
+
assert.equal(queue.pending, 0, `${ending}: and it queues nothing`);
|
|
853
|
+
}
|
|
854
|
+
return 3;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
function replacedBeforeBaked() {
|
|
858
|
+
const plain = (geometries, what) => {
|
|
859
|
+
for (const geometry of geometries) {
|
|
860
|
+
assert.equal(listeners(geometry), 0, `${what}: nothing listens`);
|
|
861
|
+
assert.ok(!Object.hasOwn(geometry, 'clone'), `${what}: clone is the plain one`);
|
|
862
|
+
}
|
|
863
|
+
};
|
|
864
|
+
const hullsOf = (node) => meshesOf(node).filter((mesh) => mesh.userData.lookOutline);
|
|
865
|
+
let scenarios = 0;
|
|
866
|
+
// Every geometry replaced by a copy and disposed: the model ends as it does
|
|
867
|
+
// when the same is done to one baked at once.
|
|
868
|
+
for (const path of [MIXED, CART, 'models/tree.pxmodel']) {
|
|
869
|
+
for (const optimize of [true, false]) {
|
|
870
|
+
const what = `${path}${optimize ? ' (optimize)' : ''}, its geometries replaced by copies`;
|
|
871
|
+
const now = build(freshModel(path), path, optimize, null);
|
|
872
|
+
replaceWithCopies(now);
|
|
873
|
+
const queue = makeLookBake();
|
|
874
|
+
const later = build(freshModel(path), path, optimize, queue);
|
|
875
|
+
const waiting = queue.tasks.flatMap((task) => [...task.geometries]);
|
|
876
|
+
const pending = queue.pending;
|
|
877
|
+
const old = replaceWithCopies(later);
|
|
878
|
+
assert.ok(pending > 0 && queue.pending === pending, `${what}: the model still waits`);
|
|
879
|
+
assert.ok(hullsOf(later).length > 0 && hullsOf(later).every((mesh) => !mesh.material.visible));
|
|
880
|
+
drain(queue);
|
|
881
|
+
assertSame(bakedOf(later), bakedOf(now), `${what}: every attribute is what baking at once gives`);
|
|
882
|
+
assert.ok(hullsOf(later).every((mesh) => mesh.material.visible && mesh.geometry.getAttribute('lookOutlineReach')), `${what}: the hulls are drawn`);
|
|
883
|
+
assert.deepEqual([queue.baked, queue.dropped], [pending, 0]);
|
|
884
|
+
plain(meshesOf(later).map((mesh) => mesh.geometry), what);
|
|
885
|
+
for (const geometry of waiting) {
|
|
886
|
+
assert.ok(old.includes(geometry));
|
|
887
|
+
assert.equal(listeners(geometry), 0, `${what}: nothing listens to a disposed one`);
|
|
888
|
+
assert.equal(geometry.getAttribute('lookOutlineNormal'), undefined, `${what}: and it was not written`);
|
|
889
|
+
const values = geometry.getAttribute('lookOcclusion');
|
|
890
|
+
if (values) assert.ok(values.array.every((value) => value === 1) && values.version === 0, `${what}: nor its occlusion`);
|
|
891
|
+
}
|
|
892
|
+
scenarios += 1;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
scenarios += copiesWhenever();
|
|
896
|
+
scenarios += cloneKeptHoldOf();
|
|
897
|
+
// Replaced by something that is not a copy, or by a copy cut down since:
|
|
898
|
+
// neither is written, and the hull stays as it was, not drawn.
|
|
899
|
+
for (const cutDown of [false, true]) {
|
|
900
|
+
const queue = makeLookBake();
|
|
901
|
+
const later = build(freshModel('models/rock.pxmodel'), 'models/rock.pxmodel', false, queue);
|
|
902
|
+
const old = [...new Set(meshesOf(later).map((mesh) => mesh.geometry))];
|
|
903
|
+
const other = new Map(old.map((geometry) => [geometry, cutDown ? geometry.clone() : new THREE.BoxGeometry(1, 1, 1)]));
|
|
904
|
+
for (const geometry of other.values()) geometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(9), 3));
|
|
905
|
+
for (const mesh of meshesOf(later)) mesh.geometry = other.get(mesh.geometry);
|
|
906
|
+
old.forEach((geometry) => geometry.dispose());
|
|
907
|
+
assert.equal(queue.pending, cutDown ? 1 : 0, 'only a copy keeps the task');
|
|
908
|
+
drain(queue);
|
|
909
|
+
assert.deepEqual([queue.baked, queue.dropped], [0, 1], 'and a task that could not write to what is left is not one that baked');
|
|
910
|
+
for (const geometry of other.values()) {
|
|
911
|
+
assert.equal(geometry.getAttribute('lookOutlineNormal'), undefined, 'what is not the copy it was is given no outline');
|
|
912
|
+
assert.ok((geometry.getAttribute('lookOcclusion')?.version ?? 0) === 0, 'and no occlusion');
|
|
913
|
+
}
|
|
914
|
+
assert.ok(hullsOf(later).length > 0 && hullsOf(later).every((mesh) => mesh.material.visible === false), 'its hull stays not drawn');
|
|
915
|
+
plain([...old, ...other.values()], 'a geometry replaced by another');
|
|
916
|
+
scenarios += 1;
|
|
917
|
+
}
|
|
918
|
+
// In a world: the copy is made on an actor's own copy of the model, as
|
|
919
|
+
// motion.js makes one for a part that glows.
|
|
920
|
+
{
|
|
921
|
+
const world = makeWorld();
|
|
922
|
+
const runtime = makeRuntime(true, 'scenes/e.scene', [placing('mixed', MIXED), placing('rock', 'models/rock.pxmodel', 4)]);
|
|
923
|
+
frame(world, runtime);
|
|
924
|
+
const queue = world.lookBake;
|
|
925
|
+
const old = replaceWithCopies(world.nodes.get('mixed').node);
|
|
926
|
+
const kept = meshesOf(world.nodes.get('rock').node)[0];
|
|
927
|
+
kept.geometry = kept.geometry.clone();
|
|
928
|
+
clockFor(queue);
|
|
929
|
+
while (queue.pending > 0) frame(world, runtime);
|
|
930
|
+
for (const mesh of [kept, ...meshesOf(world.nodes.get('mixed').node)]) {
|
|
931
|
+
if (mesh.userData.lookOutline) assert.ok(mesh.material.visible && mesh.geometry.getAttribute('lookOutlineNormal'), 'a hull on a copy is drawn');
|
|
932
|
+
else if (mesh.userData.lookDone && mesh.geometry.getAttribute('lookOcclusion')) assert.equal(mesh.geometry.getAttribute('lookOcclusion').version, 1, 'a copy has its occlusion');
|
|
933
|
+
}
|
|
934
|
+
assert.deepEqual([queue.baked, queue.dropped], [2, 0]);
|
|
935
|
+
const all = [...old, ...geometriesOf(world)];
|
|
936
|
+
plain(all, 'after the baking');
|
|
937
|
+
disposeWorld(world);
|
|
938
|
+
plain(all, 'after a dispose');
|
|
939
|
+
scenarios += 1;
|
|
940
|
+
}
|
|
941
|
+
// A copy waiting when its world is disposed is let go with the rest.
|
|
942
|
+
{
|
|
943
|
+
const world = makeWorld();
|
|
944
|
+
const runtime = makeRuntime(true, 'scenes/f.scene', [placing('mixed', MIXED)]);
|
|
945
|
+
frame(world, runtime);
|
|
946
|
+
const copies = replaceWithCopies(world.nodes.get('mixed').node).map((geometry) => geometry.clone());
|
|
947
|
+
const held = [...geometriesOf(world), ...copies];
|
|
948
|
+
assert.ok(held.some((geometry) => Object.hasOwn(geometry, 'clone') && listeners(geometry) === 1), 'copies wait');
|
|
949
|
+
disposeWorld(world);
|
|
950
|
+
assert.deepEqual([world.lookBake.pending, world.lookBake.dropped], [0, 1]);
|
|
951
|
+
plain(held, 'copies of a disposed world');
|
|
952
|
+
scenarios += 1;
|
|
953
|
+
}
|
|
954
|
+
return scenarios;
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
//
|
|
958
|
+
// The budget and the order
|
|
959
|
+
//
|
|
960
|
+
|
|
961
|
+
function budget() {
|
|
962
|
+
const queue = makeLookBake();
|
|
963
|
+
const clock = clockFor(queue);
|
|
964
|
+
const ran = [];
|
|
965
|
+
const geometry = () => new THREE.BufferGeometry();
|
|
966
|
+
// A task of steps that take `costs` milliseconds each.
|
|
967
|
+
const add = (name, costs) =>
|
|
968
|
+
queueLookBake(queue, name, [geometry()], function* () {
|
|
969
|
+
for (const [at, cost] of costs.entries()) {
|
|
970
|
+
ran.push(`${name}${at}`);
|
|
971
|
+
clock.at += cost;
|
|
972
|
+
if (at < costs.length - 1) yield;
|
|
973
|
+
}
|
|
974
|
+
});
|
|
975
|
+
add('a', [2, 2, 2, 2]);
|
|
976
|
+
add('b', [50]);
|
|
977
|
+
add('c', [1, 1]);
|
|
978
|
+
add('d', [5.9, 0.2, 1]);
|
|
979
|
+
assert.equal(queue.budgetMs, 6, 'six milliseconds a frame');
|
|
980
|
+
stepLookBake(queue);
|
|
981
|
+
assert.deepEqual(ran, [], 'the first frame bakes nothing');
|
|
982
|
+
assert.equal(queue.shown, false);
|
|
983
|
+
stepLookBake(queue);
|
|
984
|
+
assert.deepEqual(ran, ['a0', 'a1', 'a2'], 'steps start until the budget is spent');
|
|
985
|
+
stepLookBake(queue);
|
|
986
|
+
assert.deepEqual(ran.slice(3), ['a3', 'b0'], 'a step that passes the budget runs to its end, and nothing starts after it');
|
|
987
|
+
assert.deepEqual([queue.pending, queue.baked], [2, 2]);
|
|
988
|
+
stepLookBake(queue);
|
|
989
|
+
assert.deepEqual(ran.slice(5), ['c0', 'c1', 'd0'], 'the next task starts in the same frame while there is time');
|
|
990
|
+
stepLookBake(queue);
|
|
991
|
+
assert.deepEqual(ran.slice(8), ['d1', 'd2']);
|
|
992
|
+
assert.deepEqual([queue.pending, queue.baked, queue.dropped, queue.ms], [0, 4, 0, clock.at]);
|
|
993
|
+
assert.equal(queue.shown, false, 'the frame that finished the queue was drawn before it did');
|
|
994
|
+
stepLookBake(queue);
|
|
995
|
+
assert.equal(ran.length, 10);
|
|
996
|
+
assert.equal(queue.shown, true, 'the frame after it is the complete picture');
|
|
997
|
+
|
|
998
|
+
// A step that throws takes its task with it, once.
|
|
999
|
+
queueLookBake(queue, 'bad', [geometry()], function* () {
|
|
1000
|
+
clock.at += queue.budgetMs;
|
|
1001
|
+
yield;
|
|
1002
|
+
throw new Error('a step failed');
|
|
1003
|
+
});
|
|
1004
|
+
add('e', [1]);
|
|
1005
|
+
assert.equal(queue.shown, false, 'a task queued, and it is not complete again');
|
|
1006
|
+
stepLookBake(queue);
|
|
1007
|
+
assert.throws(() => stepLookBake(queue), /a step failed/);
|
|
1008
|
+
assert.deepEqual([queue.pending, queue.dropped], [1, 1]);
|
|
1009
|
+
stepLookBake(queue);
|
|
1010
|
+
assert.deepEqual([queue.pending, ran.at(-1), queue.shown], [0, 'e0', false]);
|
|
1011
|
+
stepLookBake(queue);
|
|
1012
|
+
assert.equal(queue.shown, true);
|
|
1013
|
+
|
|
1014
|
+
// A queue whose only model went before the first frame: that frame is complete.
|
|
1015
|
+
const emptied = makeLookBake();
|
|
1016
|
+
const only = geometry();
|
|
1017
|
+
queueLookBake(emptied, 'only', [only], function* () {});
|
|
1018
|
+
only.dispose();
|
|
1019
|
+
assert.deepEqual([emptied.pending, emptied.dropped, emptied.shown], [0, 1, false]);
|
|
1020
|
+
stepLookBake(emptied);
|
|
1021
|
+
assert.equal(emptied.shown, true);
|
|
1022
|
+
|
|
1023
|
+
// Order: nearest first, ties as added, a task under way stays in front.
|
|
1024
|
+
const order = makeLookBake();
|
|
1025
|
+
for (const name of ['far', 'near', 'unknown', 'near2', 'begun']) queueLookBake(order, name, [geometry()], function* () {});
|
|
1026
|
+
order.tasks[4].started = true;
|
|
1027
|
+
const distances = { far: 90, near: 4, near2: 4, begun: 500 };
|
|
1028
|
+
orderLookBake(order, (owner) => distances[owner] ?? Number.MAX_VALUE);
|
|
1029
|
+
assert.deepEqual(order.tasks.map((task) => task.owner), ['begun', 'near', 'near2', 'far', 'unknown']);
|
|
1030
|
+
assert.equal(order.unsorted, false);
|
|
1031
|
+
return 12;
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
// What baking at once gives is what it gave on origin/main.
|
|
1035
|
+
function atOnceIsAsItWas() {
|
|
1036
|
+
const baseline = lookBaseline();
|
|
1037
|
+
assert.equal(baseline, BAKED_AT_ONCE, 'a model built at once is not what it was: if the look is meant to bake something else, see BAKED_AT_ONCE');
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
export async function run() {
|
|
1041
|
+
atOnceIsAsItWas();
|
|
1042
|
+
const checks = atOnce();
|
|
1043
|
+
const models = laterEqualsAtOnce();
|
|
1044
|
+
const hulls = sharedIsBakedOnce();
|
|
1045
|
+
const scenes = worlds() + sharedAcrossScenes();
|
|
1046
|
+
const dropping = withEmptyPartsDropped();
|
|
1047
|
+
const gone = goneBeforeBaked();
|
|
1048
|
+
const replaced = replacedBeforeBaked();
|
|
1049
|
+
budget();
|
|
1050
|
+
return { checks, models, hulls, scenes, dropping, gone, replaced };
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
1054
|
+
const done = await run();
|
|
1055
|
+
console.log(`look bake: ${done.models} builds baked later equal the same builds baked at once, ${done.checks} meshes baked at once without the key, ${done.hulls} cart hulls shown after, ${done.scenes} worlds, ${done.dropping} more with empty parts dropped, ${done.gone} models gone before their task, ${done.replaced} with geometries replaced before theirs; baked at once, they come to ${BAKED_AT_ONCE.slice(0, 12)}`);
|
|
1056
|
+
}
|