@wildshard/engine 0.1.22 → 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 +8 -0
- package/lint/engine-sides.json +2 -0
- package/lint/sim-players.json +2 -13
- package/package.json +9 -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/ci-pack.mjs +3 -3
- package/scripts/engine-ci-shard.mjs +11 -0
- 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/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 +5 -3
- package/scripts/mmo-grid-proof.mjs +74 -0
- package/scripts/mmo-seat-proof.mjs +43 -0
- 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/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/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 -0
- package/scripts/tsconfig.json +2 -0
- package/scripts/vitest-ci-files.ts +5 -1
- package/scripts/vps/wildshard-config +106 -1
- 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/engine/audio/audioLog.ts +7 -2
- package/src/client/engine/boot/diagnostics.ts +69 -1
- 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/lookLightOption.ts +1 -1
- package/src/client/game/audio/cueDirector.ts +2 -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/dataCellKit.ts +9 -1
- package/src/client/game/grid/products.ts +21 -7
- package/src/client/game/grid/session.ts +6 -4
- 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 +22 -6
- 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/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/simulation.ts +5 -4
- package/src/server/game/plugin/mover.ts +18 -14
- package/src/server/game/shardfile/declaredKitItems.ts +31 -7
- package/src/server/host/bake/headlessWorker.ts +3 -3
- package/src/server/host/dedicated/cellWorker.ts +4 -2
- package/src/server/host/dedicated/main.ts +7 -4
- package/src/server/host/dedicated/packReader.ts +15 -2
- package/src/server/host/dedicated/playerStore.ts +1 -1
- package/src/server/host/headlessRuntime.ts +11 -6
- package/src/server/host/standalone/cellWorld.ts +20 -6
- 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/sim/snapshot.ts +5 -5
- 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
|
@@ -19,7 +19,7 @@ import type { AimCommand } from '@wildshard/engine/input/commands';
|
|
|
19
19
|
import type { SimHost, SimValue } from '@wildshard/engine/sim';
|
|
20
20
|
import type { PlayerSim } from '@wildshard/engine/sim/playerSim';
|
|
21
21
|
import { publishOwned } from '@wildshard/engine/sim/shardRows';
|
|
22
|
-
import { declaredKitSlots, LEVER_FAMILY, leverLines, leverProfile, SERVER_KIT_FAMILIES, type LeverProfile } from '../../../shared/game/shardfile/items';
|
|
22
|
+
import { declaredKitSlots, LEVER_FAMILY, leverLines, leverProfile, rackMeleeRows, SERVER_KIT_FAMILIES, takenLine, type LeverProfile } from '../../../shared/game/shardfile/items';
|
|
23
23
|
import { playerSeats, type PlayerSeat } from '../plugin/playerSeats';
|
|
24
24
|
import { nativeRangedHit } from '../plugin/nativeItems';
|
|
25
25
|
import { installStatusEffects } from './statusEffects';
|
|
@@ -45,7 +45,9 @@ export interface DeclaredKitItems {
|
|
|
45
45
|
type Cycle = InstanceType<typeof RangedAction.Cycle>;
|
|
46
46
|
/** One player's lever: the cycle and its reserve, whether they have taken it, and the time since a dry pull (its auto-reload window). */
|
|
47
47
|
interface LeverSeat { readonly act: Cycle; readonly store: { reserve: number }; taken: boolean; sinceEmpty: number }
|
|
48
|
-
interface KitSeat extends PlayerSeat { readonly runtimes: ReadonlyMap<string, ItemRuntime>; readonly levers: ReadonlyMap<string, LeverSeat> }
|
|
48
|
+
interface KitSeat extends PlayerSeat { readonly runtimes: ReadonlyMap<string, ItemRuntime>; readonly levers: ReadonlyMap<string, LeverSeat>; readonly racked: Set<string> }
|
|
49
|
+
/** The continuation key of a player's rack weapons still on their racks (TC-E4): no item id starts with '#'. */
|
|
50
|
+
const RACKED = '#racked';
|
|
49
51
|
type LeverRow = Extract<Shardfile['items']['rows'][number], { kind: 'weapon' }>;
|
|
50
52
|
const finiteNumber = v.pipe(v.number(), v.finite()), count = v.pipe(finiteNumber, v.integer(), v.minValue(0));
|
|
51
53
|
const LeverSaved = v.strictObject({ tube: count, chambered: v.boolean(), caseInChamber: v.boolean(), hammerCocked: v.boolean(),
|
|
@@ -81,11 +83,14 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
81
83
|
const prompts = new Map<string, { readonly at: readonly [number, number, number]; readonly radius: number }[]>();
|
|
82
84
|
for (const row of shard.targets.interactions) prompts.set(row.scene, [...(prompts.get(row.scene) ?? []), row]);
|
|
83
85
|
// A rack's prompt names its lever's scene: the page sends the prompt's own id, and this kit runs it, not a script (a shard may have none).
|
|
84
|
-
const leverPrompts = new Map(shard.targets.interactions.flatMap(row => (shard.targets.itemActions ?? []).some(action => action.scene === row.scene && levers.has(action.item)) ? [[row.id, row.scene] as const] : []));
|
|
85
86
|
const slots = declaredKitSlots(shard.items.rows), weapons = [...slots.keys()];
|
|
86
87
|
// TEMPLATE-E2E TC-E1c: the loadout's primary lever is in hand from the start; any other waits for its rack
|
|
87
88
|
const primary = shard.items.loadout.primary;
|
|
88
89
|
const scenes = new Map((shard.targets.itemActions ?? []).filter(row => rows.some(item => item.id === row.item)).map(row => [row.scene, row] as const));
|
|
90
|
+
// TEMPLATE-E2E TC-E4 (J361: Mossgate's sword is found on a rack): a melee weapon a rack takes starts on that rack, per player
|
|
91
|
+
const rackMelee = rackMeleeRows(shard);
|
|
92
|
+
// A rack's prompt arrives by its own id (the page's wire id): a lever's or a racked melee weapon's names its scene
|
|
93
|
+
const leverPrompts = new Map(shard.targets.interactions.flatMap(row => (shard.targets.itemActions ?? []).some(action => action.scene === row.scene && (levers.has(action.item) || rackMelee.has(action.item))) ? [[row.id, row.scene] as const] : []));
|
|
89
94
|
const fields = (shard.targets.itemFields ?? []).flatMap(row => {
|
|
90
95
|
const field = shard.state.player.find(entry => entry.id === row.fieldId);
|
|
91
96
|
return field === undefined || field.privacy === 'host' ? [] : [{ item: row.item, name: field.name, property: row.property }];
|
|
@@ -112,7 +117,8 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
112
117
|
const seat: LeverSeat = { act: new RangedAction.Cycle(store, { magazine: profile.magazine, reload: profile.reload, ...profile.lever }), store, taken: id === primary, sinceEmpty: 99 };
|
|
113
118
|
return [id, seat] as const;
|
|
114
119
|
}));
|
|
115
|
-
|
|
120
|
+
const racked = new Set(rackMelee);
|
|
121
|
+
return { runtimes, levers: seated, racked,
|
|
116
122
|
step: dt => {
|
|
117
123
|
for (const runtime of runtimes.values()) runtime.step(host.state.tick, dt);
|
|
118
124
|
const holding = weapons[player.held];
|
|
@@ -124,7 +130,8 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
124
130
|
for (const _event of seat.act.events(dt, due)) { /* The seat has no presentation: the page plays its own cycle. */ }
|
|
125
131
|
}
|
|
126
132
|
},
|
|
127
|
-
snapshot: (): SimValue => ({ ...Object.fromEntries([...runtimes].map(([id, runtime]) => [id, runtime.snapshot()])), ...Object.fromEntries([...seated].map(([id, seat]) => [id, leverSnapshot(seat)]))
|
|
133
|
+
snapshot: (): SimValue => ({ ...Object.fromEntries([...runtimes].map(([id, runtime]) => [id, runtime.snapshot()])), ...Object.fromEntries([...seated].map(([id, seat]) => [id, leverSnapshot(seat)])),
|
|
134
|
+
...(rackMelee.size === 0 ? {} : { [RACKED]: [...racked].sort() }) }),
|
|
128
135
|
restore: value => {
|
|
129
136
|
if (!isStates(value)) throw new Error('Invalid declared kit item continuation');
|
|
130
137
|
// A player's document can come from an older room (E7.4): its tick is that room's. The runtime's tick only orders steps,
|
|
@@ -132,6 +139,9 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
132
139
|
for (const [id, runtime] of runtimes) { const saved = value[id]; if (saved !== undefined) runtime.restore({ ...saved, tick: Math.max(-1, Math.min(saved.tick, host.state.tick - 1)) }); }
|
|
133
140
|
// A save made before a lever existed leaves it fresh.
|
|
134
141
|
for (const [id, seat] of seated) { const saved: unknown = value[id]; if (saved !== undefined) restoreLever(seat, saved); if (id === primary) seat.taken = true; }
|
|
142
|
+
// A save from before TC-E4 has no rack list: its weapons stay on their racks, as a fresh player's do.
|
|
143
|
+
const saved: unknown = value[RACKED];
|
|
144
|
+
if (Array.isArray(saved)) { racked.clear(); for (const id of saved) if (typeof id === 'string' && rackMelee.has(id)) racked.add(id); }
|
|
135
145
|
} };
|
|
136
146
|
});
|
|
137
147
|
// Joined: a save made before this owner existed restores, and its items start fresh.
|
|
@@ -146,6 +156,11 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
146
156
|
out.set(field.name, field.property === 'fuel' ? Math.round(runtime.remainingFuel * FUEL_STEPS) / FUEL_STEPS : Number(runtime.lightOn));
|
|
147
157
|
}
|
|
148
158
|
});
|
|
159
|
+
if (rackMelee.size > 0) publishOwned(host, 'items.declared-rack', (id, out) => {
|
|
160
|
+
const player = host.players.get(id); if (player === undefined) return;
|
|
161
|
+
const { racked } = seats.of(player);
|
|
162
|
+
for (const item of rackMelee) out.set(takenLine(item), Number(!racked.has(item)));
|
|
163
|
+
});
|
|
149
164
|
if (levers.size > 0) publishOwned(host, 'items.declared-lever', (id, out) => {
|
|
150
165
|
const player = host.players.get(id); if (player === undefined) return;
|
|
151
166
|
for (const [item, seat] of seats.of(player).levers) {
|
|
@@ -154,7 +169,7 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
154
169
|
out.set(lines.reloading, Number(seat.act.phase === 'reload')); out.set(lines.taken, Number(seat.taken));
|
|
155
170
|
}
|
|
156
171
|
});
|
|
157
|
-
const held = (player: PlayerSim): ItemRuntime | undefined => { const id = weapons[player.held]; return id === undefined ? undefined :
|
|
172
|
+
const held = (player: PlayerSim): ItemRuntime | undefined => { const id = weapons[player.held], seat = seats.of(player); return id === undefined || seat.racked.has(id) ? undefined : seat.runtimes.get(id); };
|
|
158
173
|
const heldLever = (player: PlayerSim): { readonly seat: LeverSeat; readonly row: LeverRow; readonly profile: LeverProfile } | undefined => {
|
|
159
174
|
const id = weapons[player.held], lever = id === undefined ? undefined : levers.get(id), seat = id === undefined ? undefined : seats.of(player).levers.get(id);
|
|
160
175
|
return lever === undefined || seat === undefined ? undefined : { seat, row: lever.row, profile: lever.profile };
|
|
@@ -215,7 +230,7 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
215
230
|
const player = host.players.get(id), want = weapons[slot];
|
|
216
231
|
if (player === undefined || want === undefined) return false;
|
|
217
232
|
// A lever still on its rack is no swap: the act is spent, and the hand stays where it is.
|
|
218
|
-
if (seats.of(player).levers.get(want)?.taken === false) return true;
|
|
233
|
+
if (seats.of(player).levers.get(want)?.taken === false || seats.of(player).racked.has(want)) return true;
|
|
219
234
|
const before = held(player), aim = eye(player, 0);
|
|
220
235
|
if (before !== undefined) safely(() => { before.hold(false, aim, false); }); // a swap lets go of a charge without striking
|
|
221
236
|
player.held = slot; return true;
|
|
@@ -235,6 +250,15 @@ export function installDeclaredKitItems(host: SimHost, shard: Pick<Shardfile, 'i
|
|
|
235
250
|
} else if (lever.taken) lever.act.beginReload();
|
|
236
251
|
return true;
|
|
237
252
|
}
|
|
253
|
+
// TC-E4: 3 takes a racked melee weapon into hand; once taken, its rack is spent
|
|
254
|
+
if (taker !== undefined && row.action === 3 && rackMelee.has(row.item)) {
|
|
255
|
+
const own = seats.of(taker).racked;
|
|
256
|
+
if (!own.has(row.item) || !near(taker, scene)) return true;
|
|
257
|
+
const slot = weapons.indexOf(row.item), before = held(taker);
|
|
258
|
+
if (before !== undefined) safely(() => { before.hold(false, eye(taker, 0), false); });
|
|
259
|
+
own.delete(row.item); if (slot !== -1) taker.held = slot;
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
238
262
|
const player = taker, runtime = player === undefined ? undefined : seats.of(player).runtimes.get(row.item);
|
|
239
263
|
if (runtime !== undefined) safely(() => { runtime.queue(row.action); });
|
|
240
264
|
return true;
|
|
@@ -24,7 +24,6 @@ import { headlessSections } from '../../../shared/host/headlessSections';
|
|
|
24
24
|
import { scriptAdmissionRows } from '@wildshard/format/scriptContract';
|
|
25
25
|
import { validateShardfileAssets } from '@wildshard/format/assetAdmission';
|
|
26
26
|
import { offlineMemoryAdmission, prepareAssetDecoders } from '@wildshard/format/shardfileAssets';
|
|
27
|
-
import { leadCommands, leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
28
27
|
|
|
29
28
|
await runTickWorker(async raw => {
|
|
30
29
|
const payload = v.parse(v.strictObject({ shard: v.unknown(), assets: v.map(v.string(), v.instance(Uint8Array)), binary: v.string(), snapshot: v.optional(v.string()), sections: v.exactOptional(v.map(v.string(), v.unknown())), product: v.exactOptional(v.string()) }), raw);
|
|
@@ -85,8 +84,9 @@ await runTickWorker(async raw => {
|
|
|
85
84
|
if (!sim.actors.has(command.actorId)) throw new Error('Unknown command actor'); numeric.set(command.actorId, command.value);
|
|
86
85
|
} else { if (sim.lane === undefined) throw new Error('Event requires a script lane'); sim.lane.enqueue({ type: command.type, target: command.target, value: command.value }); }
|
|
87
86
|
}
|
|
88
|
-
commands = numeric; sim.host.step(
|
|
89
|
-
|
|
87
|
+
commands = numeric; sim.host.step(player === undefined ? undefined : new Map([['actor.player', player]]));
|
|
88
|
+
for (const body of sim.host.players.values()) if (!Number.isFinite(body.position.x) || !Number.isFinite(body.position.y) || !Number.isFinite(body.position.z)) throw new Error('Nonfinite headless simulation state');
|
|
89
|
+
for (const body of sim.host.entities.values()) if (!Number.isFinite(body.position.x) || !Number.isFinite(body.position.y) || !Number.isFinite(body.position.z)) throw new Error('Nonfinite headless simulation state');
|
|
90
90
|
const script=sim.lane?.host.checkpoint();
|
|
91
91
|
if(script?.modules.some(module=>module.failures>0||module.disabled))throw new Error('Headless script call failed');
|
|
92
92
|
if(sim.decisions?.host.metrics().some(row=>row.refusals>0||row.disabled))throw new Error('Headless decision call failed');
|
|
@@ -12,9 +12,11 @@ import { readPackGrid, readPackProduct, type PackReads } from './packReader';
|
|
|
12
12
|
import { runCells, type CellPort } from './cellHost';
|
|
13
13
|
import { placeCell, placedHash, type PlacedCell } from './gridCells';
|
|
14
14
|
import { loopLag } from './loopLag';
|
|
15
|
+
import type { LedgerCatalogueItem } from '@wildshard/engine/game/ledger';
|
|
15
16
|
|
|
16
17
|
/** What the door boots a worker with. */
|
|
17
18
|
export interface CellWorkerData { readonly slugs: readonly string[]; readonly build: string; readonly origin: string; readonly cache: string; readonly holdMs?: number;readonly playtest?:boolean;
|
|
19
|
+
readonly catalogue?: readonly LedgerCatalogueItem[];
|
|
18
20
|
/** J107's start-over wait, a proof's override (`EMPTY_MS`): 5 minutes when absent. */
|
|
19
21
|
readonly emptyMs?: number;
|
|
20
22
|
/** Every worker hosts its road; J353 removed the mode switch. */
|
|
@@ -24,7 +26,7 @@ export interface CellWorkerData { readonly slugs: readonly string[]; readonly bu
|
|
|
24
26
|
/** SERVER-CELLS SC1: `METRICS_PORT` is set, so this worker measures its event-loop lag for `/metrics`. */
|
|
25
27
|
readonly metrics?: boolean }
|
|
26
28
|
|
|
27
|
-
const { slugs, build, origin, cache, holdMs, emptyMs, playtest, crossing, placed, metrics } = workerData as CellWorkerData, port = parentPort;
|
|
29
|
+
const { slugs, build, origin, cache, holdMs, emptyMs, playtest, crossing, placed, metrics, catalogue } = workerData as CellWorkerData, port = parentPort;
|
|
28
30
|
if (port === null) throw new Error('A cell runs in a worker');
|
|
29
31
|
for (const row of placed ?? []) placeCell(row);
|
|
30
32
|
const reads: PackReads = { fetched: 0, fetchedBytes: 0, cached: 0, refused: 0 };
|
|
@@ -36,7 +38,7 @@ runCells(port as unknown as CellPort, { slugs, build, developerBoost: process.en
|
|
|
36
38
|
return strips;
|
|
37
39
|
} } : {}),
|
|
38
40
|
load: async slug => {
|
|
39
|
-
const input = await readPackProduct(slug, build, rapier, { origin, cache }, reads, placedHash(slug));
|
|
41
|
+
const input = await readPackProduct(slug, build, rapier, { origin, cache }, reads, placedHash(slug), catalogue);
|
|
40
42
|
console.info(JSON.stringify({ at: 'cell.pack', slug, ...reads }));
|
|
41
43
|
return input;
|
|
42
44
|
} });
|
|
@@ -14,7 +14,7 @@ import { Worker } from 'node:worker_threads';
|
|
|
14
14
|
import { loadRapier } from '@wildshard/engine/physics/rapier';
|
|
15
15
|
import type { WorkerNews } from './cellProtocol';
|
|
16
16
|
import type { CellWorkerData } from './cellWorker';
|
|
17
|
-
import { readPackProduct, type PackReads } from './packReader';
|
|
17
|
+
import { readPackProduct, readReleaseItems, type PackReads } from './packReader';
|
|
18
18
|
import { openPlayerSaves, memoryPlayerSaves } from './playerSaves';
|
|
19
19
|
import type { ReleaseFile } from '../../../shared/host/releaseRows';
|
|
20
20
|
import { fetchReleaseFile, servingRelease, ReleaseWatch } from './releaseFile';
|
|
@@ -56,6 +56,8 @@ async function installedRelease(): Promise<ReleaseFile> {
|
|
|
56
56
|
return selected;
|
|
57
57
|
}
|
|
58
58
|
const release = await installedRelease();
|
|
59
|
+
const itemReads: PackReads = { fetched: 0, fetchedBytes: 0, cached: 0, refused: 0 };
|
|
60
|
+
const catalogue = await readReleaseItems(release.items, { origin, cache }, itemReads);
|
|
59
61
|
// 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
|
|
60
62
|
// the release names, home first. A cell runs its shard's pack, and the release must name that shard.
|
|
61
63
|
const listed = process.env['WORLD_CELLS'] ?? 'driftwood-isle', cells = worldCells(listed, release.shards.map(shard => shard.slug)), shards = [...new Set(cells.map(cellShard))];
|
|
@@ -80,7 +82,7 @@ const playtest=process.env['PLAYTEST']==='1'?new PlaytestFile({directory:setting
|
|
|
80
82
|
|
|
81
83
|
/** One row of the table is one worker thread, started once (J182). */
|
|
82
84
|
function bootWorker(slugs: readonly string[]): WorkerLink {
|
|
83
|
-
const data: CellWorkerData = { slugs, build, origin, cache, placed: placedCells(), ...(hold === undefined ? {} : { holdMs: Number(hold) }), ...(empty === undefined ? {} : { emptyMs: Number(empty) }), crossing: true, ...(metrics === undefined ? {} : { metrics: true }),...(playtest===undefined?{}:{playtest:true}) };
|
|
85
|
+
const data: CellWorkerData = { slugs, build, origin, cache, catalogue, placed: placedCells(), ...(hold === undefined ? {} : { holdMs: Number(hold) }), ...(empty === undefined ? {} : { emptyMs: Number(empty) }), crossing: true, ...(metrics === undefined ? {} : { metrics: true }),...(playtest===undefined?{}:{playtest:true}) };
|
|
84
86
|
const worker = new Worker(new URL('cellWorker.mjs', import.meta.url), { workerData: data });
|
|
85
87
|
let stopped = false;
|
|
86
88
|
return { send: (order, transfer = []) => { worker.postMessage(order, transfer as never); },
|
|
@@ -141,7 +143,8 @@ async function pullBundle(script: string): Promise<void> {
|
|
|
141
143
|
const watch = new ReleaseWatch({ read: readRelease, serving: release, cells: shards, ...(poll === undefined ? {} : { everyMs: Number(poll) }), failed: error => { log({ at: 'release.failed', error: String(error) }); },
|
|
142
144
|
changed: async next => {
|
|
143
145
|
if (pullScript !== undefined) await pullBundle(pullScript);
|
|
144
|
-
|
|
146
|
+
const nextCatalogue = await readReleaseItems(next.items, { origin, cache }, reads);
|
|
147
|
+
for (const slug of shards) await readPackProduct(slug, next.engineBuild, await rapier(), { origin, cache }, reads, undefined, nextCatalogue);
|
|
145
148
|
world.beginGrace(next.engineBuild);
|
|
146
149
|
} });
|
|
147
150
|
// 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
|
|
@@ -154,7 +157,7 @@ placements = placementAt === undefined || placementKey === undefined || listed.t
|
|
|
154
157
|
const ready: string[] = [];
|
|
155
158
|
for (const row of rows) {
|
|
156
159
|
// SA34a: the pack first, so the door's placed list (and so every worker's frame numbers) holds only cells it opens.
|
|
157
|
-
try { await readPackProduct(row.slug, build, await rapier(), { origin, cache }, reads, row.hash); placeCell(row); ready.push(row.instance); }
|
|
160
|
+
try { await readPackProduct(row.slug, build, await rapier(), { origin, cache }, reads, row.hash, catalogue); placeCell(row); ready.push(row.instance); }
|
|
158
161
|
catch (error) { log({ at: 'placement.refused', instance: row.instance, slug: row.slug, error: String(error) }); }
|
|
159
162
|
}
|
|
160
163
|
return ready.length === 0 ? [] : world.openCells(ready);
|
|
@@ -10,6 +10,9 @@ import type { Rapier } from '@wildshard/engine/physics/rapier';
|
|
|
10
10
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
11
11
|
import type { GridCollisionStrip } from '@wildshard/engine/game/grid/gridCollision';
|
|
12
12
|
import { readGridCollisionPack, readServerProduct, type ServerRead } from '../standalone/serverProduct';
|
|
13
|
+
import type { ReleaseFile } from '../../../shared/host/releaseRows';
|
|
14
|
+
import { readPlatformItemCatalogue, type PlatformItemCatalogue } from '@wildshard/engine/game/loot/platformCatalogue';
|
|
15
|
+
import { admitLedgerRewards, type LedgerCatalogueItem } from '@wildshard/engine/game/ledger';
|
|
13
16
|
|
|
14
17
|
/** What a reader counts, so a boot can say where its bytes came from. */
|
|
15
18
|
export interface PackReads { fetched: number; fetchedBytes: number; cached: number; refused: number }
|
|
@@ -63,6 +66,16 @@ export function readPackGrid(build: string, options: PackReaderOptions, reads: P
|
|
|
63
66
|
return readGridCollisionPack(new URL('shards/', options.origin.endsWith('/') ? options.origin : `${options.origin}/`).href, build, packRead(options, reads));
|
|
64
67
|
}
|
|
65
68
|
/** One shard's server inputs, through its build's book, or for a placed slug the book lacks, the cook's index of `hash` (SA47). */
|
|
66
|
-
export function readPackProduct(slug: string, build: string, rapier: Rapier, options: PackReaderOptions, reads: PackReads, hash?: string): Promise<HeadlessRuntimeInput> {
|
|
67
|
-
|
|
69
|
+
export async function readPackProduct(slug: string, build: string, rapier: Rapier, options: PackReaderOptions, reads: PackReads, hash?: string, catalogue: readonly LedgerCatalogueItem[] = []): Promise<HeadlessRuntimeInput> {
|
|
70
|
+
const input = await readServerProduct(new URL(`shards/${slug}/`, options.origin.endsWith('/') ? options.origin : `${options.origin}/`).href, () => build, packRead(options, reads), rapier, undefined, hash);
|
|
71
|
+
admitLedgerRewards(input.shard.ledger, catalogue);
|
|
72
|
+
return { ...input, catalogue };
|
|
73
|
+
}
|
|
74
|
+
/** Q37: the signed release selects these bytes; an old release has no catalogue grants. */
|
|
75
|
+
export async function readReleaseItems(reference: ReleaseFile['items'], options: PackReaderOptions, reads: PackReads): Promise<PlatformItemCatalogue['items']> {
|
|
76
|
+
if (reference === undefined) return [];
|
|
77
|
+
const root = options.origin.endsWith('/') ? options.origin : `${options.origin}/`;
|
|
78
|
+
const body = await packRead(options, reads)(new URL(reference.path, root), reference.path, reference.sha256);
|
|
79
|
+
if (body.byteLength !== reference.bytes) throw new Error('Item catalogue byte count mismatch');
|
|
80
|
+
return readPlatformItemCatalogue(JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(body))).items;
|
|
68
81
|
}
|
|
@@ -50,7 +50,7 @@ export class PlayerStore {
|
|
|
50
50
|
}
|
|
51
51
|
/** This player's fact ledger on this shard. */
|
|
52
52
|
facts(input: HeadlessRuntimeInput, instance: string): RuntimeFacts {
|
|
53
|
-
this.ledger ??= createQuestLedger(this.saves, input.shard, instance);
|
|
53
|
+
this.ledger ??= createQuestLedger(this.saves, input.shard, instance, input.catalogue);
|
|
54
54
|
return this.ledger;
|
|
55
55
|
}
|
|
56
56
|
/** Every document held, as its text. */
|
|
@@ -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';
|
|
@@ -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
|
}
|
|
@@ -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');
|
|
@@ -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}`);
|