@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
|
@@ -25,6 +25,21 @@ import {SPAWN_PART_ALIGN, spawnCodeListPath, splitSpawnManifest, type SpawnCodeA
|
|
|
25
25
|
type SpawnPart} from '../../shared/game/shardfile/spawnManifest';
|
|
26
26
|
|
|
27
27
|
export const PART_BYTES = 12_000_000, PART_TARGET = 10, OVER_FETCH = 0.1;
|
|
28
|
+
/** A part's size rule: at most `max` raw unless one file alone is bigger, which then stands alone (never past
|
|
29
|
+
* PART_BYTES), and about `target` on average (DL18's key boundaries). */
|
|
30
|
+
export interface PartLimits {readonly max: number; readonly target: number}
|
|
31
|
+
/** A part's average decoded size: a key boundary falls after a member with probability size / PART_TARGET_BYTES (DL18). */
|
|
32
|
+
export const PART_TARGET_BYTES = 9_000_000;
|
|
33
|
+
/** Files no public (phone) entry reads keep the 12 MB rule: a desktop's whole level (Pine 333 MB) in 4 MiB parts would
|
|
34
|
+
* pass the manifest's 128 parts. */
|
|
35
|
+
export const WHOLE_PART_LIMITS: PartLimits = {max: PART_BYTES, target: PART_TARGET_BYTES};
|
|
36
|
+
/** S12e: what a phone entry reads goes in parts of at most 4 MiB, about 3 MiB on average, the boot pack's own cap
|
|
37
|
+
* (`boot-pack-parts.mjs` PART_MAX). Measured on Pine rev2 with the phone tier on: a one-texture edit re-downloads
|
|
38
|
+
* 3.28 MB of phone parts on average (9.19 MB at 12 MB, 3.77 at 5 MB), for 45 phone parts instead of 17 and the same
|
|
39
|
+
* wire bytes (69.24 MB against 69.20). */
|
|
40
|
+
export const PART_LIMITS: PartLimits = {max: 4 << 20, target: 3 << 20};
|
|
41
|
+
/** Under `readSpawnManifest`'s 128 parts, with room for the key boundaries' spread around their average. */
|
|
42
|
+
const MANIFEST_PARTS = 96;
|
|
28
43
|
export interface SpawnPartInput {readonly rows: readonly SpawnFile[]; readonly public: boolean; readonly desktop?: boolean}
|
|
29
44
|
/** `desktop`: a desktop list holds these files too. S3: it never shares a part with a phone's own, or it fetches them all. */
|
|
30
45
|
interface Group {readonly key: string; readonly members: ReadonlySet<number>; readonly desktop: boolean; readonly urls: string[]; bytes: number}
|
|
@@ -91,8 +106,6 @@ export function spawnPartGroups(manifests: readonly SpawnPartInput[]): Group[] {
|
|
|
91
106
|
return [...groups.values()];
|
|
92
107
|
}
|
|
93
108
|
|
|
94
|
-
/** A part's average decoded size: a key boundary falls after a member with probability size / PART_TARGET_BYTES (DL18). */
|
|
95
|
-
export const PART_TARGET_BYTES = 9_000_000;
|
|
96
109
|
/** DL18 (sp-x2's real pair 5adf2b0 -> fe210797ab: one Nine edit rewrote 41 bodies, and hashed placement scattered them
|
|
97
110
|
* over 20 of 25 parts). Members are ordered by their readable stable key, so the files one generator writes (keys under
|
|
98
111
|
* one section path or name prefix) sit together, and a part ends where the keys say: after a member whose key hash falls
|
|
@@ -101,7 +114,7 @@ export const PART_TARGET_BYTES = 9_000_000;
|
|
|
101
114
|
* cut moves) instead of a scatter. Sections and schemas (`section|` keys) and build assets (`volatile|`) each form their
|
|
102
115
|
* own run, so a rebuild's restamped files never share a part with content, and setup's first reads never sit behind
|
|
103
116
|
* the build assets. */
|
|
104
|
-
export function placeByKey(urls: readonly string[], size: (url: string) => number, key: (url: string) => string): string[][] {
|
|
117
|
+
export function placeByKey(urls: readonly string[], size: (url: string) => number, key: (url: string) => string, limits: PartLimits = WHOLE_PART_LIMITS): string[][] {
|
|
105
118
|
const order = (a: string, b: string): number => (a < b ? -1 : a > b ? 1 : 0);
|
|
106
119
|
const sorted = [...urls].sort((a, b) => order(key(a), key(b)) || order(a, b));
|
|
107
120
|
const parts: string[][] = []; let current: string[] = [], bytes = 0, run = '';
|
|
@@ -109,9 +122,9 @@ export function placeByKey(urls: readonly string[], size: (url: string) => numbe
|
|
|
109
122
|
for (const url of sorted) {
|
|
110
123
|
const name = key(url), kind = name.slice(0, name.indexOf('|') + 1);
|
|
111
124
|
if (kind !== run) { cut(); run = kind; }
|
|
112
|
-
if (current.length > 0 && align(bytes) + size(url) >
|
|
125
|
+
if (current.length > 0 && align(bytes) + size(url) > limits.max) cut();
|
|
113
126
|
current.push(url); bytes = align(bytes) + size(url);
|
|
114
|
-
if (Number.parseInt(createHash('sha256').update(name).digest('hex').slice(0, 8), 16) / 2 ** 32 < size(url) /
|
|
127
|
+
if (bytes >= limits.max || Number.parseInt(createHash('sha256').update(name).digest('hex').slice(0, 8), 16) / 2 ** 32 < size(url) / limits.target) cut();
|
|
115
128
|
}
|
|
116
129
|
cut();
|
|
117
130
|
return parts;
|
|
@@ -136,7 +149,7 @@ export interface CookedMember {readonly url: string; readonly bytes: number; rea
|
|
|
136
149
|
* stay what they were; a cooked file only stops being written twice. */
|
|
137
150
|
export async function writeSpawnParts(outDir: string, manifests: readonly SpawnPartInput[], read: (url: string) => Uint8Array,
|
|
138
151
|
stableKey: (url: string) => string | undefined = () => undefined, encoder: PartEncoder = createPartEncoder(),
|
|
139
|
-
cooked: ReadonlyMap<string, CookedMember> = new Map()): Promise<SpawnPart[][]> {
|
|
152
|
+
cooked: ReadonlyMap<string, CookedMember> = new Map(), limits: PartLimits = PART_LIMITS): Promise<SpawnPart[][]> {
|
|
140
153
|
const placed = new Map<string, {url: string; bytes: number; hash: string; offset: number}>(cooked), wire = new Map<string, number>();
|
|
141
154
|
for (const member of cooked.values()) wire.set(member.url, member.wireBytes);
|
|
142
155
|
mkdirSync(join(outDir, 'assets/spawn/parts'), {recursive: true});
|
|
@@ -149,6 +162,8 @@ export async function writeSpawnParts(outDir: string, manifests: readonly SpawnP
|
|
|
149
162
|
return key;
|
|
150
163
|
};
|
|
151
164
|
const inflight = new Set<Promise<void>>(), bodies = new Map<string, readonly string[]>();
|
|
165
|
+
// A shard cook's part is a body too: the same bytes under another URL of one manifest must not take its name.
|
|
166
|
+
for (const [member, at] of cooked) bodies.set(at.hash, [...bodies.get(at.hash) ?? [], member]);
|
|
152
167
|
const write = async (batch: readonly string[]): Promise<void> => {
|
|
153
168
|
const length = batch.reduce((at, url) => align(at) + (sizes.get(url) ?? 0), 0);
|
|
154
169
|
let body = new Uint8Array(length); const offsets = new Map<string, number>(); let cursor = 0;
|
|
@@ -175,12 +190,22 @@ export async function writeSpawnParts(outDir: string, manifests: readonly SpawnP
|
|
|
175
190
|
inflight.add(job); void job.finally(() => { inflight.delete(job); }).catch(() => undefined);
|
|
176
191
|
};
|
|
177
192
|
try {
|
|
178
|
-
|
|
193
|
+
const groups = spawnPartGroups(manifests);
|
|
194
|
+
// A manifest names at most 128 parts. Estimate each one's count under the phone rule (its share of every group it
|
|
195
|
+
// touches); a shard whose desktop shares most of its files with its phone (no tier table) keeps the 12 MB rule.
|
|
196
|
+
const groupOf = new Map(groups.flatMap(group => group.urls.map(url => [url, group] as const)));
|
|
197
|
+
const estimate = (input: SpawnPartInput): number => {
|
|
198
|
+
const touched = new Set(input.rows.flatMap(row => { const group = groupOf.get(row.url); return group === undefined ? [] : [group]; }));
|
|
199
|
+
return [...touched].reduce((sum, group) => sum + Math.ceil(group.bytes / (group.key.startsWith('P:') ? limits.target : WHOLE_PART_LIMITS.target)), 0);
|
|
200
|
+
};
|
|
201
|
+
const phoneRule = manifests.every(input => estimate(input) <= MANIFEST_PARTS) ? limits : WHOLE_PART_LIMITS;
|
|
202
|
+
for (const group of groups) {
|
|
179
203
|
for (const url of group.urls) {
|
|
180
204
|
const bytes = sizes.get(url) ?? 0;
|
|
181
205
|
if (bytes > PART_BYTES) throw new Error(`Spawn file larger than a part (${bytes} > ${PART_BYTES}): ${url}`);
|
|
182
206
|
}
|
|
183
|
-
|
|
207
|
+
const rule = group.key.startsWith('P:') ? phoneRule : WHOLE_PART_LIMITS;
|
|
208
|
+
for (const batch of placeByKey(group.urls.filter(url => !cooked.has(url)), url => sizes.get(url) ?? 0, keyOf, rule)) await write(batch);
|
|
184
209
|
}
|
|
185
210
|
await Promise.all(inflight);
|
|
186
211
|
} finally { await encoder.close(); }
|
|
@@ -95,7 +95,8 @@ export function trimKtx2(bytes: Uint8Array, maxSize: number): Uint8Array {
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
interface GltfView {buffer: number; byteOffset?: number; byteLength: number; extensions?: {EXT_meshopt_compression?: {buffer: number; byteOffset?: number; byteLength: number}}}
|
|
98
|
-
interface
|
|
98
|
+
interface GltfTexture {source?: number; extensions?: {KHR_texture_basisu?: {source?: number}}}
|
|
99
|
+
interface Gltf {materials?: {normalTexture?: {index: number}}[]; textures?: GltfTexture[]; accessors?: {bufferView?: number; sparse?: {indices: {bufferView: number}; values: {bufferView: number}}}[]; bufferViews?: GltfView[]; buffers?: {byteLength: number; uri?: string}[]; images?: {bufferView?: number; mimeType?: string; uri?: string}[]}
|
|
99
100
|
interface Glb {readonly json: Gltf; readonly bin: Uint8Array}
|
|
100
101
|
|
|
101
102
|
function readGlb(bytes: Uint8Array): Glb | undefined {
|
|
@@ -195,9 +196,46 @@ export function withImages(bytes: Uint8Array, replace: (image: GlbImage) => Uint
|
|
|
195
196
|
return writeGlb(glb.json, bin);
|
|
196
197
|
}
|
|
197
198
|
|
|
198
|
-
/**
|
|
199
|
-
export
|
|
200
|
-
|
|
199
|
+
/** S12c: how a texture's texels read, so a re-encode keeps them: colour (sRGB), linear data, or a normal map. */
|
|
200
|
+
export type TextureRole = 'srgb' | 'linear' | 'normal';
|
|
201
|
+
/** S12c: a UASTC KTX2, already at its tier size, as ASTC 6×6 with the same levels; undefined when it can't. Injected, so
|
|
202
|
+
* this module stays bytes in, bytes out: the cook's is `basisuAstc6` (`astc6Encode.ts`), cached by input hash. */
|
|
203
|
+
export type Astc6Encode = (ktx2: Uint8Array, role: TextureRole) => Uint8Array | undefined;
|
|
204
|
+
|
|
205
|
+
/** The KTX2's DFD transfer function: 2 is sRGB, 1 linear. */
|
|
206
|
+
function transferOf(bytes: Uint8Array): number {
|
|
207
|
+
const view = viewOf(bytes), dfdAt = view.getUint32(48, true), dfdLength = view.getUint32(52, true);
|
|
208
|
+
return dfdLength >= 16 && dfdAt + 15 <= bytes.length ? (bytes[dfdAt + 14] ?? 0) : 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** A KTX2 at one tier: trimmed to `maxSize`, then, with `encode`, a UASTC one re-encoded as ASTC 6×6 (S4's phone format,
|
|
212
|
+
* 16/36 of 4×4's GPU bytes). Raw ASTC is only trimmed; BasisLZ (ETC1S) keeps its bytes, as S4's data planes did. */
|
|
213
|
+
export function tierKtx2(bytes: Uint8Array, maxSize: number, encode?: Astc6Encode, normal = false): Uint8Array {
|
|
214
|
+
const trimmed = trimKtx2(bytes, maxSize);
|
|
215
|
+
if (encode === undefined || !isKtx2(trimmed)) return trimmed;
|
|
216
|
+
const info = ktx2Info(trimmed);
|
|
217
|
+
// Only a plain 2D texture the trim brought to its tier size: a one-level master stays as large as it was, and an array or cube
|
|
218
|
+
// map would lose its layers in a 2D encode.
|
|
219
|
+
const view = viewOf(trimmed), plain = view.getUint32(28, true) <= 1 && view.getUint32(32, true) <= 1 && view.getUint32(36, true) === 1;
|
|
220
|
+
if (info.vkFormat !== 0 || info.scheme === BASIS_LZ || !plain || Math.max(info.width, info.height) > maxSize) return trimmed;
|
|
221
|
+
return encode(trimmed, normal ? 'normal' : transferOf(trimmed) === 2 ? 'srgb' : 'linear') ?? trimmed;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/** The images a GLB's materials sample as normal maps. */
|
|
225
|
+
function normalImages(json: Gltf): ReadonlySet<number> {
|
|
226
|
+
const out = new Set<number>();
|
|
227
|
+
for (const material of json.materials ?? []) {
|
|
228
|
+
const texture = material.normalTexture === undefined ? undefined : json.textures?.[material.normalTexture.index];
|
|
229
|
+
const source = texture?.source ?? texture?.extensions?.KHR_texture_basisu?.source;
|
|
230
|
+
if (source !== undefined) out.add(source);
|
|
231
|
+
}
|
|
232
|
+
return out;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** A GLB at one tier: each embedded KTX2 image at most `maxSize` on its largest side, and 6×6 with `encode` (`tierKtx2`). */
|
|
236
|
+
export function tierGlb(bytes: Uint8Array, maxSize: number, encode?: Astc6Encode): Uint8Array {
|
|
237
|
+
const normals = encode === undefined ? new Set<number>() : normalImages(readGlb(bytes)?.json ?? {});
|
|
238
|
+
return withImages(bytes, image => (image.mimeType === 'image/ktx2' ? tierKtx2(image.bytes, maxSize, encode, normals.has(image.index)) : image.bytes));
|
|
201
239
|
}
|
|
202
240
|
|
|
203
241
|
/** GPU memory a KTX2 takes once transcoded, mips included: ASTC 4×4 or BC7 for UASTC (1 byte a texel), its own block
|
|
@@ -217,6 +255,9 @@ export function ktx2GpuBytes(bytes: Uint8Array): number {
|
|
|
217
255
|
* key is the author's hint (D5): a `#layer` twin (a terrain layer, tiled at a texel a metre) and a horizon strip are S4's
|
|
218
256
|
* 1024 rows, kept on purpose; every other row is 512 on a phone. */
|
|
219
257
|
export const PHONE_TIER_MAX = 512;
|
|
258
|
+
/** S12d: the cap a kept row (a `#layer` twin, a horizon) is encoded under: none it reaches, so it keeps its own size and only
|
|
259
|
+
* its encoding changes to 6×6, as S4's hand-made set had it. */
|
|
260
|
+
export const KEPT_ENCODE_MAX = 16_384;
|
|
220
261
|
export function phoneTierSize(source: string): number | undefined {
|
|
221
262
|
return source.endsWith('#layer') || /\/horizon\//u.test(source) ? undefined : PHONE_TIER_MAX;
|
|
222
263
|
}
|
|
@@ -235,37 +276,69 @@ export interface PhoneTier {
|
|
|
235
276
|
type Json = null | boolean | number | string | readonly Json[] | {readonly [key: string]: Json};
|
|
236
277
|
const isMap = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
237
278
|
const hex8 = (bytes: Uint8Array): string => createHash('sha256').update(bytes).digest('hex').slice(0, 8);
|
|
279
|
+
/** S4's normal-map names (`bake-ktx2.mjs` classOf): a loose KTX2 row the 6×6 encode reads as a normal map. */
|
|
280
|
+
const NORMAL_NAME = /(?:^|[_\-.])(?:nor|nor_gl|normal|nrm)(?:[_\-.]|$)/iu;
|
|
281
|
+
|
|
282
|
+
/** The desktop target that holds a phone row's master: the same source, or its name without the `.phone` / `-phone` mark. */
|
|
283
|
+
export function masterOf(desktop: Readonly<Record<string, unknown>> | undefined, source: string): string | undefined {
|
|
284
|
+
if (desktop === undefined) return undefined;
|
|
285
|
+
for (const key of [source, source.replace(/\.phone\./u, '.'), source.replace(/-phone\./u, '.')]) {
|
|
286
|
+
const target = desktop[key];
|
|
287
|
+
if (typeof target === 'string') return target;
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
238
291
|
|
|
239
292
|
/** The phone tier of a shard's KTX2 table (`discovery.json` `native.ktx2`, any shape: `pageModeKtx2` args, `GPU_FILES`, a bare
|
|
240
293
|
* tier map). Every `phone` map's GLB and KTX2 target that `read` can read is trimmed to its row's size; a target that gets
|
|
241
294
|
* smaller moves to `<name>.t<size>-<hash8>.<ext>` beside it. Undefined when nothing gets smaller, so the cook keeps every
|
|
242
|
-
* byte of today's product.
|
|
243
|
-
|
|
295
|
+
* byte of today's product.
|
|
296
|
+
*
|
|
297
|
+
* S12c: with `encode`, a row is cooked from its desktop master (`masterOf`, the sibling `desktop` map) when it has one,
|
|
298
|
+
* trimmed and re-encoded as ASTC 6×6 (`tierKtx2`, `tierGlb`): what the phone reads once the hand-made 512 sets are gone
|
|
299
|
+
* (S12d). That file stands in for the row's target whatever its size against today's hand-made file. */
|
|
300
|
+
export function phoneTier(discovery: Uint8Array, read: (url: string) => Uint8Array | undefined, size: (source: string) => number | undefined = phoneTierSize, encode?: Astc6Encode): PhoneTier | undefined {
|
|
244
301
|
const document = JSON.parse(new TextDecoder().decode(discovery)) as Json;
|
|
245
302
|
const native = isMap(document) && isMap(document['native']) ? document['native'] : undefined;
|
|
246
303
|
if (native?.['ktx2'] === undefined) return undefined;
|
|
247
|
-
const phoneMaps: Record<string, unknown>[] = [];
|
|
304
|
+
const phoneMaps: {phone: Record<string, unknown>; desktop: Record<string, unknown> | undefined}[] = [];
|
|
305
|
+
const stringMap = (item: unknown): item is Record<string, unknown> => isMap(item) && Object.values(item).every(target => typeof target === 'string');
|
|
248
306
|
const walk = (value: unknown): void => {
|
|
249
307
|
if (Array.isArray(value)) { for (const item of value) walk(item); return; }
|
|
250
308
|
if (!isMap(value)) return;
|
|
251
309
|
for (const [key, item] of Object.entries(value)) {
|
|
252
|
-
if (key === 'phone' &&
|
|
310
|
+
if (key === 'phone' && stringMap(item)) phoneMaps.push({phone: item, desktop: stringMap(value['desktop']) ? value['desktop'] : undefined});
|
|
253
311
|
else walk(item);
|
|
254
312
|
}
|
|
255
313
|
};
|
|
256
314
|
walk(native['ktx2']);
|
|
257
315
|
const made = new Map<string, TierFile | null>(), files = new Map<string, TierFile[]>(), kept = new Set<string>();
|
|
258
|
-
|
|
316
|
+
let encodes = 0;
|
|
317
|
+
const counted: Astc6Encode | undefined = encode === undefined ? undefined : (bytes, role) => { const out = encode(bytes, role); if (out !== undefined) encodes++; return out; };
|
|
318
|
+
// A GLB's master is the same source's desktop file only: a `.phone` GLB holds a lighter mesh, not just smaller images.
|
|
319
|
+
const sameMaster = (desktop: Readonly<Record<string, unknown>> | undefined, source: string): string | undefined => { const target = desktop?.[source]; return typeof target === 'string' ? target : undefined; };
|
|
320
|
+
for (const {phone: map, desktop} of phoneMaps) for (const [source, target] of Object.entries(map)) {
|
|
259
321
|
if (typeof target !== 'string') continue;
|
|
260
|
-
|
|
322
|
+
// S12d: a row kept at its size is still encoded 6×6 from its own file when the cook encodes, which retires the hand sets.
|
|
323
|
+
const sized = size(source), own = sized === undefined && counted !== undefined, max = sized ?? (own ? KEPT_ENCODE_MAX : undefined);
|
|
324
|
+
const match = /^(.*?)(?:-[a-f0-9]{8})?\.(glb|ktx2)$/u.exec(target), held = max === undefined || match === null ? undefined : read(target);
|
|
325
|
+
// S12d: a shard that dropped its hand-made phone set (Sky Reach) names a target its product no longer carries; the row's own
|
|
326
|
+
// source, the file desktops load, is then its master, and the cook makes the phone's file from it (`phoneRowSources`).
|
|
327
|
+
const absent = held === undefined && match !== null && max !== undefined, bytes = held ?? (absent && source.endsWith(`.${match[2] ?? ''}`) ? read(source) : undefined);
|
|
261
328
|
if (max === undefined || match === null || bytes === undefined) { kept.add(target); continue; }
|
|
262
|
-
const
|
|
329
|
+
const ext = match[2] ?? '', master = encode === undefined || own ? undefined : (ext === 'glb' ? sameMaster(desktop, source) : masterOf(desktop, source));
|
|
330
|
+
const masterBytes = master?.endsWith(`.${ext}`) === true ? read(master) : undefined;
|
|
331
|
+
const key = `${target}<${masterBytes === undefined ? target : master ?? target}@${max}`;
|
|
263
332
|
let file = made.get(key);
|
|
264
333
|
if (file === undefined) {
|
|
265
334
|
// A file the trim can't read keeps today's bytes: one odd texture never stops a cook.
|
|
266
|
-
|
|
267
|
-
try {
|
|
268
|
-
|
|
335
|
+
const normal = NORMAL_NAME.test(source.split('/').pop() ?? '');
|
|
336
|
+
const cook = (input: Uint8Array): Uint8Array => { try { return ext === 'glb' ? tierGlb(input, max, counted) : tierKtx2(input, max, counted, normal); } catch { return input; } };
|
|
337
|
+
// A master stands in only when the 6×6 encode ran on it; else the row's own file is cooked, as S12b does.
|
|
338
|
+
const encodedBefore = encodes;
|
|
339
|
+
const cookedMaster = masterBytes === undefined ? undefined : cook(masterBytes);
|
|
340
|
+
const trimmed = cookedMaster !== undefined && encodes > encodedBefore ? cookedMaster : cook(bytes), fromMaster = trimmed === cookedMaster;
|
|
341
|
+
file = fromMaster || absent || trimmed.length < bytes.length ? {from: target, url: `${match[1] ?? ''}.t${max}-${hex8(trimmed)}.${ext}`, bytes: trimmed} : null;
|
|
269
342
|
made.set(key, file);
|
|
270
343
|
if (file !== null) files.set(target, [...files.get(target) ?? [], file]);
|
|
271
344
|
}
|
|
@@ -8,7 +8,15 @@ interface ContendedBoss {
|
|
|
8
8
|
readonly engaged: boolean;
|
|
9
9
|
readonly script: { readonly respawnPoint: () => { pos: Vector3; yaw: number } };
|
|
10
10
|
readonly disarm: () => void; readonly arm: () => void; readonly onPlayerDeath: () => boolean;
|
|
11
|
+
/** SC5: the brain's state, read for a beaten boss's return, and its own way back (else a plain `disarm`). SC10: `defeated`, its record,
|
|
12
|
+
* for a boss whose presence puts it away after a win (a roaming boss leaves `victory` for `dormant` when everyone walks off). */
|
|
13
|
+
readonly state?: string; readonly defeated?: boolean; readonly returnBeaten?: () => void;
|
|
11
14
|
}
|
|
15
|
+
/** SERVER-CELLS SC5 (J328): how a served world brings a beaten boss back, since a grid cell's world is never rebuilt. `rearm`: the
|
|
16
|
+
* boss stood armed from the start, so it stands armed again; a summoned one goes back to waiting for its summons. */
|
|
17
|
+
export interface BeatenReturn { readonly served: () => boolean; readonly rearm: boolean }
|
|
18
|
+
/** SC5: a served world's beaten boss comes back once nobody has stood in its arena this long, as J107's start-over waited. */
|
|
19
|
+
export const BOSS_RETURN_S = 300;
|
|
12
20
|
type ArenaPlayer = (point: Vector3) => boolean;
|
|
13
21
|
/** Marks a blow's share on a further player, which lands no further shares. */
|
|
14
22
|
const ECHO = 'boss.echo';
|
|
@@ -27,10 +35,13 @@ export class BossContenders {
|
|
|
27
35
|
private readonly players: ReadonlyMap<string, PlayerSim>;
|
|
28
36
|
private readonly inArena: ArenaPlayer;
|
|
29
37
|
private readonly place: (player: PlayerSim, position: Vector3, yaw: number) => void;
|
|
38
|
+
private readonly beaten: BeatenReturn | undefined;
|
|
39
|
+
/** SC5: seconds a beaten boss's arena has stood empty. */
|
|
40
|
+
private emptyFor = 0;
|
|
30
41
|
/** The point `BossBrain` watches, live. */
|
|
31
42
|
readonly player: { readonly position: Vector3 };
|
|
32
|
-
constructor(players: ReadonlyMap<string, PlayerSim>, inArena: ArenaPlayer, place: (player: PlayerSim, position: Vector3, yaw: number) => void) {
|
|
33
|
-
this.players = players; this.inArena = inArena; this.place = place;
|
|
43
|
+
constructor(players: ReadonlyMap<string, PlayerSim>, inArena: ArenaPlayer, place: (player: PlayerSim, position: Vector3, yaw: number) => void, beaten?: BeatenReturn) {
|
|
44
|
+
this.players = players; this.inArena = inArena; this.place = place; this.beaten = beaten;
|
|
34
45
|
const contender = (): PlayerSim => this.contender();
|
|
35
46
|
this.player = { get position() { return contender().position; } };
|
|
36
47
|
}
|
|
@@ -74,13 +85,26 @@ export class BossContenders {
|
|
|
74
85
|
/** The death checkpoint's answer. A room's only says the fight owns the death (`fell` returns them); a lone player's is the brain's. */
|
|
75
86
|
died(boss: ContendedBoss): boolean { return this.players.size > 1 ? boss.engaged : boss.onPlayerDeath(); }
|
|
76
87
|
/** Each fixed step, before the brain's: count who began the fight, and reset it once nobody is left inside. */
|
|
77
|
-
observe(boss: ContendedBoss): void {
|
|
88
|
+
observe(boss: ContendedBoss, dt: number = 1 / 60): void {
|
|
89
|
+
if (this.beaten !== undefined && (boss.state === 'victory' || (boss.defeated === true && !boss.engaged)) && this.beaten.served()) { this.unbeaten(boss, this.beaten, dt); return; }
|
|
90
|
+
this.emptyFor = 0;
|
|
78
91
|
if (this.players.size <= 1 && this.counted === 0) return;
|
|
79
92
|
if (!boss.engaged) { this.counted = 0; return; }
|
|
80
93
|
const inside = this.inside().length;
|
|
81
94
|
if (this.counted === 0) this.counted = Math.max(1, inside);
|
|
82
95
|
if (inside === 0) { this.counted = 0; boss.disarm(); boss.arm(); }
|
|
83
96
|
}
|
|
97
|
+
/** SC5: a served world's beaten boss, back once its arena has stood empty `BOSS_RETURN_S`; anyone inside starts the wait over. */
|
|
98
|
+
private unbeaten(boss: ContendedBoss, beaten: BeatenReturn, dt: number): void {
|
|
99
|
+
if (this.inside().length > 0) { this.emptyFor = 0; return; }
|
|
100
|
+
this.emptyFor += dt;
|
|
101
|
+
if (this.emptyFor < BOSS_RETURN_S) return;
|
|
102
|
+
this.emptyFor = 0; this.counted = 0;
|
|
103
|
+
if (boss.returnBeaten === undefined) boss.disarm(); else boss.returnBeaten();
|
|
104
|
+
if (beaten.rearm) boss.arm();
|
|
105
|
+
}
|
|
106
|
+
/** SC10: the cell slept this long with nobody in it, so nobody stood in the arena: a beaten boss's wait spends it. */
|
|
107
|
+
slept(seconds: number): void { if (this.beaten !== undefined) this.emptyFor += seconds; }
|
|
84
108
|
/** Players counted at the fight's start, for a continuation: 0 in any one-player fight. */
|
|
85
109
|
get engaged(): number { return this.counted; }
|
|
86
110
|
restoreEngaged(count: number): void { this.counted = count; }
|
|
@@ -56,7 +56,7 @@ export class PhaseEncounter {
|
|
|
56
56
|
const focus = new Vector3(...spec.arena.at), saved = { ...ports.saved };
|
|
57
57
|
const party = this.party = new BossContenders(sim.players, (point) => point.distanceTo(focus) < spec.arena.radius, (player, position, yaw) => {
|
|
58
58
|
player.position.copy(position); player.yaw = yaw; player.health.attributes.health = player.health.attributes.maxHealth;
|
|
59
|
-
});
|
|
59
|
+
}, { served: () => sim.respawn.served, rearm: true });
|
|
60
60
|
const phase = (): EncounterPhase => { const value = this.spec.phases[this.boss.phase]; if (!value) throw new Error('Missing encounter phase'); return value; };
|
|
61
61
|
this.boss = new BossBrain({ id: spec.id, name: spec.name, title: spec.title, retryTitle: spec.retry, intro: spec.intro, introShort: spec.introShort,
|
|
62
62
|
phases: spec.phases.map((p) => ({ at: p.at, name: p.name, caption: p.caption })), reward: {} }, {
|
|
@@ -63,6 +63,8 @@ export interface RefillPorts {
|
|
|
63
63
|
readonly random: () => number;
|
|
64
64
|
/** Put the body back. Nothing else may change the population: the queue has already dropped the entry. */
|
|
65
65
|
readonly spawn: (entry: RefillEntry, yaw: number) => void;
|
|
66
|
+
/** SC5 (J328): a served world (the MMO server's) is a room with one player in it: what falls comes back, as it does for two. */
|
|
67
|
+
readonly served?: () => boolean;
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
/**
|
|
@@ -76,20 +78,25 @@ export class CreatureRefill {
|
|
|
76
78
|
private clock = 0;
|
|
77
79
|
private readonly ports: RefillPorts;
|
|
78
80
|
constructor(ports: RefillPorts) { this.ports = ports; }
|
|
81
|
+
/** A room's refill runs: two players or more, or a served world's one (SC5: a grid cell never starts over, so this is all that refills it). */
|
|
82
|
+
private room(players: readonly RefillPlayer[]): boolean { return players.length > 1 || this.ports.served?.() === true; }
|
|
79
83
|
|
|
80
84
|
/** A body left its spawn point (it fell, or a player tamed it). */
|
|
81
85
|
left(entry: Omit<RefillEntry, 'wait'>): void {
|
|
82
|
-
if (this.ports.players()
|
|
86
|
+
if (!this.room(this.ports.players()) || this.pending.length >= REFILL_LIMIT) return;
|
|
83
87
|
this.pending.push({ ...entry, wait: REFILL_WAIT });
|
|
84
88
|
}
|
|
85
89
|
|
|
90
|
+
/** SC10: the cell slept this long with nobody near anything owed: each wait spends it at one player's rate. */
|
|
91
|
+
slept(seconds: number): void { for (const entry of this.pending) entry.wait -= seconds; }
|
|
92
|
+
|
|
86
93
|
step(dt: number): void {
|
|
87
94
|
if (this.pending.length === 0) return;
|
|
88
95
|
this.clock += dt;
|
|
89
96
|
if (this.clock < REFILL_CHECK) return;
|
|
90
97
|
const elapsed = this.clock, players = this.ports.players();
|
|
91
98
|
this.clock = 0;
|
|
92
|
-
if (players
|
|
99
|
+
if (!this.room(players)) return; // the room emptied to one: what is owed waits, and that player's game is today's
|
|
93
100
|
const due: RefillEntry[] = [];
|
|
94
101
|
for (const entry of this.pending) {
|
|
95
102
|
entry.wait -= elapsed * refillRate(playersNear(players, entry.x, entry.z));
|
|
@@ -57,6 +57,8 @@ export class LedgerBook {
|
|
|
57
57
|
}
|
|
58
58
|
/** Seat a player's book as it was saved: their serial goes on from there, so a client that remembers a higher one still hears what comes next (E7.4). */
|
|
59
59
|
seat(player: string, saved: LedgerBookSave[string]): void { this.books.set(player, { serial: saved.serial, rows: saved.rows.slice(), ids: new Set(saved.rows.map(row => row.id)) }); }
|
|
60
|
+
/** A player who has left: their serial and receipts went with their save (SC10: a long-lived world keeps only its live players'). */
|
|
61
|
+
drop(player: string): void { this.books.delete(player); }
|
|
60
62
|
private of(player: string): Book {
|
|
61
63
|
let book = this.books.get(player);
|
|
62
64
|
if (book === undefined) { book = { serial: 0, rows: [], ids: new Set() }; this.books.set(player, book); }
|
|
@@ -226,6 +226,21 @@ export class NetRoom {
|
|
|
226
226
|
this.remove(client);
|
|
227
227
|
return to.adopt(client.transport, player, client.queue, { identity: client.identity, reader: client.reader, capabilities: client.capabilities ?? [] });
|
|
228
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* GC15 (3): a player crossed into cell `toFrame` on another worker. Their client hears `travel` here, then this room lets it go with its
|
|
231
|
+
* link left open: the target room on the other worker hears the client's hello again and welcomes it (`travel`, `welcome`, full frame,
|
|
232
|
+
* as `handOff` does on one worker). False when there is nobody live to send.
|
|
233
|
+
*/
|
|
234
|
+
handOut(id: number, toFrame: number): boolean {
|
|
235
|
+
const client = this.clients.find(entry => entry.id === id);
|
|
236
|
+
if (client?.state !== 'live') return false;
|
|
237
|
+
const tick = this.world.tick(), travel: NetEvent = { kind: 'travel', tick, from: this.world.cell(), to: toFrame };
|
|
238
|
+
client.transport.send('reliable', eventsMessage(tick, [travel]).buffer);
|
|
239
|
+
this.remove(client);
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
/** GC15 (3): a client whose hello this room heard again after a travel from another worker reads this room's receipts from the start, as an adopted one does (its hello's ledger was the first room's). */
|
|
243
|
+
travelled(id: number): void { const client = this.clients.find(entry => entry.id === id); if (client !== undefined) client.ledgerSeen = 0; }
|
|
229
244
|
private adopt(transport: Transport, player: NetPlayer, queue: CommandQueue, said: { readonly identity: NetIdentity; readonly reader: WireClientReader | undefined; readonly capabilities: readonly number[] }): number | null {
|
|
230
245
|
const id = this.join(transport, player, queue), client = this.clients.find(entry => entry.id === id), { identity } = said;
|
|
231
246
|
if (client !== undefined) {
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { LastPlace, type Feet, type LastPlaceSaved, type PlaceArea, type Stand } from '../../../shared/engine/quest/lastPlace';
|
|
2
2
|
import type { PlayerHealth } from '../../../shared/engine/combat/health';
|
|
3
3
|
|
|
4
|
+
declare module '../../../client/engine/events/maps' {
|
|
5
|
+
interface EventMap {
|
|
6
|
+
/** SERVER-CELLS SC10 (J328): a grid cell's world takes no ticks while nobody is in it, and is never rebuilt. On its first seat after
|
|
7
|
+
* empty time the cell host says how long it slept, and what comes back on a clock (a beaten boss, a fallen creature, a lair) spends it. */
|
|
8
|
+
'world.slept': { seconds: number };
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
4
12
|
/** The page's death fade (ui/DeathFade: dark, then the fade back): no blow lands on the fallen until then. */
|
|
5
13
|
export const FALL_FADE = 1.35;
|
|
6
14
|
/** One player's record. A save holds a player only once they have one. */
|
|
@@ -75,7 +75,11 @@ export function installArenaEntry(host: SimHost, input: unknown, row: ArenaEntry
|
|
|
75
75
|
spawnBody: () => spawn(`${row.id}.body`, row.body.kind, row.body.variant, room.origin.x, room.origin.z, 0),
|
|
76
76
|
spawnAdd: (_index, ax, az, yaw) => spawn(`${row.id}.add.${String(adds++ % ADDS)}`, add.kind, add.variant, ax, az, yaw),
|
|
77
77
|
retire: actor => { actor.hidden = true; }, find: id => body(id), seal, saved,
|
|
78
|
-
|
|
78
|
+
// SC10 (J328): back to not beaten only when a served world's King stands again: the world's flags clear and the orb goes with them
|
|
79
|
+
persist: value => {
|
|
80
|
+
if (!value.defeated) { host.flags.clear(flag('defeated')); host.flags.clear(flag('paid')); orb = null; return; }
|
|
81
|
+
host.flags.set(flag('defeated')); if (value.rewardTaken) host.flags.set(flag('paid'));
|
|
82
|
+
},
|
|
79
83
|
// a lone player earned it alone; a room's earners come from the book at the killing blow
|
|
80
84
|
spawnReward: () => { if (!fight.bounty.room) fight.bounty.award([...host.players.keys()]); orb = orbAt; }, rewardPoint: () => orb });
|
|
81
85
|
// J105: the orb on the pedestal is each earner's own, through the ledger, and it stands until the last of them has taken theirs.
|
|
@@ -126,6 +126,8 @@ export function installArenaRoom<A extends ArenaRoomBody>(host: SimHost, rows: A
|
|
|
126
126
|
};
|
|
127
127
|
host.onStep(`${rows.step}.brain`, dt => {
|
|
128
128
|
if (portal !== undefined) for (const player of host.players.values()) through(player, portal, dt);
|
|
129
|
+
// SC10 (J328): a long-lived world forgets the doors of those who left (one who comes back starts outside, as a fresh world's would)
|
|
130
|
+
for (const id of doors.keys()) if (!host.players.has(id)) doors.delete(id);
|
|
129
131
|
seal(); sand.advance(dt);
|
|
130
132
|
const body = fight.body(); if (body === null || !body.alive) return;
|
|
131
133
|
const foe = row.party.nearest(body.position).position, initial = rows.initialize;
|
|
@@ -165,7 +165,8 @@ export function installGroundBoss(host: SimHost, input: unknown, profile: unknow
|
|
|
165
165
|
restoreRoamingFight(row, fight, value, actors);
|
|
166
166
|
if (fight.body !== null) fight.body.hidden = hidden;
|
|
167
167
|
},
|
|
168
|
-
|
|
168
|
+
// SC10: a served world's boss standing again (its record back to not beaten) takes its untaken orb with it
|
|
169
|
+
}, saved, persist: value => { if (!value.defeated) reward = null; record.persist(value); }, rewardPoint: () => reward,
|
|
169
170
|
spawnReward: () => { const at = itemPickupFloor(host.physics, fight.rewardPoint()); reward = { x: at.x, y: at.y + ITEM_PICKUP_HOVER + row.reward.hover, z: at.z }; } });
|
|
170
171
|
const Reward = v.strictObject({ version: v.literal(1), point: v.nullable(v.strictObject({ x: finite, y: finite, z: finite })) });
|
|
171
172
|
host.onStep(row.steps.reward, () => undefined, {
|
|
@@ -15,18 +15,22 @@ const Encounter = v.strictObject({ attempt: v.boolean(), waitForReturn: v.boolea
|
|
|
15
15
|
|
|
16
16
|
/** Install from data. Spawn remains the existing AS director/roster command,
|
|
17
17
|
* rather than an arbitrary callback lent to the encounter. */
|
|
18
|
-
export function installWakeBoss(host: SimHost, input: unknown, placement: { pool: { x: number; z: number }; arena: number }): { encounter: WakeBossEncounter; publish: (event: string) => void } {
|
|
18
|
+
export function installWakeBoss(host: SimHost, input: unknown, placement: { pool: { x: number; z: number }; arena: number }, returned?: () => void): { encounter: WakeBossEncounter; publish: (event: string) => void } {
|
|
19
19
|
const row = parseWakeEncounter(input), { pool, arena } = placement;
|
|
20
20
|
const encounter = new WakeBossEncounter(row, pool);
|
|
21
21
|
const body = () => Array.from(host.entities.values()).find(actor => actor.kind === row.kind) ?? null;
|
|
22
22
|
// J104, J107: whom the fight deals with is the living player nearest the pool, so it runs while anyone is in the arena. Those
|
|
23
23
|
// there when it wakes set its curves. A lone player runs the one-player encounter, unread.
|
|
24
24
|
const near = (point: { readonly x: number; readonly z: number }): boolean => Math.hypot(point.x - pool.x, point.z - pool.z) < row.arena.radius;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
// SERVER-CELLS SC10 (J328): a grid cell's world is never rebuilt, so a served world's won fight stands again once nobody has stood
|
|
26
|
+
// in the arena five minutes: the world's death flag cleared and the body gone (`returned`), so the next wake cue starts it afresh.
|
|
27
|
+
const party = new BossContenders(host.players, near, () => undefined, { served: () => host.respawn.served, rearm: false });
|
|
28
|
+
const contended = { get engaged() { return encounter.state === 'fight'; }, get state() { return encounter.state; }, script: { respawnPoint: () => ({ pos: new Vector3(pool.x, 0, pool.z), yaw: 0 }) },
|
|
29
|
+
disarm: () => undefined, arm: () => undefined, onPlayerDeath: () => false,
|
|
30
|
+
returnBeaten: () => { host.flags.clear(row.deadFlag); returned?.(); encounter.returnBeaten(); } };
|
|
28
31
|
const observation = (): WakeBossObservation => ({ player: nearestOnGround(host.players, pool.x, pool.z).position, animal: body(), wake: host.flags.has(row.wakeFlag), dead: host.flags.has(row.deadFlag) });
|
|
29
32
|
const flush = (): void => { for (const effect of encounter.takeEffects()) if (effect.kind === 'outcome') host.events.emit('boss.attempt', { boss: row.id, level: row.level, outcome: effect.outcome }); };
|
|
33
|
+
host.events.on('world.slept', ({ seconds }) => { party.slept(seconds); }, host.scope);
|
|
30
34
|
host.events.on('damage.dealt', ({ req, killed }) => {
|
|
31
35
|
const actor = body(); if (killed && actor !== null && req.target === actor.combatActor()) host.flags.set(row.deadFlag);
|
|
32
36
|
}, host.scope);
|
|
@@ -37,7 +41,7 @@ export function installWakeBoss(host: SimHost, input: unknown, placement: { pool
|
|
|
37
41
|
for (const [id, player] of host.players) if (id !== actor.id && player.health.alive && near(player.position)) return;
|
|
38
42
|
encounter.onPlayerDeath(host.players.get(actor.id)?.position ?? host.playerFocus); flush();
|
|
39
43
|
}, host.scope);
|
|
40
|
-
host.onStep(row.step,
|
|
44
|
+
host.onStep(row.step, dt => { party.observe(contended, dt); encounter.update(observation()); flush(); }, {
|
|
41
45
|
snapshot: () => { const { engaged } = party; return JSON.stringify({ ...encounter.encounterSnapshot(), ...(engaged === 0 ? {} : { engaged }) }); },
|
|
42
46
|
restore: value => { const saved = v.parse(Encounter, JSON.parse(v.parse(v.string(), value))); encounter.encounterRestore(saved); party.restoreEngaged(saved.engaged ?? 0); },
|
|
43
47
|
});
|
|
@@ -128,7 +128,7 @@ export async function prepareOpenArena(product: Pick<ShardProduct, 'json' | 'sec
|
|
|
128
128
|
easeViewToward(weapons().of(near).look,camera.position,target,dt);},spawnReward:()=>{
|
|
129
129
|
room.heartFell();
|
|
130
130
|
const at=itemPickupFloor(host.physics,fight.rewardPoint());rewardPoint=new Vector3(at.x,at.y+ITEM_PICKUP_HOVER+.5,at.z);reward=true;
|
|
131
|
-
},persist:saved=>{records.bosses.write({...records.bosses.read(),[data.definition.id]:saved});},toast,feed},ui,current);
|
|
131
|
+
},persist:saved=>{if(!saved.defeated){reward=false;rewardPoint=null;}/* SC10: the heart stands again, its untaken orb goes */records.bosses.write({...records.bosses.read(),[data.definition.id]:saved});},toast,feed},ui,current);
|
|
132
132
|
encounter.boss=boss;room.bind(boss,fight,()=>rewardPoint);first.health.checkpoint(host.scope,()=>room.party.died(boss));
|
|
133
133
|
const boundaryPorts={boss,fight,prompt,get player(){return room.near.position;},toast,
|
|
134
134
|
wall:()=>{hit('wall',room.near.position,data.view.wallDamage,data.lines.wall);},clear:()=>{actual.storm.weather.force(data.weather.clearing);},
|
|
@@ -154,7 +154,7 @@ export async function prepareOpenArena(product: Pick<ShardProduct, 'json' | 'sec
|
|
|
154
154
|
if(pickPrompt([prompt],eye,host.physics)===prompt)
|
|
155
155
|
arenaTie(fight.life,{engaged:boss.engaged,victory:boss.state==='victory',hit:reward,mounted:room.mounted(),storm:actual.storm.stormActive},data.tieLines,{boss,fight,toast:line=>{toast(line);sayFightView(host,arenaTieWord(data.definition.id),[data.tieLines.indexOf(line)]);}});
|
|
156
156
|
}
|
|
157
|
-
room.party.observe(boss);
|
|
157
|
+
room.party.observe(boss,dt);
|
|
158
158
|
if(boss.state!=='dormant'||fight.body.visible)boss.update(dt,host.clock.now);else fight.update(dt,host.clock.now,false);
|
|
159
159
|
const answer=fight.takeBoundary();if(answer!==null)arenaBoundary(answer,data.lines,data.record,boundaryPorts);
|
|
160
160
|
sayLooks(dt);
|
|
@@ -32,8 +32,10 @@ export class OpenArenaRoom {
|
|
|
32
32
|
const { center } = data.arena, radius = data.place.arenaRadius; this.centre = new Vector3(center.x, 0, center.z); this.tag = `boss.${data.record.kind}`;
|
|
33
33
|
for (const [name, row] of Object.entries(data.contacts)) this.rows.set(name, strikeFromData(row));
|
|
34
34
|
const inside = (point: { readonly x: number; readonly z: number }): boolean => (point.x - center.x) ** 2 + (point.z - center.z) ** 2 < radius ** 2;
|
|
35
|
-
|
|
35
|
+
// SC5 (J328): a served world's beaten heart stands again once the arena has stood empty; its prompt starts the next fight.
|
|
36
|
+
this.party = new BossContenders(host.players, inside, place, { served: () => host.respawn.served, rearm: false });
|
|
36
37
|
this.bounty = new BossBounty(host, () => null, data.definition.id); this.inside = inside;
|
|
38
|
+
host.events.on('world.slept', ({ seconds }) => { this.party.slept(seconds); }, host.scope);
|
|
37
39
|
}
|
|
38
40
|
private readonly inside: (point: { readonly x: number; readonly z: number }) => boolean;
|
|
39
41
|
/** The heart has fallen: name who earned it. Alone there is no one to name. */
|
|
@@ -4,6 +4,12 @@ import type { GridAssembly, GridPoint } from '../../../shared/game/grid/assembly
|
|
|
4
4
|
import { installGridCrossing, type GridCrossingSession } from '../../../shared/game/grid/crossing';
|
|
5
5
|
import type { GridSimulation } from './simulation';
|
|
6
6
|
import type { GridLoadout } from '../../../shared/game/grid/wallet';
|
|
7
|
+
import { CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
8
|
+
|
|
9
|
+
/** How far from a cell's edge a player on the road has its world opened (the road between two cells is 62.5 m). */
|
|
10
|
+
const WARM_ROAD_METRES = 55;
|
|
11
|
+
/** The least a tick's move toward it counts as heading there (a walk is 0.07 m a tick); a capsule settling is not. */
|
|
12
|
+
const WARM_STEP_METRES = 0.02;
|
|
7
13
|
|
|
8
14
|
/** A player's completed hand-off: the `travel` a client's view follows (E5-REPLICATION §6.3.4). */
|
|
9
15
|
export interface GridTravel { readonly player: string; readonly from: string | null; readonly to: string | null }
|
|
@@ -22,6 +28,12 @@ export class GridRoom {
|
|
|
22
28
|
private readonly crossings = new Map<string, { readonly session: GridCrossingSession; readonly scope: Scope }>();
|
|
23
29
|
private readonly travels: GridTravel[] = [];
|
|
24
30
|
private readonly scope = new Scope('grid-room');
|
|
31
|
+
/** each player's last cell left for the road, and the cells opened ahead of them on this stretch of road (GC5): each at
|
|
32
|
+
* most once a stretch, so two players on the road never evict each other's cell tick after tick, and a failed open is not
|
|
33
|
+
* retried every tick (the crossing still prepares it at the line and reports a failure) */
|
|
34
|
+
private readonly departed = new Map<string, string>();
|
|
35
|
+
private readonly opened = new Map<string, Set<string>>();
|
|
36
|
+
private readonly feet = new Map<string, { x: number; z: number }>();
|
|
25
37
|
constructor(grid: GridSimulation, assembly: GridAssembly, ports: GridRoomPorts) {
|
|
26
38
|
this.grid = grid; this.assembly = assembly; this.ports = ports;
|
|
27
39
|
for (const player of grid.players()) this.watch(player);
|
|
@@ -30,7 +42,7 @@ export class GridRoom {
|
|
|
30
42
|
const { grid } = this, scope = this.scope.child(`crossing:${player}`);
|
|
31
43
|
const session = installGridCrossing({ current: () => grid.current(player), prepare: (from, to) => grid.prepare(from, to, player), ready: instance => grid.ready(instance),
|
|
32
44
|
checkpoint: instance => grid.checkpoint(instance), target: feet => grid.target(feet, player) }, this.assembly, instance => this.ports.loadout(player, instance), scope,
|
|
33
|
-
(from, to) => { this.travels.push({ player, from, to }); });
|
|
45
|
+
(from, to) => { this.travels.push({ player, from, to }); if (from !== null) this.departed.set(player, from); });
|
|
34
46
|
this.crossings.set(player, { session, scope });
|
|
35
47
|
}
|
|
36
48
|
/** Another player comes onto the highway at `at`, world coordinates, or into the world at `site`, in its own. */
|
|
@@ -39,11 +51,40 @@ export class GridRoom {
|
|
|
39
51
|
leave(player: string): boolean {
|
|
40
52
|
const crossing = this.crossings.get(player);
|
|
41
53
|
if (crossing === undefined || !this.grid.leave(player)) return false;
|
|
42
|
-
crossing.scope.dispose(); this.crossings.delete(player);
|
|
54
|
+
crossing.scope.dispose(); this.crossings.delete(player); this.departed.delete(player); this.feet.delete(player); this.opened.delete(player);
|
|
43
55
|
return true;
|
|
44
56
|
}
|
|
45
57
|
/** Everyone's own crossing, once per fixed tick, before any world steps. */
|
|
46
|
-
cross(): void {
|
|
58
|
+
cross(): void {
|
|
59
|
+
for (const [player, { session }] of this.crossings) {
|
|
60
|
+
const feet = this.grid.worldFeet(player);
|
|
61
|
+
this.warm(player, feet);
|
|
62
|
+
session.step(feet);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** GC5 (preview's in-page server, J311): a player on the road has the nearest cell ahead opened before they reach its line,
|
|
66
|
+
* as the page builds its own: opened only at the 6 m line, a cell's world held them at its wall for its whole load. The
|
|
67
|
+
* cell they left is not ahead. A failed open stays the crossing's to report. */
|
|
68
|
+
private warm(player: string, feet: Readonly<GridPoint>): void {
|
|
69
|
+
const previous = this.feet.get(player);
|
|
70
|
+
this.feet.set(player, { x: feet.x, z: feet.z });
|
|
71
|
+
if (this.grid.current(player) !== null) { this.opened.delete(player); return; }
|
|
72
|
+
if (previous === undefined) return;
|
|
73
|
+
const left = this.departed.get(player), edge = (p: Readonly<{ x: number; z: number }>, cell: { readonly origin: GridPoint }): number =>
|
|
74
|
+
Math.max(Math.abs(p.x - cell.origin.x), Math.abs(p.z - cell.origin.z)) - CHUNK_HALF;
|
|
75
|
+
let best: string | undefined, bestDistance = WARM_ROAD_METRES;
|
|
76
|
+
for (const cell of this.assembly.cells) {
|
|
77
|
+
// only a cell they draw nearer to: not one behind them, nor the one they left
|
|
78
|
+
const distance = edge(feet, cell);
|
|
79
|
+
if (cell.instance === left || distance > bestDistance || distance > edge(previous, cell) - WARM_STEP_METRES) continue;
|
|
80
|
+
best = cell.instance; bestDistance = distance;
|
|
81
|
+
}
|
|
82
|
+
if (best === undefined || this.grid.ready(best)) return;
|
|
83
|
+
const opened = this.opened.get(player) ?? new Set<string>();
|
|
84
|
+
if (opened.has(best)) return;
|
|
85
|
+
opened.add(best); this.opened.set(player, opened);
|
|
86
|
+
void this.grid.prefetch([best]).catch(() => undefined);
|
|
87
|
+
}
|
|
47
88
|
/** One fixed tick: everyone's own crossing, then every occupied world. */
|
|
48
89
|
step(commands?: ReadonlyMap<string, SimTickCommand>): void { this.cross(); this.grid.stepAll(commands); }
|
|
49
90
|
/** Every hand-off since the last call. */
|