@wildshard/engine 0.1.15 → 0.1.17
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 +15 -0
- package/index.html +157 -11
- package/lint/engine-sides.json +16 -0
- package/lint/host-register.json +496 -0
- package/lint/ratchet.json +2 -2
- package/lint/shard-imports.d.mts +1 -0
- package/lint/shard-imports.mjs +56 -8
- package/lint/wildshard-plugin.js +22 -4
- package/package.json +16 -5
- package/scripts/app-build/buildIdentity.d.mts +3 -1
- package/scripts/app-build/buildIdentity.mjs +25 -5
- package/scripts/app-build/builtAt.d.mts +4 -0
- package/scripts/app-build/builtAt.mjs +21 -0
- package/scripts/app-build/serviceWorker.ts +16 -2
- package/scripts/app-build/versionFiles.ts +2 -1
- package/scripts/app-build-pipeline.mjs +4 -1
- package/scripts/audio-download-proof.mjs +843 -0
- package/scripts/build-app.mjs +4 -0
- package/scripts/build-mirror.d.mts +2 -0
- package/scripts/build-mirror.mjs +5 -4
- package/scripts/built-product.mjs +3 -3
- package/scripts/cell-mem/metrics-preload.mjs +65 -0
- package/scripts/cell-mem-bench.mjs +130 -0
- package/scripts/check-chunks.mjs +2 -1
- package/scripts/devserver-client.d.mts +5 -0
- package/scripts/devserver-client.mjs +68 -0
- package/scripts/engine-ci-budget.ts +7 -1
- package/scripts/format-lock.mjs +20 -11
- package/scripts/generate-title-launch.mjs +3 -2
- package/scripts/grid-crossing-walk-proof.mjs +16 -8
- package/scripts/heavy-lane.py +25 -1
- package/scripts/host-ruler/register-migrate.mjs +242 -0
- package/scripts/host-ruler/register.d.mts +36 -0
- package/scripts/host-ruler/register.mjs +116 -0
- package/scripts/host-ruler/roots.d.mts +29 -0
- package/scripts/host-ruler/roots.mjs +333 -0
- package/scripts/host-ruler/server-roots.d.mts +23 -0
- package/scripts/host-ruler/server-roots.mjs +272 -0
- package/scripts/main-watch.d.mts +1 -1
- package/scripts/main-watch.mjs +10 -6
- package/scripts/map-hash.mjs +3 -6
- package/scripts/mmo-bots.mjs +2 -2
- package/scripts/offline-proof-rules.d.mts +1 -0
- package/scripts/offline-proof-rules.mjs +22 -1
- package/scripts/online-rig.mjs +4 -4
- package/scripts/page-release/flow.d.mts +1 -0
- package/scripts/page-release/flow.mjs +6 -2
- package/scripts/page-release.mjs +5 -1
- package/scripts/physics-route.json +0 -71
- package/scripts/pins-catalogue.ts +103 -0
- package/scripts/pins-reuse.mjs +3 -1
- package/scripts/pins.ts +22 -14
- package/scripts/preview-grid.ts +203 -0
- package/scripts/road-preload-proof.mjs +167 -0
- package/scripts/server-release/publish.mjs +2 -2
- package/scripts/server-release/served-slug.d.mts +2 -0
- package/scripts/server-release/served-slug.mjs +10 -0
- package/scripts/server-release/sign.d.mts +1 -0
- package/scripts/server-release/sign.mjs +3 -7
- package/scripts/shard-components.mjs +0 -2
- package/scripts/shard-outputs.d.mts +8 -0
- package/scripts/shard-outputs.mjs +45 -11
- package/scripts/side-parity.d.mts +2 -1
- package/scripts/side-parity.mjs +25 -4
- package/scripts/test-amber.d.mts +1 -0
- package/scripts/test-amber.mjs +10 -0
- package/scripts/test-products.json +3 -3
- package/scripts/tracked-public.d.mts +1 -0
- package/scripts/tracked-public.mjs +17 -0
- package/src/cli/engine.mjs +8 -0
- package/src/client/app/bootRoute.ts +4 -1
- package/src/client/app/dropModal.ts +15 -2
- package/src/client/app/entry.ts +67 -11
- package/src/client/app/slugPath.ts +5 -0
- package/src/client/engine/audio/Audio.ts +20 -2
- package/src/client/engine/boot/bakedTextures.ts +3 -2
- package/src/client/engine/boot/bootTrace.ts +6 -1
- package/src/client/engine/boot/bytes.ts +4 -3
- package/src/client/engine/boot/clearDownloads.ts +1 -1
- package/src/client/engine/boot/contentRead.ts +4 -0
- package/src/client/engine/boot/dropNotice.ts +20 -6
- package/src/client/engine/boot/gpuFiles.ts +25 -2
- package/src/client/engine/boot/lastEnd.ts +8 -2
- package/src/client/engine/boot/shardPrefetch.ts +7 -1
- package/src/client/engine/boot/sw.ts +19 -0
- package/src/client/engine/core/Game.ts +11 -3
- package/src/client/engine/core/GpuRecovery.ts +7 -0
- package/src/client/engine/core/Volumetrics.ts +5 -0
- package/src/client/engine/core/assets.ts +27 -20
- package/src/client/engine/core/bootstrap.ts +1 -2
- package/src/client/engine/core/ktx2.ts +84 -11
- package/src/client/engine/explore/Compare.ts +2 -2
- package/src/client/engine/explore/TouchFly.ts +3 -5
- package/src/client/engine/input/dom.ts +12 -0
- package/src/client/engine/net/predictor.ts +6 -2
- package/src/client/engine/player/Player.ts +10 -2
- package/src/client/engine/player/TouchControls.ts +12 -4
- package/src/client/engine/pwa/sw.js +47 -8
- package/src/client/engine/render/drawCheck.ts +96 -0
- package/src/client/engine/saves/staleBuildNote.ts +46 -0
- package/src/client/engine/telemetry/browserErrors.ts +157 -20
- package/src/client/engine/telemetry/screenOutbox.ts +61 -0
- package/src/client/engine/telemetry/staleBuildReport.ts +12 -0
- package/src/client/engine/ui/DeathFade.ts +99 -11
- package/src/client/engine/ui/ErrorModal.ts +13 -6
- package/src/client/engine/ui/Feedback.ts +2 -1
- package/src/client/engine/ui/Loading.ts +10 -6
- package/src/client/engine/ui/Map.ts +2 -1
- package/src/client/engine/ui/WeaponStrip.ts +2 -1
- package/src/client/engine/ui/backGuard.ts +104 -0
- package/src/client/engine/ui/hudAdapters.ts +30 -4
- package/src/client/engine/ui/loading.css +17 -0
- package/src/client/engine/ui/namePrompt.ts +6 -5
- package/src/client/engine/ui/styles/combat.css +12 -0
- package/src/client/engine/ui/styles/namePrompt.css +4 -2
- package/src/client/game/boot/audio.generated.ts +0 -294
- package/src/client/game/boot/bytes.generated.ts +0 -11
- package/src/client/game/boot/versions.generated.ts +0 -11
- package/src/client/game/compendium/keepsakes.ts +16 -6
- package/src/client/game/grapple/tool.ts +10 -7
- package/src/client/game/grid/cellLoading.ts +23 -12
- package/src/client/game/grid/cellScreens.ts +39 -74
- package/src/client/game/grid/liveSession.ts +40 -7
- package/src/client/game/grid/nearPlaceholderPlan.ts +8 -0
- package/src/client/game/grid/nearPlaceholderView.ts +9 -3
- package/src/client/game/grid/oneWayIn.ts +92 -27
- package/src/client/game/grid/pageEntry.ts +19 -0
- package/src/client/game/grid/pageShell.ts +1 -1
- package/src/client/game/grid/plotAudio.ts +114 -0
- package/src/client/game/grid/products.ts +55 -5
- package/src/client/game/grid/roadLookPlatform.ts +2 -2
- package/src/client/game/grid/session.ts +38 -22
- package/src/client/game/grid/spawnGround.ts +68 -0
- package/src/client/game/grid/voidLook.ts +29 -23
- package/src/client/game/loot/runtime.ts +3 -1
- package/src/client/game/mainMenu.ts +14 -6
- package/src/client/game/riding/hud.ts +6 -4
- package/src/client/game/session/finish.ts +17 -3
- package/src/client/game/session/play.ts +8 -2
- package/src/client/game/session/session.ts +4 -1
- package/src/client/game/shardfile/clientWorker.ts +41 -12
- package/src/client/game/shardfile/serverRoute.ts +10 -22
- package/src/client/game/slugPage.css +11 -0
- package/src/client/game/slugPage.ts +84 -0
- package/src/client/game/systems/viewmodel/heldView.ts +6 -3
- package/src/client/game/titleDeck.ts +55 -32
- package/src/client/host/online/doctor.ts +7 -6
- package/src/client/host/online/linkScreens.ts +16 -0
- package/src/client/host/online/release.ts +51 -5
- package/src/client/host/online/shell.ts +48 -27
- package/src/client/host/standalone/shell.ts +7 -3
- package/src/cook/game/audioReport.ts +57 -0
- package/src/cook/game/entryTotals.ts +26 -6
- package/src/cook/game/installedRuntimeReads.ts +3 -0
- package/src/server/engine/sim/respawn.ts +6 -1
- package/src/server/engine/sim.ts +3 -0
- package/src/server/game/grid/simulation.ts +35 -0
- package/src/server/game/loot/harvest.ts +2 -0
- package/src/server/game/loot/keepsakeProgression.ts +40 -0
- package/src/server/game/loot/playerOwned.ts +5 -1
- package/src/server/game/plugin/simulation.ts +4 -0
- package/src/server/game/population/nativeBake.ts +2 -1
- package/src/server/game/quest/chapterRecords.ts +2 -0
- package/src/server/game/quest/serverChapters.ts +4 -0
- package/src/server/game/quest/serverDoors.ts +11 -5
- package/src/server/game/roomRespawn.ts +4 -0
- package/src/server/game/shardfile/installedSides.ts +18 -0
- package/src/server/game/shardfile/nativeAssemblyHosts.ts +19 -10
- package/src/server/game/shardfile/nativeAssemblyInput.ts +1 -4
- package/src/server/host/bake/headlessWorker.ts +5 -1
- package/src/server/host/dedicated/cellHost.ts +98 -29
- package/src/server/host/dedicated/cellProtocol.ts +11 -1
- package/src/server/host/dedicated/cellWorker.ts +9 -3
- package/src/server/host/dedicated/crossing.ts +6 -2
- package/src/server/host/dedicated/dedicatedRoom.ts +21 -8
- package/src/server/host/dedicated/gridCells.ts +52 -9
- package/src/server/host/dedicated/main.ts +31 -12
- package/src/server/host/dedicated/placementFile.ts +72 -0
- package/src/server/host/dedicated/releaseFile.ts +17 -10
- package/src/server/host/dedicated/roadRoom.ts +21 -5
- package/src/server/host/dedicated/workerTable.ts +13 -1
- package/src/server/host/dedicated/world.ts +81 -9
- package/src/server/host/headlessRuntime.ts +10 -5
- package/src/server/host/installers.ts +62 -0
- package/src/server/host/openWorld.ts +59 -0
- package/src/server/host/ropeDecks.ts +2 -0
- package/src/server/host/standalone/cellWorld.ts +25 -19
- package/src/server/host/standalone/fallFloor.ts +2 -2
- package/src/server/host/standalone/gridServer.ts +7 -4
- package/src/server/host/standalone/roadWorld.ts +41 -4
- package/src/shared/engine/audio/bootAudio.ts +33 -0
- package/src/shared/engine/level/spec.ts +3 -3
- package/src/shared/engine/net/acts.ts +3 -0
- package/src/shared/engine/physics/query.ts +27 -0
- package/src/shared/engine/physics/terrain.ts +19 -28
- package/src/shared/engine/saves/saves.lock.json +15 -0
- package/src/shared/engine/sim/actRoutes.ts +2 -0
- package/src/shared/game/compendium/keepsakeProgression.ts +24 -0
- package/src/shared/game/grid/catalogue.ts +12 -5
- package/src/shared/game/grid/catalogueSlot.ts +11 -0
- package/src/shared/game/grid/farProxy.ts +6 -5
- package/src/shared/game/grid/pageMode.ts +1 -1
- package/src/shared/game/grid/roadLayout.ts +26 -3
- package/src/shared/game/grid/singleplayer.json +0 -13
- package/src/shared/game/grid/voidFloor.ts +122 -0
- package/src/shared/game/strings.ts +15 -0
- package/src/shared/host/standalone/netInput.ts +2 -1
|
@@ -3,6 +3,7 @@ import '@wildshard/engine/core/portableMathFirst';
|
|
|
3
3
|
import {createTrustedHeadlessTape} from '../../../shared/host/headlessTape';
|
|
4
4
|
import { runHeadlessJourney } from '../../../shared/host/headlessJourney';
|
|
5
5
|
import { proveShardfileEntries } from '@wildshard/engine/game/bake/entryways';
|
|
6
|
+
import { openWorldAdapter } from '../openWorld';
|
|
6
7
|
import { createTrustedHeadlessAdapter } from '../headlessRuntime';
|
|
7
8
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
8
9
|
// oxlint-disable-next-line import/no-nodejs-modules -- Only the platform-selected physics binary is read inside the isolated worker.
|
|
@@ -34,8 +35,11 @@ await runTickWorker(async raw => {
|
|
|
34
35
|
if (payload.product !== undefined) {
|
|
35
36
|
// A native assembly's server-class files live only in the built product, never in the client's sections or assets.
|
|
36
37
|
const { loadHeadlessProduct } = await import('../headlessProduct');
|
|
37
|
-
return
|
|
38
|
+
return openWorldAdapter({ shard, assets: payload.assets, rapier, product: await loadHeadlessProduct(payload.product) }, payload.snapshot);
|
|
38
39
|
}
|
|
40
|
+
// SERVER-PARITY HS1 left: a runtime plan carried as sections, with no product, still ticks the bare resident. Far Reach's and
|
|
41
|
+
// Dunes' proof witnesses build their checkpoints that way; moving it to `openWorldAdapter` re-records them.
|
|
42
|
+
// oxlint-disable-next-line typescript/no-deprecated -- HS1 left, above
|
|
39
43
|
if (sections.has('sim/runtime-plan')) return createTrustedHeadlessAdapter({ shard, assets: payload.assets, rapier, sections }, payload.snapshot);
|
|
40
44
|
let commands: ReadonlyMap<string, number> = new Map();
|
|
41
45
|
let effects: HeadlessEffect[] = [];
|
|
@@ -4,15 +4,16 @@ import { installAppIdentity } from '@wildshard/engine/app/identity';
|
|
|
4
4
|
import { Scope } from '@wildshard/engine/app/scope';
|
|
5
5
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
6
6
|
import { ServerClock } from '@wildshard/engine/net/serverClock';
|
|
7
|
-
import { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
7
|
+
import type { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
8
8
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
9
9
|
import type { Rapier } from '@wildshard/engine/physics/rapier';
|
|
10
10
|
import { DedicatedRoom, type DedicatedRoomRoad } from './dedicatedRoom';
|
|
11
|
-
import { cellShard, roadName } from './gridCells';
|
|
11
|
+
import { cellShard, gridAssembly, placeCell, roadName } from './gridCells';
|
|
12
12
|
import { RoadRoom } from './roadRoom';
|
|
13
|
+
import { placedStrips } from '@wildshard/engine/game/grid/voidFloor';
|
|
13
14
|
import { openRoad } from '../standalone/roadWorld';
|
|
14
15
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
15
|
-
import type { CellOrder, WorkerNews, WorkerReading } from './cellProtocol';
|
|
16
|
+
import type { CellOrder, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
16
17
|
import { SeatTransport } from './socketPump';
|
|
17
18
|
|
|
18
19
|
/** How often a worker reads itself (E7.8). */
|
|
@@ -21,7 +22,7 @@ const READING_MS = 10_000;
|
|
|
21
22
|
const TICKS_KEPT = 720;
|
|
22
23
|
/** The save prefix a cell's stores share. Nothing outside a cell ever reads it. */
|
|
23
24
|
const SAVE_PREFIX = 'wildshard.room.';
|
|
24
|
-
/** J107: a cell left empty this long
|
|
25
|
+
/** J107: a cell everyone left starts over once it has stood empty this long, on its own timer, before anyone comes back (J320). */
|
|
25
26
|
const EMPTY_MS = 300_000;
|
|
26
27
|
|
|
27
28
|
/** A port as `worker_threads` and a `MessageChannel` both give it. */
|
|
@@ -46,12 +47,15 @@ export interface CellHostOptions {
|
|
|
46
47
|
readonly playtest?:boolean;
|
|
47
48
|
/**
|
|
48
49
|
* GC15 (`WORLD_CROSSING=worker`): the grid pack's road strips. Given, this worker hosts the road between its cells, each of its grid
|
|
49
|
-
* cells opens onto it instead of standing in lone walls, and a seat walks cell, road, cell on one socket. Left out, every cell is lone.
|
|
50
|
+
* cells opens onto it instead of standing in lone walls, and a seat walks cell, road, cell on one socket. Left out, or no strips, every cell is lone.
|
|
50
51
|
*/
|
|
51
52
|
readonly road?: () => Promise<readonly GridCollisionStrip[]>;
|
|
52
53
|
}
|
|
53
|
-
/**
|
|
54
|
-
|
|
54
|
+
/**
|
|
55
|
+
* One cell, and when it last emptied. A cell with nobody in it takes no ticks: that is all sleep is (Q80). Its world, colliders and sim stay
|
|
56
|
+
* in memory from the worker's boot (J320). `used`: someone stood in this world since it booted, so it has something to start over from.
|
|
57
|
+
*/
|
|
58
|
+
interface Cell { readonly slug: string; room: DedicatedRoom; emptySince: number; used: boolean; waking: Promise<void> | null }
|
|
55
59
|
const percentile = (sorted: readonly number[], at: number): number => sorted[Math.min(sorted.length - 1, Math.floor(sorted.length * at))] ?? 0;
|
|
56
60
|
|
|
57
61
|
/** A worker has no page, so no app identity: all it needs of one is the save prefix. */
|
|
@@ -66,19 +70,37 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
66
70
|
const post = (news: WorkerNews): void => { port.postMessage(news); };
|
|
67
71
|
const fail = (error: unknown): void => { clock?.pause(); post({ kind: 'failed', reason: error instanceof Error ? error.message : String(error) }); };
|
|
68
72
|
// GC15: the road this worker hosts, once its cells are open, and what its cells need of it.
|
|
69
|
-
|
|
73
|
+
// SA34a: `seams` are placed cells' own copies of the pack's strips beside them, which the pack baked with no row for a cell it never saw.
|
|
74
|
+
let road: RoadRoom | undefined, rapier: Rapier | undefined, crossing: { readonly name: string; readonly assembly: GridAssembly; readonly strips: readonly GridCollisionStrip[]; readonly seams: readonly GridCollisionStrip['duplicates'][number][] } | undefined;
|
|
70
75
|
const seams = (instance: string): DedicatedRoomRoad | undefined => {
|
|
71
76
|
if (crossing === undefined || !crossing.assembly.cells.some(cell => cell.instance === instance)) return undefined;
|
|
72
|
-
return { name: crossing.name, assembly: crossing.assembly, seams: crossing.strips.flatMap(strip => strip.duplicates.filter(row => row.instance === instance).map(row => row.mesh)
|
|
77
|
+
return { name: crossing.name, assembly: crossing.assembly, seams: [...crossing.strips.flatMap(strip => strip.duplicates), ...crossing.seams].filter(row => row.instance === instance).map(row => row.mesh) };
|
|
73
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* GC30: a cell this worker hosts and whose entryways all have ground at road height. Any other (another worker's, or Far Reach's sky
|
|
81
|
+
* islands) is walled on the road: a walker meets the wall and turns back, never falls in with no way out.
|
|
82
|
+
*/
|
|
83
|
+
const enterable = (instance: string): boolean => { const room = cells.get(instance)?.room; return room !== undefined && room.entrywaysStand(); };
|
|
74
84
|
/** A cell on this worker, or its road, by name. */
|
|
75
85
|
const named = (name: string): Cell | RoadRoom | undefined => road !== undefined && road.name === name ? road : cells.get(name);
|
|
86
|
+
const emptyMs = options.emptyMs ?? EMPTY_MS;
|
|
87
|
+
/** `startOver`, once it is made below: a start-over opens a cell, and a cell's room says when it emptied. */
|
|
88
|
+
const later = { startOver: (_cell: Cell, _since: number): void => undefined };
|
|
89
|
+
/** Someone stood in this world: it has something to start over from. A refused seat never got this far. */
|
|
90
|
+
const used = (slug: string, room: DedicatedRoom): void => { const cell = cells.get(slug); if (cell !== undefined && cell.room === room) cell.used = true; };
|
|
91
|
+
/** J107 on J320's terms: the last seat left this cell's world, so it starts over once it has stood empty `emptyMs`, nobody waiting on it. */
|
|
92
|
+
const emptied = (slug: string, room: DedicatedRoom): void => {
|
|
93
|
+
const cell = cells.get(slug);
|
|
94
|
+
if (cell === undefined || cell.room !== room || disposed) return;
|
|
95
|
+
const since = cell.emptySince = diagnosticNow();
|
|
96
|
+
if (cell.used) scope.timeout(emptyMs, () => { later.startOver(cell, since); });
|
|
97
|
+
};
|
|
76
98
|
// GO3: a row names cells by grid instance; each loads its shard's pack.
|
|
77
99
|
const open = async (slug: string): Promise<DedicatedRoom> => {
|
|
78
100
|
const shard = cellShard(slug), begun = diagnosticNow(), input = await options.load(shard), onto = seams(slug);
|
|
79
101
|
rapier ??= input.rapier;
|
|
80
|
-
const room = await DedicatedRoom.boot({ slug: shard, cell: slug, build: options.build, bootId: options.bootId(), input, now: options.roomNow ?? diagnosticNow, ...(onto === undefined ? {} : { road: onto }),
|
|
81
|
-
post: news => { if (news.kind === '
|
|
102
|
+
const room: DedicatedRoom = await DedicatedRoom.boot({ slug: shard, cell: slug, build: options.build, bootId: options.bootId(), input, now: options.roomNow ?? diagnosticNow, ...(onto === undefined ? {} : { road: onto }),
|
|
103
|
+
post: news => { if (news.kind === 'seated') used(slug, room); else if (news.kind === 'left' && news.seats === 0) emptied(slug, room); post({ ...news, slug }); },
|
|
82
104
|
reports: { file: report => { post({ kind: 'report', slug, report }); } }, ...(options.holdMs === undefined ? {} : { holdMs: options.holdMs }),...(options.playtest===true?{playtest:row=>{post({kind:'playtest',slug,row});}}:{}) });
|
|
83
105
|
post({ kind: 'cell', slug, ms: diagnosticNow() - begun });
|
|
84
106
|
options.booted?.(slug, room);
|
|
@@ -99,33 +121,77 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
99
121
|
readAt = now; dropsAt = clock?.drops ?? 0; ticks = [];
|
|
100
122
|
post({ kind: 'reading', reading: row });
|
|
101
123
|
};
|
|
102
|
-
/**
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
/** One start-over at a time on this worker: each boot stalls the clock of every other cell here, so they never pile up. */
|
|
125
|
+
let overs: Promise<void> = Promise.resolve();
|
|
126
|
+
/** The fresh world, swapped in while the cell is still empty. One that fails keeps the old world and says so; the worker plays on. */
|
|
127
|
+
const restart = async (cell: Cell): Promise<void> => {
|
|
128
|
+
if (disposed || cell.room.taken > 0) return;
|
|
129
|
+
try {
|
|
130
|
+
const old = cell.room, room = await open(cell.slug);
|
|
131
|
+
if (disposed) { room.dispose(); return; }
|
|
132
|
+
cell.room = room; old.dispose(); cell.used = false; cell.emptySince = diagnosticNow();
|
|
133
|
+
} catch (error) { console.warn(JSON.stringify({ at: 'cell.start-over-failed', slug: cell.slug, error: error instanceof Error ? error.message : String(error) })); }
|
|
134
|
+
};
|
|
135
|
+
/** A cell everyone left starts over. An arrival meanwhile waits for it (`settled`). A timer can fire a little early by this clock, so it looks again. */
|
|
136
|
+
later.startOver = (cell: Cell, since: number): void => {
|
|
137
|
+
if (disposed || cell.waking !== null || !cell.used || cell.room.taken > 0 || cell.emptySince !== since) return;
|
|
138
|
+
const left = emptyMs - (diagnosticNow() - since);
|
|
139
|
+
if (left > 0) { scope.timeout(left, () => { later.startOver(cell, since); }); return; }
|
|
140
|
+
const job = overs.then(() => restart(cell)).finally(() => { if (cell.waking === job) cell.waking = null; });
|
|
141
|
+
cell.waking = job; overs = job;
|
|
142
|
+
};
|
|
143
|
+
/** J320: an arrival never boots a cell. It waits only for a start-over already under way, and false when the worker closed meanwhile. */
|
|
144
|
+
const settled = async (...waiting: readonly Cell[]): Promise<boolean> => {
|
|
145
|
+
for (let busy = waiting.find(cell => cell.waking !== null); busy?.waking; busy = waiting.find(cell => cell.waking !== null)) await busy.waking;
|
|
146
|
+
return !disposed;
|
|
111
147
|
};
|
|
112
148
|
const dispose = (): void => { if (disposed) return; disposed = true; clock?.pause(); scope.dispose(); for (const { room } of cells.values()) room.dispose(); road?.dispose(); options.closed?.(); };
|
|
113
149
|
const find = async (cell: Cell | RoadRoom, id: number, device: string): Promise<void> => {
|
|
114
150
|
if (cell instanceof RoadRoom) { post({ kind: 'found', id, held: cell.holds(device), spawn: cell.spawn }); return; }
|
|
115
|
-
await
|
|
151
|
+
if (await settled(cell)) post({ kind: 'found', id, held: cell.room.holds(device), spawn: cell.room.spawn });
|
|
116
152
|
};
|
|
117
153
|
const seat = async (cell: Cell | RoadRoom, order: Extract<CellOrder, { kind: 'seat' }>): Promise<void> => {
|
|
118
154
|
// The transport starts its port: made before a wake, a close on the way would reach nobody.
|
|
119
|
-
if (!(cell instanceof RoadRoom) && cell
|
|
155
|
+
if (!(cell instanceof RoadRoom) && !await settled(cell)) return;
|
|
120
156
|
const transport = new SeatTransport(order.port), hello = (): void => { transport.deliver('reliable', order.hello); };
|
|
121
157
|
if (cell instanceof RoadRoom) cell.seat(order, transport, hello); else cell.room.seat(order, transport, hello);
|
|
122
158
|
};
|
|
123
|
-
/**
|
|
159
|
+
/**
|
|
160
|
+
* SA34a: cells placed on the running world, one order at a time. The road's grid grows first (a cell opened here builds its seams from
|
|
161
|
+
* it), then this worker opens the ones it hosts, then its road lays the grown grid out, whatever opened. A failure is answered, never
|
|
162
|
+
* thrown: the other cells and the road play on.
|
|
163
|
+
*/
|
|
164
|
+
let placing: Promise<void> = Promise.resolve();
|
|
165
|
+
/** RR2: what this worker holds, for the door's `/health`: a road counts its strips only once it is open */
|
|
166
|
+
const resident = (): WorkerResident => ({ cells: cells.size, road: road !== undefined, strips: road === undefined ? 0 : crossing?.strips.length ?? 0 });
|
|
167
|
+
const place = async (order: Extract<CellOrder, { kind: 'place' }>): Promise<void> => {
|
|
168
|
+
const opened: string[] = [];
|
|
169
|
+
let laid: (() => void) | undefined;
|
|
170
|
+
try {
|
|
171
|
+
for (const row of order.cells) placeCell(row);
|
|
172
|
+
const was = crossing?.assembly, grown = gridAssembly();
|
|
173
|
+
if (crossing !== undefined && was !== undefined && was !== grown) {
|
|
174
|
+
const { strips, seams: more } = placedStrips(grown, was), fresh = grown.cells.slice(was.cells.length);
|
|
175
|
+
crossing = { name: crossing.name, assembly: grown, strips: [...crossing.strips, ...strips], seams: [...crossing.seams, ...more] };
|
|
176
|
+
laid = () => { road?.place(grown, strips, fresh.filter(cell => !enterable(cell.instance))); };
|
|
177
|
+
}
|
|
178
|
+
for (const slug of order.open) {
|
|
179
|
+
if (cells.has(slug)) continue;
|
|
180
|
+
const room = await open(slug);
|
|
181
|
+
if (disposed) { room.dispose(); post({ kind: 'placed', id: order.id, opened, error: 'The worker closed' }); return; }
|
|
182
|
+
cells.set(slug, { slug, room, emptySince: diagnosticNow(), used: false, waking: null }); opened.push(slug);
|
|
183
|
+
}
|
|
184
|
+
post({ kind: 'placed', id: order.id, opened, resident: resident() });
|
|
185
|
+
// RR2: a place that failed partway still opened `opened` and grew the road's strips, so its answer says what is resident too
|
|
186
|
+
} catch (error) { post({ kind: 'placed', id: order.id, opened, error: error instanceof Error ? error.message : String(error), resident: resident() }); }
|
|
187
|
+
finally { if (!disposed) laid?.(); }
|
|
188
|
+
};
|
|
189
|
+
/** GC15: a seat walks from one of this worker's cells into another, or onto or off its road; a target starting over is waited for (J320). */
|
|
124
190
|
const cross = async (order: Extract<CellOrder, { kind: 'cross' }>): Promise<void> => {
|
|
125
191
|
const { kind: _kind, from: fromSlug, to: toSlug, at, ...entry } = order, from = named(fromSlug), to = named(toSlug);
|
|
126
192
|
if (from === undefined || to === undefined) throw new Error(`${from === undefined ? fromSlug : toSlug} is not on this worker`);
|
|
127
|
-
|
|
128
|
-
if (!(from
|
|
193
|
+
// Both settled in one look, then read and moved with no await between: a start-over can't begin under the seat (J320).
|
|
194
|
+
if (!await settled(...[from, to].filter((cell): cell is Cell => !(cell instanceof RoadRoom)))) return;
|
|
129
195
|
const source = from instanceof RoadRoom ? from : from.room, target = to instanceof RoadRoom ? to : to.room;
|
|
130
196
|
const moved = source.handOver(entry.device, target, entry, at);
|
|
131
197
|
post({ kind: 'crossed', device: entry.device, name: entry.name, from: fromSlug, to: toSlug, moved, stays: source.holds(entry.device), body: moved ? target.bodyId(entry.device) ?? entry.body : entry.body });
|
|
@@ -142,6 +208,7 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
142
208
|
if (!ready) { fail(new Error('A worker was told something before it booted')); return; }
|
|
143
209
|
if (order.kind === 'drain') { clock?.pause(); for (const { room } of cells.values()) room.drain(); road?.drain(); post({ kind: 'drained' }); return; }
|
|
144
210
|
if (order.kind === 'cross') { cross(order).catch(fail); return; }
|
|
211
|
+
if (order.kind === 'place') { placing = placing.then(() => place(order)); return; }
|
|
145
212
|
const cell = named(order.slug);
|
|
146
213
|
if (cell === undefined) { fail(new Error(`${order.slug} is not on this worker`)); return; }
|
|
147
214
|
(order.kind === 'find' ? find(cell, order.id, order.device) : seat(cell, order)).catch(fail);
|
|
@@ -151,11 +218,13 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
151
218
|
installCellIdentity();
|
|
152
219
|
void (async (): Promise<void> => {
|
|
153
220
|
const first = options.slugs[0];
|
|
154
|
-
|
|
155
|
-
|
|
221
|
+
// SA34a: a worker booted after a placement (its `placed`) lays the placed cells out from the start.
|
|
222
|
+
// GC28: a book with no grid pack reads no strips: no road to stand on, so the cells open lone (the worker's `road.pack` line says 0).
|
|
223
|
+
if (options.road !== undefined && first !== undefined) { const assembly = gridAssembly(), strips = await options.road(), placed = placedStrips(assembly, gridAssembly(false)); if (strips.length > 0) crossing = { name: roadName(first), assembly, strips: [...strips, ...placed.strips], seams: placed.seams }; }
|
|
224
|
+
for (const slug of options.slugs) { const room = await open(slug); if (disposed) return; cells.set(slug, { slug, room, emptySince: diagnosticNow(), used: false, waking: null }); }
|
|
156
225
|
if (crossing !== undefined && rapier !== undefined) {
|
|
157
226
|
const { name, assembly, strips } = crossing, begun = diagnosticNow();
|
|
158
|
-
road = new RoadRoom({ name, build: options.build, assembly, host: openRoad(rapier, assembly.cells.filter(cell => !
|
|
227
|
+
road = new RoadRoom({ name, build: options.build, assembly, host: openRoad(rapier, assembly.cells.filter(cell => !enterable(cell.instance)), strips, assembly.cells), hosts: instance => cells.has(instance),
|
|
159
228
|
now: options.roomNow ?? diagnosticNow, post: news => { post({ ...news, slug: name }); }, reports: { file: report => { post({ kind: 'report', slug: name, report }); } },
|
|
160
229
|
...(options.holdMs === undefined ? {} : { holdMs: options.holdMs }) });
|
|
161
230
|
post({ kind: 'cell', slug: name, ms: diagnosticNow() - begun });
|
|
@@ -165,7 +234,7 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
165
234
|
clock = new ServerClock({ now: diagnosticNow, wait: (ms, run) => { const timer = scope.timeout(ms, run); return () => { scope.cancelTimer(timer); }; }, step });
|
|
166
235
|
clock.start();
|
|
167
236
|
scope.interval(READING_MS, reading);
|
|
168
|
-
post({ kind: 'booted', ms: diagnosticNow() - started });
|
|
237
|
+
post({ kind: 'booted', ms: diagnosticNow() - started, resident: resident() });
|
|
169
238
|
})().catch(fail);
|
|
170
239
|
return { dispose };
|
|
171
240
|
}
|
|
@@ -2,6 +2,7 @@ import type { ChatReport, WorldLine } from '@wildshard/engine/net/chat';
|
|
|
2
2
|
import type { PlayerDoc } from './playerDoc';
|
|
3
3
|
import type { SaveReceipt, SaveWrite } from './saves/saveStore';
|
|
4
4
|
import type {PlaytestHit} from './playtest';
|
|
5
|
+
import type { PlacedCell } from './gridCells';
|
|
5
6
|
|
|
6
7
|
// J182: what the door and a cell worker say to each other. Sockets stay with the door, and a seat's bytes go through its own port.
|
|
7
8
|
|
|
@@ -30,6 +31,11 @@ export type CellOrder =
|
|
|
30
31
|
| { readonly kind: 'chat'; readonly from: string; readonly line: WorldLine }
|
|
31
32
|
/** GC15: a seat in cell `from` walks into `to` on the same worker. The entry is the door's read of their save on `to`'s shard. */
|
|
32
33
|
| ({ readonly kind: 'cross'; readonly from: string; readonly to: string; readonly at: ResumeAt } & SeatEntry)
|
|
34
|
+
/**
|
|
35
|
+
* SA34a: cells placed on the running world (SA33), told to every booted worker so its road lays them out: no void floor over their
|
|
36
|
+
* squares, their strips, and walls round any it can't hand a seat to. `open` names the ones this worker opens and hosts.
|
|
37
|
+
*/
|
|
38
|
+
| { readonly kind: 'place'; readonly id: number; readonly cells: readonly PlacedCell[]; readonly open: readonly string[] }
|
|
33
39
|
| { readonly kind: 'close' };
|
|
34
40
|
/** One 10 s reading of a worker (E7.8). */
|
|
35
41
|
export interface WorkerReading {
|
|
@@ -50,15 +56,19 @@ export type RoomNews =
|
|
|
50
56
|
| { readonly kind: 'chat'; readonly line: WorldLine }
|
|
51
57
|
/** GC15: this seat's feet left for cell `to`, standing at `at` in its frame: the door reads their save there and orders the `cross`. */
|
|
52
58
|
| { readonly kind: 'crossing'; readonly device: string; readonly to: string; readonly at: ResumeAt };
|
|
59
|
+
/** ROAD-RESIDENT RR2: what a worker holds in memory: its open cells, whether its road is open, and the strips that road stands on. */
|
|
60
|
+
export interface WorkerResident { readonly cells: number; readonly road: boolean; readonly strips: number }
|
|
53
61
|
/** What a worker says to the door. */
|
|
54
62
|
export type WorkerNews =
|
|
55
|
-
| { readonly kind: 'booted'; readonly ms: number }
|
|
63
|
+
| { readonly kind: 'booted'; readonly ms: number; readonly resident?: WorkerResident }
|
|
56
64
|
| { readonly kind: 'failed'; readonly reason: string }
|
|
57
65
|
| { readonly kind: 'found'; readonly id: number; readonly held: boolean; readonly spawn: ResumeAt }
|
|
58
66
|
| { readonly kind: 'report'; readonly slug: string; readonly report: ChatReport }
|
|
59
67
|
| { readonly kind: 'reading'; readonly reading: WorkerReading }
|
|
60
68
|
| { readonly kind: 'cell'; readonly slug: string; readonly ms: number }
|
|
61
69
|
| { readonly kind: 'drained' }
|
|
70
|
+
/** SA34a: a `place` order's end: the cells this worker opened, or why it opened none. Its other cells and its road play on either way. */
|
|
71
|
+
| { readonly kind: 'placed'; readonly id: number; readonly opened: readonly string[]; readonly error?: string; readonly resident?: WorkerResident }
|
|
62
72
|
/** GC15: a `cross` order's end. Moved, the seat and its link are in `to` (as `body`) and `from` has let it go; else it `stays` in `from`, or neither holds it. */
|
|
63
73
|
| { readonly kind: 'crossed'; readonly device: string; readonly name: string; readonly body: string; readonly from: string; readonly to: string; readonly moved: boolean; readonly stays: boolean }
|
|
64
74
|
| (RoomNews & { readonly slug: string });
|
|
@@ -10,17 +10,23 @@ import { parentPort, workerData } from 'node:worker_threads';
|
|
|
10
10
|
import { loadRapier } from '@wildshard/engine/physics/rapier';
|
|
11
11
|
import { readPackGrid, readPackProduct, type PackReads } from './packReader';
|
|
12
12
|
import { runCells, type CellPort } from './cellHost';
|
|
13
|
+
import { placeCell, type PlacedCell } from './gridCells';
|
|
13
14
|
|
|
14
15
|
/** What the door boots a worker with. */
|
|
15
16
|
export interface CellWorkerData { readonly slugs: readonly string[]; readonly build: string; readonly origin: string; readonly cache: string; readonly holdMs?: number;readonly playtest?:boolean;
|
|
17
|
+
/** J107's start-over wait, a proof's override (`EMPTY_MS`): 5 minutes when absent. */
|
|
18
|
+
readonly emptyMs?: number;
|
|
16
19
|
/** GC15: `WORLD_CROSSING=worker`, this worker hosts the road between its cells. */
|
|
17
|
-
readonly crossing?: boolean
|
|
20
|
+
readonly crossing?: boolean;
|
|
21
|
+
/** SA33: the cells the door had placed when it booted this worker; a worker's module state is its own. */
|
|
22
|
+
readonly placed?: readonly PlacedCell[] }
|
|
18
23
|
|
|
19
|
-
const { slugs, build, origin, cache, holdMs,playtest, crossing } = workerData as CellWorkerData, port = parentPort;
|
|
24
|
+
const { slugs, build, origin, cache, holdMs, emptyMs, playtest, crossing, placed } = workerData as CellWorkerData, port = parentPort;
|
|
20
25
|
if (port === null) throw new Error('A cell runs in a worker');
|
|
26
|
+
for (const row of placed ?? []) placeCell(row);
|
|
21
27
|
const reads: PackReads = { fetched: 0, fetchedBytes: 0, cached: 0, refused: 0 };
|
|
22
28
|
const rapier = await loadRapier(await readFile(new URL('rapier.wasm', import.meta.url)));
|
|
23
|
-
runCells(port as unknown as CellPort, { slugs, build, bootId: () => randomBytes(4).toString('hex'), memory: () => process.memoryUsage(), closed: () => { process.exit(0); }, ...(holdMs === undefined ? {} : { holdMs }),...(playtest===undefined?{}:{playtest}),...(crossing === true ? { road: async () => {
|
|
29
|
+
runCells(port as unknown as CellPort, { slugs, build, bootId: () => randomBytes(4).toString('hex'), memory: () => process.memoryUsage(), closed: () => { process.exit(0); }, ...(holdMs === undefined ? {} : { holdMs }), ...(emptyMs === undefined ? {} : { emptyMs }),...(playtest===undefined?{}:{playtest}),...(crossing === true ? { road: async () => {
|
|
24
30
|
// A build whose server book has no grid pack gives a road with no strips: this line says so before anyone falls through it.
|
|
25
31
|
const strips = await readPackGrid(build, { origin, cache }, reads);
|
|
26
32
|
console.info(JSON.stringify({ at: 'road.pack', strips: strips.length, ...reads }));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// has walked. A cell and its worker's road hand a seat to each other through the door (`World.crossing`), on the same socket.
|
|
3
3
|
import { CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
4
4
|
import type { NetRoom } from '@wildshard/engine/net/room';
|
|
5
|
+
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
5
6
|
import type { SimNetWorld } from '@wildshard/engine/net/simWorld';
|
|
6
7
|
import type { Transport } from '@wildshard/engine/net/transport';
|
|
7
8
|
import type { GridAssembly, GridCell, GridPoint } from '@wildshard/engine/game/grid/assembly';
|
|
@@ -20,8 +21,11 @@ export interface CrossArrival {
|
|
|
20
21
|
export interface CrossTarget {
|
|
21
22
|
readonly net: NetRoom; readonly sim: SimNetWorld;
|
|
22
23
|
holds: (device: string) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Make the body first, at `at` in this room's frame; the reason when it can't, with nothing left behind. GC34: `motion` is the
|
|
26
|
+
* walker's body in the room it leaves, so the new one takes its velocity, clocks and mode (`carryMotion`) and never starts from rest.
|
|
27
|
+
*/
|
|
28
|
+
admit: (entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim) => CrossArrival | string;
|
|
25
29
|
}
|
|
26
30
|
/** Feet the grid can place: a body gone to NaN is skipped, never thrown on, so one bad body can't end its worker. */
|
|
27
31
|
export function finite(feet: Readonly<GridPoint>): boolean { return Number.isFinite(feet.x) && Number.isFinite(feet.y) && Number.isFinite(feet.z); }
|
|
@@ -9,9 +9,11 @@ import { saves } from '@wildshard/engine/saves/runtime';
|
|
|
9
9
|
import type { SimHost } from '@wildshard/engine/sim';
|
|
10
10
|
import { actRoutes } from '@wildshard/engine/sim/actRoutes';
|
|
11
11
|
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
12
|
+
import { carryMotion } from '@wildshard/engine/game/grid/simulation';
|
|
12
13
|
import { netBuys, netWorldInput } from '../../../shared/host/standalone/netInput';
|
|
13
14
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
14
|
-
import { LEAD_SEAT,
|
|
15
|
+
import { LEAD_SEAT, type CellWorld } from '../standalone/cellWorld';
|
|
16
|
+
import { openWorld } from '../openWorld';
|
|
15
17
|
import type { FallFloor } from '../standalone/fallFloor';
|
|
16
18
|
import { ledgerFilings } from '../standalone/ledgerFilings';
|
|
17
19
|
import { questBooks } from '@wildshard/engine/quest/players';
|
|
@@ -24,7 +26,7 @@ import { LEFT } from './socketPump';
|
|
|
24
26
|
import type {PlaytestHit} from './playtest';
|
|
25
27
|
import { cellFrame, cellName } from './gridCells';
|
|
26
28
|
import {hitHistoryOf} from '@wildshard/engine/combat/rewind';
|
|
27
|
-
import { floorBelow } from '@wildshard/engine/physics/query';
|
|
29
|
+
import { entrywaysStand, floorBelow } from '@wildshard/engine/physics/query';
|
|
28
30
|
import type { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
29
31
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
30
32
|
import { buildStrips } from '../standalone/roadWorld';
|
|
@@ -69,7 +71,7 @@ export interface DedicatedRoomOptions {
|
|
|
69
71
|
/** GO3: the grid instance this room is, which names it everywhere else and numbers its frames. Left out, the shard's own grid cell. */
|
|
70
72
|
readonly cell?: string;
|
|
71
73
|
/**
|
|
72
|
-
* GC15 (`WORLD_CROSSING=worker`): this worker's road, which the cell opens onto instead of standing
|
|
74
|
+
* GC15 (`WORLD_CROSSING=worker`): this worker's road, which the cell opens onto instead of standing lone. Its seam
|
|
73
75
|
* strips are built into the cell's world, and a seat whose feet leave the cell asks the door to cross onto the road.
|
|
74
76
|
*/
|
|
75
77
|
readonly road?: DedicatedRoomRoad;
|
|
@@ -138,7 +140,8 @@ export class DedicatedRoom implements CrossTarget {
|
|
|
138
140
|
if (seat === undefined) throw new Error(`No seat for ${body}`);
|
|
139
141
|
return seat;
|
|
140
142
|
};
|
|
141
|
-
|
|
143
|
+
// SERVER-PARITY HS1: the one world-build entry a shard's CI journeys tick too
|
|
144
|
+
const cell = await openWorld(input, { room: true, cell: options.cell ?? cellName(slug), saves, lone: options.road === undefined,
|
|
142
145
|
owned: body => seated(body).store.slots,
|
|
143
146
|
profiles: {
|
|
144
147
|
read: identity => seats.get(identity)?.store.rewards.read(slug).players[identity] ?? null,
|
|
@@ -227,6 +230,8 @@ export class DedicatedRoom implements CrossTarget {
|
|
|
227
230
|
}
|
|
228
231
|
return seat;
|
|
229
232
|
}
|
|
233
|
+
/** GC30: whether a walker off the road stands at this cell's entryways (`entrywaysStand`); else its worker's road walls it. */
|
|
234
|
+
entrywaysStand(): boolean { return entrywaysStand(this.host.physics, ARRIVAL_LIFT); }
|
|
230
235
|
/** GC15: this seat's feet left for cell `to`, standing at `at` in that cell's own frame. The door reads their save there and orders `handOver`. */
|
|
231
236
|
crossing(device: string, to: string, at: ResumeAt): void {
|
|
232
237
|
if ((this.seats.get(device)?.transport ?? null) !== null) this.options.post({ kind: 'crossing', device, to, at });
|
|
@@ -241,7 +246,8 @@ export class DedicatedRoom implements CrossTarget {
|
|
|
241
246
|
handOver(device: string, target: CrossTarget, entry: SeatEntry, at: ResumeAt): boolean {
|
|
242
247
|
const seat = this.seats.get(device), transport = seat?.transport ?? null;
|
|
243
248
|
if (seat === undefined || transport === null || seat.client === null || !this.net.live(seat.client) || target === this || target.holds(device)) return false;
|
|
244
|
-
|
|
249
|
+
// GC34: the walker's own motion goes with them; a rider's lives on the mount it leaves here, so it arrives on foot from rest
|
|
250
|
+
const arrived = target.admit(entry, transport, at, mountedPlayerOf(this.host, seat.body)?.mounted === true ? undefined : this.host.players.get(seat.body));
|
|
245
251
|
if (typeof arrived === 'string') return false;
|
|
246
252
|
mountedPlayerOf(this.host, seat.body)?.dismount();
|
|
247
253
|
this.write(seat, 'cross');
|
|
@@ -252,13 +258,14 @@ export class DedicatedRoom implements CrossTarget {
|
|
|
252
258
|
return arrived.land(client);
|
|
253
259
|
}
|
|
254
260
|
/** GC15: a crossing seat's body here, from the door's read of its save on this shard (the previous copy if that one won't import). */
|
|
255
|
-
admit(entry: SeatEntry, transport: Transport, at: ResumeAt): CrossArrival | string {
|
|
261
|
+
admit(entry: SeatEntry, transport: Transport, at: ResumeAt, motion?: PlayerSim): CrossArrival | string {
|
|
256
262
|
const { previous, ...current } = entry, { device } = entry;
|
|
257
263
|
let arrived = this.place(current, transport, at), recovered = false;
|
|
258
264
|
if (typeof arrived === 'string' && previous !== undefined) { arrived = this.place({ ...current, doc: previous.doc, recovery: previous.recovery }, transport, at); recovered = typeof arrived !== 'string'; }
|
|
259
265
|
if (typeof arrived === 'string') return arrived;
|
|
260
266
|
if (recovered) this.options.post({ kind: 'recovered', device, seq: entry.seq });
|
|
261
|
-
const seat = arrived;
|
|
267
|
+
const seat = arrived, player = this.host.players.get(seat.body);
|
|
268
|
+
if (motion !== undefined && player !== undefined) carryMotion(motion, player);
|
|
262
269
|
this.arriving.add(seat.body);
|
|
263
270
|
return { body: seat.body, land: client => {
|
|
264
271
|
this.settle(seat);
|
|
@@ -368,7 +375,13 @@ export class DedicatedRoom implements CrossTarget {
|
|
|
368
375
|
const player = this.host.players.get(body);
|
|
369
376
|
if (player === undefined || !finite(player.position)) continue;
|
|
370
377
|
const { x, y, z } = player.position, top = floorBelow(this.host.physics, x, z, y + ARRIVAL_LIFT, ARRIVAL_LIFT * 2);
|
|
371
|
-
if (top
|
|
378
|
+
if (top === undefined || top <= y + ARRIVAL_SKIN) continue;
|
|
379
|
+
// GC34: set on the top, the walker keeps the ground speed, board, push and dash it crossed with (a reset stands it still, on foot)
|
|
380
|
+
const { x: vx, z: vz } = player.velocity, { on, hoverAir, hoverBob } = player.board, impulse = player.impulse.clone(), dash = { ...player.dash };
|
|
381
|
+
player.resetPose({ x, y: top + ARRIVAL_SKIN, z }, player.yaw);
|
|
382
|
+
if (on) player.setBoard(true);
|
|
383
|
+
player.board.hoverAir = hoverAir; player.board.hoverBob = hoverBob;
|
|
384
|
+
player.velocity.x = vx; player.velocity.z = vz; player.impulse.copy(impulse); Object.assign(player.dash, dash);
|
|
372
385
|
}
|
|
373
386
|
}
|
|
374
387
|
private filings(): readonly LedgerFiling[] {
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// player's progress under the shard's slug, so a save made before GO3 reads back. A name the grid doesn't place is a cell of its own.
|
|
4
4
|
import { GridAssembly } from '@wildshard/engine/game/grid/assembly';
|
|
5
5
|
import { catalogueDocument } from '@wildshard/engine/game/grid/catalogueDocument';
|
|
6
|
+
import { GRID_RADIUS } from '@wildshard/format/contentBounds';
|
|
6
7
|
|
|
7
8
|
/** `WORLD_CELLS=grid`: every grid cell the release names, the home cell first. */
|
|
8
9
|
export const WHOLE_GRID = 'grid';
|
|
@@ -10,19 +11,61 @@ export const WHOLE_GRID = 'grid';
|
|
|
10
11
|
const UNPLACED_FRAME = 1;
|
|
11
12
|
|
|
12
13
|
/** The grid's cells in catalogue order, and each one's frame, by instance and by shard. */
|
|
13
|
-
interface GridNames { readonly instances: readonly string[]; readonly frames: ReadonlyMap<string, number>; readonly shards: ReadonlyMap<string, string>; readonly cells: ReadonlyMap<string, string>; readonly home: string | undefined
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
interface GridNames { readonly instances: readonly string[]; readonly frames: ReadonlyMap<string, number>; readonly shards: ReadonlyMap<string, string>; readonly cells: ReadonlyMap<string, string>; readonly home: string | undefined;
|
|
15
|
+
/** Each taken spot (`x,z`), and the instance on it. */
|
|
16
|
+
readonly spots: ReadonlyMap<string, string> }
|
|
17
|
+
/** SA33: one cell a signed placement file names: the API's placement of a new slug (SA30), on a spot the catalogue leaves empty. */
|
|
18
|
+
export interface PlacedCell { readonly instance: string; readonly slug: string; readonly cell: readonly [number, number] }
|
|
19
|
+
/** SA33: the cells placed on this running server, in the placement file's order, after the catalogue's. A restart forgets them; the
|
|
20
|
+
* placement watch's first look places them again. */
|
|
21
|
+
const placed: PlacedCell[] = [];
|
|
22
|
+
let read: { readonly from: unknown; readonly placed: number; readonly names: GridNames } | null = null;
|
|
23
|
+
/** Parsed once per installed catalogue, the way a grid page assembles it, then the placed cells: frame `catalogue count + n`. */
|
|
16
24
|
function gridNames(): GridNames {
|
|
17
25
|
const { grid } = catalogueDocument();
|
|
18
|
-
if (read?.from === grid) return read.names;
|
|
19
|
-
const { cells } = new GridAssembly({ developer: false, devserver: false }, grid);
|
|
20
|
-
const names: GridNames = { instances:
|
|
21
|
-
shards: new Map(
|
|
22
|
-
home: cells.find(cell => cell.cell[0] === 0 && cell.cell[1] === 0)?.instance };
|
|
23
|
-
read = { from: grid, names };
|
|
26
|
+
if (read?.from === grid && read.placed === placed.length) return read.names;
|
|
27
|
+
const { cells } = new GridAssembly({ developer: false, devserver: false }, grid), rows = [...cells.map(({ instance, slug, cell }) => ({ instance, slug, cell })), ...placed];
|
|
28
|
+
const names: GridNames = { instances: rows.map(cell => cell.instance), frames: new Map(rows.map((cell, index) => [cell.instance, index + 1])),
|
|
29
|
+
shards: new Map(rows.map(cell => [cell.instance, cell.slug])), cells: new Map(rows.map(cell => [cell.slug, cell.instance])),
|
|
30
|
+
home: cells.find(cell => cell.cell[0] === 0 && cell.cell[1] === 0)?.instance, spots: new Map(rows.map(cell => [cell.cell.join(','), cell.instance])) };
|
|
31
|
+
read = { from: grid, placed: placed.length, names };
|
|
24
32
|
return names;
|
|
25
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* SA33: place a cell the API placed (a new slug, J314) on this running server. True when it is new here, false when this server already
|
|
36
|
+
* places it the same way. A slug keeps one cell for life and a spot holds one cell, so a row that disagrees with the catalogue or an earlier
|
|
37
|
+
* placement throws and changes nothing. The server draws nothing, so any spot inside the format's grid (the 7 × 7, SA29) is admitted.
|
|
38
|
+
*/
|
|
39
|
+
export function placeCell(row: PlacedCell): boolean {
|
|
40
|
+
const { shards, cells, spots } = gridNames(), [x, z] = row.cell, spot = `${String(x)},${String(z)}`;
|
|
41
|
+
if (shards.has(row.instance)) {
|
|
42
|
+
if (cells.get(row.slug) === row.instance && spots.get(spot) === row.instance) return false;
|
|
43
|
+
throw new Error(`${row.instance} is already placed elsewhere`);
|
|
44
|
+
}
|
|
45
|
+
if (!Number.isInteger(x) || !Number.isInteger(z) || Math.abs(x) > GRID_RADIUS || Math.abs(z) > GRID_RADIUS) throw new Error(`${row.instance}'s cell ${spot} is off the grid`);
|
|
46
|
+
if (cells.has(row.slug) || shards.has(row.slug)) throw new Error(`${row.slug} already has a cell`);
|
|
47
|
+
if (cells.has(row.instance)) throw new Error(`${row.instance} is a placed shard's name`);
|
|
48
|
+
const taken = spots.get(spot);
|
|
49
|
+
if (taken !== undefined) throw new Error(`${spot} is ${taken}'s`);
|
|
50
|
+
placed.push({ instance: row.instance, slug: row.slug, cell: [x, z] });
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
let assembled: { readonly from: unknown; readonly placed: number; readonly assembly: GridAssembly } | null = null;
|
|
54
|
+
/**
|
|
55
|
+
* SA34a: the grid a road walks: the installed catalogue's cells and then the placed ones, so a road and its cells know a placed cell's
|
|
56
|
+
* square. `placedToo` false: the catalogue's alone, the grid the build's road pack was baked for.
|
|
57
|
+
*/
|
|
58
|
+
export function gridAssembly(placedToo = true): GridAssembly {
|
|
59
|
+
const { grid } = catalogueDocument(), count = placedToo ? placed.length : 0;
|
|
60
|
+
if (assembled?.from === grid && assembled.placed === count) return assembled.assembly;
|
|
61
|
+
const assembly = new GridAssembly({ developer: false, devserver: false }, count === 0 ? grid : { ...grid, cells: [...grid.cells, ...placed.map(({ instance, slug, cell }) => ({ instance, slug, cell: [...cell] }))] });
|
|
62
|
+
assembled = { from: grid, placed: count, assembly };
|
|
63
|
+
return assembly;
|
|
64
|
+
}
|
|
65
|
+
/** What a worker thread is booted with, so its rooms name, frame and load a placed cell as the door does. */
|
|
66
|
+
export function placedCells(): readonly PlacedCell[] { return [...placed]; }
|
|
67
|
+
/** Tests only: forget every placed cell. */
|
|
68
|
+
export function forgetPlacedCells(): void { placed.length = 0; read = null; assembled = null; }
|
|
26
69
|
|
|
27
70
|
/** The instance a name means: an instance stands, a grid shard's slug becomes its cell, and anything else is its own name. */
|
|
28
71
|
export function cellName(name: string): string { const { shards, cells } = gridNames(); return shards.has(name) ? name : cells.get(name) ?? name; }
|
|
@@ -24,9 +24,10 @@ import { sendSentryTest, serverSentry } from './serverSentry';
|
|
|
24
24
|
import {PlaytestFile} from './playtest';
|
|
25
25
|
import { World, type PlayerSaves, type WorkerLink } from './world';
|
|
26
26
|
import { cloudflareTurn } from './voiceRelay';
|
|
27
|
-
import { worldSettings } from './workerTable';
|
|
27
|
+
import { worldCrossing, worldSettings } from './workerTable';
|
|
28
28
|
import { doorTrust } from './doorTrust';
|
|
29
|
-
import { cellShard, worldCells } from './gridCells';
|
|
29
|
+
import { WHOLE_GRID, cellShard, placeCell, placedCells, worldCells } from './gridCells';
|
|
30
|
+
import { PlacementWatch, fetchPlacementFile } from './placementFile';
|
|
30
31
|
|
|
31
32
|
declare const __BUILD_ID__: string;
|
|
32
33
|
/** scripts/build-server.mjs: package.json's version, the Sentry release (S8). */
|
|
@@ -56,8 +57,8 @@ async function installedRelease(): Promise<ReleaseFile> {
|
|
|
56
57
|
const release = await installedRelease();
|
|
57
58
|
// C5, C11, GO3: the cells, by grid instance, fixed at startup; a player with no save lands in the first. `grid` opens every grid cell
|
|
58
59
|
// the release names, home first. A cell runs its shard's pack, and the release must name that shard.
|
|
59
|
-
const
|
|
60
|
-
const hold = process.env['HOLD_MS'], grace = process.env['GRACE_MS'], poll = process.env['RELEASE_POLL_MS'], recordEvery = process.env['RECORD_MS'];
|
|
60
|
+
const listed = process.env['WORLD_CELLS'] ?? 'driftwood-isle', cells = worldCells(listed, release.shards.map(shard => shard.slug)), shards = [...new Set(cells.map(cellShard))];
|
|
61
|
+
const hold = process.env['HOLD_MS'], empty = process.env['EMPTY_MS'], grace = process.env['GRACE_MS'], poll = process.env['RELEASE_POLL_MS'], recordEvery = process.env['RECORD_MS'];
|
|
61
62
|
// An env file's blank row means unset.
|
|
62
63
|
const setting = (name: string): string | undefined => { const value = process.env[name]; return value === '' ? undefined : value; };
|
|
63
64
|
const sentry = serverSentry({ dsn: setting('SENTRY_DSN'), version: engineVersion, build, channel: release.channel });
|
|
@@ -65,15 +66,16 @@ const reports = new ServerReports({ build, channel: release.channel, telemetryUr
|
|
|
65
66
|
const url = process.env['DATABASE_URL'] ?? savesUrl(release.channel), saves: PlayerSaves = url === 'memory:' ? memoryPlayerSaves() : await openPlayerSaves(url, new URL('migrations/', import.meta.url), release.saveEpoch, log, issue => { reports.contract(issue); });
|
|
66
67
|
const recordTag=setting('RECORD_TAG');
|
|
67
68
|
const turnKey = setting('WILDSHARD_TURN_KEY_ID'), turnToken = setting('WILDSHARD_TURN_KEY_TOKEN');
|
|
68
|
-
// GC15:
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
const
|
|
69
|
+
// GC15, GC35: each worker opens its road and lets a seat walk between the cells it hosts; only `WORLD_CROSSING=off` keeps cells lone (J322).
|
|
70
|
+
const crossing = worldCrossing(setting('WORLD_CROSSING'));
|
|
71
|
+
// SA33: where the API's signed placement file is, and its own key's public half. Both or neither; only a whole-grid world grows.
|
|
72
|
+
const placementAt = setting('PLACEMENT_URL'), placementKey = setting('PLACEMENT_PUBLIC_KEY');
|
|
73
|
+
if ((placementAt === undefined) !== (placementKey === undefined)) throw new Error('PLACEMENT_URL and PLACEMENT_PUBLIC_KEY go together');
|
|
72
74
|
const playtest=process.env['PLAYTEST']==='1'?new PlaytestFile({directory:setting('PLAYTEST_DIR')??'/var/log/wildshard',build,log,...(recordTag===undefined?{}:{tag:recordTag})}):undefined;
|
|
73
75
|
|
|
74
76
|
/** One row of the table is one worker thread, started once (J182). */
|
|
75
77
|
function bootWorker(slugs: readonly string[]): WorkerLink {
|
|
76
|
-
const data: CellWorkerData = { slugs, build, origin, cache, ...(hold === undefined ? {} : { holdMs: Number(hold) }), ...(crossing ? { crossing } : {}),...(playtest===undefined?{}:{playtest:true}) };
|
|
78
|
+
const data: CellWorkerData = { slugs, build, origin, cache, placed: placedCells(), ...(hold === undefined ? {} : { holdMs: Number(hold) }), ...(empty === undefined ? {} : { emptyMs: Number(empty) }), ...(crossing ? { crossing } : {}),...(playtest===undefined?{}:{playtest:true}) };
|
|
77
79
|
const worker = new Worker(new URL('cellWorker.mjs', import.meta.url), { workerData: data });
|
|
78
80
|
let stopped = false;
|
|
79
81
|
return { send: (order, transfer = []) => { worker.postMessage(order, transfer as never); },
|
|
@@ -93,17 +95,19 @@ const failed = (error: unknown): void => { if (ending) return; ending = true; lo
|
|
|
93
95
|
process.on('uncaughtException', failed);
|
|
94
96
|
// VH10: which forwarded header the door believes, and which pages may open a socket. A word it doesn't know stops here.
|
|
95
97
|
const trust = doorTrust(process.env);
|
|
96
|
-
const world: World = await World.open({ build, cells, ...worldSettings(release.channel, process.env), ...trust, secret: need('SEAT_SECRET'), saves, log, boot: bootWorker, ...(grace === undefined ? {} : { graceMs: Number(grace) }),
|
|
98
|
+
const world: World = await World.open({ build, cells, roads: crossing, ...worldSettings(release.channel, process.env), ...trust, secret: need('SEAT_SECRET'), saves, log, boot: bootWorker, ...(grace === undefined ? {} : { graceMs: Number(grace) }),
|
|
97
99
|
// Q77: a worker that fails ends the process. systemd starts it again, clients redial, and saves stand at the last checkpoint.
|
|
98
100
|
crashed: failed, reading: (index, row) => { reports.heard(index, row); },
|
|
99
101
|
...(playtest===undefined?{}:{playtest:row=>{playtest.append(row);}}),
|
|
100
102
|
// J218: phones on 4G need TURN to reach each other's voice. Without the key, voice falls back to public STUN.
|
|
101
103
|
...(turnKey === undefined || turnToken === undefined ? {} : { voiceIce: cloudflareTurn(turnKey, turnToken) }),
|
|
102
104
|
restart: () => { stop(0); } });
|
|
105
|
+
/** SA33's watch, once the door listens; `/health` names its serial. */
|
|
106
|
+
let placements: PlacementWatch | null = null;
|
|
103
107
|
const server = createServer((request, response) => {
|
|
104
108
|
if (request.url !== '/health') { response.writeHead(404).end(); return; }
|
|
105
109
|
// E7.5 prep: any page may read it (no player data), so the Connection doctor sees the build; `now` lets it read a phone's clock.
|
|
106
|
-
response.writeHead(200, { 'content-type': 'application/json', 'access-control-allow-origin': '*', 'cache-control': 'no-store' }).end(JSON.stringify({ ...world.health(), serial: release.serial, uptime: Math.round((Date.now() - started) / 1000), now: Date.now() }));
|
|
110
|
+
response.writeHead(200, { 'content-type': 'application/json', 'access-control-allow-origin': '*', 'cache-control': 'no-store' }).end(JSON.stringify({ ...world.health(), serial: release.serial, ...(placements === null ? {} : { placements: placements.serial }), uptime: Math.round((Date.now() - started) / 1000), now: Date.now() }));
|
|
107
111
|
});
|
|
108
112
|
server.on('upgrade', (request, socket, head) => { world.upgrade(request, socket, head); });
|
|
109
113
|
stop = (code): void => { void (async (): Promise<void> => {
|
|
@@ -131,4 +135,19 @@ const watch = new ReleaseWatch({ read: readRelease, serving: release, cells: sha
|
|
|
131
135
|
for (const slug of shards) await readPackProduct(slug, next.engineBuild, await rapier(), { origin, cache }, reads);
|
|
132
136
|
world.beginGrace(next.engineBuild);
|
|
133
137
|
} });
|
|
134
|
-
|
|
138
|
+
// SA33: a cell the API placed opens on this running server within a look, on a worker of its own, with no grace and no restart. Its shard's
|
|
139
|
+
// server pack must already be in this build's book: one that isn't is refused here, before any worker boots, and asked for again next look.
|
|
140
|
+
placements = placementAt === undefined || placementKey === undefined || listed.trim() !== WHOLE_GRID ? null : new PlacementWatch({
|
|
141
|
+
read: () => fetchPlacementFile(placementAt, placementKey), channel: release.channel, ...(poll === undefined ? {} : { everyMs: Number(poll) }),
|
|
142
|
+
failed: error => { log({ at: 'placement.failed', error: String(error) }); },
|
|
143
|
+
open: async rows => {
|
|
144
|
+
const ready: string[] = [];
|
|
145
|
+
for (const row of rows) {
|
|
146
|
+
// SA34a: the pack first, so the door's placed list (and so every worker's frame numbers) holds only cells it opens.
|
|
147
|
+
try { await readPackProduct(row.slug, build, await rapier(), { origin, cache }, reads); placeCell(row); ready.push(row.instance); }
|
|
148
|
+
catch (error) { log({ at: 'placement.refused', instance: row.instance, slug: row.slug, error: String(error) }); }
|
|
149
|
+
}
|
|
150
|
+
return ready.length === 0 ? [] : world.openCells(ready);
|
|
151
|
+
} });
|
|
152
|
+
void placements?.look();
|
|
153
|
+
process.once('SIGTERM', () => { watch.dispose(); placements?.dispose(); stop(0); });
|