castle-web-cli 0.4.232 → 0.4.233
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/castle-host/host.d.ts +1 -0
- package/dist/castle-host/host.js +51 -3
- package/dist/castleJson.d.ts +4 -2
- package/dist/castleJson.js +2 -0
- package/dist/check.d.ts +3 -1
- package/dist/check.js +11 -1
- package/dist/devSessionStorage.js +47 -1
- 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 +5 -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 +5 -0
- package/dist/save-deck.js +37 -4
- package/dist/serve.js +3 -0
- package/dist/shell/assets/{index-D2tWM896.js → index-BjOxR-lW.js} +4 -4
- 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/kits/base/castle.json +1 -1
- package/kits/base/package-lock.json +1 -1
- package/kits/base/sdk/README.md +79 -2
- package/kits/base/sdk/avatar.d.ts +6 -2
- package/kits/base/sdk/avatar.js +12 -4
- package/kits/base/sdk/castle.d.ts +1 -1
- package/kits/base/sdk/commands.d.ts +14 -0
- package/kits/base/sdk/hub.d.ts +6 -2
- package/kits/base/sdk/hub.js +13 -0
- package/kits/base/sdk/multiplayer.js +17 -1
- package/kits/base/sdk/save.js +2 -1
- package/kits/base/sdk/server/hub.d.ts +87 -0
- package/kits/base/sdk/server/hub.js +70 -0
- package/kits/base/sdk/server/platformHandle.d.ts +31 -1
- package/kits/base/sdk/server/storage.d.ts +13 -0
- package/kits/base/sdk/server/storage.js +46 -0
- package/kits/base/sdk/server/wrapper.d.ts +36 -5
- package/kits/base/sdk/server/wrapper.js +83 -8
- package/kits/hub-game/CLAUDE.md +329 -11
- 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/code/client/actorBudget.js +47 -0
- package/kits/hub-game/code/client/attention.js +11 -2
- package/kits/hub-game/code/client/avatar.js +309 -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 +251 -0
- package/kits/hub-game/code/client/ballot.js +467 -0
- package/kits/hub-game/code/client/build.js +22 -0
- package/kits/hub-game/code/client/chrome.js +1144 -50
- 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/decor.js +509 -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/grab.js +339 -20
- package/kits/hub-game/code/client/hookLayer.js +299 -13
- package/kits/hub-game/code/client/idle.js +163 -22
- package/kits/hub-game/code/client/interestCap.js +81 -0
- package/kits/hub-game/code/client/keys.js +36 -0
- package/kits/hub-game/code/client/labelsNear.js +205 -0
- package/kits/hub-game/code/client/menuIcons.js +34 -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/rehello.js +167 -0
- package/kits/hub-game/code/client/shot.js +92 -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 +109 -1
- package/kits/hub-game/code/client/stuck.js +259 -0
- package/kits/hub-game/code/client/talk.js +538 -47
- package/kits/hub-game/code/client/tiers.js +516 -27
- package/kits/hub-game/code/client/toastBand.js +37 -0
- package/kits/hub-game/code/client/together.js +32 -0
- package/kits/hub-game/code/client/visibility.js +43 -0
- package/kits/hub-game/code/client/wear.js +461 -170
- package/kits/hub-game/code/client/yours.js +199 -0
- package/kits/hub-game/code/companionSpec.js +45 -0
- package/kits/hub-game/code/privateText.js +7 -0
- package/kits/hub-game/code/server/actions.js +133 -0
- package/kits/hub-game/code/server/actors.js +9 -1
- 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 +82 -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/earned.js +461 -0
- package/kits/hub-game/code/server/friendBests.js +166 -0
- package/kits/hub-game/code/server/friendsAmong.js +232 -0
- package/kits/hub-game/code/server/history.js +5 -0
- package/kits/hub-game/code/server/hub.js +1254 -50
- package/kits/hub-game/code/server/idle.js +30 -11
- package/kits/hub-game/code/server/index.js +2 -2
- package/kits/hub-game/code/server/labels.js +28 -2
- package/kits/hub-game/code/server/manifest.js +378 -7
- package/kits/hub-game/code/server/menu.js +133 -0
- package/kits/hub-game/code/server/npcs.js +830 -80
- package/kits/hub-game/code/server/party.js +2 -2
- package/kits/hub-game/code/server/players.js +22 -0
- package/kits/hub-game/code/server/shot.js +110 -0
- package/kits/hub-game/code/server/standing.js +124 -0
- package/kits/hub-game/code/server/vis.js +113 -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/cues.js +9 -0
- package/kits/hub-game/code/shared/decor.js +41 -0
- package/kits/hub-game/code/shared/shot.js +19 -0
- package/kits/hub-game/code/shared/spin.js +57 -0
- package/kits/hub-game/code/systems/hub.js +845 -95
- package/kits/hub-game/docs/content-pack.md +1 -1
- package/kits/hub-game/docs/contract.md +2244 -61
- package/kits/hub-game/docs/home-pieces.md +64 -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 +2 -0
- package/kits/hub-game/package.json +2 -1
- package/kits/hub-game/scripts/check.mjs +78 -11
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +121 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +293 -0
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +23 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +107 -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/soundscape-wave-analysis.mjs +125 -0
- package/kits/hub-game/scripts/test-actions-client.mjs +488 -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 +19 -17
- package/kits/hub-game/scripts/test-ask-client.mjs +358 -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 +753 -0
- package/kits/hub-game/scripts/test-avatar.mjs +540 -7
- package/kits/hub-game/scripts/test-ballot.mjs +1001 -0
- package/kits/hub-game/scripts/test-build.mjs +31 -0
- package/kits/hub-game/scripts/test-cells.mjs +71 -0
- package/kits/hub-game/scripts/test-chat.mjs +662 -0
- package/kits/hub-game/scripts/test-classic.mjs +2 -0
- package/kits/hub-game/scripts/test-companion-chat.mjs +198 -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-decor-client.mjs +303 -0
- package/kits/hub-game/scripts/test-decor.mjs +457 -0
- package/kits/hub-game/scripts/test-earned-client.mjs +459 -0
- package/kits/hub-game/scripts/test-earned.mjs +1194 -0
- package/kits/hub-game/scripts/test-emote-bubble.mjs +110 -0
- package/kits/hub-game/scripts/test-friend-bests.mjs +435 -0
- package/kits/hub-game/scripts/test-grab-orbit.mjs +918 -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-hub-leaving.mjs +203 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +439 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +716 -2
- package/kits/hub-game/scripts/test-hud-clear.mjs +328 -4
- package/kits/hub-game/scripts/test-idle.mjs +361 -1
- package/kits/hub-game/scripts/test-interest-cap.mjs +36 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +493 -0
- package/kits/hub-game/scripts/test-interest-client.mjs +118 -0
- package/kits/hub-game/scripts/test-keys.mjs +46 -1
- package/kits/hub-game/scripts/test-labels.mjs +596 -0
- package/kits/hub-game/scripts/test-manifest.mjs +207 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +480 -0
- package/kits/hub-game/scripts/test-menu.mjs +296 -0
- package/kits/hub-game/scripts/test-npcs.mjs +1718 -12
- package/kits/hub-game/scripts/test-object-entry.mjs +76 -0
- package/kits/hub-game/scripts/test-pack.mjs +7 -0
- package/kits/hub-game/scripts/test-picker.mjs +314 -0
- package/kits/hub-game/scripts/test-rehello.mjs +1039 -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-shot.mjs +756 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +5432 -0
- package/kits/hub-game/scripts/test-spin.mjs +314 -0
- package/kits/hub-game/scripts/test-standing.mjs +416 -0
- package/kits/hub-game/scripts/test-stuck.mjs +1903 -0
- package/kits/hub-game/scripts/test-tier-cells.mjs +706 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +339 -0
- package/kits/hub-game/scripts/test-tiers.mjs +477 -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 +343 -0
- package/kits/hub-game/scripts/test-visibility.mjs +134 -0
- package/kits/hub-game/scripts/test-yours-chrome.mjs +166 -0
- package/kits/hub-game/scripts/test-yours.mjs +372 -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/nameTags.js +59 -4
- 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 +74 -4
- package/kits/multiplayer-3d/package.json +2 -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-own-name-tag.mjs +247 -0
- package/kits/physics-2d/CLAUDE.md +9 -0
- package/kits/physics-2d/castle.json +2 -2
- package/kits/physics-2d/engine/scene.js +253 -1
- 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/scripts/test-skip-unchanged.mjs +326 -1
- package/kits/physics-3d/CLAUDE.md +1169 -30
- package/kits/physics-3d/behaviors/Player.jsx +629 -72
- package/kits/physics-3d/castle.json +3 -3
- package/kits/physics-3d/docs/pxmodel-format.md +8 -0
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +69 -13
- package/kits/physics-3d/engine3d/actornode.js +86 -0
- package/kits/physics-3d/engine3d/animationBudget.js +23 -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 +96 -0
- package/kits/physics-3d/engine3d/gait.js +118 -0
- package/kits/physics-3d/engine3d/kithooks.js +47 -0
- package/kits/physics-3d/engine3d/look.js +507 -48
- package/kits/physics-3d/engine3d/lookbake.js +208 -0
- package/kits/physics-3d/engine3d/materialpresets.js +2 -0
- package/kits/physics-3d/engine3d/motion.js +39 -10
- package/kits/physics-3d/engine3d/nearshadows.js +37 -19
- package/kits/physics-3d/engine3d/optimize.js +9 -5
- package/kits/physics-3d/engine3d/orbitinput.js +487 -9
- package/kits/physics-3d/engine3d/orbitlens.js +48 -0
- package/kits/physics-3d/engine3d/ownmodel.js +213 -0
- package/kits/physics-3d/engine3d/pxmodel.js +42 -11
- package/kits/physics-3d/engine3d/shadowfade.js +882 -0
- package/kits/physics-3d/engine3d/sky.js +547 -0
- package/kits/physics-3d/engine3d/skylife.js +306 -0
- 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 +796 -69
- package/kits/physics-3d/main.jsx +5 -0
- package/kits/physics-3d/package.json +1 -1
- package/kits/physics-3d/scripts/look-baseline.mjs +155 -0
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +2563 -80
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +435 -0
- package/kits/physics-3d/scripts/test-frame-cap.mjs +452 -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 +3 -0
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +1920 -0
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +545 -0
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +583 -0
- package/kits/physics-3d/scripts/test-orbit-view.mjs +230 -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-static-actors.mjs +8 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +2171 -0
- package/kits/physics-3d/scripts/test-steady-hover.mjs +2 -0
- package/kits/physics-3d/scripts/test-view-range.mjs +260 -0
- package/kits/physics-3d/systems/physics3d.js +383 -6
- package/kits/real-time/castle.json +2 -2
- package/kits/real-time/code/server/gameHooks.js +7 -0
- package/kits/real-time/code/server/session.js +97 -19
- package/package.json +2 -2
- package/dist/shell/assets/index-Cf61cNfT.css +0 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Cues and action edges (v1.50), only in a deck with soundscape.cues.
|
|
2
|
+
// Private actions are processed before nearby players or actor broadcasts.
|
|
3
|
+
// Quiet, expired and distant state is consumed, never replayed on return.
|
|
4
|
+
import { hub, simNow } from './state.js';
|
|
5
|
+
import { CUE_NAMES } from '../shared/cues.js';
|
|
6
|
+
import { isBuskerCue } from './soundscapeBusker.js';
|
|
7
|
+
import { CUE_VOICES, ACTION_VOICES } from './soundscapeCues.js';
|
|
8
|
+
|
|
9
|
+
export function distanceGain(a, b, radius) {
|
|
10
|
+
if (!a || !b || (!Number.isFinite(a.x) || !Number.isFinite(a.y) || !Number.isFinite(a.z) || !Number.isFinite(b.x) || !Number.isFinite(b.y) || !Number.isFinite(b.z) || !Number.isFinite(radius)) || radius < 1 || radius > 60) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
return Math.max(0, 1 - Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z) / radius);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function makeActions(ui, voices = CUE_VOICES, busker = null) {
|
|
17
|
+
const seen = new Map();
|
|
18
|
+
let sceneWas = null;
|
|
19
|
+
let panelWas = null;
|
|
20
|
+
let first = false;
|
|
21
|
+
let me = null;
|
|
22
|
+
let simulation = 0;
|
|
23
|
+
let now = 0;
|
|
24
|
+
let on = false;
|
|
25
|
+
const play = (name, gain, priority, table) => {
|
|
26
|
+
if (on && typeof name === 'string' && Object.hasOwn(table, name)) {
|
|
27
|
+
ui.play(name, table[name], now, gain, priority);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const player = (id, actor, own) => {
|
|
31
|
+
let was = seen.get(id);
|
|
32
|
+
if (!was) {
|
|
33
|
+
was = { emote: null, at: null, seat: null };
|
|
34
|
+
seen.set(id, was);
|
|
35
|
+
}
|
|
36
|
+
const e = Object.hasOwn(hub.emotes, id) ? hub.emotes[id] : null;
|
|
37
|
+
const seat = Object.hasOwn(hub.seated, id) && typeof hub.seated[id] === 'string' ? hub.seated[id] : null;
|
|
38
|
+
const at = actor?.components.Transform;
|
|
39
|
+
const gain = !actor || hub.hidden.has(actor.id) ? 0 : own ? 1 : distanceGain(me, at, 12);
|
|
40
|
+
if (!first && e && (was.emote !== e.id || was.at !== e.at) && Number.isFinite(e.at) && Number.isFinite(e.until) && simulation >= e.at && simulation < e.until) {
|
|
41
|
+
play(e.id, gain, own ? 2 : 1, ACTION_VOICES);
|
|
42
|
+
}
|
|
43
|
+
if (!first && seat && seat !== was.seat) {
|
|
44
|
+
play('sit', gain, own ? 2 : 1, ACTION_VOICES);
|
|
45
|
+
}
|
|
46
|
+
was.emote = e?.id ?? null;
|
|
47
|
+
was.at = e?.at ?? null;
|
|
48
|
+
was.seat = seat;
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
frame(scene, mp, local, panel, frameNow, live) {
|
|
52
|
+
now = frameNow;
|
|
53
|
+
on = live;
|
|
54
|
+
first = sceneWas !== scene;
|
|
55
|
+
if (first) {
|
|
56
|
+
seen.clear();
|
|
57
|
+
panelWas = null;
|
|
58
|
+
sceneWas = scene;
|
|
59
|
+
}
|
|
60
|
+
const self = mp?.net?.selfId?.() ?? null;
|
|
61
|
+
me = local?.components.Transform;
|
|
62
|
+
simulation = simNow();
|
|
63
|
+
const events = hub.cueEvents;
|
|
64
|
+
if (self) { player(self, local, true); }
|
|
65
|
+
if (!first && panel && panel !== panelWas) { play('chat', 1, 2, ACTION_VOICES); }
|
|
66
|
+
panelWas = panel;
|
|
67
|
+
if (events) {
|
|
68
|
+
for (let i = 0; i < events.length; i += 1) {
|
|
69
|
+
const e = events[i];
|
|
70
|
+
if (e && !Object.hasOwn(e, 'actor') && CUE_NAMES.includes(e.cue)) {
|
|
71
|
+
if (isBuskerCue(e.cue)) { busker?.receive(e, now, on); }
|
|
72
|
+
else { play(e.cue, 1, 2, voices); }
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const avatars = mp?.avatars?.actors;
|
|
77
|
+
if (avatars) {
|
|
78
|
+
for (const [id, actorId] of avatars) {
|
|
79
|
+
if (id !== self) { player(id, scene.getActor(actorId), false); }
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (events) {
|
|
83
|
+
for (let i = 0; i < events.length; i += 1) {
|
|
84
|
+
const e = events[i];
|
|
85
|
+
if (e && Object.hasOwn(e, 'actor') && CUE_NAMES.includes(e.cue)) {
|
|
86
|
+
if (isBuskerCue(e.cue)) { busker?.receive(e, now, on); continue; }
|
|
87
|
+
if (hub.hidden.has(e.actor)) { continue; }
|
|
88
|
+
const at = typeof e.actor === 'string' ? scene.getActor(e.actor)?.components.Transform : null;
|
|
89
|
+
play(e.cue, distanceGain(me, at, e.radius), 1, voices);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
events.length = 0;
|
|
93
|
+
}
|
|
94
|
+
for (const id of seen.keys()) {
|
|
95
|
+
if (id !== self && !avatars?.has(id)) { seen.delete(id); }
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
// Synthesised beds: light live graphs, baked heavy generators, and optional
|
|
2
|
+
// live seeded music. All clocks are the context's; frame is the scheduler.
|
|
3
|
+
|
|
4
|
+
import { makeZoneMusic, ZONE_SONGS } from './soundscapeMusic.js';
|
|
5
|
+
import { HARBOUR_WAVE_RMS } from './soundscapeWaves.js';
|
|
6
|
+
import { bakeBed, makeBedGenerator, offlineFactory, pauseBedBakes, LOOP_S } from './soundscapeBaked.js';
|
|
7
|
+
import { tracked } from './soundscapeSynthesis.js';
|
|
8
|
+
|
|
9
|
+
const MUSIC_LEVEL = 0.0141804316 * 10 ** (1 / 20);
|
|
10
|
+
|
|
11
|
+
// All six beds now land 8 dB above the old -41 dBFS target, about -33
|
|
12
|
+
// active RMS at volume 0.7. Music is 9 dB above its old -47 dBFS pre-bus
|
|
13
|
+
// calibration target, sitting roughly level with the beds; song calibration
|
|
14
|
+
// preserves each track mix. All music has the same pre-bus RMS target,
|
|
15
|
+
// including the legacy market tune.
|
|
16
|
+
// Modulation and calls rise with their bed; market keeps the 0.45 spot mix.
|
|
17
|
+
// Harbour and crowd carry a correction measured by an offline render of the
|
|
18
|
+
// whole chain (2144c68d) so they land on the square's active RMS (formerly
|
|
19
|
+
// -41.26, now about -33.26); market speakers stay ~1.7 dB under it, as a distant spot.
|
|
20
|
+
export const AMBIENCE_LEVELS = {
|
|
21
|
+
square: { bed: 0.1503, modulation: 0.0451, music: MUSIC_LEVEL },
|
|
22
|
+
meadow: { bed: 0.1159, modulation: 0.0331, call: 0.0530, music: MUSIC_LEVEL },
|
|
23
|
+
night: { bed: 0.1842, modulation: 0.0603, call: 0.0837, music: MUSIC_LEVEL },
|
|
24
|
+
harbour: { bed: 0.7328 * 10 ** (-41 / 20) / (0.315 * HARBOUR_WAVE_RMS), music: MUSIC_LEVEL },
|
|
25
|
+
// Crowd A's audition WAV active RMS (2048-sample windows within 20 dB
|
|
26
|
+
// of the loudest), undoing its reported +1.2 dB normaliser gain.
|
|
27
|
+
// The bed level applies only at the output, preserving voice/clap balance.
|
|
28
|
+
crowd: { bed: 1.0568 * 10 ** (-41 / 20) / (0.315 * (0.0598642507 / 10 ** (1.2 / 20))), music: MUSIC_LEVEL },
|
|
29
|
+
market: { bed: 10 ** (-41 / 20) / 0.315, music: MUSIC_LEVEL },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// Filter, level, modulation rate/depth, animal pitch, note root, scale,
|
|
33
|
+
// seconds per note, waveform. Eight notes form a bar, six in the harbour.
|
|
34
|
+
export const BEDS = {
|
|
35
|
+
square: [480, AMBIENCE_LEVELS.square.bed, 0.09, AMBIENCE_LEVELS.square.modulation, 0, 196, [0, 2, 4, 7, 9], 0.9, 'sine'],
|
|
36
|
+
meadow: [850, AMBIENCE_LEVELS.meadow.bed, 0.13, AMBIENCE_LEVELS.meadow.modulation, 2400, 220, [0, 2, 4, 7, 9], 0.65, 'triangle'],
|
|
37
|
+
night: [260, AMBIENCE_LEVELS.night.bed, 0.07, AMBIENCE_LEVELS.night.modulation, 370, 146.83, [0, 3, 5, 7, 10], 1.8, 'sine'],
|
|
38
|
+
harbour: [700, AMBIENCE_LEVELS.harbour.bed, 0.28, 0.025, 1100, 174.61, [0, 2, 5, 7, 9], 0.6, 'sine'],
|
|
39
|
+
crowd: [620, AMBIENCE_LEVELS.crowd.bed, 0.045, AMBIENCE_LEVELS.crowd.modulation, 0, 98, [0, 7], 1.2, 'sine'],
|
|
40
|
+
market: [740, AMBIENCE_LEVELS.market.bed, 0.37, 180, 0, 164.81, [0, 2, 5, 7, 10], 1.1, 'triangle'],
|
|
41
|
+
};
|
|
42
|
+
const FADE_S = 1.5;
|
|
43
|
+
|
|
44
|
+
function release(nodes) {
|
|
45
|
+
for (const node of nodes) {
|
|
46
|
+
try {
|
|
47
|
+
node.stop?.();
|
|
48
|
+
} catch {
|
|
49
|
+
// Already over, or not started.
|
|
50
|
+
}
|
|
51
|
+
node.disconnect();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function liveGenerator(ctx, bed, output = bed.air) {
|
|
56
|
+
const generator = makeBedGenerator(tracked(ctx, bed.nodes), output, bed.name, bed.levels.bed);
|
|
57
|
+
if (bed.name === 'harbour') {
|
|
58
|
+
bed.waves = generator;
|
|
59
|
+
} else {
|
|
60
|
+
bed.generator = generator;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function makeBed(ctx, bus, name, music, noise, next, musicSeed, deps, requestBake) {
|
|
65
|
+
const p = Object.hasOwn(BEDS, name) ? BEDS[name] : null;
|
|
66
|
+
if (!p) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const nodes = [];
|
|
70
|
+
const made = (node) => { nodes.push(node); return node; };
|
|
71
|
+
try {
|
|
72
|
+
const mix = made(ctx.createGain());
|
|
73
|
+
mix.gain.value = 0;
|
|
74
|
+
mix.connect(bus);
|
|
75
|
+
const air = made(ctx.createGain());
|
|
76
|
+
air.connect(mix);
|
|
77
|
+
const levels = AMBIENCE_LEVELS[name];
|
|
78
|
+
const bed = { name, nodes, mix, air, levels, p, next, animal: null, animalAt: ctx.currentTime + 3 + next() * 8, noteAt: ctx.currentTime + 0.03, note: 0, pattern: [], fade: null, gain: 0, ducked: null };
|
|
79
|
+
if (Object.hasOwn(LOOP_S, name)) {
|
|
80
|
+
const factory = offlineFactory(deps.createOfflineContext, deps.win);
|
|
81
|
+
if (factory) {
|
|
82
|
+
bed.baked = true;
|
|
83
|
+
// Completion only hands the buffer to the frame scheduler. It never
|
|
84
|
+
// creates live nodes after quiet/dispose, or outside the sound gate.
|
|
85
|
+
requestBake(name, factory).then((buffer) => {
|
|
86
|
+
if (!bed.stopped) {
|
|
87
|
+
bed.buffer = buffer;
|
|
88
|
+
}
|
|
89
|
+
}, () => {
|
|
90
|
+
if (!bed.stopped) {
|
|
91
|
+
bed.livePending = true;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
} else {
|
|
95
|
+
liveGenerator(ctx, bed);
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
const src = made(ctx.createBufferSource());
|
|
99
|
+
src.buffer = noise(ctx);
|
|
100
|
+
src.loop = true;
|
|
101
|
+
const filter = made(ctx.createBiquadFilter());
|
|
102
|
+
filter.type = name === 'crowd' || name === 'market' ? 'bandpass' : 'lowpass';
|
|
103
|
+
filter.frequency.value = p[0];
|
|
104
|
+
filter.Q.value = name === 'market' ? 1.8 : 0.6;
|
|
105
|
+
const level = made(ctx.createGain());
|
|
106
|
+
level.gain.value = p[1];
|
|
107
|
+
src.connect(filter);
|
|
108
|
+
filter.connect(level);
|
|
109
|
+
level.connect(air);
|
|
110
|
+
const lfo = made(ctx.createOscillator());
|
|
111
|
+
lfo.frequency.value = p[2];
|
|
112
|
+
const depth = made(ctx.createGain());
|
|
113
|
+
depth.gain.value = p[3];
|
|
114
|
+
lfo.connect(depth);
|
|
115
|
+
depth.connect(name === 'market' ? filter.frequency : level.gain);
|
|
116
|
+
src.start();
|
|
117
|
+
lfo.start();
|
|
118
|
+
bed.level = level;
|
|
119
|
+
}
|
|
120
|
+
if (music && Object.hasOwn(ZONE_SONGS, name)) {
|
|
121
|
+
const duck = made(ctx.createGain());
|
|
122
|
+
duck.connect(mix);
|
|
123
|
+
if (name === 'night') {
|
|
124
|
+
for (let i = 0; i < 8; i += 1) {
|
|
125
|
+
bed.pattern.push(p[6][Math.floor(next() * p[6].length)]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
bed.music = { duck, player: makeZoneMusic(tracked(ctx, nodes), duck, name, levels.music, musicSeed, bed.pattern) };
|
|
129
|
+
} else if (music) {
|
|
130
|
+
const osc = made(ctx.createOscillator());
|
|
131
|
+
osc.type = p[8];
|
|
132
|
+
const env = made(ctx.createGain());
|
|
133
|
+
env.gain.value = 0;
|
|
134
|
+
const duck = made(ctx.createGain());
|
|
135
|
+
osc.connect(env);
|
|
136
|
+
env.connect(duck);
|
|
137
|
+
duck.connect(mix);
|
|
138
|
+
osc.start();
|
|
139
|
+
bed.music = { osc, env, duck };
|
|
140
|
+
for (let i = 0; i < (name === 'harbour' ? 6 : 8); i += 1) {
|
|
141
|
+
bed.pattern.push(p[6][Math.floor(next() * p[6].length)]);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return bed;
|
|
145
|
+
} catch (err) {
|
|
146
|
+
release(nodes);
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function stopAnimal(bed) {
|
|
152
|
+
if (bed.animal) {
|
|
153
|
+
release(bed.animal.nodes);
|
|
154
|
+
bed.animal = null;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function stopBed(bed) {
|
|
159
|
+
if (bed) {
|
|
160
|
+
bed.stopped = true;
|
|
161
|
+
stopAnimal(bed);
|
|
162
|
+
bed.waves?.stop();
|
|
163
|
+
bed.generator?.stop();
|
|
164
|
+
bed.music?.player?.stop();
|
|
165
|
+
release(bed.nodes);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function gainNow(bed, t) {
|
|
170
|
+
if (bed.baked && !bed.source) {
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
const f = bed.fade;
|
|
174
|
+
if (!f) {
|
|
175
|
+
return bed.gain;
|
|
176
|
+
}
|
|
177
|
+
const u = Math.max(0, Math.min(1, (t - f.at) / FADE_S));
|
|
178
|
+
return Math.sqrt(f.from * f.from * (1 - u) + f.to * f.to * u);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Four ramps approximate equal power. Interrupted fades start where they
|
|
182
|
+
// stand, including a reversal onto the bed already fading away.
|
|
183
|
+
function fade(bed, to, t) {
|
|
184
|
+
const from = gainNow(bed, t);
|
|
185
|
+
const gain = bed.mix.gain;
|
|
186
|
+
gain.cancelScheduledValues(t);
|
|
187
|
+
gain.setValueAtTime(from, t);
|
|
188
|
+
const audibleTo = bed.baked && !bed.source ? 0 : to;
|
|
189
|
+
for (let i = 1; i <= 4; i += 1) {
|
|
190
|
+
gain.linearRampToValueAtTime(Math.sqrt(from * from * (1 - i / 4) + audibleTo * audibleTo * i / 4), t + FADE_S * i / 4);
|
|
191
|
+
}
|
|
192
|
+
bed.fade = { from, to, at: t };
|
|
193
|
+
bed.gain = to;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function duck(bed, on, t) {
|
|
197
|
+
if (bed.ducked !== on) {
|
|
198
|
+
bed.ducked = on;
|
|
199
|
+
bed.air.gain.setTargetAtTime(on ? 0.35 : 1, t, 0.2);
|
|
200
|
+
bed.music?.duck.gain.setTargetAtTime(on ? 0 : 1, t, 0.2);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function animal(ctx, bed, t) {
|
|
205
|
+
const nodes = [];
|
|
206
|
+
try {
|
|
207
|
+
const osc = ctx.createOscillator();
|
|
208
|
+
nodes.push(osc);
|
|
209
|
+
const env = ctx.createGain();
|
|
210
|
+
nodes.push(env);
|
|
211
|
+
env.gain.value = 0;
|
|
212
|
+
osc.connect(env);
|
|
213
|
+
env.connect(bed.air);
|
|
214
|
+
const night = bed.name === 'night';
|
|
215
|
+
const gull = bed.name === 'harbour';
|
|
216
|
+
const length = night ? 1.3 : gull ? 0.8 : 0.45;
|
|
217
|
+
const pitch = bed.p[4] * (0.9 + bed.next() * 0.2);
|
|
218
|
+
osc.type = gull ? 'triangle' : 'sine';
|
|
219
|
+
for (let i = 0; i < (night ? 2 : 3); i += 1) {
|
|
220
|
+
const at = t + i * length / 3;
|
|
221
|
+
osc.frequency.setValueAtTime(pitch, at);
|
|
222
|
+
osc.frequency.exponentialRampToValueAtTime(pitch * (night ? 0.84 : gull ? 0.65 : 1.45), at + length / 4);
|
|
223
|
+
env.gain.setValueAtTime(0, at);
|
|
224
|
+
env.gain.linearRampToValueAtTime(bed.levels.call, at + 0.025);
|
|
225
|
+
env.gain.linearRampToValueAtTime(0, at + length / 4);
|
|
226
|
+
}
|
|
227
|
+
const shot = { nodes, until: t + length };
|
|
228
|
+
bed.animal = shot;
|
|
229
|
+
osc.onended = () => {
|
|
230
|
+
if (bed.animal === shot) {
|
|
231
|
+
stopAnimal(bed);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
osc.start(t);
|
|
235
|
+
osc.stop(t + length);
|
|
236
|
+
} catch (err) {
|
|
237
|
+
release(nodes);
|
|
238
|
+
throw err;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function startReadyBed(ctx, bed, t) {
|
|
243
|
+
const nodes = [];
|
|
244
|
+
try {
|
|
245
|
+
if (bed.livePending) {
|
|
246
|
+
let output = bed.air;
|
|
247
|
+
if (bed.spot) {
|
|
248
|
+
// Distance owns mix.gain; readiness fades on a separate unit gain.
|
|
249
|
+
const startup = ctx.createGain();
|
|
250
|
+
nodes.push(startup);
|
|
251
|
+
startup.gain.setValueAtTime(0, t);
|
|
252
|
+
for (let i = 1; i <= 4; i += 1) {
|
|
253
|
+
startup.gain.linearRampToValueAtTime(Math.sqrt(i / 4), t + FADE_S * i / 4);
|
|
254
|
+
}
|
|
255
|
+
startup.connect(bed.air);
|
|
256
|
+
output = startup;
|
|
257
|
+
}
|
|
258
|
+
const generator = makeBedGenerator(tracked(ctx, nodes), output, bed.name, bed.levels.bed);
|
|
259
|
+
if (bed.name === 'harbour') {
|
|
260
|
+
bed.waves = generator;
|
|
261
|
+
} else {
|
|
262
|
+
bed.generator = generator;
|
|
263
|
+
}
|
|
264
|
+
bed.livePending = false;
|
|
265
|
+
bed.baked = false;
|
|
266
|
+
} else {
|
|
267
|
+
const source = ctx.createBufferSource();
|
|
268
|
+
nodes.push(source);
|
|
269
|
+
const level = ctx.createGain();
|
|
270
|
+
nodes.push(level);
|
|
271
|
+
source.buffer = bed.buffer;
|
|
272
|
+
source.loop = true;
|
|
273
|
+
// Unit render already includes .5 crowd, .9/MARKET_RMS market and
|
|
274
|
+
// harbour's own calibration. Only the external bed level belongs here.
|
|
275
|
+
level.gain.value = bed.levels.bed;
|
|
276
|
+
if (bed.spot) {
|
|
277
|
+
level.gain.setValueAtTime(0, t);
|
|
278
|
+
for (let i = 1; i <= 4; i += 1) {
|
|
279
|
+
level.gain.linearRampToValueAtTime(bed.levels.bed * Math.sqrt(i / 4), t + FADE_S * i / 4);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
source.connect(level);
|
|
283
|
+
level.connect(bed.air);
|
|
284
|
+
source.start(t, bed.next() * bed.buffer.duration);
|
|
285
|
+
bed.source = source;
|
|
286
|
+
}
|
|
287
|
+
} catch (err) {
|
|
288
|
+
bed.failed = true;
|
|
289
|
+
release(nodes);
|
|
290
|
+
// The soundscape frame reports this through its existing failure path.
|
|
291
|
+
throw err;
|
|
292
|
+
}
|
|
293
|
+
bed.nodes.push(...nodes);
|
|
294
|
+
if (!bed.spot) {
|
|
295
|
+
const target = bed.gain;
|
|
296
|
+
bed.fade = null;
|
|
297
|
+
bed.gain = 0;
|
|
298
|
+
fade(bed, target, t);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function schedule(ctx, bed, t) {
|
|
303
|
+
if (bed.failed) { return; }
|
|
304
|
+
if ((bed.livePending || (bed.buffer && !bed.source)) && bed.gain > 0) {
|
|
305
|
+
startReadyBed(ctx, bed, t);
|
|
306
|
+
}
|
|
307
|
+
bed.waves?.frame(t);
|
|
308
|
+
bed.generator?.frame(t);
|
|
309
|
+
if (bed.animal && bed.animal.until <= t) {
|
|
310
|
+
stopAnimal(bed);
|
|
311
|
+
}
|
|
312
|
+
if (!bed.baked && !bed.waves && !bed.generator && t >= bed.animalAt) {
|
|
313
|
+
bed.animalAt = t + (bed.name === 'night' ? 18 : 5) + bed.next() * 16;
|
|
314
|
+
if (bed.p[4] && !bed.animal) {
|
|
315
|
+
animal(ctx, bed, t + 0.02);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!bed.music) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (bed.music.player) {
|
|
322
|
+
bed.music.player.frame(t);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const slot = bed.p[7];
|
|
326
|
+
// A long frame discards missed notes. At most one bar is ever ahead.
|
|
327
|
+
if (bed.noteAt < t) {
|
|
328
|
+
bed.noteAt = t + 0.03;
|
|
329
|
+
}
|
|
330
|
+
while (bed.noteAt < t + slot * bed.pattern.length) {
|
|
331
|
+
const at = bed.noteAt;
|
|
332
|
+
const index = bed.note++ % bed.pattern.length;
|
|
333
|
+
const note = bed.pattern[index];
|
|
334
|
+
const duration = slot * 0.85;
|
|
335
|
+
const pad = bed.name === 'night';
|
|
336
|
+
bed.music.osc.frequency.setValueAtTime(bed.p[5] * 2 ** (note / 12), at);
|
|
337
|
+
bed.music.env.gain.setValueAtTime(0, at);
|
|
338
|
+
const accent = bed.name === 'harbour' ? (index % 3 === 0 ? 1 : 0.65) : 1;
|
|
339
|
+
bed.music.env.gain.linearRampToValueAtTime(bed.levels.music / Math.sqrt(0.85 / 9) * accent, at + (pad ? duration * 0.4 : 0.025));
|
|
340
|
+
bed.music.env.gain.linearRampToValueAtTime(0, at + duration);
|
|
341
|
+
bed.noteAt += slot;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function makeAmbience(options, deps) {
|
|
346
|
+
const { noise, seeded, hash, loudestLoop, random = Math.random } = deps;
|
|
347
|
+
const draw = options.music === true ? random() : 0;
|
|
348
|
+
const sessionSeed = Number.isFinite(draw) ? Math.floor(draw * 4294967296) >>> 0 : 1;
|
|
349
|
+
let current = null;
|
|
350
|
+
let old = null;
|
|
351
|
+
let spot = null;
|
|
352
|
+
let spotGain = 0;
|
|
353
|
+
let context = null;
|
|
354
|
+
let ducked = false;
|
|
355
|
+
let sounding = false;
|
|
356
|
+
const canBake = () => sounding && (deps.canBake?.() ?? true);
|
|
357
|
+
const requested = new Set();
|
|
358
|
+
const requestBake = (name, factory, first = false) => {
|
|
359
|
+
const promise = bakeBed(context, name, factory, canBake, first);
|
|
360
|
+
if (!requested.has(name)) {
|
|
361
|
+
requested.add(name);
|
|
362
|
+
// Prewarming has no live graph to fall back to; makeBed handles failure
|
|
363
|
+
// only if this bed is subsequently selected inside an audible frame.
|
|
364
|
+
promise.catch(() => {});
|
|
365
|
+
}
|
|
366
|
+
return promise;
|
|
367
|
+
};
|
|
368
|
+
const referenced = [...new Set([options.default, ...Object.values(options.beds ?? {}), ...Object.values(options.spots ?? {})])]
|
|
369
|
+
.filter((name) => Object.hasOwn(LOOP_S, name));
|
|
370
|
+
const clear = () => {
|
|
371
|
+
sounding = false;
|
|
372
|
+
pauseBedBakes(context, canBake);
|
|
373
|
+
stopBed(current);
|
|
374
|
+
stopBed(old);
|
|
375
|
+
stopBed(spot);
|
|
376
|
+
current = old = spot = null;
|
|
377
|
+
spotGain = 0;
|
|
378
|
+
ducked = false;
|
|
379
|
+
};
|
|
380
|
+
return {
|
|
381
|
+
quiet: clear,
|
|
382
|
+
frame(ctx, bus, name, near) {
|
|
383
|
+
if (context !== ctx) {
|
|
384
|
+
clear();
|
|
385
|
+
context = ctx;
|
|
386
|
+
requested.clear();
|
|
387
|
+
}
|
|
388
|
+
sounding = true;
|
|
389
|
+
const factory = offlineFactory(deps.createOfflineContext, deps.win);
|
|
390
|
+
if (factory) {
|
|
391
|
+
// Current zone first, then only the heavy beds declared by this deck.
|
|
392
|
+
// Direct callers may also select a zone/spot without mapped options.
|
|
393
|
+
for (const bed of new Set([name, ...referenced, near.bed])) {
|
|
394
|
+
if (Object.hasOwn(LOOP_S, bed)) { requestBake(bed, factory, bed === name); }
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
const t = ctx.currentTime;
|
|
398
|
+
if (old?.fade && t >= old.fade.at + FADE_S) {
|
|
399
|
+
stopBed(old);
|
|
400
|
+
old = null;
|
|
401
|
+
}
|
|
402
|
+
if (current?.name !== name && (current || name)) {
|
|
403
|
+
const reuse = old?.name === name ? old : null;
|
|
404
|
+
if (old && !reuse) {
|
|
405
|
+
stopBed(old);
|
|
406
|
+
}
|
|
407
|
+
old = current;
|
|
408
|
+
current = reuse;
|
|
409
|
+
if (old) {
|
|
410
|
+
fade(old, 0, t);
|
|
411
|
+
}
|
|
412
|
+
if (!current && Object.hasOwn(BEDS, name)) {
|
|
413
|
+
current = makeBed(ctx, bus, name, options.music === true, noise, seeded(hash(name)), sessionSeed ^ hash(name), deps, requestBake);
|
|
414
|
+
}
|
|
415
|
+
if (current) {
|
|
416
|
+
fade(current, 1, t);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
if (spot?.name !== near.bed) {
|
|
420
|
+
stopBed(spot);
|
|
421
|
+
spot = Object.hasOwn(BEDS, near.bed) ? makeBed(ctx, bus, near.bed, false, noise, seeded(hash(`spot|${near.bed}`)), undefined, deps, requestBake) : null;
|
|
422
|
+
if (spot) {
|
|
423
|
+
spot.spot = true;
|
|
424
|
+
}
|
|
425
|
+
spotGain = -1;
|
|
426
|
+
}
|
|
427
|
+
if (spot && Math.abs(near.gain - spotGain) > 0.005) {
|
|
428
|
+
spotGain = near.gain;
|
|
429
|
+
spot.gain = spotGain;
|
|
430
|
+
spot.mix.gain.setTargetAtTime(spotGain, t, 0.08);
|
|
431
|
+
}
|
|
432
|
+
const loop = loudestLoop();
|
|
433
|
+
if (loop >= 0.06) {
|
|
434
|
+
ducked = true;
|
|
435
|
+
} else if (loop <= 0.03) {
|
|
436
|
+
ducked = false;
|
|
437
|
+
}
|
|
438
|
+
if (current) {
|
|
439
|
+
duck(current, ducked, t);
|
|
440
|
+
schedule(ctx, current, t);
|
|
441
|
+
}
|
|
442
|
+
if (old) {
|
|
443
|
+
duck(old, ducked, t);
|
|
444
|
+
schedule(ctx, old, t);
|
|
445
|
+
}
|
|
446
|
+
if (spot) {
|
|
447
|
+
duck(spot, ducked, t);
|
|
448
|
+
schedule(ctx, spot, t);
|
|
449
|
+
}
|
|
450
|
+
},
|
|
451
|
+
counts: () => ({ beds: Number(Boolean(current)) + Number(Boolean(old)), spot: Number(Boolean(spot)), nodes: (current?.nodes.length ?? 0) + (old?.nodes.length ?? 0) + (spot?.nodes.length ?? 0) + (current?.animal?.nodes.length ?? 0) + (old?.animal?.nodes.length ?? 0) + (spot?.animal?.nodes.length ?? 0), bed: current?.name ?? null, spotGain, ...(current?.music?.player ? { music: current.music.player.state() } : {}), ...(current?.name === 'market' ? { market: current.generator?.state() ?? { baked: true, ready: Boolean(current.source) } } : {}), ...(spot?.name === 'market' ? { marketSpot: spot.generator?.state() ?? { baked: true, ready: Boolean(spot.source) } } : {}) }),
|
|
452
|
+
};
|
|
453
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
// Referenced heavy ambience beds bake serially behind the sound gate. Music stays live.
|
|
2
|
+
import { makeStadiumCrowd } from './soundscapeCrowd.js';
|
|
3
|
+
import { makeMarketTalk } from './soundscapeMarket.js';
|
|
4
|
+
import { makeHarbour } from './soundscapeWaves.js';
|
|
5
|
+
import { tracked, release } from './soundscapeSynthesis.js';
|
|
6
|
+
|
|
7
|
+
export const LOOP_S = { crowd: 40, market: 60, harbour: 48 };
|
|
8
|
+
export const XFADE_S = 3;
|
|
9
|
+
export const LEAD_IN_S = 8;
|
|
10
|
+
// Harbour's per-sample white noise must retain the live rate: reducing it
|
|
11
|
+
// packs more power into the wash low-passes and changes the calibrated RMS.
|
|
12
|
+
export const RATE = { crowd: 24000, market: 24000, harbour: null };
|
|
13
|
+
// Keep the original frame cadence and suspend-quantum clock for seeded draws,
|
|
14
|
+
// but schedule the entire fixed-pool graph before rendering: no suspends.
|
|
15
|
+
export const FRAME_S = 1 / 30;
|
|
16
|
+
const buffers = new WeakMap();
|
|
17
|
+
|
|
18
|
+
// Chromium truncates the requested sample frame before rounding UP to the
|
|
19
|
+
// next render quantum; rounding the time directly can select a later quantum.
|
|
20
|
+
export function quantiseSuspendTime(time, rate) {
|
|
21
|
+
const frame = Math.floor(time * rate);
|
|
22
|
+
return Math.ceil(frame / 128) * 128 / rate;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function makeBedGenerator(ctx, destination, kind, level) {
|
|
26
|
+
if (kind === 'crowd') {
|
|
27
|
+
return makeStadiumCrowd(ctx, destination, 'A', 0xc20d, level);
|
|
28
|
+
}
|
|
29
|
+
if (kind === 'market') {
|
|
30
|
+
return makeMarketTalk(ctx, destination, 'A', 0x3a7, level);
|
|
31
|
+
}
|
|
32
|
+
return makeHarbour(ctx, destination, 'A-rolled', 0x5ea, level);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function offlineFactory(injected, win = globalThis.window) {
|
|
36
|
+
if (injected) {
|
|
37
|
+
return injected;
|
|
38
|
+
}
|
|
39
|
+
const Ctor = win?.OfflineAudioContext ?? win?.webkitOfflineAudioContext;
|
|
40
|
+
return Ctor ? (channels, length, sampleRate) => new Ctor(channels, length, sampleRate) : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// The extra tail continues across the wrap into the start, then gives way
|
|
44
|
+
// to the original start. The two endpoints follow the same sample stream;
|
|
45
|
+
// cos/sin weights preserve power for uncorrelated parts of the bed.
|
|
46
|
+
export function seamlessLoop(context, rendered, loopS, leadS = LEAD_IN_S, crossfadeS = XFADE_S) {
|
|
47
|
+
const rate = rendered.sampleRate;
|
|
48
|
+
const length = Math.round(loopS * rate);
|
|
49
|
+
const lead = Math.round(leadS * rate);
|
|
50
|
+
const overlap = Math.round(crossfadeS * rate);
|
|
51
|
+
const loop = context.createBuffer(rendered.numberOfChannels, length, rate);
|
|
52
|
+
for (let channel = 0; channel < rendered.numberOfChannels; channel += 1) {
|
|
53
|
+
const from = rendered.getChannelData(channel);
|
|
54
|
+
const to = loop.getChannelData(channel);
|
|
55
|
+
to.set(from.subarray(lead, lead + length));
|
|
56
|
+
for (let i = 0; i < overlap; i += 1) {
|
|
57
|
+
const angle = i / (overlap - 1) * Math.PI / 2;
|
|
58
|
+
to[i] = from[lead + length + i] * Math.cos(angle) + from[lead + i] * Math.sin(angle);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return loop;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function renderBed(context, kind, factory) {
|
|
65
|
+
const duration = LEAD_IN_S + LOOP_S[kind] + XFADE_S;
|
|
66
|
+
// All three generators are mono (no panner, merger or stereo source).
|
|
67
|
+
// Crowd/market retain their measured RMS at 24 kHz. Harbour needs the
|
|
68
|
+
// live rate to preserve noise density, despite its low wash cutoff.
|
|
69
|
+
const rate = RATE[kind] ?? context.sampleRate;
|
|
70
|
+
const offline = factory(1, Math.round(duration * rate), rate);
|
|
71
|
+
const nodes = [];
|
|
72
|
+
try {
|
|
73
|
+
// Keep each generator's internal calibration, applying bed level only
|
|
74
|
+
// on the live playback gain. No music, air ducking or master in this graph.
|
|
75
|
+
const generator = makeBedGenerator(tracked(offline, nodes), offline.destination, kind, 1);
|
|
76
|
+
for (let index = 0; index * FRAME_S < duration; index += 1) {
|
|
77
|
+
// Match Chromium's former suspend checkpoints: truncate, then round up.
|
|
78
|
+
// Crowd/market use this explicit expiry clock; harbour uses frame time.
|
|
79
|
+
// Pool reuse is reserved by event end times, never rendering callbacks.
|
|
80
|
+
const at = quantiseSuspendTime(index * FRAME_S, rate);
|
|
81
|
+
generator.frame(at, at);
|
|
82
|
+
}
|
|
83
|
+
const rendered = await offline.startRendering();
|
|
84
|
+
return seamlessLoop(context, rendered, LOOP_S[kind]);
|
|
85
|
+
} finally {
|
|
86
|
+
release(nodes);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Cache promises as well as completed buffers. A failed render is cached too:
|
|
91
|
+
// later visits use the live fallback rather than retrying on a failing device.
|
|
92
|
+
const always = () => true;
|
|
93
|
+
|
|
94
|
+
// Gates belong to the requesting ambience instances. Check again immediately
|
|
95
|
+
// before starting, including when the previous render completes between frames.
|
|
96
|
+
function pump(context, cache) {
|
|
97
|
+
if (cache.running || cache.scheduled) { return; }
|
|
98
|
+
cache.scheduled = true;
|
|
99
|
+
queueMicrotask(() => {
|
|
100
|
+
cache.scheduled = false;
|
|
101
|
+
const job = cache.queue.find((entry) => [...entry.gates].some((gate) => gate()));
|
|
102
|
+
if (!job) { return; }
|
|
103
|
+
cache.queue.splice(cache.queue.indexOf(job), 1);
|
|
104
|
+
cache.running = true;
|
|
105
|
+
renderBed(context, job.kind, job.factory).then(job.resolve, job.reject).then(() => {
|
|
106
|
+
job.gates.clear();
|
|
107
|
+
job.factory = null;
|
|
108
|
+
cache.running = false;
|
|
109
|
+
pump(context, cache);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function bakeBed(context, kind, factory, canStart = always, first = false) {
|
|
115
|
+
let cache = buffers.get(context);
|
|
116
|
+
if (!cache) {
|
|
117
|
+
cache = { kinds: new Map(), queue: [], running: false, scheduled: false };
|
|
118
|
+
buffers.set(context, cache);
|
|
119
|
+
}
|
|
120
|
+
let job = cache.kinds.get(kind);
|
|
121
|
+
if (!job) {
|
|
122
|
+
job = { kind, factory, gates: new Set() };
|
|
123
|
+
job.promise = new Promise((resolve, reject) => { job.resolve = resolve; job.reject = reject; });
|
|
124
|
+
cache.kinds.set(kind, job);
|
|
125
|
+
cache.queue.push(job);
|
|
126
|
+
}
|
|
127
|
+
if (cache.queue.includes(job)) {
|
|
128
|
+
job.gates.add(canStart);
|
|
129
|
+
if (first) {
|
|
130
|
+
cache.queue.splice(cache.queue.indexOf(job), 1);
|
|
131
|
+
cache.queue.unshift(job);
|
|
132
|
+
}
|
|
133
|
+
pump(context, cache);
|
|
134
|
+
}
|
|
135
|
+
return job.promise;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Quiet/dispose removes the owner's queued gates; a running bake may finish.
|
|
139
|
+
// A later visit can reattach to the same cached promise without retrying failures.
|
|
140
|
+
export function pauseBedBakes(context, canStart) {
|
|
141
|
+
const cache = buffers.get(context);
|
|
142
|
+
for (const job of cache?.queue ?? []) { job.gates.delete(canStart); }
|
|
143
|
+
}
|