@wildshard/engine 0.1.21 → 0.1.23
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/lint/engine-sides.json +5 -0
- package/lint/shardfile-boundaries.mjs +4 -2
- package/lint/sim-players.json +2 -13
- package/lint/wildshard-plugin.js +1 -1
- package/package.json +10 -2
- package/scripts/apfs-clone.mjs +5 -2
- package/scripts/app-build/catalogue.ts +39 -8
- package/scripts/app-build/serviceWorker.ts +4 -1
- package/scripts/app-build/splitOutput.mjs +33 -11
- package/scripts/audio-download-proof.mjs +1 -1
- package/scripts/check-spelled-paths.mjs +6 -3
- package/scripts/ci-pack.mjs +3 -3
- package/scripts/committed-fast-checks.mjs +2 -2
- package/scripts/engine-ci-shard.mjs +11 -0
- package/scripts/failmode-cases.mjs +1 -1
- package/scripts/failmode-proof.mjs +35 -11
- package/scripts/fight-page-census.mjs +131 -0
- package/scripts/goldens/board.py +44 -11
- package/scripts/goldens/native-residency.d.mts +1 -0
- package/scripts/goldens/native-residency.mjs +18 -4
- package/scripts/grid-crossing-walk-proof.mjs +3 -3
- package/scripts/hover-speed-probe.mjs +2 -2
- package/scripts/keep-copy.mjs +120 -0
- package/scripts/land.mjs +36 -6
- package/scripts/lane-live.mjs +136 -0
- package/scripts/leftovers-report.mjs +47 -0
- package/scripts/loading-card-proof.mjs +42 -9
- package/scripts/loading-flow/benchmax.mjs +57 -7
- package/scripts/loading-flow/stalls.d.mts +2 -0
- package/scripts/loading-flow/stalls.mjs +13 -0
- package/scripts/mmo-bots.mjs +11 -5
- package/scripts/mmo-grid-proof.mjs +74 -0
- package/scripts/mmo-seat-proof.mjs +43 -0
- package/scripts/net-lag-proof.mjs +1 -1
- package/scripts/nightly-heads.ts +13 -13
- package/scripts/nightly-model.ts +26 -12
- package/scripts/nightly.proof.ts +18 -5
- package/scripts/nightly.ts +13 -8
- package/scripts/no-astc-boot.mjs +77 -0
- package/scripts/online-rig.mjs +7 -7
- package/scripts/parity/boot-smoke.mjs +1 -1
- package/scripts/physics-route.json +6 -6
- package/scripts/pins-reuse.mjs +1 -0
- package/scripts/pins-staging.ts +54 -0
- package/scripts/pins.ts +5 -0
- package/scripts/release-cook.mjs +6 -2
- package/scripts/ring3.proof.ts +71 -0
- package/scripts/ring3.ts +100 -0
- package/scripts/scratch-dir.mjs +31 -12
- package/scripts/scratch-sweep.mjs +15 -23
- package/scripts/server-release/items.d.mts +7 -0
- package/scripts/server-release/items.mjs +28 -0
- package/scripts/server-release/publish.mjs +9 -1
- package/scripts/side-parity.mjs +1 -1
- package/scripts/test-products.json +1 -21
- package/scripts/tsconfig.json +2 -0
- package/scripts/vitest-ci-files.ts +5 -1
- package/scripts/vps/cook-follow.d.mts +6 -0
- package/scripts/vps/cook-follow.mjs +45 -0
- package/scripts/vps/harden-apply.sh +10 -1
- package/scripts/vps/rebuild.sh +104 -36
- package/scripts/vps/wildshard-config +106 -3
- package/scripts/warm-native-chrome.mjs +9 -3
- package/scripts/worker-client-fights.mjs +9 -3
- package/scripts/worktree-reap.mjs +15 -131
- package/scripts/worktree.mjs +92 -12
- package/src/client/app/entry.ts +2 -3
- package/src/client/engine/audio/audioLog.ts +7 -2
- package/src/client/engine/boot/contentRead.ts +24 -4
- package/src/client/engine/boot/diagnostics.ts +69 -1
- package/src/client/engine/boot/downloadGiveUp.ts +34 -0
- package/src/client/engine/combat/EquipmentService.ts +2 -0
- package/src/client/engine/core/Game.ts +6 -2
- package/src/client/engine/core/ktx2.ts +5 -3
- package/src/client/engine/core/ktx2Zstd.ts +2 -1
- package/src/client/engine/pwa/sw.js +26 -8
- package/src/client/engine/render/dataLook.ts +14 -7
- package/src/client/engine/render/lookLight.ts +64 -20
- package/src/client/engine/ui/Loading.ts +6 -8
- package/src/client/engine/ui/downloadFailed.ts +54 -0
- package/src/client/engine/ui/lookLightOption.ts +1 -1
- package/src/client/game/audio/cueDirector.ts +2 -1
- package/src/client/game/boot/spawnDownload.ts +12 -1
- package/src/client/game/boss/arenaRoom.ts +4 -3
- package/src/client/game/boss/roamingProjection.ts +1 -1
- package/src/client/game/devScene/hook.ts +1 -1
- package/src/client/game/devScene/liveLook.ts +1 -1
- package/src/client/game/grid/copyPrompts.ts +3 -4
- package/src/client/game/grid/dataCellKit.ts +99 -0
- package/src/client/game/grid/enteredEquipment.ts +11 -2
- package/src/client/game/grid/live.ts +9 -299
- package/src/client/game/grid/liveSession.ts +31 -8
- package/src/client/game/grid/neighbourLife.ts +50 -32
- package/src/client/game/grid/products.ts +21 -7
- package/src/client/game/grid/reveal.ts +7 -2
- package/src/client/game/grid/session.ts +10 -74
- package/src/client/game/plugin/weaponFamily.ts +6 -0
- package/src/client/game/population/signals.ts +1 -1
- package/src/client/game/quest/chapterDirector.ts +1 -0
- package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
- package/src/client/game/shardfile/clientWorker.ts +35 -9
- package/src/client/game/shardfile/look.ts +1 -1
- package/src/client/game/shardfile/runtimeProduct.ts +9 -5
- package/src/client/game/shardfile/wirePage.ts +5 -2
- package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
- package/src/client/host/online/shell.ts +37 -13
- package/src/cook/game/cookWorker.ts +8 -5
- package/src/cook/game/tierTextures.ts +5 -3
- package/src/server/engine/net/simWorld.ts +3 -4
- package/src/server/game/grid/cellHome.ts +58 -0
- package/src/server/game/grid/room.ts +2 -38
- package/src/server/game/grid/simulation.ts +5 -4
- package/src/server/game/plugin/mover.ts +18 -14
- package/src/server/game/shardfile/declaredKitItems.ts +39 -9
- package/src/server/host/bake/headlessWorker.ts +3 -3
- package/src/server/host/dedicated/cellHost.ts +2 -2
- package/src/server/host/dedicated/cellProtocol.ts +1 -1
- package/src/server/host/dedicated/cellWorker.ts +5 -3
- package/src/server/host/dedicated/dedicatedRoom.ts +8 -3
- package/src/server/host/dedicated/gridCells.ts +5 -3
- package/src/server/host/dedicated/main.ts +12 -7
- package/src/server/host/dedicated/packReader.ts +15 -2
- package/src/server/host/dedicated/playerStore.ts +1 -1
- package/src/server/host/dedicated/workerTable.ts +0 -10
- package/src/server/host/dedicated/world.ts +39 -5
- package/src/server/host/headlessRuntime.ts +11 -6
- package/src/server/host/standalone/cellWorld.ts +21 -7
- package/src/server/host/standalone/gridServer.ts +3 -1
- package/src/server/host/standalone/roadWorld.ts +6 -0
- package/src/shared/engine/physics/gridBorders.ts +15 -1
- package/src/shared/engine/saves/shape.ts +17 -2
- package/src/shared/engine/sim/snapshot.ts +5 -5
- package/src/shared/engine/strings.ts +10 -0
- package/src/shared/game/grid/placementRows.ts +4 -3
- package/src/shared/game/ledger.ts +13 -4
- package/src/shared/game/loot/platformCatalogue.ts +14 -0
- package/src/shared/game/quest/ledger.ts +3 -3
- package/src/shared/game/shardfile/items.ts +9 -1
- package/src/shared/host/headlessJourney.ts +3 -3
- package/src/shared/host/headlessTape.ts +7 -6
- package/src/shared/host/releaseRows.ts +4 -1
- package/src/client/game/grid/cellLoading.ts +0 -110
- package/src/client/game/grid/cellScreens.ts +0 -48
|
@@ -122,7 +122,7 @@ export interface WorldOptions {
|
|
|
122
122
|
/** VH10: the pages a browser may open a socket from; `null` is any. The game's own hosts when absent. */
|
|
123
123
|
readonly allowedOrigins?: readonly string[] | null;
|
|
124
124
|
/**
|
|
125
|
-
*
|
|
125
|
+
* J353: each worker hosts a road. SA34a: a placed cell then opens on the worker of its nearest open cell, whose
|
|
126
126
|
* road hands a seat into it, and every worker's road is told of it; without roads it boots on a worker of its own (SA33).
|
|
127
127
|
*/
|
|
128
128
|
readonly roads?: boolean;
|
|
@@ -146,6 +146,10 @@ export class World {
|
|
|
146
146
|
/** The static table: which worker each cell is on (J182). */
|
|
147
147
|
private readonly links = new Map<string, WorkerLink>();
|
|
148
148
|
private readonly workers: WorkerLink[] = [];
|
|
149
|
+
/** The row each worker owns, retained for a planned replacement. */
|
|
150
|
+
private readonly workerSlugs = new Map<WorkerLink, readonly string[]>();
|
|
151
|
+
/** A replacement's old worker may exit without taking the whole server down. */
|
|
152
|
+
private readonly replacing = new Set<WorkerLink>();
|
|
149
153
|
private readonly sockets = new Map<string, number>();
|
|
150
154
|
private readonly connects = new Map<string, ConnectAttempt[]>();
|
|
151
155
|
private readonly ends = new Set<SocketTransport>();
|
|
@@ -201,13 +205,16 @@ export class World {
|
|
|
201
205
|
}
|
|
202
206
|
/** A worker on its row. At startup its cells are in the table at once, and any failure ends the process (Q77). SA33: a `late` worker's cells
|
|
203
207
|
* join the table only once it has booted, and one that fails to boot is let go with nobody seated on it; after its boot it is like any. */
|
|
204
|
-
private bootWorker(slugs: readonly string[], late = false): Promise<void> {
|
|
205
|
-
const link = this.options.boot(slugs), index = this.workers.push(link) - 1;
|
|
208
|
+
private bootWorker(slugs: readonly string[], late = false, slot?: number): Promise<void> {
|
|
209
|
+
const link = this.options.boot(slugs), index = slot ?? this.workers.push(link) - 1;
|
|
210
|
+
if (slot !== undefined) this.workers[slot] = link;
|
|
211
|
+
this.workerSlugs.set(link, slugs);
|
|
206
212
|
if (!late) for (const slug of slugs) this.links.set(slug, link);
|
|
207
213
|
let up = false;
|
|
208
214
|
return new Promise((resolve, reject) => {
|
|
209
215
|
const ended = (reason: string): void => {
|
|
210
|
-
this.options.log({ at: 'worker.ended', index, slugs, reason }); reject(new Error(reason)); this.up.delete(link); this.resident.delete(link);
|
|
216
|
+
this.options.log({ at: 'worker.ended', index, slugs, reason }); reject(new Error(reason)); this.up.delete(link); this.resident.delete(link); this.stands.delete(link); this.workerSlugs.delete(link);
|
|
217
|
+
if (this.replacing.delete(link)) return;
|
|
211
218
|
if (late && !up) { link.stop(); if (this.workers.at(-1) === link) this.workers.pop(); return; }
|
|
212
219
|
this.options.crashed(new Error(reason));
|
|
213
220
|
};
|
|
@@ -217,6 +224,33 @@ export class World {
|
|
|
217
224
|
}, ended);
|
|
218
225
|
});
|
|
219
226
|
}
|
|
227
|
+
/** MP1.3: replace an idle worker without exposing a process or host control surface. Seats need the drain/reconnect half first. */
|
|
228
|
+
async restartWorker(index: number): Promise<void> {
|
|
229
|
+
const old = this.workers[index], slugs = old === undefined ? undefined : this.workerSlugs.get(old);
|
|
230
|
+
if (old === undefined || slugs === undefined) throw new Error(`No worker ${String(index)}`);
|
|
231
|
+
if ([...this.seated.values()].some(slug => this.linkOf(slug) === old)) throw new Error('A worker with seated players needs drain and reconnect');
|
|
232
|
+
this.options.log({ at: 'worker.restarting', index, slugs });
|
|
233
|
+
this.replacing.add(old); this.up.delete(old); this.resident.delete(old); this.stands.delete(old); old.stop();
|
|
234
|
+
await this.bootWorker(slugs, false, index);
|
|
235
|
+
this.openRoads();
|
|
236
|
+
}
|
|
237
|
+
/** MP1.3: drain one worker's seats through their normal save-and-redial path, then replace only that worker. */
|
|
238
|
+
async restartDrainedWorker(index: number): Promise<void> {
|
|
239
|
+
const old = this.workers[index], slugs = old === undefined ? undefined : this.workerSlugs.get(old);
|
|
240
|
+
if (old === undefined || slugs === undefined) throw new Error(`No worker ${String(index)}`);
|
|
241
|
+
this.options.log({ at: 'worker.draining', index, slugs });
|
|
242
|
+
const drained = new Promise<void>(resolve => {
|
|
243
|
+
const timer = this.scope.timeout(DRAIN_MS, resolve);
|
|
244
|
+
this.drains.set(index, () => { this.scope.cancelTimer(timer); resolve(); });
|
|
245
|
+
old.send({ kind: 'drain', leave: true });
|
|
246
|
+
});
|
|
247
|
+
await drained;
|
|
248
|
+
if (!await this.options.saves.drain(DRAIN_MS)) throw new Error('Worker save drain timed out');
|
|
249
|
+
if ([...this.seated.values()].some(slug => this.linkOf(slug) === old)) throw new Error('Worker drain left seated players');
|
|
250
|
+
this.replacing.add(old); this.up.delete(old); this.resident.delete(old); this.stands.delete(old); old.stop();
|
|
251
|
+
await this.bootWorker(slugs, false, index);
|
|
252
|
+
this.openRoads();
|
|
253
|
+
}
|
|
220
254
|
/**
|
|
221
255
|
* SA33: open cells on a running world (a placement the API made, J314) on a worker of their own. No other worker is told anything, so every
|
|
222
256
|
* player in another cell stays where they are, and the door seats a player in a new cell only once its worker has booted. A cell this world
|
|
@@ -460,7 +494,7 @@ export class World {
|
|
|
460
494
|
}
|
|
461
495
|
/**
|
|
462
496
|
* GC15: a seat's feet left cell `from` for `to`. On the same worker the door reads their save on `to`'s shard and orders the move, which
|
|
463
|
-
* keeps the seat and the socket. A cell and its worker's road
|
|
497
|
+
* keeps the seat and the socket. A cell and its worker's road cross the same way, with no save to read for the road. Between workers nothing moves yet (GC15 (3): `exportPlayer`/`importPlayer` and re-pointing the socket).
|
|
464
498
|
*/
|
|
465
499
|
private async crossing(from: string, device: string, to: string, at: ResumeAt): Promise<void> {
|
|
466
500
|
const link = this.linkOf(to), name = this.names.get(device);
|
|
@@ -16,7 +16,6 @@ import { HEADLESS_ARENA } from '@wildshard/engine/game/boss/headlessArenaViews';
|
|
|
16
16
|
import type { NativeSweptMeleeInput } from '@wildshard/engine/game/plugin/nativeSwept';
|
|
17
17
|
import { installPortableMath } from '@wildshard/engine/core/portableMath';
|
|
18
18
|
import { createSimHost, type SimHost, type SimHostPorts, type SimLevel, type SimTickCommand } from '@wildshard/engine/sim';
|
|
19
|
-
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
20
19
|
import { shardRows } from '@wildshard/engine/sim/shardRows';
|
|
21
20
|
import type { NetCommand } from '@wildshard/wire/netCommand';
|
|
22
21
|
import type { NetTickAct } from '@wildshard/engine/net/acts';
|
|
@@ -38,12 +37,16 @@ import type { ShardProduct } from '@wildshard/engine/game/shardfile/shardProduct
|
|
|
38
37
|
import { prepareProductRuntimePlan } from '@wildshard/engine/game/shardfile/nativePlan';
|
|
39
38
|
import { holdPageState, type RuntimeStateValue } from '@wildshard/engine/game/shardfile/runtimeState';
|
|
40
39
|
import type { NativeAssemblyPorts } from '@wildshard/engine/game/shardfile/nativeAssemblyInput';
|
|
40
|
+
import type { LedgerCatalogueItem } from '@wildshard/engine/game/ledger';
|
|
41
|
+
import { installCellHome } from '@wildshard/engine/game/grid/cellHome';
|
|
41
42
|
|
|
42
43
|
/** The same admitted bytes and native physics implementation used by the ordinary headless worker. */
|
|
43
44
|
export interface HeadlessRuntimePreparation { shard: Shardfile; assets: ReadonlyMap<string, Uint8Array>; rapier: Rapier; readonly product: ShardProduct }
|
|
44
45
|
/** Build workers carry verified native sections before any output exists.
|
|
45
46
|
* Existing native callers may instead supply or explicitly load their built product. */
|
|
46
|
-
export type HeadlessRuntimeInput = Omit<HeadlessRuntimePreparation, 'product'> & { readonly product?: ShardProduct; readonly sections?: ReadonlyMap<string, unknown
|
|
47
|
+
export type HeadlessRuntimeInput = Omit<HeadlessRuntimePreparation, 'product'> & { readonly product?: ShardProduct; readonly sections?: ReadonlyMap<string, unknown>;
|
|
48
|
+
/** Q37: the installed release's immutable trusted catalogue, never the shard's own data. */
|
|
49
|
+
readonly catalogue?: readonly LedgerCatalogueItem[] };
|
|
47
50
|
/** Current tick inputs and buffered effects; only a completed tick publishes them to the parent. */
|
|
48
51
|
/** What a page's save held, for a world's first boot: its quest flags and its declared fields, up before its fights install. */
|
|
49
52
|
export interface PageProgress { readonly flags: readonly string[]; readonly state: ReadonlyMap<string, RuntimeStateValue> }
|
|
@@ -234,7 +237,7 @@ export async function prepareNativeRuntime(provided: HeadlessRuntimeInput, room?
|
|
|
234
237
|
}
|
|
235
238
|
/** Install the selected plan into one fresh or strictly restored native host.
|
|
236
239
|
* A failed install disposes its world; installation may emit no gameplay effects. */
|
|
237
|
-
export async function createTrustedHeadlessResident(preparation: HeadlessRuntimeInput, snapshot?: string | Readonly<SimSnapshot | SimSnapshotBytes>, world?: { readonly room?: boolean; readonly near?: NearColliders; readonly page?: PageProgress }): Promise<TrustedHeadlessResident> {
|
|
240
|
+
export async function createTrustedHeadlessResident(preparation: HeadlessRuntimeInput, snapshot?: string | Readonly<SimSnapshot | SimSnapshotBytes>, world?: { readonly room?: boolean; readonly grid?: boolean; readonly near?: NearColliders; readonly page?: PageProgress }): Promise<TrustedHeadlessResident> {
|
|
238
241
|
// The roster rolls its herds while this installs, so a room opened afterwards is too late: a save from a native-Math boot
|
|
239
242
|
// would hold recipes its restore on the portable table can't reproduce.
|
|
240
243
|
installPortableMath();
|
|
@@ -247,18 +250,20 @@ export async function createTrustedHeadlessResident(preparation: HeadlessRuntime
|
|
|
247
250
|
const otherCommands = new Map<string, readonly HeadlessCommand[]>();
|
|
248
251
|
const context: HeadlessRuntimeInstallation = { combat, ...(world?.room === true ? { room: true } : {}), restoring: saved !== undefined, ...(saved === undefined ? {} : { snapshot: saved }), commands: () => commands, playerCommands: id => otherCommands.get(id) ?? [], emit: effect => { effects.push(effect); } };
|
|
249
252
|
const ports = { ...plan.ports, rapier: preparation.rapier };
|
|
253
|
+
const install = (target: SimHost): void => { plan.install(target, context); if (world?.grid === true) installCellHome(target); };
|
|
250
254
|
let installing: SimHost | undefined;
|
|
251
255
|
let host: SimHost;
|
|
252
256
|
try {
|
|
253
|
-
if (saved === undefined) { installing = createSimHost(plan.level, ports); if (world?.near !== undefined) { installing.physics.near = world.near; world.near.attach(installing.physics); } if (world?.page !== undefined) { for (const flag of world.page.flags) installing.flags.set(flag); holdPageState(installing, world.page.state); }
|
|
257
|
+
if (saved === undefined) { installing = createSimHost(plan.level, ports); if (world?.near !== undefined) { installing.physics.near = world.near; world.near.attach(installing.physics); } if (world?.page !== undefined) { for (const flag of world.page.flags) installing.flags.set(flag); holdPageState(installing, world.page.state); } install(installing); host = installing; }
|
|
254
258
|
else host = restoreSimHost(plan.level, ports, saved, fresh => {
|
|
255
|
-
installing = fresh; if (ports.heightAt !== undefined) fresh.setHeightQuery(ports.heightAt);
|
|
259
|
+
installing = fresh; if (ports.heightAt !== undefined) fresh.setHeightQuery(ports.heightAt); install(fresh);
|
|
256
260
|
});
|
|
257
261
|
if (effects.length > 0) throw new Error('Trusted runtime emitted gameplay effects during installation');
|
|
258
262
|
if (saved !== undefined && world?.near !== undefined) { host.physics.near = world.near; world.near.attach(host.physics); }
|
|
259
263
|
} catch (error) { installing?.dispose(); throw error; }
|
|
260
264
|
if (plan.economy !== undefined) installRoomLoot(host, plan.economy, context);
|
|
261
|
-
const lead =
|
|
265
|
+
const lead = host.players.get('actor.player');
|
|
266
|
+
if (lead === undefined) throw new RangeError('Unknown trusted runtime owner');
|
|
262
267
|
// ENG-18: a room catches its seats' falls itself (cellWorld's FallFloor); a resident alone catches its own, or nobody does.
|
|
263
268
|
const caught = world?.room === true ? null : residentFallNet(host, shardPlayArea(preparation.shard.manifest?.bounds, preparation.product), host.level.player.at);
|
|
264
269
|
if (caught !== null && preparation.product !== undefined) registerInstalled(host, 'fallFloor'); // SS3: the page's play area, read off its rows
|
|
@@ -7,7 +7,6 @@ import { removeChunkEdgeWalls } from '@wildshard/engine/physics/terrain';
|
|
|
7
7
|
import type { SimHost } from '@wildshard/engine/sim';
|
|
8
8
|
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
9
9
|
import { actRoutes } from '@wildshard/engine/sim/actRoutes';
|
|
10
|
-
import type { PlaceArea } from '@wildshard/engine/quest/lastPlace';
|
|
11
10
|
import { questBooks } from '@wildshard/engine/quest/players';
|
|
12
11
|
import { decodeSimSnapshot, type SimSnapshot } from '@wildshard/engine/sim/snapshot';
|
|
13
12
|
import { restoreSimHost } from '@wildshard/engine/sim/restore';
|
|
@@ -24,7 +23,10 @@ import { installPlayerOwned, type OwnedBook, type OwnedStores, type CreatureRewa
|
|
|
24
23
|
import { QUEST_OWNED } from '@wildshard/engine/game/quest/nativeComposition';
|
|
25
24
|
import { shardRows } from '@wildshard/engine/sim/shardRows';
|
|
26
25
|
import { createQuestLedger } from '@wildshard/engine/game/quest/ledger';
|
|
27
|
-
import {
|
|
26
|
+
import { admitLedgerRewards } from '@wildshard/engine/game/ledger';
|
|
27
|
+
import { installCellHome } from '@wildshard/engine/game/grid/cellHome';
|
|
28
|
+
import { serverDiscoveries, serverPlaces } from '@wildshard/engine/game/quest/serverPlaces';
|
|
29
|
+
import type { PlaceArea } from '@wildshard/engine/quest/lastPlace';
|
|
28
30
|
import { RESPAWN_NOW_ACT, STORY_ACT, UNSTUCK_ACT } from '@wildshard/engine/net/acts';
|
|
29
31
|
import { installServerChapters } from '@wildshard/engine/game/quest/serverChapters';
|
|
30
32
|
import { installServerDoors } from '@wildshard/engine/game/quest/serverDoors';
|
|
@@ -64,7 +66,7 @@ export interface CellWorld extends GridResident {
|
|
|
64
66
|
/** What a host lends a cell it opens. */
|
|
65
67
|
export interface CellWorldOptions {
|
|
66
68
|
readonly saves: SaveStore;
|
|
67
|
-
/** A
|
|
69
|
+
/** A one-shard page's fall floor sets a player back on the ground they last
|
|
68
70
|
* stood on instead of a death. It has no edge walls (GC36, J322), so past its edge a player falls to that floor. */
|
|
69
71
|
readonly lone: boolean;
|
|
70
72
|
/** C6: a room holds every solid, since no one list can follow every player. Left out, a native world keeps its solids near its lead. */
|
|
@@ -105,13 +107,14 @@ async function openDataCell(input: HeadlessRuntimeInput, snapshot: string | SimS
|
|
|
105
107
|
const kitOf = (sim: ShardfileSimulation): DeclaredKitItems | null => installDeclaredKitItems(sim.host, shard, sim.itemHooks);
|
|
106
108
|
if (snapshot === undefined) {
|
|
107
109
|
const fresh = createShardfileSim(shard, assets, ports), kit = kitOf(fresh);
|
|
110
|
+
installCellHome(fresh.host);
|
|
108
111
|
// SS3: a data shard's simulation builds its declared prop solids; a shard with none built has no server half to claim
|
|
109
112
|
if (fresh.colliders.size > 0) registerInstalled(fresh.host, 'collision');
|
|
110
113
|
return { host: fresh.host, sim: () => fresh, kit: () => kit, dispose: () => { fresh.dispose(); } };
|
|
111
114
|
}
|
|
112
115
|
const probe = createShardfileSim(shard, assets, ports), { level } = probe.host; probe.dispose();
|
|
113
116
|
const installed: { value?: ReturnType<typeof bindShardfileSim>; kit?: DeclaredKitItems | null } = {};
|
|
114
|
-
const host = restoreSimHost(level, { rapier }, typeof snapshot === 'string' ? decodeSimSnapshot(snapshot) : snapshot, restored => { installed.value = bindShardfileSim(restored, shard, assets, { ...ports, restoring: true }); installed.kit = kitOf(installed.value); if (installed.value.colliders.size > 0) registerInstalled(restored, 'collision'); });
|
|
117
|
+
const host = restoreSimHost(level, { rapier }, typeof snapshot === 'string' ? decodeSimSnapshot(snapshot) : snapshot, restored => { installed.value = bindShardfileSim(restored, shard, assets, { ...ports, restoring: true }); installed.kit = kitOf(installed.value); installCellHome(restored); if (installed.value.colliders.size > 0) registerInstalled(restored, 'collision'); });
|
|
115
118
|
return { host, sim: () => installed.value, kit: () => installed.kit ?? null, dispose: () => { (installed.value ?? { dispose: () => { host.dispose(); } }).dispose(); } };
|
|
116
119
|
}
|
|
117
120
|
|
|
@@ -135,18 +138,29 @@ function ownedOf(host: SimHost, input: HeadlessRuntimeInput, stores: OwnedStores
|
|
|
135
138
|
return installPlayerOwned(host, input.shard.identity.slug, sold ?? null, !shardRows(host).owned.has(QUEST_OWNED), stores, input.shard, profiles);
|
|
136
139
|
}
|
|
137
140
|
|
|
141
|
+
/** The radius a data cell's place takes when its manifest POI names none. */
|
|
142
|
+
const PLACE_RADIUS = 8;
|
|
143
|
+
/** Where a fallen player in a data cell comes back (TEMPLATE-E2E TC-E3, J361: "the last camp or the depot"): the product's
|
|
144
|
+
* published places, else the shard's own map POIs. A cell with neither respawns at the shard's spawn, as before. */
|
|
145
|
+
export async function dataCellPlaces(input: Pick<HeadlessRuntimeInput, 'shard' | 'product'>): Promise<readonly PlaceArea[]> {
|
|
146
|
+
const published = input.product === undefined ? [] : await serverPlaces(input.product);
|
|
147
|
+
if (published.length > 0) return published;
|
|
148
|
+
return (input.shard.manifest?.pois ?? []).map(poi => ({ id: poi.id, label: poi.name, x: poi.x, z: poi.z, r: poi.r ?? PLACE_RADIUS }));
|
|
149
|
+
}
|
|
150
|
+
|
|
138
151
|
/** Whether this output runs on the trusted headless owner. */
|
|
139
152
|
export const nativeCell = (input: HeadlessRuntimeInput): boolean => input.product !== undefined && (hasNativeAssembly(input.product) || input.product.has('sim/runtime-plan'));
|
|
140
153
|
|
|
141
154
|
/** Open `cell`'s world from `input`, at `snapshot` if there is one. */
|
|
142
155
|
export async function openCellWorld(cell: Pick<GridCell, 'instance'>, input: HeadlessRuntimeInput, snapshot: string | SimSnapshot | undefined, options: CellWorldOptions, refused?: SimSnapshot): Promise<CellWorld> {
|
|
156
|
+
admitLedgerRewards(input.shard.ledger, input.catalogue ?? []);
|
|
143
157
|
const declared = new Set(input.shard.ledger.map(row => row.fact)), placed = { id: cell.instance, shard: input.shard.identity.slug }, { facts, lone } = options;
|
|
144
|
-
const ledger = facts === undefined ? createQuestLedger(options.saves, input.shard, cell.instance) : null;
|
|
158
|
+
const ledger = facts === undefined ? createQuestLedger(options.saves, input.shard, cell.instance, input.catalogue) : null;
|
|
145
159
|
const fact: CellWorld['fact'] = (name, entity, player) => !declared.has(name) ? null : ledger === null ? facts?.(name, entity, player, input) ?? null : ledger(name, entity);
|
|
146
160
|
if (nativeCell(input)) {
|
|
147
161
|
// J68: a native assembly keeps its ground whole and its solids as data. A saved world holds none of them, so a throwaway fresh one lists them.
|
|
148
162
|
const near = options.wholeSolids !== true && input.product !== undefined && hasNativeAssembly(input.product) ? new NearColliders() : undefined;
|
|
149
|
-
const around = { room: true, ...(near === undefined ? {} : { near }) };
|
|
163
|
+
const around = { room: true, grid: true, ...(near === undefined ? {} : { near }) };
|
|
150
164
|
if (near !== undefined && snapshot !== undefined) (await bootTask('server:restore-collision-inventory', () => createTrustedHeadlessResident(input, undefined, around))).dispose();
|
|
151
165
|
// A world with no save of its own takes the page's: the flags and records its fights read as they install.
|
|
152
166
|
const seeded = snapshot === undefined && options.pageless !== true;
|
|
@@ -165,7 +179,7 @@ export async function openCellWorld(cell: Pick<GridCell, 'instance'>, input: Hea
|
|
|
165
179
|
}
|
|
166
180
|
const effects: HeadlessEffect[] = [], { host, dispose, sim, kit } = await bootTask(snapshot === undefined ? 'server:data-simulation-and-collision' : 'server:data-continuation-restore', () => openDataCell(input, snapshot, effects));
|
|
167
181
|
if (snapshot !== undefined) removeChunkEdgeWalls(host.physics); // GC36: a world saved while lone cells had walls
|
|
168
|
-
installRoomRespawn(host,
|
|
182
|
+
installRoomRespawn(host, await dataCellPlaces(input));
|
|
169
183
|
installDeclaredClimate(host, input.shard.rows);
|
|
170
184
|
bindDiscovery(host, input.product === undefined ? [] : await serverDiscoveries(input.product));
|
|
171
185
|
host.respawn.served = true; actRoutes(host).introLocks = true;
|
|
@@ -33,7 +33,7 @@ import { landedBy } from '@wildshard/engine/combat/damageBook';
|
|
|
33
33
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
34
34
|
import { actRoutes } from '@wildshard/engine/sim/actRoutes';
|
|
35
35
|
import { openCellWorld, type CellWorld, type CellWorldOptions } from './cellWorld';
|
|
36
|
-
import { addCellWalls, addVoidFloor, renewVoidFloor, ROAD } from './roadWorld';
|
|
36
|
+
import { addCellWalls, addVoidFloor, installRoadCombat, renewVoidFloor, ROAD } from './roadWorld';
|
|
37
37
|
import { netBuys, netWorldInput } from '../../../shared/host/standalone/netInput';
|
|
38
38
|
import { cellDocuments, CONTINUATION, ContinuationSlots, SITE, siteDocuments, type SavedContinuation, type SavedSite } from './continuation';
|
|
39
39
|
import { ledgerFilings } from './ledgerFilings';
|
|
@@ -198,11 +198,13 @@ export class StandaloneGrid {
|
|
|
198
198
|
try {
|
|
199
199
|
const restored = restoreSimHost(ROAD, { rapier }, decodeSimSnapshot(saved)), player = sessionPlayer(restored);
|
|
200
200
|
if (renewVoidFloor(restored, cells, player.position, ROAD_SKIN)) player.motor.resetAt(player.position);
|
|
201
|
+
installRoadCombat(restored);
|
|
201
202
|
holdStrips(restored, strips.map(strip => strip.mesh));
|
|
202
203
|
return restored;
|
|
203
204
|
} catch (error) { refused?.(error); } // a road holds no progress but where the player stood
|
|
204
205
|
}
|
|
205
206
|
const road = createSimHost(ROAD, { rapier }), [x, y, z] = readableSnapshot(saved ?? '')?.players[0]?.position ?? [], stood = arrival ?? (x === undefined || y === undefined || z === undefined ? undefined : { x, y, z });
|
|
207
|
+
installRoadCombat(road);
|
|
206
208
|
addCellWalls(road, cells);
|
|
207
209
|
addVoidFloor(road, cells);
|
|
208
210
|
holdStrips(road, strips.map(strip => strip.mesh));
|
|
@@ -85,12 +85,18 @@ export function renewVoidFloor(road: SimHost, cells: readonly Pick<GridCell, 'ce
|
|
|
85
85
|
export function buildStrips(host: SimHost, meshes: readonly GridCollisionStrip['mesh'][]): void {
|
|
86
86
|
withOwner(host.scope, () => { for (const mesh of meshes) stripCollider(host.physics, mesh); });
|
|
87
87
|
}
|
|
88
|
+
/** The road admits no ordinary damage, including scripted environmental hits.
|
|
89
|
+
* Terminal out-of-world falls retain CombatPipeline.fall's recovery path. */
|
|
90
|
+
export function installRoadCombat(road: SimHost): void {
|
|
91
|
+
road.events.answer('damage.admit', () => null, road.scope);
|
|
92
|
+
}
|
|
88
93
|
/**
|
|
89
94
|
* GC15: a dedicated worker's road, with nobody on it yet: every strip built, the void's floor round `placed` (SA34), and walls only round `walled`, the cells it can't hand a
|
|
90
95
|
* seat to (those on another worker: GC7's one line). Its lead seat is the room's to park.
|
|
91
96
|
*/
|
|
92
97
|
export function openRoad(rapier: Rapier, walled: readonly Pick<GridCell, 'origin'>[], strips: readonly GridCollisionStrip[], placed: readonly Pick<GridCell, 'cell'>[]): SimHost {
|
|
93
98
|
const road = createSimHost(ROAD, { rapier });
|
|
99
|
+
installRoadCombat(road);
|
|
94
100
|
addCellWalls(road, walled);
|
|
95
101
|
addVoidFloor(road, placed);
|
|
96
102
|
buildStrips(road, strips.map(strip => strip.mesh));
|
|
@@ -3,6 +3,7 @@ import { withOwner } from '../app/ownership';
|
|
|
3
3
|
import { CELL_ABOVE, CELL_BELOW, CHUNK_HALF } from '../core/config';
|
|
4
4
|
import type { Physics } from './Physics';
|
|
5
5
|
import { groups, queryGroups } from './groups';
|
|
6
|
+
import { tagCollider } from './surface';
|
|
6
7
|
|
|
7
8
|
const ORIGIN = { x: 0, y: 0, z: 0 };
|
|
8
9
|
interface Point { x: number; y: number; z: number }
|
|
@@ -12,9 +13,22 @@ export function installGridBorders(physics: Physics, scope: Scope, origin: Reado
|
|
|
12
13
|
if (scope.disposed) return;
|
|
13
14
|
const { R, world } = physics;
|
|
14
15
|
const halfHeight = (CELL_ABOVE + CELL_BELOW) / 2, y = origin.y + (CELL_ABOVE - CELL_BELOW) / 2;
|
|
16
|
+
const border = groups('BORDER'), near = (a: number, b: number): boolean => Math.abs(a - b) < .001;
|
|
15
17
|
withOwner(scope, () => {
|
|
16
18
|
for (const [dx, dz, hx, hz] of [[CHUNK_HALF + 0.5, 0, 0.5, CHUNK_HALF + 1], [-CHUNK_HALF - 0.5, 0, 0.5, CHUNK_HALF + 1], [0, CHUNK_HALF + 0.5, CHUNK_HALF + 1, 0.5], [0, -CHUNK_HALF - 0.5, CHUNK_HALF + 1, 0.5]] as const) {
|
|
17
|
-
|
|
19
|
+
// A restored world already carries its walls. Match their actual shape,
|
|
20
|
+
// rather than an in-memory handle from the physics world it replaced.
|
|
21
|
+
let installed = false;
|
|
22
|
+
world.forEachCollider(collider => {
|
|
23
|
+
if (collider.collisionGroups() !== border || collider.shapeType() !== R.ShapeType.Cuboid || collider.isSensor() || collider.parent() !== null) return;
|
|
24
|
+
const at = collider.translation(), half = collider.halfExtents(), rotation = collider.rotation();
|
|
25
|
+
if (half !== null && near(at.x, origin.x + dx) && near(at.y, y) && near(at.z, origin.z + dz)
|
|
26
|
+
&& near(half.x, hx) && near(half.y, halfHeight) && near(half.z, hz)
|
|
27
|
+
&& near(Math.abs(rotation.w), 1) && near(rotation.x, 0) && near(rotation.y, 0) && near(rotation.z, 0)) {
|
|
28
|
+
installed = true; tagCollider(collider, 'edge', 'grid.home');
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (!installed) tagCollider(world.createCollider(R.ColliderDesc.cuboid(hx, halfHeight, hz).setTranslation(origin.x + dx, y, origin.z + dz).setCollisionGroups(border)), 'edge', 'grid.home');
|
|
18
32
|
}
|
|
19
33
|
});
|
|
20
34
|
}
|
|
@@ -15,14 +15,29 @@ const optionsOf = (schema: Node): readonly Schema[] => schema['options'] as Sche
|
|
|
15
15
|
const lazy = (schema: Node, input: unknown): Schema => (schema['getter'] as (input: unknown) => Schema)(input);
|
|
16
16
|
/** A lazy getter that cannot answer without its input: whatever it reaches is unknown. */
|
|
17
17
|
const OPAQUE: Node = { type: 'opaque' };
|
|
18
|
+
/** A lazy getter that takes no input answers the same for every value: its answer, once per lazy schema. */
|
|
19
|
+
const resolvedLazies = new WeakMap<object, unknown>();
|
|
20
|
+
function inputFree(s: Node): unknown {
|
|
21
|
+
const getter = s['getter'];
|
|
22
|
+
if (typeof getter !== 'function' || getter.length > 0) return OPAQUE;
|
|
23
|
+
if (!resolvedLazies.has(s)) {
|
|
24
|
+
let answer: unknown = OPAQUE;
|
|
25
|
+
try { answer = (getter as () => unknown)(); } catch { /* a getter that throws without input is opaque */ }
|
|
26
|
+
resolvedLazies.set(s, answer);
|
|
27
|
+
}
|
|
28
|
+
return resolvedLazies.get(s);
|
|
29
|
+
}
|
|
18
30
|
/** The schemas directly inside `schema`. A lazy one's is its getter's answer with no input. */
|
|
19
31
|
function children(s: Node): unknown[] {
|
|
20
32
|
const out: unknown[] = [];
|
|
21
33
|
for (const key of ['wrapped', 'item', 'value', 'rest']) if (record(s[key])) out.push(s[key]);
|
|
22
34
|
if (record(s['entries'])) out.push(...Object.values(s['entries']));
|
|
23
35
|
for (const key of ['items', 'options']) if (Array.isArray(s[key])) out.push(...(s[key] as unknown[]).filter(record));
|
|
24
|
-
// A lazy getter's answer can depend on its input: whatever it reaches is unknown until a real value resolves it.
|
|
25
|
-
|
|
36
|
+
// A lazy getter's answer can depend on its input: whatever it reaches is unknown until a real value resolves it. One that
|
|
37
|
+
// declares no input can't (the JSON slots' recursive `v.lazy(() => …)`): its answer is walked like any child, so a save of
|
|
38
|
+
// plain JSON reaches no object and `known` / `keepUnknown` return it as is (NINE-DRAGON-BENCHMAX NB2: walking each boot
|
|
39
|
+
// trace write cost ~85 ms at CPU x4, ~24 s of Nine's shaders and firstFrame on NB1).
|
|
40
|
+
if (s.type === 'lazy') return [inputFree(s)];
|
|
26
41
|
return out.filter(child => child === OPAQUE || (record(child) && child['kind'] === 'schema'));
|
|
27
42
|
}
|
|
28
43
|
/** Which object types a schema reaches, once per schema: `strict` for `known`, `objects` for `keepUnknown`. Most save
|
|
@@ -4,7 +4,6 @@ import { byteArray } from './snapshotPhysics';
|
|
|
4
4
|
import type { QuestBookSaved } from '../quest/players';
|
|
5
5
|
import type { SimHost, SimLevel, SimSlots, SimValue } from '../../../server/engine/sim';
|
|
6
6
|
import { SIM_API_VERSION } from './apiVersion';
|
|
7
|
-
import { leadPlayer } from './leadPlayer';
|
|
8
7
|
import type { PlayerSim } from '../../../server/engine/sim/playerSim';
|
|
9
8
|
import { SHOVE_TIME } from '../player/shove';
|
|
10
9
|
import type { DrivenMode } from '../player/modes';
|
|
@@ -160,7 +159,7 @@ function encode(value: unknown, host: SimHost, parents = new Set<object>()): Eve
|
|
|
160
159
|
if (value === null || typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') return { kind: 'value', value };
|
|
161
160
|
if (typeof value !== 'object') throw new TypeError('Snapshot payload contains a callback or unsupported value');
|
|
162
161
|
for (const player of host.players.values()) {
|
|
163
|
-
if (value === player || player.isExternalObject(value)) return
|
|
162
|
+
if (value === player || player.isExternalObject(value)) return { kind: 'player', id: player.id };
|
|
164
163
|
if (value === player.position) return { kind: 'position', id: player.id };
|
|
165
164
|
if (value === player.health) return { kind: 'actor', id: player.id };
|
|
166
165
|
}
|
|
@@ -181,7 +180,7 @@ function decode(value: EventValue, host: SimHost): unknown {
|
|
|
181
180
|
switch (value.kind) {
|
|
182
181
|
case 'value': return value.value;
|
|
183
182
|
case 'undefined': return undefined;
|
|
184
|
-
case 'player': { const player =
|
|
183
|
+
case 'player': { const player = host.players.get(value.id ?? 'actor.player'); if (player === undefined) throw new RangeError(`Unknown snapshot player: ${value.id ?? ''}`); return player; }
|
|
185
184
|
case 'number': return value.value === 'nan' ? Number.NaN : value.value === 'infinity' ? Infinity : -Infinity;
|
|
186
185
|
case 'vector': {
|
|
187
186
|
if (value.value.length !== 3 || !value.value.every(Number.isFinite)) throw new RangeError('Invalid event vector');
|
|
@@ -406,9 +405,10 @@ export function restoreInstalledHost(host: SimHost, ports: { rapier: Rapier }, s
|
|
|
406
405
|
let replacement: Physics | null = null;
|
|
407
406
|
try {
|
|
408
407
|
install?.(host);
|
|
409
|
-
//
|
|
408
|
+
// Restores boot an owned actor.player host. Registry order cannot change that legacy identity.
|
|
409
|
+
// The installers ran for that owner; everyone else rejoins before their state lands.
|
|
410
410
|
for (const entry of saved.players.slice(1)) if (!host.players.has(entry.id)) host.addPlayer(entry.id);
|
|
411
|
-
if (saved.players[0]?.id !==
|
|
411
|
+
if (saved.players[0]?.id !== 'actor.player' || !sameIds(saved.players.map((entry) => entry.id), host.players.keys()) || !sameIds(saved.entities.map((entry) => entry.id), host.entities.keys())
|
|
412
412
|
|| !sameIds(saved.strikes.map((entry) => entry.id), host.strikes.keys()) || !sameIds(saved.adapters.map((entry) => entry.id), [...host.adapters].filter(([id, adapter]) => adapter.joined !== true || saved.adapters.some(entry => entry.id === id)).map(([id]) => id))
|
|
413
413
|
|| !sameIds(saved.quests.map((entry) => entry.id), host.quests.map((quest) => quest.def.id))
|
|
414
414
|
|| saved.players.some(invalidPlayer) || saved.boardColliders?.length === 0) throw new RangeError('Snapshot instance registrations do not match');
|
|
@@ -441,6 +441,16 @@ export const ENGINE_STRINGS = {
|
|
|
441
441
|
"s_doctor_http_status": "HTTP ⟦0⟧",
|
|
442
442
|
"s_doctor_http_none": "No HTTP response",
|
|
443
443
|
"s_doctor_http_slow": "No answer in ⟦0⟧ s",
|
|
444
|
+
"s_download_failed_tag": "Download failed",
|
|
445
|
+
"s_download_failed_title": "The world didn't download",
|
|
446
|
+
"s_download_failed_body": "We tried ⟦0⟧ times and the files didn't arrive. What's already downloaded is kept, so the next try is quicker.",
|
|
447
|
+
"s_download_failed_retry": "Try again",
|
|
448
|
+
"s_download_failed_trying": "Trying…",
|
|
449
|
+
"s_download_failed_check": "Check connection",
|
|
450
|
+
"s_download_failed_copy": "Copy diagnostics",
|
|
451
|
+
"s_download_failed_copied": "Copied",
|
|
452
|
+
"s_download_failed_refused": "Copy refused",
|
|
453
|
+
"s_download_failed_details": "Details",
|
|
444
454
|
"s_build_title": "Build",
|
|
445
455
|
"s_build_running": "Running now",
|
|
446
456
|
"s_build_check": "Check",
|
|
@@ -11,15 +11,16 @@ export interface PlacementFile {
|
|
|
11
11
|
/** Rises with every write; an older file is never believed (J179). */
|
|
12
12
|
readonly serial: number;
|
|
13
13
|
/** SA47: `hash` is the channel pointer's shardfile (the raw upload), so a box whose build's book lacks the slug opens it from the
|
|
14
|
-
* cook's `index/<build>/<hash>.json`. A file from before SA47 names none.
|
|
15
|
-
|
|
14
|
+
* cook's `index/<build>/<hash>.json`. A file from before SA47 names none. `speedClass` is the grid row's (QA 11-15 row 8): the
|
|
15
|
+
* server reads no manifest, so a placed road-class cell keeps the page's 30 m/s board only when the file carries it. */
|
|
16
|
+
readonly cells: readonly { readonly instance: string; readonly slug: string; readonly cell: readonly [number, number]; readonly hash?: string; readonly speedClass?: 'road' }[];
|
|
16
17
|
}
|
|
17
18
|
const placedId = v.pipe(v.string(), v.regex(/^_?[a-z0-9]+(?:-[a-z0-9]+)*$/u), v.maxLength(64));
|
|
18
19
|
const placedSpot = v.pipe(v.number(), v.integer());
|
|
19
20
|
const placedHash = v.pipe(v.string(), v.regex(/^[a-f0-9]{64}$/u));
|
|
20
21
|
/** A placement file's body, once its signature has held. The spot's bounds are `placeCell`'s. */
|
|
21
22
|
export const PlacementSchema: v.GenericSchema<PlacementFile> = v.object({ kind: v.literal('placement'), channel: v.picklist(['production', 'staging']), serial: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
22
|
-
cells: v.pipe(v.array(v.object({ instance: placedId, slug: placedId, cell: v.tuple([placedSpot, placedSpot]), hash: v.exactOptional(placedHash) })), v.maxLength(49)) });
|
|
23
|
+
cells: v.pipe(v.array(v.object({ instance: placedId, slug: placedId, cell: v.tuple([placedSpot, placedSpot]), hash: v.exactOptional(placedHash), speedClass: v.exactOptional(v.literal('road')) })), v.maxLength(49)) });
|
|
23
24
|
/** The file on R2: the body as signed, and its signature in hex (as the release file's, `releaseRows.ts`). */
|
|
24
25
|
export const SignedPlacementSchema: v.GenericSchema<{ readonly body: string; readonly signature: string }> = v.object({ body: v.string(), signature: v.string() });
|
|
25
26
|
/** The API's placement key (SA33a, `~/.config/wildshard/placement-signing-key.pub.pem`), SPKI DER in hex: the box's PLACEMENT_PUBLIC_KEY. */
|
|
@@ -17,6 +17,17 @@ export interface LedgerInstance { id: string; shard: string; cell?: readonly [nu
|
|
|
17
17
|
export interface LedgerRewardPolicy { id: string; quantity: number; repeat?: { everyTicks: number; maxGrants: number } }
|
|
18
18
|
/** Catalogue grants default to one item, once per stable instance and shard, independent of author facts or revisions. */
|
|
19
19
|
export interface LedgerCatalogueItem { id: string; maxTier: number; reward?: LedgerRewardPolicy }
|
|
20
|
+
/** Refuse every inadmissible mapping at world load, before a player or save exists. */
|
|
21
|
+
export function admitLedgerRewards(input: unknown, catalogue: readonly LedgerCatalogueItem[]): readonly LedgerRule[] {
|
|
22
|
+
const items = new Map(catalogue.map(item => [item.id, item]));
|
|
23
|
+
if (items.size !== catalogue.length || catalogue.some(item => !Number.isSafeInteger(item.maxTier) || item.maxTier < 0)) throw new Error('Invalid platform catalogue');
|
|
24
|
+
const rules = parseLedgerRules(input);
|
|
25
|
+
for (const rule of rules) for (const reward of rule.rewards) if (reward.kind === 'catalogue') {
|
|
26
|
+
const item = items.get(reward.item);
|
|
27
|
+
if (item === undefined || reward.tier > item.maxTier || reward.quantity !== (item.reward?.quantity ?? 1)) throw new Error('Reward is outside the platform catalogue policy');
|
|
28
|
+
}
|
|
29
|
+
return rules;
|
|
30
|
+
}
|
|
20
31
|
/** A grant is confirmed only by a durable save write; a pending receipt may be retried. */
|
|
21
32
|
export interface LedgerReceipt {
|
|
22
33
|
id: string; status: 'granted' | 'duplicate' | 'pending';
|
|
@@ -37,8 +48,7 @@ export class Ledger {
|
|
|
37
48
|
constructor(store: SaveStore, instances: readonly LedgerInstance[], mappings: readonly { shard: string; revision: number; rules: readonly LedgerRule[] }[], catalogue: readonly LedgerCatalogueItem[]) {
|
|
38
49
|
this.instances = new Map(instances.map((instance) => [instance.id, instance.shard]));
|
|
39
50
|
if (this.instances.size !== instances.length) throw new Error('Duplicate ledger instance');
|
|
40
|
-
|
|
41
|
-
if (items.size !== catalogue.length || catalogue.some((item) => !Number.isSafeInteger(item.maxTier) || item.maxTier < 0)) throw new Error('Invalid platform catalogue');
|
|
51
|
+
admitLedgerRewards([], catalogue);
|
|
42
52
|
this.catalogue = new Map(catalogue.map((item) => [item.id, structuredClone(item.reward ?? { id: item.id, quantity: 1 })]));
|
|
43
53
|
const policies = [...this.catalogue.values()];
|
|
44
54
|
if (new Set(policies.map((policy) => policy.id)).size !== policies.length || policies.some((policy) => policy.id.length === 0 || policy.id.length > 128
|
|
@@ -47,10 +57,9 @@ export class Ledger {
|
|
|
47
57
|
this.rules = new Map();
|
|
48
58
|
for (const mapping of mappings) {
|
|
49
59
|
if (!Number.isSafeInteger(mapping.revision) || mapping.revision < 1) throw new Error('Invalid ledger revision');
|
|
50
|
-
for (const rule of
|
|
60
|
+
for (const rule of admitLedgerRewards(mapping.rules, catalogue)) {
|
|
51
61
|
const key = JSON.stringify([mapping.shard, mapping.revision, rule.fact]);
|
|
52
62
|
if (this.rules.has(key)) throw new Error('Duplicate ledger mapping');
|
|
53
|
-
for (const reward of rule.rewards) if (reward.kind === 'catalogue' && (items.get(reward.item) === undefined || reward.tier > (items.get(reward.item) ?? -1) || reward.quantity !== this.catalogue.get(reward.item)?.quantity)) throw new Error('Reward is outside the platform catalogue policy');
|
|
54
63
|
this.rules.set(key, { revision: mapping.revision, rule });
|
|
55
64
|
}
|
|
56
65
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as v from 'valibot';
|
|
2
|
+
|
|
3
|
+
/** MMO-PLAN MP3.4 / Q37: api-server's /api/items.json, copied into a signed release. */
|
|
4
|
+
export interface PlatformItemCatalogue { readonly version: 1; readonly items: readonly { readonly id: string; readonly maxTier: number }[] }
|
|
5
|
+
export const MAX_ITEM_CATALOGUE_BYTES = 1_048_576;
|
|
6
|
+
const item = v.strictObject({ id: v.pipe(v.string(), v.regex(/^[a-z0-9][a-z0-9._-]{0,127}$/u)), maxTier: v.pipe(v.number(), v.safeInteger(), v.minValue(0)) });
|
|
7
|
+
const document: v.GenericSchema<PlatformItemCatalogue> = v.strictObject({ version: v.literal(1), items: v.pipe(v.array(item), v.maxLength(4096)) });
|
|
8
|
+
const schema = v.pipe(document, v.check(value => new Set(value.items.map(row => row.id)).size === value.items.length, 'Duplicate platform item'));
|
|
9
|
+
export function readPlatformItemCatalogue(input: unknown): PlatformItemCatalogue { return v.parse(schema, input); }
|
|
10
|
+
/** Stable bytes make an unchanged catalogue keep its digest across releases and API row ordering. */
|
|
11
|
+
export function platformItemCatalogueBytes(input: unknown): Uint8Array {
|
|
12
|
+
const value = readPlatformItemCatalogue(input), items = [...value.items].sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
13
|
+
return new TextEncoder().encode(JSON.stringify({ version: value.version, items }));
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { SaveStore } from '@wildshard/engine/saves/store';
|
|
2
2
|
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
3
|
-
import { Ledger, LedgerEmitter, type LedgerReceipt } from '../ledger';
|
|
3
|
+
import { Ledger, LedgerEmitter, type LedgerReceipt, type LedgerCatalogueItem } from '../ledger';
|
|
4
4
|
import type { RuntimeFacts } from '../plugin/runtimeRows';
|
|
5
5
|
|
|
6
6
|
/** Check the profile slot without invoking its fresh-state fallback or granting a fact. */
|
|
@@ -8,9 +8,9 @@ export function admittedQuestLedger(saves: SaveStore): boolean { return new Ledg
|
|
|
8
8
|
|
|
9
9
|
/** One declared ledger over the caller's original SaveStore and placement.
|
|
10
10
|
* Runtime adapters and native page features share this exact grant owner. */
|
|
11
|
-
export function createQuestLedger(saves: SaveStore, source: Pick<Shardfile, 'identity' | 'ledger'>, instance: string): RuntimeFacts {
|
|
11
|
+
export function createQuestLedger(saves: SaveStore, source: Pick<Shardfile, 'identity' | 'ledger'>, instance: string, catalogue: readonly LedgerCatalogueItem[] = []): RuntimeFacts {
|
|
12
12
|
const identity = { instance, shard: source.identity.slug, revision: source.identity.revision };
|
|
13
|
-
const ledger = new Ledger(saves, [{ id: instance, shard: identity.shard }], [{ shard: identity.shard, revision: identity.revision, rules: source.ledger }],
|
|
13
|
+
const ledger = new Ledger(saves, [{ id: instance, shard: identity.shard }], [{ shard: identity.shard, revision: identity.revision, rules: source.ledger }], catalogue);
|
|
14
14
|
const emit = (name: string, entity: string): LedgerReceipt => {
|
|
15
15
|
const rule = source.ledger.find((row) => row.fact === name);
|
|
16
16
|
if (rule === undefined) throw new Error(`Undeclared ledger fact ${name}`);
|
|
@@ -95,7 +95,15 @@ export function leverProfile(row: { readonly id: string; readonly profile?: unkn
|
|
|
95
95
|
/** The owned lines a lever's server seat publishes to its holder: rounds in the gun (tube and chamber), the reserve, a reload under
|
|
96
96
|
* way (0 or 1) and whether the player has taken it (0 or 1). A line at zero is dropped from `owned`, so absent reads as zero. */
|
|
97
97
|
export function leverLines(id: string): { readonly rounds: string; readonly reserve: string; readonly reloading: string; readonly taken: string } {
|
|
98
|
-
return { rounds: `${id}.rounds`, reserve: `${id}.reserve`, reloading: `${id}.reloading`, taken:
|
|
98
|
+
return { rounds: `${id}.rounds`, reserve: `${id}.reserve`, reloading: `${id}.reloading`, taken: takenLine(id) };
|
|
99
|
+
}
|
|
100
|
+
/** The owned line that says a player has taken a declared weapon off its rack (a lever's, TC-E1; a melee weapon's, TC-E4). */
|
|
101
|
+
export function takenLine(id: string): string { return `${id}.taken`; }
|
|
102
|
+
/** TEMPLATE-E2E TC-E4: the declared melee weapons a rack hands over (an item scene's take, action 3), other than the loadout's
|
|
103
|
+
* primary. Each starts on its rack for every player and comes to hand when that player takes it. */
|
|
104
|
+
export function rackMeleeRows(shard: { readonly items: { readonly rows: readonly { readonly id: string; readonly kind?: string; readonly family?: string }[]; readonly loadout: { readonly primary: string | null } }; readonly targets: { readonly itemActions?: readonly { readonly item: string; readonly action: number }[] | undefined } }): ReadonlySet<string> {
|
|
105
|
+
const melee = new Set(shard.items.rows.filter(row => row.kind === 'weapon' && row.family === 'kit.melee').map(row => row.id));
|
|
106
|
+
return new Set((shard.targets.itemActions ?? []).flatMap(row => row.action === 3 && melee.has(row.item) && row.item !== shard.items.loadout.primary ? [row.item] : []));
|
|
99
107
|
}
|
|
100
108
|
/** Normal equipment factory result plus authoritative fixed-step runtimes, scoped to the one session. */
|
|
101
109
|
export interface DeclaredItems {
|
|
@@ -6,7 +6,6 @@ import { floorBelow } from '@wildshard/engine/physics/query';
|
|
|
6
6
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
7
7
|
import { walkingSpeed } from '@wildshard/engine/player/walk';
|
|
8
8
|
import type { AnimalSim } from '@wildshard/engine/entities/AnimalSim';
|
|
9
|
-
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
10
9
|
|
|
11
10
|
export interface WalkPoint { readonly x:number;readonly z:number;readonly jump?:boolean|number;readonly jumpAt?:number }
|
|
12
11
|
export interface WalkStall { readonly tick:number;readonly waypoint:number;readonly x:number;readonly y:number;readonly z:number }
|
|
@@ -97,8 +96,9 @@ export interface HeadlessJourneySample {readonly commands:readonly HeadlessComma
|
|
|
97
96
|
* its script/decision/finite-state refusals. The parent request watchdog still
|
|
98
97
|
* preempts a blocked worker. This proof does not encode a resumable checkpoint.
|
|
99
98
|
* `capture` sees the placed start with no commands, then every committed tick. */
|
|
100
|
-
export function runHeadlessJourney(host:SimHost,step:(commands:readonly HeadlessCommand[])=>void,input:HeadlessJourneyPlan,capture?:(sample:HeadlessJourneySample)=>void):HeadlessJourneyReport {
|
|
101
|
-
const player=
|
|
99
|
+
export function runHeadlessJourney(host:SimHost,step:(commands:readonly HeadlessCommand[])=>void,input:HeadlessJourneyPlan,capture?:(sample:HeadlessJourneySample)=>void,playerId='actor.player'):HeadlessJourneyReport {
|
|
100
|
+
const player=host.players.get(playerId);if(player===undefined)throw new RangeError(`Unknown journey player ${playerId}`);
|
|
101
|
+
const plan=v.parse(HeadlessJourneyPlanSchema,input),cursor=new PhysicsRouteCursor(plan.points,{once:plan.once===true,edge:plan.inside!==undefined}),initial=host.state.tick;
|
|
102
102
|
let distance=0,maxTickMicros=0,out=0,ticks=0;
|
|
103
103
|
const observe=(commands:readonly HeadlessCommand[]):void=>{const p=player.position;capture?.({commands,x:p.x,y:p.y,z:p.z,grounded:player.fall.grounded});};
|
|
104
104
|
const held=new Map<AnimalSim,boolean>();
|
|
@@ -2,7 +2,6 @@ import * as v from 'valibot';
|
|
|
2
2
|
import type {SimHost} from '@wildshard/engine/sim';
|
|
3
3
|
import {PhysicsRouteCursor,type WalkPoint} from './headlessJourney';
|
|
4
4
|
import type {HeadlessCommand,HeadlessEffect} from './tickProtocol';
|
|
5
|
-
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
6
5
|
|
|
7
6
|
export interface HeadlessTapeSegment {id:string;ticks:number;commands:HeadlessCommand[];route?:WalkPoint[];frames?:HeadlessCommand[][]}
|
|
8
7
|
export interface HeadlessTapePlan {version:1;observe:string[];segments:HeadlessTapeSegment[]}
|
|
@@ -38,12 +37,14 @@ export function headlessTapeReportSchema(effect:v.GenericSchema<HeadlessEffect>)
|
|
|
38
37
|
}
|
|
39
38
|
/** Private worker-side execution of an already admitted offline tape. Every
|
|
40
39
|
* repeated command still enters the existing native owner and fixed tick.
|
|
41
|
-
* The worker keeps its request watchdog; the reply is terminal observations.
|
|
40
|
+
* The worker keeps its request watchdog; the reply is terminal observations.
|
|
41
|
+
* playerId names the seat driven by step and observed throughout the tape. */
|
|
42
42
|
export function runTrustedHeadlessTape(host:SimHost,step:(commands:readonly HeadlessCommand[])=>void,
|
|
43
|
-
effects:()=>readonly HeadlessEffect[],plan:HeadlessTapePlan):HeadlessTapeReport {
|
|
43
|
+
effects:()=>readonly HeadlessEffect[],plan:HeadlessTapePlan,playerId='actor.player'):HeadlessTapeReport {
|
|
44
44
|
if(host.scope.disposed||host.scope.disposing)throw new Error('Tape owner retired');
|
|
45
45
|
const owners=plan.observe.map(id=>{const owner=host.adapters.get(id);if(owner===undefined)throw new Error(`Missing tape observation owner ${id}`);return {id,owner};});
|
|
46
|
-
const player=
|
|
46
|
+
const player=host.players.get(playerId);if(player===undefined)throw new RangeError(`Unknown tape player ${playerId}`);
|
|
47
|
+
const initial=host.state.tick,observations:HeadlessTapeObservation[]=[],encoder=new TextEncoder();let bytes=0;
|
|
47
48
|
for(const segment of plan.segments){
|
|
48
49
|
let peakY=player.position.y;const emitted:HeadlessEffect[]=[];
|
|
49
50
|
const cursor=segment.route===undefined?null:new PhysicsRouteCursor(segment.route,{once:true});
|
|
@@ -88,12 +89,12 @@ export function runTrustedHeadlessTape(host:SimHost,step:(commands:readonly Head
|
|
|
88
89
|
/** A resident tape owner stays pinned across streamed parts as well as inside
|
|
89
90
|
* each ordinary terminal plan. No part may silently rebind an observation. */
|
|
90
91
|
export function createTrustedHeadlessTape(host:SimHost,step:(commands:readonly HeadlessCommand[])=>void,
|
|
91
|
-
effects:()=>readonly HeadlessEffect[]):(plan:HeadlessTapePlan)=>HeadlessTapeReport {
|
|
92
|
+
effects:()=>readonly HeadlessEffect[],playerId='actor.player'):(plan:HeadlessTapePlan)=>HeadlessTapeReport {
|
|
92
93
|
let pinned:{id:string;owner:unknown}[]|undefined;
|
|
93
94
|
return plan=>{
|
|
94
95
|
const owners=plan.observe.map(id=>({id,owner:host.adapters.get(id)}));
|
|
95
96
|
if(pinned===undefined)pinned=owners;
|
|
96
97
|
else if(owners.length!==pinned.length||owners.some((row,index)=>row.id!==pinned?.[index]?.id||row.owner!==pinned[index]?.owner))throw new Error('Tape observation owner changed between parts');
|
|
97
|
-
return runTrustedHeadlessTape(host,step,effects,plan);
|
|
98
|
+
return runTrustedHeadlessTape(host,step,effects,plan,playerId);
|
|
98
99
|
};
|
|
99
100
|
}
|
|
@@ -14,10 +14,13 @@ export interface ReleaseFile {
|
|
|
14
14
|
readonly bundle?: { readonly name: string; readonly sha256: string };
|
|
15
15
|
/** The address clients dial. For the first sitting this is the quick tunnel's name (C22). */
|
|
16
16
|
readonly socket?: string;
|
|
17
|
+
/** Q37: immutable trusted item data, copied from the API before this release is signed. */
|
|
18
|
+
readonly items?: { readonly path: string; readonly sha256: string; readonly bytes: number };
|
|
17
19
|
}
|
|
18
20
|
const Whole = v.pipe(v.number(), v.integer(), v.minValue(0));
|
|
19
21
|
/** A release file's body, once its signature has held. */
|
|
20
22
|
export const ReleaseSchema: v.GenericSchema<ReleaseFile> = v.object({ channel: v.picklist(['production', 'staging', 'preview']), serial: Whole, engineBuild: v.pipe(v.string(), v.minLength(1)), saveEpoch: v.pipe(Whole, v.minValue(1)), shards: v.array(v.object({ slug: v.string(), revision: Whole })),
|
|
21
|
-
bundle: v.exactOptional(v.object({ name: v.pipe(v.string(), v.minLength(1)), sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/u)) })), socket: v.exactOptional(v.string())
|
|
23
|
+
bundle: v.exactOptional(v.object({ name: v.pipe(v.string(), v.minLength(1)), sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/u)) })), socket: v.exactOptional(v.string()),
|
|
24
|
+
items: v.exactOptional(v.pipe(v.strictObject({ path: v.pipe(v.string(), v.regex(/^assets\/catalogue\/items-[0-9a-f]{64}\.json$/u)), sha256: v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/u)), bytes: v.pipe(v.number(), v.safeInteger(), v.minValue(1), v.maxValue(1_048_576)) }), v.check(row => row.path === `assets/catalogue/items-${row.sha256}.json`, 'Item catalogue digest and path disagree'))) });
|
|
22
25
|
/** The file on R2: the body as signed, and its signature in hex (C20). */
|
|
23
26
|
export const SignedSchema: v.GenericSchema<{ readonly body: string; readonly signature: string }> = v.object({ body: v.string(), signature: v.string() });
|