@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.
Files changed (100) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lint/engine-sides.json +2 -0
  3. package/lint/sim-players.json +2 -13
  4. package/package.json +9 -2
  5. package/scripts/apfs-clone.mjs +5 -2
  6. package/scripts/app-build/catalogue.ts +39 -8
  7. package/scripts/app-build/serviceWorker.ts +4 -1
  8. package/scripts/app-build/splitOutput.mjs +33 -11
  9. package/scripts/ci-pack.mjs +3 -3
  10. package/scripts/engine-ci-shard.mjs +11 -0
  11. package/scripts/fight-page-census.mjs +131 -0
  12. package/scripts/goldens/board.py +44 -11
  13. package/scripts/goldens/native-residency.d.mts +1 -0
  14. package/scripts/goldens/native-residency.mjs +18 -4
  15. package/scripts/keep-copy.mjs +120 -0
  16. package/scripts/land.mjs +36 -6
  17. package/scripts/lane-live.mjs +136 -0
  18. package/scripts/leftovers-report.mjs +47 -0
  19. package/scripts/loading-card-proof.mjs +42 -9
  20. package/scripts/loading-flow/benchmax.mjs +57 -7
  21. package/scripts/loading-flow/stalls.d.mts +2 -0
  22. package/scripts/loading-flow/stalls.mjs +13 -0
  23. package/scripts/mmo-bots.mjs +5 -3
  24. package/scripts/mmo-grid-proof.mjs +74 -0
  25. package/scripts/mmo-seat-proof.mjs +43 -0
  26. package/scripts/nightly-heads.ts +13 -13
  27. package/scripts/nightly-model.ts +26 -12
  28. package/scripts/nightly.proof.ts +18 -5
  29. package/scripts/nightly.ts +13 -8
  30. package/scripts/no-astc-boot.mjs +77 -0
  31. package/scripts/physics-route.json +6 -6
  32. package/scripts/pins-reuse.mjs +1 -0
  33. package/scripts/pins-staging.ts +54 -0
  34. package/scripts/pins.ts +5 -0
  35. package/scripts/ring3.proof.ts +71 -0
  36. package/scripts/ring3.ts +100 -0
  37. package/scripts/scratch-dir.mjs +31 -12
  38. package/scripts/scratch-sweep.mjs +15 -23
  39. package/scripts/server-release/items.d.mts +7 -0
  40. package/scripts/server-release/items.mjs +28 -0
  41. package/scripts/server-release/publish.mjs +9 -1
  42. package/scripts/side-parity.mjs +1 -1
  43. package/scripts/test-products.json +1 -0
  44. package/scripts/tsconfig.json +2 -0
  45. package/scripts/vitest-ci-files.ts +5 -1
  46. package/scripts/vps/wildshard-config +106 -1
  47. package/scripts/warm-native-chrome.mjs +9 -3
  48. package/scripts/worker-client-fights.mjs +9 -3
  49. package/scripts/worktree-reap.mjs +15 -131
  50. package/scripts/worktree.mjs +92 -12
  51. package/src/client/engine/audio/audioLog.ts +7 -2
  52. package/src/client/engine/boot/diagnostics.ts +69 -1
  53. package/src/client/engine/core/ktx2.ts +5 -3
  54. package/src/client/engine/core/ktx2Zstd.ts +2 -1
  55. package/src/client/engine/pwa/sw.js +26 -8
  56. package/src/client/engine/render/dataLook.ts +14 -7
  57. package/src/client/engine/render/lookLight.ts +64 -20
  58. package/src/client/engine/ui/Loading.ts +6 -8
  59. package/src/client/engine/ui/lookLightOption.ts +1 -1
  60. package/src/client/game/audio/cueDirector.ts +2 -1
  61. package/src/client/game/boss/arenaRoom.ts +4 -3
  62. package/src/client/game/boss/roamingProjection.ts +1 -1
  63. package/src/client/game/devScene/hook.ts +1 -1
  64. package/src/client/game/devScene/liveLook.ts +1 -1
  65. package/src/client/game/grid/dataCellKit.ts +9 -1
  66. package/src/client/game/grid/products.ts +21 -7
  67. package/src/client/game/grid/session.ts +6 -4
  68. package/src/client/game/population/signals.ts +1 -1
  69. package/src/client/game/quest/chapterDirector.ts +1 -0
  70. package/src/client/game/shardfile/clientBossTelegraph.ts +4 -3
  71. package/src/client/game/shardfile/clientWorker.ts +22 -6
  72. package/src/client/game/shardfile/look.ts +1 -1
  73. package/src/client/game/shardfile/runtimeProduct.ts +9 -5
  74. package/src/client/game/shardfile/wirePage.ts +5 -2
  75. package/src/client/game/shardfile/worldSceneTextures.ts +15 -9
  76. package/src/cook/game/cookWorker.ts +8 -5
  77. package/src/cook/game/tierTextures.ts +5 -3
  78. package/src/server/engine/net/simWorld.ts +3 -4
  79. package/src/server/game/grid/cellHome.ts +58 -0
  80. package/src/server/game/grid/simulation.ts +5 -4
  81. package/src/server/game/plugin/mover.ts +18 -14
  82. package/src/server/game/shardfile/declaredKitItems.ts +31 -7
  83. package/src/server/host/bake/headlessWorker.ts +3 -3
  84. package/src/server/host/dedicated/cellWorker.ts +4 -2
  85. package/src/server/host/dedicated/main.ts +7 -4
  86. package/src/server/host/dedicated/packReader.ts +15 -2
  87. package/src/server/host/dedicated/playerStore.ts +1 -1
  88. package/src/server/host/headlessRuntime.ts +11 -6
  89. package/src/server/host/standalone/cellWorld.ts +20 -6
  90. package/src/server/host/standalone/gridServer.ts +3 -1
  91. package/src/server/host/standalone/roadWorld.ts +6 -0
  92. package/src/shared/engine/physics/gridBorders.ts +15 -1
  93. package/src/shared/engine/sim/snapshot.ts +5 -5
  94. package/src/shared/game/ledger.ts +13 -4
  95. package/src/shared/game/loot/platformCatalogue.ts +14 -0
  96. package/src/shared/game/quest/ledger.ts +3 -3
  97. package/src/shared/game/shardfile/items.ts +9 -1
  98. package/src/shared/host/headlessJourney.ts +3 -3
  99. package/src/shared/host/headlessTape.ts +7 -6
  100. package/src/shared/host/releaseRows.ts +4 -1
