@wildshard/engine 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/index.html +17 -4
- package/lint/engine-sides.json +9 -0
- package/lint/sim-players.json +2 -13
- package/package.json +36 -3
- 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/app-build/titlePreloads.mjs +8 -5
- package/scripts/bake-road-surfaces.entry.ts +18 -0
- package/scripts/bake-road-surfaces.mjs +44 -0
- package/scripts/changelog.mjs +2 -1
- 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/capture.mjs +18 -6
- package/scripts/goldens/native-residency.d.mts +2 -0
- package/scripts/goldens/native-residency.mjs +31 -4
- package/scripts/grid-road-lag.mjs +209 -0
- package/scripts/keep-copy.mjs +172 -0
- package/scripts/land.d.mts +4 -1
- package/scripts/land.mjs +121 -9
- 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 +59 -7
- package/scripts/loading-flow/stalls.d.mts +2 -0
- package/scripts/loading-flow/stalls.mjs +13 -0
- package/scripts/map-hash.mjs +1 -1
- 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-tag.mjs +2 -4
- package/scripts/nightly.proof.ts +18 -5
- package/scripts/nightly.ts +13 -8
- package/scripts/no-astc-boot.mjs +77 -0
- package/scripts/page-release/content.mjs +19 -10
- package/scripts/page-release/flow.d.mts +3 -2
- package/scripts/page-release/flow.mjs +31 -21
- package/scripts/page-release/packs.d.mts +5 -0
- package/scripts/page-release/packs.mjs +13 -3
- package/scripts/page-release/preview.d.mts +2 -0
- package/scripts/page-release/preview.mjs +74 -0
- package/scripts/page-release.mjs +13 -5
- 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/road-drive-proof.mjs +269 -0
- package/scripts/road-memory-probe.mjs +129 -0
- package/scripts/scratch-dir.mjs +33 -14
- package/scripts/scratch-sweep.mjs +15 -23
- package/scripts/server-release/github.mjs +59 -26
- package/scripts/server-release/items.d.mts +7 -0
- package/scripts/server-release/items.mjs +28 -0
- package/scripts/server-release/publish.mjs +24 -2
- package/scripts/server-release/sign.mjs +8 -4
- package/scripts/side-parity.mjs +1 -1
- package/scripts/test-products.json +1 -0
- package/scripts/test_prebuilt_output.py +3 -1
- package/scripts/tsconfig.json +2 -0
- package/scripts/turn-in-shots.mjs +83 -0
- package/scripts/vitest-bench-observe-proof.py +168 -0
- package/scripts/vitest-bench.py +122 -77
- package/scripts/vitest-ci-files.ts +5 -1
- package/scripts/vps/rebuild.sh +3 -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 +36 -140
- package/scripts/worktree.mjs +92 -12
- package/scripts/zone-gate-proof.mjs +93 -0
- package/src/client/engine/audio/audioLog.ts +7 -2
- package/src/client/engine/boot/diagnostics.ts +69 -1
- package/src/client/engine/boot/sw.ts +3 -1
- package/src/client/engine/core/ktx2.ts +33 -10
- package/src/client/engine/core/ktx2Zstd.ts +2 -1
- package/src/client/engine/models/place.ts +7 -5
- package/src/client/engine/pwa/sw.js +83 -10
- package/src/client/engine/render/dataLook.ts +14 -7
- package/src/client/engine/render/lookLight.ts +64 -20
- package/src/client/engine/render/precompile.ts +6 -0
- package/src/client/engine/render/tiers.ts +9 -0
- package/src/client/engine/ui/Loading.ts +6 -8
- package/src/client/engine/ui/lookLightOption.ts +1 -1
- package/src/client/engine/ui/playerReload.ts +5 -5
- package/src/client/game/audio/cueDirector.ts +2 -1
- package/src/client/game/boot/bytes.generated.ts +4 -1
- package/src/client/game/boot/versions.generated.ts +8 -5
- 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/cellClip.ts +70 -6
- package/src/client/game/grid/dataCellKit.ts +9 -1
- package/src/client/game/grid/gateCard.css +9 -0
- package/src/client/game/grid/gateCard.ts +67 -0
- package/src/client/game/grid/live.ts +17 -3
- package/src/client/game/grid/liveSession.ts +15 -5
- package/src/client/game/grid/neighbourLife.ts +10 -1
- package/src/client/game/grid/neighbourPanels.ts +29 -2
- package/src/client/game/grid/pageEntry.ts +21 -0
- package/src/client/game/grid/products.ts +21 -7
- package/src/client/game/grid/regionalWorld.ts +5 -0
- package/src/client/game/grid/roadCompressedSurfaces.ts +69 -0
- package/src/client/game/grid/roadLook.ts +5 -73
- package/src/client/game/grid/roadLookPlatform.ts +11 -6
- package/src/client/game/grid/roadSurfaceMaps.ts +80 -0
- package/src/client/game/grid/roadTilePool.ts +4 -0
- package/src/client/game/grid/session.ts +58 -16
- package/src/client/game/grid/softWallLook.ts +6 -1
- package/src/client/game/plugin/ui.ts +3 -0
- package/src/client/game/population/signals.ts +1 -1
- package/src/client/game/quest/chapterDirector.ts +1 -0
- package/src/client/game/session/play.ts +3 -0
- package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
- package/src/client/game/shardfile/clientSource.ts +5 -2
- package/src/client/game/shardfile/clientWorker.ts +25 -8
- package/src/client/game/shardfile/look.ts +1 -1
- package/src/client/game/shardfile/runtimeProduct.ts +9 -5
- package/src/client/game/shardfile/slabLibrary.ts +37 -0
- package/src/client/game/shardfile/slabRanges.ts +145 -0
- 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 +2 -2
- package/src/client/host/standalone/shell.ts +4 -1
- 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 +32 -8
- package/src/server/game/plugin/mover.ts +18 -14
- package/src/server/game/plugin/simulation.ts +2 -0
- package/src/server/game/shardfile/dataRespawn.ts +47 -0
- 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 +20 -6
- package/src/server/host/standalone/roadWorld.ts +36 -0
- package/src/server/host/standalone/serverHost.ts +2 -2
- package/src/shared/engine/entities/AnimalSim.ts +10 -0
- package/src/shared/engine/physics/gridBorders.ts +15 -1
- package/src/shared/engine/physics/transferWalls.ts +9 -4
- package/src/shared/engine/sim/snapshot.ts +5 -5
- package/src/shared/game/grid/allocator.ts +8 -1
- package/src/shared/game/grid/gateCount.ts +27 -0
- package/src/shared/game/grid/zoneWalls.ts +64 -0
- 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/game/strings.ts +2 -0
- 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/shared/host/standalone/harnessPlace.ts +4 -0
- package/src/test/engine/simState.ts +134 -0
- package/src/test/game/builtProduct.ts +6 -0
- package/src/test/game/headless/admittedProductCache.ts +61 -0
- package/src/test/game/headless/checkedReplayPipeline.ts +21 -0
- package/src/test/game/headless/nativeBounds.ts +27 -0
- package/src/test/game/headless/processUsage.ts +22 -0
- package/src/test/game/headless/productSession.ts +39 -0
- package/src/test/game/headless/ropeBodies.ts +60 -0
- package/src/test/game/headless/worker.ts +34 -0
- package/src/test/game/headlessNative.ts +114 -0
- package/src/test/game/headlessWorker.ts +43 -0
- package/src/test/tsconfig.game.json +3 -0
|
@@ -236,23 +236,26 @@ export interface GcReport {readonly kept: number; readonly deleted: number; read
|
|
|
236
236
|
export const PACK_BUDGET_BYTES = 4_000_000_000;
|
|
237
237
|
/** A part younger than this may belong to a cook that hasn't written its index yet. */
|
|
238
238
|
const GC_GRACE_MS = 3_600_000;
|
|
239
|
+
/** PAGE-SIZE PZ2's content sets (`content/<set>/…`, page-release content.mjs). They are content-named and name no build,
|
|
240
|
+
* so garbage collection never takes one; a set's own retention waits for a build-to-set record. */
|
|
241
|
+
const CONTENT_SETS = 'content/';
|
|
239
242
|
|
|
243
|
+
/** The cook's usage: `objects`, `bytes` and `share` count only its own keys, never the page's content sets (`CONTENT_SETS`),
|
|
244
|
+
* which it neither writes nor collects. From 2026-11-14 they filled the 4 GB budget alone (32.7 of 33.53 GB) and every
|
|
245
|
+
* job failed "Over the pack budget". `byPrefix` still lists every prefix, content sets included, so a report shows them. */
|
|
240
246
|
function usageOf(rows: readonly StoredObject[], budget: number): StoreUsage {
|
|
241
247
|
const byPrefix: Record<string, {count: number; bytes: number}> = {};
|
|
242
248
|
let objects = 0, bytes = 0;
|
|
243
249
|
for (const row of rows) {
|
|
244
250
|
const path = row.key.split('/'), name = path.slice(0, path.length > 3 ? 3 : Math.min(2, path.length - 1)).join('/'), kept = byPrefix[name] ?? {count: 0, bytes: 0};
|
|
245
|
-
kept.count++; kept.bytes += row.bytes; byPrefix[name] = kept;
|
|
251
|
+
kept.count++; kept.bytes += row.bytes; byPrefix[name] = kept;
|
|
252
|
+
if (!row.key.startsWith(CONTENT_SETS)) { objects++; bytes += row.bytes; }
|
|
246
253
|
}
|
|
247
254
|
return {objects, bytes, share: bytes / budget, byPrefix};
|
|
248
255
|
}
|
|
249
256
|
|
|
250
257
|
export async function storeUsage(store: PackStore, budget: number): Promise<StoreUsage> { return usageOf(await store.list(''), budget); }
|
|
251
258
|
|
|
252
|
-
/** PAGE-SIZE PZ2's content sets (`content/<set>/…`, page-release content.mjs). They are content-named and name no build,
|
|
253
|
-
* so garbage collection never takes one; a set's own retention waits for a build-to-set record. */
|
|
254
|
-
const CONTENT_SETS = 'content/';
|
|
255
|
-
|
|
256
259
|
/** J83: keep what a kept build's index names, and delete the rest, indexes of other builds included.
|
|
257
260
|
* PAGE-SIZE PZ5: a kept build's server book (`assets/spawn/server-<build>.json`, page-release packs.mjs) and every part it
|
|
258
261
|
* names are kept too, so a carried build's solo server still finds them; the content sets are never collected. */
|
|
@@ -252,14 +252,16 @@ export function ktx2GpuBytes(bytes: Uint8Array): number {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
/** S12b: the largest side a phone draws from one KTX2 table row, or undefined to keep the file as it is. The table's source
|
|
255
|
-
* key is the author's hint (D5): a `#layer` twin (a terrain layer, tiled at a texel a metre)
|
|
256
|
-
*
|
|
255
|
+
* key is the author's hint (D5): a `#layer` twin (a terrain layer, tiled at a texel a metre), a horizon strip and a painted
|
|
256
|
+
* sky panorama (a `panorama` file or a `sky/` folder: the whole sky, seen at screen size) are kept on purpose; every other
|
|
257
|
+
* row is 512 on a phone. The panorama was cut to 258 x 47 from its 4128 x 760 phone file and Nalati's sky drew as a blur
|
|
258
|
+
* (SHARD-REPOS SH-nalati-6, 2026-11-15). */
|
|
257
259
|
export const PHONE_TIER_MAX = 512;
|
|
258
260
|
/** S12d: the cap a kept row (a `#layer` twin, a horizon) is encoded under: none it reaches, so it keeps its own size and only
|
|
259
261
|
* its encoding changes to 6×6, as S4's hand-made set had it. */
|
|
260
262
|
export const KEPT_ENCODE_MAX = 16_384;
|
|
261
263
|
export function phoneTierSize(source: string): number | undefined {
|
|
262
|
-
return source.endsWith('#layer') || /\/horizon
|
|
264
|
+
return source.endsWith('#layer') || /\/(?:horizon|sky)\/|\/panorama[.-][^/]*$/u.test(source) ? undefined : PHONE_TIER_MAX;
|
|
263
265
|
}
|
|
264
266
|
|
|
265
267
|
/** One phone file the cook made: `from` is the table target it stands in for, `url` its own content-named URL. */
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { NetCommand } from '@wildshard/wire/netCommand';
|
|
2
2
|
import type { AnimalPoseSample } from '../../../shared/engine/entities/AnimalSim';
|
|
3
3
|
import type { SimHost } from '../sim';
|
|
4
|
-
import { leadPlayer } from '../../../shared/engine/sim/leadPlayer';
|
|
5
4
|
import type { AnimalNetView } from '../../../shared/engine/net/animalNet';
|
|
6
5
|
import { actRoutes } from '../../../shared/engine/sim/actRoutes';
|
|
7
6
|
import { CombatWire, type CombatEvent } from './combatWire';
|
|
@@ -39,10 +38,10 @@ export class SimNetWorld implements NetWorld {
|
|
|
39
38
|
private readonly frame: number;
|
|
40
39
|
private readonly filings: (() => readonly LedgerFiling[]) | undefined;
|
|
41
40
|
private readonly turn = { still: new Set<string>(), extra: new Map<string, NetCommand>() };
|
|
42
|
-
/** `frame` names the cell this host's positions are local to; 0 is the highway, and any world that is not on a grid. `filings` reads the tick's grants, which the host's owner holds: the sim keeps none. */
|
|
43
|
-
constructor(host: SimHost, frame = 0, filings?: () => readonly LedgerFiling[]) {
|
|
41
|
+
/** `frame` names the cell this host's positions are local to; 0 is the highway, and any world that is not on a grid. `filings` reads the tick's grants, which the host's owner holds: the sim keeps none. `owner` selects the default network seat explicitly; legacy standalone callers use actor.player. */
|
|
42
|
+
constructor(host: SimHost, frame = 0, filings?: () => readonly LedgerFiling[], owner = 'actor.player') {
|
|
44
43
|
this.host = host; this.frame = frame; this.filings = filings; this.wire = new CombatWire(host); keepHitHistory(host);
|
|
45
|
-
this.player = this.playerOf(
|
|
44
|
+
this.player = this.playerOf(owner);
|
|
46
45
|
}
|
|
47
46
|
/** A player, as the client that owns it reads it. */
|
|
48
47
|
playerOf(id: string): NetPlayer {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Actor } from '@wildshard/engine/combat/pipeline';
|
|
2
|
+
import { gridZone } from '../../../shared/game/grid/rules';
|
|
3
|
+
import type { SimHost } from '@wildshard/engine/sim';
|
|
4
|
+
import type { AnimalSim } from '@wildshard/engine/entities/AnimalSim';
|
|
5
|
+
import { CELL_ABOVE, CELL_BELOW, CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
6
|
+
import { gridCreatureConstraint, installGridBorders } from '@wildshard/engine/physics/gridBorders';
|
|
7
|
+
import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
|
|
8
|
+
import { CharacterMotor } from '@wildshard/engine/physics/CharacterMotor';
|
|
9
|
+
|
|
10
|
+
/** A late controller may already have moved a driven boss before its own body step.
|
|
11
|
+
* Start the physics query inside the home; this port has no hidden continuation. */
|
|
12
|
+
function bindHome(host: SimHost, actor: AnimalSim, mounted: readonly AnimalSim[]): void {
|
|
13
|
+
const previous = actor.motionConstraint, radius = actor.dims.bodyRadius * actor.scale, limit = Math.max(0, CHUNK_HALF - radius - .001);
|
|
14
|
+
const constrain = gridCreatureConstraint(() => host.physics, radius), start = { x: 0, y: 0, z: 0 };
|
|
15
|
+
actor.motionConstraint = (from, to) => {
|
|
16
|
+
previous?.(from, to);
|
|
17
|
+
if (mounted.includes(actor)) return;
|
|
18
|
+
start.x = Math.max(-limit, Math.min(limit, from.x)); start.z = Math.max(-limit, Math.min(limit, from.z));
|
|
19
|
+
start.y = Math.max(-CELL_BELOW + radius + .001, Math.min(CELL_ABOVE - radius - .001, from.y));
|
|
20
|
+
constrain(start, to);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/** MP5.1: one cell's unmounted creatures stay home. Players and their mounted traveller remain free to cross. */
|
|
24
|
+
export function installCellHome(host: SimHost): void {
|
|
25
|
+
const bound = new WeakSet<AnimalSim>(), mounted: AnimalSim[] = [];
|
|
26
|
+
// Resolve the live object on every request: ids repeat between cells, and
|
|
27
|
+
// seats and creatures can join or leave after installation.
|
|
28
|
+
const interior = (actor: Actor): boolean => {
|
|
29
|
+
const player = host.players.get(actor.id);
|
|
30
|
+
if (player?.health === actor) return gridZone(player.position) === 'shard';
|
|
31
|
+
const creature = host.entities.get(actor.id);
|
|
32
|
+
return creature?.combatActor() === actor && gridZone(creature.position) === 'shard';
|
|
33
|
+
};
|
|
34
|
+
host.events.answer('damage.admit', request => request !== null && interior(request.target)
|
|
35
|
+
&& (request.source === 'env' || interior(request.source)) ? request : null, host.scope);
|
|
36
|
+
const sync = (): void => {
|
|
37
|
+
mounted.length = 0;
|
|
38
|
+
for (const player of host.players.values()) { const ride = mountedPlayerOf(host, player.id); if (ride?.mounted === true && ride.horse !== null) mounted.push(ride.horse); }
|
|
39
|
+
for (const actor of host.entities.values()) if (!bound.has(actor)) { bindHome(host, actor, mounted); bound.add(actor); }
|
|
40
|
+
};
|
|
41
|
+
// A dismount or a controller can put a capsule outside before its move.
|
|
42
|
+
// Rapier then keeps it on the wall's outside face; repair that invalid start
|
|
43
|
+
// after body resolution, while ordinary in-home movement needs no reset.
|
|
44
|
+
const repair = (): void => {
|
|
45
|
+
for (const actor of host.entities.values()) {
|
|
46
|
+
if (mounted.includes(actor)) continue;
|
|
47
|
+
const limit = Math.max(0, CHUNK_HALF - actor.dims.bodyRadius * actor.scale - .001);
|
|
48
|
+
const x = Math.max(-limit, Math.min(limit, actor.position.x)), z = Math.max(-limit, Math.min(limit, actor.position.z));
|
|
49
|
+
if (x === actor.position.x && z === actor.position.z) continue;
|
|
50
|
+
actor.position.x = x; actor.position.z = z;
|
|
51
|
+
if (actor.motor instanceof CharacterMotor) actor.motor.resetAt(actor.position);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
installGridBorders(host.physics, host.scope); sync(); repair();
|
|
55
|
+
host.onStep('grid.home', sync, { joined: true, snapshot: () => null, restore: value => { if (value !== null) throw new Error('Invalid cell home continuation'); },
|
|
56
|
+
physicsRestored: () => { installGridBorders(host.physics, host.scope); sync(); repair(); } });
|
|
57
|
+
host.onStep('grid.home.poses', repair, undefined, 'afterBodies');
|
|
58
|
+
}
|
|
@@ -10,7 +10,6 @@ import type { GridAssembly, GridCell, GridPoint } from '../../../shared/game/gri
|
|
|
10
10
|
import type { ResidencyAllocator } from '../../../shared/game/grid/allocator';
|
|
11
11
|
import { GridContinuationCache, GRID_CONTINUATION_CACHE_BYTES } from '../../../shared/game/grid/continuations';
|
|
12
12
|
import { gridBoardLimitAt } from '../../../shared/game/grid/rules';
|
|
13
|
-
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
14
13
|
|
|
15
14
|
/** Admission returns one owned, renderer-free regional host; its world is always in authored local coordinates. */
|
|
16
15
|
export interface GridResident { readonly host: SimHost; readonly dispose: () => void }
|
|
@@ -18,13 +17,21 @@ export interface GridResident { readonly host: SimHost; readonly dispose: () =>
|
|
|
18
17
|
export interface GridSimLease { release: () => void; update?: (state: { needed?: boolean; distance?: number }) => void }
|
|
19
18
|
/** Durable snapshots and native/browser admission are injected; no network operation runs during a fixed tick. */
|
|
20
19
|
export interface GridSimulationPorts {
|
|
20
|
+
/** The session's owning seat; older standalone callers use actor.player. */
|
|
21
|
+
readonly owner?: string;
|
|
21
22
|
readonly highway: GridResident;
|
|
23
|
+
/** ZE11 (J352): the cells a walker crosses into from the road (the session's home); absent, every cell. Any other cell is entered
|
|
24
|
+
* only by its gate's zone entry. */
|
|
25
|
+
readonly enterable?: (instance: string) => boolean;
|
|
22
26
|
load: (cell: GridCell, saved: SimSnapshot | undefined) => Promise<GridResident>;
|
|
23
27
|
save?: (instance: string, snapshot: SimSnapshot) => boolean;
|
|
24
28
|
/**
|
|
25
29
|
* An owner that keeps every continuation itself, and reloads them in `load` (E5.2b, a phone's worker). It captures an occupied
|
|
26
30
|
* world when told to, in whatever form it stores. Nothing is captured on admission or packed in memory: capturing a whole
|
|
27
|
-
* physics world grows a wasm heap that never gives it back, and a world nobody entered has nothing to keep.
|
|
31
|
+
* physics world grows a wasm heap that never gives it back, and a world nobody entered has nothing to keep. ZONE-ENTRY ZE2:
|
|
32
|
+
* it is not told at a leave. The world left stays resident with everything it held, so its capture is owed until its
|
|
33
|
+
* eviction, the only time it is lost: a whole world's capture stood the in-page server's tick for 122 to 134 ms
|
|
34
|
+
* (Driftwood) on the step onto the road. What a reload in between loses is only what moved since its last progress save.
|
|
28
35
|
*/
|
|
29
36
|
durable?: (instance: string, host: SimHost) => boolean;
|
|
30
37
|
read?: (instance: string) => SimSnapshot | undefined;
|
|
@@ -83,7 +90,7 @@ export function carryMotion(from: PlayerSim, to: PlayerSim): void {
|
|
|
83
90
|
|
|
84
91
|
/**
|
|
85
92
|
* Independent local physics worlds; only a world with a player in it advances, while visible neighbours remain frozen.
|
|
86
|
-
* Each player crosses on their own (P1-E3.9). `owner` is the
|
|
93
|
+
* Each player crosses on their own (P1-E3.9). `owner` is the explicit seat this session was built around:
|
|
87
94
|
* its systems bind to that seat, so when it leaves others behind the seat stays, parked, and a lone player never parks.
|
|
88
95
|
*/
|
|
89
96
|
export class GridSimulation {
|
|
@@ -96,6 +103,8 @@ export class GridSimulation {
|
|
|
96
103
|
private readonly requests = new Map<string, Promise<void>>();
|
|
97
104
|
private readonly cancelFrames = new Set<() => void>();
|
|
98
105
|
private readonly cleanupIssues: string[] = [];
|
|
106
|
+
/** Worlds left with their `durable` capture not yet taken (ZE2): it is taken at their eviction. */
|
|
107
|
+
private readonly owed = new Set<string>();
|
|
99
108
|
private sequence: Promise<void> = Promise.resolve();
|
|
100
109
|
private used = 0;
|
|
101
110
|
private disposed = false;
|
|
@@ -105,8 +114,8 @@ export class GridSimulation {
|
|
|
105
114
|
constructor(assembly: GridAssembly, ports: GridSimulationPorts) {
|
|
106
115
|
this.assembly = assembly; this.ports = ports;
|
|
107
116
|
this.limit = ports.maxResidents ?? 4;
|
|
108
|
-
const owner =
|
|
109
|
-
if (!Number.isInteger(this.limit) || this.limit < 1 || this.limit > 9 || ports.highway.host.embedded || !owner.hasMotor) throw new RangeError('Invalid grid simulation owner');
|
|
117
|
+
const owner = ports.highway.host.players.get(ports.owner ?? 'actor.player');
|
|
118
|
+
if (!Number.isInteger(this.limit) || this.limit < 1 || this.limit > 9 || ports.highway.host.embedded || owner === undefined || !owner.hasMotor) throw new RangeError('Invalid grid simulation owner');
|
|
110
119
|
this.owner = owner.id; this.sites.set(owner.id, null);
|
|
111
120
|
if (ports.reserve !== undefined && ports.residentBytes === undefined) throw new Error('Sim reservation needs admitted resident bytes');
|
|
112
121
|
if (ports.allocator !== undefined && (ports.residentBytes === undefined || ports.reserve !== undefined)) throw new Error('Use one sim reservation owner with admitted bytes');
|
|
@@ -162,7 +171,7 @@ export class GridSimulation {
|
|
|
162
171
|
const distance = (cell: GridCell): number => Math.max(Math.abs(feet.x - cell.origin.x), Math.abs(feet.z - cell.origin.z)) - CHUNK_HALF;
|
|
163
172
|
const active = this.current(player);
|
|
164
173
|
if (active !== null && distance(this.assembly.cell(active)) <= 10) return active;
|
|
165
|
-
return [...this.assembly.cells].sort((a, b) => a.instance.localeCompare(b.instance)).find((cell) => distance(cell) <= 6)?.instance ?? null;
|
|
174
|
+
return [...this.assembly.cells].sort((a, b) => a.instance.localeCompare(b.instance)).find((cell) => distance(cell) <= 6 && (this.ports.enterable?.(cell.instance) ?? true))?.instance ?? null;
|
|
166
175
|
}
|
|
167
176
|
/** Physics construction is not enough when the runtime/admitted closure has an additional readiness fence. */
|
|
168
177
|
ready(instance: string | null): boolean { return !this.disposed && (instance === null || (this.residents.has(instance) && !this.resident(instance).evicting && (this.ports.admitted?.(instance) ?? true))); }
|
|
@@ -229,13 +238,28 @@ export class GridSimulation {
|
|
|
229
238
|
/** Snapshot before leaving the active region. Failure keeps both its world and the traveller authoritative. */
|
|
230
239
|
checkpoint(instance: string): boolean {
|
|
231
240
|
const resident = this.residents.get(instance); if (resident === undefined || this.disposed) return false;
|
|
232
|
-
if (this.ports.durable !== undefined)
|
|
241
|
+
if (this.ports.durable !== undefined) {
|
|
242
|
+
if (this.occupied(instance)) { this.owed.add(instance); return true; }
|
|
243
|
+
if (!this.owed.has(instance)) return true;
|
|
244
|
+
// Nobody stands here, so the owner's seat holds no capsule; a capture reads one, as a parked seat holds.
|
|
245
|
+
const { host } = resident.value, parked = !this.seat(host, this.owner).hasMotor;
|
|
246
|
+
if (parked) this.parkOwner(host);
|
|
247
|
+
try { if (!this.ports.durable(instance, host)) return false; } finally { if (parked) this.unparkOwner(host); }
|
|
248
|
+
this.owed.delete(instance); return true;
|
|
249
|
+
}
|
|
233
250
|
const snapshot = this.occupied(instance) ? snapshotSimHost(resident.value.host) : this.snapshots.read(instance);
|
|
234
251
|
if (snapshot === undefined) throw new Error('Missing admitted grid continuation');
|
|
235
252
|
const packed = this.snapshots.pack(instance, snapshot); if (packed === null) return false;
|
|
236
253
|
if (this.ports.save?.(instance, snapshot) !== true) return false;
|
|
237
254
|
this.snapshots.store(instance, packed); return true;
|
|
238
255
|
}
|
|
256
|
+
/** Take every capture a step out left owed whose world nobody stands in now (a save on the road: a reload there must not lose
|
|
257
|
+
* the world left behind). False when one fails; the rest are still tried, and a failed one stays owed. */
|
|
258
|
+
flushOwed(): boolean {
|
|
259
|
+
let ok = true;
|
|
260
|
+
for (const instance of this.owed) if (!this.occupied(instance) && !this.checkpoint(instance)) ok = false;
|
|
261
|
+
return ok;
|
|
262
|
+
}
|
|
239
263
|
/** Readiness keeps a frozen destination resident; unneeded neighbours may be evicted by the shared allocator. */
|
|
240
264
|
retain(instance: string, needed: boolean, distance: number): void {
|
|
241
265
|
if (!Number.isFinite(distance) || distance < 0) throw new RangeError('Invalid sim residency distance');
|
|
@@ -260,7 +284,7 @@ export class GridSimulation {
|
|
|
260
284
|
commit: () => {
|
|
261
285
|
if (closed) return; closed = true;
|
|
262
286
|
if (this.disposed || this.residents.get(instance) !== resident) return;
|
|
263
|
-
this.residents.delete(instance);
|
|
287
|
+
this.residents.delete(instance); this.owed.delete(instance);
|
|
264
288
|
if (this.ports.read !== undefined) this.snapshots.drop(instance);
|
|
265
289
|
// Each cleanup runs even if another fails. The infallible allocator commit exposes failures for the session owner.
|
|
266
290
|
for (const dispose of [() => { this.ports.invalidated?.(instance); }, () => { resident.value.dispose(); }, () => { resident.lease?.release(); }]) {
|
|
@@ -24,7 +24,6 @@ import { MoverMechanic, type NativeMoverMotion } from '@wildshard/engine/sim/mov
|
|
|
24
24
|
import { parseMovers, type MoverData } from "@wildshard/format/movers";
|
|
25
25
|
import { carryPrompt } from "../../../shared/game/shardfile/wirePrompts";
|
|
26
26
|
import { actRoutes } from "@wildshard/engine/sim/actRoutes";
|
|
27
|
-
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
28
27
|
import { questBooks } from '@wildshard/engine/quest/players';
|
|
29
28
|
import { publishScriptBody } from '@wildshard/engine/sim/shardRows';
|
|
30
29
|
|
|
@@ -208,6 +207,8 @@ export class MoverRuntime {
|
|
|
208
207
|
private readonly carryPoses = new Map<string, CarryPose>();
|
|
209
208
|
/** Who rides each carry mover, when it is not the lead (P1-E3.10). A lone player's save never holds one. */
|
|
210
209
|
private readonly riders = new Map<string, string>();
|
|
210
|
+
/** Owner of legacy unnamed carry commands, selected when the native host installs. */
|
|
211
|
+
private nativeOwner = 'actor.player';
|
|
211
212
|
private readonly previousRides = new Map<string, boolean>();
|
|
212
213
|
private readonly flags: Pick<Flags, 'has' | 'set'> | undefined;
|
|
213
214
|
private readonly riderFlags: MoverPorts['riderFlags'];
|
|
@@ -279,10 +280,11 @@ export class MoverRuntime {
|
|
|
279
280
|
}
|
|
280
281
|
/** Queue a host-validated interact command; scene dispatch resolves the stable mover id, never an arbitrary function export. */
|
|
281
282
|
command(id: string, action: 1 | 2 | 3, player?: string): void {
|
|
283
|
+
const rider = player === this.nativeOwner ? undefined : player;
|
|
282
284
|
const row = this.data.find(m => m.id === id); if (row === undefined) throw new Error('Unknown mover');
|
|
283
285
|
if (row.carry !== undefined) {
|
|
284
|
-
if (this.riding(id) || this.carrying(
|
|
285
|
-
if (
|
|
286
|
+
if (this.riding(id) || this.carrying(rider) || action === 3) return;
|
|
287
|
+
if (rider === undefined) this.riders.delete(id); else this.riders.set(id, rider);
|
|
286
288
|
}
|
|
287
289
|
this.pending.set(id, action);
|
|
288
290
|
}
|
|
@@ -292,8 +294,8 @@ export class MoverRuntime {
|
|
|
292
294
|
if (id !== undefined && rows.length === 0) throw new Error('Unknown mover');
|
|
293
295
|
return rows.some(row => row.carry !== undefined && (this.pending.has(row.id) || [1, 0.5].includes(this.host.world.entity(row.entity)?.fields[6] ?? 0)));
|
|
294
296
|
}
|
|
295
|
-
/** Whether `player` (the
|
|
296
|
-
carrying(player?: string): boolean { return this.data.some(row => row.carry !== undefined && this.riders.get(row.id) ===
|
|
297
|
+
/** Whether `player` (the configured owner when absent) is on a carry mover. */
|
|
298
|
+
carrying(player?: string): boolean { const rider = player === this.nativeOwner ? undefined : player; return this.data.some(row => row.carry !== undefined && this.riders.get(row.id) === rider && this.riding(row.id)); }
|
|
297
299
|
/** View-only edges, including first arrival hints, never an authored update hook. */
|
|
298
300
|
takeRideTransitions(id: string): readonly MoverRideTransition[] { return this.rideEvents.get(id)?.splice(0) ?? []; }
|
|
299
301
|
/** Borrow the same declared prompts on the page; the native command names are the stable mover ids. */
|
|
@@ -324,7 +326,7 @@ export class MoverRuntime {
|
|
|
324
326
|
}
|
|
325
327
|
private carryNative(host: SimHost): void {
|
|
326
328
|
for (const [id, carry] of this.carryPoses) {
|
|
327
|
-
const named = this.riders.get(id), rider =
|
|
329
|
+
const named = this.riders.get(id), rider = host.players.get(named ?? this.nativeOwner);
|
|
328
330
|
if (!carry.riding) this.riders.delete(id);
|
|
329
331
|
if (rider === undefined) continue; // left the world mid-ride: the boat goes on without them
|
|
330
332
|
rider.position.set(...carry.at); rider.motor.resetAt(rider.position); rider.velocity.y = 0; rider.fall.grounded = false; if (!carry.riding) rider.yaw = carry.yaw;
|
|
@@ -332,23 +334,24 @@ export class MoverRuntime {
|
|
|
332
334
|
this.carryPoses.clear();
|
|
333
335
|
}
|
|
334
336
|
/** Protect ordinary walking while the existing fixed mover lane publishes carry. */
|
|
335
|
-
bindNativeCarry(host: SimHost): void {
|
|
337
|
+
bindNativeCarry(host: SimHost, owner = 'actor.player'): void {
|
|
336
338
|
if (!this.data.some(row => row.carry !== undefined)) return;
|
|
339
|
+
if (!host.players.has(owner)) throw new RangeError('Unknown native carry owner');
|
|
340
|
+
this.nativeOwner = owner;
|
|
337
341
|
host.events.answer('player.carrying', carried => carried || this.carrying(), host.scope);
|
|
338
|
-
|
|
339
|
-
host.leading.push(body => this.carrying(body === lead ? undefined : body.id)); // a client's capsule stays out of a boat's way
|
|
342
|
+
host.leading.push(body => this.carrying(body.id === owner ? undefined : body.id)); // a client's capsule stays out of a boat's way
|
|
340
343
|
const routes = actRoutes(host);
|
|
341
344
|
for (const row of this.data) row.carry?.prompts.forEach(({ at: [x, y, z], radius }, end) => {
|
|
342
345
|
routes.claims.set(carryPrompt(row.id, end), player => {
|
|
343
346
|
const body = host.players.get(player)?.position;
|
|
344
|
-
if (body !== undefined && Math.hypot(body.x - x, body.y - y, body.z - z) <= radius + CARRY_REACH) this.command(row.id, end === 0 ? 1 : 2, player ===
|
|
347
|
+
if (body !== undefined && Math.hypot(body.x - x, body.y - y, body.z - z) <= radius + CARRY_REACH) this.command(row.id, end === 0 ? 1 : 2, player === owner ? undefined : player);
|
|
345
348
|
else routes.refused++;
|
|
346
349
|
});
|
|
347
350
|
});
|
|
348
351
|
host.events.answer('player.traversal', dt => {
|
|
349
352
|
const player = host.traversing;
|
|
350
353
|
if (typeof dt !== 'number') return dt;
|
|
351
|
-
if (player === null || player ===
|
|
354
|
+
if (player === null || player.id === owner) return this.carrying();
|
|
352
355
|
return this.carrying(player.id) ? true : dt;
|
|
353
356
|
}, host.scope);
|
|
354
357
|
host.onStep('movers.carry', () => { this.carryNative(host); }, undefined, 'afterBodies');
|
|
@@ -537,7 +540,7 @@ export class MoverScriptDriver {
|
|
|
537
540
|
schedules: [this.schedule(() => { if (this.runtime === undefined) throw new Error('Missing mover runtime'); return this.runtime; }, permissions), ...(extra?.schedules ?? [])] });
|
|
538
541
|
}
|
|
539
542
|
/** Attach native handles to the same host; an explicit drive owns one fixed tick, never another script host. */
|
|
540
|
-
install(sim: SimHost, input: ReturnType<typeof createShardfileComposedLane> | DeclaredMoverComposition, options: { id: string; restoring?: boolean; restoreFlags?: ReadonlySet<string>; activation?: MoverActivationPorts; drive?: boolean; permissions?: () => ReadonlyMap<string, number>; joined?: boolean }): MoverRuntime {
|
|
543
|
+
install(sim: SimHost, input: ReturnType<typeof createShardfileComposedLane> | DeclaredMoverComposition, options: { id: string; owner?: string; restoring?: boolean; restoreFlags?: ReadonlySet<string>; activation?: MoverActivationPorts; drive?: boolean; permissions?: () => ReadonlyMap<string, number>; joined?: boolean }): MoverRuntime {
|
|
541
544
|
if (this.runtime !== undefined) throw new Error('Mover driver is already installed');
|
|
542
545
|
const lane = 'host' in input ? input : this.compose({ ...input.content, sim: { ...input.content.sim, scripts: [...input.assets.keys()] } }, input.assets,
|
|
543
546
|
{ rules: input.rules, entities: [], actors: new Map(), query: () => [] }, undefined, options.permissions,
|
|
@@ -548,13 +551,14 @@ export class MoverScriptDriver {
|
|
|
548
551
|
const riderFlags = arrivals.length === 0 ? undefined : (rider: string | undefined): Flags | undefined => {
|
|
549
552
|
if (sim.players.size === 0) return sim.flags;
|
|
550
553
|
const books = questBooks(sim); books.claim(arrivals);
|
|
551
|
-
|
|
554
|
+
const player = rider ?? options.owner ?? 'actor.player';
|
|
555
|
+
return sim.players.has(player) ? books.of(player).flags : undefined;
|
|
552
556
|
};
|
|
553
557
|
const runtime = new MoverRuntime(this.data, { lane, flags: sim.flags, ...(riderFlags === undefined ? {} : { riderFlags }), host: lane.host, physics: () => sim.physics, scope: sim.scope,
|
|
554
558
|
...(options.restoring === undefined ? {} : { restoring: options.restoring }),
|
|
555
559
|
...(options.restoreFlags === undefined ? {} : { restoreFlags: options.restoreFlags }),
|
|
556
560
|
activation: { ground: () => playerGrounds(sim), ...options.activation } });
|
|
557
|
-
this.runtime = runtime; runtime.bindNativeCarry(sim);
|
|
561
|
+
this.runtime = runtime; runtime.bindNativeCarry(sim, options.owner);
|
|
558
562
|
for (const row of this.data) publishScriptBody(sim, row.id, () => runtime.pose(row.id));
|
|
559
563
|
// `joined`: a save from before these movers had their step holds none of it, so its world has no bodies to reconnect: build them
|
|
560
564
|
let continued = false;
|
|
@@ -64,6 +64,7 @@ import type { Shardfile } from "@wildshard/format/shardSchema";
|
|
|
64
64
|
import { speciesResolver, simStrikes } from "./brain";
|
|
65
65
|
import { createShardfileScriptLane, verifiedScriptModules, type ScriptModuleAssets, type ShardScriptPorts } from "../shardfile/scripts";
|
|
66
66
|
import { installDeclaredBrains, type DeclaredBrainPorts } from "../shardfile/brainRuntime";
|
|
67
|
+
import { installDataRespawns } from "../shardfile/dataRespawn";
|
|
67
68
|
import { createShardfileComposedLane, type DeclaredScriptBrainPorts } from "../shardfile/scriptComposition";
|
|
68
69
|
import { bindPlayerColumns, dataCreaturePorts } from "../../../shared/game/shardfile/dataCreaturePorts";
|
|
69
70
|
import { prepareDeclaredGroupBrains, type DeclaredGroupPorts, type DeclaredGroupPolicy } from "../shardfile/groupRuntime";
|
|
@@ -644,6 +645,7 @@ export function bindShardfileSim(host: SimHost, shard: Shardfile, assets: Readon
|
|
|
644
645
|
} });
|
|
645
646
|
}
|
|
646
647
|
installDeclaredBrains(host, shard.creatures.spawns.filter((spawn) => spawn.brain === null || (!custom.has(spawn.brain) && !groupIds.has(spawn.brain))), shard.creatures.brains.filter((brain) => brain.kind !== 'script'), ports.brains ?? dataPorts?.brains);
|
|
648
|
+
installDataRespawns(host, shard.creatures.spawns);
|
|
647
649
|
dataPorts?.install();
|
|
648
650
|
const decisionRows = decisionScriptsFromSections(ports.sections);
|
|
649
651
|
const decisionActors = new Set(decisionRows.flatMap(row => Object.values(row.actors)));
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// TEMPLATE-E2E TC-E2 (J361, meta TEMPLATE-E2E-PLAN): a data shard's creatures respawn. A `creatures.spawns` row's optional
|
|
2
|
+
// `respawn` (seconds, 1 to 3600, shard-format 0.5.8) brings its body back at its `at`, whole, that long after it dies: the
|
|
3
|
+
// declared brain and group skip a dead actor and resume once it is alive again, so reviving the body restores them. The
|
|
4
|
+
// waits are the host's state (one adapter), so a save keeps the clock; a cell asleep spends it (SC10, as declared homes do).
|
|
5
|
+
import * as v from 'valibot';
|
|
6
|
+
import type { SimHost } from '@wildshard/engine/sim';
|
|
7
|
+
|
|
8
|
+
/** One spawn row's revive inputs (the format's `creatures.spawns` row). */
|
|
9
|
+
export interface RespawnRow { readonly id: string; readonly at: readonly [number, number, number]; readonly yaw: number; readonly respawn?: number | undefined }
|
|
10
|
+
|
|
11
|
+
const finite = v.pipe(v.number(), v.finite());
|
|
12
|
+
const Saved = v.strictObject({ version: v.literal(1), waits: v.array(v.tuple([v.string(), finite])) });
|
|
13
|
+
export const DATA_RESPAWN_STEP = 'data.respawn';
|
|
14
|
+
|
|
15
|
+
/** Install the respawn clocks for the rows that declare one; nothing when none does (no adapter, so old saves restore). */
|
|
16
|
+
export function installDataRespawns(host: SimHost, rows: readonly RespawnRow[]): { readonly waits: () => ReadonlyMap<string, number> } | null {
|
|
17
|
+
const timed = new Map(rows.flatMap((row) => (row.respawn === undefined ? [] : [[row.id, row] as const])));
|
|
18
|
+
if (timed.size === 0) return null;
|
|
19
|
+
for (const id of timed.keys()) if (!host.entities.has(id)) throw new Error(`Respawn row ${id} names no body`);
|
|
20
|
+
const waits = new Map<string, number>();
|
|
21
|
+
host.events.on('actor.died', ({ actor }) => { const row = timed.get(actor.id); if (row?.respawn !== undefined) waits.set(row.id, row.respawn); }, host.scope);
|
|
22
|
+
host.events.on('world.slept', ({ seconds }) => { for (const [id, left] of waits) waits.set(id, Math.max(Number.MIN_VALUE, left - seconds)); }, host.scope);
|
|
23
|
+
const revive = (row: RespawnRow): void => {
|
|
24
|
+
const body = host.entities.get(row.id); if (body === undefined) return;
|
|
25
|
+
body.place(row.at[0], row.at[2], row.yaw, row.at[1]);
|
|
26
|
+
body.revive();
|
|
27
|
+
// A data cell keeps a dead body's motor (no body bands drop it): stand its capsule at the spawn, no sweep. Under body
|
|
28
|
+
// bands a dead body has none, and the next sync makes one where it now stands.
|
|
29
|
+
body.motor?.resetAt?.(body.position);
|
|
30
|
+
};
|
|
31
|
+
host.onStep(DATA_RESPAWN_STEP, (dt) => {
|
|
32
|
+
for (const [id, left] of waits) {
|
|
33
|
+
const next = left - dt;
|
|
34
|
+
if (next > 0) { waits.set(id, next); continue; }
|
|
35
|
+
waits.delete(id);
|
|
36
|
+
const row = timed.get(id); if (row !== undefined) revive(row);
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
snapshot: () => ({ version: 1, waits: [...waits].sort(([a], [b]) => a.localeCompare(b)) }),
|
|
40
|
+
restore: (value) => {
|
|
41
|
+
const state = v.parse(Saved, value);
|
|
42
|
+
waits.clear();
|
|
43
|
+
for (const [id, left] of state.waits) { if (!timed.has(id)) throw new Error(`Incompatible respawn continuation: ${id}`); waits.set(id, left); }
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
return { waits: () => waits };
|
|
47
|
+
}
|
|
@@ -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
|
} });
|