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,2470 @@
|
|
|
1
|
+
// `"engine": { "sky": { ... } }` (physics-2d engine/skyKey.js, engine3d/sky.js;
|
|
2
|
+
// docs/engine-sky.md has the terms), on the real `renderWorld`, the real key reader and
|
|
3
|
+
// the real SceneRuntime.
|
|
4
|
+
//
|
|
5
|
+
// - The key: absent is null with no warning and no work; every malformed
|
|
6
|
+
// shape is null with one warning; a good one is read with its defaults.
|
|
7
|
+
// - Which zone: in at a box's edge, out `edge` past it, the first box listed,
|
|
8
|
+
// the zone with no box for a point in none and for no player.
|
|
9
|
+
// - The fade: `fade` seconds by the clock, backwards when the player turns
|
|
10
|
+
// back, a third zone after the one under way; none at a scene's first
|
|
11
|
+
// frame or when the player is somewhere else at once.
|
|
12
|
+
// - Without the key a frame is the frame it was: nothing on the world, the
|
|
13
|
+
// scene graph untouched, the same one draw. With it the sky is in the scene
|
|
14
|
+
// graph for the draw and at no other time, casts nothing, and is no actor.
|
|
15
|
+
// - Pictures: a retained texture per zone as soon as its image is ready,
|
|
16
|
+
// preuploaded one per frame; the flat colour for one missing, failed,
|
|
17
|
+
// not yet arrived, or not an image.
|
|
18
|
+
// - It dies with its scene: another load, a scene without the key, an
|
|
19
|
+
// editor's frame, a dispose, a frame that throws. Two worlds keep their own.
|
|
20
|
+
// - `runtime.skyZone`: null without the key; with it, the zone and the fade.
|
|
21
|
+
// - Its life (engine3d/skylife.js): the dome and what it owns are attached,
|
|
22
|
+
// detached and disposed only by the outermost render of their world or
|
|
23
|
+
// with none in progress. Every way a callback can get in the way is
|
|
24
|
+
// walked: a frame from inside a frame (the same runtime, another with a
|
|
25
|
+
// key, one without), a load and a dispose from inside one, each returning,
|
|
26
|
+
// throwing and caught, throwing and not; listeners that throw on
|
|
27
|
+
// `removed`, on the material's disposal and on each texture's; a disposal
|
|
28
|
+
// listener that draws a frame. After each: no dome in the scene graph, no
|
|
29
|
+
// record but a live one of the frame's own key, everything a gone record
|
|
30
|
+
// owned disposed exactly once, and the next frame's sky right.
|
|
31
|
+
//
|
|
32
|
+
// test-static-actors.mjs runs it (`npm run check`).
|
|
33
|
+
import assert from 'node:assert/strict';
|
|
34
|
+
import * as THREE from 'three';
|
|
35
|
+
// Its import registers the resolver the kit's modules need under node.
|
|
36
|
+
import { makeWorld } from './test-static-passes.mjs';
|
|
37
|
+
// three.js's own keeper of a geometry's GPU side, from its source.
|
|
38
|
+
import { WebGLGeometries } from 'three/src/renderers/webgl/WebGLGeometries.js';
|
|
39
|
+
|
|
40
|
+
const { renderWorld: engineRenderWorld, disposeWorld } = await import('../engine3d/world3d.js');
|
|
41
|
+
const { zoneAt, stepFade, renderWithSky, leaveSky, SNAP_M, FRAME_MOST_S } = await import('../engine3d/sky.js');
|
|
42
|
+
const { readSkyKey, SKY_FADE, SKY_EDGE, SKY_BELOW } = await import('../../physics-2d/engine/skyKey.js');
|
|
43
|
+
// Its import registers what lets physics-2d's SceneRuntime load under node.
|
|
44
|
+
await import('./test-camera-orbit.mjs');
|
|
45
|
+
const { SceneRuntime } = await import('../../physics-2d/engine/scene.js');
|
|
46
|
+
const { Physics3DSystem } = await import('../systems/physics3d.js');
|
|
47
|
+
const { skyKeyFor, leaveSky: leaveSkyAlone } = await import('../engine3d/skylife.js');
|
|
48
|
+
|
|
49
|
+
const ZONES = [
|
|
50
|
+
{ id: 'square', color: '#bfe3f2', art: 'drawings/sky-square.webp' },
|
|
51
|
+
{ id: 'hollow', color: '#3d3a5c', art: 'drawings/sky-hollow.webp', box: [-95, -17, -17, 17] },
|
|
52
|
+
{ id: 'sunny', color: '#c9ecff', art: 'drawings/sky-sunny.webp', box: [17, -17, 95, 17] },
|
|
53
|
+
{ id: 'stadium', color: '#bfe3f2', box: [-17, -95, 17, -17] },
|
|
54
|
+
];
|
|
55
|
+
const sceneWith = (sky) => ({ engine: sky === undefined ? {} : { sky } });
|
|
56
|
+
const good = (extra = {}) => ({ zones: structuredClone(ZONES), ...extra });
|
|
57
|
+
const quiet = () => {};
|
|
58
|
+
|
|
59
|
+
// An image art as physics-2d's `imageArt` hands it over, once decoded.
|
|
60
|
+
const image = (path, fields = {}) => ({ kind: 'image', path, url: `data:${path}`, image: { width: 1024, height: 256 }, ready: true, failed: false, ...fields });
|
|
61
|
+
const allArt = () => Object.fromEntries(ZONES.filter((z) => z.art).map((z) => [z.art, image(z.art)]));
|
|
62
|
+
|
|
63
|
+
// The clock `renderWorld` reads.
|
|
64
|
+
let clock = 0;
|
|
65
|
+
const realNow = performance.now.bind(performance);
|
|
66
|
+
const tick = (seconds) => {
|
|
67
|
+
clock += seconds * 1000;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// A world with a composer that notes what the scene graph held as it drew.
|
|
71
|
+
function skyWorld() {
|
|
72
|
+
const world = makeWorld();
|
|
73
|
+
world.sky = null;
|
|
74
|
+
world.draws = [];
|
|
75
|
+
// Every record this world has had, with what it owned and how often each
|
|
76
|
+
// was disposed; and how many frames are being drawn.
|
|
77
|
+
world.records = new Map();
|
|
78
|
+
world.level = 0;
|
|
79
|
+
world.composer = {
|
|
80
|
+
render() {
|
|
81
|
+
const sky = world.scene.children.filter((child) => child.name === 'engine.sky');
|
|
82
|
+
world.draws.push({ children: world.scene.children.length, sky: sky.length, mesh: sky[0] ?? null, shown: sky[0]?.visible ?? null, level: world.level });
|
|
83
|
+
track(world);
|
|
84
|
+
world.level += 1;
|
|
85
|
+
try {
|
|
86
|
+
world.onRender?.(world.level - 1);
|
|
87
|
+
} finally {
|
|
88
|
+
world.level -= 1;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
world.renderer = { dispose() {}, shadowMap: { enabled: false } };
|
|
93
|
+
return world;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Note the world's record and everything it owns, once each; `world.onOwned`
|
|
97
|
+
// may hang a listener of its own on each. A resource disposed a second time
|
|
98
|
+
// is written down in `twice`.
|
|
99
|
+
const twice = [];
|
|
100
|
+
// The world's record: what `world.sky` is, unless it is the marker that
|
|
101
|
+
// stands there while a record's resources are disposed, which is no record.
|
|
102
|
+
const recordOf = (world) => (world.sky && world.sky.releasing !== true ? world.sky : null);
|
|
103
|
+
function track(world) {
|
|
104
|
+
const record = recordOf(world);
|
|
105
|
+
if (!record) return;
|
|
106
|
+
world.records ??= new Map();
|
|
107
|
+
if (!world.records.has(record)) world.records.set(record, new Map());
|
|
108
|
+
const owned = world.records.get(record);
|
|
109
|
+
for (const item of [...record.owned(), ...record.shed]) {
|
|
110
|
+
if (owned.has(item)) continue;
|
|
111
|
+
const kind = item.isTexture ? 'texture' : item.isMaterial ? 'material' : 'geometry';
|
|
112
|
+
const entry = { kind, disposed: 0, after: 0 };
|
|
113
|
+
owned.set(item, entry);
|
|
114
|
+
item.addEventListener('dispose', () => {
|
|
115
|
+
entry.disposed += 1;
|
|
116
|
+
if (entry.disposed > 1) twice.push(kind);
|
|
117
|
+
});
|
|
118
|
+
world.onOwned?.(item, kind);
|
|
119
|
+
// And one after whatever a scenario hung there, where the renderer's own
|
|
120
|
+
// would be: it must run whatever the ones before it do.
|
|
121
|
+
item.addEventListener('dispose', () => (entry.after += 1));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// THE POSTCONDITION (engine3d/skylife.js), asserted from outside after every
|
|
126
|
+
// outermost frame of every scenario in this file: `renderWorld` here is the
|
|
127
|
+
// engine's, wrapped. After the outermost sky frame of a world returns or
|
|
128
|
+
// throws, EITHER `world.sky` is null, OR it is a record whose key is the key
|
|
129
|
+
// the frame's runtime has NOW for THIS world, with its dome out of the scene
|
|
130
|
+
// graph, and the frame did not throw. And always: no dome in the scene
|
|
131
|
+
// graph once no frame of the world is being drawn, nothing ever disposed
|
|
132
|
+
// twice, and everything a record that is gone owned disposed exactly once.
|
|
133
|
+
//
|
|
134
|
+
// "Outermost sky frame" is what the engine can know: the first frame of a
|
|
135
|
+
// world to come through the sky's code (its runtime has a key, or the world
|
|
136
|
+
// has a record) with none in progress. A frame of a scene without the key
|
|
137
|
+
// on a world with no record runs nothing of the sky's, so a keyed frame drawn
|
|
138
|
+
// from inside it is the outermost.
|
|
139
|
+
let framesChecked = 0;
|
|
140
|
+
let randomCoverage = null;
|
|
141
|
+
function renderWorld(world, runtime) {
|
|
142
|
+
const outermostSky = (world.skyDepth ?? 0) === 0 && Boolean(runtime?.sky || world.sky);
|
|
143
|
+
world.calls = (world.calls ?? 0) + 1;
|
|
144
|
+
let threw = false;
|
|
145
|
+
try {
|
|
146
|
+
engineRenderWorld(world, runtime);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
threw = true;
|
|
149
|
+
throw err;
|
|
150
|
+
} finally {
|
|
151
|
+
world.calls -= 1;
|
|
152
|
+
track(world);
|
|
153
|
+
if (outermostSky) {
|
|
154
|
+
framesChecked += 1;
|
|
155
|
+
const record = recordOf(world);
|
|
156
|
+
assert.ok(world.sky === null || world.sky === record, 'postcondition: the disposal marker is gone');
|
|
157
|
+
assert.equal(world.skyDepth, 0, 'postcondition: no frame of the world is still counted');
|
|
158
|
+
if (record) {
|
|
159
|
+
assert.equal(threw, false, 'postcondition: a frame that threw leaves no record');
|
|
160
|
+
assert.equal(record.key, skyKeyFor(world, runtime), 'postcondition: a record left is of the key the frame\'s runtime has now for this world');
|
|
161
|
+
assert.equal(record.mesh.parent, null, 'postcondition: its dome is out of the scene graph');
|
|
162
|
+
assert.equal(record.mesh.visible, true, 'postcondition: and left shown');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (world.calls === 0) assert.equal(domesIn(world), 0, 'postcondition: no dome in the scene graph outside a frame');
|
|
166
|
+
assert.deepEqual(twice, [], 'postcondition: nothing is disposed twice');
|
|
167
|
+
// (Not from inside a disposal, which is half way through one.)
|
|
168
|
+
for (const [seen, owned] of (world.skyDepth ?? 0) === 0 ? (world.records ?? []) : []) {
|
|
169
|
+
if (seen === world.sky) continue;
|
|
170
|
+
for (const entry of owned.values()) {
|
|
171
|
+
assert.equal(entry.disposed, 1, `postcondition: a gone record's ${entry.kind} is disposed exactly once`);
|
|
172
|
+
assert.equal(entry.after, 1, `postcondition: every listener on a gone record's ${entry.kind} ran, the last one too`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const domesIn = (world) => world.scene.children.filter((child) => child.name === 'engine.sky').length;
|
|
179
|
+
|
|
180
|
+
// The invariant, after anything: no dome in the scene graph; a record only
|
|
181
|
+
// if it is live, at rest and (when `runtime` is given) of that runtime's key;
|
|
182
|
+
// everything a gone record owned disposed exactly once, and nothing of a
|
|
183
|
+
// live one's but a texture it let go.
|
|
184
|
+
function settled(world, runtime, what) {
|
|
185
|
+
assert.equal(domesIn(world), 0, `${what}: no dome in the scene graph`);
|
|
186
|
+
const record = world.sky ?? null;
|
|
187
|
+
assert.equal(world.skyDepth ?? 0, 0, `${what}: no frame is in progress`);
|
|
188
|
+
if (record && runtime) assert.equal(record.key, skyKeyFor(world, runtime), `${what}: a record left is of the frame's key`);
|
|
189
|
+
for (const [seen, owned] of world.records) {
|
|
190
|
+
assert.equal(seen.mesh.parent, null, `${what}: a dome has no parent`);
|
|
191
|
+
assert.equal(seen.mesh.visible, true, `${what}: a dome is left shown`);
|
|
192
|
+
for (const [item, entry] of owned) {
|
|
193
|
+
if (seen !== record) assert.equal(entry.disposed, 1, `${what}: a gone record's ${entry.kind} is disposed once`);
|
|
194
|
+
else if (entry.kind !== 'texture') assert.equal(entry.disposed, 0, `${what}: a live record's ${entry.kind} is not disposed`);
|
|
195
|
+
else assert.equal(entry.disposed, [...seen.textures.values()].some((held) => held.texture === item) ? 0 : 1, `${what}: a live record's texture`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// And the frame after: one dome, shown, of the runtime's key, its zone's sky.
|
|
201
|
+
function nextFrameIsRight(world, runtime, what) {
|
|
202
|
+
world.onRender = null;
|
|
203
|
+
world.onOwned = null;
|
|
204
|
+
tick(1 / 60);
|
|
205
|
+
renderWorld(world, runtime);
|
|
206
|
+
const draw = world.draws.at(-1);
|
|
207
|
+
if (world.disposed === true || !runtime.sky) {
|
|
208
|
+
assert.equal(draw.sky, 0, `${what}: the next frame has no sky`);
|
|
209
|
+
assert.equal(world.sky ?? null, null, `${what}: and makes none`);
|
|
210
|
+
settled(world, null, `${what}, after the next frame`);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
assert.deepEqual([draw.sky, draw.shown], [1, true], `${what}: the next frame is drawn with its dome`);
|
|
214
|
+
assert.equal(world.sky.key, runtime.sky, `${what}: of its own key`);
|
|
215
|
+
const t = runtime.player.components.Transform;
|
|
216
|
+
const zone = runtime.sky.zones[zoneAt(runtime.sky, t.x, t.z)];
|
|
217
|
+
assert.equal(runtime.skyZone.id, zone.id, `${what}: in its zone`);
|
|
218
|
+
// (At rest `to` is `from`; mid-fade the zone is the one it is turning into.)
|
|
219
|
+
assert.equal(hex(uniformsOf(world).colorTo.value), zone.color, `${what}: that zone's sky`);
|
|
220
|
+
assert.equal(uniformsOf(world).hasTo.value, zone.art && runtime.sprites[zone.art] ? 1 : 0, `${what}: with its picture`);
|
|
221
|
+
settled(world, runtime, `${what}, after the next frame`);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// What a SceneRuntime is to `renderWorld` and the sky: a player's Transform,
|
|
225
|
+
// the deck's art, and the key as a load reads it.
|
|
226
|
+
function runtimeWith(sky, { sprites = allArt(), player = { x: 0, z: 0 } } = {}) {
|
|
227
|
+
const actor = player ? { id: 'player', components: { Player: {}, Transform: { x: player.x, y: 1, z: player.z } } } : null;
|
|
228
|
+
return {
|
|
229
|
+
data: sceneWith(sky),
|
|
230
|
+
sprites,
|
|
231
|
+
sky: readSkyKey(sceneWith(sky), quiet),
|
|
232
|
+
get skyZone() {
|
|
233
|
+
return this.sky === null ? null : this.sky.zone;
|
|
234
|
+
},
|
|
235
|
+
// What `SceneRuntime.load` does that the sky hears of: the physics
|
|
236
|
+
// system's `reset` first, with the world the runtime draws in, then the
|
|
237
|
+
// key read again.
|
|
238
|
+
// `load(world)` loads the same scene again; `load(world, undefined)` one
|
|
239
|
+
// without the key.
|
|
240
|
+
load(world, ...next) {
|
|
241
|
+
this.three = world;
|
|
242
|
+
new Physics3DSystem().reset(this);
|
|
243
|
+
this.data = sceneWith(next.length > 0 ? next[0] : sky);
|
|
244
|
+
this.sky = readSkyKey(this.data, quiet);
|
|
245
|
+
},
|
|
246
|
+
player: actor,
|
|
247
|
+
getActor: (id) => (actor && id === actor.id ? actor : null),
|
|
248
|
+
actorWith: (name) => (actor && name in actor.components ? actor : null),
|
|
249
|
+
moveTo(x, z) {
|
|
250
|
+
actor.components.Transform.x = x;
|
|
251
|
+
actor.components.Transform.z = z;
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const uniformsOf = (world) => world.sky.material.uniforms;
|
|
257
|
+
const hex = (color) => `#${color.getHexString()}`;
|
|
258
|
+
const near = (a, b, what) => assert.ok(Math.abs(a - b) < 1e-9, `${what}: ${a} is not ${b}`);
|
|
259
|
+
|
|
260
|
+
// Model both explicit warmups and the renderer's lazy uploads on a draw.
|
|
261
|
+
// A version already uploaded does no GPU work, as in WebGLTextures.
|
|
262
|
+
function preloadWorld() {
|
|
263
|
+
const world = skyWorld();
|
|
264
|
+
world.uploads = [];
|
|
265
|
+
world.warmups = [];
|
|
266
|
+
const versions = new Map();
|
|
267
|
+
const upload = (texture) => {
|
|
268
|
+
if (versions.get(texture) === texture.version) return;
|
|
269
|
+
versions.set(texture, texture.version);
|
|
270
|
+
world.uploads.push({ texture, frame: world.draws.length, image: texture.image, flipY: texture.flipY });
|
|
271
|
+
};
|
|
272
|
+
world.renderer.initTexture = (texture) => {
|
|
273
|
+
world.warmups.push(world.draws.length);
|
|
274
|
+
upload(texture);
|
|
275
|
+
};
|
|
276
|
+
world.renderer.domElement = new THREE.EventDispatcher();
|
|
277
|
+
world.restoreContext = () => {
|
|
278
|
+
versions.clear();
|
|
279
|
+
world.renderer.domElement.dispatchEvent({ type: 'webglcontextrestored' });
|
|
280
|
+
};
|
|
281
|
+
const draw = world.composer.render;
|
|
282
|
+
world.composer.render = () => {
|
|
283
|
+
const record = recordOf(world);
|
|
284
|
+
if (record) {
|
|
285
|
+
const u = record.material.uniforms;
|
|
286
|
+
if (u.hasFrom.value) upload(u.mapFrom.value);
|
|
287
|
+
if (u.blend.value > 0 && u.hasTo.value) upload(u.mapTo.value);
|
|
288
|
+
}
|
|
289
|
+
draw();
|
|
290
|
+
};
|
|
291
|
+
return world;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Decodes finish only when the scenario chooses. The asymmetric rows make
|
|
295
|
+
// orientation visible, and every close is counted, even after release.
|
|
296
|
+
async function withBitmaps(scenario) {
|
|
297
|
+
const original = globalThis.createImageBitmap;
|
|
298
|
+
const pending = [];
|
|
299
|
+
globalThis.createImageBitmap = (image, options) => new Promise((resolve, reject) => {
|
|
300
|
+
const bitmap = { rows: ['last', 'first'], closed: 0, close() { this.closed += 1; } };
|
|
301
|
+
pending.push({ image, options, bitmap, resolve: () => resolve(bitmap), reject });
|
|
302
|
+
});
|
|
303
|
+
try {
|
|
304
|
+
await scenario(pending);
|
|
305
|
+
} finally {
|
|
306
|
+
if (original === undefined) delete globalThis.createImageBitmap;
|
|
307
|
+
else globalThis.createImageBitmap = original;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const scenarios = {
|
|
312
|
+
async 'preload: context restore reuploads retained zones one per idle frame before a crossing'() {
|
|
313
|
+
await withBitmaps(async (pending) => {
|
|
314
|
+
const world = preloadWorld();
|
|
315
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: -18 } });
|
|
316
|
+
const canvas = world.renderer.domElement;
|
|
317
|
+
assert.equal(canvas._listeners, undefined, 'no listener before the sky key is active');
|
|
318
|
+
renderWorld(world, runtime);
|
|
319
|
+
assert.equal(canvas._listeners.webglcontextrestored.length, 1);
|
|
320
|
+
pending.forEach((decode) => decode.resolve());
|
|
321
|
+
await Promise.resolve();
|
|
322
|
+
for (let i = 0; i < 3; i++) {
|
|
323
|
+
tick(1 / 60);
|
|
324
|
+
renderWorld(world, runtime);
|
|
325
|
+
}
|
|
326
|
+
assert.equal(world.uploads.length, 3);
|
|
327
|
+
const retained = [...world.sky.textures.values()];
|
|
328
|
+
assert.ok(retained.every((held) => held.uploaded));
|
|
329
|
+
world.restoreContext();
|
|
330
|
+
assert.ok(retained.every((held) => !held.uploaded));
|
|
331
|
+
assert.equal(world.uploads.length, 3, 'restore itself does not upload');
|
|
332
|
+
for (let i = 0; i < 3; i++) {
|
|
333
|
+
tick(1 / 60);
|
|
334
|
+
renderWorld(world, runtime);
|
|
335
|
+
assert.equal(world.uploads.length, 4 + i, 'one reupload per idle frame');
|
|
336
|
+
}
|
|
337
|
+
assert.deepEqual(world.uploads.slice(3).map(({ texture }) => texture), retained.map((held) => held.texture));
|
|
338
|
+
runtime.moveTo(-18, -16);
|
|
339
|
+
for (let i = 0; i < 6; i++) {
|
|
340
|
+
tick(0.25);
|
|
341
|
+
renderWorld(world, runtime);
|
|
342
|
+
}
|
|
343
|
+
assert.equal(runtime.skyZone.id, 'hollow');
|
|
344
|
+
assert.equal(runtime.skyZone.blend, 0);
|
|
345
|
+
assert.equal(world.uploads.length, 6, 'the crossing needs no lazy upload');
|
|
346
|
+
assert.equal(Math.max(...world.warmups.map((frame) => world.warmups.filter((at) => at === frame).length)), 1);
|
|
347
|
+
leaveSky(world);
|
|
348
|
+
assert.equal(canvas._listeners.webglcontextrestored.length, 0, 'release removes the listener');
|
|
349
|
+
world.restoreContext();
|
|
350
|
+
assert.ok(retained.every((held) => held.uploaded), 'restore cannot reach released entries');
|
|
351
|
+
});
|
|
352
|
+
},
|
|
353
|
+
|
|
354
|
+
async 'preload: twenty complete crossings upload each zone once, dispose nothing, and never call outsideCall'() {
|
|
355
|
+
await withBitmaps(async (pending) => {
|
|
356
|
+
const world = preloadWorld();
|
|
357
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: -18 } });
|
|
358
|
+
// Crossing must leave both adopted and frozen scenery untouched. These
|
|
359
|
+
// are the exact keeper methods/epoch outsideCall/dropStill would touch.
|
|
360
|
+
let outside = 0;
|
|
361
|
+
world.skipping.epoch = 42;
|
|
362
|
+
world.stillKeeper = { begin() { outside += 1; }, interrupt() { outside += 1; }, end() { outside += 1; } };
|
|
363
|
+
renderWorld(world, runtime);
|
|
364
|
+
assert.equal(pending.length, 3, 'all ready art starts decoding immediately, even outside the fade');
|
|
365
|
+
assert.equal(world.uploads.length, 0, 'inactive pictures wait for bitmap decode');
|
|
366
|
+
for (const decode of pending) decode.resolve();
|
|
367
|
+
await Promise.resolve();
|
|
368
|
+
for (let i = 0; i < 3; i++) {
|
|
369
|
+
tick(1 / 60);
|
|
370
|
+
renderWorld(world, runtime);
|
|
371
|
+
assert.equal(world.uploads.length, i + 1, 'one upload per frame');
|
|
372
|
+
}
|
|
373
|
+
const textures = [...world.sky.textures.values()].map((held) => held.texture);
|
|
374
|
+
for (let n = 0; n < 20; n++) {
|
|
375
|
+
runtime.moveTo(n % 2 ? -16 : -18, -16);
|
|
376
|
+
for (let i = 0; i < 6; i++) {
|
|
377
|
+
tick(0.25);
|
|
378
|
+
renderWorld(world, runtime);
|
|
379
|
+
}
|
|
380
|
+
assert.equal(runtime.skyZone.blend, 0, 'each crossing includes fade end');
|
|
381
|
+
}
|
|
382
|
+
assert.equal(world.uploads.length, 3);
|
|
383
|
+
assert.equal(new Set(world.uploads.map((entry) => entry.texture)).size, 3);
|
|
384
|
+
assert.deepEqual([...world.sky.textures.values()].map((held) => held.texture), textures);
|
|
385
|
+
assert.ok([...world.records.get(world.sky).values()].every((entry) => entry.disposed === 0));
|
|
386
|
+
assert.ok(pending.every(({ bitmap }) => bitmap.closed === 0));
|
|
387
|
+
assert.equal(outside, 0, 'no outsideCall on crossing');
|
|
388
|
+
assert.equal(world.skipping.epoch, 42, 'no thaw on crossing');
|
|
389
|
+
assert.equal(Math.max(...world.warmups.map((frame) => world.warmups.filter((at) => at === frame).length)), 1);
|
|
390
|
+
});
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
async 'preload: bitmap orientation, colour space and sampling match the original image'() {
|
|
394
|
+
await withBitmaps(async (pending) => {
|
|
395
|
+
const world = preloadWorld();
|
|
396
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
397
|
+
renderWorld(world, runtime);
|
|
398
|
+
for (const decode of pending) decode.resolve();
|
|
399
|
+
await Promise.resolve();
|
|
400
|
+
for (let i = 0; i < 3; i++) renderWorld(world, runtime);
|
|
401
|
+
for (const [index, decode] of pending.entries()) {
|
|
402
|
+
assert.deepEqual(decode.options, { imageOrientation: 'flipY', premultiplyAlpha: 'none', colorSpaceConversion: 'none' });
|
|
403
|
+
const texture = world.sky.textures.get(index).texture;
|
|
404
|
+
assert.equal(texture.image, decode.bitmap);
|
|
405
|
+
assert.equal(texture.flipY, false, 'flip already baked into bitmap');
|
|
406
|
+
// Original HTML image rows after WebGL's default flipY=true are the
|
|
407
|
+
// same as the preflipped bitmap uploaded without a second flip.
|
|
408
|
+
assert.deepEqual(texture.image.rows, ['first', 'last'].reverse());
|
|
409
|
+
assert.equal(texture.image.rows[1], 'first', 'v=1 (overhead) is still the first image row');
|
|
410
|
+
assert.equal(texture.colorSpace, THREE.SRGBColorSpace);
|
|
411
|
+
assert.equal(texture.wrapS, THREE.RepeatWrapping);
|
|
412
|
+
assert.equal(texture.wrapT, THREE.ClampToEdgeWrapping);
|
|
413
|
+
assert.equal(texture.minFilter, THREE.LinearFilter);
|
|
414
|
+
assert.equal(texture.magFilter, THREE.LinearFilter);
|
|
415
|
+
assert.equal(texture.generateMipmaps, false);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
|
|
420
|
+
async 'preload: inactive art replacement and removal dispose once and close the old bitmaps'() {
|
|
421
|
+
await withBitmaps(async (pending) => {
|
|
422
|
+
const world = preloadWorld();
|
|
423
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
424
|
+
renderWorld(world, runtime);
|
|
425
|
+
pending.forEach((decode) => decode.resolve());
|
|
426
|
+
await Promise.resolve();
|
|
427
|
+
const old = world.sky.textures.get(1).texture;
|
|
428
|
+
let gone = 0;
|
|
429
|
+
old.addEventListener('dispose', () => (gone += 1));
|
|
430
|
+
runtime.sprites[ZONES[1].art] = image(ZONES[1].art);
|
|
431
|
+
renderWorld(world, runtime);
|
|
432
|
+
assert.equal(gone, 1);
|
|
433
|
+
assert.equal(pending[1].bitmap.closed, 1);
|
|
434
|
+
assert.notEqual(world.sky.textures.get(1).texture, old);
|
|
435
|
+
pending[3].resolve();
|
|
436
|
+
await Promise.resolve();
|
|
437
|
+
delete runtime.sprites[ZONES[1].art];
|
|
438
|
+
renderWorld(world, runtime);
|
|
439
|
+
renderWorld(world, runtime);
|
|
440
|
+
assert.equal(gone, 1);
|
|
441
|
+
assert.equal(pending[3].bitmap.closed, 1);
|
|
442
|
+
assert.equal(world.sky.textures.size, 2);
|
|
443
|
+
});
|
|
444
|
+
},
|
|
445
|
+
|
|
446
|
+
async 'preload: every release path disposes all textures and closes bitmaps'() {
|
|
447
|
+
for (const release of [
|
|
448
|
+
(world, runtime) => runtime.load(world),
|
|
449
|
+
(world) => renderWorld(world, runtimeWith(undefined)),
|
|
450
|
+
(world) => disposeWorld(world),
|
|
451
|
+
]) {
|
|
452
|
+
await withBitmaps(async (pending) => {
|
|
453
|
+
const world = preloadWorld();
|
|
454
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
455
|
+
renderWorld(world, runtime);
|
|
456
|
+
pending.forEach((decode) => decode.resolve());
|
|
457
|
+
await Promise.resolve();
|
|
458
|
+
const record = world.sky;
|
|
459
|
+
release(world, runtime);
|
|
460
|
+
assert.equal(world.sky, null);
|
|
461
|
+
assert.equal(world.renderer.domElement._listeners.webglcontextrestored.length, 0);
|
|
462
|
+
assert.ok([...world.records.get(record).values()].every((entry) => entry.disposed === 1));
|
|
463
|
+
assert.ok(pending.every(({ bitmap }) => bitmap.closed === 1));
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
|
|
468
|
+
async 'preload: late results after release or art replacement are closed and never uploaded'() {
|
|
469
|
+
for (const change of ['release', 'replaced before a frame', 'removed by a frame']) {
|
|
470
|
+
await withBitmaps(async (pending) => {
|
|
471
|
+
const world = preloadWorld();
|
|
472
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
473
|
+
renderWorld(world, runtime);
|
|
474
|
+
const texture = world.sky.textures.get(0).texture;
|
|
475
|
+
const source = texture.image;
|
|
476
|
+
if (change === 'release') disposeWorld(world);
|
|
477
|
+
else if (change === 'replaced before a frame') runtime.sprites[ZONES[0].art] = image(ZONES[0].art);
|
|
478
|
+
else {
|
|
479
|
+
delete runtime.sprites[ZONES[0].art];
|
|
480
|
+
renderWorld(world, runtime);
|
|
481
|
+
}
|
|
482
|
+
pending[0].resolve();
|
|
483
|
+
await Promise.resolve();
|
|
484
|
+
assert.equal(pending[0].bitmap.closed, 1, change);
|
|
485
|
+
assert.equal(texture.image, source, change);
|
|
486
|
+
assert.equal(world.uploads.length, 0, change);
|
|
487
|
+
if (world.sky) disposeWorld(world);
|
|
488
|
+
for (const decode of pending.slice(1)) decode.resolve();
|
|
489
|
+
await Promise.resolve();
|
|
490
|
+
assert.ok(pending.every(({ bitmap }) => bitmap.closed === 1));
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
|
|
495
|
+
async 'preload: a fade reached before bitmap readiness draws the original image without a blank or reupload'() {
|
|
496
|
+
await withBitmaps(async (pending) => {
|
|
497
|
+
const world = preloadWorld();
|
|
498
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
499
|
+
renderWorld(world, runtime);
|
|
500
|
+
const first = uniformsOf(world).mapFrom.value;
|
|
501
|
+
assert.equal(first.image, runtime.sprites[ZONES[0].art].image);
|
|
502
|
+
runtime.moveTo(-18, 0);
|
|
503
|
+
tick(0.1);
|
|
504
|
+
renderWorld(world, runtime);
|
|
505
|
+
const to = uniformsOf(world).mapTo.value;
|
|
506
|
+
assert.equal(to.image, runtime.sprites[ZONES[1].art].image);
|
|
507
|
+
assert.deepEqual([uniformsOf(world).hasFrom.value, uniformsOf(world).hasTo.value], [1, 1]);
|
|
508
|
+
assert.ok(runtime.skyZone.blend > 0);
|
|
509
|
+
pending[0].resolve();
|
|
510
|
+
pending[1].resolve();
|
|
511
|
+
await Promise.resolve();
|
|
512
|
+
assert.deepEqual(pending.slice(0, 2).map(({ bitmap }) => bitmap.closed), [1, 1]);
|
|
513
|
+
for (let i = 0; i < 30; i++) {
|
|
514
|
+
runtime.moveTo(i % 2 ? -16 : -18, 0);
|
|
515
|
+
tick(0.1);
|
|
516
|
+
renderWorld(world, runtime);
|
|
517
|
+
}
|
|
518
|
+
assert.equal(world.uploads.length, 2, 'fallback uploads are kept too');
|
|
519
|
+
assert.ok(world.uploads.every(({ flipY }) => flipY === true));
|
|
520
|
+
assert.ok(world.warmups.every((frame) => world.warmups.filter((at) => at === frame).length === 1));
|
|
521
|
+
disposeWorld(world);
|
|
522
|
+
pending[2].resolve();
|
|
523
|
+
await Promise.resolve();
|
|
524
|
+
assert.equal(pending[2].bitmap.closed, 1);
|
|
525
|
+
});
|
|
526
|
+
},
|
|
527
|
+
|
|
528
|
+
async 'preload: decode rejection or synchronous failure falls back to the original image'() {
|
|
529
|
+
await withBitmaps(async (pending) => {
|
|
530
|
+
const world = preloadWorld();
|
|
531
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
532
|
+
renderWorld(world, runtime);
|
|
533
|
+
pending.forEach(({ reject }) => reject(new Error('decode failed')));
|
|
534
|
+
await Promise.resolve();
|
|
535
|
+
for (let i = 0; i < 3; i++) renderWorld(world, runtime);
|
|
536
|
+
assert.equal(world.uploads.length, 3);
|
|
537
|
+
assert.ok(world.uploads.every(({ texture, image, flipY }) => image === texture.image && flipY === true));
|
|
538
|
+
globalThis.createImageBitmap = () => { throw new Error('unsupported source'); };
|
|
539
|
+
const next = preloadWorld();
|
|
540
|
+
renderWorld(next, runtime);
|
|
541
|
+
assert.equal(next.uploads.length, 1);
|
|
542
|
+
});
|
|
543
|
+
},
|
|
544
|
+
|
|
545
|
+
async 'preload: simultaneous late fade images preserve both original images with one scheduled upload'() {
|
|
546
|
+
await withBitmaps(async (pending) => {
|
|
547
|
+
const world = preloadWorld();
|
|
548
|
+
const sprites = allArt();
|
|
549
|
+
for (const art of Object.values(sprites)) art.ready = false;
|
|
550
|
+
const runtime = runtimeWith(good(), { sprites, player: { x: -16, z: 0 } });
|
|
551
|
+
renderWorld(world, runtime);
|
|
552
|
+
runtime.moveTo(-18, 0);
|
|
553
|
+
tick(0.1);
|
|
554
|
+
renderWorld(world, runtime);
|
|
555
|
+
sprites[ZONES[0].art].ready = true;
|
|
556
|
+
sprites[ZONES[1].art].ready = true;
|
|
557
|
+
tick(0.1);
|
|
558
|
+
renderWorld(world, runtime);
|
|
559
|
+
assert.deepEqual([uniformsOf(world).hasFrom.value, uniformsOf(world).hasTo.value], [1, 1]);
|
|
560
|
+
near(runtime.skyZone.blend, 0.2 / 1.5, 'the same fade');
|
|
561
|
+
assert.equal(world.warmups.length, 1, 'one proactive upload');
|
|
562
|
+
assert.equal(world.uploads.length, 2, 'the other active image uses the required immediate fallback');
|
|
563
|
+
pending.forEach((decode) => decode.resolve());
|
|
564
|
+
await Promise.resolve();
|
|
565
|
+
renderWorld(world, runtime);
|
|
566
|
+
assert.equal(world.uploads.length, 2, 'late bitmap results do not upload again');
|
|
567
|
+
assert.ok(pending.every(({ bitmap }) => bitmap.closed === 1));
|
|
568
|
+
disposeWorld(world);
|
|
569
|
+
});
|
|
570
|
+
},
|
|
571
|
+
|
|
572
|
+
'preload: without createImageBitmap, ready and later-ready art use the old image path'() {
|
|
573
|
+
const original = globalThis.createImageBitmap;
|
|
574
|
+
delete globalThis.createImageBitmap;
|
|
575
|
+
try {
|
|
576
|
+
const world = preloadWorld();
|
|
577
|
+
const late = image(ZONES[2].art, { ready: false });
|
|
578
|
+
const runtime = runtimeWith(good());
|
|
579
|
+
runtime.sprites[ZONES[2].art] = late;
|
|
580
|
+
renderWorld(world, runtime);
|
|
581
|
+
renderWorld(world, runtime);
|
|
582
|
+
assert.equal(world.uploads.length, 2);
|
|
583
|
+
late.ready = true;
|
|
584
|
+
renderWorld(world, runtime);
|
|
585
|
+
assert.equal(world.uploads.length, 3, 'later-ready inactive art is preloaded');
|
|
586
|
+
const held = world.sky.textures.get(2).texture;
|
|
587
|
+
let disposed = 0;
|
|
588
|
+
held.addEventListener('dispose', () => (disposed += 1));
|
|
589
|
+
late.ready = false;
|
|
590
|
+
renderWorld(world, runtime);
|
|
591
|
+
assert.equal(world.sky.textures.get(2).texture, held, 'same art object keeps its texture even while unready');
|
|
592
|
+
late.ready = true;
|
|
593
|
+
renderWorld(world, runtime);
|
|
594
|
+
assert.equal(world.sky.textures.get(2).texture, held);
|
|
595
|
+
assert.equal(disposed, 0);
|
|
596
|
+
for (const { texture } of world.uploads) {
|
|
597
|
+
assert.ok(Object.values(runtime.sprites).some((art) => art.image === texture.image));
|
|
598
|
+
assert.equal(texture.flipY, true);
|
|
599
|
+
}
|
|
600
|
+
renderWorld(world, runtime);
|
|
601
|
+
assert.equal(world.uploads.length, 3);
|
|
602
|
+
} finally {
|
|
603
|
+
if (original !== undefined) globalThis.createImageBitmap = original;
|
|
604
|
+
}
|
|
605
|
+
},
|
|
606
|
+
|
|
607
|
+
async 'preload: later-ready inactive art starts decoding and uploads on the next frame after decode'() {
|
|
608
|
+
await withBitmaps(async (pending) => {
|
|
609
|
+
const world = preloadWorld();
|
|
610
|
+
const late = image(ZONES[2].art, { ready: false });
|
|
611
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: -20 } });
|
|
612
|
+
runtime.sprites[ZONES[2].art] = late;
|
|
613
|
+
renderWorld(world, runtime);
|
|
614
|
+
assert.equal(pending.length, 2);
|
|
615
|
+
late.ready = true;
|
|
616
|
+
renderWorld(world, runtime);
|
|
617
|
+
assert.equal(pending.length, 3, 'starts on the first ready frame');
|
|
618
|
+
assert.equal(world.uploads.length, 0, 'pending inactive art waits for decode');
|
|
619
|
+
pending[2].resolve();
|
|
620
|
+
await Promise.resolve();
|
|
621
|
+
renderWorld(world, runtime);
|
|
622
|
+
assert.equal(world.uploads.length, 1);
|
|
623
|
+
assert.equal(world.uploads[0].image, pending[2].bitmap);
|
|
624
|
+
disposeWorld(world);
|
|
625
|
+
pending.slice(0, 2).forEach((decode) => decode.resolve());
|
|
626
|
+
await Promise.resolve();
|
|
627
|
+
assert.ok(pending.every(({ bitmap }) => bitmap.closed === 1));
|
|
628
|
+
});
|
|
629
|
+
},
|
|
630
|
+
|
|
631
|
+
'preload: a renderer without initTexture draws using the ordinary image path'() {
|
|
632
|
+
const world = skyWorld();
|
|
633
|
+
const runtime = runtimeWith(good());
|
|
634
|
+
renderWorld(world, runtime);
|
|
635
|
+
assert.equal(uniformsOf(world).hasFrom.value, 1);
|
|
636
|
+
assert.equal(uniformsOf(world).mapFrom.value.image, runtime.sprites[ZONES[0].art].image);
|
|
637
|
+
runtime.moveTo(-18, 0);
|
|
638
|
+
renderWorld(world, runtime);
|
|
639
|
+
assert.equal(uniformsOf(world).mapFrom.value.image, runtime.sprites[ZONES[1].art].image);
|
|
640
|
+
},
|
|
641
|
+
|
|
642
|
+
async 'preload: without engine.sky, no decoding, warmup, sky fields or extra draws'() {
|
|
643
|
+
await withBitmaps(async (pending) => {
|
|
644
|
+
const world = preloadWorld();
|
|
645
|
+
delete world.sky;
|
|
646
|
+
Object.defineProperty(world.renderer, 'initTexture', { get() { throw new Error('keyless frame read initTexture'); } });
|
|
647
|
+
const runtime = runtimeWith(undefined);
|
|
648
|
+
Object.defineProperty(runtime, 'sprites', { get() { throw new Error('keyless frame read sprites'); } });
|
|
649
|
+
renderWorld(world, runtime);
|
|
650
|
+
assert.equal(pending.length, 0);
|
|
651
|
+
assert.equal(world.draws.length, 1);
|
|
652
|
+
assert.equal(world.draws[0].sky, 0);
|
|
653
|
+
assert.equal(Object.keys(world).filter((key) => key.startsWith('sky')).length, 0);
|
|
654
|
+
assert.equal(world.renderer.domElement._listeners, undefined, 'no restore listener without the sky key');
|
|
655
|
+
});
|
|
656
|
+
},
|
|
657
|
+
|
|
658
|
+
'the key: absent is null, with no warning and nothing read but the key'() {
|
|
659
|
+
let warned = 0;
|
|
660
|
+
const warn = () => {
|
|
661
|
+
warned += 1;
|
|
662
|
+
};
|
|
663
|
+
for (const data of [undefined, null, {}, { engine: {} }, { engine: null }, { engine: { shadows: { distance: 40 } } }]) {
|
|
664
|
+
assert.equal(readSkyKey(data, warn), null);
|
|
665
|
+
}
|
|
666
|
+
assert.equal(warned, 0);
|
|
667
|
+
// Only `engine` and its `sky` are read of a scene without the key.
|
|
668
|
+
const read = [];
|
|
669
|
+
const watched = (target, name) => new Proxy(target, { get: (t, k) => (read.push(`${name}.${String(k)}`), t[k]) });
|
|
670
|
+
assert.equal(readSkyKey(watched({ engine: watched({}, 'engine'), actors: [] }, 'data'), warn), null);
|
|
671
|
+
assert.deepEqual(read, ['data.engine', 'engine.sky']);
|
|
672
|
+
},
|
|
673
|
+
|
|
674
|
+
'the key: a good one is read with its defaults, and is not the scene\'s own object'() {
|
|
675
|
+
const data = sceneWith(good());
|
|
676
|
+
const key = readSkyKey(data, quiet);
|
|
677
|
+
assert.equal(key.fade, SKY_FADE);
|
|
678
|
+
assert.equal(key.edge, SKY_EDGE);
|
|
679
|
+
assert.equal(key.below, SKY_BELOW);
|
|
680
|
+
assert.equal(key.home, 0);
|
|
681
|
+
assert.deepEqual(key.zones.map((z) => z.id), ['square', 'hollow', 'sunny', 'stadium']);
|
|
682
|
+
assert.equal(key.zones[3].art, null);
|
|
683
|
+
assert.deepEqual([...key.zones[1].box], [-95, -17, -17, 17]);
|
|
684
|
+
data.engine.sky.zones[1].box[0] = 0;
|
|
685
|
+
data.engine.sky.zones[1].id = 'changed';
|
|
686
|
+
assert.equal(key.zones[1].box[0], -95);
|
|
687
|
+
assert.equal(key.zones[1].id, 'hollow');
|
|
688
|
+
assert.ok(Object.isFrozen(key) && Object.isFrozen(key.zones) && Object.isFrozen(key.zones[1]) && Object.isFrozen(key.zone));
|
|
689
|
+
const tuned = readSkyKey(sceneWith(good({ fade: 2, edge: 0, below: 0 })), quiet);
|
|
690
|
+
assert.deepEqual([tuned.fade, tuned.edge, tuned.below], [2, 0, 0]);
|
|
691
|
+
assert.equal(readSkyKey(sceneWith({ zones: [{ id: 'a', color: '#ABCDEF' }] }), quiet).zones[0].color, '#abcdef');
|
|
692
|
+
},
|
|
693
|
+
|
|
694
|
+
'the key: anything malformed is no key, with one warning'() {
|
|
695
|
+
const zone = (fields) => good({ zones: [{ id: 'home', color: '#112233' }, { id: 'a', color: '#445566', box: [0, 0, 1, 1], ...fields }] });
|
|
696
|
+
const bad = {
|
|
697
|
+
'not an object': 'sky',
|
|
698
|
+
'an array': [],
|
|
699
|
+
null: null,
|
|
700
|
+
'an unknown key': good({ fog: { color: '#ffffff' } }),
|
|
701
|
+
'no zones': {},
|
|
702
|
+
'zones not a list': { zones: {} },
|
|
703
|
+
'no zone': { zones: [] },
|
|
704
|
+
'too many zones': { zones: [{ id: 'home', color: '#000000' }, ...Array.from({ length: 16 }, (_, i) => ({ id: `z${i}`, color: '#000000', box: [0, 0, 1, 1] }))] },
|
|
705
|
+
'fade 0': good({ fade: 0 }),
|
|
706
|
+
'fade negative': good({ fade: -1 }),
|
|
707
|
+
'fade too long': good({ fade: 11 }),
|
|
708
|
+
'fade a string': good({ fade: '1.5' }),
|
|
709
|
+
'fade NaN': good({ fade: NaN }),
|
|
710
|
+
'edge negative': good({ edge: -0.1 }),
|
|
711
|
+
'edge too far': good({ edge: 10.5 }),
|
|
712
|
+
'below negative': good({ below: -1 }),
|
|
713
|
+
'below too low': good({ below: 46 }),
|
|
714
|
+
'a zone that is not an object': { zones: ['square'] },
|
|
715
|
+
'a zone with an unknown key': zone({ ambient: '#ffffff' }),
|
|
716
|
+
'no id': zone({ id: undefined }),
|
|
717
|
+
'an empty id': zone({ id: '' }),
|
|
718
|
+
'an id that is not a string': zone({ id: 3 }),
|
|
719
|
+
'two zones with one id': zone({ id: 'home' }),
|
|
720
|
+
'no colour': zone({ color: undefined }),
|
|
721
|
+
'a short colour': zone({ color: '#fff' }),
|
|
722
|
+
'a named colour': zone({ color: 'skyblue' }),
|
|
723
|
+
'a colour that is a number': zone({ color: 0xffffff }),
|
|
724
|
+
'an empty art': zone({ art: '' }),
|
|
725
|
+
'an art that is not a string': zone({ art: 4 }),
|
|
726
|
+
'a box of three': zone({ box: [0, 0, 1] }),
|
|
727
|
+
'a box of five': zone({ box: [0, 0, 1, 1, 1] }),
|
|
728
|
+
'a box with a string': zone({ box: [0, 0, '1', 1] }),
|
|
729
|
+
'a box with Infinity': zone({ box: [0, 0, Infinity, 1] }),
|
|
730
|
+
'a box the wrong way round': zone({ box: [1, 0, 0, 1] }),
|
|
731
|
+
'a box with no depth': zone({ box: [0, 1, 1, 1] }),
|
|
732
|
+
'a box that is an object': zone({ box: { x0: 0 } }),
|
|
733
|
+
'no zone without a box': { zones: [{ id: 'a', color: '#000000', box: [0, 0, 1, 1] }] },
|
|
734
|
+
'two zones without a box': { zones: [{ id: 'a', color: '#000000' }, { id: 'b', color: '#000000' }] },
|
|
735
|
+
};
|
|
736
|
+
for (const [name, sky] of Object.entries(bad)) {
|
|
737
|
+
const warnings = [];
|
|
738
|
+
assert.equal(readSkyKey(sceneWith(sky), (message) => warnings.push(message)), null, name);
|
|
739
|
+
assert.equal(warnings.length, 1, `${name}: one warning`);
|
|
740
|
+
assert.match(warnings[0], /^engine\.sky is ignored: /, name);
|
|
741
|
+
}
|
|
742
|
+
},
|
|
743
|
+
|
|
744
|
+
'which zone: in at the edge, out `edge` past it, first listed, the open zone otherwise'() {
|
|
745
|
+
const key = readSkyKey(sceneWith(good()), quiet);
|
|
746
|
+
const [square, hollow, sunny, stadium] = [0, 1, 2, 3];
|
|
747
|
+
assert.equal(zoneAt(key, 0, 0), square);
|
|
748
|
+
assert.equal(zoneAt(key, -17, 0), hollow, 'on the line is in');
|
|
749
|
+
assert.equal(zoneAt(key, -16.99, 0), square, 'short of the line is out, coming from outside');
|
|
750
|
+
assert.equal(zoneAt(key, -16.99, 0, hollow), hollow, 'and still in, coming from inside');
|
|
751
|
+
assert.equal(zoneAt(key, -17 + SKY_EDGE, 0, hollow), hollow, '`edge` past the line is still in');
|
|
752
|
+
assert.equal(zoneAt(key, -17 + SKY_EDGE + 0.01, 0, hollow), square, 'further is out');
|
|
753
|
+
assert.equal(zoneAt(key, -17, -17, hollow), hollow, 'the corner two boxes share: the one the player was in');
|
|
754
|
+
assert.equal(zoneAt(key, -17, -17, stadium), stadium);
|
|
755
|
+
assert.equal(zoneAt(key, -17, -17), hollow, 'and from neither, the first listed');
|
|
756
|
+
assert.equal(zoneAt(key, 50, 0, hollow), sunny, 'a jump into another box');
|
|
757
|
+
assert.equal(zoneAt(key, NaN, 0, hollow), square);
|
|
758
|
+
assert.equal(zoneAt(key, 0, Infinity), square);
|
|
759
|
+
const tight = readSkyKey(sceneWith(good({ edge: 0 })), quiet);
|
|
760
|
+
assert.equal(zoneAt(tight, -16.99, 0, hollow), square, 'no edge: out at the line');
|
|
761
|
+
},
|
|
762
|
+
|
|
763
|
+
'the fade: its length, backwards on turning back, a third zone after the one under way'() {
|
|
764
|
+
const fade = { from: 0, to: 0, mix: 0, next: -1 };
|
|
765
|
+
stepFade(fade, 0, 0.1, 1.5);
|
|
766
|
+
assert.deepEqual(fade, { from: 0, to: 0, mix: 0, next: -1 }, 'at rest');
|
|
767
|
+
stepFade(fade, 1, 0.3, 1.5);
|
|
768
|
+
near(fade.mix, 0.2, 'a fifth of the way after a fifth of the time');
|
|
769
|
+
assert.deepEqual([fade.from, fade.to], [0, 1]);
|
|
770
|
+
for (let i = 0; i < 3; i++) stepFade(fade, 1, 0.3, 1.5);
|
|
771
|
+
near(fade.mix, 0.8, 'four fifths');
|
|
772
|
+
stepFade(fade, 1, 0.3, 1.5);
|
|
773
|
+
assert.deepEqual(fade, { from: 1, to: 1, mix: 0, next: -1 }, 'done in 1.5 s: at rest in the new zone');
|
|
774
|
+
|
|
775
|
+
// Turned back at 40%: 60% of the way from 1 to 0, and done 0.6 s later.
|
|
776
|
+
stepFade(fade, 0, 0.6, 1.5);
|
|
777
|
+
near(fade.mix, 0.4, '40%');
|
|
778
|
+
stepFade(fade, 1, 0, 1.5);
|
|
779
|
+
assert.deepEqual([fade.from, fade.to], [0, 1]);
|
|
780
|
+
near(fade.mix, 0.6, 'the same picture, read the other way');
|
|
781
|
+
stepFade(fade, 1, 0.3, 1.5);
|
|
782
|
+
near(fade.mix, 0.8, 'and on from there');
|
|
783
|
+
stepFade(fade, 1, 0.3, 1.5);
|
|
784
|
+
assert.deepEqual(fade, { from: 1, to: 1, mix: 0, next: -1 });
|
|
785
|
+
|
|
786
|
+
// A third zone mid-fade waits; the fade under way ends, then the next.
|
|
787
|
+
stepFade(fade, 2, 0.75, 1.5);
|
|
788
|
+
stepFade(fade, 3, 0.3, 1.5);
|
|
789
|
+
assert.deepEqual([fade.from, fade.to, fade.next], [1, 2, 3]);
|
|
790
|
+
near(fade.mix, 0.7, 'the fade under way goes on');
|
|
791
|
+
stepFade(fade, 3, 0.6, 1.5);
|
|
792
|
+
assert.deepEqual([fade.from, fade.to, fade.next], [2, 3, -1], 'then the next starts');
|
|
793
|
+
assert.ok(fade.mix > 0 && fade.mix < 1e-6);
|
|
794
|
+
// Back in the zone the fade is going to: nothing waits any more.
|
|
795
|
+
Object.assign(fade, { from: 1, to: 2, mix: 0.5, next: 3 });
|
|
796
|
+
stepFade(fade, 2, 0.1, 1.5);
|
|
797
|
+
assert.equal(fade.next, -1);
|
|
798
|
+
// A wait for the zone the fade is leaving is a turn back.
|
|
799
|
+
Object.assign(fade, { from: 1, to: 2, mix: 0.5, next: 3 });
|
|
800
|
+
stepFade(fade, 1, 0, 1.5);
|
|
801
|
+
assert.deepEqual([fade.from, fade.to, fade.next], [2, 1, -1]);
|
|
802
|
+
},
|
|
803
|
+
|
|
804
|
+
'without the key: the frame it was, and nothing on the world'() {
|
|
805
|
+
const world = skyWorld();
|
|
806
|
+
delete world.sky;
|
|
807
|
+
const before = [...world.scene.children];
|
|
808
|
+
const added = [];
|
|
809
|
+
world.scene.addEventListener('childadded', (event) => added.push(event.child));
|
|
810
|
+
for (const runtime of [runtimeWith(undefined), { data: {} }, undefined, runtimeWith('malformed')]) {
|
|
811
|
+
renderWorld(world, runtime);
|
|
812
|
+
assert.ok(!world.sky, 'nothing of the mode\'s');
|
|
813
|
+
assert.equal(runtime?.skyZone ?? null, null);
|
|
814
|
+
}
|
|
815
|
+
assert.equal(world.draws.length, 4, 'one draw a frame');
|
|
816
|
+
assert.ok(world.draws.every((draw) => draw.sky === 0 && draw.children === before.length));
|
|
817
|
+
assert.deepEqual(world.scene.children, before);
|
|
818
|
+
assert.equal(added.length, 0, 'nothing was ever added to the scene');
|
|
819
|
+
assert.ok(!('sky' in world), 'not even the field, on a world made without it');
|
|
820
|
+
},
|
|
821
|
+
|
|
822
|
+
'with the key: in the scene graph for the draw and at no other time'() {
|
|
823
|
+
const world = skyWorld();
|
|
824
|
+
const runtime = runtimeWith(good());
|
|
825
|
+
const children = world.scene.children.length;
|
|
826
|
+
for (let i = 0; i < 3; i++) {
|
|
827
|
+
renderWorld(world, runtime);
|
|
828
|
+
tick(1 / 60);
|
|
829
|
+
assert.equal(world.scene.children.length, children, 'out again after the frame');
|
|
830
|
+
assert.equal(world.sky.mesh.parent, null);
|
|
831
|
+
}
|
|
832
|
+
assert.ok(world.draws.every((draw) => draw.sky === 1 && draw.children === children + 1));
|
|
833
|
+
const mesh = world.sky.mesh;
|
|
834
|
+
assert.ok(world.draws.every((draw) => draw.mesh === mesh), 'one mesh, kept');
|
|
835
|
+
assert.equal(mesh.castShadow, false, 'not in any shadow pass');
|
|
836
|
+
assert.equal(mesh.receiveShadow, false);
|
|
837
|
+
assert.equal(mesh.frustumCulled, false);
|
|
838
|
+
assert.equal(mesh.userData.actorId, undefined, 'not an actor');
|
|
839
|
+
assert.equal(world.nodes.size, 0, 'no node');
|
|
840
|
+
assert.equal(mesh.renderOrder, Number.MAX_SAFE_INTEGER, 'after every opaque thing');
|
|
841
|
+
const material = mesh.material;
|
|
842
|
+
assert.equal(material.depthWrite, false);
|
|
843
|
+
assert.equal(material.depthTest, true);
|
|
844
|
+
assert.equal(material.transparent, false);
|
|
845
|
+
assert.equal(material.fog, false);
|
|
846
|
+
assert.equal(material.lights, false, 'unlit');
|
|
847
|
+
assert.equal(material.toneMapped, false);
|
|
848
|
+
assert.match(material.vertexShader, /gl_Position = clip\.xyww/, 'on the far plane');
|
|
849
|
+
assert.match(material.vertexShader, /mat3\(viewMatrix\) \* position/, 'turned with the camera, never moved');
|
|
850
|
+
},
|
|
851
|
+
|
|
852
|
+
'the dome: every direction, the picture laid as the terms say'() {
|
|
853
|
+
const world = skyWorld();
|
|
854
|
+
renderWorld(world, runtimeWith(good({ below: 8 })));
|
|
855
|
+
const geometry = world.sky.mesh.geometry;
|
|
856
|
+
const position = geometry.getAttribute('position');
|
|
857
|
+
const uv = geometry.getAttribute('uv');
|
|
858
|
+
const at = (bearing, up) => {
|
|
859
|
+
let best = -1;
|
|
860
|
+
let score = Infinity;
|
|
861
|
+
const b = (bearing * Math.PI) / 180;
|
|
862
|
+
const e = (up * Math.PI) / 180;
|
|
863
|
+
const want = new THREE.Vector3(Math.sin(b) * Math.cos(e), Math.sin(e), -Math.cos(b) * Math.cos(e));
|
|
864
|
+
const v = new THREE.Vector3();
|
|
865
|
+
for (let i = 0; i < position.count; i++) {
|
|
866
|
+
const d = v.fromBufferAttribute(position, i).normalize().distanceTo(want);
|
|
867
|
+
if (d < score) [best, score] = [i, d];
|
|
868
|
+
}
|
|
869
|
+
assert.ok(score < 1e-6, `a vertex toward ${bearing}, ${up} up`);
|
|
870
|
+
return [uv.getX(best), uv.getY(best)];
|
|
871
|
+
};
|
|
872
|
+
const same = ([u, v], [wantU, wantV], what) => assert.ok(Math.abs(u - wantU) < 1e-6 && Math.abs(v - wantV) < 1e-6, `${what}: ${u}, ${v}`);
|
|
873
|
+
same(at(0, 0), [0, 8 / 98], 'north on the horizon: the left edge');
|
|
874
|
+
same(at(90, 0), [0.25, 8 / 98], 'east: a quarter along');
|
|
875
|
+
same(at(180, 50), [0.5, 58 / 98], 'south, 50 up');
|
|
876
|
+
same(at(270, -8), [0.75, 0], 'west, `below` under the horizon: the last row');
|
|
877
|
+
assert.equal(at(45, 90)[1], 1, 'overhead: the first row');
|
|
878
|
+
assert.equal(at(45, -90)[1], 0, 'straight down: the last row again');
|
|
879
|
+
// Closed: every edge is shared by two triangles, but the seam's and the poles'.
|
|
880
|
+
const index = geometry.getIndex();
|
|
881
|
+
const corners = new Map();
|
|
882
|
+
const v = new THREE.Vector3();
|
|
883
|
+
const keyOf = (i) => {
|
|
884
|
+
v.fromBufferAttribute(position, i);
|
|
885
|
+
return [v.x, v.y, v.z].map((n) => Math.round(n * 1e4) + 0).join(',');
|
|
886
|
+
};
|
|
887
|
+
for (let t = 0; t < index.count; t += 3) {
|
|
888
|
+
for (let k = 0; k < 3; k++) {
|
|
889
|
+
const [a, b] = [keyOf(index.getX(t + k)), keyOf(index.getX(t + ((k + 1) % 3)))].sort();
|
|
890
|
+
if (a !== b) corners.set(`${a}|${b}`, (corners.get(`${a}|${b}`) ?? 0) + 1);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
assert.ok([...corners.values()].every((count) => count === 2), 'no direction is open');
|
|
894
|
+
assert.ok(index.count / 3 < 500, `${index.count / 3} triangles`);
|
|
895
|
+
// No ring at `below` when it is 0.
|
|
896
|
+
const flat = skyWorld();
|
|
897
|
+
renderWorld(flat, runtimeWith(good({ below: 0 })));
|
|
898
|
+
assert.ok(flat.sky.mesh.geometry.getIndex().count < index.count);
|
|
899
|
+
},
|
|
900
|
+
|
|
901
|
+
'a scene\'s first frame is its zone\'s sky, with no fade'() {
|
|
902
|
+
const world = skyWorld();
|
|
903
|
+
const runtime = runtimeWith(good(), { player: { x: -50, z: 0 } });
|
|
904
|
+
assert.deepEqual({ ...runtime.skyZone }, { id: 'square', blend: 0, from: 'square', to: 'square' }, 'the four fields and no more');
|
|
905
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.blend], ['square', 0], 'before a frame: the open zone');
|
|
906
|
+
renderWorld(world, runtime);
|
|
907
|
+
const u = uniformsOf(world);
|
|
908
|
+
assert.equal(u.blend.value, 0);
|
|
909
|
+
assert.equal(hex(u.colorFrom.value), '#3d3a5c');
|
|
910
|
+
assert.equal(u.hasFrom.value, 1);
|
|
911
|
+
assert.equal(u.mapFrom.value.image, runtime.sprites['drawings/sky-hollow.webp'].image);
|
|
912
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to, runtime.skyZone.blend], ['hollow', 'hollow', 'hollow', 0]);
|
|
913
|
+
},
|
|
914
|
+
|
|
915
|
+
'walking across a line: 1.5 s by the clock, and `skyZone` says so'() {
|
|
916
|
+
const world = skyWorld();
|
|
917
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
918
|
+
renderWorld(world, runtime);
|
|
919
|
+
assert.equal(runtime.skyZone.id, 'square');
|
|
920
|
+
const zone = runtime.skyZone;
|
|
921
|
+
runtime.moveTo(-17.2, 0);
|
|
922
|
+
const seen = [];
|
|
923
|
+
for (let i = 0; i < 20; i++) {
|
|
924
|
+
tick(0.1);
|
|
925
|
+
renderWorld(world, runtime);
|
|
926
|
+
seen.push([zone.id, zone.from, zone.to, +zone.blend.toFixed(6), +uniformsOf(world).blend.value.toFixed(6)]);
|
|
927
|
+
}
|
|
928
|
+
assert.equal(runtime.skyZone, zone, 'the same object from a load to the next');
|
|
929
|
+
assert.deepEqual(seen[0], ['hollow', 'square', 'hollow', 0.066667, 0.066667]);
|
|
930
|
+
assert.deepEqual(seen[6], ['hollow', 'square', 'hollow', 0.466667, 0.466667]);
|
|
931
|
+
assert.deepEqual(seen[13], ['hollow', 'square', 'hollow', 0.933333, 0.933333]);
|
|
932
|
+
assert.deepEqual(seen[14], ['hollow', 'hollow', 'hollow', 0, 0], 'at rest after 1.5 s');
|
|
933
|
+
assert.deepEqual(seen[19], ['hollow', 'hollow', 'hollow', 0, 0]);
|
|
934
|
+
const u = uniformsOf(world);
|
|
935
|
+
assert.equal(u.mapFrom.value.image, runtime.sprites['drawings/sky-hollow.webp'].image, 'one picture at rest');
|
|
936
|
+
assert.equal(world.sky.textures.size, 3, 'all ready zones stay cached across a fade');
|
|
937
|
+
// A long gap between two frames moves the fade no more than FRAME_MOST_S.
|
|
938
|
+
runtime.moveTo(-10, 0);
|
|
939
|
+
tick(30);
|
|
940
|
+
renderWorld(world, runtime);
|
|
941
|
+
near(zone.blend, FRAME_MOST_S / 1.5, 'a stalled frame');
|
|
942
|
+
// Pacing on the line: no change inside the edge.
|
|
943
|
+
const paced = skyWorld();
|
|
944
|
+
const pacer = runtimeWith(good(), { player: { x: -20, z: 0 } });
|
|
945
|
+
renderWorld(paced, pacer);
|
|
946
|
+
for (const x of [-17.1, -16.9, -16.5, -16.3, -16.9, -17.4, -16.26]) {
|
|
947
|
+
pacer.moveTo(x, 0);
|
|
948
|
+
tick(0.05);
|
|
949
|
+
renderWorld(paced, pacer);
|
|
950
|
+
assert.deepEqual([pacer.skyZone.id, pacer.skyZone.blend], ['hollow', 0], `at ${x}`);
|
|
951
|
+
}
|
|
952
|
+
pacer.moveTo(-16.2, 0);
|
|
953
|
+
tick(0.05);
|
|
954
|
+
renderWorld(paced, pacer);
|
|
955
|
+
assert.equal(pacer.skyZone.id, 'square');
|
|
956
|
+
assert.ok(pacer.skyZone.blend > 0);
|
|
957
|
+
},
|
|
958
|
+
|
|
959
|
+
'turning back, and a third zone, through the frames'() {
|
|
960
|
+
const world = skyWorld();
|
|
961
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
962
|
+
renderWorld(world, runtime);
|
|
963
|
+
runtime.moveTo(-18, 0);
|
|
964
|
+
for (let i = 0; i < 6; i++) {
|
|
965
|
+
tick(0.1);
|
|
966
|
+
renderWorld(world, runtime);
|
|
967
|
+
}
|
|
968
|
+
near(runtime.skyZone.blend, 0.4, '40% into Hollow End');
|
|
969
|
+
runtime.moveTo(-15, 0);
|
|
970
|
+
tick(0.1);
|
|
971
|
+
renderWorld(world, runtime);
|
|
972
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to], ['square', 'hollow', 'square']);
|
|
973
|
+
near(runtime.skyZone.blend, 0.6 + 0.1 / 1.5, 'backwards from where it was');
|
|
974
|
+
// Mid-fade, the player is put in a third zone a step away (the corner).
|
|
975
|
+
const corner = skyWorld();
|
|
976
|
+
const walker = runtimeWith(good(), { player: { x: -16, z: -16 } });
|
|
977
|
+
renderWorld(corner, walker);
|
|
978
|
+
walker.moveTo(-17.5, -16);
|
|
979
|
+
tick(0.5);
|
|
980
|
+
renderWorld(corner, walker);
|
|
981
|
+
walker.moveTo(-16, -17.9);
|
|
982
|
+
tick(0.1);
|
|
983
|
+
renderWorld(corner, walker);
|
|
984
|
+
assert.deepEqual([walker.skyZone.id, walker.skyZone.from, walker.skyZone.to], ['stadium', 'square', 'hollow'], 'the fade under way goes on');
|
|
985
|
+
// The rest of the first fade (0.35 s of it are done: the half-second
|
|
986
|
+
// frame counted as FRAME_MOST_S), then all of the second (1.5 s).
|
|
987
|
+
for (let i = 0; i < 12; i++) {
|
|
988
|
+
tick(0.1);
|
|
989
|
+
renderWorld(corner, walker);
|
|
990
|
+
}
|
|
991
|
+
assert.deepEqual([walker.skyZone.id, walker.skyZone.from, walker.skyZone.to], ['stadium', 'hollow', 'stadium']);
|
|
992
|
+
for (let i = 0; i < 16; i++) {
|
|
993
|
+
tick(0.1);
|
|
994
|
+
renderWorld(corner, walker);
|
|
995
|
+
}
|
|
996
|
+
assert.deepEqual([walker.skyZone.id, walker.skyZone.from, walker.skyZone.to, walker.skyZone.blend], ['stadium', 'stadium', 'stadium', 0]);
|
|
997
|
+
},
|
|
998
|
+
|
|
999
|
+
'somewhere else at once: the sky is that zone\'s, with no fade'() {
|
|
1000
|
+
const world = skyWorld();
|
|
1001
|
+
const runtime = runtimeWith(good(), { player: { x: 0, z: 0 } });
|
|
1002
|
+
renderWorld(world, runtime);
|
|
1003
|
+
runtime.moveTo(0 - SNAP_M - 20, 0);
|
|
1004
|
+
tick(1 / 60);
|
|
1005
|
+
renderWorld(world, runtime);
|
|
1006
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to, runtime.skyZone.blend], ['hollow', 'hollow', 'hollow', 0]);
|
|
1007
|
+
// A step of just under SNAP_M is a walk: it fades.
|
|
1008
|
+
runtime.moveTo(-17.5, 0);
|
|
1009
|
+
tick(1 / 60);
|
|
1010
|
+
renderWorld(world, runtime);
|
|
1011
|
+
runtime.moveTo(-17.5 + SNAP_M - 0.1, 0);
|
|
1012
|
+
tick(1 / 60);
|
|
1013
|
+
renderWorld(world, runtime);
|
|
1014
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to], ['square', 'hollow', 'square']);
|
|
1015
|
+
assert.ok(runtime.skyZone.blend > 0);
|
|
1016
|
+
// Mid-fade, a put elsewhere: no fade is left.
|
|
1017
|
+
runtime.moveTo(60, 0);
|
|
1018
|
+
tick(1 / 60);
|
|
1019
|
+
renderWorld(world, runtime);
|
|
1020
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to, runtime.skyZone.blend], ['sunny', 'sunny', 'sunny', 0]);
|
|
1021
|
+
},
|
|
1022
|
+
|
|
1023
|
+
'no player: the open zone; the camera is never asked'() {
|
|
1024
|
+
const world = skyWorld();
|
|
1025
|
+
world.camera.position.set(-60, 5, 0);
|
|
1026
|
+
const runtime = runtimeWith(good(), { player: null });
|
|
1027
|
+
renderWorld(world, runtime);
|
|
1028
|
+
assert.equal(runtime.skyZone.id, 'square');
|
|
1029
|
+
const there = runtimeWith(good(), { player: { x: 0, z: 0 } });
|
|
1030
|
+
const other = skyWorld();
|
|
1031
|
+
other.camera.position.set(-60, 5, 0);
|
|
1032
|
+
renderWorld(other, there);
|
|
1033
|
+
assert.equal(there.skyZone.id, 'square', 'the player\'s zone, though the camera is over Hollow End');
|
|
1034
|
+
// A Player whose Transform is not numbers.
|
|
1035
|
+
there.player.components.Transform.x = undefined;
|
|
1036
|
+
tick(0.1);
|
|
1037
|
+
renderWorld(other, there);
|
|
1038
|
+
assert.equal(there.skyZone.id, 'square');
|
|
1039
|
+
},
|
|
1040
|
+
|
|
1041
|
+
'pictures: retained per ready zone, the flat colour for what is not a ready image'() {
|
|
1042
|
+
const sprites = allArt();
|
|
1043
|
+
const made = [];
|
|
1044
|
+
const world = skyWorld();
|
|
1045
|
+
const runtime = runtimeWith(good(), { sprites, player: { x: -16, z: 0 } });
|
|
1046
|
+
renderWorld(world, runtime);
|
|
1047
|
+
assert.deepEqual([...world.sky.textures.keys()], [0, 1, 2], 'all zones with ready art');
|
|
1048
|
+
const first = world.sky.textures.get(0).texture;
|
|
1049
|
+
assert.ok(first.isTexture && first.image === sprites['drawings/sky-square.webp'].image);
|
|
1050
|
+
assert.equal(first.colorSpace, THREE.SRGBColorSpace);
|
|
1051
|
+
assert.equal(first.wrapS, THREE.RepeatWrapping);
|
|
1052
|
+
assert.equal(first.wrapT, THREE.ClampToEdgeWrapping);
|
|
1053
|
+
assert.equal(first.minFilter, THREE.LinearFilter);
|
|
1054
|
+
assert.equal(first.magFilter, THREE.LinearFilter);
|
|
1055
|
+
assert.equal(first.generateMipmaps, false);
|
|
1056
|
+
first.addEventListener('dispose', () => made.push('square gone'));
|
|
1057
|
+
tick(0.1);
|
|
1058
|
+
renderWorld(world, runtime);
|
|
1059
|
+
assert.equal(world.sky.textures.get(0).texture, first, 'kept from frame to frame');
|
|
1060
|
+
// Into Hollow End: the same cache during and after the fade.
|
|
1061
|
+
runtime.moveTo(-18, 0);
|
|
1062
|
+
tick(0.1);
|
|
1063
|
+
renderWorld(world, runtime);
|
|
1064
|
+
assert.deepEqual([...world.sky.textures.keys()].sort(), [0, 1, 2]);
|
|
1065
|
+
assert.deepEqual([uniformsOf(world).hasFrom.value, uniformsOf(world).hasTo.value], [1, 1]);
|
|
1066
|
+
for (let i = 0; i < 20; i++) {
|
|
1067
|
+
tick(0.1);
|
|
1068
|
+
renderWorld(world, runtime);
|
|
1069
|
+
}
|
|
1070
|
+
assert.deepEqual([...world.sky.textures.keys()], [0, 1, 2]);
|
|
1071
|
+
assert.deepEqual(made, []);
|
|
1072
|
+
|
|
1073
|
+
// The Stadium has no art: its colour.
|
|
1074
|
+
runtime.moveTo(0, -60);
|
|
1075
|
+
tick(0.1);
|
|
1076
|
+
renderWorld(world, runtime);
|
|
1077
|
+
assert.equal(runtime.skyZone.id, 'stadium');
|
|
1078
|
+
assert.equal(uniformsOf(world).hasFrom.value, 0);
|
|
1079
|
+
assert.equal(uniformsOf(world).mapFrom.value, null);
|
|
1080
|
+
assert.equal(hex(uniformsOf(world).colorFrom.value), '#bfe3f2');
|
|
1081
|
+
assert.equal(world.sky.textures.size, 3);
|
|
1082
|
+
|
|
1083
|
+
// Not arrived, failed, missing from the deck, a sprite: the colour.
|
|
1084
|
+
const cases = {
|
|
1085
|
+
'not arrived': image('drawings/sky-hollow.webp', { ready: false }),
|
|
1086
|
+
failed: image('drawings/sky-hollow.webp', { ready: false, failed: true }),
|
|
1087
|
+
'failed after arriving': image('drawings/sky-hollow.webp', { failed: true }),
|
|
1088
|
+
missing: undefined,
|
|
1089
|
+
'a sprite': { resolution: { width: 8, height: 8 }, frames: [{}], layers: [] },
|
|
1090
|
+
'no image': image('drawings/sky-hollow.webp', { image: null }),
|
|
1091
|
+
};
|
|
1092
|
+
for (const [name, art] of Object.entries(cases)) {
|
|
1093
|
+
const w = skyWorld();
|
|
1094
|
+
const r = runtimeWith(good(), { sprites: { 'drawings/sky-hollow.webp': art }, player: { x: -50, z: 0 } });
|
|
1095
|
+
renderWorld(w, r);
|
|
1096
|
+
assert.equal(uniformsOf(w).hasFrom.value, 0, name);
|
|
1097
|
+
assert.equal(hex(uniformsOf(w).colorFrom.value), '#3d3a5c', name);
|
|
1098
|
+
assert.equal(w.sky.textures.size, 0, name);
|
|
1099
|
+
}
|
|
1100
|
+
// It arrives later: the picture from that frame on.
|
|
1101
|
+
const late = image('drawings/sky-hollow.webp', { ready: false });
|
|
1102
|
+
const w = skyWorld();
|
|
1103
|
+
const r = runtimeWith(good(), { sprites: { 'drawings/sky-hollow.webp': late }, player: { x: -50, z: 0 } });
|
|
1104
|
+
renderWorld(w, r);
|
|
1105
|
+
assert.equal(uniformsOf(w).hasFrom.value, 0);
|
|
1106
|
+
late.ready = true;
|
|
1107
|
+
renderWorld(w, r);
|
|
1108
|
+
assert.equal(uniformsOf(w).hasFrom.value, 1);
|
|
1109
|
+
assert.equal(uniformsOf(w).mapFrom.value.image, late.image);
|
|
1110
|
+
// The deck's art replaced (a repainted file is a new art object): a new texture, the old one let go.
|
|
1111
|
+
const old = uniformsOf(w).mapFrom.value;
|
|
1112
|
+
let gone = 0;
|
|
1113
|
+
old.addEventListener('dispose', () => (gone += 1));
|
|
1114
|
+
r.sprites['drawings/sky-hollow.webp'] = image('drawings/sky-hollow.webp', { image: { width: 512, height: 256 } });
|
|
1115
|
+
renderWorld(w, r);
|
|
1116
|
+
assert.notEqual(uniformsOf(w).mapFrom.value, old);
|
|
1117
|
+
assert.equal(gone, 1);
|
|
1118
|
+
},
|
|
1119
|
+
|
|
1120
|
+
'it dies with its scene: a load, a scene without the key, an editor\'s frame, a dispose'() {
|
|
1121
|
+
const disposed = (world) => {
|
|
1122
|
+
const sky = world.sky;
|
|
1123
|
+
const gone = { material: 0, geometry: 0, textures: 0 };
|
|
1124
|
+
sky.material.addEventListener('dispose', () => (gone.material += 1));
|
|
1125
|
+
sky.mesh.geometry.addEventListener('dispose', () => (gone.geometry += 1));
|
|
1126
|
+
for (const held of sky.textures.values()) held.texture.addEventListener('dispose', () => (gone.textures += 1));
|
|
1127
|
+
return gone;
|
|
1128
|
+
};
|
|
1129
|
+
for (const [name, leave] of Object.entries({
|
|
1130
|
+
'a scene without the key': (world) => renderWorld(world, runtimeWith(undefined)),
|
|
1131
|
+
'a scene with a malformed key': (world) => renderWorld(world, runtimeWith({ zones: [] })),
|
|
1132
|
+
'an editor\'s frame': (world) => renderWorld(world, undefined),
|
|
1133
|
+
dispose: (world) => disposeWorld(world),
|
|
1134
|
+
'a frame of a disposed world': (world) => {
|
|
1135
|
+
world.disposed = true;
|
|
1136
|
+
renderWorld(world, runtimeWith(good()));
|
|
1137
|
+
},
|
|
1138
|
+
})) {
|
|
1139
|
+
const world = skyWorld();
|
|
1140
|
+
const runtime = runtimeWith(good(), { player: { x: -18, z: 0 } });
|
|
1141
|
+
renderWorld(world, runtime);
|
|
1142
|
+
runtime.moveTo(-16, 0);
|
|
1143
|
+
tick(0.5);
|
|
1144
|
+
renderWorld(world, runtime);
|
|
1145
|
+
assert.equal(runtime.skyZone.from, 'hollow', name);
|
|
1146
|
+
const gone = disposed(world);
|
|
1147
|
+
leave(world);
|
|
1148
|
+
assert.equal(world.sky, null, name);
|
|
1149
|
+
assert.deepEqual(gone, { material: 1, geometry: 1, textures: 3 }, name);
|
|
1150
|
+
assert.ok(!world.scene.children.some((child) => child.name === 'engine.sky'), name);
|
|
1151
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.to, runtime.skyZone.blend], ['square', 'square', 'square', 0], `${name}: what the scene that left says`);
|
|
1152
|
+
}
|
|
1153
|
+
// The same scene loaded again (a new key object): from nothing, no fade.
|
|
1154
|
+
const world = skyWorld();
|
|
1155
|
+
const first = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1156
|
+
renderWorld(world, first);
|
|
1157
|
+
first.moveTo(-18, 0);
|
|
1158
|
+
tick(0.3);
|
|
1159
|
+
renderWorld(world, first);
|
|
1160
|
+
assert.ok(first.skyZone.blend > 0);
|
|
1161
|
+
const old = world.sky;
|
|
1162
|
+
const gone = disposed(world);
|
|
1163
|
+
const again = runtimeWith(good(), { player: { x: -18, z: 0 } });
|
|
1164
|
+
renderWorld(world, again);
|
|
1165
|
+
assert.notEqual(world.sky, old);
|
|
1166
|
+
assert.deepEqual(gone, { material: 1, geometry: 1, textures: 3 });
|
|
1167
|
+
assert.deepEqual([again.skyZone.id, again.skyZone.from, again.skyZone.blend], ['hollow', 'hollow', 0]);
|
|
1168
|
+
// After a dispose, a keyed frame makes nothing.
|
|
1169
|
+
disposeWorld(world);
|
|
1170
|
+
renderWorld(world, again);
|
|
1171
|
+
assert.equal(world.sky, null);
|
|
1172
|
+
assert.equal(leaveSky(world), null);
|
|
1173
|
+
assert.equal(leaveSky(undefined), null);
|
|
1174
|
+
},
|
|
1175
|
+
|
|
1176
|
+
'a frame that throws leaves nothing; the next starts from nothing'() {
|
|
1177
|
+
const world = skyWorld();
|
|
1178
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1179
|
+
renderWorld(world, runtime);
|
|
1180
|
+
runtime.moveTo(-18, 0);
|
|
1181
|
+
tick(0.3);
|
|
1182
|
+
renderWorld(world, runtime);
|
|
1183
|
+
const material = world.sky.material;
|
|
1184
|
+
let gone = 0;
|
|
1185
|
+
material.addEventListener('dispose', () => (gone += 1));
|
|
1186
|
+
world.onRender = () => {
|
|
1187
|
+
throw new Error('the composer failed');
|
|
1188
|
+
};
|
|
1189
|
+
assert.throws(() => renderWorld(world, runtime), /the composer failed/);
|
|
1190
|
+
assert.equal(world.sky, null);
|
|
1191
|
+
assert.equal(gone, 1);
|
|
1192
|
+
assert.ok(!world.scene.children.some((child) => child.name === 'engine.sky'));
|
|
1193
|
+
world.onRender = null;
|
|
1194
|
+
tick(0.1);
|
|
1195
|
+
renderWorld(world, runtime);
|
|
1196
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.blend], ['hollow', 'hollow', 0]);
|
|
1197
|
+
// A player whose Transform throws when read: the frame is drawn, with no
|
|
1198
|
+
// sky, and then throws; nothing is kept.
|
|
1199
|
+
const bad = runtimeWith(good());
|
|
1200
|
+
Object.defineProperty(bad.player.components, 'Transform', {
|
|
1201
|
+
get() {
|
|
1202
|
+
throw new Error('a getter');
|
|
1203
|
+
},
|
|
1204
|
+
});
|
|
1205
|
+
const w = skyWorld();
|
|
1206
|
+
assert.throws(() => renderWorld(w, bad), /a getter/);
|
|
1207
|
+
assert.equal(w.sky, null);
|
|
1208
|
+
assert.deepEqual(w.draws.map((draw) => draw.sky), [0]);
|
|
1209
|
+
assert.ok(!w.scene.children.some((child) => child.name === 'engine.sky'));
|
|
1210
|
+
},
|
|
1211
|
+
|
|
1212
|
+
'its life: every callback, returning, throwing and caught, throwing and not'() {
|
|
1213
|
+
// What a callback of the outer frame's draw does.
|
|
1214
|
+
const inside = {
|
|
1215
|
+
'a frame of the same runtime': ({ world, runtime }) => renderWorld(world, runtime),
|
|
1216
|
+
'a frame of another runtime with a key': ({ world, other }) => renderWorld(world, other),
|
|
1217
|
+
'a frame of a runtime without the key': ({ world }) => renderWorld(world, runtimeWith(undefined)),
|
|
1218
|
+
'a frame with no runtime (an editor\'s)': ({ world }) => renderWorld(world, undefined),
|
|
1219
|
+
'a load': ({ world, runtime }) => runtime.load(world, good({ fade: 3 })),
|
|
1220
|
+
'a load of a scene without the key': ({ world, runtime }) => runtime.load(world, undefined),
|
|
1221
|
+
'a dispose': ({ world }) => disposeWorld(world),
|
|
1222
|
+
};
|
|
1223
|
+
const draws = (name) => name.startsWith('a frame');
|
|
1224
|
+
for (const [name, act] of Object.entries(inside)) {
|
|
1225
|
+
for (const outcome of ['returns', 'throws and is caught', 'throws and is not caught']) {
|
|
1226
|
+
const what = `${name}, which ${outcome}`;
|
|
1227
|
+
const world = skyWorld();
|
|
1228
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1229
|
+
const other = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1230
|
+
renderWorld(world, runtime);
|
|
1231
|
+
// Mid-fade, so the record holds two textures.
|
|
1232
|
+
runtime.moveTo(-18, 0);
|
|
1233
|
+
tick(0.2);
|
|
1234
|
+
renderWorld(world, runtime);
|
|
1235
|
+
const first = world.sky;
|
|
1236
|
+
assert.equal(first.textures.size, 3, what);
|
|
1237
|
+
const during = {};
|
|
1238
|
+
world.onRender = (level) => {
|
|
1239
|
+
if (level === 1) {
|
|
1240
|
+
// The frame from inside: what it was drawn with.
|
|
1241
|
+
during.inner = world.draws.at(-1);
|
|
1242
|
+
if (outcome !== 'returns') throw new Error('the frame inside failed');
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
const run = () => {
|
|
1246
|
+
act({ world, runtime, other });
|
|
1247
|
+
if (!draws(name) && outcome !== 'returns') throw new Error('the callback failed');
|
|
1248
|
+
};
|
|
1249
|
+
if (outcome === 'throws and is caught') assert.throws(run, /failed/, what);
|
|
1250
|
+
else run();
|
|
1251
|
+
// Back in the outer frame: its dome is where it was, shown, and
|
|
1252
|
+
// nothing it is drawn from has been disposed.
|
|
1253
|
+
during.domes = domesIn(world);
|
|
1254
|
+
during.shown = first.mesh.visible;
|
|
1255
|
+
during.parent = first.mesh.parent;
|
|
1256
|
+
during.disposed = [...world.records.get(first).values()].reduce((sum, entry) => sum + entry.disposed, 0);
|
|
1257
|
+
during.record = world.sky;
|
|
1258
|
+
};
|
|
1259
|
+
tick(0.1);
|
|
1260
|
+
const frame = () => renderWorld(world, runtime);
|
|
1261
|
+
if (outcome === 'throws and is not caught') {
|
|
1262
|
+
assert.throws(frame, /failed/, what);
|
|
1263
|
+
// What threw, threw from inside the draw: the outer callback never came back.
|
|
1264
|
+
} else {
|
|
1265
|
+
frame();
|
|
1266
|
+
assert.deepEqual([during.domes, during.shown, during.parent, during.disposed, during.record], [1, true, world.scene, 0, first], `${what}: the outer frame's dome and resources are untouched while it draws`);
|
|
1267
|
+
}
|
|
1268
|
+
if (draws(name)) {
|
|
1269
|
+
const mine = name === 'a frame of the same runtime';
|
|
1270
|
+
assert.deepEqual([during.inner.sky, during.inner.shown], mine ? [1, true] : [1, false], `${what}: the frame inside is drawn ${mine ? 'with the dome as it is' : 'without a sky'}`);
|
|
1271
|
+
}
|
|
1272
|
+
// A frame from inside that returned changes nothing of the record: the
|
|
1273
|
+
// outer frame's runtime still has the key. Anything that threw, a
|
|
1274
|
+
// load and a dispose end it.
|
|
1275
|
+
const kept = draws(name) && outcome === 'returns';
|
|
1276
|
+
assert.equal(world.sky ?? null, kept ? first : null, `${what}: the record is ${kept ? 'kept' : 'gone'}`);
|
|
1277
|
+
assert.equal(world.records.size, 1, `${what}: no other record was made`);
|
|
1278
|
+
settled(world, kept ? runtime : null, what);
|
|
1279
|
+
nextFrameIsRight(world, runtime, what);
|
|
1280
|
+
if (!kept && world.disposed !== true && runtime.sky) {
|
|
1281
|
+
assert.notEqual(world.sky, first, `${what}: from a new record`);
|
|
1282
|
+
assert.equal(runtime.skyZone.blend, 0, `${what}: with no fade`);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
},
|
|
1287
|
+
|
|
1288
|
+
'review 1: a frame of another runtime from inside leaves the outer frame its dome'() {
|
|
1289
|
+
const world = skyWorld();
|
|
1290
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1291
|
+
const other = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1292
|
+
renderWorld(world, runtime);
|
|
1293
|
+
const outer = world.sky;
|
|
1294
|
+
let after = null;
|
|
1295
|
+
world.onRender = (level) => {
|
|
1296
|
+
if (level !== 0) return;
|
|
1297
|
+
renderWorld(world, other);
|
|
1298
|
+
// What the outer `WebGLRenderer.render` goes on with.
|
|
1299
|
+
const entries = [...world.records.get(outer).values()];
|
|
1300
|
+
after = { parent: outer.mesh.parent, shown: outer.mesh.visible, record: world.sky, disposed: entries.filter((entry) => entry.disposed > 0).length };
|
|
1301
|
+
};
|
|
1302
|
+
renderWorld(world, runtime);
|
|
1303
|
+
assert.deepEqual(after, { parent: world.scene, shown: true, record: outer, disposed: 0 });
|
|
1304
|
+
assert.deepEqual([world.draws.at(-1).sky, world.draws.at(-1).shown], [1, false], 'the other runtime\'s frame is drawn without the outer\'s sky');
|
|
1305
|
+
assert.equal(other.skyZone.id, 'square', 'and nothing of it was worked out');
|
|
1306
|
+
assert.equal(world.sky, outer, 'and the outer frame keeps its record: its runtime still has the key');
|
|
1307
|
+
settled(world, runtime, 'after');
|
|
1308
|
+
nextFrameIsRight(world, runtime, 'after');
|
|
1309
|
+
},
|
|
1310
|
+
|
|
1311
|
+
'review 2: a load lets the sky go at once, or the frame in progress does on its way out'() {
|
|
1312
|
+
const world = skyWorld();
|
|
1313
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1314
|
+
renderWorld(world, runtime);
|
|
1315
|
+
const first = world.sky;
|
|
1316
|
+
// Another runtime of this world loading is not this record's end.
|
|
1317
|
+
const bystander = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1318
|
+
bystander.load(world);
|
|
1319
|
+
bystander.load(world, undefined);
|
|
1320
|
+
assert.equal(world.sky, first, 'a load ends only the record of the key it replaces');
|
|
1321
|
+
runtime.load(world);
|
|
1322
|
+
assert.equal(world.sky, null, 'no render in progress: gone with the load');
|
|
1323
|
+
settled(world, null, 'a load');
|
|
1324
|
+
renderWorld(world, runtime);
|
|
1325
|
+
const second = world.sky;
|
|
1326
|
+
assert.notEqual(second, first);
|
|
1327
|
+
// A load from inside a render callback: the frame ends with nothing kept.
|
|
1328
|
+
world.onRender = (level) => {
|
|
1329
|
+
if (level !== 0) return;
|
|
1330
|
+
runtime.load(world);
|
|
1331
|
+
assert.equal(world.sky, second, 'while the frame draws, the record it draws with stands');
|
|
1332
|
+
};
|
|
1333
|
+
renderWorld(world, runtime);
|
|
1334
|
+
assert.equal(world.sky, null);
|
|
1335
|
+
settled(world, null, 'a load from inside a frame');
|
|
1336
|
+
nextFrameIsRight(world, runtime, 'a load from inside a frame');
|
|
1337
|
+
// A world that never played the key: a load reads `world.sky` and does nothing.
|
|
1338
|
+
const plain = skyWorld();
|
|
1339
|
+
delete plain.sky;
|
|
1340
|
+
runtimeWith(undefined).load(plain);
|
|
1341
|
+
assert.ok(!('sky' in plain));
|
|
1342
|
+
},
|
|
1343
|
+
|
|
1344
|
+
'review 3: listeners on the dome that throw never run, and a thrown frame keeps nothing'() {
|
|
1345
|
+
const world = skyWorld();
|
|
1346
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1347
|
+
renderWorld(world, runtime);
|
|
1348
|
+
let heard = 0;
|
|
1349
|
+
const thrower = () => {
|
|
1350
|
+
heard += 1;
|
|
1351
|
+
throw new Error('a listener');
|
|
1352
|
+
};
|
|
1353
|
+
for (const type of ['added', 'removed']) world.sky.mesh.addEventListener(type, thrower);
|
|
1354
|
+
for (const type of ['childadded', 'childremoved']) world.scene.addEventListener(type, thrower);
|
|
1355
|
+
tick(0.1);
|
|
1356
|
+
renderWorld(world, runtime);
|
|
1357
|
+
assert.equal(heard, 0, 'attaching and detaching dispatch nothing');
|
|
1358
|
+
settled(world, runtime, 'a frame');
|
|
1359
|
+
world.onRender = () => {
|
|
1360
|
+
throw new Error('the composer failed');
|
|
1361
|
+
};
|
|
1362
|
+
assert.throws(() => renderWorld(world, runtime), /the composer failed/);
|
|
1363
|
+
assert.equal(heard, 0);
|
|
1364
|
+
assert.equal(world.sky, null);
|
|
1365
|
+
settled(world, null, 'a thrown frame');
|
|
1366
|
+
nextFrameIsRight(world, runtime, 'a thrown frame');
|
|
1367
|
+
},
|
|
1368
|
+
|
|
1369
|
+
'review 4: a frame from inside that throws, caught by the outer callback, still ends the record'() {
|
|
1370
|
+
const world = skyWorld();
|
|
1371
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1372
|
+
renderWorld(world, runtime);
|
|
1373
|
+
runtime.moveTo(-18, 0);
|
|
1374
|
+
tick(0.3);
|
|
1375
|
+
const first = world.sky;
|
|
1376
|
+
world.onRender = (level) => {
|
|
1377
|
+
if (level === 1) throw new Error('the frame inside failed');
|
|
1378
|
+
try {
|
|
1379
|
+
renderWorld(world, runtime);
|
|
1380
|
+
} catch {
|
|
1381
|
+
// The deck's callback swallows it.
|
|
1382
|
+
}
|
|
1383
|
+
};
|
|
1384
|
+
renderWorld(world, runtime);
|
|
1385
|
+
assert.equal(world.sky, null, 'the outer frame succeeded, and kept nothing');
|
|
1386
|
+
settled(world, null, 'after');
|
|
1387
|
+
world.onRender = null;
|
|
1388
|
+
tick(0.1);
|
|
1389
|
+
renderWorld(world, runtime);
|
|
1390
|
+
assert.notEqual(world.sky, first);
|
|
1391
|
+
assert.deepEqual([runtime.skyZone.id, runtime.skyZone.from, runtime.skyZone.blend], ['hollow', 'hollow', 0], 'the fade went with it');
|
|
1392
|
+
},
|
|
1393
|
+
|
|
1394
|
+
'review 5: a frame drawn from inside a dispose listener makes nothing'() {
|
|
1395
|
+
for (const kind of ['texture', 'geometry', 'material']) {
|
|
1396
|
+
const world = skyWorld();
|
|
1397
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1398
|
+
let entered = 0;
|
|
1399
|
+
world.onOwned = (item, itemKind) => {
|
|
1400
|
+
if (itemKind !== kind) return;
|
|
1401
|
+
item.addEventListener('dispose', () => {
|
|
1402
|
+
entered += 1;
|
|
1403
|
+
renderWorld(world, runtime);
|
|
1404
|
+
assert.deepEqual([world.draws.at(-1).sky, recordOf(world), world.sky?.releasing], [0, null, true], `${kind}: drawn without a sky, and nothing made while the old one is disposed`);
|
|
1405
|
+
});
|
|
1406
|
+
};
|
|
1407
|
+
renderWorld(world, runtime);
|
|
1408
|
+
const first = world.sky;
|
|
1409
|
+
// Let go by a frame of a scene without the key.
|
|
1410
|
+
renderWorld(world, runtimeWith(undefined));
|
|
1411
|
+
assert.equal(entered, kind === 'texture' ? 3 : 1, kind);
|
|
1412
|
+
assert.equal(world.sky, null, `${kind}: nothing was made to replace it`);
|
|
1413
|
+
assert.equal(world.records.size, 1, kind);
|
|
1414
|
+
settled(world, null, `${kind}: a frame from inside its disposal`);
|
|
1415
|
+
nextFrameIsRight(world, runtime, kind);
|
|
1416
|
+
assert.notEqual(world.sky, first);
|
|
1417
|
+
// And by a dispose.
|
|
1418
|
+
world.onOwned = (item, itemKind) => {
|
|
1419
|
+
if (itemKind === kind) item.addEventListener('dispose', () => renderWorld(world, runtime));
|
|
1420
|
+
};
|
|
1421
|
+
tick(0.1);
|
|
1422
|
+
const fresh = skyWorld();
|
|
1423
|
+
fresh.onOwned = world.onOwned;
|
|
1424
|
+
fresh.onOwned = (item, itemKind) => {
|
|
1425
|
+
if (itemKind === kind) item.addEventListener('dispose', () => renderWorld(fresh, runtime));
|
|
1426
|
+
};
|
|
1427
|
+
renderWorld(fresh, runtime);
|
|
1428
|
+
disposeWorld(fresh);
|
|
1429
|
+
assert.equal(fresh.sky, null, kind);
|
|
1430
|
+
assert.equal(fresh.records.size, 1, kind);
|
|
1431
|
+
settled(fresh, null, `${kind}: a frame from inside a dispose`);
|
|
1432
|
+
}
|
|
1433
|
+
},
|
|
1434
|
+
|
|
1435
|
+
'review 6: a disposal that throws costs no other resource its own'() {
|
|
1436
|
+
// Each of what a record owns in turn, mid-fade (three textures), and all at once.
|
|
1437
|
+
for (const throwing of ['first texture', 'second texture', 'third texture', 'geometry', 'material', 'all']) {
|
|
1438
|
+
for (const [how, leave] of Object.entries({
|
|
1439
|
+
'a frame of a scene without the key': (world) => renderWorld(world, runtimeWith(undefined)),
|
|
1440
|
+
'a dispose': (world) => disposeWorld(world),
|
|
1441
|
+
'the end of a frame whose scene was loaded again inside it': (world, runtime) => {
|
|
1442
|
+
world.onRender = (level) => {
|
|
1443
|
+
if (level === 0) runtime.load(world);
|
|
1444
|
+
};
|
|
1445
|
+
renderWorld(world, runtime);
|
|
1446
|
+
},
|
|
1447
|
+
})) {
|
|
1448
|
+
const what = `${throwing} throws on disposal, by ${how}`;
|
|
1449
|
+
const world = skyWorld();
|
|
1450
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1451
|
+
let textures = 0;
|
|
1452
|
+
world.onOwned = (item, kind) => {
|
|
1453
|
+
const which = kind === 'texture' ? ['first texture', 'second texture', 'third texture'][textures++] : kind;
|
|
1454
|
+
if (throwing === 'all' || throwing === which) {
|
|
1455
|
+
item.addEventListener('dispose', () => {
|
|
1456
|
+
throw new Error(`${which} failed`);
|
|
1457
|
+
});
|
|
1458
|
+
}
|
|
1459
|
+
};
|
|
1460
|
+
renderWorld(world, runtime);
|
|
1461
|
+
runtime.moveTo(-18, 0);
|
|
1462
|
+
tick(0.2);
|
|
1463
|
+
renderWorld(world, runtime);
|
|
1464
|
+
assert.equal(world.sky.textures.size, 3, what);
|
|
1465
|
+
world.onOwned = null;
|
|
1466
|
+
const before = world.draws.length;
|
|
1467
|
+
// The first error comes out, once everything is disposed and the frame drawn.
|
|
1468
|
+
assert.throws(() => leave(world, runtime), throwing === 'all' ? /first texture failed/ : new RegExp(`${throwing} failed`), what);
|
|
1469
|
+
if (how !== 'a dispose') assert.ok(world.draws.length > before, `${what}: the frame was drawn`);
|
|
1470
|
+
assert.equal(world.sky, null, what);
|
|
1471
|
+
assert.equal([...world.records.values()][0].size, 5, what);
|
|
1472
|
+
settled(world, null, what);
|
|
1473
|
+
if (how !== 'a dispose') nextFrameIsRight(world, runtime, what);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
// A frame that is itself throwing keeps its own error.
|
|
1477
|
+
const world = skyWorld();
|
|
1478
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1479
|
+
world.onOwned = (item) => {
|
|
1480
|
+
item.addEventListener('dispose', () => {
|
|
1481
|
+
throw new Error('a disposal failed');
|
|
1482
|
+
});
|
|
1483
|
+
};
|
|
1484
|
+
renderWorld(world, runtime);
|
|
1485
|
+
world.onRender = () => {
|
|
1486
|
+
throw new Error('the composer failed');
|
|
1487
|
+
};
|
|
1488
|
+
assert.throws(() => renderWorld(world, runtime), /the composer failed/);
|
|
1489
|
+
settled(world, null, 'a thrown frame with throwing disposals');
|
|
1490
|
+
// A load releases everything and propagates the first disposal error.
|
|
1491
|
+
const loaded = skyWorld();
|
|
1492
|
+
loaded.onOwned = world.onOwned;
|
|
1493
|
+
renderWorld(loaded, runtime);
|
|
1494
|
+
assert.throws(() => runtime.load(loaded), /a disposal failed/);
|
|
1495
|
+
settled(loaded, null, 'a load with throwing disposals');
|
|
1496
|
+
},
|
|
1497
|
+
|
|
1498
|
+
'a texture let go mid-life whose disposal throws is disposed once'() {
|
|
1499
|
+
const world = skyWorld();
|
|
1500
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1501
|
+
renderWorld(world, runtime);
|
|
1502
|
+
world.onOwned = (item, kind) => {
|
|
1503
|
+
if (kind === 'texture') {
|
|
1504
|
+
item.addEventListener('dispose', () => {
|
|
1505
|
+
throw new Error('a texture failed');
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
};
|
|
1509
|
+
world.records.clear();
|
|
1510
|
+
tick(0.1);
|
|
1511
|
+
renderWorld(world, runtime);
|
|
1512
|
+
// Remove the square's art: only art changes can shed a cached texture.
|
|
1513
|
+
delete runtime.sprites['drawings/sky-square.webp'];
|
|
1514
|
+
runtime.moveTo(-18, 0);
|
|
1515
|
+
let threw = 0;
|
|
1516
|
+
for (let i = 0; i < 20 && threw === 0; i++) {
|
|
1517
|
+
tick(0.1);
|
|
1518
|
+
try {
|
|
1519
|
+
renderWorld(world, runtime);
|
|
1520
|
+
} catch (err) {
|
|
1521
|
+
assert.match(err.message, /a texture failed/);
|
|
1522
|
+
threw += 1;
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
assert.equal(threw, 1, 'the frame that let it go threw');
|
|
1526
|
+
assert.equal(world.sky, null);
|
|
1527
|
+
const entries = [...[...world.records.values()][0].values()];
|
|
1528
|
+
assert.deepEqual(entries.map((entry) => entry.disposed), entries.map(() => 1), 'each once, the one that threw in the step included');
|
|
1529
|
+
settled(world, null, 'after');
|
|
1530
|
+
nextFrameIsRight(world, runtime, 'after');
|
|
1531
|
+
// The same for a picture replaced in the deck.
|
|
1532
|
+
const w = skyWorld();
|
|
1533
|
+
const r = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1534
|
+
w.onOwned = world.onOwned;
|
|
1535
|
+
w.onOwned = (item, kind) => {
|
|
1536
|
+
if (kind === 'texture') {
|
|
1537
|
+
item.addEventListener('dispose', () => {
|
|
1538
|
+
throw new Error('a texture failed');
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
};
|
|
1542
|
+
renderWorld(w, r);
|
|
1543
|
+
r.sprites['drawings/sky-hollow.webp'] = image('drawings/sky-hollow.webp', { image: { width: 512, height: 256 } });
|
|
1544
|
+
assert.throws(() => renderWorld(w, r), /a texture failed/);
|
|
1545
|
+
settled(w, null, 'a picture replaced');
|
|
1546
|
+
},
|
|
1547
|
+
|
|
1548
|
+
'every call-out: whatever a listener does there, the frame ends right'() {
|
|
1549
|
+
// What a deck's code does when it is run from inside the sky's own work.
|
|
1550
|
+
const actions = {
|
|
1551
|
+
'loads a scene without the key into the frame\'s runtime': ({ world, frame }) => frame.load(world, undefined),
|
|
1552
|
+
'loads a scene without the key into another runtime': ({ world, bystander }) => bystander.load(world, undefined),
|
|
1553
|
+
'loads a different keyed scene': ({ world, frame }) => frame.load(world, good({ fade: 3 })),
|
|
1554
|
+
'disposes the world': ({ world }) => disposeWorld(world),
|
|
1555
|
+
're-enters renderWorld': ({ world, frame }) => renderWorld(world, frame),
|
|
1556
|
+
throws: () => {
|
|
1557
|
+
throw new Error('a listener failed');
|
|
1558
|
+
},
|
|
1559
|
+
};
|
|
1560
|
+
// Where it is run from (skylife.js's table; C4, the draw itself, is the
|
|
1561
|
+
// scenario before this one). Each sets a world up, hangs `fire` where
|
|
1562
|
+
// the call-out will run it, and returns the runtime whose frame it is
|
|
1563
|
+
// and what to call.
|
|
1564
|
+
const onDisposalOf = (world, kind, fire, which = 0) => {
|
|
1565
|
+
let seen = 0;
|
|
1566
|
+
world.onOwned = (item, itemKind) => {
|
|
1567
|
+
if (itemKind === kind && seen++ === which) item.addEventListener('dispose', fire);
|
|
1568
|
+
};
|
|
1569
|
+
};
|
|
1570
|
+
const points = {
|
|
1571
|
+
'C1 the release of another scene\'s record as a frame starts'(world, fire) {
|
|
1572
|
+
const old = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1573
|
+
onDisposalOf(world, 'material', fire);
|
|
1574
|
+
renderWorld(world, old);
|
|
1575
|
+
world.onOwned = null;
|
|
1576
|
+
const frame = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1577
|
+
return { frame, run: () => renderWorld(world, frame) };
|
|
1578
|
+
},
|
|
1579
|
+
'C2 the step, reading the Player\'s Transform'(world, fire) {
|
|
1580
|
+
const frame = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1581
|
+
renderWorld(world, frame);
|
|
1582
|
+
const t = frame.player.components.Transform;
|
|
1583
|
+
let x = t.x;
|
|
1584
|
+
Object.defineProperty(t, 'x', {
|
|
1585
|
+
get() {
|
|
1586
|
+
fire();
|
|
1587
|
+
return x;
|
|
1588
|
+
},
|
|
1589
|
+
set(value) {
|
|
1590
|
+
x = value;
|
|
1591
|
+
},
|
|
1592
|
+
});
|
|
1593
|
+
return { frame, run: () => renderWorld(world, frame) };
|
|
1594
|
+
},
|
|
1595
|
+
'C3 the disposal of a texture the step let go'(world, fire) {
|
|
1596
|
+
const frame = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1597
|
+
// The square's picture, let go on art removal at the end of the fade.
|
|
1598
|
+
onDisposalOf(world, 'texture', fire);
|
|
1599
|
+
renderWorld(world, frame);
|
|
1600
|
+
world.onOwned = null;
|
|
1601
|
+
frame.moveTo(-18, 0);
|
|
1602
|
+
for (let i = 0; i < 5; i++) {
|
|
1603
|
+
tick(0.25);
|
|
1604
|
+
renderWorld(world, frame);
|
|
1605
|
+
}
|
|
1606
|
+
assert.ok(frame.skyZone.blend > 0.8 && world.sky.textures.size === 3);
|
|
1607
|
+
delete frame.sprites['drawings/sky-square.webp'];
|
|
1608
|
+
tick(0.25);
|
|
1609
|
+
return { frame, run: () => renderWorld(world, frame) };
|
|
1610
|
+
},
|
|
1611
|
+
'C5 the release of a record whose key went, as a frame ends'(world, fire) {
|
|
1612
|
+
const frame = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1613
|
+
onDisposalOf(world, 'material', fire);
|
|
1614
|
+
renderWorld(world, frame);
|
|
1615
|
+
world.onOwned = null;
|
|
1616
|
+
world.onRender = (level) => {
|
|
1617
|
+
if (level === 0) frame.load(world);
|
|
1618
|
+
};
|
|
1619
|
+
return { frame, run: () => renderWorld(world, frame) };
|
|
1620
|
+
},
|
|
1621
|
+
'C6 the release at a load'(world, fire) {
|
|
1622
|
+
const frame = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1623
|
+
onDisposalOf(world, 'geometry', fire);
|
|
1624
|
+
renderWorld(world, frame);
|
|
1625
|
+
world.onOwned = null;
|
|
1626
|
+
return { frame, run: () => frame.load(world) };
|
|
1627
|
+
},
|
|
1628
|
+
'C6 the release at a dispose'(world, fire) {
|
|
1629
|
+
const frame = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1630
|
+
onDisposalOf(world, 'texture', fire);
|
|
1631
|
+
renderWorld(world, frame);
|
|
1632
|
+
world.onOwned = null;
|
|
1633
|
+
return { frame, run: () => disposeWorld(world) };
|
|
1634
|
+
},
|
|
1635
|
+
};
|
|
1636
|
+
const error = console.error;
|
|
1637
|
+
console.error = () => {};
|
|
1638
|
+
try {
|
|
1639
|
+
for (const [where, setUp] of Object.entries(points)) {
|
|
1640
|
+
for (const [does, act] of Object.entries(actions)) {
|
|
1641
|
+
const what = `${where}: a listener ${does}`;
|
|
1642
|
+
const world = skyWorld();
|
|
1643
|
+
const bystander = runtimeWith(good(), { player: { x: 0, z: 60 } });
|
|
1644
|
+
let fired = 0;
|
|
1645
|
+
let frame = null;
|
|
1646
|
+
const fire = () => {
|
|
1647
|
+
if (fired++ === 0) act({ world, frame, bystander });
|
|
1648
|
+
};
|
|
1649
|
+
const point = setUp(world, fire);
|
|
1650
|
+
frame = point.frame;
|
|
1651
|
+
assert.equal(fired, 0, `${what}: not before its time`);
|
|
1652
|
+
let threw = null;
|
|
1653
|
+
try {
|
|
1654
|
+
point.run();
|
|
1655
|
+
} catch (err) {
|
|
1656
|
+
threw = err;
|
|
1657
|
+
}
|
|
1658
|
+
assert.ok(fired >= 1, `${what}: the listener ran`);
|
|
1659
|
+
if (threw) assert.match(threw.message, /a listener failed/, what);
|
|
1660
|
+
assert.equal(Boolean(threw), does === 'throws', `${what}: ${threw ? 'threw' : 'did not throw'}`);
|
|
1661
|
+
// A frame that throws never leaves a LIVE record.
|
|
1662
|
+
if (threw) assert.equal(world.sky ?? null, null, `${what}: a thrown frame keeps no record`);
|
|
1663
|
+
settled(world, frame, what);
|
|
1664
|
+
nextFrameIsRight(world, frame, what);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
} finally {
|
|
1668
|
+
console.error = error;
|
|
1669
|
+
}
|
|
1670
|
+
},
|
|
1671
|
+
|
|
1672
|
+
'review 7: every release that is due runs, whatever has already gone wrong'() {
|
|
1673
|
+
// Switch runtimes with the old record's material throwing on disposal,
|
|
1674
|
+
// then throw from the replacement frame.
|
|
1675
|
+
const setUp = () => {
|
|
1676
|
+
const world = skyWorld();
|
|
1677
|
+
const old = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1678
|
+
world.onOwned = (item, kind) => {
|
|
1679
|
+
if (kind === 'material') {
|
|
1680
|
+
item.addEventListener('dispose', () => {
|
|
1681
|
+
throw new Error('the old material failed');
|
|
1682
|
+
});
|
|
1683
|
+
}
|
|
1684
|
+
};
|
|
1685
|
+
renderWorld(world, old);
|
|
1686
|
+
world.onOwned = null;
|
|
1687
|
+
return { world, next: runtimeWith(good(), { player: { x: 50, z: 0 } }) };
|
|
1688
|
+
};
|
|
1689
|
+
const thrown = setUp();
|
|
1690
|
+
thrown.world.onRender = () => {
|
|
1691
|
+
throw new Error('the replacement frame failed');
|
|
1692
|
+
};
|
|
1693
|
+
assert.throws(() => renderWorld(thrown.world, thrown.next), /the replacement frame failed/, 'the frame\'s own error is the one thrown');
|
|
1694
|
+
assert.equal(thrown.world.sky, null, 'nothing is left stale');
|
|
1695
|
+
assert.equal(thrown.world.records.size, 1, 'a frame already going to throw makes no record');
|
|
1696
|
+
settled(thrown.world, null, 'a replacement frame that throws');
|
|
1697
|
+
nextFrameIsRight(thrown.world, thrown.next, 'a replacement frame that throws');
|
|
1698
|
+
// The replacement frame succeeds: it throws the disposal's error, and
|
|
1699
|
+
// a frame that throws does not leave a LIVE record.
|
|
1700
|
+
const drawn = setUp();
|
|
1701
|
+
const before = drawn.world.draws.length;
|
|
1702
|
+
assert.throws(() => renderWorld(drawn.world, drawn.next), /the old material failed/);
|
|
1703
|
+
assert.deepEqual(drawn.world.draws.slice(before).map((draw) => draw.sky), [0], 'it was drawn, without a sky');
|
|
1704
|
+
assert.equal(drawn.world.sky, null);
|
|
1705
|
+
settled(drawn.world, null, 'a replacement frame that succeeds');
|
|
1706
|
+
nextFrameIsRight(drawn.world, drawn.next, 'a replacement frame that succeeds');
|
|
1707
|
+
},
|
|
1708
|
+
|
|
1709
|
+
'review 8: a key that goes during a call-out is not drawn'() {
|
|
1710
|
+
// (a) While runtime A's record is released, a disposal listener loads a
|
|
1711
|
+
// scene without the key into runtime B, whose frame this is.
|
|
1712
|
+
const world = skyWorld();
|
|
1713
|
+
const a = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1714
|
+
const b = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1715
|
+
world.onOwned = (item, kind) => {
|
|
1716
|
+
if (kind === 'material') item.addEventListener('dispose', () => b.load(world, undefined));
|
|
1717
|
+
};
|
|
1718
|
+
renderWorld(world, a);
|
|
1719
|
+
world.onOwned = null;
|
|
1720
|
+
renderWorld(world, b);
|
|
1721
|
+
assert.equal(b.sky, null);
|
|
1722
|
+
assert.equal(world.draws.at(-1).sky, 0, 'B\'s frame is drawn without the sky of a key it no longer has');
|
|
1723
|
+
assert.equal(world.sky, null, 'and no record is made for it');
|
|
1724
|
+
assert.equal(world.records.size, 1);
|
|
1725
|
+
settled(world, b, '(a)');
|
|
1726
|
+
// (b) A texture's disposal listener, during the step, loads a scene
|
|
1727
|
+
// without the key: the dome of a record that has just gone stale is not
|
|
1728
|
+
// attached.
|
|
1729
|
+
const w = skyWorld();
|
|
1730
|
+
const r = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1731
|
+
w.onOwned = (item, kind) => {
|
|
1732
|
+
if (kind === 'texture') item.addEventListener('dispose', () => r.load(w, undefined));
|
|
1733
|
+
};
|
|
1734
|
+
renderWorld(w, r);
|
|
1735
|
+
w.onOwned = null;
|
|
1736
|
+
// A repainted picture: the step lets the old texture go.
|
|
1737
|
+
r.sprites['drawings/sky-hollow.webp'] = image('drawings/sky-hollow.webp', { image: { width: 512, height: 256 } });
|
|
1738
|
+
renderWorld(w, r);
|
|
1739
|
+
assert.equal(r.sky, null);
|
|
1740
|
+
assert.equal(w.draws.at(-1).sky, 0, 'drawn without it');
|
|
1741
|
+
assert.equal(w.sky, null);
|
|
1742
|
+
settled(w, r, '(b)');
|
|
1743
|
+
nextFrameIsRight(w, r, '(b)');
|
|
1744
|
+
// (c) The same with nobody told: the runtime's key is simply another
|
|
1745
|
+
// (a runtime drawn into a world that is not its own hears of no load).
|
|
1746
|
+
// During the step, read from the Player's Transform:
|
|
1747
|
+
for (const [name, next] of Object.entries({ none: undefined, another: good({ fade: 3 }) })) {
|
|
1748
|
+
const world2 = skyWorld();
|
|
1749
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1750
|
+
renderWorld(world2, runtime);
|
|
1751
|
+
const first = world2.sky;
|
|
1752
|
+
const t = runtime.player.components.Transform;
|
|
1753
|
+
let once = 0;
|
|
1754
|
+
Object.defineProperty(t, 'x', {
|
|
1755
|
+
get() {
|
|
1756
|
+
if (once++ === 0) runtime.sky = readSkyKey(sceneWith(next), quiet);
|
|
1757
|
+
return -30;
|
|
1758
|
+
},
|
|
1759
|
+
});
|
|
1760
|
+
renderWorld(world2, runtime);
|
|
1761
|
+
assert.equal(world2.draws.at(-1).sky, 0, `(c) ${name}: the frame is drawn without the sky of the key that went`);
|
|
1762
|
+
assert.equal(world2.sky, null, `(c) ${name}: and its record is let go`);
|
|
1763
|
+
assert.equal(world2.records.get(first).size, 5);
|
|
1764
|
+
settled(world2, runtime, `(c) ${name}`);
|
|
1765
|
+
nextFrameIsRight(world2, runtime, `(c) ${name}`);
|
|
1766
|
+
}
|
|
1767
|
+
// (e) A frame of another runtime drawn from a listener during the step
|
|
1768
|
+
// changes nothing: it is a frame from inside.
|
|
1769
|
+
{
|
|
1770
|
+
const world4 = skyWorld();
|
|
1771
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1772
|
+
const other = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1773
|
+
renderWorld(world4, runtime);
|
|
1774
|
+
const t = runtime.player.components.Transform;
|
|
1775
|
+
let once = 0;
|
|
1776
|
+
Object.defineProperty(t, 'x', {
|
|
1777
|
+
get() {
|
|
1778
|
+
if (once++ === 0) renderWorld(world4, other);
|
|
1779
|
+
return -30;
|
|
1780
|
+
},
|
|
1781
|
+
});
|
|
1782
|
+
const before = world4.draws.length;
|
|
1783
|
+
renderWorld(world4, runtime);
|
|
1784
|
+
assert.deepEqual(world4.draws.slice(before).map((draw) => draw.sky), [0, 1], '(e) the frame inside has no sky (and makes none); the frame itself has its own');
|
|
1785
|
+
assert.equal(world4.sky?.key, runtime.sky);
|
|
1786
|
+
settled(world4, runtime, '(e)');
|
|
1787
|
+
nextFrameIsRight(world4, runtime, '(e)');
|
|
1788
|
+
}
|
|
1789
|
+
// (f) Two textures let go by one step, the first throwing on disposal:
|
|
1790
|
+
// the second is disposed all the same, the frame is drawn (without a
|
|
1791
|
+
// sky) and throws.
|
|
1792
|
+
{
|
|
1793
|
+
const world5 = skyWorld();
|
|
1794
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
1795
|
+
let textures = 0;
|
|
1796
|
+
world5.onOwned = (item, kind) => {
|
|
1797
|
+
if (kind === 'texture' && textures++ === 0) {
|
|
1798
|
+
item.addEventListener('dispose', () => {
|
|
1799
|
+
throw new Error('the first texture failed');
|
|
1800
|
+
});
|
|
1801
|
+
}
|
|
1802
|
+
};
|
|
1803
|
+
renderWorld(world5, runtime);
|
|
1804
|
+
runtime.moveTo(-18, 0);
|
|
1805
|
+
tick(0.2);
|
|
1806
|
+
renderWorld(world5, runtime);
|
|
1807
|
+
assert.equal(world5.sky.textures.size, 3);
|
|
1808
|
+
world5.onOwned = null;
|
|
1809
|
+
// Remove two pictures: both are let go by that frame's step.
|
|
1810
|
+
delete runtime.sprites['drawings/sky-square.webp'];
|
|
1811
|
+
delete runtime.sprites['drawings/sky-hollow.webp'];
|
|
1812
|
+
runtime.moveTo(50, 0);
|
|
1813
|
+
const before = world5.draws.length;
|
|
1814
|
+
assert.throws(() => renderWorld(world5, runtime), /the first texture failed/);
|
|
1815
|
+
assert.deepEqual(world5.draws.slice(before).map((draw) => draw.sky), [0], '(f) drawn, without a sky');
|
|
1816
|
+
assert.equal(world5.sky, null);
|
|
1817
|
+
settled(world5, null, '(f)');
|
|
1818
|
+
nextFrameIsRight(world5, runtime, '(f)');
|
|
1819
|
+
}
|
|
1820
|
+
// And while another scene's record is released as the frame starts:
|
|
1821
|
+
for (const [name, next] of Object.entries({ none: undefined, another: good({ fade: 3 }) })) {
|
|
1822
|
+
const world3 = skyWorld();
|
|
1823
|
+
const old = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1824
|
+
const runtime = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1825
|
+
const captured = runtime.sky;
|
|
1826
|
+
world3.onOwned = (item, kind) => {
|
|
1827
|
+
if (kind === 'geometry') item.addEventListener('dispose', () => (runtime.sky = readSkyKey(sceneWith(next), quiet)));
|
|
1828
|
+
};
|
|
1829
|
+
renderWorld(world3, old);
|
|
1830
|
+
world3.onOwned = null;
|
|
1831
|
+
renderWorld(world3, runtime);
|
|
1832
|
+
assert.notEqual(world3.sky?.key, captured, `(d) ${name}: nothing is made for the key the frame began with`);
|
|
1833
|
+
assert.equal(world3.sky?.key ?? null, runtime.sky, `(d) ${name}: but for the one the runtime has`);
|
|
1834
|
+
assert.equal(world3.draws.at(-1).sky, next ? 1 : 0, `(d) ${name}`);
|
|
1835
|
+
settled(world3, runtime, `(d) ${name}`);
|
|
1836
|
+
nextFrameIsRight(world3, runtime, `(d) ${name}`);
|
|
1837
|
+
}
|
|
1838
|
+
},
|
|
1839
|
+
|
|
1840
|
+
'review 9: a frame with no record of its own keeps none a frame inside it would have made'() {
|
|
1841
|
+
// The old record's disposal throws as the frame starts; the frame's draw
|
|
1842
|
+
// re-enters renderWorld.
|
|
1843
|
+
for (const outer of ['returns', 'throws']) {
|
|
1844
|
+
const world = skyWorld();
|
|
1845
|
+
const old = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
1846
|
+
world.onOwned = (item, kind) => {
|
|
1847
|
+
if (kind === 'material') {
|
|
1848
|
+
item.addEventListener('dispose', () => {
|
|
1849
|
+
throw new Error('the old material failed');
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
};
|
|
1853
|
+
renderWorld(world, old);
|
|
1854
|
+
world.onOwned = null;
|
|
1855
|
+
const next = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
1856
|
+
world.onRender = (level) => {
|
|
1857
|
+
if (level !== 0) return;
|
|
1858
|
+
renderWorld(world, next);
|
|
1859
|
+
assert.equal(recordOf(world), null, 'a frame from inside makes nothing');
|
|
1860
|
+
if (outer === 'throws') throw new Error('the outer draw failed');
|
|
1861
|
+
};
|
|
1862
|
+
assert.throws(() => renderWorld(world, next), outer === 'throws' ? /the outer draw failed/ : /the old material failed/, outer);
|
|
1863
|
+
assert.equal(world.sky, null, `${outer}: no record at depth 0 after a frame that threw`);
|
|
1864
|
+
assert.equal(world.skyDepth, 0);
|
|
1865
|
+
settled(world, null, outer);
|
|
1866
|
+
nextFrameIsRight(world, next, outer);
|
|
1867
|
+
}
|
|
1868
|
+
},
|
|
1869
|
+
|
|
1870
|
+
'review 10: a runtime that draws in another world has no sky in this one'() {
|
|
1871
|
+
const player = () => ({ id: 'p', components: { Transform: { x: -30, y: 1, z: 0 }, Player: {} } });
|
|
1872
|
+
// A real SceneRuntime drawn into world A while its `three` is world B.
|
|
1873
|
+
const a = skyWorld();
|
|
1874
|
+
const b = skyWorld();
|
|
1875
|
+
const runtime = new SceneRuntime({ engine: { sky: good() }, actors: [player()] }, [], allArt(), {});
|
|
1876
|
+
runtime.three = b;
|
|
1877
|
+
renderWorld(a, runtime);
|
|
1878
|
+
assert.equal(a.sky, null, 'no record is made in a world that is not the runtime\'s');
|
|
1879
|
+
assert.equal(a.draws.at(-1).sky, 0);
|
|
1880
|
+
assert.equal(skyKeyFor(a, runtime), null);
|
|
1881
|
+
assert.equal(skyKeyFor(b, runtime), runtime.sky);
|
|
1882
|
+
// Drawing in A as its own; during A's draw it is pointed at B and loads
|
|
1883
|
+
// a scene without the key (which resets B, not A).
|
|
1884
|
+
runtime.three = a;
|
|
1885
|
+
renderWorld(a, runtime);
|
|
1886
|
+
assert.equal(a.sky.key, runtime.sky);
|
|
1887
|
+
renderWorld(b, runtimeWith(good()));
|
|
1888
|
+
a.onRender = () => {
|
|
1889
|
+
runtime.three = b;
|
|
1890
|
+
runtime.load({ actors: [player()] });
|
|
1891
|
+
};
|
|
1892
|
+
renderWorld(a, runtime);
|
|
1893
|
+
assert.equal(runtime.sky, null);
|
|
1894
|
+
assert.equal(a.sky, null, 'A keeps no record of a key its frame\'s runtime no longer has');
|
|
1895
|
+
settled(a, runtime, 'A');
|
|
1896
|
+
assert.ok(b.sky, 'B\'s own record, of another runtime, is not that load\'s to end');
|
|
1897
|
+
// And pointed at B with its key kept: still none for A.
|
|
1898
|
+
const again = new SceneRuntime({ engine: { sky: good() }, actors: [player()] }, [], allArt(), {});
|
|
1899
|
+
again.three = a;
|
|
1900
|
+
a.onRender = null;
|
|
1901
|
+
renderWorld(a, again);
|
|
1902
|
+
assert.ok(a.sky);
|
|
1903
|
+
a.onRender = () => {
|
|
1904
|
+
again.three = b;
|
|
1905
|
+
};
|
|
1906
|
+
renderWorld(a, again);
|
|
1907
|
+
assert.ok(again.sky);
|
|
1908
|
+
assert.equal(a.sky, null);
|
|
1909
|
+
settled(a, again, 'A again');
|
|
1910
|
+
},
|
|
1911
|
+
|
|
1912
|
+
'random interference: 2,500 frames over two worlds and three runtimes'() {
|
|
1913
|
+
// A small seeded generator (mulberry32).
|
|
1914
|
+
let seed = 20261005;
|
|
1915
|
+
const rng = () => {
|
|
1916
|
+
seed = (seed + 0x6d2b79f5) | 0;
|
|
1917
|
+
let t = Math.imul(seed ^ (seed >>> 15), 1 | seed);
|
|
1918
|
+
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
|
1919
|
+
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
|
1920
|
+
};
|
|
1921
|
+
const pick = (list) => list[Math.floor(rng() * list.length)];
|
|
1922
|
+
const specs = [good(), good({ fade: 0.4 }), good({ edge: 0 }), undefined];
|
|
1923
|
+
// Mostly beside a line between two zones, where a step crosses it.
|
|
1924
|
+
const places = [
|
|
1925
|
+
[-16.5, 0],
|
|
1926
|
+
[-17.5, 0],
|
|
1927
|
+
[16.5, 0],
|
|
1928
|
+
[17.5, 0],
|
|
1929
|
+
[0, -16.5],
|
|
1930
|
+
[0, -17.5],
|
|
1931
|
+
[0, 0],
|
|
1932
|
+
[-17.5, -17.5],
|
|
1933
|
+
];
|
|
1934
|
+
const worlds = [skyWorld(), skyWorld()];
|
|
1935
|
+
const retired = [];
|
|
1936
|
+
// What may happen this frame, and how deep frames are nested.
|
|
1937
|
+
let budget = 0;
|
|
1938
|
+
let nest = 0;
|
|
1939
|
+
let armed = false;
|
|
1940
|
+
const counts = {};
|
|
1941
|
+
const runtimes = [];
|
|
1942
|
+
const loadInto = (runtime, spec) => {
|
|
1943
|
+
// A reset that fails has still released the record, and the load stops.
|
|
1944
|
+
try {
|
|
1945
|
+
new Physics3DSystem().reset(runtime);
|
|
1946
|
+
} catch (err) {
|
|
1947
|
+
assert.match(String(err), /interference/);
|
|
1948
|
+
return;
|
|
1949
|
+
}
|
|
1950
|
+
runtime.data = sceneWith(spec);
|
|
1951
|
+
runtime.sky = readSkyKey(runtime.data, quiet);
|
|
1952
|
+
};
|
|
1953
|
+
const actions = {
|
|
1954
|
+
'a frame': () => {
|
|
1955
|
+
if (nest >= 3) return false;
|
|
1956
|
+
nest += 1;
|
|
1957
|
+
try {
|
|
1958
|
+
renderWorld(pick(worlds), pick(runtimes));
|
|
1959
|
+
} finally {
|
|
1960
|
+
nest -= 1;
|
|
1961
|
+
}
|
|
1962
|
+
return true;
|
|
1963
|
+
},
|
|
1964
|
+
'a frame, its error caught': () => {
|
|
1965
|
+
if (nest >= 3) return false;
|
|
1966
|
+
nest += 1;
|
|
1967
|
+
try {
|
|
1968
|
+
renderWorld(pick(worlds), pick(runtimes));
|
|
1969
|
+
} catch (err) {
|
|
1970
|
+
assert.match(err.message, /interference/);
|
|
1971
|
+
} finally {
|
|
1972
|
+
nest -= 1;
|
|
1973
|
+
}
|
|
1974
|
+
return true;
|
|
1975
|
+
},
|
|
1976
|
+
'an editor\'s frame': () => {
|
|
1977
|
+
if (nest >= 3) return false;
|
|
1978
|
+
nest += 1;
|
|
1979
|
+
try {
|
|
1980
|
+
renderWorld(pick(worlds), undefined);
|
|
1981
|
+
} finally {
|
|
1982
|
+
nest -= 1;
|
|
1983
|
+
}
|
|
1984
|
+
return true;
|
|
1985
|
+
},
|
|
1986
|
+
'a frame with no key that throws, caught': () => {
|
|
1987
|
+
if (nest >= 3) return false;
|
|
1988
|
+
nest += 1;
|
|
1989
|
+
const world = pick(worlds);
|
|
1990
|
+
const was = world.onRender;
|
|
1991
|
+
world.onRender = () => {
|
|
1992
|
+
world.onRender = was;
|
|
1993
|
+
throw new Error('interference');
|
|
1994
|
+
};
|
|
1995
|
+
try {
|
|
1996
|
+
renderWorld(world, rng() < 0.5 ? undefined : runtimeWith(undefined));
|
|
1997
|
+
} catch (err) {
|
|
1998
|
+
assert.match(err.message, /interference/);
|
|
1999
|
+
} finally {
|
|
2000
|
+
world.onRender = was;
|
|
2001
|
+
nest -= 1;
|
|
2002
|
+
}
|
|
2003
|
+
return true;
|
|
2004
|
+
},
|
|
2005
|
+
'a load of a keyed scene': () => (loadInto(pick(runtimes), pick(specs.slice(0, 3))), true),
|
|
2006
|
+
'a load of a scene without the key': () => (loadInto(pick(runtimes), undefined), true),
|
|
2007
|
+
'a runtime pointed at another world': () => {
|
|
2008
|
+
pick(runtimes).three = pick([worlds[0], worlds[1], undefined]);
|
|
2009
|
+
return true;
|
|
2010
|
+
},
|
|
2011
|
+
'a world disposed': () => {
|
|
2012
|
+
if (rng() > 0.6) return false;
|
|
2013
|
+
disposeWorld(pick(worlds));
|
|
2014
|
+
return true;
|
|
2015
|
+
},
|
|
2016
|
+
'a throw': () => {
|
|
2017
|
+
throw new Error('interference');
|
|
2018
|
+
},
|
|
2019
|
+
};
|
|
2020
|
+
const names = Object.keys(actions);
|
|
2021
|
+
const interfere = (site, chance) => {
|
|
2022
|
+
if (!armed || budget <= 0 || rng() > chance) return;
|
|
2023
|
+
budget -= 1;
|
|
2024
|
+
const name = pick(names);
|
|
2025
|
+
const tally = (counts[site] ??= {});
|
|
2026
|
+
let happened = false;
|
|
2027
|
+
try {
|
|
2028
|
+
happened = actions[name]();
|
|
2029
|
+
} catch (err) {
|
|
2030
|
+
tally[name] = (tally[name] ?? 0) + 1;
|
|
2031
|
+
throw err;
|
|
2032
|
+
}
|
|
2033
|
+
if (happened) tally[name] = (tally[name] ?? 0) + 1;
|
|
2034
|
+
};
|
|
2035
|
+
const wire = (world) => {
|
|
2036
|
+
world.onRender = () => interfere('the draw', 0.5);
|
|
2037
|
+
world.onOwned = (item) => item.addEventListener('dispose', () => interfere('a dispose listener', 0.5));
|
|
2038
|
+
return world;
|
|
2039
|
+
};
|
|
2040
|
+
worlds.forEach(wire);
|
|
2041
|
+
for (let i = 0; i < 3; i++) {
|
|
2042
|
+
// Engine art records are stored data; art getters are rejected, tested
|
|
2043
|
+
// with both keys in test-static-scenery.mjs. Repaint them between frames.
|
|
2044
|
+
const sprites = allArt();
|
|
2045
|
+
const runtime = runtimeWith(pick(specs), { sprites, player: { x: -16.5, z: 0 } });
|
|
2046
|
+
const t = runtime.player.components.Transform;
|
|
2047
|
+
let x = -16.5;
|
|
2048
|
+
Object.defineProperty(t, 'x', {
|
|
2049
|
+
get() {
|
|
2050
|
+
interfere('a getter on the Player\'s Transform', 0.4);
|
|
2051
|
+
return x;
|
|
2052
|
+
},
|
|
2053
|
+
set(value) {
|
|
2054
|
+
x = value;
|
|
2055
|
+
},
|
|
2056
|
+
});
|
|
2057
|
+
runtimes.push(runtime);
|
|
2058
|
+
}
|
|
2059
|
+
const FRAMES = 2500;
|
|
2060
|
+
let lastWorld = 0;
|
|
2061
|
+
let lastRuntime = 0;
|
|
2062
|
+
const seen = { threw: 0, withSky: 0, fading: 0, disposedWorlds: 0, deepest: 0 };
|
|
2063
|
+
const started = Date.now();
|
|
2064
|
+
for (let frame = 0; frame < FRAMES; frame++) {
|
|
2065
|
+
// A disposed world is replaced by a new one, and kept to be looked at.
|
|
2066
|
+
for (let w = 0; w < worlds.length; w++) {
|
|
2067
|
+
if (worlds[w].disposed === true) {
|
|
2068
|
+
retired.push(worlds[w]);
|
|
2069
|
+
for (const runtime of runtimes) if (runtime.three === worlds[w]) runtime.three = undefined;
|
|
2070
|
+
worlds[w] = wire(skyWorld());
|
|
2071
|
+
seen.disposedWorlds += 1;
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
// The players walk, or are put somewhere.
|
|
2075
|
+
for (const runtime of runtimes) {
|
|
2076
|
+
for (const path of Object.keys(runtime.sprites)) {
|
|
2077
|
+
if (rng() < 0.03) runtime.sprites[path] = image(path, { image: { width: 512, height: 256 } });
|
|
2078
|
+
if (rng() < 0.03) runtime.sprites[path] = image(path, { ready: false });
|
|
2079
|
+
}
|
|
2080
|
+
const t = runtime.player.components.Transform;
|
|
2081
|
+
if (rng() < 0.06) [t.x, t.z] = pick(places);
|
|
2082
|
+
else if (rng() < 0.6) t.x += (rng() - 0.5) * 3;
|
|
2083
|
+
}
|
|
2084
|
+
tick(rng() * 0.3);
|
|
2085
|
+
budget = Math.floor(rng() * 5);
|
|
2086
|
+
// Mostly the same runtime in the same world as the frame before, as a
|
|
2087
|
+
// game is; sometimes any.
|
|
2088
|
+
if (rng() < 0.3 || worlds[lastWorld].disposed === true) [lastWorld, lastRuntime] = [Math.floor(rng() * 2), Math.floor(rng() * 3)];
|
|
2089
|
+
const world = worlds[lastWorld];
|
|
2090
|
+
const runtime = runtimes[lastRuntime];
|
|
2091
|
+
const before = world.draws.length;
|
|
2092
|
+
armed = true;
|
|
2093
|
+
try {
|
|
2094
|
+
renderWorld(world, runtime);
|
|
2095
|
+
} catch (err) {
|
|
2096
|
+
assert.match(err.message, /interference/, `frame ${frame}: only what was thrown at it comes out`);
|
|
2097
|
+
seen.threw += 1;
|
|
2098
|
+
} finally {
|
|
2099
|
+
armed = false;
|
|
2100
|
+
}
|
|
2101
|
+
assert.equal(nest, 0);
|
|
2102
|
+
assert.ok(world.draws.length > before, `frame ${frame}: it was drawn`);
|
|
2103
|
+
seen.deepest = Math.max(seen.deepest, ...world.draws.slice(before).map((draw) => draw.level));
|
|
2104
|
+
if (world.draws.slice(before).some((draw) => draw.sky === 1 && draw.shown)) seen.withSky += 1;
|
|
2105
|
+
if (runtime.sky && runtime.skyZone.blend > 0 && world.sky?.key === runtime.sky) seen.fading += 1;
|
|
2106
|
+
// Outside every frame: no dome in either graph, nothing counted in.
|
|
2107
|
+
for (const each of worlds) {
|
|
2108
|
+
assert.equal(domesIn(each), 0, `frame ${frame}: no dome in a graph outside a frame`);
|
|
2109
|
+
assert.equal(each.skyDepth ?? 0, 0, `frame ${frame}: no frame counted in`);
|
|
2110
|
+
assert.equal(each.level, 0);
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
assert.ok(Date.now() - started < 120000, 'no frame hangs');
|
|
2114
|
+
// The end: both worlds disposed, with nothing interfering.
|
|
2115
|
+
for (const world of worlds) disposeWorld(world);
|
|
2116
|
+
let records = 0;
|
|
2117
|
+
let resources = 0;
|
|
2118
|
+
for (const world of [...worlds, ...retired]) {
|
|
2119
|
+
assert.equal(world.sky ?? null, null);
|
|
2120
|
+
for (const owned of (world.records ?? new Map()).values()) {
|
|
2121
|
+
records += 1;
|
|
2122
|
+
for (const entry of owned.values()) {
|
|
2123
|
+
resources += 1;
|
|
2124
|
+
assert.equal(entry.disposed, 1, `a ${entry.kind} is disposed exactly once by the end`);
|
|
2125
|
+
}
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
assert.deepEqual(twice, []);
|
|
2129
|
+
// Every interference happened at every place it can, many times.
|
|
2130
|
+
const sites = ['the draw', 'a dispose listener', 'a getter on the Player\'s Transform'];
|
|
2131
|
+
for (const site of sites) {
|
|
2132
|
+
for (const name of names) assert.ok((counts[site]?.[name] ?? 0) >= 5, `${name}, from ${site}: ${counts[site]?.[name] ?? 0} times`);
|
|
2133
|
+
}
|
|
2134
|
+
assert.ok(seen.withSky > 300 && seen.threw > 100 && seen.fading > 10 && seen.disposedWorlds > 5 && records > 100, JSON.stringify({ seen, records }));
|
|
2135
|
+
randomCoverage = { frames: FRAMES, ...seen, records, resources, counts };
|
|
2136
|
+
},
|
|
2137
|
+
|
|
2138
|
+
'a frame that threw inside a disposal, with no frame round it, costs the next frame nothing'() {
|
|
2139
|
+
const world = skyWorld();
|
|
2140
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2141
|
+
const other = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
2142
|
+
world.onOwned = (item, kind) => {
|
|
2143
|
+
if (kind !== 'material') return;
|
|
2144
|
+
item.addEventListener('dispose', () => {
|
|
2145
|
+
// A frame, from a listener of a load's release, that throws; caught here.
|
|
2146
|
+
world.onRender = () => {
|
|
2147
|
+
throw new Error('the frame inside failed');
|
|
2148
|
+
};
|
|
2149
|
+
assert.throws(() => renderWorld(world, other), /the frame inside failed/);
|
|
2150
|
+
world.onRender = null;
|
|
2151
|
+
});
|
|
2152
|
+
};
|
|
2153
|
+
renderWorld(world, runtime);
|
|
2154
|
+
world.onOwned = null;
|
|
2155
|
+
runtime.load(world);
|
|
2156
|
+
assert.equal(world.sky, null);
|
|
2157
|
+
renderWorld(world, runtime);
|
|
2158
|
+
const record = world.sky;
|
|
2159
|
+
assert.ok(record, 'the next frame has its sky');
|
|
2160
|
+
tick(0.1);
|
|
2161
|
+
renderWorld(world, runtime);
|
|
2162
|
+
assert.equal(world.sky, record, 'and keeps it: nothing was left over to say a frame threw');
|
|
2163
|
+
settled(world, runtime, 'after');
|
|
2164
|
+
},
|
|
2165
|
+
|
|
2166
|
+
'review 11: a dispose listener that throws stops no later listener, three.js\'s own included'() {
|
|
2167
|
+
// three.js's WebGLGeometries on the sky's geometry, as the renderer has it
|
|
2168
|
+
// once the dome is drawn: a `dispose` listener that frees the attributes
|
|
2169
|
+
// and the binding states. A deck's listener that throws is there first.
|
|
2170
|
+
const ways = {
|
|
2171
|
+
'a frame of a scene without the key': (world) => renderWorld(world, runtimeWith(undefined)),
|
|
2172
|
+
'a load': (world, runtime) => runtime.load(world),
|
|
2173
|
+
'a dispose': (world) => disposeWorld(world),
|
|
2174
|
+
};
|
|
2175
|
+
for (const [how, leave] of Object.entries(ways)) {
|
|
2176
|
+
const world = skyWorld();
|
|
2177
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
2178
|
+
const freed = { attributes: 0, states: 0 };
|
|
2179
|
+
const info = { memory: { geometries: 0 } };
|
|
2180
|
+
const geometries = new WebGLGeometries(null, { remove: () => (freed.attributes += 1) }, info, { releaseStatesOfGeometry: () => (freed.states += 1) });
|
|
2181
|
+
// What the renderer's WebGLTextures and material cleanup are to this:
|
|
2182
|
+
// a listener, added when the thing is first drawn.
|
|
2183
|
+
const internal = new Map();
|
|
2184
|
+
world.onOwned = (item, kind) => {
|
|
2185
|
+
item.addEventListener('dispose', () => {
|
|
2186
|
+
throw new Error(`a deck's ${kind} listener failed`);
|
|
2187
|
+
});
|
|
2188
|
+
if (kind === 'geometry') geometries.get(world.sky.mesh, item);
|
|
2189
|
+
else item.addEventListener('dispose', (event) => internal.set(item, { kind, type: event.type, target: event.target, calls: (internal.get(item)?.calls ?? 0) + 1 }));
|
|
2190
|
+
};
|
|
2191
|
+
renderWorld(world, runtime);
|
|
2192
|
+
runtime.moveTo(-18, 0);
|
|
2193
|
+
tick(0.2);
|
|
2194
|
+
renderWorld(world, runtime);
|
|
2195
|
+
assert.equal(info.memory.geometries, 1, how);
|
|
2196
|
+
assert.equal(world.sky.textures.size, 3, how);
|
|
2197
|
+
const error = console.error;
|
|
2198
|
+
console.error = () => {};
|
|
2199
|
+
try {
|
|
2200
|
+
assert.throws(() => leave(world, runtime), /a deck's texture listener failed/, how);
|
|
2201
|
+
} finally {
|
|
2202
|
+
console.error = error;
|
|
2203
|
+
}
|
|
2204
|
+
assert.deepEqual([info.memory.geometries, freed], [0, { attributes: 3, states: 1 }], `${how}: three.js let the geometry go: its index, position and uv, and its binding states`);
|
|
2205
|
+
assert.deepEqual([...internal.values()].map((entry) => [entry.kind, entry.type, entry.calls]).sort(), [['material', 'dispose', 1], ['texture', 'dispose', 1], ['texture', 'dispose', 1], ['texture', 'dispose', 1]], `${how}: and the listeners after the thrower on all textures and the material ran, once`);
|
|
2206
|
+
for (const [item, entry] of internal) assert.equal(entry.target, item, `${how}: with the event three.js sends`);
|
|
2207
|
+
settled(world, null, how);
|
|
2208
|
+
}
|
|
2209
|
+
// A texture the step lets go (not a release): the same.
|
|
2210
|
+
const world = skyWorld();
|
|
2211
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2212
|
+
let later = 0;
|
|
2213
|
+
world.onOwned = (item, kind) => {
|
|
2214
|
+
if (kind !== 'texture') return;
|
|
2215
|
+
item.addEventListener('dispose', () => {
|
|
2216
|
+
throw new Error('a deck\'s texture listener failed');
|
|
2217
|
+
});
|
|
2218
|
+
item.addEventListener('dispose', () => (later += 1));
|
|
2219
|
+
};
|
|
2220
|
+
renderWorld(world, runtime);
|
|
2221
|
+
world.onOwned = null;
|
|
2222
|
+
runtime.sprites['drawings/sky-hollow.webp'] = image('drawings/sky-hollow.webp', { image: { width: 512, height: 256 } });
|
|
2223
|
+
assert.throws(() => renderWorld(world, runtime), /a deck's texture listener failed/);
|
|
2224
|
+
assert.equal(later, 3, 'the replaced texture and both textures released after the error ran their later listeners');
|
|
2225
|
+
// As three.js dispatches: a listener taken off by one before it still
|
|
2226
|
+
// runs this time (the list is copied), `this` is the resource, and the
|
|
2227
|
+
// event's target is cleared after.
|
|
2228
|
+
const w = skyWorld();
|
|
2229
|
+
const r = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2230
|
+
const heard = [];
|
|
2231
|
+
let event = null;
|
|
2232
|
+
w.onOwned = (item, kind) => {
|
|
2233
|
+
if (kind !== 'material') return;
|
|
2234
|
+
const second = function (e) {
|
|
2235
|
+
heard.push(['second', this === item, e.target === item]);
|
|
2236
|
+
};
|
|
2237
|
+
item.addEventListener('dispose', function (e) {
|
|
2238
|
+
event = e;
|
|
2239
|
+
heard.push(['first', this === item, e.target === item]);
|
|
2240
|
+
item.removeEventListener('dispose', second);
|
|
2241
|
+
});
|
|
2242
|
+
item.addEventListener('dispose', second);
|
|
2243
|
+
};
|
|
2244
|
+
renderWorld(w, r);
|
|
2245
|
+
disposeWorld(w);
|
|
2246
|
+
assert.deepEqual(heard, [['first', true, true], ['second', true, true]]);
|
|
2247
|
+
assert.deepEqual([event.type, event.target], ['dispose', null]);
|
|
2248
|
+
},
|
|
2249
|
+
|
|
2250
|
+
'three.js keeps `dispose` listeners where skylife.js reads them, and `dispose()` only dispatches'() {
|
|
2251
|
+
// skylife.js `disposed` calls a resource's `dispose` listeners itself,
|
|
2252
|
+
// from three.js's EventDispatcher's own storage. If either of these
|
|
2253
|
+
// fails, three.js has changed under it: read `disposed` again.
|
|
2254
|
+
const strip = (fn) => fn.toString().replace(/\/\*[\s\S]*?\*\//g, '').replace(/\s+/g, '');
|
|
2255
|
+
for (const [name, item, Class] of [
|
|
2256
|
+
['Texture', new THREE.Texture(), THREE.Texture],
|
|
2257
|
+
['BufferGeometry', new THREE.BufferGeometry(), THREE.BufferGeometry],
|
|
2258
|
+
['ShaderMaterial', new THREE.ShaderMaterial(), THREE.Material],
|
|
2259
|
+
]) {
|
|
2260
|
+
assert.equal(item._listeners, undefined, `${name}: no storage before a listener is added`);
|
|
2261
|
+
const listener = () => {};
|
|
2262
|
+
item.addEventListener('dispose', listener);
|
|
2263
|
+
assert.ok(Array.isArray(item._listeners?.dispose), `${name}: _listeners.dispose is an array`);
|
|
2264
|
+
assert.deepEqual(item._listeners.dispose, [listener], name);
|
|
2265
|
+
assert.equal(strip(Class.prototype.dispose), "dispose(){this.dispatchEvent({type:'dispose'});}", `${name}: dispose() is the dispatch and nothing else`);
|
|
2266
|
+
assert.equal(item.dispose, Class.prototype.dispose, `${name}: and is not overridden`);
|
|
2267
|
+
}
|
|
2268
|
+
// A resource kept another way falls back to its own `dispose()`, guarded.
|
|
2269
|
+
const made = [];
|
|
2270
|
+
const fake = (name, fails) => ({
|
|
2271
|
+
dispose() {
|
|
2272
|
+
made.push(name);
|
|
2273
|
+
if (fails) throw new Error(`${name} failed`);
|
|
2274
|
+
},
|
|
2275
|
+
});
|
|
2276
|
+
const world = { scene: new THREE.Scene() };
|
|
2277
|
+
world.sky = { key: {}, mesh: new THREE.Object3D(), shed: [], owned: () => [fake('one', true), { _listeners: { dispose: 'not a list' }, ...fake('two', false) }, fake('three', true)], forget() {} };
|
|
2278
|
+
assert.match(leaveSkyAlone(world).message, /one failed/);
|
|
2279
|
+
assert.deepEqual(made, ['one', 'two', 'three']);
|
|
2280
|
+
assert.equal(world.sky, null);
|
|
2281
|
+
},
|
|
2282
|
+
|
|
2283
|
+
'review 12: a frame without a key, drawn and caught inside a disposal, is heard'() {
|
|
2284
|
+
// As a frame starts, the old record's disposal draws an editor's frame
|
|
2285
|
+
// (or a scene's without the key) that throws, and catches it.
|
|
2286
|
+
for (const [which, inner] of Object.entries({ 'an editor\'s frame': () => undefined, 'a frame of a scene without the key': () => runtimeWith(undefined) })) {
|
|
2287
|
+
const world = skyWorld();
|
|
2288
|
+
const old = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2289
|
+
let caught = 0;
|
|
2290
|
+
world.onOwned = (item, kind) => {
|
|
2291
|
+
if (kind !== 'material') return;
|
|
2292
|
+
item.addEventListener('dispose', () => {
|
|
2293
|
+
world.onRender = () => {
|
|
2294
|
+
world.onRender = null;
|
|
2295
|
+
throw new Error('the frame inside failed');
|
|
2296
|
+
};
|
|
2297
|
+
try {
|
|
2298
|
+
renderWorld(world, inner());
|
|
2299
|
+
} catch {
|
|
2300
|
+
caught += 1;
|
|
2301
|
+
}
|
|
2302
|
+
});
|
|
2303
|
+
};
|
|
2304
|
+
renderWorld(world, old);
|
|
2305
|
+
world.onOwned = null;
|
|
2306
|
+
const next = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
2307
|
+
renderWorld(world, next);
|
|
2308
|
+
assert.equal(caught, 1, which);
|
|
2309
|
+
assert.equal(world.sky, null, `${which}: a frame inside this one threw, so it keeps no record`);
|
|
2310
|
+
settled(world, null, which);
|
|
2311
|
+
nextFrameIsRight(world, next, which);
|
|
2312
|
+
assert.ok(world.sky);
|
|
2313
|
+
}
|
|
2314
|
+
// While it is disposed, `world.sky` is a marker, not a record, and gone after.
|
|
2315
|
+
const world = skyWorld();
|
|
2316
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2317
|
+
const during = [];
|
|
2318
|
+
world.onOwned = (item) => item.addEventListener('dispose', () => during.push([world.sky?.releasing, world.sky?.key, world.skyDepth]));
|
|
2319
|
+
renderWorld(world, runtime);
|
|
2320
|
+
disposeWorld(world);
|
|
2321
|
+
assert.deepEqual(during, Array.from({ length: 5 }, () => [true, undefined, 1]));
|
|
2322
|
+
assert.equal(world.sky, null);
|
|
2323
|
+
// And nothing of the engine's mistakes it for a record: a load and a
|
|
2324
|
+
// dispose from inside a disposal do nothing.
|
|
2325
|
+
const w = skyWorld();
|
|
2326
|
+
const r = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2327
|
+
w.onOwned = (item, kind) => {
|
|
2328
|
+
if (kind !== 'geometry') return;
|
|
2329
|
+
item.addEventListener('dispose', () => {
|
|
2330
|
+
r.load(w);
|
|
2331
|
+
disposeWorld(w);
|
|
2332
|
+
});
|
|
2333
|
+
};
|
|
2334
|
+
renderWorld(w, r);
|
|
2335
|
+
r.load(w);
|
|
2336
|
+
assert.equal(w.sky, null);
|
|
2337
|
+
settled(w, null, 'a load and a dispose from inside a disposal');
|
|
2338
|
+
},
|
|
2339
|
+
|
|
2340
|
+
'a keyed frame from inside a frame of a scene that never had the key'() {
|
|
2341
|
+
const world = skyWorld();
|
|
2342
|
+
delete world.sky;
|
|
2343
|
+
const plain = runtimeWith(undefined);
|
|
2344
|
+
const runtime = runtimeWith(good(), { player: { x: -30, z: 0 } });
|
|
2345
|
+
world.onRender = (level) => {
|
|
2346
|
+
if (level === 0) renderWorld(world, runtime);
|
|
2347
|
+
};
|
|
2348
|
+
renderWorld(world, plain);
|
|
2349
|
+
assert.deepEqual(world.draws.map((draw) => draw.sky), [0, 1], 'the frame inside is drawn with its sky, attached and detached by itself');
|
|
2350
|
+
assert.equal(world.sky.key, runtime.sky);
|
|
2351
|
+
settled(world, runtime, 'after');
|
|
2352
|
+
world.onRender = null;
|
|
2353
|
+
renderWorld(world, plain);
|
|
2354
|
+
assert.equal(world.sky, null, 'and the next frame of the scene without the key lets it go');
|
|
2355
|
+
settled(world, null, 'after the keyless frame');
|
|
2356
|
+
},
|
|
2357
|
+
|
|
2358
|
+
'two worlds: each its own sky, textures and fade'() {
|
|
2359
|
+
const a = skyWorld();
|
|
2360
|
+
const b = skyWorld();
|
|
2361
|
+
const one = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
2362
|
+
const two = runtimeWith(good(), { player: { x: 50, z: 0 } });
|
|
2363
|
+
renderWorld(a, one);
|
|
2364
|
+
renderWorld(b, two);
|
|
2365
|
+
assert.notEqual(a.sky.mesh, b.sky.mesh);
|
|
2366
|
+
assert.notEqual(a.sky.material, b.sky.material);
|
|
2367
|
+
one.moveTo(-18, 0);
|
|
2368
|
+
tick(0.3);
|
|
2369
|
+
renderWorld(a, one);
|
|
2370
|
+
renderWorld(b, two);
|
|
2371
|
+
assert.deepEqual([one.skyZone.id, one.skyZone.from, two.skyZone.id, two.skyZone.blend], ['hollow', 'square', 'sunny', 0]);
|
|
2372
|
+
disposeWorld(a);
|
|
2373
|
+
assert.equal(a.sky, null);
|
|
2374
|
+
assert.ok(b.sky);
|
|
2375
|
+
tick(0.1);
|
|
2376
|
+
renderWorld(b, two);
|
|
2377
|
+
assert.equal(two.skyZone.id, 'sunny');
|
|
2378
|
+
// One scene drawn by two worlds: each world steps its own fade.
|
|
2379
|
+
const c = skyWorld();
|
|
2380
|
+
renderWorld(c, two);
|
|
2381
|
+
assert.notEqual(c.sky, b.sky);
|
|
2382
|
+
assert.equal(c.sky.key, b.sky.key);
|
|
2383
|
+
},
|
|
2384
|
+
|
|
2385
|
+
'the runtime: `sky` and `skyZone` are latched by a load'() {
|
|
2386
|
+
const warnings = [];
|
|
2387
|
+
const warn = console.warn;
|
|
2388
|
+
console.warn = (message) => warnings.push(message);
|
|
2389
|
+
try {
|
|
2390
|
+
const plain = new SceneRuntime({ actors: [] }, [], {}, {});
|
|
2391
|
+
assert.equal(plain.sky, null);
|
|
2392
|
+
assert.equal(plain.skyZone, null);
|
|
2393
|
+
const runtime = new SceneRuntime({ engine: { sky: good() }, actors: [] }, [], {}, {});
|
|
2394
|
+
const key = runtime.sky;
|
|
2395
|
+
assert.equal(key.zones.length, 4);
|
|
2396
|
+
assert.equal(runtime.skyZone, key.zone);
|
|
2397
|
+
assert.equal(runtime.skyZone.id, 'square');
|
|
2398
|
+
assert.throws(() => {
|
|
2399
|
+
'use strict';
|
|
2400
|
+
runtime.skyZone = null;
|
|
2401
|
+
}, TypeError);
|
|
2402
|
+
assert.throws(() => {
|
|
2403
|
+
'use strict';
|
|
2404
|
+
runtime.skyZone.id = 'x';
|
|
2405
|
+
}, TypeError);
|
|
2406
|
+
// The scene's data changed after the load: the key is what the load read.
|
|
2407
|
+
runtime.data.engine.sky.zones.length = 0;
|
|
2408
|
+
assert.equal(runtime.sky, key);
|
|
2409
|
+
runtime.load({ engine: { sky: good({ fade: 3 }) }, actors: [] });
|
|
2410
|
+
assert.notEqual(runtime.sky, key);
|
|
2411
|
+
assert.equal(runtime.sky.fade, 3);
|
|
2412
|
+
runtime.load({ actors: [] });
|
|
2413
|
+
assert.equal(runtime.sky, null);
|
|
2414
|
+
assert.equal(runtime.skyZone, null);
|
|
2415
|
+
assert.equal(warnings.length, 0);
|
|
2416
|
+
runtime.load({ engine: { sky: { zones: [] } }, actors: [] });
|
|
2417
|
+
assert.equal(runtime.sky, null);
|
|
2418
|
+
assert.equal(runtime.skyZone, null);
|
|
2419
|
+
assert.equal(warnings.length, 1);
|
|
2420
|
+
// Through the real runtime and `renderWorld`: a Player's Transform decides.
|
|
2421
|
+
runtime.load({
|
|
2422
|
+
engine: { sky: good() },
|
|
2423
|
+
actors: [{ id: 'p', components: { Transform: { x: 60, y: 1, z: 0 }, Player: {} } }],
|
|
2424
|
+
});
|
|
2425
|
+
const world = skyWorld();
|
|
2426
|
+
renderWorld(world, runtime);
|
|
2427
|
+
assert.equal(runtime.skyZone.id, 'sunny');
|
|
2428
|
+
} finally {
|
|
2429
|
+
console.warn = warn;
|
|
2430
|
+
}
|
|
2431
|
+
},
|
|
2432
|
+
|
|
2433
|
+
'`renderWithSky` by its own clock argument'() {
|
|
2434
|
+
const world = skyWorld();
|
|
2435
|
+
const runtime = runtimeWith(good(), { player: { x: -16, z: 0 } });
|
|
2436
|
+
const draw = (w) => w.composer.render();
|
|
2437
|
+
renderWithSky(world, runtime, draw, 1000);
|
|
2438
|
+
runtime.moveTo(-18, 0);
|
|
2439
|
+
renderWithSky(world, runtime, draw, 1150);
|
|
2440
|
+
near(runtime.skyZone.blend, 0.1, '150 ms of 1.5 s');
|
|
2441
|
+
renderWithSky(world, runtime, draw, 900);
|
|
2442
|
+
near(runtime.skyZone.blend, 0.1, 'a clock that goes back moves nothing');
|
|
2443
|
+
},
|
|
2444
|
+
};
|
|
2445
|
+
|
|
2446
|
+
export async function run() {
|
|
2447
|
+
let count = 0;
|
|
2448
|
+
performance.now = () => clock;
|
|
2449
|
+
try {
|
|
2450
|
+
for (const [name, scenario] of Object.entries(scenarios)) {
|
|
2451
|
+
if (process.env.ONLY && !name.includes(process.env.ONLY)) continue;
|
|
2452
|
+
try {
|
|
2453
|
+
clock = 5000;
|
|
2454
|
+
await scenario();
|
|
2455
|
+
count += 1;
|
|
2456
|
+
} catch (err) {
|
|
2457
|
+
err.message = `${name}: ${err.message}`;
|
|
2458
|
+
throw err;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
} finally {
|
|
2462
|
+
performance.now = realNow;
|
|
2463
|
+
}
|
|
2464
|
+
return count;
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
if (process.argv[1] === new URL(import.meta.url).pathname) {
|
|
2468
|
+
console.log(`sky: ${await run()} scenarios, the postcondition held after ${framesChecked} outermost frames`);
|
|
2469
|
+
if (randomCoverage && process.env.COVERAGE) console.log(JSON.stringify(randomCoverage, null, 1));
|
|
2470
|
+
}
|