@@ -157,7 +157,7 @@ export interface GridSessionHost {
157
157
  readonly physics: Physics;
158
158
  readonly scope: Scope;
159
159
  readonly feet: () => { readonly x: number; readonly y: number; readonly z: number };
160
- /** Home/far coverage can load before controls; neighbour products and near views start after this boundary. */
160
+ /** Only home coverage can load before controls; every neighbour read waits for this boundary. */
161
161
  readonly backgroundReady?: () => boolean;
162
162
  /** Presentation-only short range while an actual crossing waits at its
163
163
  * in-world screen. Disabled in the same frame the crossing settles. */
@@ -248,7 +248,8 @@ function neighbourTiles(scope: Scope, prepare: (tile: PreparedRingTile) => Promi
248
248
  async function loadFar(slug: string): Promise<{ prepared: FarPrepared; bytes: number }> {
249
249
  // Pure authored projects have no repo bake: their proxy comes from their product's sections and far files (O26: read
250
250
  // hash-verified on their own, not after admitting the whole product), instead of a nonexistent far.json
251
- const shardfile = await readGridShardfileFar(slug);
251
+ // a slug the build baked no far for (an upload with no mesh collision) reads its product's far row whatever its world
252
+ const shardfile = await readGridShardfileFar(slug, publicBytes()[`/assets/baked/${slug}/far.json`] === undefined);
252
253
  if (shardfile !== null) return loadShardfileFar(shardfile.rows, shardfile.read);
253
254
  const response = await fetch(versionedUrl(`/assets/baked/${slug}/far.json`));
254
255
  if (!response.ok) throw new Error(`far.json ${slug}: ${String(response.status)}`);
@@ -596,8 +597,9 @@ export class GridSession {
596
597
  const home = this.home;
597
598
  // the root world is neutral highway physics and the home an owned region like every cell, so every cell is a neighbour
598
599
  this.neighbours = [...this.assembly.cells];
599
- const initialRing = new Set(this.neighbours.filter(cell => Math.abs(cell.cell[0] - home.cell[0]) <= 1
600
- && Math.abs(cell.cell[1] - home.cell[1]) <= 1).map(cell => cell.instance));
600
+ // NB12: the eight adjacent cells used to compete with home for downloads
601
+ // and GLTF decodes. The home's own coverage is the only boot exception.
602
+ const initialRing = new Set([home.instance]);
601
603
  const backgroundReady = (): boolean => host.backgroundReady?.() !== false;
602
604
  // ringsReady: the far ring charges each proxy its declared bytes before it loads, not the 1.6 MB cap, so placeholder
603
605
  // charges never leave a visible cell out of the ring (12 visible proxies of 0.4-1.6 MB fit its 14.4 MB)
@@ -14,7 +14,7 @@ export function installPopulationSignals(ctx: ShardContext, scope: Scope, effect
14
14
  if(typeof x!=='number'||typeof zOrY!=='number')return;
15
15
  if(view.name.startsWith('creature.signal:')) {
16
16
  const name=view.name.slice('creature.signal:'.length);
17
- ctx.app.events.emit('creature.signal',{name,x,z:zOrY});notice(notices?.signal(name,view.tick/60)??null);
17
+ ctx.app.events.emit('creature.signal',{name,x,z:zOrY});wirePage.drew(view.name);notice(notices?.signal(name,view.tick/60)??null);
18
18
  } else if(view.name.startsWith('creature.sound:')&&typeof third==='number') {
19
19
  ctx.app.events.emit('creature.sound',{cue:view.name.slice('creature.sound:'.length),x,y:zOrY,z:third});
20
20
  } else if(view.name==='creature.knockdown'&&typeof third==='number') {
@@ -156,6 +156,7 @@ function wiredQuestSpawns(ctx: ShardContext, rows: QuestSpawnPageRows, flags: Fl
156
156
  const [id, x = 0, y = 0, z = 0] = args, cue = rows.cues.find(row => row.id === id);
157
157
  if (cue?.kind === 'sound') bank.shot(cue.name, { at: { x, y, z } });
158
158
  else if (cue?.kind === 'puff' && puffs.length < 64) puffs.push({ x, y, z });
159
+ if (cue !== undefined) wirePage.drew(name);
159
160
  }));
160
161
  ctx.scope.onDispose(flags.onChange((flag, on) => {
161
162
  const effects = complete.get(flag);
@@ -23,14 +23,15 @@ export function installClientBossTelegraph(ctx: ShardContext, input: unknown): v
23
23
  new MeshBasicMaterial({ color: view.color, transparent: true, opacity: 0, depthWrite: false, side: DoubleSide, fog: false }));
24
24
  wall.name = view.system; wall.visible = false; ctx.root.add(wall); ctx.scope.own(wall.geometry); ctx.scope.own(wall.material); ctx.scope.onDispose(() => { wall.removeFromParent(); });
25
25
  /** A page on a server holds no body to read a strike off: the server says it, until it stops saying so. */
26
- const heard = { through: 0, aim: 0, x: 0, z: 0, fresh: false, at: Number.NEGATIVE_INFINITY }, name = `${BOSS_STRIKE}${strike.id}`;
26
+ const heard = { through: 0, aim: 0, x: 0, z: 0, fresh: 0, at: Number.NEGATIVE_INFINITY }, name = `${BOSS_STRIKE}${strike.id}`;
27
27
  wirePage.whenLive(ctx.scope, client => client.onView(call => {
28
28
  if (call.name !== name) return;
29
29
  const [through = 0, aim = 0, x = 0, z = 0] = call.args;
30
- Object.assign(heard, { through, aim, x, z, fresh: true });
30
+ Object.assign(heard, { through, aim, x, z, fresh: heard.fresh + 1 });
31
31
  }));
32
32
  ctx.system({ id: view.system, phase: 'update', run: (_dt, t) => {
33
- if (heard.fresh) { heard.fresh = false; heard.at = t; } // the clock's the frame's: a slow frame still shows what it heard
33
+ // the clock's the frame's: a slow frame still shows what it heard, and counts every word it draws (EG-15's census)
34
+ if (heard.fresh > 0) { wirePage.drew(name, heard.fresh); heard.fresh = 0; heard.at = t; }
34
35
  const live = t - heard.at < HEARD_FOR;
35
36
  wall.visible = live;
36
37
  if (!live) return;
@@ -6,7 +6,7 @@ import type { LiveGridWire } from '../grid/liveSession';
6
6
  import { chosenCell, gotoHosted, pageGoto } from '../../../shared/game/grid/pageMode';
7
7
  import type { SystemSpec } from '@wildshard/engine/app/systems';
8
8
  import type { Player } from '@wildshard/engine/player/Player';
9
- import { Vector3, type Object3D } from 'three';
9
+ import { Scene, Vector3, type Object3D } from 'three';
10
10
  import { appIdentity } from '@wildshard/engine/app/identity';
11
11
  import { bootMark, bootTask } from '@wildshard/engine/boot/timing';
12
12
  import { SEAT_GRACE_MS, seatedInTime } from './seatGrace';
@@ -58,6 +58,7 @@ import { OWNED_ROW } from '../../../shared/game/loot/ownedRows';
58
58
  import { declaredKitSlots } from '../../../shared/game/shardfile/items';
59
59
  import { earlyStandalone, serverRoute } from './serverRoute';
60
60
  import { worldHosted } from '../grid/oneWayIn';
61
+ import { setLampFollow } from '@wildshard/engine/render/lookLight';
61
62
 
62
63
  type Creatures = Pick<RowBodiesView, 'animals' | 'spawn' | 'retire' | 'onWindup' | 'presentHit' | 'presentDeath' | 'presentReward'>;
63
64
  /** What a grid page lends: its crossing follows the server, and its creatures are the entered cell's. */
@@ -166,6 +167,10 @@ export interface WorkerClientReport {
166
167
  owned: Readonly<Record<string, number>>; sky: number | null; day: number | null;
167
168
  /** What this page drew of what it only hears, by name. */
168
169
  drawn: Readonly<Record<string, number>>;
170
+ /** EG-15: every view word the server said to this page, by name: what `drawn` is held against (scripts/fight-page-census.mjs). */
171
+ heard: Readonly<Record<string, number>>;
172
+ /** Of those, the words for a view this page hasn't built (`wirePage.unbuilt`): not drawn, and not dark. */
173
+ offstage: Readonly<Record<string, number>>;
169
174
  /** Movers this page holds, the poses rows have given them, and the highest drift rows have laid. */
170
175
  movers: number; posed: number; sand: number;
171
176
  /** Bodies this page made and the rows put away, by kind: what its own sim still builds. */
@@ -175,8 +180,14 @@ export interface WorkerClientReport {
175
180
  /** What corrections disagreed on, and server-owned transitions that were deliberately not corrections. */
176
181
  missed: Readonly<NetPlayer['predictor']['missed']>; misses: readonly (readonly number[])[]; authoritative: Readonly<NetPlayer['predictor']['authoritative']>;
177
182
  }
178
- /** A fight as a proof reads it: its row, where its body stands and the server's name for it. */
179
- export type WorkerClientFight = EncounterRow & { readonly at: { readonly x: number; readonly y: number; readonly z: number } | null; readonly name: string | null };
183
+ /** A fight as a proof reads it: its row, where its body stands and the server's name for it. `shown` (EG-15): the page's body for that row
184
+ * is in the scene and visible; null when the page holds no row body for it (an open arena draws its own, off its view words). */
185
+ export type WorkerClientFight = EncounterRow & { readonly at: { readonly x: number; readonly y: number; readonly z: number } | null; readonly name: string | null; readonly shown: boolean | null };
186
+ /** Whether an object is drawn: visible, and so is every parent up to a scene. */
187
+ function inScene(object: Object3D): boolean {
188
+ for (let at: Object3D | null = object; at !== null; at = at.parent) { if (!at.visible) return false; if (at instanceof Scene) return true; }
189
+ return false;
190
+ }
180
191
  declare global { interface Window { __onlinePlayers?: () => OtherPlayers['shown']; __workerClientFights?: () => readonly WorkerClientFight[]; __workerClientHits?: (by: number) => void; __workerClientTravel?: (to: ShardSlug) => void;__workerClientSky?: (name: string) => void; __workerClientTime?: (pick: OptionValue<'time'>) => void; __workerClientRow?: (name: string) => number | undefined; __workerClientFlag?: (flag: string) => void; __workerClientDevColliders?: (name: string, boxes: readonly DevBox[]) => void; __workerClientRows?: (kind: string) => readonly { readonly x: number; readonly y: number; readonly z: number }[]; __workerClientGate?: (flag: string) => boolean; __workerClientBot?: (id: string, x: number, y: number, z: number) => { readonly move: (x: number, y: number, z: number) => void; readonly press: (id: string) => void; readonly end: () => void }; __workerClient?: () => WorkerClientReport; __workerClientSave?: () => Promise<void> } }
181
192
 
182
193
  /** The page's pose inputs, as acts short enough to go. */
@@ -429,6 +440,8 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
429
440
  wirePage.led = () => net.predictor.leading; wirePage.rowBody = handle => bodies.get(handle)?.body ?? null;
430
441
  wirePage.namedBody = id => { for (const [handle, { body }] of bodies) if (client.entities.get(handle)?.id === id) return body; return null; };
431
442
  scope.onDispose(() => { wirePage.unbind(); wirePage.led = () => false; wirePage.rowBody = () => null; wirePage.namedBody = () => null; });
443
+ // SHARD-SOURCE AP24b: a look lamp that follows an actor rides its body, or one of its bones, by the server's name for it
444
+ scope.onDispose(setLampFollow(ports.scene, (actor, bone) => { const body = wirePage.namedBody(actor); return body === null ? null : bone === undefined ? body.mesh : body.mesh.skeleton.getBoneByName(bone) ?? null; }));
432
445
  // J116: the lock's body by the server's name for it
433
446
  net.lockTarget = () => {
434
447
  if (lockOn.state !== 'locked' || lockOn.target === null) return undefined;
@@ -475,9 +488,11 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
475
488
  if (shell.redials === true) others = new (await import('@wildshard/engine/net/otherPlayers')).OtherPlayers(client, ports.scene, scope, player.position);
476
489
  if (new URLSearchParams(location.search).has('bossGod')) shell.bossGod();
477
490
  bootMark('server:ready-send'); shell.ready();
478
- const started = diagnosticNow(), report: WorkerClientReport = { drawn: wirePage.drawn, frames: 0, framesPerSecond: 0, ticksPerSecond: 0, correctionsPerMinute: 0, corrections: 0, retired: {}, spawnMs: {}, missed: net.predictor.missed, misses: net.predictor.misses, authoritative: net.predictor.authoritative, worstOffset: 0, queue: 0, replaysPerFrame: 0, delayMs: 0, jitterMs: 0, interpHeld: 0, interpStarved: 0, mainMsP95: 0, workerTickMs: 0, rows: 0, attacks: 0, hits: 0, kills: 0, refused: 0, held: 0, dropped: 0, hp: 0, falls: 0, closed: null, x: 0, z: 0, cell: 0, serverX: 0, serverZ: 0, restored, savedTick: -1, savedOk: false, receipts: [], quests: {}, flags: [], paid: 0, fights: [], owned: {}, sky: null, day: null, clawed: false, own: null, movers: 0, posed: 0, sand: 0 };
491
+ const heard: Record<string, number> = {};
492
+ const started = diagnosticNow(), report: WorkerClientReport = { drawn: wirePage.drawn, heard, offstage: wirePage.offstage, frames: 0, framesPerSecond: 0, ticksPerSecond: 0, correctionsPerMinute: 0, corrections: 0, retired: {}, spawnMs: {}, missed: net.predictor.missed, misses: net.predictor.misses, authoritative: net.predictor.authoritative, worstOffset: 0, queue: 0, replaysPerFrame: 0, delayMs: 0, jitterMs: 0, interpHeld: 0, interpStarved: 0, mainMsP95: 0, workerTickMs: 0, rows: 0, attacks: 0, hits: 0, kills: 0, refused: 0, held: 0, dropped: 0, hp: 0, falls: 0, closed: null, x: 0, z: 0, cell: 0, serverX: 0, serverZ: 0, restored, savedTick: -1, savedOk: false, receipts: [], quests: {}, flags: [], paid: 0, fights: [], owned: {}, sky: null, day: null, clawed: false, own: null, movers: 0, posed: 0, sand: 0 };
479
493
  if (unseated) void shell.booted.then(answer => { report.restored = answer.restored; bootMark('server:seated-late'); return undefined; }, () => undefined);
480
494
  scope.onDispose(client.onLedger(receipt => { report.receipts.push(`${receipt.grant}:${receipt.name}`); }));
495
+ scope.onDispose(client.onView(({ name }) => { heard[name] = (heard[name] ?? 0) + 1; }));
481
496
  const contacts: NetCombatEvent[] = [];
482
497
  scope.onDispose(client.onTravel(() => { contacts.length = 0; }));
483
498
  scope.onDispose(client.onCombat(event => {
@@ -531,7 +546,7 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
531
546
  let inputs = poses.get(id);
532
547
  if (inputs === undefined) { inputs = {}; poses.set(id, inputs); }
533
548
  inputs[field] = value;
534
- for (const [handle, { body }] of bodies) if (client.entities.get(handle)?.id === id) { body.mem[field] = value; break; }
549
+ for (const [handle, { body }] of bodies) if (client.entities.get(handle)?.id === id) { body.mem[field] = value; wirePage.drew(name); break; }
535
550
  }));
536
551
  const decks = new NetMovers(client, wirePage.movers, player.position);
537
552
  scope.onDispose(net.world.addMover(decks));
@@ -616,7 +631,8 @@ async function startWorkerClient(ports: WorkerClientPorts, card: ReturnType<type
616
631
  const out: WorkerClientFight[] = [];
617
632
  for (const fight of wirePage.encounters()) {
618
633
  const body = client.latest === null ? null : client.fields(client.latest, fight.body);
619
- out.push({ ...fight, at: body === null ? null : { x: Number(body['x']), y: Number(body['y']), z: Number(body['z']) }, name: client.entities.get(fight.body)?.id ?? null });
634
+ const held = bodies.get(fight.body)?.body.mesh ?? null;
635
+ out.push({ ...fight, at: body === null ? null : { x: Number(body['x']), y: Number(body['y']), z: Number(body['z']) }, name: client.entities.get(fight.body)?.id ?? null, shown: held === null ? null : inScene(held) });
620
636
  }
621
637
  return out;
622
638
  };
@@ -23,6 +23,6 @@ export function shardfileLook(look: Shardfile['look'], assets?: ReadonlyMap<stri
23
23
  // exposure and vignette); the bloom radius rides the bloom, which the row and the tier gate
24
24
  return dataLook({ day: look.day ?? DATA_LOOK_DAY, dayOverride: look.dayOverride, keys: look.keys, lut, neutral: look.grade.tone === 'neutral', aces: look.grade.tone === 'aces',
25
25
  exposure: look.grade.exposure, vignette: look.grade.vignette ?? null, bloomRadius: resolved.bloom.radius, sky: look.sky?.graph ?? null,
26
- light: { rim: resolved.rim, pools: resolved.pools, heightFogDensity: resolved.atmosphere.fogHeightDensity, lamps: resolved.lamps, bounce: resolved.bounce, environment: resolved.environment,
26
+ light: { rim: resolved.rim, pools: resolved.pools, heightFogDensity: resolved.atmosphere.fogHeightDensity, lamps: resolved.lamps, lampsLit: resolved.lampsLit, bounce: resolved.bounce, environment: resolved.environment,
27
27
  shadow: resolved.shadow, motes: resolved.motes } });
28
28
  }
@@ -12,6 +12,7 @@ import { ClientAssets } from './clientAssets';
12
12
  import { buildYield, pacedResolve, workSlice, type WorkSlice } from '@wildshard/engine/core/workSlice';
13
13
  import { pageScope } from '@wildshard/engine/app/resources';
14
14
  import { waitFor } from '@wildshard/engine/boot/waits';
15
+ import { bootTask } from '@wildshard/engine/boot/timing';
15
16
  import { currentOwner } from '@wildshard/engine/app/ownership';
16
17
  import { shardProductData } from '../../../shared/game/shardfile/productData';
17
18
  import { absentShardProduct, type ShardProduct } from '../../../shared/game/shardfile/shardProduct';
@@ -374,12 +375,15 @@ export async function runtimeLookMaterials(ctx: Pick<ShardContext, 'scope' | 'ga
374
375
  }));
375
376
  shard = { ...shard, look: { ...look, families: [], materials }, terrain: null, props: null };
376
377
  }
377
- const assets = new Map(product.assets.retained);
378
- const files = Object.values(shard.look.materials).flatMap(entry => entry.family === 'graph' && 'file' in entry ? [entry.file] : []);
379
- for (const ref of files) assets.set(ref, await product.assets.read(ref));
380
- for (const ref of new Set([...materialTextureRefs(shard.look.materials), ...keptGraphFileTextureRefs(shard.look.materials, hash => assets.get(hash))])) assets.set(ref, await product.assets.read(ref));
378
+ const assets = await bootTask(`look:material-inputs ${source.identity.slug}`, async () => {
379
+ const files = new Map(product.assets.retained);
380
+ const graphFiles = Object.values(shard.look.materials).flatMap(entry => entry.family === 'graph' && 'file' in entry ? [entry.file] : []);
381
+ for (const ref of graphFiles) files.set(ref, await product.assets.read(ref));
382
+ for (const ref of new Set([...materialTextureRefs(shard.look.materials), ...keptGraphFileTextureRefs(shard.look.materials, hash => files.get(hash))])) files.set(ref, await product.assets.read(ref));
383
+ return files;
384
+ });
381
385
  if (ctx.scope.disposed) throw new Error('Runtime look scope unloaded while reading materials');
382
- return clientMaterials(shard, assets, renderer, ctx.scope, { trustedGraphs: true, ...(graphs === undefined ? {} : { graphs }), ...(units === undefined ? {} : { units }) });
386
+ return bootTask(`look:material-compile ${source.identity.slug}`, () => clientMaterials(shard, assets, renderer, ctx.scope, { trustedGraphs: true, ...(graphs === undefined ? {} : { graphs }), ...(units === undefined ? {} : { units }) }));
383
387
  }
384
388
 
385
389
  /** Prepare the requested original graph materials for resident effects and boss storms. */
@@ -111,8 +111,11 @@ export class WirePage {
111
111
  }
112
112
  /** The kind a row spawns as here: its declared species' page kind, else the wire's `kind` (a native body, an older server). */
113
113
  rowKind(species: unknown, kind: string): string { return typeof species === 'string' && species !== '' ? this.speciesKinds.get(species) ?? kind : kind; }
114
- /** Count one thing drawn. */
115
- drew(what: string): void { this.drawn[what] = (this.drawn[what] ?? 0) + 1; }
114
+ /** Count a thing drawn, or `times` of them (a frame that draws every word heard since the last). */
115
+ drew(what: string, times = 1): void { this.drawn[what] = (this.drawn[what] ?? 0) + times; }
116
+ /** Words for a view this page hasn't built (a room nobody entered), by name: heard, and rightly not drawn (EG-15). */
117
+ readonly offstage: Record<string, number> = {};
118
+ unbuilt(what: string): void { this.offstage[what] = (this.offstage[what] ?? 0) + 1; }
116
119
 
117
120
  /** One of this player's lines as the server last said it: 0 for none. */
118
121
  line(name: string): number { return this.client?.owned.get(name) ?? 0; }
@@ -16,6 +16,8 @@ import { prepareLentLooks, setLentParam, setLentTexture } from './lentLooks';
16
16
  import { applyTextureSampler } from './clientMaterials';
17
17
  import type { SceneHandles } from './sceneHandles';
18
18
  import type { ShardProduct } from '../../../shared/game/shardfile/shardProduct';
19
+ import { waitFor } from '@wildshard/engine/boot/waits';
20
+ import { bootTask } from '@wildshard/engine/boot/timing';
19
21
 
20
22
  /** Client-only: load each declared texture under `owner`, lend it to its compiled looks (they are lent first) and
21
23
  * publish a product texture that names a handle, and a volume with its numbers for the world's variant (`cube`). */
@@ -55,7 +57,8 @@ export async function lendWorldSceneTextures(rows: readonly WorldSceneLentTextur
55
57
  /** A baked volume: its deflated RGBA8 voxels as a linear 3D texture (GPU-only once uploaded), lent with its box to its looks. */
56
58
  async function lendVolume(row: Extract<WorldSceneLentTexture, { kind: 'volume' }>, volume: Extract<WorldSceneLentTexture, { kind: 'volume' }>['files']['cell']['phone'],
57
59
  owner: Scope, product: Pick<ShardProduct, 'url'>, handles: SceneHandles): Promise<void> {
58
- const bytes = await fetchDeflatedBytes(product.url(volume.file)), [x, y, z] = volume.size;
60
+ const url = product.url(volume.file);
61
+ const bytes = await bootTask(`texture:volume-inflate ${volume.file}`, () => waitFor('Preparing volume texture', fetchDeflatedBytes(url), 'work', url)), [x, y, z] = volume.size;
59
62
  if (owner.disposed) throw new Error('World scene textures unloaded while loading');
60
63
  if (bytes.length !== x * y * z * 4) throw new Error(`Lent volume ${row.label} size differs`);
61
64
  const texture = owner.own(new Data3DTexture(bytes, x, y, z));
@@ -70,8 +73,8 @@ async function lendVolume(row: Extract<WorldSceneLentTexture, { kind: 'volume' }
70
73
  }
71
74
 
72
75
  /** A product's raw r8 texels as a data texture (its wrap and magnification; trilinear with mipmaps, else linear). */
73
- async function loadRaster(row: Extract<WorldSceneLentTexture, { kind: 'raster' }>, product: Pick<ShardProduct, 'file'>): Promise<Texture> {
74
- const bytes = Uint8Array.from(await product.file(row.file)), [width, height] = row.size;
76
+ async function loadRaster(row: Extract<WorldSceneLentTexture, { kind: 'raster' }>, product: Pick<ShardProduct, 'file' | 'url'>): Promise<Texture> {
77
+ const bytes = Uint8Array.from(await bootTask(`texture:raster-read ${row.file}`, () => waitFor('Reading texture', product.file(row.file), 'file', product.url(row.file)))), [width, height] = row.size;
75
78
  if (bytes.length !== width * height) throw new Error(`Lent raster ${row.label} size differs`);
76
79
  const texture = new DataTexture(bytes, width, height, RedFormat, UnsignedByteType);
77
80
  texture.wrapS = texture.wrapT = row.wrap === 'repeat' ? RepeatWrapping : ClampToEdgeWrapping;
@@ -81,10 +84,11 @@ async function loadRaster(row: Extract<WorldSceneLentTexture, { kind: 'raster' }
81
84
  }
82
85
 
83
86
  /** A product's own KTX2 blob for the tier (its encoded orientation, flipY false), sampled by its row; GPU-only once uploaded. */
84
- async function loadProduct(row: Extract<WorldSceneLentTexture, { kind: 'product' }>, product: Pick<ShardProduct, 'file'>, loader: KTX2Loader | null): Promise<Texture> {
87
+ async function loadProduct(row: Extract<WorldSceneLentTexture, { kind: 'product' }>, product: Pick<ShardProduct, 'file' | 'url'>, loader: KTX2Loader | null): Promise<Texture> {
85
88
  if (loader === null) throw new Error('Product textures need a KTX2 reader');
86
- const bytes = Uint8Array.from(await product.file(row.file[TIER]));
87
- const texture = await new Promise<Texture>((resolve, reject) => { loader.parse(bytes.buffer, resolve, reject); });
89
+ const file = row.file[TIER], url = product.url(file);
90
+ const bytes = Uint8Array.from(await bootTask(`texture:read ${file}`, () => waitFor('Reading texture', product.file(file), 'file', url)));
91
+ const texture = await bootTask(`texture:decode ${file}`, () => waitFor('Preparing texture', new Promise<Texture>((resolve, reject) => { loader.parse(bytes.buffer, resolve, reject); }), 'worker', url));
88
92
  texture.flipY = false; texture.name = row.label;
89
93
  if (row.colour !== undefined) texture.colorSpace = row.colour === 'srgb' ? SRGBColorSpace : LinearSRGBColorSpace;
90
94
  applyTextureSampler(texture, row.sampler);
@@ -95,8 +99,9 @@ async function loadProduct(row: Extract<WorldSceneLentTexture, { kind: 'product'
95
99
 
96
100
  async function blob(url: string): Promise<Blob> {
97
101
  let type = '';
98
- const bytes = await readContent(phoneUrl(url), 25_000_000, {fetch: (address, init) => fetch(address, init),
99
- response: response => {type = response.headers.get('content-type') ?? '';}});
102
+ const path = phoneUrl(url);
103
+ const bytes = await bootTask(`texture:layer-read ${path}`, () => waitFor('Reading texture layer', readContent(path, 25_000_000, {fetch: (address, init) => fetch(address, init),
104
+ response: response => {type = response.headers.get('content-type') ?? '';}}), 'file', path));
100
105
  return new Blob([bytes], {type});
101
106
  }
102
107
 
@@ -116,7 +121,8 @@ async function loadLayers(row: Extract<WorldSceneLentTexture, { kind: 'layers' }
116
121
  const files = await Promise.all(row.layers.map(layer => Promise.all([blob(`${row.base}/${layer.name}.jpg`), layer.alpha ? blob(`${row.base}/${layer.name}-a.jpg`) : null])));
117
122
  for (const [i, [rgb, alpha]] of files.entries()) {
118
123
  if (slice.due()) await slice.yield();
119
- const texels = await decodeLayerTexels(rgb, alpha, size);
124
+ const path = `${row.base}/${row.layers[i]?.name ?? i}`;
125
+ const texels = await bootTask(`texture:layer-decode ${path}`, () => waitFor('Preparing texture layer', decodeLayerTexels(rgb, alpha, size), 'worker', path));
120
126
  if (texels !== null) { data.set(texels, i * size * size * 4); continue; }
121
127
  const colour = await createImageBitmap(rgb), cover = alpha === null ? null : await createImageBitmap(alpha), at = i * size * size * 4;
122
128
  try {
@@ -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; objects++; bytes += row.bytes;
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) and a horizon strip are S4's
256
- * 1024 rows, kept on purpose; every other row is 512 on a phone. */
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\//u.test(source) ? undefined : PHONE_TIER_MAX;
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(leadPlayer(host).id);
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,6 +17,8 @@ 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;
22
23
  load: (cell: GridCell, saved: SimSnapshot | undefined) => Promise<GridResident>;
23
24
  save?: (instance: string, snapshot: SimSnapshot) => boolean;
@@ -83,7 +84,7 @@ export function carryMotion(from: PlayerSim, to: PlayerSim): void {
83
84
 
84
85
  /**
85
86
  * 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 player this session was built around, the lead of every host:
87
+ * Each player crosses on their own (P1-E3.9). `owner` is the explicit seat this session was built around:
87
88
  * its systems bind to that seat, so when it leaves others behind the seat stays, parked, and a lone player never parks.
88
89
  */
89
90
  export class GridSimulation {
@@ -105,8 +106,8 @@ export class GridSimulation {
105
106
  constructor(assembly: GridAssembly, ports: GridSimulationPorts) {
106
107
  this.assembly = assembly; this.ports = ports;
107
108
  this.limit = ports.maxResidents ?? 4;
108
- const owner = leadPlayer(ports.highway.host);
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');
109
+ const owner = ports.highway.host.players.get(ports.owner ?? 'actor.player');
110
+ 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
111
  this.owner = owner.id; this.sites.set(owner.id, null);
111
112
  if (ports.reserve !== undefined && ports.residentBytes === undefined) throw new Error('Sim reservation needs admitted resident bytes');
112
113
  if (ports.allocator !== undefined && (ports.residentBytes === undefined || ports.reserve !== undefined)) throw new Error('Use one sim reservation owner with admitted bytes');
@@ -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(player) || action === 3) return;
285
- if (player === undefined) this.riders.delete(id); else this.riders.set(id, player);
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 lead when absent) is on a carry mover: each carries the one who called it. */
296
- carrying(player?: string): boolean { return this.data.some(row => row.carry !== undefined && this.riders.get(row.id) === player && this.riding(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 = named === undefined ? leadPlayer(host) : host.players.get(named);
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
- const lead = leadPlayer(host);
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 === lead.id ? undefined : 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 === lead) return this.carrying();
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
- return rider === undefined ? books.lead.flags : sim.players.has(rider) ? books.of(rider).flags : undefined;
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;