castle-web-cli 0.4.233 → 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/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 +17 -2
- package/dist/castle-host/host.js +793 -36
- package/dist/castleJson.d.ts +20 -1
- package/dist/castleJson.js +44 -2
- package/dist/check.js +9 -2
- 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 +3 -1
- 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/index.js +8 -2
- package/dist/init.js +1 -1
- package/dist/save-deck.d.ts +20 -1
- package/dist/save-deck.js +141 -5
- package/dist/serve.js +29 -11
- package/dist/shell/assets/{index-BjOxR-lW.js → index-DulbYIJm.js} +97 -97
- package/dist/shell/index.html +1 -1
- package/dist/vitePlugins.d.ts +2 -1
- package/dist/vitePlugins.js +13 -0
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +260 -3
- package/kits/base/sdk/castle.d.ts +7 -3
- package/kits/base/sdk/castle.js +2 -0
- package/kits/base/sdk/commands.d.ts +162 -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 +33 -6
- package/kits/base/sdk/hub.js +50 -4
- package/kits/base/sdk/multiplayer.d.ts +7 -1
- package/kits/base/sdk/multiplayer.js +140 -40
- 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 +79 -6
- package/kits/base/sdk/server/hub.d.ts +31 -1
- package/kits/base/sdk/server/hub.js +50 -3
- package/kits/base/sdk/server/platformHandle.d.ts +13 -1
- package/kits/base/sdk/server/storage.d.ts +4 -0
- package/kits/base/sdk/server/storage.js +19 -3
- package/kits/base/sdk/server/wrapper.d.ts +7 -1
- package/kits/base/sdk/server/wrapper.js +10 -1
- package/kits/base/sdk/social.d.ts +9 -0
- package/kits/base/sdk/social.js +5 -0
- package/kits/hub-game/CLAUDE.md +123 -3
- package/kits/hub-game/README.md +63 -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/arrivalCamera.js +50 -0
- package/kits/hub-game/code/client/askSlot.js +117 -0
- package/kits/hub-game/code/client/avatar.js +4 -2
- package/kits/hub-game/code/client/avatarShare.js +2 -0
- package/kits/hub-game/code/client/backVisibility.js +13 -0
- package/kits/hub-game/code/client/ballot.js +15 -10
- package/kits/hub-game/code/client/build.js +16 -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 +1148 -258
- package/kits/hub-game/code/client/crowdNames.js +241 -0
- package/kits/hub-game/code/client/decor.js +10 -4
- 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/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 +31 -11
- package/kits/hub-game/code/client/hookLayer.js +87 -8
- 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 +14 -2
- 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/labelsNear.js +31 -2
- 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/menuRows.js +43 -0
- package/kits/hub-game/code/client/modelReady.js +7 -0
- 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/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 +64 -10
- 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/state.js +53 -0
- package/kits/hub-game/code/client/talk.js +209 -45
- package/kits/hub-game/code/client/tiers.js +68 -66
- package/kits/hub-game/code/client/together.js +7 -2
- 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/worldLabels.js +241 -0
- package/kits/hub-game/code/client/yours.js +10 -9
- package/kits/hub-game/code/npcDisplayText.js +55 -0
- package/kits/hub-game/code/server/act.js +124 -0
- package/kits/hub-game/code/server/actions.js +6 -1
- package/kits/hub-game/code/server/actors.js +2 -1
- 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/companion.js +28 -3
- package/kits/hub-game/code/server/doorAnalytics.js +52 -0
- package/kits/hub-game/code/server/earned.js +22 -5
- package/kits/hub-game/code/server/frameBatch.js +183 -0
- package/kits/hub-game/code/server/friendsAmong.js +49 -9
- package/kits/hub-game/code/server/history.js +2 -0
- package/kits/hub-game/code/server/hub.js +1306 -95
- package/kits/hub-game/code/server/idle.js +30 -1
- package/kits/hub-game/code/server/index.js +26 -4
- package/kits/hub-game/code/server/invites.js +19 -0
- package/kits/hub-game/code/server/labels.js +9 -1
- package/kits/hub-game/code/server/loadAbandon.js +106 -0
- package/kits/hub-game/code/server/manifest.js +211 -3
- package/kits/hub-game/code/server/menu.js +31 -3
- package/kits/hub-game/code/server/npcs.js +226 -64
- 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/players.js +9 -1
- 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/standing.js +4 -5
- package/kits/hub-game/code/server/storageLimit.js +187 -0
- package/kits/hub-game/code/server/vis.js +67 -5
- package/kits/hub-game/code/shared/act.js +35 -0
- package/kits/hub-game/code/shared/danceIdle.js +28 -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 +35 -1
- package/kits/hub-game/code/systems/hub.js +970 -169
- package/kits/hub-game/docs/analytics.md +279 -0
- package/kits/hub-game/docs/contract.md +1257 -42
- package/kits/hub-game/docs/home-pieces.md +9 -2
- package/kits/hub-game/docs/observed-progress.md +252 -0
- package/kits/hub-game/main.jsx +2 -0
- package/kits/hub-game/package-lock.json +10 -3
- package/kits/hub-game/package.json +6 -3
- 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 +39 -5
- package/kits/hub-game/scripts/companion-follower-wire.json +1 -1
- package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +11 -0
- package/kits/hub-game/scripts/fixtures/decor-keyless.json +5 -5
- package/kits/hub-game/scripts/fixtures/engine-models-stub.mjs +3 -0
- package/kits/hub-game/scripts/fixtures/fake-dom.mjs +19 -3
- package/kits/hub-game/scripts/fixtures/interest-legacy.json +3 -3
- package/kits/hub-game/scripts/fixtures/vis-shared-wire.json +1 -1
- package/kits/hub-game/scripts/pose-storage-fixture.mjs +46 -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 +367 -2
- package/kits/hub-game/scripts/test-actors.mjs +20 -7
- 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-slot.mjs +85 -0
- package/kits/hub-game/scripts/test-avatar-wire.mjs +49 -10
- package/kits/hub-game/scripts/test-avatar.mjs +44 -0
- package/kits/hub-game/scripts/test-back-visibility.mjs +82 -0
- package/kits/hub-game/scripts/test-ballot.mjs +11 -4
- package/kits/hub-game/scripts/test-ban-join.mjs +121 -13
- package/kits/hub-game/scripts/test-build.mjs +20 -2
- package/kits/hub-game/scripts/test-chat.mjs +206 -5
- package/kits/hub-game/scripts/test-companion-chat.mjs +20 -2
- 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 +45 -4
- package/kits/hub-game/scripts/test-decor.mjs +7 -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.mjs +33 -3
- 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-grab-orbit.mjs +47 -4
- package/kits/hub-game/scripts/test-high-only.mjs +170 -0
- package/kits/hub-game/scripts/test-hub-ops.mjs +321 -2
- package/kits/hub-game/scripts/test-hub-trip.mjs +879 -11
- package/kits/hub-game/scripts/test-hud-clear.mjs +162 -59
- 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 +66 -0
- package/kits/hub-game/scripts/test-interest-cells.mjs +20 -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-labels.mjs +71 -3
- 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 +265 -0
- package/kits/hub-game/scripts/test-menu-client.mjs +105 -0
- package/kits/hub-game/scripts/test-menu.mjs +23 -0
- package/kits/hub-game/scripts/test-npcs.mjs +819 -10
- package/kits/hub-game/scripts/test-observed.mjs +745 -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 +234 -7
- 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 +699 -5
- 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 +145 -0
- package/kits/hub-game/scripts/test-signin-client.mjs +45 -0
- package/kits/hub-game/scripts/test-soundscape.mjs +22 -17
- package/kits/hub-game/scripts/test-standing.mjs +35 -2
- package/kits/hub-game/scripts/test-storage-limit.mjs +333 -0
- package/kits/hub-game/scripts/test-stuck.mjs +5 -4
- package/kits/hub-game/scripts/test-talk-overlay-dom.mjs +130 -0
- package/kits/hub-game/scripts/test-tiers-render.mjs +86 -13
- package/kits/hub-game/scripts/test-tiers.mjs +7 -8
- package/kits/hub-game/scripts/test-vis.mjs +433 -6
- 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 +50 -6
- package/kits/hub-game/scripts/test-yours.mjs +39 -8
- package/kits/multiplayer-3d/castle.json +5 -5
- package/kits/multiplayer-3d/code/client/joinFailure.js +27 -0
- package/kits/multiplayer-3d/code/client/resumeGate.js +139 -0
- package/kits/multiplayer-3d/code/systems/multiplayer.js +369 -30
- package/kits/multiplayer-3d/package-lock.json +8 -1
- package/kits/multiplayer-3d/package.json +2 -1
- package/kits/multiplayer-3d/scripts/test-join-watchdog.mjs +436 -0
- package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +624 -0
- package/kits/physics-2d/CLAUDE.md +10 -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 +87 -5
- 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-3d/CLAUDE.md +25 -1651
- 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 +35 -18
- 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 +1 -1
- package/kits/physics-3d/engine3d/PlayOnly3D.jsx +5 -1
- package/kits/physics-3d/engine3d/Scene3DPlayer.jsx +19 -333
- package/kits/physics-3d/engine3d/actornode.js +1 -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/framecap.js +4 -1
- 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 +8 -0
- package/kits/physics-3d/engine3d/initialModelFiles.js +18 -0
- package/kits/physics-3d/engine3d/look.js +7 -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 +3 -3
- package/kits/physics-3d/engine3d/nearshadows.js +77 -10
- package/kits/physics-3d/engine3d/orbitinput.js +59 -25
- 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 +3 -3
- 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 +23 -15
- package/kits/physics-3d/engine3d/sky.js +1 -1
- 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/world3d.js +468 -18
- package/kits/physics-3d/eslint.config.js +2 -1
- package/kits/physics-3d/main.jsx +6 -3
- 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/test-camera-follow.mjs +5 -1
- package/kits/physics-3d/scripts/test-camera-orbit.mjs +52 -4
- package/kits/physics-3d/scripts/test-drop-empty-parts.mjs +1 -1
- package/kits/physics-3d/scripts/test-empty-gait-hints.mjs +89 -0
- package/kits/physics-3d/scripts/test-frame-cap-bob.mjs +6 -3
- package/kits/physics-3d/scripts/test-frame-cap.mjs +1 -1
- 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-look-bake.mjs +1 -1
- package/kits/physics-3d/scripts/test-near-shadows.mjs +2 -2
- package/kits/physics-3d/scripts/test-orbit-shadow-fade.mjs +88 -7
- package/kits/physics-3d/scripts/test-orbit-shift-lock.mjs +40 -3
- package/kits/physics-3d/scripts/test-orbit-shot.mjs +75 -1
- package/kits/physics-3d/scripts/test-rapier-gz.mjs +106 -0
- package/kits/physics-3d/scripts/test-sky.mjs +1 -1
- package/kits/physics-3d/scripts/test-square-first.mjs +921 -0
- package/kits/physics-3d/scripts/test-static-actors.mjs +3 -1
- package/kits/physics-3d/scripts/test-static-physics.mjs +4 -1
- package/kits/physics-3d/scripts/test-static-scenery.mjs +5 -2
- package/kits/physics-3d/scripts/test-steady-hover.mjs +5 -2
- package/kits/physics-3d/scripts/test-still-shadows.mjs +477 -0
- package/kits/physics-3d/systems/physics3d.js +37 -4
- 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/session.js +6 -4
- package/kits/real-time/package-lock.json +1 -1
- package/package.json +2 -2
|
@@ -14,6 +14,8 @@ import * as Interpolate from '@imports/castle.real-time/code/client/interpolate.
|
|
|
14
14
|
import * as Ownership from '@imports/castle.real-time/code/client/ownership.js';
|
|
15
15
|
import * as Smoothing from '@imports/castle.real-time/code/client/smooth.js';
|
|
16
16
|
import * as Poses from '../client/poses.js';
|
|
17
|
+
import * as ResumeGate from '../client/resumeGate.js';
|
|
18
|
+
import { joinPlaceName, showJoinFailure } from '../client/joinFailure.js';
|
|
17
19
|
import * as Steer from '../client/steer.js';
|
|
18
20
|
import { eligibleClaims } from '../options.js';
|
|
19
21
|
import { connectSession } from '@imports/castle.real-time/code/client/connection.js';
|
|
@@ -23,6 +25,8 @@ import { GONE, SCENE, STATE, WORLD } from '@imports/castle.real-time/code/client
|
|
|
23
25
|
|
|
24
26
|
// How long the joining overlay may hold the card before giving up.
|
|
25
27
|
const JOIN_WAIT_MS = 10000;
|
|
28
|
+
const JOIN_WATCHDOG_MS = 20000;
|
|
29
|
+
const JOIN_FAILURE_LIMIT = 3;
|
|
26
30
|
import { game } from '@imports/castle.real-time/code/client/gameHooks.js';
|
|
27
31
|
|
|
28
32
|
// Apply this fraction of a server player correction per frame. Corrections over
|
|
@@ -45,6 +49,8 @@ const WRITTEN_SLACK = 0.005;
|
|
|
45
49
|
const JOIN_BACK_MS = 250;
|
|
46
50
|
// Castle refuses a player barred from the hub every hub join with this code.
|
|
47
51
|
const HUB_BANNED = 'CAULDRON_HUB_BANNED';
|
|
52
|
+
const finalJoinError = (code) => code === HUB_BANNED ||
|
|
53
|
+
(typeof code === 'string' && code.startsWith('CAULDRON_HUB_INVITE_') && code !== 'CAULDRON_HUB_INVITE_NOT_IN_SESSION') ? code : null;
|
|
48
54
|
|
|
49
55
|
// A deck may provide its own multiplayer system. The engine registry permits
|
|
50
56
|
// duplicate systems, which would create duplicate session connections, so these
|
|
@@ -90,13 +96,13 @@ class MultiplayerSystem {
|
|
|
90
96
|
this.joined = false;
|
|
91
97
|
this.joinStartedAt = 0;
|
|
92
98
|
|
|
93
|
-
// `starting`
|
|
99
|
+
// `starting` spans connection acquisition through placement, not only the promise.
|
|
94
100
|
this.starting = false;
|
|
95
101
|
|
|
96
102
|
// What `Multiplayer.join` is asked for, and whether the kit's join overlay
|
|
97
103
|
// stays down while it happens (the caller covers the join itself, as a
|
|
98
|
-
// hub's door animation does). `generation`
|
|
99
|
-
//
|
|
104
|
+
// hub's door animation does). `generation` invalidates pending joins when
|
|
105
|
+
// switching sessions, abandoning a join, or disposing the runtime.
|
|
100
106
|
// A client hook may name the first join instead (`firstJoin`, a hub place
|
|
101
107
|
// that joins its world through a destination route).
|
|
102
108
|
this.target = game.firstJoin?.() ?? { mode: 'public' };
|
|
@@ -106,8 +112,16 @@ class MultiplayerSystem {
|
|
|
106
112
|
// refused, or its connection closes for good, it is not tried again. The
|
|
107
113
|
// caller that switched to it reads `joinState()` and decides where to go.
|
|
108
114
|
this.joinFailed = false;
|
|
109
|
-
|
|
115
|
+
this.joinFailures = 0;
|
|
116
|
+
this.joinRetryAt = 0;
|
|
117
|
+
this.joinAttempt = null;
|
|
118
|
+
this.joinFrameAt = null;
|
|
119
|
+
this.joinScene = null;
|
|
120
|
+
this.joinAttemptNumber = 0;
|
|
121
|
+
this.removeJoinFailure = null;
|
|
122
|
+
// The CastleError code of a join refused for good, else null.
|
|
110
123
|
this.joinError = null;
|
|
124
|
+
this.joinFailure = null;
|
|
111
125
|
// Whether the join `switchSession` asked for has resolved (for a hub join,
|
|
112
126
|
// the host committed the trip), kept apart from whether its connection is
|
|
113
127
|
// still open. `holding` keeps a new connection's messages queued, nothing
|
|
@@ -184,6 +198,21 @@ class MultiplayerSystem {
|
|
|
184
198
|
// The JSON of the last state block sent, so a block goes out only when it
|
|
185
199
|
// changes.
|
|
186
200
|
this.sentState = '';
|
|
201
|
+
|
|
202
|
+
// A placed player who went away (the page hidden, its frames stopped, or
|
|
203
|
+
// the connection dropped) is kept behind the cover until a current
|
|
204
|
+
// snapshot arrives (`client/resumeGate.js`). `frameAt` is the page time of
|
|
205
|
+
// the last network frame, where an away begins; `wasAway` says the cover
|
|
206
|
+
// is for a return, not a join, until the next session. `gaveUp` keeps a
|
|
207
|
+
// gate that timed out from arming again before the connection is back.
|
|
208
|
+
// `outAt` is the page time the player last came out from behind it, by a
|
|
209
|
+
// snapshot, by giving up, or by the session closing under it (`returning`).
|
|
210
|
+
this.resume = ResumeGate.makeGate();
|
|
211
|
+
this.frameAt = 0;
|
|
212
|
+
this.wasAway = false;
|
|
213
|
+
this.gaveUp = false;
|
|
214
|
+
this.outAt = null;
|
|
215
|
+
this.onVisibility = null;
|
|
187
216
|
}
|
|
188
217
|
|
|
189
218
|
// Run the network frame after engine behaviors and local physics. Connection,
|
|
@@ -192,7 +221,9 @@ class MultiplayerSystem {
|
|
|
192
221
|
// Connecting on the first stepped frame keeps editor-only runtimes out of
|
|
193
222
|
// multiplayer sessions because the scene editor constructs but never steps them.
|
|
194
223
|
if (!this.net) {
|
|
195
|
-
|
|
224
|
+
this.stepJoin(scene);
|
|
225
|
+
this.watchJoin(scene);
|
|
226
|
+
showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
|
|
196
227
|
return void this.start(scene);
|
|
197
228
|
}
|
|
198
229
|
|
|
@@ -200,28 +231,41 @@ class MultiplayerSystem {
|
|
|
200
231
|
// platform closed it). Everything drawn from it goes, and the next frame
|
|
201
232
|
// joins afresh behind the overlay.
|
|
202
233
|
if (this.net.closed()) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
234
|
+
this.generation += 1;
|
|
235
|
+
this.joinError = finalJoinError(this.net.closeError?.());
|
|
236
|
+
if (this.resume.armed) {
|
|
237
|
+
this.outAt = performance.now();
|
|
238
|
+
}
|
|
206
239
|
if (this.target?.mode === 'hub' && this.joinCommitted && !this.joined) {
|
|
207
240
|
this.joinLost = true;
|
|
208
241
|
}
|
|
209
|
-
this.
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.
|
|
213
|
-
this.joinFailed = this.target?.mode === 'hub' || this.joinError !== null;
|
|
214
|
-
this.holding = false;
|
|
215
|
-
this.net = null;
|
|
216
|
-
this.joined = false;
|
|
217
|
-
this.joinStartedAt = 0;
|
|
218
|
-
this.starting = false;
|
|
219
|
-
this.sentState = '';
|
|
242
|
+
if (!this.joined) {
|
|
243
|
+
this.failedJoin(scene, this.net.closeError?.() ?? 'CLOSED', null);
|
|
244
|
+
}
|
|
245
|
+
this.clearConnection(scene);
|
|
220
246
|
return;
|
|
221
247
|
}
|
|
248
|
+
const now = performance.now();
|
|
249
|
+
const last = this.frameAt;
|
|
250
|
+
this.frameAt = now;
|
|
222
251
|
if (this.holding) {
|
|
223
252
|
return;
|
|
224
253
|
}
|
|
254
|
+
|
|
255
|
+
// Frames that stopped for a while, or a connection no longer connected,
|
|
256
|
+
// mean the room drawn is no longer current. The page being hidden arms the
|
|
257
|
+
// same gate from its event (`start`), before the page goes.
|
|
258
|
+
if (last && now - last > ResumeGate.STALL_MS) {
|
|
259
|
+
this.away(last);
|
|
260
|
+
}
|
|
261
|
+
const connected = this.net.status().state === 'connected';
|
|
262
|
+
if (connected) {
|
|
263
|
+
this.joinStage('connected');
|
|
264
|
+
this.gaveUp = false;
|
|
265
|
+
} else {
|
|
266
|
+
this.away(last || now);
|
|
267
|
+
}
|
|
268
|
+
ResumeGate.noteConnection(this.resume, connected, now);
|
|
225
269
|
if (gaitModel()) {
|
|
226
270
|
this.walkTimeHint = walkFrameTime((this.walkFrame ??= {}));
|
|
227
271
|
}
|
|
@@ -231,7 +275,22 @@ class MultiplayerSystem {
|
|
|
231
275
|
}
|
|
232
276
|
|
|
233
277
|
// Drain all queued messages before choosing the render time for this frame.
|
|
278
|
+
// A current snapshot releases the resume gate inside `receive`; one that
|
|
279
|
+
// never comes releases it after RESUME_WAIT_MS of visible time.
|
|
234
280
|
this.receive(scene);
|
|
281
|
+
// An assigned connection may already hold its WORLD, even after a parked
|
|
282
|
+
// frame or while reconnecting. Drain placement before any join recovery.
|
|
283
|
+
this.stepJoin(scene);
|
|
284
|
+
if (!this.net) { return; }
|
|
285
|
+
// Drain first: a placement queued for this frame wins over the timeout.
|
|
286
|
+
if (this.watchJoin(scene)) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (ResumeGate.waited(this.resume, now, !pageHidden())) {
|
|
290
|
+
console.warn('[multiplayer] no current snapshot since coming back; showing the room as it is');
|
|
291
|
+
this.resumed();
|
|
292
|
+
this.gaveUp = true;
|
|
293
|
+
}
|
|
235
294
|
this.applyGone(scene);
|
|
236
295
|
this.reportGone(scene);
|
|
237
296
|
|
|
@@ -272,56 +331,203 @@ class MultiplayerSystem {
|
|
|
272
331
|
}
|
|
273
332
|
this.publish(scene, local);
|
|
274
333
|
updateSoloBadge(this.net.status(), game);
|
|
275
|
-
showJoinOverlay(this.joiningOverlayWanted());
|
|
334
|
+
showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
|
|
276
335
|
}
|
|
277
336
|
|
|
278
337
|
// Join the session `target` names (the public one unless `switchSession`
|
|
279
338
|
// said otherwise) and retain the transport across scene loads.
|
|
280
339
|
async start(scene) {
|
|
281
|
-
if (this.starting || this.joinFailed) {
|
|
340
|
+
if (this.net || this.starting || this.joinFailed || performance.now() < this.joinRetryAt) {
|
|
282
341
|
return;
|
|
283
342
|
}
|
|
284
343
|
this.starting = true;
|
|
285
344
|
this.joinStartedAt ||= performance.now();
|
|
345
|
+
const now = performance.now();
|
|
346
|
+
this.joinAttempt = { number: ++this.joinAttemptNumber, at: now, stepAt: now,
|
|
347
|
+
visibleMs: 0, hidden: pageHidden(), stages: new Set() };
|
|
348
|
+
this.joinStage('attempt start', { mode: this.target?.mode ?? (this.target?.destination ? 'destination' : 'public') });
|
|
286
349
|
const generation = this.generation;
|
|
350
|
+
|
|
351
|
+
// The cover has to be up before the page goes, so the first frame shown
|
|
352
|
+
// when it comes back is the cover and not the scene it last drew.
|
|
353
|
+
if (!this.onVisibility && typeof document !== 'undefined') {
|
|
354
|
+
this.onVisibility = () => {
|
|
355
|
+
if (pageHidden()) {
|
|
356
|
+
if (this.joinAttempt) { this.joinAttempt.hidden = true; }
|
|
357
|
+
this.away(this.frameAt || performance.now());
|
|
358
|
+
} else {
|
|
359
|
+
this.visibleJoin(this.joinScene ?? scene, this.joinAttempt?.hidden === true);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
document.addEventListener('visibilitychange', this.onVisibility);
|
|
363
|
+
}
|
|
287
364
|
try {
|
|
288
365
|
const net = await connectSession({
|
|
289
366
|
join: this.target,
|
|
367
|
+
isCurrent: () => generation === this.generation,
|
|
368
|
+
...(game.unpack ? { unpack: game.unpack } : {}),
|
|
290
369
|
onLog: (text) => console.log(`[multiplayer] ${text}`),
|
|
291
370
|
|
|
292
371
|
// A deck message can be handled on arrival through the `arrive` hook,
|
|
293
372
|
// which still runs in a hidden tab. State messages always wait for a frame.
|
|
294
|
-
onArrival: (msg) => msg.k !== STATE && msg.k !== WORLD && game.arrive?.(msg, this) === true,
|
|
373
|
+
onArrival: (msg) => generation === this.generation && msg.k !== STATE && msg.k !== WORLD && game.arrive?.(msg, this) === true,
|
|
295
374
|
|
|
296
375
|
// A reconnect may reach a restarted server process, which builds its
|
|
297
376
|
// world from scratch: it is named the scene again.
|
|
298
377
|
onConnected: () => {
|
|
299
378
|
if (generation === this.generation) {
|
|
379
|
+
this.joinStage('connected');
|
|
300
380
|
this.nameScene(scene);
|
|
381
|
+
this.reconnected();
|
|
301
382
|
}
|
|
302
383
|
},
|
|
303
384
|
});
|
|
304
385
|
if (generation !== this.generation) {
|
|
305
|
-
//
|
|
386
|
+
// Switched, abandoned or disposed while pending: this net is not wanted.
|
|
306
387
|
net.close();
|
|
307
388
|
return;
|
|
308
389
|
}
|
|
309
390
|
this.net = net;
|
|
310
391
|
this.joinCommitted = true;
|
|
392
|
+
if (net.status().state === 'connected') { this.joinStage('connected'); }
|
|
393
|
+
this.joinRetryAt = 0;
|
|
311
394
|
|
|
312
395
|
this.nameScene(scene);
|
|
313
396
|
} catch (err) {
|
|
314
397
|
console.log(`[multiplayer] could not join: ${err?.message ?? err}`);
|
|
315
398
|
if (generation === this.generation) {
|
|
316
399
|
this.starting = false;
|
|
317
|
-
|
|
318
|
-
// the town's own included: asking again changes nothing.
|
|
319
|
-
this.joinError = err?.code === HUB_BANNED ? HUB_BANNED : null;
|
|
320
|
-
this.joinFailed = this.target?.mode === 'hub' || this.joinError !== null;
|
|
400
|
+
this.failedJoin(scene, err?.code ?? null, err?.extensions?.closeCode ?? null);
|
|
321
401
|
}
|
|
322
402
|
}
|
|
323
403
|
}
|
|
324
404
|
|
|
405
|
+
// Join-stage diagnostics are emitted once even if a socket reconnects or a
|
|
406
|
+
// visibility event repeats. Durations are wall time; the budget below is not.
|
|
407
|
+
joinStage(stage, detail = {}) {
|
|
408
|
+
const attempt = this.joinAttempt;
|
|
409
|
+
if (!attempt || attempt.stages.has(stage)) { return; }
|
|
410
|
+
attempt.stages.add(stage);
|
|
411
|
+
console.warn(`[multiplayer] join ${stage}`, {
|
|
412
|
+
attempt: attempt.number, ms: Math.round(performance.now() - attempt.at), ...detail,
|
|
413
|
+
});
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Only adjacent visible steps spend the budget. A suspended WebView can
|
|
417
|
+
// miss visibilitychange entirely, including while getSession is pending.
|
|
418
|
+
stepJoin(scene) {
|
|
419
|
+
this.joinScene = scene;
|
|
420
|
+
const now = performance.now();
|
|
421
|
+
const last = this.joinFrameAt;
|
|
422
|
+
this.joinFrameAt = now;
|
|
423
|
+
if (this.joined || this.target?.mode === 'hub' || this.joinFailed || this.net?.status().solo) { return; }
|
|
424
|
+
const attempt = this.joinAttempt;
|
|
425
|
+
const gap = attempt ? now - attempt.stepAt : 0;
|
|
426
|
+
const stalled = this.starting ? gap > ResumeGate.STALL_MS : last !== null && now - last > ResumeGate.STALL_MS;
|
|
427
|
+
if (!pageHidden() && (attempt?.hidden || stalled)) {
|
|
428
|
+
this.visibleJoin(scene, true, true);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (!this.starting || !attempt) { return; }
|
|
432
|
+
if (!pageHidden()) { attempt.visibleMs += gap; }
|
|
433
|
+
attempt.stepAt = now;
|
|
434
|
+
attempt.hidden ||= pageHidden();
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// A visibility event never abandons an assigned net: its next frame must
|
|
438
|
+
// drain first. Connected nets keep waiting for placement under the watchdog.
|
|
439
|
+
visibleJoin(scene, stale, drained = false) {
|
|
440
|
+
if (this.joined || this.target?.mode === 'hub' || this.joinFailed || this.net?.status().solo) { return; }
|
|
441
|
+
this.joinRetryAt = 0;
|
|
442
|
+
if (this.net && !drained) {
|
|
443
|
+
if (this.joinAttempt && stale) { this.joinAttempt.hidden = true; }
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
if (this.joinAttempt) {
|
|
447
|
+
this.joinAttempt.hidden = false;
|
|
448
|
+
if (stale) { this.joinAttempt.stepAt = performance.now(); }
|
|
449
|
+
}
|
|
450
|
+
if (this.starting && stale && (!this.net || this.net.status().state !== 'connected')) {
|
|
451
|
+
this.joinStage('visible rejoin');
|
|
452
|
+
this.abandonJoin(scene, 'VISIBLE_REJOIN');
|
|
453
|
+
// A return retries now rather than waiting through the normal backoff.
|
|
454
|
+
this.joinRetryAt = 0;
|
|
455
|
+
void this.start(scene);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
watchJoin(scene) {
|
|
460
|
+
if (this.target?.mode === 'hub' || this.joined || this.net?.status().solo || !this.starting ||
|
|
461
|
+
!(this.joinAttempt?.visibleMs > JOIN_WATCHDOG_MS)) { return false; }
|
|
462
|
+
this.joinStage('watchdog abort', { visibleMs: Math.round(this.joinAttempt.visibleMs) });
|
|
463
|
+
this.abandonJoin(scene, 'JOIN_TIMEOUT');
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
abandonJoin(scene, code) {
|
|
468
|
+
// Invalidate before closing: callbacks and a late promise belong to the
|
|
469
|
+
// abandoned attempt and must never reach this scene or replace its net.
|
|
470
|
+
this.generation += 1;
|
|
471
|
+
this.net?.close();
|
|
472
|
+
this.failedJoin(scene, code, null);
|
|
473
|
+
this.clearConnection(scene);
|
|
474
|
+
this.joinCommitted = false;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// The same scene/transport cleanup for an ended socket and an abandoned join.
|
|
478
|
+
clearConnection(scene) {
|
|
479
|
+
this.reset(scene);
|
|
480
|
+
this.shortIds.clear();
|
|
481
|
+
this.rowInterval = 0;
|
|
482
|
+
this.rowLagShown = 0;
|
|
483
|
+
this.joinFailed ||= this.target?.mode === 'hub' || this.joinError !== null;
|
|
484
|
+
this.holding = false;
|
|
485
|
+
this.net = null;
|
|
486
|
+
this.joined = false;
|
|
487
|
+
this.joinStartedAt = 0;
|
|
488
|
+
this.starting = false;
|
|
489
|
+
this.sentState = '';
|
|
490
|
+
this.endAway();
|
|
491
|
+
this.clock = Clock.makeClock();
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
failedJoin(scene, code, closeCode) {
|
|
495
|
+
if (this.net?.status().solo) { return; }
|
|
496
|
+
this.joinStage('failure', { code, closeCode });
|
|
497
|
+
this.joinFailure = { code, closeCode };
|
|
498
|
+
this.joinError = finalJoinError(code);
|
|
499
|
+
this.joinFailed = this.target?.mode === 'hub' || this.joinError !== null;
|
|
500
|
+
if (this.target?.mode === 'hub') { return; }
|
|
501
|
+
this.joinFailures += 1;
|
|
502
|
+
// Permanent refusals keep the deck's existing ban/invite failure surface.
|
|
503
|
+
if (this.joinError !== null) { return; }
|
|
504
|
+
this.joinFailed ||= this.joinFailures >= JOIN_FAILURE_LIMIT;
|
|
505
|
+
if (this.joinFailed) {
|
|
506
|
+
this.joinStage('gave up');
|
|
507
|
+
showJoinOverlay(false);
|
|
508
|
+
this.removeJoinFailure ??= showJoinFailure(this.joinName(), () => {
|
|
509
|
+
if (!this.joinFailed) { return; }
|
|
510
|
+
this.joinStage('retry tapped');
|
|
511
|
+
this.removeJoinFailure?.();
|
|
512
|
+
this.removeJoinFailure = null;
|
|
513
|
+
this.joinFailures = 0;
|
|
514
|
+
this.joinFailed = false;
|
|
515
|
+
this.joinError = null;
|
|
516
|
+
this.joinFailure = null;
|
|
517
|
+
this.joinRetryAt = 0;
|
|
518
|
+
this.joinStartedAt = 0;
|
|
519
|
+
void this.start(this.joinScene ?? scene);
|
|
520
|
+
showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
|
|
521
|
+
});
|
|
522
|
+
} else {
|
|
523
|
+
this.joinRetryAt = performance.now() + Math.min(30_000, 1_000 * 2 ** Math.min(this.joinFailures - 1, 5));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
joinName() {
|
|
528
|
+
return joinPlaceName(castleJson.hub?.title);
|
|
529
|
+
}
|
|
530
|
+
|
|
325
531
|
// A deck whose server takes its scene from the client names the scene this
|
|
326
532
|
// runtime is playing, before anything else is sent. A server that already
|
|
327
533
|
// has one ignores it.
|
|
@@ -339,6 +545,10 @@ class MultiplayerSystem {
|
|
|
339
545
|
// A scene swap requested in the same frame is applied before the next one,
|
|
340
546
|
// so the new session is named the new scene.
|
|
341
547
|
switchSession(scene, join, { quiet = false, hold = false } = {}) {
|
|
548
|
+
this.removeJoinFailure?.();
|
|
549
|
+
this.removeJoinFailure = null;
|
|
550
|
+
this.joinAttempt = null;
|
|
551
|
+
this.joinFrameAt = null;
|
|
342
552
|
this.generation += 1;
|
|
343
553
|
this.reset(scene);
|
|
344
554
|
this.net?.close();
|
|
@@ -348,11 +558,16 @@ class MultiplayerSystem {
|
|
|
348
558
|
this.joinWarned = false;
|
|
349
559
|
this.starting = false;
|
|
350
560
|
this.joinFailed = false;
|
|
561
|
+
this.joinFailures = 0;
|
|
562
|
+
this.joinRetryAt = 0;
|
|
351
563
|
this.joinError = null;
|
|
564
|
+
this.joinFailure = null;
|
|
352
565
|
this.joinCommitted = false;
|
|
353
566
|
this.joinLost = false;
|
|
354
567
|
this.holding = hold;
|
|
355
568
|
this.sentState = '';
|
|
569
|
+
this.endAway();
|
|
570
|
+
this.outAt = null;
|
|
356
571
|
this.gone.clear();
|
|
357
572
|
// The new session numbers its rows afresh.
|
|
358
573
|
this.shortIds.clear();
|
|
@@ -362,7 +577,7 @@ class MultiplayerSystem {
|
|
|
362
577
|
this.clock = Clock.makeClock();
|
|
363
578
|
this.target = join;
|
|
364
579
|
this.quiet = quiet;
|
|
365
|
-
showJoinOverlay(this.joiningOverlayWanted());
|
|
580
|
+
showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
|
|
366
581
|
}
|
|
367
582
|
|
|
368
583
|
// Where the join `switchSession` asked for stands: 'joining', 'joined' (it
|
|
@@ -383,14 +598,107 @@ class MultiplayerSystem {
|
|
|
383
598
|
|
|
384
599
|
// Whether the session has placed this player and the body and camera have
|
|
385
600
|
// caught up with it, which is when a caller covering the join can uncover.
|
|
601
|
+
// A player kept behind the resume gate is not placed until it releases.
|
|
386
602
|
placed() {
|
|
387
|
-
return Boolean(this.net) && this.joined && !this.placedTo && this.settleFrames === 0;
|
|
603
|
+
return Boolean(this.net) && this.joined && !this.placedTo && this.settleFrames === 0 && !this.resume.armed;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// The room stopped being current at page time `since`. A placed player is
|
|
607
|
+
// kept behind the cover from now until a current snapshot (`receive`). The
|
|
608
|
+
// cover goes up at once, because this runs from the page's hidden event.
|
|
609
|
+
away(since) {
|
|
610
|
+
if (!this.net || !this.joined || this.gaveUp || this.net.status().solo || this.joinError) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
const serverAt = Clock.ready(this.clock) ? since - this.clock.offset : null;
|
|
614
|
+
if (ResumeGate.arm(this.resume, since, serverAt)) {
|
|
615
|
+
console.log('[multiplayer] away; holding the room until a current snapshot');
|
|
616
|
+
this.wasAway = true;
|
|
617
|
+
showJoinOverlay(this.joiningOverlayWanted(), this.coverText());
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// The connection came back after dropping, perhaps while the page was hidden
|
|
622
|
+
// and no frame saw it go: whatever changed meanwhile was not seen here.
|
|
623
|
+
reconnected() {
|
|
624
|
+
const now = performance.now();
|
|
625
|
+
this.gaveUp = false;
|
|
626
|
+
this.away(this.frameAt || now);
|
|
627
|
+
ResumeGate.noteConnection(this.resume, false, now);
|
|
628
|
+
ResumeGate.noteConnection(this.resume, true, now);
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// A current snapshot arrived after an away. Every displayed pose is
|
|
632
|
+
// forgotten, so this frame draws each object and player at its current pose
|
|
633
|
+
// rather than smoothing from the one shown before the away, and each live
|
|
634
|
+
// object this client does not hold is placed afresh at the network's
|
|
635
|
+
// present rather than steered there from where its body was left.
|
|
636
|
+
//
|
|
637
|
+
// Each history also loses the samples from before the away that a later
|
|
638
|
+
// one follows: interpolating between the two would draw a glide across the
|
|
639
|
+
// whole absence. A history with nothing newer keeps its newest pose, which
|
|
640
|
+
// is still where that object is.
|
|
641
|
+
//
|
|
642
|
+
// A live body is placed on its rapier body, which its Transform follows
|
|
643
|
+
// only at the next physics step, so the cover stays up one more frame.
|
|
644
|
+
resumed() {
|
|
645
|
+
const from = this.resume.serverAt;
|
|
646
|
+
ResumeGate.clear(this.resume);
|
|
647
|
+
this.outAt = performance.now();
|
|
648
|
+
this.shown = Smoothing.makeSmoothing();
|
|
649
|
+
if (from !== null) {
|
|
650
|
+
for (const track of [...this.objects.values(), ...this.players.values()]) {
|
|
651
|
+
// A sample at `from` itself arrived by the last frame before the away.
|
|
652
|
+
const first = track.samples.findIndex((s) => s.simMs > from);
|
|
653
|
+
if (first > 0) {
|
|
654
|
+
track.samples.splice(0, first);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
for (const id of [...this.live.keys()]) {
|
|
659
|
+
if (!this.own.mine.has(id)) {
|
|
660
|
+
this.live.delete(id);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
if (gaitModel()) {
|
|
664
|
+
this.playerWalkSpeeds?.clear();
|
|
665
|
+
this.objectWalkSpeeds?.clear();
|
|
666
|
+
}
|
|
667
|
+
this.settleFrames = Math.max(this.settleFrames, 1);
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// Whether this player is behind the resume cover, or came out from behind
|
|
671
|
+
// it within `RETURN_MS`. A session that ends now most likely ended over the
|
|
672
|
+
// absence (a game that ran out while the player was away), and what the
|
|
673
|
+
// page still draws of it is the room as it was: a caller leaving the place
|
|
674
|
+
// goes straight under its own cover rather than playing a beat over it.
|
|
675
|
+
returning() {
|
|
676
|
+
return this.resume.armed || (this.outAt !== null && performance.now() - this.outAt < ResumeGate.RETURN_MS);
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
// Leave the resume gate without a snapshot: the session it waited on has
|
|
680
|
+
// gone, and the join overlay covers the next one.
|
|
681
|
+
endAway() {
|
|
682
|
+
ResumeGate.clear(this.resume);
|
|
683
|
+
this.wasAway = false;
|
|
684
|
+
this.gaveUp = false;
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
// What the cover says.
|
|
688
|
+
coverText() {
|
|
689
|
+
const name = this.joinName();
|
|
690
|
+
return this.wasAway ? 'Reconnecting…' : name ? `Joining ${name}…` : 'Joining…';
|
|
388
691
|
}
|
|
389
692
|
|
|
390
693
|
// Drain queued transport messages. State messages update clock, ownership, pose
|
|
391
694
|
// histories, and deck state in that order; other message kinds go to the deck.
|
|
392
695
|
receive(scene) {
|
|
393
696
|
const selfId = this.net.selfId();
|
|
697
|
+
|
|
698
|
+
// A snapshot releases the resume gate only once the page is shown and
|
|
699
|
+
// connected again; the whole drain is applied before it does.
|
|
700
|
+
const resuming = this.resume.armed && !pageHidden() && this.net.status().state === 'connected';
|
|
701
|
+
let fresh = false;
|
|
394
702
|
for (const msg of this.net.drain()) {
|
|
395
703
|
if (msg.k !== STATE && msg.k !== WORLD) {
|
|
396
704
|
game.message?.(scene, msg, this);
|
|
@@ -414,9 +722,13 @@ class MultiplayerSystem {
|
|
|
414
722
|
|
|
415
723
|
// Pair simulation time with the page arrival time before filing samples.
|
|
416
724
|
Clock.noteArrival(this.clock, msg.t, msg.localMs);
|
|
725
|
+
fresh ||= resuming && ResumeGate.current(this.resume, msg);
|
|
417
726
|
if (!this.joined && (msg.k === WORLD || (msg.ps ?? []).some((pose) => pose[0] === selfId))) {
|
|
418
727
|
this.joined = true;
|
|
728
|
+
this.starting = false;
|
|
729
|
+
this.joinFailures = 0;
|
|
419
730
|
console.log('[multiplayer] placed by the session');
|
|
731
|
+
this.joinStage('placed');
|
|
420
732
|
}
|
|
421
733
|
for (const id of msg.gone ?? []) {
|
|
422
734
|
this.gone.add(id);
|
|
@@ -496,6 +808,9 @@ class MultiplayerSystem {
|
|
|
496
808
|
// available through the system state.
|
|
497
809
|
game.state?.(scene, msg, this);
|
|
498
810
|
}
|
|
811
|
+
if (fresh) {
|
|
812
|
+
this.resumed();
|
|
813
|
+
}
|
|
499
814
|
this.placeGrants(scene);
|
|
500
815
|
}
|
|
501
816
|
|
|
@@ -1063,7 +1378,17 @@ class MultiplayerSystem {
|
|
|
1063
1378
|
// yet placed. A session that never answers releases it after JOIN_WAIT_MS so
|
|
1064
1379
|
// the deck is not stuck behind it.
|
|
1065
1380
|
joiningOverlayWanted() {
|
|
1066
|
-
if (this.
|
|
1381
|
+
if (this.net?.status().solo || this.joinError || (this.joinFailed && this.target?.mode !== 'hub')) {
|
|
1382
|
+
return false;
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
// A player behind the resume gate is covered even when the join was quiet:
|
|
1386
|
+
// the caller covered the join, not the return. So is the frame a returning
|
|
1387
|
+
// snapshot's placement takes the camera to follow.
|
|
1388
|
+
if (this.resume.armed || (this.wasAway && this.joined && (this.placedTo || this.settleFrames > 0))) {
|
|
1389
|
+
return true;
|
|
1390
|
+
}
|
|
1391
|
+
if (this.quiet) {
|
|
1067
1392
|
return false;
|
|
1068
1393
|
}
|
|
1069
1394
|
|
|
@@ -1087,12 +1412,21 @@ class MultiplayerSystem {
|
|
|
1087
1412
|
|
|
1088
1413
|
// Release scene resources and leave the session when the engine runtime ends.
|
|
1089
1414
|
dispose(scene) {
|
|
1415
|
+
this.generation += 1;
|
|
1416
|
+
this.starting = false;
|
|
1417
|
+
this.removeJoinFailure?.();
|
|
1418
|
+
this.removeJoinFailure = null;
|
|
1090
1419
|
game.dispose?.(scene, this);
|
|
1091
1420
|
this.reset(scene);
|
|
1092
1421
|
this.net?.close();
|
|
1093
1422
|
this.net = null;
|
|
1094
1423
|
this.joined = false;
|
|
1095
1424
|
this.joinStartedAt = 0;
|
|
1425
|
+
this.endAway();
|
|
1426
|
+
if (this.onVisibility) {
|
|
1427
|
+
document.removeEventListener('visibilitychange', this.onVisibility);
|
|
1428
|
+
this.onVisibility = null;
|
|
1429
|
+
}
|
|
1096
1430
|
showJoinOverlay(false);
|
|
1097
1431
|
// The badge is a fixed element outside the scene, so a disposed runtime
|
|
1098
1432
|
// (an editor preview closing, say) has to take it down explicitly.
|
|
@@ -1100,6 +1434,11 @@ class MultiplayerSystem {
|
|
|
1100
1434
|
}
|
|
1101
1435
|
}
|
|
1102
1436
|
|
|
1437
|
+
// Whether the page is hidden. False outside a browser.
|
|
1438
|
+
function pageHidden() {
|
|
1439
|
+
return typeof document !== 'undefined' && document.hidden === true;
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1103
1442
|
// File one player or object pose under the message's simulation timestamp.
|
|
1104
1443
|
function sample(tracks, msg, id, pose) {
|
|
1105
1444
|
// A WORLD message represents complete current state. Replace an existing track
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"@lezer/highlight": "^1.2.3",
|
|
21
21
|
"castle-web-fonts": "^1.0.0",
|
|
22
22
|
"codemirror": "^6.0.2",
|
|
23
|
+
"fflate": "^0.8.3",
|
|
23
24
|
"matter-js": "^0.20.0",
|
|
24
25
|
"react": "^19.2.4",
|
|
25
26
|
"react-dom": "^19.2.4",
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
},
|
|
32
33
|
"../../sdk": {
|
|
33
34
|
"name": "castle-web-sdk",
|
|
34
|
-
"version": "0.4.
|
|
35
|
+
"version": "0.4.49",
|
|
35
36
|
"dev": true,
|
|
36
37
|
"devDependencies": {
|
|
37
38
|
"eslint": "^9.0.0",
|
|
@@ -304,6 +305,12 @@
|
|
|
304
305
|
"integrity": "sha512-aK6BbWfhf4U/wCcLHKPJl/xa6VkVstRaPywWtMKGwuOLc/wZTyQYuoxgvZnNsBvv7Kg3YTBQYYBCggcviQczuA==",
|
|
305
306
|
"license": "MIT"
|
|
306
307
|
},
|
|
308
|
+
"node_modules/fflate": {
|
|
309
|
+
"version": "0.8.3",
|
|
310
|
+
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz",
|
|
311
|
+
"integrity": "sha512-tbZNuJrLwGUp3zshBtdy4W+ORxZuIh8a5ilyIEQDC5rY1f3U20JMry0Ll3WBzU58EZKsEuJFXhb5gwv8CsPvgA==",
|
|
312
|
+
"license": "MIT"
|
|
313
|
+
},
|
|
307
314
|
"node_modules/matter-js": {
|
|
308
315
|
"version": "0.20.0",
|
|
309
316
|
"resolved": "https://registry.npmjs.org/matter-js/-/matter-js-0.20.0.tgz",
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"private": true,
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "node scripts/test-own-name-tag.mjs && node scripts/test-eligible-claims.mjs",
|
|
6
|
+
"test": "node scripts/test-own-name-tag.mjs && node scripts/test-eligible-claims.mjs && node scripts/test-resume-gate.mjs && node scripts/test-join-watchdog.mjs",
|
|
7
7
|
"check": "eslint . && npm test && node --input-type=module -e \"const { bundleProject } = await import('../../cli/dist/bundle.js'); await bundleProject('.');\"",
|
|
8
8
|
"format": "prettier --write \"code/**/*.js\" castle.json package.json"
|
|
9
9
|
},
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@lezer/highlight": "^1.2.3",
|
|
23
23
|
"castle-web-fonts": "^1.0.0",
|
|
24
24
|
"codemirror": "^6.0.2",
|
|
25
|
+
"fflate": "^0.8.3",
|
|
25
26
|
"matter-js": "^0.20.0",
|
|
26
27
|
"react": "^19.2.4",
|
|
27
28
|
"react-dom": "^19.2.4",
|