@wildshard/engine 0.1.18 → 0.1.20
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/CHANGELOG.md +16 -0
- package/budgets/shard-size-baseline.json +10 -4
- package/index.html +6 -4
- package/lint/engine-sides.json +18 -0
- package/lint/ratchet.json +0 -68
- package/lint/ratchet.mjs +1 -4
- package/package.json +19 -15
- package/scripts/agent-sync.mjs +27 -8
- package/scripts/app-build/appCook.ts +8 -2
- package/scripts/app-build/catalogue.ts +10 -7
- package/scripts/app-build/gen.ts +33 -2
- package/scripts/app-build/isolation.d.mts +10 -0
- package/scripts/app-build/isolation.mjs +47 -0
- package/scripts/app-build/outputProducts.mjs +4 -0
- package/scripts/app-build/previousDeploy.d.mts +2 -0
- package/scripts/app-build/previousDeploy.mjs +10 -1
- package/scripts/app-build/serviceWorker.ts +10 -3
- package/scripts/app-build/splitOutput.mjs +4 -2
- package/scripts/app-build/standaloneOutput.d.mts +1 -1
- package/scripts/app-build/standaloneOutput.mjs +5 -3
- package/scripts/app-build/titlePreloads.d.mts +8 -0
- package/scripts/app-build/titlePreloads.mjs +69 -0
- package/scripts/app-build/worldMapAtlas.ts +10 -6
- package/scripts/app-build-pipeline.mjs +31 -3
- package/scripts/built-product.mjs +1 -1
- package/scripts/cell-mem-bench.mjs +83 -23
- package/scripts/check-custom-sections-zero.mjs +1 -1
- package/scripts/check-devserver.mjs +2 -0
- package/scripts/check-models.mjs +2 -0
- package/scripts/check-paths.allow.json +0 -115
- package/scripts/check-paths.mjs +2 -2
- package/scripts/check-platform-ratchets.mjs +2 -3
- package/scripts/chromium-keychain.d.mts +1 -1
- package/scripts/ci-static.sh +1 -1
- package/scripts/committed-fast-checks.mjs +0 -2
- package/scripts/content-sw-proof.mjs +2 -1
- package/scripts/cook-worker.mjs +9 -3
- package/scripts/cook.mjs +18 -5
- package/scripts/docs-inputs-proof.mjs +6 -6
- package/scripts/e7-voice-staging-proof.mjs +1 -1
- package/scripts/gate-related-tests.mjs +1 -1
- package/scripts/git-source-view.mjs +1 -1
- package/scripts/goldens/capture.mjs +17 -5
- package/scripts/grid-crossing-nightly.mjs +59 -0
- package/scripts/grid-crossing-qa.mjs +44 -0
- package/scripts/grid-crossing-ratchet.d.mts +6 -0
- package/scripts/grid-crossing-ratchet.mjs +52 -0
- package/scripts/grid-crossing-report.mjs +122 -0
- package/scripts/grid-crossing-stages.mjs +47 -0
- package/scripts/grid-crossing-tour.mjs +284 -0
- package/scripts/grid-crossing-walk-proof.mjs +126 -17
- package/scripts/host-ruler/roots.mjs +2 -2
- package/scripts/host-ruler.d.mts +91 -0
- package/scripts/host-ruler.mjs +565 -0
- package/scripts/land.mjs +2 -1
- package/scripts/live-prepush.py +3 -5
- package/scripts/loading-flow/benchmax.mjs +37 -12
- package/scripts/loading-flow/deskbench.mjs +276 -0
- package/scripts/loading-flow/stalls.d.mts +17 -3
- package/scripts/loading-flow/stalls.mjs +82 -3
- package/scripts/look-loop/test_look_loop.py +1 -38
- package/scripts/memory-proof.mjs +61 -6
- package/scripts/mmo-bots.mjs +8 -2
- package/scripts/net-lag-proof.mjs +219 -0
- package/scripts/night-market-kit-budget.mjs +2 -2
- package/scripts/nightly-model.ts +9 -6
- package/scripts/offline-proof-rules.d.mts +2 -2
- package/scripts/offline-proof-rules.mjs +15 -4
- package/scripts/offline-proof.mjs +80 -13
- package/scripts/{shard-platform-output.mjs → output-reader.mjs} +1 -1
- package/scripts/page-release/content.d.mts +9 -1
- package/scripts/page-release/content.mjs +131 -17
- package/scripts/page-release/flow.mjs +36 -10
- package/scripts/page-release/stamp-content.mjs +24 -0
- package/scripts/page-release.mjs +28 -6
- package/scripts/page-size.mjs +2 -1
- package/scripts/parity/boot-smoke.mjs +13 -2
- package/scripts/pin-format.ts +5 -2
- package/scripts/pin-packs.ts +1 -1
- package/scripts/pins-reuse.d.mts +1 -0
- package/scripts/pins-reuse.mjs +22 -0
- package/scripts/pins.ts +4 -4
- package/scripts/precommit-checks.mjs +1 -7
- package/scripts/precommit-jobs.mjs +0 -1
- package/scripts/precommit-source.py +1 -9
- package/scripts/program-discovery.mjs +1 -1
- package/scripts/ring-cook.mjs +2 -1
- package/scripts/ring-step.ts +1 -1
- package/scripts/scratch-dir.mjs +95 -0
- package/scripts/scratch-sweep.mjs +182 -0
- package/scripts/script-scenario-metrics.mjs +1 -1
- package/scripts/shard-output-content.d.mts +1 -1
- package/scripts/shard-output-content.mjs +2 -2
- package/scripts/shard-outputs.mjs +1 -1
- package/scripts/shard-public.mjs +1 -1
- package/scripts/shard-wire-meter.mjs +24 -9
- package/scripts/side-parity.mjs +4 -2
- package/scripts/standalone-smoke.mjs +8 -3
- package/scripts/tier-textures.mjs +22 -4
- package/scripts/tile-bake-report.mjs +1 -1
- package/scripts/tile-bakes.mjs +1 -1
- package/scripts/title-assets.generated.json +2 -0
- package/scripts/tsconfig.json +2 -14
- package/scripts/vendor/basisu/LICENSE +201 -0
- package/scripts/vendor/basisu/basis_encoder.cjs +2 -0
- package/scripts/vendor/basisu/basis_encoder.wasm +0 -0
- package/scripts/vitest-push-guards.config.ts +1 -1
- package/scripts/vps/harden-apply.sh +4 -1
- package/scripts/vps/harden-prometheus.sh +179 -0
- package/scripts/vps/harden.sh +16 -0
- package/scripts/vps/rebuild.sh +18 -0
- package/scripts/vps/wildshard-config +6 -2
- package/scripts/worker-client-play.mjs +6 -2
- package/scripts/worktree-reap.mjs +59 -13
- package/scripts/worktree.mjs +19 -5
- package/src/.oxlintrc.json +3 -182
- package/src/client/app/entry.ts +10 -2
- package/src/client/engine/anim/rigParser.ts +2 -2
- package/src/client/engine/boot/bootCache.ts +2 -2
- package/src/client/engine/boot/bootTrace.ts +12 -4
- package/src/client/engine/boot/browserChunkRecovery.ts +4 -0
- package/src/client/engine/boot/clearDownloads.ts +5 -2
- package/src/client/engine/boot/contentRead.ts +11 -0
- package/src/client/engine/boot/gpuFiles.ts +4 -2
- package/src/client/engine/boot/lastEnd.ts +99 -12
- package/src/client/engine/boot/texturePack.ts +2 -2
- package/src/client/engine/core/Game.ts +63 -19
- package/src/client/engine/core/gpuOnly.ts +10 -0
- package/src/client/engine/core/renderBudget.ts +134 -0
- package/src/client/engine/net/netPlayer.ts +19 -2
- package/src/client/engine/net/otherPlayers.ts +55 -8
- package/src/client/engine/net/predictor.ts +33 -9
- package/src/client/engine/net/redial.ts +68 -10
- package/src/client/engine/pwa/cacheNames.ts +58 -1
- package/src/client/engine/pwa/sw.js +41 -11
- package/src/client/engine/render/dataLook.ts +219 -44
- package/src/client/engine/render/families/detail.ts +89 -0
- package/src/client/engine/render/families/pbr.ts +9 -1
- package/src/client/engine/render/families/registry.ts +11 -2
- package/src/client/engine/render/families/sceneSurface.ts +116 -0
- package/src/client/engine/render/look.ts +12 -0
- package/src/client/engine/render/lookLight.ts +103 -11
- package/src/client/engine/render/lookRender.ts +105 -0
- package/src/client/engine/render/precompile.ts +4 -2
- package/src/client/engine/render/tiers.ts +4 -1
- package/src/client/engine/saves/indexed.ts +2 -2
- package/src/client/engine/telemetry/browserErrors.ts +24 -3
- package/src/client/engine/telemetry/staleBuildReport.ts +22 -1
- package/src/client/engine/ui/debugOptions.ts +1 -1
- package/src/client/engine/ui/lookLightOption.ts +10 -6
- package/src/client/engine/ui/namePrompt.ts +7 -0
- package/src/client/engine/world/declaredProps.ts +5 -1
- package/src/client/engine/world/skyRig.ts +4 -1
- package/src/client/engine/world/terrainTileView.ts +64 -23
- package/src/client/game/boot/audio.generated.ts +114 -114
- package/src/client/game/boot/bytes.generated.ts +118 -220
- package/src/client/game/boot/placedSpawn.ts +35 -0
- package/src/client/game/boot/spawnDownload.ts +25 -6
- package/src/client/game/boot/versions.generated.ts +7 -5
- package/src/client/game/devScene/hook.ts +428 -0
- package/src/client/game/devScene/liveLook.ts +21 -0
- package/src/client/game/grid/cellLoading.ts +12 -2
- package/src/client/game/grid/live.ts +152 -19
- package/src/client/game/grid/liveSession.ts +53 -3
- package/src/client/game/grid/mapAtlas.ts +18 -4
- package/src/client/game/grid/minimapBlend.ts +15 -5
- package/src/client/game/grid/oneWayIn.ts +5 -1
- package/src/client/game/grid/pageEntry.ts +12 -1
- package/src/client/game/grid/placedCells.ts +114 -12
- package/src/client/game/grid/placedContent.ts +85 -0
- package/src/client/game/grid/prefetch.ts +9 -1
- package/src/client/game/grid/productInputs.ts +23 -10
- package/src/client/game/grid/productLeases.ts +4 -1
- package/src/client/game/grid/products.ts +8 -4
- package/src/client/game/grid/roadLook.ts +24 -15
- package/src/client/game/grid/roadLookPlatform.ts +4 -2
- package/src/client/game/grid/roadResources.ts +24 -0
- package/src/client/game/grid/roadSign.worker.ts +4 -3
- package/src/client/game/grid/roadSignPaint.ts +16 -5
- package/src/client/game/grid/roadSignPreparation.ts +4 -3
- package/src/client/game/grid/roadSignScale.ts +8 -0
- package/src/client/game/grid/roadTileCapture.worker.ts +3 -1
- package/src/client/game/grid/roadTileCaptureWorker.ts +2 -1
- package/src/client/game/grid/roadTileWrite.worker.ts +4 -2
- package/src/client/game/grid/roadTileWriter.ts +2 -1
- package/src/client/game/grid/screenReports.ts +39 -0
- package/src/client/game/grid/session.ts +32 -7
- package/src/client/game/grid/softWallLook.ts +25 -8
- package/src/client/game/mainMenu.ts +6 -2
- package/src/client/game/plugin/context.ts +2 -1
- package/src/client/game/plugin/followedMovers.ts +7 -1
- package/src/client/game/quest/figures.ts +2 -0
- package/src/client/game/session/finish.ts +9 -0
- package/src/client/game/shardfile/assetCache.ts +4 -4
- package/src/client/game/shardfile/client.ts +28 -8
- package/src/client/game/shardfile/clientAssets.ts +9 -5
- package/src/client/game/shardfile/clientLibrary.ts +1 -1
- package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
- package/src/client/game/shardfile/clientViews.ts +36 -8
- package/src/client/game/shardfile/clientWater.ts +51 -9
- package/src/client/game/shardfile/clientWorker.ts +19 -7
- package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
- package/src/client/game/shardfile/groundMerge.ts +57 -5
- package/src/client/game/shardfile/hybrid.ts +2 -0
- package/src/client/game/shardfile/look.ts +8 -3
- package/src/client/game/shardfile/product.ts +34 -7
- package/src/client/game/shardfile/productChecks.ts +2 -2
- package/src/client/game/shardfile/productCost.ts +2 -2
- package/src/client/game/shardfile/readAsset.ts +2 -2
- package/src/client/game/shardfile/reflectingWater.ts +73 -0
- package/src/client/game/shardfile/seatGrace.ts +9 -0
- package/src/client/game/shardfile/skinPlayback.ts +1 -1
- package/src/client/game/shardfile/slabLibrary.ts +115 -49
- package/src/client/game/shardfile/tileContent.ts +1 -1
- package/src/client/game/shardfile/tileDriver.ts +38 -11
- package/src/client/game/shardfile/wirePage.ts +7 -3
- package/src/client/game/shardfile/worldScenes.ts +17 -10
- package/src/client/game/systems/npc/figureRows.ts +9 -0
- package/src/client/host/online/doctor.ts +22 -7
- package/src/client/host/online/doctorView.ts +2 -0
- package/src/client/host/online/linkScreens.ts +109 -5
- package/src/client/host/online/shell.ts +13 -4
- package/src/client/host/standalone/shell.ts +40 -0
- package/src/cook/game/astc6Encode.ts +55 -0
- package/src/cook/game/astc6Wasm.ts +176 -0
- package/src/cook/game/cookJob.ts +30 -6
- package/src/cook/game/cookWorker.ts +38 -11
- package/src/cook/game/entryTotals.ts +51 -24
- package/src/cook/game/shardCook.ts +35 -7
- package/src/cook/game/spawnParts.ts +33 -8
- package/src/cook/game/tierTextures.ts +87 -14
- package/src/server/engine/ai/bossContenders.ts +27 -3
- package/src/server/engine/ai/phases.ts +1 -1
- package/src/server/engine/entities/creatureRefill.ts +9 -2
- package/src/server/engine/net/ledgerBook.ts +2 -0
- package/src/server/engine/net/room.ts +15 -0
- package/src/server/engine/sim/respawn.ts +8 -0
- package/src/server/game/boss/arenaRoomEntry.ts +5 -1
- package/src/server/game/boss/arenaRoomNative.ts +2 -0
- package/src/server/game/boss/native.ts +2 -1
- package/src/server/game/boss/nativeWake.ts +9 -5
- package/src/server/game/boss/openArenaNative.ts +2 -2
- package/src/server/game/boss/openArenaRoom.ts +3 -1
- package/src/server/game/grid/room.ts +44 -3
- package/src/server/game/grid/simulation.ts +23 -0
- package/src/server/game/population/mixedRoster.ts +11 -3
- package/src/server/game/population/nativeBake.ts +8 -3
- package/src/server/game/population/nativeReturns.ts +6 -3
- package/src/server/game/population/roster.ts +5 -3
- package/src/server/game/quest/eliteDrops.ts +18 -3
- package/src/server/game/quest/nativeChapter.ts +1 -1
- package/src/server/game/quest/nativeComposition.ts +5 -1
- package/src/server/game/riding/nativeTaming.ts +22 -7
- package/src/server/game/riding/wildRefill.ts +3 -2
- package/src/server/game/shardfile/bossRow.ts +4 -2
- package/src/server/game/shardfile/homeKeeper.ts +4 -2
- package/src/server/host/bake/headlessWorker.ts +1 -1
- package/src/server/host/dedicated/cellHost.ts +112 -18
- package/src/server/host/dedicated/cellProtocol.ts +18 -1
- package/src/server/host/dedicated/cellWorker.ts +8 -5
- package/src/server/host/dedicated/dedicatedRoom.ts +38 -11
- package/src/server/host/dedicated/gridCells.ts +15 -6
- package/src/server/host/dedicated/loopLag.ts +21 -0
- package/src/server/host/dedicated/main.ts +13 -5
- package/src/server/host/dedicated/packReader.ts +3 -3
- package/src/server/host/dedicated/placementFile.ts +3 -2
- package/src/server/host/dedicated/roadRoom.ts +34 -4
- package/src/server/host/dedicated/serverMetrics.ts +135 -0
- package/src/server/host/dedicated/socketPump.ts +21 -4
- package/src/server/host/dedicated/workerTable.ts +32 -14
- package/src/server/host/dedicated/world.ts +65 -7
- package/src/server/host/headless.ts +1 -1
- package/src/server/host/headlessRuntime.ts +1 -1
- package/src/server/host/standalone/roadWorld.ts +15 -3
- package/src/server/host/standalone/serverHost.ts +57 -8
- package/src/server/host/standalone/serverProduct.ts +48 -16
- package/src/server/host/standalone/serverRuntime.ts +1 -1
- package/src/shared/engine/ai/BossBrain.ts +8 -0
- package/src/shared/engine/core/framePacing.ts +12 -1
- package/src/shared/engine/physics/terrainTiles.ts +20 -4
- package/src/shared/game/boss/wake.ts +6 -0
- package/src/shared/game/devColliders.ts +107 -0
- package/src/shared/game/devGameplay.ts +41 -0
- package/src/shared/game/eliteSystem.ts +8 -0
- package/src/shared/game/grid/allocator.ts +3 -0
- package/src/shared/game/grid/placementRows.ts +5 -2
- package/src/shared/game/plugin/bossRecord.ts +3 -2
- package/src/shared/game/shardfile/ktx2Targets.ts +23 -3
- package/src/shared/game/shardfile/outputDescriptor.ts +9 -5
- package/src/shared/game/shardfile/packReads.ts +28 -3
- package/src/shared/game/shardfile/serverPack.ts +9 -0
- package/src/shared/game/systems/looks/trampleField.ts +2 -0
- package/src/shared/host/formatJsonSchema.ts +2 -2
- package/src/tsconfig.json +1 -27
- package/lint/host-reviews.json +0 -14
- package/lint/listed-view-code.json +0 -13
- package/lint/platform-pending-users.json +0 -2520
- package/lint/platform-pending-users.md +0 -18
- package/scripts/cell-mem/metrics-preload.mjs +0 -65
- package/scripts/check-closed-components.d.mts +0 -7
- package/scripts/check-closed-components.mjs +0 -87
- package/scripts/g571-hosts.d.mts +0 -3
- package/scripts/g571-hosts.mjs +0 -54
- package/scripts/host-ruler/register-migrate.mjs +0 -242
- package/scripts/listed-view-code.d.mts +0 -7
- package/scripts/listed-view-code.mjs +0 -93
- package/scripts/look-loop/fit-lut.py +0 -142
- package/scripts/look-loop/palette-delta.py +0 -183
- package/scripts/look-loop/regions/driftwood-isle.json +0 -25
- package/scripts/look-loop/regions/far-reach.json +0 -225
- package/scripts/look-loop/regions/open-plot-night-market.json +0 -855
- package/scripts/look-loop/regions/pine-hollow.json +0 -22
- package/scripts/look-loop/regions/sunscar-dunes.json +0 -281
- package/scripts/platform-chargebacks.d.mts +0 -9
- package/scripts/platform-chargebacks.mjs +0 -135
- package/scripts/shard-component-spans.d.mts +0 -15
- package/scripts/shard-component-spans.mjs +0 -18
- package/scripts/shard-components.d.mts +0 -16
- package/scripts/shard-components.mjs +0 -363
- package/scripts/shard-platform-hosts.d.mts +0 -2
- package/scripts/shard-platform-hosts.mjs +0 -93
- package/scripts/shard-platform-sections.d.mts +0 -2
- package/scripts/shard-platform-sections.mjs +0 -9
- package/scripts/shard-platform.d.mts +0 -76
- package/scripts/shard-platform.mjs +0 -1072
- package/src/.oxfmtrc.json +0 -48
- package/src/scripts/ask-new.sh +0 -29
- package/src/scripts/asks.mjs +0 -142
- package/src/scripts/herdr-prompt.sh +0 -34
- package/src/scripts/herdr-question-open.sh +0 -67
- package/src/scripts/md-wrap.mjs +0 -229
- /package/scripts/{shard-platform-format.d.mts → node-format.d.mts} +0 -0
- /package/scripts/{shard-platform-format.mjs → node-format.mjs} +0 -0
- /package/scripts/{shard-platform-output.d.mts → output-reader.d.mts} +0 -0
|
@@ -14,7 +14,7 @@ import { RemoteStrike } from './remoteStrike';
|
|
|
14
14
|
import { NameTag, type NameTagShown } from './nameTag';
|
|
15
15
|
import { RemoteDeath, type DeathPhase } from './remoteDeath';
|
|
16
16
|
import { RemoteHurt, type HurtShown } from './remoteHurt';
|
|
17
|
-
import { HeldInHand } from './heldOnOthers';
|
|
17
|
+
import { HeldInHand, heldOnOthers } from './heldOnOthers';
|
|
18
18
|
import type { NetClient } from './client';
|
|
19
19
|
import { othersOnMap } from './othersOnMap';
|
|
20
20
|
import { talkerKey, voiceNear, type Talker } from './voiceNear';
|
|
@@ -169,8 +169,58 @@ class OtherBody {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
/** Every other player's body, kept to the client's rows. */
|
|
172
|
+
/** A body leaving: the castaway's mesh and contact disc are shared by every body (userData.shared), so only its own are freed, its
|
|
173
|
+
* skeleton's bone texture with them. A sprite's geometry is three's own, shared by every sprite. Its held item, the kit's copy,
|
|
174
|
+
* is let go of first (`undress`). */
|
|
175
|
+
function freeBody(group: THREE.Object3D): void {
|
|
176
|
+
group.traverse(node => {
|
|
177
|
+
if (node instanceof THREE.SkinnedMesh) node.skeleton.dispose();
|
|
178
|
+
if (node instanceof THREE.Mesh) { const geometry = node.geometry as THREE.BufferGeometry; if (geometry.userData['shared'] !== true) geometry.dispose(); }
|
|
179
|
+
if (node instanceof THREE.Mesh || node instanceof THREE.Sprite) { for (const material of [node.material].flat() as THREE.Material[]) { if (material.userData['shared'] === true) continue; if (material instanceof THREE.SpriteMaterial) material.map?.dispose(); material.dispose(); } }
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** NET-LAG NL4: the warm body's depth under the world, out of every view; its slots tried for the kit's held items. */
|
|
184
|
+
const WARM_DEPTH = -1000, WARM_SLOTS = 16;
|
|
185
|
+
/**
|
|
186
|
+
* NET-LAG NL4 (Jake's 60 ms frames in Driftwood): the first other player to come into view linked its body's programs inside
|
|
187
|
+
* that frame, the castaway's skinned body, its contact disc, its Name and the held item in the world's light (the item's
|
|
188
|
+
* first-person program is another): 4 programs in a 200 ms frame, 20 in a 440 ms one, on desktop Chromium's Metal. One body
|
|
189
|
+
* of the same build is drawn from the start, under the world, never culled, so the boot's in-play warm-up links those
|
|
190
|
+
* programs paced and every body after it draws with programs already built (three keys a program by its material's settings,
|
|
191
|
+
* so a body's own deck materials share the warm deck's). It holds every slot of the kit lent now, and
|
|
192
|
+
* takes the new kit's items when a crossing lends one (the old copies are freed with their kit).
|
|
193
|
+
*/
|
|
194
|
+
class WarmBody {
|
|
195
|
+
readonly group = new THREE.Group();
|
|
196
|
+
private readonly hand: THREE.Object3D | null;
|
|
197
|
+
private readonly items = new THREE.Group();
|
|
198
|
+
private kit = -1;
|
|
199
|
+
constructor() {
|
|
200
|
+
this.group.name = 'other-player-warm'; this.group.position.y = WARM_DEPTH;
|
|
201
|
+
const model = castawayBody(), board = new BoardUnder();
|
|
202
|
+
board.deck.visible = true; // a rider's deck, shown here so its programs warm too
|
|
203
|
+
this.group.add(model.root, groundContact(), nameTag('warm'), board.deck);
|
|
204
|
+
this.hand = model.mounts.rightHand;
|
|
205
|
+
this.hand.add(this.items);
|
|
206
|
+
this.unculled();
|
|
207
|
+
}
|
|
208
|
+
private slot = WARM_SLOTS;
|
|
209
|
+
/** Each frame: a newly lent kit's items replace the last's, one slot a frame (each first copy clones a first-person model). */
|
|
210
|
+
frame(): void {
|
|
211
|
+
if (this.kit !== heldOnOthers.lent) { this.kit = heldOnOthers.lent; this.items.clear(); this.slot = 0; }
|
|
212
|
+
if (this.slot >= WARM_SLOTS) return;
|
|
213
|
+
const held = heldOnOthers.prop(this.slot++);
|
|
214
|
+
if (held !== null) { const item = held.prop.clone(); item.traverse(node => { node.frustumCulled = false; }); this.items.add(item); }
|
|
215
|
+
}
|
|
216
|
+
/** Drawn wherever the camera looks, so the warm-up and every frame count its programs as used. */
|
|
217
|
+
private unculled(): void { this.group.traverse(node => { node.frustumCulled = false; }); }
|
|
218
|
+
dispose(): void { this.group.removeFromParent(); this.items.clear(); freeBody(this.group); }
|
|
219
|
+
}
|
|
220
|
+
|
|
172
221
|
export class OtherPlayers {
|
|
173
222
|
private readonly bodies = new Map<number, OtherBody>();
|
|
223
|
+
private readonly warm: WarmBody | null = null;
|
|
174
224
|
private readonly client: NetClient;
|
|
175
225
|
private readonly scene: THREE.Object3D;
|
|
176
226
|
private readonly row = new Float64Array(PLAYER_CLASS.row.length);
|
|
@@ -179,6 +229,8 @@ export class OtherPlayers {
|
|
|
179
229
|
constructor(client: NetClient, scene: THREE.Object3D, scope: Scope, me: Readonly<THREE.Vector3> | null = null) {
|
|
180
230
|
this.client = client; this.scene = scene; this.me = me;
|
|
181
231
|
scope.onDispose(() => { for (const handle of this.bodies.keys()) this.drop(handle); });
|
|
232
|
+
try { const warm = new WarmBody(); scene.add(warm.group); this.warm = warm; scope.onDispose(() => { warm.dispose(); }); }
|
|
233
|
+
catch (error) { console.error('[other players] warm body', error); }
|
|
182
234
|
if (me !== null) scope.onDispose(voiceNear.lend({ distanceTo: talker => this.distanceTo(talker) }));
|
|
183
235
|
}
|
|
184
236
|
/** Metres to a talker's body, as drawn: the body with its row's id, or, from a server that names none, the nearest with its Name. */
|
|
@@ -209,6 +261,7 @@ export class OtherPlayers {
|
|
|
209
261
|
return body !== undefined;
|
|
210
262
|
}
|
|
211
263
|
frame(renderTick: number, dt: number): void {
|
|
264
|
+
this.warm?.frame();
|
|
212
265
|
const { client, bodies, row } = this, own = client.welcome?.handle ?? 0;
|
|
213
266
|
for (const handle of bodies.keys()) if (!client.entities.has(handle)) this.drop(handle);
|
|
214
267
|
for (const [handle, info] of client.entities) {
|
|
@@ -228,12 +281,6 @@ export class OtherPlayers {
|
|
|
228
281
|
const body = this.bodies.get(handle);
|
|
229
282
|
if (body === undefined) return;
|
|
230
283
|
this.bodies.delete(handle); this.scene.remove(body.group); body.undress();
|
|
231
|
-
|
|
232
|
-
// bone texture with them. A sprite's geometry is three's own, shared by every sprite.
|
|
233
|
-
body.group.traverse(node => {
|
|
234
|
-
if (node instanceof THREE.SkinnedMesh) node.skeleton.dispose();
|
|
235
|
-
if (node instanceof THREE.Mesh) { const geometry = node.geometry as THREE.BufferGeometry; if (geometry.userData['shared'] !== true) geometry.dispose(); }
|
|
236
|
-
if (node instanceof THREE.Mesh || node instanceof THREE.Sprite) { for (const material of [node.material].flat() as THREE.Material[]) { if (material.userData['shared'] === true) continue; if (material instanceof THREE.SpriteMaterial) material.map?.dispose(); material.dispose(); } }
|
|
237
|
-
});
|
|
284
|
+
freeBody(body.group);
|
|
238
285
|
}
|
|
239
286
|
}
|
|
@@ -30,8 +30,20 @@ export const PREDICTION_SNAP = 3;
|
|
|
30
30
|
const RIDE_ROOM = 64;
|
|
31
31
|
/** One saved move. */
|
|
32
32
|
const SAVED_WORDS: number = MOTION_WORDS + RIDE_ROOM;
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* NET-LAG NL12 (b): a correction glides at a steady pace over a time scaled to its size, never as a step. At 150 to 200 ms
|
|
35
|
+
* (J282) corrections are routine, and an exponential glide moved the drawn feet most in its first frame: a third of a 0.3 m
|
|
36
|
+
* correction in one 30 fps frame. Metres a second the glide adds on top of the feet's own motion, under half a walk.
|
|
37
|
+
*/
|
|
38
|
+
export const GLIDE_SPEED = 2;
|
|
39
|
+
/** The shortest glide: 4 frames at 30 fps, 8 at 60. */
|
|
40
|
+
export const GLIDE_MIN_S: number = 4 / 30;
|
|
41
|
+
/** The longest: a correction near the snap distance still settles within half a second. */
|
|
42
|
+
export const GLIDE_MAX_S = 0.5;
|
|
43
|
+
/** The pace that glides `distance` away: its own size over GLIDE_SPEED, held between the shortest and longest glide. */
|
|
44
|
+
function glidePace(distance: number): number {
|
|
45
|
+
return distance / Math.min(GLIDE_MAX_S, Math.max(GLIDE_MIN_S, distance / GLIDE_SPEED));
|
|
46
|
+
}
|
|
35
47
|
|
|
36
48
|
/** What a predictor drives. */
|
|
37
49
|
export interface PredictedBody {
|
|
@@ -105,6 +117,8 @@ export class Predictor {
|
|
|
105
117
|
private resets: number | null = null;
|
|
106
118
|
/** The newest frame has this body on a ride. */
|
|
107
119
|
private aboard = false;
|
|
120
|
+
/** Metres a second the render offset loses now (NL12 b). */
|
|
121
|
+
private glide = 0;
|
|
108
122
|
constructor(body: PredictedBody, columns: readonly NetColumn<never>[], corrected?: (row:Omit<NetCorrection,'kind'|'session'>)=>void) {
|
|
109
123
|
this.corrected=corrected;
|
|
110
124
|
this.body = body; this.columns = columns; this.table = ownerTable(columns);
|
|
@@ -154,6 +168,8 @@ export class Predictor {
|
|
|
154
168
|
const saved = offset >= 0 && offset < count, slot = (head + offset) % PREDICTION_RING, at = slot * SAVED_WORDS; // else older than the ring, or nothing saved
|
|
155
169
|
if (saved) { this.head = (slot + 1) % PREDICTION_RING; this.count = count - offset - 1; }
|
|
156
170
|
if (!forced && (!saved || this.matches(slot, owner, ridden))) return false;
|
|
171
|
+
// NL12 (c): the write below can take feet under a deck only if the server's world lacks the deck; NL5 gave the room the same
|
|
172
|
+
// rope planks (`server/host/ropeDecks.ts`), and `test/net-predict-deck.test.ts` replays a correction 0.3 to 1 m low back onto them
|
|
157
173
|
const s = body.motionState, { ride } = body, feet = ride?.feet ?? s.position, x = feet.x + body.renderOffset.x, y = feet.y + body.renderOffset.y, z = feet.z + body.renderOffset.z, { yaw } = s;
|
|
158
174
|
if (saved) restoreMotion(s, body.motor, states, at);
|
|
159
175
|
if (saved && this.rode[slot] === 1) ride?.restore(states, at + MOTION_WORDS);
|
|
@@ -169,13 +185,14 @@ export class Predictor {
|
|
|
169
185
|
if (!led && !boarded) this.corrections++;
|
|
170
186
|
const offsetX = x - feet.x, offsetY = y - feet.y, offsetZ = z - feet.z, far = offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ > PREDICTION_SNAP * PREDICTION_SNAP;
|
|
171
187
|
body.renderOffset.set(far ? 0 : offsetX, far ? 0 : offsetY, far ? 0 : offsetZ);
|
|
188
|
+
this.glide = glidePace(body.renderOffset.length());
|
|
172
189
|
if(!led&&!boarded)this.corrected?.({tick:tick??s.tick,mode:ride!==null?'ride':s.board.on?'board':s.swim.on?'swim':'foot',offset:Math.hypot(offsetX,offsetY,offsetZ),snapped:far});
|
|
173
190
|
return !led && !boarded;
|
|
174
191
|
}
|
|
175
192
|
|
|
176
193
|
/** A session's first frame: this body stands where the server says, with nothing to compare it to. */
|
|
177
|
-
adopt(lastSeq: number, owner: ArrayLike<number>, tick?: number, ridden: ArrayLike<number> | null = null): void {
|
|
178
|
-
const { body, table } = this, s = body.motionState, { yaw } = s;
|
|
194
|
+
adopt(lastSeq: number, owner: ArrayLike<number>, tick?: number, ridden: ArrayLike<number> | null = null, glide = false): void {
|
|
195
|
+
const { body, table } = this, s = body.motionState, { yaw } = s, was = { x: s.position.x, y: s.position.y, z: s.position.z };
|
|
179
196
|
if (tick !== undefined) s.tick = tick;
|
|
180
197
|
this.acked = lastSeq; this.led = this.flag(table.led, owner) === 1; this.resets = this.value(table.resets, owner); this.aboard = ridden !== null;
|
|
181
198
|
this.head = 0; this.count = 0;
|
|
@@ -185,14 +202,21 @@ export class Predictor {
|
|
|
185
202
|
this.write(s, owner); // the reset cleared the ground the owner block had just landed
|
|
186
203
|
if (ridden !== null) body.ride?.adopt(ridden);
|
|
187
204
|
body.renderOffset.set(0, 0, 0);
|
|
205
|
+
// OFFLINE OF10: a page that played unseated glides onto its seat when it is near, as a correction does; a far seat snaps
|
|
206
|
+
if (glide) {
|
|
207
|
+
const dx = was.x - s.position.x, dy = was.y - s.position.y, dz = was.z - s.position.z;
|
|
208
|
+
if (Math.hypot(dx, dy, dz) < PREDICTION_SNAP) body.renderOffset.set(dx, dy, dz);
|
|
209
|
+
}
|
|
210
|
+
this.glide = glidePace(body.renderOffset.length());
|
|
188
211
|
}
|
|
189
212
|
|
|
190
|
-
/** Each render frame: the camera glides back onto the predicted feet. */
|
|
213
|
+
/** Each render frame: the camera glides back onto the predicted feet at the correction's steady pace (NL12 b). */
|
|
191
214
|
update(dt: number): void {
|
|
192
|
-
const { renderOffset } = this.body;
|
|
193
|
-
if (
|
|
194
|
-
|
|
195
|
-
if (
|
|
215
|
+
const { renderOffset } = this.body, left = renderOffset.length();
|
|
216
|
+
if (left === 0) return;
|
|
217
|
+
const step = (this.glide > 0 ? this.glide : glidePace(left)) * dt;
|
|
218
|
+
if (step >= left || left - step < 1e-4) renderOffset.set(0, 0, 0);
|
|
219
|
+
else renderOffset.multiplyScalar((left - step) / left);
|
|
196
220
|
}
|
|
197
221
|
|
|
198
222
|
private matches(slot: number, owner: ArrayLike<number>, ridden: ArrayLike<number> | null): boolean {
|
|
@@ -8,10 +8,14 @@ import type { NetClient } from './client';
|
|
|
8
8
|
export type LinkState = 'live' | 'reconnecting' | 'resuming' | 'lost' | 'full' | 'ended';
|
|
9
9
|
/** Why a link is down, as far as a browser can tell (meta MMO-FAILURE-MODES-PLAN FM4): `silent` stopped carrying frames (a half-open
|
|
10
10
|
* socket), `closed` was closed with no word (1006, a reset), `restart` was closed by a restarting server, `hidden` went quiet while the
|
|
11
|
-
* page was out of view. It rides `onState`'s reason for `reconnecting` and `resuming`. */
|
|
12
|
-
export type LinkCause = 'silent' | 'closed' | 'restart' | 'hidden' | 'updating';
|
|
11
|
+
* page was out of view, `offline` is a device that says it has no network (FM4b mode 2). It rides `onState`'s reason for `reconnecting` and `resuming`. */
|
|
12
|
+
export type LinkCause = 'silent' | 'closed' | 'restart' | 'hidden' | 'updating' | 'offline';
|
|
13
13
|
/** Where the dial is, for a screen that shows it: dials so far, the wait to the next (null while one is out), and how long it's been down. */
|
|
14
|
-
export interface LinkProgress { readonly dials: number; readonly nextDialMs: number | null; readonly downMs: number }
|
|
14
|
+
export interface LinkProgress { readonly dials: number; readonly nextDialMs: number | null; readonly downMs: number; readonly away?: LinkAway }
|
|
15
|
+
/** FM4b modes 4 and 45: the page was away for `ms` and came back to a quiet or closed link. `hidden` is time out of view the page
|
|
16
|
+
* measured (visibilitychange); `asleep` is a gap in the page's own clock ticks while it wasn't known hidden (a sleep, a frozen tab).
|
|
17
|
+
* It says nothing about the world's hold on the seat (J114): only what this page measured. */
|
|
18
|
+
export interface LinkAway { readonly ms: number; readonly how: 'hidden' | 'asleep' }
|
|
15
19
|
|
|
16
20
|
/** No frame for this long: say so. The predictor's ring is full by then, so the player holds still. */
|
|
17
21
|
const STRIP_MS = 1000;
|
|
@@ -24,6 +28,8 @@ const GIVE_UP_MS = 120_000;
|
|
|
24
28
|
/** The waits between dials, then the last for ever, each ±20%. */
|
|
25
29
|
const DIAL_WAITS_MS = [250, 500, 1000, 2000, 4000], DIAL_JITTER = 0.2;
|
|
26
30
|
const WATCH_MS = 100;
|
|
31
|
+
/** FM4b modes 4 and 45: away this long (out of view, or no clock tick at all) and back to a quiet link is the Welcome back card. */
|
|
32
|
+
const AWAY_MS = 30_000;
|
|
27
33
|
/** Words from a server that a redial would only hear again. */
|
|
28
34
|
const FINAL = new Set(['reload', 'refused', 'replaced']);
|
|
29
35
|
/** J178: the world is full, and a seat frees when someone leaves: this long between tries, for as long as the player waits. */
|
|
@@ -51,7 +57,10 @@ export interface RedialOptions {
|
|
|
51
57
|
readonly onCut?: (reason: string) => void;
|
|
52
58
|
readonly now?: () => number;
|
|
53
59
|
readonly random?: () => number;
|
|
60
|
+
/** FM4b mode 2: does the device say it has a network? Default `navigator.onLine`; a browser with no answer counts as online. */
|
|
61
|
+
readonly online?: () => boolean;
|
|
54
62
|
}
|
|
63
|
+
const browserOnline = (): boolean => typeof navigator === 'undefined' || (navigator as { onLine?: boolean }).onLine !== false;
|
|
55
64
|
|
|
56
65
|
/**
|
|
57
66
|
* E7.1: one client's link, kept up. It watches for frames, and a link that stops carrying them is closed and dialled again on a
|
|
@@ -62,6 +71,7 @@ export class Redial {
|
|
|
62
71
|
private readonly scope = new Scope('net.redial');
|
|
63
72
|
private readonly now: () => number;
|
|
64
73
|
private readonly random: () => number;
|
|
74
|
+
private readonly online: () => boolean;
|
|
65
75
|
private readonly offFrame: () => void;
|
|
66
76
|
private transport: Transport;
|
|
67
77
|
private offClose: () => void;
|
|
@@ -75,8 +85,14 @@ export class Redial {
|
|
|
75
85
|
private dialled: number | null = null;
|
|
76
86
|
private waitingForSeat = false;
|
|
77
87
|
private cause: LinkCause = 'closed';
|
|
88
|
+
/** When the device last said it went offline while the link was down; null while it has a network. */
|
|
89
|
+
private offlineAt: number | null = null;
|
|
90
|
+
/** The watch's last tick: a gap after it is time the page did nothing at all (FM4b mode 45). */
|
|
91
|
+
private tickAt: number;
|
|
92
|
+
private awayFor: LinkAway | null = null;
|
|
78
93
|
constructor(options: RedialOptions) {
|
|
79
|
-
this.options = options; this.transport = options.transport; this.now = options.now ?? diagnosticNow; this.random = options.random ?? jitterFrom(this.now());
|
|
94
|
+
this.options = options; this.transport = options.transport; this.now = options.now ?? diagnosticNow; this.random = options.random ?? jitterFrom(this.now()); this.online = options.online ?? browserOnline;
|
|
95
|
+
this.tickAt = this.now();
|
|
80
96
|
this.offFrame = options.client.onFrame(() => { this.heard(); });
|
|
81
97
|
this.offClose = this.watchClose(options.transport);
|
|
82
98
|
this.scope.interval(WATCH_MS, () => { this.watch(); });
|
|
@@ -90,11 +106,14 @@ export class Redial {
|
|
|
90
106
|
/** The dial's progress now. */
|
|
91
107
|
get progress(): LinkProgress {
|
|
92
108
|
const now = this.now(), down = this.phase !== 'up';
|
|
93
|
-
|
|
109
|
+
const away = this.awayFor === null ? {} : { away: this.awayFor };
|
|
110
|
+
return { dials: this.dials, nextDialMs: this.phase === 'down' && this.dialled === null ? Math.max(0, this.dialAt - now) : null, downMs: down ? Math.max(0, now - this.lostAt) : 0, ...away };
|
|
94
111
|
}
|
|
95
|
-
/** The page came back into view (an iPhone returning to Safari): a link that went quiet while hidden redials at once.
|
|
96
|
-
|
|
112
|
+
/** The page came back into view (an iPhone returning to Safari): a link that went quiet while hidden redials at once.
|
|
113
|
+
* `hiddenMs` is how long the page measured itself out of view (FM4b mode 4). */
|
|
114
|
+
check(hiddenMs = 0): void {
|
|
97
115
|
const now = this.now();
|
|
116
|
+
this.woke(now, hiddenMs);
|
|
98
117
|
if (this.phase === 'up' && this.heardAt !== null && now - this.heardAt >= STRIP_MS) { this.because('hidden'); this.lose(now); }
|
|
99
118
|
// a link that went silent while the page was away was the page's absence: say welcome back
|
|
100
119
|
if (this.phase === 'down') { if (this.cause === 'silent') this.because('hidden'); this.dialAt = now; }
|
|
@@ -112,26 +131,44 @@ export class Redial {
|
|
|
112
131
|
private heard(): void {
|
|
113
132
|
const now = this.now(), wasDown = this.phase === 'down';
|
|
114
133
|
this.heardAt = now;
|
|
115
|
-
if (wasDown) { this.phase = 'up'; this.dialled = null; this.dials = 0; this.waitingForSeat = false; }
|
|
134
|
+
if (wasDown) { this.phase = 'up'; this.dialled = null; this.dials = 0; this.waitingForSeat = false; this.offlineAt = null; this.awayFor = null; }
|
|
116
135
|
this.show('live');
|
|
117
136
|
}
|
|
118
137
|
private watch(): void {
|
|
119
138
|
const now = this.now();
|
|
139
|
+
this.woke(now, 0);
|
|
120
140
|
if (this.phase === 'up') {
|
|
121
141
|
if (this.heardAt === null) return;
|
|
122
142
|
const silent = now - this.heardAt;
|
|
123
|
-
if (silent >= STRIP_MS && this.state === 'live') this.because('silent');
|
|
143
|
+
if (silent >= STRIP_MS && this.state === 'live') this.because(this.online() ? 'silent' : 'offline');
|
|
124
144
|
if (silent >= DROP_MS) this.lose(now); else if (silent >= STRIP_MS) this.show('reconnecting');
|
|
125
145
|
} else if (this.phase === 'down') this.redial(now);
|
|
126
146
|
}
|
|
127
147
|
private redial(now: number): void {
|
|
128
148
|
if (this.waitingForSeat) { if (this.dialled === null && now >= this.dialAt) this.dial(now); else if (this.dialled !== null && now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
149
|
+
if (this.offline(now)) { if (this.dialled !== null && now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
129
150
|
const out = now - this.lostAt;
|
|
130
151
|
if (out >= GIVE_UP_MS) { this.stop(); this.show('lost'); return; }
|
|
131
152
|
if (out >= RESUMING_MS) this.show('resuming');
|
|
132
153
|
if (this.dialled !== null) { if (now - this.dialled >= DROP_MS) { this.failedDial(now); this.drop(); } return; }
|
|
133
154
|
if (now >= this.dialAt) this.dial(now);
|
|
134
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* FM4b mode 2: a device with no network is not dialled (each dial would only fail) and its give-up clock stands still, so a
|
|
158
|
+
* phone in a tunnel never reaches `lost` while it waits; the world's own hold on the seat (J114) is the server's and goes on.
|
|
159
|
+
* The network back: the clock goes on from where it stopped and the dial goes out at once. True while offline.
|
|
160
|
+
*/
|
|
161
|
+
private offline(now: number): boolean {
|
|
162
|
+
if (!this.online()) {
|
|
163
|
+
this.offlineAt ??= now;
|
|
164
|
+
this.because('offline');
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
if (this.offlineAt === null) return false;
|
|
168
|
+
this.lostAt += now - this.offlineAt; this.offlineAt = null; this.dialAt = now;
|
|
169
|
+
this.because('closed');
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
135
172
|
private dial(now: number): void {
|
|
136
173
|
const transport = this.options.dial();
|
|
137
174
|
this.offClose(); this.transport = transport; this.dialled = now; this.dials++;
|
|
@@ -154,9 +191,30 @@ export class Redial {
|
|
|
154
191
|
if (reason === 'retry' || cut) this.because('updating');
|
|
155
192
|
if (cut) this.options.onCut?.(reason);
|
|
156
193
|
if (reason === 'full') { this.phase = 'down'; this.waitingForSeat = true; this.dialled = null; this.dialAt = now + FULL_RETRY_MS; this.show('full'); return; }
|
|
157
|
-
if (this.phase === 'up') { if (this.cause !== 'updating') this.because(reason === 'restart' ? 'restart' : 'closed'); this.lose(now, false); }
|
|
194
|
+
if (this.phase === 'up') { if (this.cause !== 'updating') this.because(reason === 'restart' ? 'restart' : this.online() ? 'closed' : 'offline'); this.lose(now, false); }
|
|
158
195
|
else if (this.phase === 'down') { if (reason === 'restart') this.because('restart'); this.failedDial(now); }
|
|
159
196
|
}
|
|
197
|
+
/**
|
|
198
|
+
* FM4b modes 4 and 45: the page was away (out of view for `hiddenMs`, or no clock tick for 30 s) and comes back to a link that is
|
|
199
|
+
* quiet or down. The time away is not dialling time: a link lost while away counts its give-up clock from the return, and one
|
|
200
|
+
* already down moves its clock on by the gap no dial could go out in, so a phone back after 4 minutes dials for 2 minutes more
|
|
201
|
+
* and never opens on Couldn't reconnect. A healthy return (frames heard within the last second) changes nothing.
|
|
202
|
+
*/
|
|
203
|
+
private woke(now: number, hiddenMs: number): void {
|
|
204
|
+
const gap = now - this.tickAt;
|
|
205
|
+
this.tickAt = now;
|
|
206
|
+
if (gap < AWAY_MS && hiddenMs < AWAY_MS) return;
|
|
207
|
+
const how = hiddenMs >= AWAY_MS || this.awayFor?.how === 'hidden' ? 'hidden' : 'asleep', ms = Math.max(gap, hiddenMs, this.awayFor?.ms ?? 0);
|
|
208
|
+
if (this.phase === 'up') {
|
|
209
|
+
if (this.heardAt === null || now - this.heardAt < STRIP_MS) return;
|
|
210
|
+
this.awayFor = { ms, how }; this.because('hidden'); this.heardAt = now; this.lose(now);
|
|
211
|
+
} else if (this.phase === 'down' && !this.waitingForSeat) {
|
|
212
|
+
// the suspended gap moves the give-up clock on; hidden time with ticks running was dialled through, so it counts
|
|
213
|
+
if (gap >= AWAY_MS) { this.lostAt += gap; if (this.offlineAt !== null) this.offlineAt += gap; }
|
|
214
|
+
this.awayFor = { ms, how }; this.dialAt = now;
|
|
215
|
+
if (this.cause === 'silent' || this.cause === 'closed') this.because('hidden');
|
|
216
|
+
}
|
|
217
|
+
}
|
|
160
218
|
/** The link is gone or no use: from now it is dialled, and a player's 35 s count from the last frame. */
|
|
161
219
|
private lose(now: number, close = true): void {
|
|
162
220
|
this.phase = 'down'; this.lostAt = this.heardAt ?? now; this.dialled = null; this.dialAt = now + (DIAL_WAITS_MS[0] ?? 0) * (1 + (this.random() * 2 - 1) * DIAL_JITTER);
|
|
@@ -1,2 +1,59 @@
|
|
|
1
|
-
/** MF1/MF4: immutable code, content and versioned metadata, keyed by exact absolute URL.
|
|
1
|
+
/** MF1/MF4: immutable code, content and versioned metadata, keyed by exact absolute URL. Production's name; the other
|
|
2
|
+
* channels' names carry the channel (`cacheName`). */
|
|
2
3
|
export const ASSET_CACHE_NAME = 'ws-assets-v1';
|
|
4
|
+
|
|
5
|
+
/** OFFLINE OF12 (J298, Jake 2026-11-12: "The preview build should have a different cache"): every Cache Storage name a
|
|
6
|
+
* build writes carries its channel, so preview and staging on one origin (a local proof, any later shared host) keep
|
|
7
|
+
* disjoint caches and neither's activate deletes the other's. One bundle serves every channel and the deploy stamps
|
|
8
|
+
* `__WS_WORLD__` into the document, so the channel is read at run time, as `homeIconChannel` (app-build/homeIcons.mjs)
|
|
9
|
+
* reads it: no world is preview, a world whose release file is production's is production, any other world is staging.
|
|
10
|
+
* Production keeps the names it always had (renaming them would cold-start every player's cache); preview and staging
|
|
11
|
+
* put the channel after `ws-` (`ws-preview-assets-v1`, `ws-staging-shell-v3-<build>`), so production's prefix tests
|
|
12
|
+
* (`ws-shell-`) never match another channel's caches. */
|
|
13
|
+
export type CacheChannel = 'production' | 'staging' | 'preview';
|
|
14
|
+
export const CACHE_CHANNELS: readonly CacheChannel[] = ['production', 'staging', 'preview'];
|
|
15
|
+
|
|
16
|
+
/** The channel of a build stamp (`__WS_WORLD__`, or undefined on a build with no world). */
|
|
17
|
+
export function cacheChannel(world: unknown): CacheChannel {
|
|
18
|
+
if (typeof world !== 'object' || world === null) return 'preview';
|
|
19
|
+
const release: unknown = Reflect.get(world, 'release');
|
|
20
|
+
return typeof release === 'string' && /\/releases\/production\.json(?:[?#]|$)/u.test(release) ? 'production' : 'staging';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One cache name for a channel: production's as given; another channel's with the channel after `ws-`. */
|
|
24
|
+
export function cacheName(base: string, channel: CacheChannel): string {
|
|
25
|
+
if (channel === 'production') return base;
|
|
26
|
+
return base.startsWith('ws-') ? `ws-${channel}-${base.slice(3)}` : `${base}-${channel}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Whether a Cache Storage name is this channel's own (production's are the `ws-` names no other channel prefixes). */
|
|
30
|
+
export function ownsCache(name: string, channel: CacheChannel): boolean {
|
|
31
|
+
if (channel !== 'production') return name.startsWith(`ws-${channel}-`);
|
|
32
|
+
return name.startsWith('ws-') && !CACHE_CHANNELS.some(other => other !== 'production' && name.startsWith(`ws-${other}-`));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A dedicated worker has no document stamp: the page that starts it hands it the channel (`setCacheChannel`). */
|
|
36
|
+
let given: CacheChannel | undefined;
|
|
37
|
+
export function setCacheChannel(channel: unknown): void {
|
|
38
|
+
if (typeof channel === 'string' && (CACHE_CHANNELS as readonly string[]).includes(channel)) given = channel as CacheChannel;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** This page's (or this worker's, once told) channel. */
|
|
42
|
+
export function pageCacheChannel(): CacheChannel {
|
|
43
|
+
return given ?? cacheChannel((globalThis as { __WS_WORLD__?: unknown }).__WS_WORLD__);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The cross-build asset cache of this page's channel. */
|
|
47
|
+
export function assetCacheName(): string { return cacheName(ASSET_CACHE_NAME, pageCacheChannel()); }
|
|
48
|
+
|
|
49
|
+
/** A production worker opens this empty cache, so another channel's worker on the same origin can tell production's
|
|
50
|
+
* caches (kept) from its own channel's from before OF12, which used production's names (deleted once, see `isForeign`). */
|
|
51
|
+
export const PRODUCTION_MARK = 'ws-production-mark';
|
|
52
|
+
|
|
53
|
+
/** Whether a cache belongs to another channel that is on this origin, which this channel must never delete. Production's
|
|
54
|
+
* names are another channel's only where a production worker has run (`productionHere`, its mark); elsewhere they are
|
|
55
|
+
* this origin's own caches from before the channel names, a one-time cold start's leftovers. */
|
|
56
|
+
export function isForeign(name: string, channel: CacheChannel, productionHere: boolean): boolean {
|
|
57
|
+
if (ownsCache(name, channel) || !name.startsWith('ws-')) return false;
|
|
58
|
+
return channel === 'production' || !ownsCache(name, 'production') || productionHere;
|
|
59
|
+
}
|
|
@@ -1,16 +1,38 @@
|
|
|
1
1
|
import { workerScope } from '../app/workerScope.js';
|
|
2
2
|
import { diagnosticNow } from '../../../shared/engine/core/clock';
|
|
3
|
+
import { cacheChannel, cacheName, ownsCache, PRODUCTION_MARK } from './cacheNames';
|
|
3
4
|
/* MF1: one URL cache, one build shell, and one previous generation of code.
|
|
4
5
|
* No fetched-body reconstruction, checksums, receipts, packs, retries or work timers. */
|
|
5
6
|
const BUILD = '__BUILD_ID__';
|
|
6
7
|
const DOCUMENT = '__DOCUMENT__';
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
8
|
+
// PZ12 (J274): the page origin's COOP and COEP for the baked document (empty on a channel that is not isolated)
|
|
9
|
+
const DOCUMENT_HEADERS = (baked => baked.startsWith('{') ? JSON.parse(baked) : {})('__DOCUMENT_HEADERS__');
|
|
10
|
+
const ISOLATED = Object.keys(DOCUMENT_HEADERS).length > 0;
|
|
11
|
+
/** PZ12: a dedicated worker in an isolated page starts only if its own script carries COEP. A worker chunk whose name did
|
|
12
|
+
* not change across the switch is held here (or in the HTTP cache) with the headers it was first fetched with, so on an
|
|
13
|
+
* isolated channel every worker script this worker answers wears the document's headers. */
|
|
14
|
+
async function isolatedWorkerScript(pending) {
|
|
15
|
+
const response = await pending;
|
|
16
|
+
if (response.type === 'opaque' || response.type === 'opaqueredirect') return response;
|
|
17
|
+
const headers = new Headers(response.headers);
|
|
18
|
+
for (const [name, value] of Object.entries(DOCUMENT_HEADERS)) headers.set(name, value);
|
|
19
|
+
return new Response(response.body, { status: response.status, statusText: response.statusText, headers });
|
|
20
|
+
}
|
|
21
|
+
const answer = (event, request, pending) => { event.respondWith(ISOLATED && request.destination === 'worker' ? isolatedWorkerScript(pending) : pending); };
|
|
11
22
|
/** OFFLINE OF5 (J298): a world build (its document stamped with `__WS_WORLD__`; play, staging) never runs the in-page solo
|
|
12
23
|
* server, so it never precaches the solo server's code or its server book. Read at run time: a deploy stamps the document. */
|
|
13
24
|
const WORLD = /\bglobalThis\.__WS_WORLD__=/u.test(DOCUMENT);
|
|
25
|
+
/** OFFLINE OF12: every cache this worker opens carries its channel (cacheNames.ts), read from the same stamp, so preview and
|
|
26
|
+
* staging on one origin keep disjoint caches. Production's names are the ones it always had. */
|
|
27
|
+
const CHANNEL = cacheChannel((() => {
|
|
28
|
+
const stamp = /\bglobalThis\.__WS_WORLD__=(\{[^;]+\});/u.exec(DOCUMENT)?.[1];
|
|
29
|
+
try { return stamp === undefined ? undefined : JSON.parse(stamp); } catch { return {}; }
|
|
30
|
+
})());
|
|
31
|
+
const ASSETS = cacheName('__ASSET_CACHE__', CHANNEL);
|
|
32
|
+
const BOOKS = cacheName('ws-builds-v1', CHANNEL);
|
|
33
|
+
const SHELL_FAMILY = cacheName('ws-shell-', CHANNEL);
|
|
34
|
+
const SHELL_PREFIX = cacheName('ws-shell-v3-', CHANNEL);
|
|
35
|
+
const SHELL = `${SHELL_PREFIX}${BUILD}`;
|
|
14
36
|
const SOLO_ONLY = /\/standalone\/(?:serverWorker|serverRuntime)-[^/]+\.js$|\/assets\/spawn\/server-[^/]+\.json$/u;
|
|
15
37
|
const FILES = JSON.parse('__FILES__');
|
|
16
38
|
/** What this build precaches and records as its generation: its files, less the solo server's on a world build. */
|
|
@@ -37,7 +59,7 @@ const isHtml = response => /\btext\/html\b/i.test(response.headers.get('content-
|
|
|
37
59
|
const { base: CONTENT_BASE, files: CONTENT_FILES } = JSON.parse('__CONTENT__');
|
|
38
60
|
/** OF5: the server book on the content base is solo-only too (a URL there, its path under the base's folder). */
|
|
39
61
|
const CONTENT_PRECACHE = CONTENT_FILES.filter(href => !WORLD || !SOLO_ONLY.test(new URL(href).pathname));
|
|
40
|
-
const CONTENT_CACHE = 'ws-content-v1';
|
|
62
|
+
const CONTENT_CACHE = cacheName('ws-content-v1', CHANNEL);
|
|
41
63
|
const CONTENT_URL = CONTENT_BASE === '' ? undefined : new URL(CONTENT_BASE);
|
|
42
64
|
/** A base on the page's own origin (contentBase.ts allows one) owns its folder only; the rest of the origin is the page's. */
|
|
43
65
|
const SAME_ORIGIN_BASE = CONTENT_URL?.origin === self.location.origin;
|
|
@@ -114,6 +136,8 @@ workerScope.listen(self, 'install', event => {
|
|
|
114
136
|
]) : undefined;
|
|
115
137
|
event.waitUntil((async () => {
|
|
116
138
|
await routes;
|
|
139
|
+
// OF12: production marks the origin, so another channel's worker here keeps production's caches
|
|
140
|
+
if (CHANNEL === 'production') await caches.open(PRODUCTION_MARK);
|
|
117
141
|
const [assets, shell, books] = await Promise.all([store(ASSETS), store(SHELL), caches.open(BOOKS)]);
|
|
118
142
|
await importPrevious(assets, books);
|
|
119
143
|
const namedShell = SHELL_FILES.filter(path => immutable(new URL(abs(path))));
|
|
@@ -269,9 +293,15 @@ workerScope.listen(self, 'activate', event => {
|
|
|
269
293
|
await books.delete(key);
|
|
270
294
|
}
|
|
271
295
|
await carryNetworkFirst().catch(() => undefined);
|
|
296
|
+
// OF12: only this channel's older shells (and production's legacy caches) go. Another channel's worker on this origin
|
|
297
|
+
// also drops every cache under production's names (its own from before OF12, and the legacy ws-content-v0) on each
|
|
298
|
+
// activate, unless production runs here too; nothing on this channel writes them again, so in effect it happens once.
|
|
299
|
+
const productionHere = CHANNEL !== 'production' && await caches.has(PRODUCTION_MARK);
|
|
272
300
|
for (const name of await caches.keys()) {
|
|
273
|
-
if (name === SHELL) continue;
|
|
274
|
-
|
|
301
|
+
if (name === SHELL || name === PRODUCTION_MARK) continue;
|
|
302
|
+
const legacy = CHANNEL === 'production' && (name.startsWith('ws-static-') || name === 'ws-immutable');
|
|
303
|
+
if (name.startsWith(SHELL_FAMILY) || legacy) await caches.delete(name);
|
|
304
|
+
else if (CHANNEL !== 'production' && !productionHere && ownsCache(name, 'production')) await caches.delete(name);
|
|
275
305
|
}
|
|
276
306
|
})());
|
|
277
307
|
});
|
|
@@ -399,7 +429,7 @@ workerScope.listen(self, 'fetch', event => {
|
|
|
399
429
|
if (url.pathname === '/version.json' || url.pathname === '/sw.js' || url.pathname.startsWith('/api/')) return;
|
|
400
430
|
if (request.mode === 'navigate' || url.pathname === '/' || url.pathname === '/index.html') {
|
|
401
431
|
const received=diagnosticNow();
|
|
402
|
-
event.respondWith(new Response(DOCUMENT, { headers: { 'content-type': 'text/html;charset=utf-8', 'cache-control': 'no-store' } }));
|
|
432
|
+
event.respondWith(new Response(DOCUMENT, { headers: { ...DOCUMENT_HEADERS, 'content-type': 'text/html;charset=utf-8', 'cache-control': 'no-store' } }));
|
|
403
433
|
bootPublish(event,[{operation:'sw:navigation-handler-and-delivery',url:request.url,start:received,end:diagnosticNow(),result:'complete'}]);
|
|
404
434
|
return;
|
|
405
435
|
}
|
|
@@ -408,12 +438,12 @@ workerScope.listen(self, 'fetch', event => {
|
|
|
408
438
|
return;
|
|
409
439
|
}
|
|
410
440
|
if (immutable(url)) {
|
|
411
|
-
event
|
|
441
|
+
answer(event, request, cached(request, ASSETS, event));
|
|
412
442
|
return;
|
|
413
443
|
}
|
|
414
444
|
if (/^\/(?:assets|basis|fonts)\//.test(url.pathname) || url.pathname === '/manifest.webmanifest') {
|
|
415
|
-
event
|
|
416
|
-
} else if (NETWORK_FIRST.test(url.pathname)) event
|
|
445
|
+
answer(event, request, cached(request, SHELL, event));
|
|
446
|
+
} else if (NETWORK_FIRST.test(url.pathname)) answer(event, request, networkFirst(request, SHELL, event));
|
|
417
447
|
});
|
|
418
448
|
|
|
419
449
|
workerScope.listen(self, 'message', event => {
|