@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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// SA33 (meta SHARD-AUTHORING, J314): a new slug's cell reaches a running server with no engine release. The API places a new slug (SA30) and
|
|
2
2
|
// writes this file, signed with its own placement key; the release key stays engine CI's, because it vouches for the server bundle the box
|
|
3
|
-
// runs. A placement can only add a cell on an empty spot, for a shard whose server pack this build's book
|
|
4
|
-
// build, the bundle or the save epoch, and a new serial here starts no grace, so
|
|
3
|
+
// runs. A placement can only add a cell on an empty spot, for a shard whose server pack this build's book holds or (SA47) the cook's index
|
|
4
|
+
// of the cell's shardfile `hash` names: it never moves the build, the bundle or the save epoch, and a new serial here starts no grace, so
|
|
5
|
+
// players in every other cell stay connected.
|
|
5
6
|
import { Scope } from '@wildshard/engine/app/scope';
|
|
6
7
|
import { fetchSignedText, readSigned } from './releaseFile';
|
|
7
8
|
import { PlacementSchema, type PlacementFile } from '@wildshard/engine/game/grid/placementRows';
|
|
@@ -7,7 +7,7 @@ import { SimNetWorld } from '@wildshard/engine/net/simWorld';
|
|
|
7
7
|
import type { Transport } from '@wildshard/engine/net/transport';
|
|
8
8
|
import type { SimHost } from '@wildshard/engine/sim';
|
|
9
9
|
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
10
|
-
import { carryMotion } from '@wildshard/engine/game/grid/simulation';
|
|
10
|
+
import { carryMotion, motionOf } from '@wildshard/engine/game/grid/simulation';
|
|
11
11
|
import type { GridAssembly, GridCell } from '@wildshard/engine/game/grid/assembly';
|
|
12
12
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
13
13
|
import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
|
|
@@ -16,8 +16,9 @@ import { LEAD_SEAT } from '../standalone/cellWorld';
|
|
|
16
16
|
import { HOLD_MS, type ResumeAt, type RoomNews, type SeatEntry } from './cellProtocol';
|
|
17
17
|
import { crossedTo, finite, type CrossArrival, type CrossTarget } from './crossing';
|
|
18
18
|
import { FallFloor } from '../standalone/fallFloor';
|
|
19
|
-
import { placeOnRoad } from '../standalone/roadWorld';
|
|
20
|
-
import { LEFT } from './socketPump';
|
|
19
|
+
import { openCellWalls, placeOnRoad } from '../standalone/roadWorld';
|
|
20
|
+
import { LEFT, SeatTransport } from './socketPump';
|
|
21
|
+
import { cellFrame } from './gridCells';
|
|
21
22
|
|
|
22
23
|
/** How often a seat whose crossing is asked for asks again, and how often holds are looked at, in ticks. */
|
|
23
24
|
const ASK_TICKS = 30;
|
|
@@ -54,6 +55,8 @@ export class RoadRoom implements CrossTarget {
|
|
|
54
55
|
readonly host: SimHost;
|
|
55
56
|
private readonly options: RoadRoomOptions;
|
|
56
57
|
private readonly seats = new Map<string, RoadSeat>();
|
|
58
|
+
/** GC15 (3): cells on other workers this road crosses into (`open`), their walls down. */
|
|
59
|
+
private readonly opened = new Set<string>();
|
|
57
60
|
/** The grid the trigger reads: the options' until a placement grows it (SA34a). */
|
|
58
61
|
private assembly: GridAssembly;
|
|
59
62
|
constructor(options: RoadRoomOptions) {
|
|
@@ -73,6 +76,11 @@ export class RoadRoom implements CrossTarget {
|
|
|
73
76
|
get holding(): number { let held = 0; for (const seat of this.seats.values()) if (seat.transport === null) held++; return held; }
|
|
74
77
|
holds(device: string): boolean { return this.seats.has(device); }
|
|
75
78
|
bodyId(device: string): string | undefined { return this.seats.get(device)?.body; }
|
|
79
|
+
/** GC4: someone on this road stands within `reach` of `origin` on both axes (a cell's square grown by how near counts). */
|
|
80
|
+
near(origin: { readonly x: number; readonly z: number }, reach: number): boolean {
|
|
81
|
+
for (const seat of this.seats.values()) { const at = this.host.players.get(seat.body)?.position; if (at !== undefined && Math.abs(at.x - origin.x) <= reach && Math.abs(at.z - origin.z) <= reach) return true; }
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
76
84
|
bodyOf(device: string): PlayerSim | undefined { const seat = this.seats.get(device); return seat === undefined ? undefined : this.host.players.get(seat.body); }
|
|
77
85
|
|
|
78
86
|
admit(entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim): CrossArrival | string {
|
|
@@ -100,6 +108,28 @@ export class RoadRoom implements CrossTarget {
|
|
|
100
108
|
hello();
|
|
101
109
|
this.options.post({ kind: 'seated', device: seat.device, body: seat.body, seats: this.seats.size });
|
|
102
110
|
}
|
|
111
|
+
/** GC15 (3): cells on other workers whose entryways stand: their walls on this road come down and a walker crosses into them. */
|
|
112
|
+
open(cells: readonly string[]): void {
|
|
113
|
+
const fresh = cells.filter(cell => !this.options.hosts(cell) && !this.opened.has(cell));
|
|
114
|
+
openCellWalls(this.host, fresh);
|
|
115
|
+
for (const cell of fresh) this.opened.add(cell);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* GC15 (3): the seat walks off the road into `to`, a cell on another worker. Its client hears `travel` (`NetRoom.handOut`), the seat goes
|
|
119
|
+
* from here with no hold, and its port says `out` with the walker's motion, after everything else it was sent: the door moves the socket.
|
|
120
|
+
* False when nothing went (no live link here).
|
|
121
|
+
*/
|
|
122
|
+
handOut(device: string, to: string): boolean {
|
|
123
|
+
const seat = this.seats.get(device), transport = seat?.transport ?? null, player = seat === undefined ? undefined : this.host.players.get(seat.body);
|
|
124
|
+
if (seat === undefined || !(transport instanceof SeatTransport) || seat.client === null || player === undefined || !this.opened.has(to)) return false;
|
|
125
|
+
const motion = mountedPlayerOf(this.host, seat.body)?.mounted === true ? null : motionOf(player);
|
|
126
|
+
if (!this.net.handOut(seat.client, cellFrame(to))) return false;
|
|
127
|
+
mountedPlayerOf(this.host, seat.body)?.dismount();
|
|
128
|
+
seat.closeOff?.(); seat.closeOff = null; seat.transport = null; seat.client = null;
|
|
129
|
+
transport.handOut(motion);
|
|
130
|
+
this.release(seat);
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
103
133
|
/** The seat walks off the road into `target`, a cell on this worker: its body there first, then its link (`DedicatedRoom.handOver`'s order). */
|
|
104
134
|
handOver(device: string, target: CrossTarget, entry: SeatEntry, at: ResumeAt): boolean {
|
|
105
135
|
const seat = this.seats.get(device), transport = seat?.transport ?? null;
|
|
@@ -155,7 +185,7 @@ export class RoadRoom implements CrossTarget {
|
|
|
155
185
|
if (seat.transport === null || player === undefined || !finite(player.position)) continue;
|
|
156
186
|
const crossed = crossedTo(this.assembly, null, player.position);
|
|
157
187
|
const to = crossed?.cell?.instance ?? null;
|
|
158
|
-
if (crossed === undefined || to === null || !this.options.hosts(to)) { seat.asked = null; continue; }
|
|
188
|
+
if (crossed === undefined || to === null || (!this.options.hosts(to) && !this.opened.has(to))) { seat.asked = null; continue; }
|
|
159
189
|
if (seat.asked === to && this.host.state.tick - seat.askedAt < ASK_TICKS) continue;
|
|
160
190
|
seat.asked = to; seat.askedAt = this.host.state.tick;
|
|
161
191
|
this.options.post({ kind: 'crossing', device: seat.device, to, at: { ...crossed.at, yaw: player.yaw } });
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SERVER-CELLS SC1 (J328): the dedicated server's `/metrics`, Prometheus text on 127.0.0.1 only, on `METRICS_PORT` (unset: off). The
|
|
2
|
+
// process's own numbers come from the metrics client's defaults; the rest is read from what the door already hears: each worker's 10 s
|
|
3
|
+
// reading (tick times, ticks per second, drops, cells awake, players, its heap and its event-loop lag), each `cell.booted`, each crossing,
|
|
4
|
+
// and `/health`'s table for the cells each worker holds. Nothing here alters a reply or a tick, and nothing leaves loopback.
|
|
5
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- Its own loopback port.
|
|
6
|
+
import { createServer, type Server, type ServerResponse } from 'node:http';
|
|
7
|
+
// oxlint-disable-next-line import/no-nodejs-modules -- The port it ended up on.
|
|
8
|
+
import type { AddressInfo } from 'node:net';
|
|
9
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
10
|
+
import { Counter, Gauge, Histogram, Registry, collectDefaultMetrics } from '@prometheus-io/client';
|
|
11
|
+
import type { WorkerReading } from './cellProtocol';
|
|
12
|
+
import { loopLag, type LoopLag } from './loopLag';
|
|
13
|
+
|
|
14
|
+
/** Only loopback: the box's Prometheus scrapes it there (SC2), and nothing else may. */
|
|
15
|
+
const HOST = '127.0.0.1';
|
|
16
|
+
/** The main thread's lag window, as long as a worker's reading, so a second scraper never shortens it. */
|
|
17
|
+
const LAG_MS = 10_000;
|
|
18
|
+
|
|
19
|
+
/** `METRICS_PORT`: unset or blank is off; 0 asks for any free port (a proof's); anything else must be a port, or the server refuses to start. */
|
|
20
|
+
export function metricsPort(env: Readonly<Record<string, string | undefined>>): number | undefined {
|
|
21
|
+
const value = env['METRICS_PORT'];
|
|
22
|
+
if (value === undefined || value.trim() === '') return undefined;
|
|
23
|
+
const port = Number(value);
|
|
24
|
+
if (!Number.isInteger(port) || port < 0 || port > 65_535) throw new Error(`METRICS_PORT ${value} is not a port`);
|
|
25
|
+
return port;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** What `/metrics` reads of the world when scraped: `/health`'s table, each open cell and the worker it runs on. */
|
|
29
|
+
export interface MetricsWorld { health: () => { readonly table: Readonly<Record<string, number>> } }
|
|
30
|
+
|
|
31
|
+
/** The server's metrics: fed by the door's callbacks, served on loopback once `listen` is called. */
|
|
32
|
+
export class ServerMetrics {
|
|
33
|
+
readonly registry: Registry = new Registry();
|
|
34
|
+
private world: MetricsWorld | undefined;
|
|
35
|
+
private server: Server | undefined;
|
|
36
|
+
private readonly log: (line: Record<string, unknown>) => void;
|
|
37
|
+
/** The main thread's lag over its last whole window. */
|
|
38
|
+
private mainLag: LoopLag = { p50: 0, p99: 0, max: 0 };
|
|
39
|
+
private readonly scope = new Scope('dedicated.metrics');
|
|
40
|
+
private readonly lag: Gauge<'thread' | 'quantile'>;
|
|
41
|
+
private readonly memory: Gauge<'thread' | 'kind'>;
|
|
42
|
+
private readonly tick: Gauge<'worker' | 'quantile'>;
|
|
43
|
+
private readonly cellTick: Gauge<'cell'>;
|
|
44
|
+
/** Each worker's cells awake in its last reading. */
|
|
45
|
+
private readonly ticking = new Map<number, ReadonlySet<string>>();
|
|
46
|
+
private readonly rate: Gauge<'worker'>;
|
|
47
|
+
private readonly drops: Counter<'worker'>;
|
|
48
|
+
private readonly awake: Gauge<'worker'>;
|
|
49
|
+
private readonly players: Gauge<'worker'>;
|
|
50
|
+
private readonly held: Gauge<'worker'>;
|
|
51
|
+
private readonly boots: Histogram;
|
|
52
|
+
private readonly crossings: Histogram<'moved'>;
|
|
53
|
+
|
|
54
|
+
constructor(log: (line: Record<string, unknown>) => void) {
|
|
55
|
+
this.log = log;
|
|
56
|
+
const registers = [this.registry], readLag = loopLag();
|
|
57
|
+
this.scope.interval(LAG_MS, () => { this.mainLag = readLag(); });
|
|
58
|
+
collectDefaultMetrics({ register: this.registry });
|
|
59
|
+
// A metric's `collect` runs with the metric as `this`: these read the server's own state.
|
|
60
|
+
const mainLag = (): LoopLag => this.mainLag, table = (): Readonly<Record<string, number>> => this.world?.health().table ?? {};
|
|
61
|
+
this.lag = new Gauge({ name: 'wildshard_eventloop_lag_seconds', help: 'Event-loop lag per thread over its last 10 s window.', labelNames: ['thread', 'quantile'], registers,
|
|
62
|
+
collect() { const { p50, p99, max } = mainLag(); this.set({ thread: 'main', quantile: '0.5' }, p50 / 1000); this.set({ thread: 'main', quantile: '0.99' }, p99 / 1000); this.set({ thread: 'main', quantile: '1' }, max / 1000); } });
|
|
63
|
+
this.memory = new Gauge({ name: 'wildshard_thread_memory_bytes', help: 'Each thread\'s own heap, external and array-buffer bytes (a worker\'s from its last reading).', labelNames: ['thread', 'kind'], registers,
|
|
64
|
+
collect() { const own = process.memoryUsage(); this.set({ thread: 'main', kind: 'heap' }, own.heapUsed); this.set({ thread: 'main', kind: 'external' }, own.external); this.set({ thread: 'main', kind: 'arrayBuffers' }, own.arrayBuffers); } });
|
|
65
|
+
this.tick = new Gauge({ name: 'wildshard_tick_seconds', help: 'Tick time per worker over its last 10 s reading.', labelNames: ['worker', 'quantile'], registers });
|
|
66
|
+
this.cellTick = new Gauge({ name: 'wildshard_cell_tick_seconds', help: 'SC8: each awake cell\'s mean tick time over its worker\'s last 10 s reading (its awake cost).', labelNames: ['cell'], registers });
|
|
67
|
+
this.rate = new Gauge({ name: 'wildshard_ticks_per_second', help: 'Ticks per second per worker over its last 10 s reading.', labelNames: ['worker'], registers });
|
|
68
|
+
this.drops = new Counter({ name: 'wildshard_tick_drops_total', help: 'Ticks a worker\'s clock dropped to catch up.', labelNames: ['worker'], registers });
|
|
69
|
+
this.registry.registerMetric(new Gauge({ name: 'wildshard_cells_resident', help: 'Cells open in memory, per worker (from /health\'s table).', labelNames: ['worker'], registers: [],
|
|
70
|
+
collect() {
|
|
71
|
+
this.reset();
|
|
72
|
+
const counts = new Map<number, number>();
|
|
73
|
+
for (const index of Object.values(table())) counts.set(index, (counts.get(index) ?? 0) + 1);
|
|
74
|
+
for (const [index, count] of counts) this.set({ worker: String(index) }, count);
|
|
75
|
+
} }));
|
|
76
|
+
this.awake = new Gauge({ name: 'wildshard_cells_awake', help: 'Cells with someone in them, ticking, per worker.', labelNames: ['worker'], registers });
|
|
77
|
+
this.players = new Gauge({ name: 'wildshard_players', help: 'Players seated, per worker.', labelNames: ['worker'], registers });
|
|
78
|
+
this.held = new Gauge({ name: 'wildshard_players_held', help: 'Bodies held for a dropped player, per worker.', labelNames: ['worker'], registers });
|
|
79
|
+
this.boots = new Histogram({ name: 'wildshard_cell_boot_seconds', help: 'How long a cell (or a worker\'s road) took to open: each `cell.booted`.', buckets: [0.05, 0.1, 0.25, 0.5, 1, 2, 4, 8, 16], registers });
|
|
80
|
+
this.crossings = new Histogram({ name: 'wildshard_crossing_seconds', help: 'A crossing, from the source\'s ask to the worker\'s answer, by whether the seat moved.', labelNames: ['moved'], buckets: [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2], registers });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The world whose table says which cells each worker holds. */
|
|
84
|
+
watch(world: MetricsWorld): void { this.world = world; }
|
|
85
|
+
/** One worker's 10 s reading. */
|
|
86
|
+
reading(index: number, row: WorkerReading): void {
|
|
87
|
+
const worker = String(index);
|
|
88
|
+
for (const [quantile, ms] of [['0.5', row.p50], ['0.95', row.p95], ['0.99', row.p99], ['1', row.max]] as const) this.tick.set({ worker, quantile }, ms / 1000);
|
|
89
|
+
this.rate.set({ worker }, row.ticksPerSecond);
|
|
90
|
+
// a cell gone back to sleep stops reporting its last awake cost (review SHOULD)
|
|
91
|
+
const awake = new Set(Object.keys(row.cellMs ?? {}));
|
|
92
|
+
for (const cell of this.ticking.get(index) ?? []) if (!awake.has(cell)) this.cellTick.remove({ cell });
|
|
93
|
+
this.ticking.set(index, awake);
|
|
94
|
+
for (const [cell, ms] of Object.entries(row.cellMs ?? {})) this.cellTick.set({ cell }, ms / 1000);
|
|
95
|
+
this.drops.inc({ worker }, Math.max(0, row.drops));
|
|
96
|
+
this.awake.set({ worker }, row.awake);
|
|
97
|
+
this.players.set({ worker }, row.players);
|
|
98
|
+
this.held.set({ worker }, row.held);
|
|
99
|
+
const thread = `worker-${worker}`;
|
|
100
|
+
this.memory.set({ thread, kind: 'heap' }, row.heap);
|
|
101
|
+
if (row.external !== undefined) this.memory.set({ thread, kind: 'external' }, row.external);
|
|
102
|
+
if (row.arrayBuffers !== undefined) this.memory.set({ thread, kind: 'arrayBuffers' }, row.arrayBuffers);
|
|
103
|
+
if (row.lag !== undefined) for (const [quantile, ms] of [['0.5', row.lag.p50], ['0.99', row.lag.p99], ['1', row.lag.max]] as const) this.lag.set({ thread, quantile }, ms / 1000);
|
|
104
|
+
}
|
|
105
|
+
/** A cell, or a worker's road, opened in `ms`. */
|
|
106
|
+
booted(ms: number): void { this.boots.observe(ms / 1000); }
|
|
107
|
+
/** A crossing took `ms`, and the seat moved or stayed. */
|
|
108
|
+
crossed(ms: number, moved: boolean): void { this.crossings.observe({ moved: String(moved) }, ms / 1000); }
|
|
109
|
+
/** The scrape. */
|
|
110
|
+
text(): Promise<string> { return this.registry.metrics(); }
|
|
111
|
+
/** One `/metrics` answer: a scrape that fails says why, and the game never hears of it. */
|
|
112
|
+
private async answer(response: ServerResponse): Promise<void> {
|
|
113
|
+
try { const text = await this.text(); response.writeHead(200, { 'content-type': this.registry.contentType }).end(text); }
|
|
114
|
+
catch (error) { response.writeHead(500).end(String(error)); }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Serve `/metrics` on 127.0.0.1:`port`; answers the port it listens on. */
|
|
118
|
+
async listen(port: number): Promise<number> {
|
|
119
|
+
const server = this.server = createServer((request, response) => {
|
|
120
|
+
if (request.method !== 'GET' || request.url !== '/metrics') { response.writeHead(404).end(); return; }
|
|
121
|
+
void this.answer(response);
|
|
122
|
+
});
|
|
123
|
+
await new Promise<void>((resolve, reject) => { server.once('error', reject); server.listen(port, HOST, () => { server.off('error', reject); resolve(); }); });
|
|
124
|
+
// Once up, a failure on this side port is a line, never a crash of the game; and it never keeps the process alive.
|
|
125
|
+
server.on('error', error => { this.log({ at: 'metrics.error', error: String(error) }); });
|
|
126
|
+
server.unref();
|
|
127
|
+
return (server.address() as AddressInfo).port;
|
|
128
|
+
}
|
|
129
|
+
async close(): Promise<void> {
|
|
130
|
+
this.scope.dispose();
|
|
131
|
+
const server = this.server;
|
|
132
|
+
this.server = undefined;
|
|
133
|
+
if (server !== undefined) await new Promise<void>(resolve => { server.closeAllConnections(); server.close(() => { resolve(); }); });
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -7,15 +7,17 @@ export const LEFT = 'left';
|
|
|
7
7
|
/** The byte a `ready` carries to say so. */
|
|
8
8
|
export const LEAVE_FLAG = 1;
|
|
9
9
|
/** What crosses between a socket's thread and its room's. */
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// GC15 (3): `out`, from the room's end: this seat left for a cell on another worker. Everything the room said before it went first, on
|
|
11
|
+
// this same port, so the door moves the socket to the target's port only once the `travel` is on its way to the client.
|
|
12
|
+
type Pumped = { readonly channel: NetChannel; readonly bytes: ArrayBuffer } | { readonly close: string; readonly silentMs: number } | { readonly out: true; readonly motion: unknown };
|
|
13
|
+
const pumped = (value: unknown): Pumped | null => typeof value === 'object' && value !== null && ('close' in value || 'bytes' in value || 'out' in value) ? value as Pumped : null;
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* J182: the socket lives on the main thread and its cell in a worker, and this is all that joins them. `end` keeps backpressure, the
|
|
15
17
|
* silence check and the keepalive, because those need the socket; the room hears the same bytes it would on any Transport. The port
|
|
16
18
|
* closes with the socket, and what the room says after that goes nowhere.
|
|
17
19
|
*/
|
|
18
|
-
export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => number = diagnosticNow): void {
|
|
20
|
+
export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => number = diagnosticNow, out?: (motion: unknown) => void): void {
|
|
19
21
|
const off = end.onMessage((channel, bytes) => { port.postMessage({ channel, bytes }, [bytes]); });
|
|
20
22
|
// E7.3: a clean quit from the menu: `ready` again, with a flag. The body goes at once.
|
|
21
23
|
const quit = end.onControl((control, bytes) => { if (control === 'ready' && new Uint8Array(bytes)[0] === LEAVE_FLAG) end.close(LEFT); });
|
|
@@ -23,7 +25,11 @@ export function pumpSocket(end: SocketTransport, port: MessagePort, now: () => n
|
|
|
23
25
|
port.onmessage = (event: MessageEvent<unknown>): void => {
|
|
24
26
|
const message = pumped(event.data);
|
|
25
27
|
if (message === null) return;
|
|
26
|
-
if ('
|
|
28
|
+
if ('out' in message) {
|
|
29
|
+
// GC15 (3): the room let this seat go to another worker: the socket stays open and the door points it at the target's port
|
|
30
|
+
off(); quit(); closed(); port.close();
|
|
31
|
+
if (out === undefined) end.close('retry'); else out(message.motion);
|
|
32
|
+
} else if ('close' in message) { off(); quit(); closed(); end.close(message.close); port.close(); } else end.send(message.channel, message.bytes);
|
|
27
33
|
};
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -42,6 +48,7 @@ export class SeatTransport implements Transport {
|
|
|
42
48
|
port.onmessage = (event: MessageEvent<unknown>): void => {
|
|
43
49
|
const message = pumped(event.data);
|
|
44
50
|
if (message === null) return;
|
|
51
|
+
if ('out' in message) return;
|
|
45
52
|
if ('close' in message) { this.silentMs = message.silentMs; this.ended(message.close); } else this.deliver(message.channel, message.bytes);
|
|
46
53
|
};
|
|
47
54
|
}
|
|
@@ -57,6 +64,16 @@ export class SeatTransport implements Transport {
|
|
|
57
64
|
this.port.postMessage({ channel, bytes }, [bytes]);
|
|
58
65
|
}
|
|
59
66
|
onMessage(listener: (channel: NetChannel, bytes: ArrayBuffer) => void): () => void { this.messages.add(listener); return () => { this.messages.delete(listener); }; }
|
|
67
|
+
/**
|
|
68
|
+
* GC15 (3): this seat walks on to a cell on another worker. After everything already sent (the `travel`), the door hears `out` and
|
|
69
|
+
* moves the socket; this end is done, and its close listeners never hear of it: nothing closed.
|
|
70
|
+
*/
|
|
71
|
+
handOut(motion: unknown): void {
|
|
72
|
+
if (!this.open) return;
|
|
73
|
+
// oxlint-disable-next-line unicorn/require-post-message-target-origin -- A MessagePort has no origin.
|
|
74
|
+
this.port.postMessage({ out: true, motion });
|
|
75
|
+
this.open = false; this.closes.clear(); this.messages.clear();
|
|
76
|
+
}
|
|
60
77
|
onClose(listener: (reason: string) => void): () => void { this.closes.add(listener); return () => { this.closes.delete(listener); }; }
|
|
61
78
|
close(reason = 'closed'): void {
|
|
62
79
|
if (!this.open) return;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
// J182, J185: which worker runs which cell. Fixed at startup, never by load, and a cell never moves. How many workers, and how many cells fit
|
|
2
2
|
// one, is a startup setting a bench decides (E7.3e), so nothing here is a promise about the number.
|
|
3
|
+
// SERVER-CELLS SC8: the table is weighed by each cell's measured awake cost (its mean tick ms with a player in it), not by name.
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/**
|
|
6
|
+
* SC8: each cell's awake cost, ms per tick with one player in it: `cell-mem-bench.mjs`'s `cellMs` (the worker readings' per-cell
|
|
7
|
+
* tick time; `/metrics` serves the same as `wildshard_cell_tick_seconds{cell}`), COSTS_MEASURED. Re-measure when a shard grows.
|
|
8
|
+
*/
|
|
9
|
+
const COST: ReadonlyMap<string, number> = new Map<string, number>([
|
|
10
|
+
['nalati-grasslands', 2.741], ['driftwood-isle', 1.755], ['pine-hollow', 1.594], ['blender-template', 1.311], ['far-reach', 0.866], ['template-2', 0.746], ['sunscar-dunes', 0.682], ['nine-dragon-stack', 0.63], ['pastel-plain', 0.608], ['open-plot-0-3', 0.606], ['ink-cel-valley', 0.576], ['open-plot-0-4', 0.374], ['open-plot-4-2', 0.281], ['open-plot-4-4', 0.269], ['open-plot-4-3', 0.244], ['open-plot-4-0', 0.221], ['open-plot-0-0', 0.211], ['open-plot-4-1', 0.206], ['open-plot-2-4', 0.202], ['open-plot-2-0', 0.195], ['open-plot-0-2', 0.186], ['open-plot-3-4', 0.184], ['open-plot-3-0', 0.183], ['open-plot-1-0', 0.18], ['open-plot-0-1', 0.175],
|
|
11
|
+
]);
|
|
12
|
+
/** SC8: the measurement the costs come from. */
|
|
13
|
+
export const COSTS_MEASURED = 'opus-cells3, 2026-11-14 ~02:00 Cancún: cell-mem-bench --remote wildshard-agent --counts 25, release 7251ca24 (v0.1.19) packs, a bot in every cell';
|
|
14
|
+
/** A cell with no measured cost (a new Open Plot) weighs as a measured Open Plot does. */
|
|
15
|
+
const UNMEASURED = 0.206;
|
|
16
|
+
/** Cells that always share a worker. */
|
|
17
|
+
const TOGETHER: readonly (readonly string[])[] = [['sunscar-dunes', 'far-reach']];
|
|
8
18
|
/** What each channel starts on (J185). Production tries 4 and goes to 8 only if the bench says it doesn't fit. Staging runs on pinned CPUs. The cap is per grid (J182). */
|
|
9
19
|
const SETTINGS: Readonly<Record<string, { readonly workers: number; readonly seats: number }>> = { production: { workers: 4, seats: 32 }, staging: { workers: 2, seats: 16 } };
|
|
10
20
|
|
|
@@ -25,17 +35,25 @@ export function worldCrossing(value: string | undefined): boolean {
|
|
|
25
35
|
throw new Error(`WORLD_CROSSING=${value}: only worker (the default) or off`);
|
|
26
36
|
}
|
|
27
37
|
|
|
38
|
+
/** SC8: a cell's awake cost in ms per tick (measured, or an Open Plot's when it has none). */
|
|
39
|
+
export function cellCost(slug: string): number { return COST.get(slug) ?? UNMEASURED; }
|
|
40
|
+
|
|
28
41
|
/**
|
|
29
|
-
* The table for the cells this server opens: one row a worker, at most `workers` rows
|
|
30
|
-
*
|
|
42
|
+
* The table for the cells this server opens: one row a worker, at most `workers` rows, no empty row. SC8: heaviest first, each cell (or
|
|
43
|
+
* group that shares a worker) goes to the row whose awake cost is lowest so far (fewest cells on a tie, then the first row), so the
|
|
44
|
+
* busiest worker carries as little awake cost as the cells allow. One cell is one worker; GC31: one worker holds every cell. A crossing
|
|
45
|
+
* between workers is GC15's move, so no cell needs a neighbour's worker.
|
|
31
46
|
*/
|
|
32
47
|
export function workerTable(cells: readonly string[], workers: number): readonly (readonly string[])[] {
|
|
33
|
-
const open = new Set(cells),
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
const open = [...new Set(cells)].sort(), grouped = new Set(TOGETHER.flat());
|
|
49
|
+
const units = [...TOGETHER.map(group => group.filter(slug => open.includes(slug))).filter(group => group.length > 0), ...open.filter(slug => !grouped.has(slug)).map(slug => [slug])];
|
|
50
|
+
const weight = (unit: readonly string[]): number => unit.reduce((total, slug) => total + cellCost(slug), 0);
|
|
51
|
+
if (units.length === 0) return [];
|
|
52
|
+
units.sort((a, b) => weight(b) - weight(a) || (a[0] ?? '').localeCompare(b[0] ?? ''));
|
|
53
|
+
const rows = Array.from({ length: Math.max(1, Math.min(workers, units.length)) }, () => ({ cells: [] as string[], cost: 0 }));
|
|
54
|
+
for (const unit of units) {
|
|
55
|
+
const row = rows.reduce((best, next) => (next.cost < best.cost || (next.cost === best.cost && next.cells.length < best.cells.length) ? next : best));
|
|
56
|
+
row.cells.push(...unit); row.cost += weight(unit);
|
|
57
|
+
}
|
|
58
|
+
return rows.map(row => row.cells);
|
|
41
59
|
}
|
|
@@ -21,6 +21,7 @@ import {CorrectionSchema} from '@wildshard/engine/net/measurements';
|
|
|
21
21
|
import type {PlaytestRow} from './playtest';
|
|
22
22
|
import type { ChatReport } from '@wildshard/engine/net/chat';
|
|
23
23
|
import type { CellOrder, ResumeAt, SavedCheckpoint, SeatEntry, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
24
|
+
import type { MotionSnapshot } from '@wildshard/engine/game/grid/simulation';
|
|
24
25
|
import { bodyId } from './seats';
|
|
25
26
|
import { SaveNewerError, type PlayerDoc } from './playerDoc';
|
|
26
27
|
import { LEAVE_FLAG, LEFT, pumpSocket } from './socketPump';
|
|
@@ -107,8 +108,12 @@ export interface WorldOptions {
|
|
|
107
108
|
readonly crashed: (error: unknown) => void;
|
|
108
109
|
/** The grace ran out: stop, and let systemd start what is on disk. */
|
|
109
110
|
readonly restart: () => void;
|
|
110
|
-
/** One worker's 10 s reading, for what leaves the box (E7.8a). */
|
|
111
|
+
/** One worker's 10 s reading, for what leaves the box (E7.8a) and `/metrics` (SC1). */
|
|
111
112
|
readonly reading?: (index: number, reading: WorkerReading) => void;
|
|
113
|
+
/** SERVER-CELLS SC1: a cell (or a worker's road) opened in `ms`, as `cell.booted` logs it. */
|
|
114
|
+
readonly booted?: (index: number, slug: string, ms: number) => void;
|
|
115
|
+
/** SC1: a crossing's time from its source's ask to its worker's answer, and whether the seat moved. */
|
|
116
|
+
readonly crossed?: (ms: number, moved: boolean) => void;
|
|
112
117
|
readonly playtest?:(row:PlaytestRow)=>void;
|
|
113
118
|
/** J218: the ICE servers voice chat hands a player who joins; public STUN when absent. */
|
|
114
119
|
readonly voiceIce?: () => Promise<readonly VoiceIceServer[]>;
|
|
@@ -158,8 +163,14 @@ export class World {
|
|
|
158
163
|
private readonly voiceBodies = new Map<string, (body: string) => void>();
|
|
159
164
|
private readonly finds = new Map<number, (found: { held: boolean; spawn: ResumeAt }) => void>();
|
|
160
165
|
private readonly drains = new Map<number, () => void>();
|
|
161
|
-
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered. */
|
|
162
|
-
private readonly crossings = new
|
|
166
|
+
/** GC15: devices whose crossing the door is reading a save for, or whose `cross` order a worker has not answered, and when it began (SC1). */
|
|
167
|
+
private readonly crossings = new Map<string, number>();
|
|
168
|
+
/** GC15 (3): each seated device's socket and a copy of the hello it was seated with, so a crossing onto another worker can move both. */
|
|
169
|
+
private readonly seatSockets = new Map<string, { readonly end: SocketTransport; readonly hello: ArrayBuffer }>();
|
|
170
|
+
/** GC15 (3): a crossing onto another worker, between the source's `handOut` and the socket's `out`: where it arrives and with what save. */
|
|
171
|
+
private readonly outs = new Map<string, { readonly from: string; readonly to: string; readonly at: ResumeAt; readonly entry: SeatEntry }>();
|
|
172
|
+
/** GC15 (3): each worker's grid cells whose entryways stand, as its `booted` said. */
|
|
173
|
+
private readonly stands = new Map<WorkerLink, readonly string[]>();
|
|
163
174
|
/** GC15: devices whose source said `left` while their crossing was in flight: applied if the crossing is abandoned before `cross`. */
|
|
164
175
|
private readonly leftCrossing = new Set<string>();
|
|
165
176
|
private asked = 0;
|
|
@@ -201,7 +212,7 @@ export class World {
|
|
|
201
212
|
this.options.crashed(new Error(reason));
|
|
202
213
|
};
|
|
203
214
|
link.listen(news => {
|
|
204
|
-
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
215
|
+
if (news.kind === 'booted') { up = true; this.up.add(link); if (news.resident !== undefined) this.resident.set(link, news.resident); if (news.stands !== undefined) { this.stands.set(link, news.stands); this.openRoads(); } if (late) for (const slug of slugs) this.links.set(slug, link); this.options.log({ at: 'worker.booted', index, slugs, ms: news.ms }); resolve(); }
|
|
205
216
|
else if (news.kind === 'failed') ended(news.reason); else this.heard(index, news);
|
|
206
217
|
}, ended);
|
|
207
218
|
});
|
|
@@ -256,7 +267,7 @@ export class World {
|
|
|
256
267
|
else if (news.kind === 'report') { if (!this.options.saves.report(news.report, cellShard(news.slug))) this.refuse('report-backlog'); }
|
|
257
268
|
else if (news.kind === 'chat') { for (const link of this.workers) link.send({ kind: 'chat', from: news.slug, line: news.line }); }
|
|
258
269
|
else if(news.kind==='playtest')this.options.playtest?.(news.row);
|
|
259
|
-
else if (news.kind === 'cell') this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms });
|
|
270
|
+
else if (news.kind === 'cell') { this.options.log({ at: 'cell.booted', index, slug: news.slug, ms: news.ms }); this.options.booted?.(index, news.slug, news.ms); }
|
|
260
271
|
else if (news.kind === 'reading') { this.options.log({ at: 'worker', index, ...news.reading, refusals: this.refusals, connections: this.connectionStats, saves: this.options.saves.stats?.() }); this.options.reading?.(index, news.reading); }
|
|
261
272
|
else if (news.kind === 'placed') {
|
|
262
273
|
const link = this.workers[index];
|
|
@@ -267,7 +278,10 @@ export class World {
|
|
|
267
278
|
}
|
|
268
279
|
else if (news.kind === 'drained') { this.drains.get(index)?.(); this.drains.delete(index); }
|
|
269
280
|
else if (news.kind === 'crossing') void this.crossing(news.slug, news.device, news.to, news.at);
|
|
281
|
+
else if (news.kind === 'handedOut') { if (!news.out && this.outs.get(news.device)?.from === news.from) { this.outs.delete(news.device); this.abandon(news.device, news.from); } }
|
|
270
282
|
else if (news.kind === 'crossed') {
|
|
283
|
+
const begun = this.crossings.get(news.device);
|
|
284
|
+
if (begun !== undefined) this.options.crossed?.(diagnosticNow() - begun, news.moved);
|
|
271
285
|
this.crossings.delete(news.device); this.leftCrossing.delete(news.device);
|
|
272
286
|
// A moved seat stands in the target, on the same link; one the target refused after the source let it go is in neither.
|
|
273
287
|
if (this.seated.get(news.device) === news.from) {
|
|
@@ -363,6 +377,13 @@ export class World {
|
|
|
363
377
|
/** Everyone in the grid or on their way: the cap counts all of them, whichever cell they stand in (J182). */
|
|
364
378
|
private get taken(): number { return this.seated.size + this.pending.size; }
|
|
365
379
|
/** The worker a cell runs on, or (GC15) whose road a name is. */
|
|
380
|
+
/** GC15 (3): every worker's road hears which cells on the other workers a walker can stand in, and drops its walls round them. */
|
|
381
|
+
private openRoads(): void {
|
|
382
|
+
for (const link of this.up) {
|
|
383
|
+
const cells = [...this.stands].filter(([other]) => other !== link && this.up.has(other)).flatMap(([, list]) => list);
|
|
384
|
+
if (cells.length > 0) link.send({ kind: 'open', cells });
|
|
385
|
+
}
|
|
386
|
+
}
|
|
366
387
|
private linkOf(slug: string): WorkerLink | undefined { return this.links.get(roadHome(slug) ?? slug); }
|
|
367
388
|
private link(slug: string): WorkerLink {
|
|
368
389
|
const link = this.linkOf(slug);
|
|
@@ -443,8 +464,10 @@ export class World {
|
|
|
443
464
|
*/
|
|
444
465
|
private async crossing(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
445
466
|
const link = this.linkOf(to), name = this.names.get(device);
|
|
467
|
+
// GC15 (3): from a worker's road into a cell another worker hosts
|
|
468
|
+
if (link !== undefined && link !== this.linkOf(from) && roadHome(from) !== null && roadHome(to) === null) { await this.crossWorkers(from, device, to, at); return; }
|
|
446
469
|
if (link === undefined || link !== this.linkOf(from) || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device)) return;
|
|
447
|
-
this.crossings.
|
|
470
|
+
this.crossings.set(device, diagnosticNow());
|
|
448
471
|
try {
|
|
449
472
|
// The road keeps no progress: a seat walks onto it with nothing to read.
|
|
450
473
|
const saved: SavedPlayer = roadHome(to) === null ? await this.options.saves.read(device, cellShard(to)) : { doc: null, seq: 0 };
|
|
@@ -453,6 +476,32 @@ export class World {
|
|
|
453
476
|
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) });
|
|
454
477
|
} catch (error) { this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
455
478
|
}
|
|
479
|
+
/**
|
|
480
|
+
* GC15 (3): a seat on one worker's road walks into a cell on another worker. The door reads their save on that cell's shard, the road
|
|
481
|
+
* sends the client `travel` and lets the seat go (`handOut`), and when its port says `out` the door points the same socket at a new port
|
|
482
|
+
* into the target's worker, which seats them at `at` and hears their hello again (`arrive`). The socket never closes.
|
|
483
|
+
*/
|
|
484
|
+
private async crossWorkers(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
485
|
+
const source = this.linkOf(from), name = this.names.get(device);
|
|
486
|
+
if (source === undefined || this.seated.get(device) !== from || name === undefined || this.draining || this.crossings.has(device) || !this.seatSockets.has(device)) return;
|
|
487
|
+
this.crossings.set(device, diagnosticNow());
|
|
488
|
+
try {
|
|
489
|
+
const saved = await this.options.saves.read(device, cellShard(to));
|
|
490
|
+
if (this.seated.get(device) !== from || this.draining || !this.seatSockets.has(device)) { this.abandon(device, from); return; }
|
|
491
|
+
this.outs.set(device, { from, to, at, entry: { device, name, body: bodyId(this.options.secret, device), doc: saved.doc, seq: saved.seq,
|
|
492
|
+
...(saved.recovery === undefined ? {} : { recovery: saved.recovery }), ...(saved.previous === undefined ? {} : { previous: saved.previous }) } });
|
|
493
|
+
source.send({ kind: 'handOut', from, device, to });
|
|
494
|
+
} catch (error) { this.outs.delete(device); this.abandon(device, from); this.options.log({ at: 'cell.cross-refused', device, from, to, reason: String(error) }); }
|
|
495
|
+
}
|
|
496
|
+
/** GC15 (3): the source let the seat go and everything it said is on its way: the socket now pumps into the target's worker. */
|
|
497
|
+
private movedOut(device: string, end: SocketTransport, motion: unknown): void {
|
|
498
|
+
const out = this.outs.get(device), kept = this.seatSockets.get(device), link = out === undefined ? undefined : this.linkOf(out.to);
|
|
499
|
+
this.outs.delete(device);
|
|
500
|
+
if (out === undefined || kept?.end !== end || link === undefined || !end.isOpen || this.draining) { this.abandon(device, out?.from ?? ''); end.close(this.draining ? 'restart' : 'retry'); return; }
|
|
501
|
+
const { port1, port2 } = new MessageChannel(), hello = kept.hello.slice(0);
|
|
502
|
+
pumpSocket(end, port1, undefined, next => { this.movedOut(device, end, next); });
|
|
503
|
+
link.send({ kind: 'arrive', from: out.from, to: out.to, at: out.at, port: port2, hello, motion: motion as MotionSnapshot | null, ...out.entry }, [port2, hello]);
|
|
504
|
+
}
|
|
456
505
|
/** A crossing that never reached its worker: a `left` the source said meanwhile counts now. */
|
|
457
506
|
private abandon(device: string, from: string): void {
|
|
458
507
|
this.crossings.delete(device);
|
|
@@ -479,7 +528,16 @@ export class World {
|
|
|
479
528
|
});
|
|
480
529
|
end.onClose(off);end.control('playtest');
|
|
481
530
|
}
|
|
482
|
-
|
|
531
|
+
this.seatSockets.set(entry.device, { end, hello: hello.slice(0) });
|
|
532
|
+
end.onClose(() => {
|
|
533
|
+
if (this.seatSockets.get(entry.device)?.end !== end) return;
|
|
534
|
+
this.seatSockets.delete(entry.device);
|
|
535
|
+
// GC15 (3), review MUST: the socket went while a crossing onto another worker waited for its `out`, which this close swallowed:
|
|
536
|
+
// the crossing is off, and a `left` the road said (or says next) frees the seat
|
|
537
|
+
const out = this.outs.get(entry.device);
|
|
538
|
+
if (out !== undefined) { this.outs.delete(entry.device); this.abandon(entry.device, out.from); }
|
|
539
|
+
});
|
|
540
|
+
pumpSocket(end, port1, undefined, motion => { this.movedOut(entry.device, end, motion); });
|
|
483
541
|
const rebody = this.voice.attach(end, slug, entry.name, entry.body);
|
|
484
542
|
this.voiceBodies.set(entry.device, rebody);
|
|
485
543
|
end.onClose(() => { if (this.voiceBodies.get(entry.device) === rebody) this.voiceBodies.delete(entry.device); });
|
|
@@ -14,7 +14,7 @@ import { createHash } from 'node:crypto';
|
|
|
14
14
|
import { pathToFileURL } from 'node:url';
|
|
15
15
|
import { validateShardfileAssets } from '@wildshard/format/assetAdmission';
|
|
16
16
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
17
|
-
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/
|
|
17
|
+
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
18
18
|
import { TickWorkerHost } from './tickWorkerHost';
|
|
19
19
|
import { AuthorProofPlanSchema, TickCommandSchema, type HeadlessCommand, type AuthorProofPlan, type AuthorProofReport, type HeadlessCommandSource, type HeadlessTickCommit, type HeadlessTapePartReport } from '../../shared/host/tickProtocol';
|
|
20
20
|
import * as v from 'valibot';
|
|
@@ -3,7 +3,7 @@ import * as v from 'valibot';
|
|
|
3
3
|
import { runHeadlessJourney } from '../../shared/host/headlessJourney';
|
|
4
4
|
import { registerNativeQuestInputs } from '@wildshard/engine/game/quest/nativeInputs';
|
|
5
5
|
import { hasDeclaredClientPage } from '@wildshard/format/runtimeBinds';
|
|
6
|
-
import { prepareAssetDecoders } from '@wildshard/format/
|
|
6
|
+
import { prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
7
7
|
import { parseNativeRuntimePlan } from '@wildshard/format/nativeRuntimePlan';
|
|
8
8
|
import { MoverScriptDriver, type MoverRuntime } from '@wildshard/engine/game/plugin/mover';
|
|
9
9
|
import { installRopeDecks } from './ropeDecks';
|
|
@@ -23,19 +23,31 @@ const WALL = 0.5, WALL_HEIGHT = 30;
|
|
|
23
23
|
const WALL_OFF = 2;
|
|
24
24
|
export const ROAD: SimLevel = { version: SIM_API_VERSION, id: 'grid-road', seed: 1, ground: { size: ROAD_HALF_SIZE * 2, height: FALL_FLOOR }, player: { at: { x: 0, y: 0, z: 0 }, yaw: 0, speed: ROAD_SPEED }, entities: [], quests: [], weapon: HOST_PROBE };
|
|
25
25
|
|
|
26
|
+
/** Each road world's cell walls, by the cell they stand round, so GC15 (3) can open one a walker can now cross into. */
|
|
27
|
+
const walls = new WeakMap<SimHost, Map<string, Collider[]>>();
|
|
26
28
|
/**
|
|
27
29
|
* A wall around every cell in the road's own world, as the page's readiness walls are while a cell loads. A player stops just short of
|
|
28
30
|
* a cell until its world is ready and the crossing takes them in, 6 m out at most; the road never runs on under a cell's own
|
|
29
31
|
* hills, where a late hand-off would set them down inside one. A cell's terrain can end in a bank above road level at its very edge,
|
|
30
32
|
* and a capsule set down touching that bank stays stuck in it, so the wall stands clear of it.
|
|
31
33
|
*/
|
|
32
|
-
export function addCellWalls(road: SimHost, cells: readonly Pick<GridCell, 'origin'>[]): void {
|
|
34
|
+
export function addCellWalls(road: SimHost, cells: readonly (Pick<GridCell, 'origin'> & { readonly instance?: string })[]): void {
|
|
33
35
|
const { R, world } = road.physics, reach = CHUNK_HALF + WALL_OFF + WALL / 2, long = reach + WALL / 2;
|
|
36
|
+
const kept = walls.get(road) ?? new Map<string, Collider[]>();
|
|
37
|
+
walls.set(road, kept);
|
|
34
38
|
withOwner(road.scope, () => {
|
|
35
|
-
for (const { origin } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const)
|
|
36
|
-
world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
39
|
+
for (const { origin, instance } of cells) for (const [x, z, hx, hz] of [[reach, 0, WALL / 2, long], [-reach, 0, WALL / 2, long], [0, reach, long, WALL / 2], [0, -reach, long, WALL / 2]] as const) {
|
|
40
|
+
const collider = world.createCollider(R.ColliderDesc.cuboid(hx, WALL_HEIGHT, hz).setTranslation(origin.x + x, WALL_HEIGHT, origin.z + z).setCollisionGroups(groups('WORLD')));
|
|
41
|
+
if (instance !== undefined) kept.set(instance, [...kept.get(instance) ?? [], collider]);
|
|
42
|
+
}
|
|
37
43
|
});
|
|
38
44
|
}
|
|
45
|
+
/** GC15 (3): take down the walls round these cells (on another worker, their entryways standing): the road crosses into them now. */
|
|
46
|
+
export function openCellWalls(road: SimHost, instances: readonly string[]): void {
|
|
47
|
+
const kept = walls.get(road);
|
|
48
|
+
if (kept === undefined) return;
|
|
49
|
+
for (const instance of instances) { for (const collider of kept.get(instance) ?? []) if (collider.isValid()) road.physics.world.removeCollider(collider, false); kept.delete(instance); }
|
|
50
|
+
}
|
|
39
51
|
/** Each road world's void floor colliders, so a placement can lift them (SA34a). */
|
|
40
52
|
const floors = new WeakMap<SimHost, readonly Collider[]>();
|
|
41
53
|
/** SA34: the 7 × 7's void, walkable: a road-level floor over every empty cell and out to the rail, and the rim on the rail. */
|