@wildshard/engine 0.1.21 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lint/engine-sides.json +3 -0
- package/lint/shardfile-boundaries.mjs +4 -2
- package/lint/wildshard-plugin.js +1 -1
- package/package.json +2 -1
- package/scripts/audio-download-proof.mjs +1 -1
- package/scripts/check-spelled-paths.mjs +6 -3
- package/scripts/committed-fast-checks.mjs +2 -2
- package/scripts/failmode-cases.mjs +1 -1
- package/scripts/failmode-proof.mjs +35 -11
- package/scripts/grid-crossing-walk-proof.mjs +3 -3
- package/scripts/hover-speed-probe.mjs +2 -2
- package/scripts/mmo-bots.mjs +7 -3
- package/scripts/net-lag-proof.mjs +1 -1
- package/scripts/online-rig.mjs +7 -7
- package/scripts/parity/boot-smoke.mjs +1 -1
- package/scripts/release-cook.mjs +6 -2
- package/scripts/test-products.json +0 -21
- package/scripts/vps/cook-follow.d.mts +6 -0
- package/scripts/vps/cook-follow.mjs +45 -0
- package/scripts/vps/harden-apply.sh +10 -1
- package/scripts/vps/rebuild.sh +104 -36
- package/scripts/vps/wildshard-config +0 -2
- package/src/client/app/entry.ts +2 -3
- package/src/client/engine/boot/contentRead.ts +24 -4
- package/src/client/engine/boot/downloadGiveUp.ts +34 -0
- package/src/client/engine/combat/EquipmentService.ts +2 -0
- package/src/client/engine/core/Game.ts +6 -2
- package/src/client/engine/ui/downloadFailed.ts +54 -0
- package/src/client/game/boot/spawnDownload.ts +12 -1
- package/src/client/game/grid/copyPrompts.ts +3 -4
- package/src/client/game/grid/dataCellKit.ts +91 -0
- package/src/client/game/grid/enteredEquipment.ts +11 -2
- package/src/client/game/grid/live.ts +9 -299
- package/src/client/game/grid/liveSession.ts +31 -8
- package/src/client/game/grid/neighbourLife.ts +50 -32
- package/src/client/game/grid/reveal.ts +7 -2
- package/src/client/game/grid/session.ts +4 -70
- package/src/client/game/plugin/weaponFamily.ts +6 -0
- package/src/client/game/shardfile/clientWorker.ts +13 -3
- package/src/client/host/online/shell.ts +37 -13
- package/src/server/game/grid/room.ts +2 -38
- package/src/server/game/shardfile/declaredKitItems.ts +8 -2
- package/src/server/host/dedicated/cellHost.ts +2 -2
- package/src/server/host/dedicated/cellProtocol.ts +1 -1
- package/src/server/host/dedicated/cellWorker.ts +1 -1
- package/src/server/host/dedicated/dedicatedRoom.ts +8 -3
- package/src/server/host/dedicated/gridCells.ts +5 -3
- package/src/server/host/dedicated/main.ts +6 -4
- package/src/server/host/dedicated/workerTable.ts +0 -10
- package/src/server/host/dedicated/world.ts +39 -5
- package/src/server/host/standalone/cellWorld.ts +1 -1
- package/src/shared/engine/saves/shape.ts +17 -2
- package/src/shared/engine/strings.ts +10 -0
- package/src/shared/game/grid/placementRows.ts +4 -3
- package/src/client/game/grid/cellLoading.ts +0 -110
- package/src/client/game/grid/cellScreens.ts +0 -48
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A grid data cell's declared items, in hand while the feet stand in it (TEMPLATE-E2E TC-E1b). Standalone, a shardfile shard's
|
|
3
|
+
* client builds its `items` rows into the page's equipment (`client.ts` `buildEquipment`); in the grid a data cell (no runtime,
|
|
4
|
+
* no declared client page: the templates) has no client of its own, so it held bare hands (G68) and Brasscap's lever never came
|
|
5
|
+
* to hand. Entering the cell now builds its rows (kit families, item models) into one equipment service bound under the page's
|
|
6
|
+
* controls (`EnteredEquipment.bind`); leaving disposes it and the road's bare hands come back.
|
|
7
|
+
*
|
|
8
|
+
* On the wire the server owns every round: the kit takes the road's weapon wire, so a press, a reload and the held row go to the
|
|
9
|
+
* server's seat for this cell (its slots are the cell's `enteredItems`), and a declared lever follows the server's owned lines
|
|
10
|
+
* (rounds, reserve, taken) as the standalone client's does. An item request (a rack's take) is the scene the server runs it by.
|
|
11
|
+
*/
|
|
12
|
+
import { Object3D, Vector3 } from 'three';
|
|
13
|
+
import type { Scope } from '@wildshard/engine/app/scope';
|
|
14
|
+
import type { Actor, CombatTarget } from '@wildshard/engine/combat/pipeline';
|
|
15
|
+
import type { ItemTarget } from '@wildshard/engine/combat/items';
|
|
16
|
+
import { EquipmentService } from '@wildshard/engine/combat/EquipmentService';
|
|
17
|
+
import type { Weapon } from '@wildshard/engine/combat/Weapon';
|
|
18
|
+
import { playerModes } from '@wildshard/engine/player/modes';
|
|
19
|
+
import type { Shardfile } from '@wildshard/format/shardSchema';
|
|
20
|
+
import { installDeclaredItems, leverLines } from '../../../shared/game/shardfile/items';
|
|
21
|
+
import { declaredItemIcon, declaredKitItemFamilies, declaredLever } from '../plugin/weaponFamily';
|
|
22
|
+
import { itemScene } from '../shardfile/clientItems';
|
|
23
|
+
import { loadItemModels } from '../shardfile/itemModels';
|
|
24
|
+
import { wirePage } from '../shardfile/wirePage';
|
|
25
|
+
import type { RegionalRuntimePage } from './regionalRuntime';
|
|
26
|
+
|
|
27
|
+
function isItemModel(value: unknown): value is Object3D { return value instanceof Object3D; }
|
|
28
|
+
|
|
29
|
+
/** Whether a data cell has anything to hold: a declared weapon (a kit is built around one). */
|
|
30
|
+
export function holdsItems(source: Pick<Shardfile, 'items'>): boolean {
|
|
31
|
+
return source.items.rows.some(row => row.kind === 'weapon');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Build the cell's declared kit under `entry` and bind it as the page's held equipment until `entry` is disposed. */
|
|
35
|
+
/** `here`: whether the wire's frames are this cell's (a crossing's frames are another's, and their lines are not this kit's). */
|
|
36
|
+
export async function enterDataCellKit(source: Shardfile, assets: ReadonlyMap<string, Uint8Array>, page: RegionalRuntimePage, entry: Scope, here: () => boolean = () => true): Promise<EquipmentService | null> {
|
|
37
|
+
const controls = page.equipment;
|
|
38
|
+
if (controls === undefined || !holdsItems(source)) return null;
|
|
39
|
+
const models = await loadItemModels(source.items, assets, entry);
|
|
40
|
+
if (entry.disposed || entry.disposing) return null;
|
|
41
|
+
const { app } = page.context, camera = page.world.game.camera, player = page.world.player;
|
|
42
|
+
const health = (): NonNullable<typeof app.player> => { const actor = app.player; if (actor === null) throw new Error('Player health has not entered play'); return actor; };
|
|
43
|
+
const actor: Actor = { id: 'actor.player', get tags() { return health().tags; }, get state() { return health().state; }, get attributes() { return health().attributes; }, get alive() { return health().alive; }, applyDamage: (request) => health().applyDamage(request) };
|
|
44
|
+
const aimTarget = (target: CombatTarget): ItemTarget => {
|
|
45
|
+
const { dims, scale = 1 } = target.target;
|
|
46
|
+
return { ...target, aimPoint: target.position.clone().add(new Vector3(0, dims === undefined ? 0.9 : dims.bodyY * scale, 0)) };
|
|
47
|
+
};
|
|
48
|
+
const items = installDeclaredItems(source.items, { scope: entry, actorId: actor.id, input: app.input, bindings: app.input.bindings,
|
|
49
|
+
observation: { get mode() { return playerModes(player).current(); }, get item() { return app.equipment?.current.row.id ?? null; }, get flags() { return wirePage.client === null ? [] : [...wirePage.client.flags()]; } },
|
|
50
|
+
families: declaredKitItemFamilies(), models, icon: declaredItemIcon,
|
|
51
|
+
aim: () => ({ origin: camera.getWorldPosition(new Vector3()), direction: camera.getWorldDirection(new Vector3()) }),
|
|
52
|
+
// SR11 (C9): on the wire an item request is the scene the server takes it by
|
|
53
|
+
relay: (item, action) => { const scene = itemScene(source, item, action); if (scene === undefined || wirePage.client === null) return false; wirePage.send(scene); return true; },
|
|
54
|
+
runtime: row => ({ actor, combat: app.combat, active: () => app.state === 'play',
|
|
55
|
+
targets: () => app.combat.targets().map(aimTarget),
|
|
56
|
+
effect: (target, effect, from) => { const service = app.effects; if (service === null) throw new Error('Missing normal effect host'); service.apply(target, effect, from); },
|
|
57
|
+
hook: row.hook === null ? null : (command) => command.action, // the server runs an item's script on the wire
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
const weapons: readonly Weapon[] = [items.primary, items.secondary, ...items.extras].filter((weapon): weapon is Weapon => weapon !== null);
|
|
61
|
+
const first = weapons[0];
|
|
62
|
+
if (first === undefined) return null;
|
|
63
|
+
const kit = new EquipmentService(first, { scope: entry, events: app.events, input: { bind: (action, run, _scope, allowed) => { app.input.bind(action, run, entry, allowed ?? (() => kit.enabled)); } }, order: [...items.order] });
|
|
64
|
+
for (const weapon of weapons) if (weapon !== first) kit.add(weapon, { locked: true });
|
|
65
|
+
items.install(kit);
|
|
66
|
+
// the held models hang off the page's viewmodel, as a standalone page's do (client.ts)
|
|
67
|
+
const host = app.equipmentHost;
|
|
68
|
+
if (host !== null) for (const item of [...weapons, ...items.tools]) {
|
|
69
|
+
const model: unknown = Reflect.get(item, 'model');
|
|
70
|
+
if (isItemModel(model)) { host.viewmodel.add(model); entry.onDispose(() => { model.removeFromParent(); }); }
|
|
71
|
+
}
|
|
72
|
+
// the road's switches, read before the kit takes the controls: the page's reveal, menu and safe zone set them on the controls,
|
|
73
|
+
// which set both while a kit is bound, so the kit starts where the road stands; it takes the road's wire with it
|
|
74
|
+
const road = controls.service, enabled = road.enabled, visible = road.visible;
|
|
75
|
+
controls.bind(kit, entry, { wire: true });
|
|
76
|
+
kit.enabled = enabled; kit.visible = visible; kit.stowed = false;
|
|
77
|
+
// TE-ENG2: a lever follows the server's owned lines; taken, it unlocks and comes to hand
|
|
78
|
+
const levers = weapons.flatMap(weapon => { const lever = declaredLever(weapon); return lever === null ? [] : [lever]; });
|
|
79
|
+
app.addContentSystem({ id: 'grid.data-cell-kit', phase: 'update', run: (dt, t) => {
|
|
80
|
+
for (const lever of levers) {
|
|
81
|
+
if (wirePage.client !== null && here()) {
|
|
82
|
+
const lines = leverLines(lever.row.id);
|
|
83
|
+
lever.mirror(wirePage.line(lines.rounds), wirePage.line(lines.reserve), wirePage.line(lines.reloading) > 0, wirePage.line(lines.taken) > 0);
|
|
84
|
+
}
|
|
85
|
+
if (lever.taken && !kit.has(lever.id)) { kit.unlock(lever.id); kit.select(lever.id); }
|
|
86
|
+
}
|
|
87
|
+
kit.update(dt, t);
|
|
88
|
+
} }, entry);
|
|
89
|
+
entry.onDispose(() => { kit.enabled = false; kit.visible = false; kit.adsHeld = false; kit.altHeld = false; });
|
|
90
|
+
return kit;
|
|
91
|
+
}
|
|
@@ -7,6 +7,7 @@ const callbacks = new Set<PropertyKey>(['onFire', 'onHit', 'onImpact', 'onReload
|
|
|
7
7
|
export class EnteredEquipment {
|
|
8
8
|
readonly service: EquipmentService;
|
|
9
9
|
private active: EquipmentService;
|
|
10
|
+
private wired = false;
|
|
10
11
|
constructor(private readonly road: EquipmentService) {
|
|
11
12
|
this.active = road;
|
|
12
13
|
this.service = new Proxy(road, {
|
|
@@ -26,6 +27,8 @@ export class EnteredEquipment {
|
|
|
26
27
|
owner.unlock(id); return undefined;
|
|
27
28
|
};
|
|
28
29
|
if (key === 'setEnabled') return (on: boolean) => { this.service.enabled = on; };
|
|
30
|
+
// TC-E1b: a wired kit (a data cell's) takes the road's wire with it; the road keeps it for when the kit goes
|
|
31
|
+
if (key === 'bindWire') return (wire: Parameters<EquipmentService['bindWire']>[0]) => { road.bindWire(wire); if (this.wired && this.active !== road) this.active.bindWire(wire); };
|
|
29
32
|
const value: unknown = Reflect.get(active, key, active);
|
|
30
33
|
const bound: unknown = typeof value === 'function' ? value.bind(active) : value;
|
|
31
34
|
return bound;
|
|
@@ -39,7 +42,9 @@ export class EnteredEquipment {
|
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
/** Install only after trusted play and continuation succeed; leaving restores every prior callback descriptor. */
|
|
42
|
-
|
|
45
|
+
/** `wire`: the kit plays on the server's wire as the road does (a data cell's declared kit, TC-E1b); leaving gives the server
|
|
46
|
+
* the road's held row again. A regional runtime's kit keeps its own contacts. */
|
|
47
|
+
bind(equipment: EquipmentService, entry: Scope, options: { readonly wire?: boolean } = {}): void {
|
|
43
48
|
if (entry.disposed || this.active !== this.road || equipment === this.road) throw new Error('Equipment entry is not available');
|
|
44
49
|
const prior = [...callbacks].map(key => [key, Object.getOwnPropertyDescriptor(equipment, key)] as const);
|
|
45
50
|
if (prior.some(([, descriptor]) => descriptor?.configurable === false)) throw new Error('Equipment callbacks are not configurable');
|
|
@@ -54,8 +59,12 @@ export class EnteredEquipment {
|
|
|
54
59
|
} });
|
|
55
60
|
}
|
|
56
61
|
this.active = equipment;
|
|
62
|
+
const wire = options.wire === true ? this.road.boundWire : null;
|
|
63
|
+
this.wired = options.wire === true;
|
|
64
|
+
if (wire !== null) equipment.bindWire(wire);
|
|
57
65
|
entry.onDispose(() => {
|
|
58
|
-
this.active = this.road;
|
|
66
|
+
this.active = this.road; this.wired = false;
|
|
67
|
+
if (options.wire === true) { equipment.bindWire(null); const now = this.road.boundWire; if (now !== null) this.road.bindWire(now); }
|
|
59
68
|
for (const [key, descriptor] of prior) {
|
|
60
69
|
if (descriptor === undefined) Reflect.deleteProperty(equipment, key); else Object.defineProperty(equipment, key, descriptor);
|
|
61
70
|
}
|
|
@@ -3,7 +3,7 @@ import { prepareFrameMotors, type FrameMember } from '@wildshard/engine/physics/
|
|
|
3
3
|
import type { Physics } from '@wildshard/engine/physics/Physics';
|
|
4
4
|
import { TraversalReadiness, readinessModel, type ReadinessBundle, type ReadinessLink, type ReadinessTicket } from '@wildshard/engine/sim/readiness';
|
|
5
5
|
import type { ReadinessWalls } from '@wildshard/engine/physics/readinessWalls';
|
|
6
|
-
import { CHUNK_HALF
|
|
6
|
+
import { CHUNK_HALF } from '@wildshard/engine/core/config';
|
|
7
7
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
8
8
|
import { GhostWorlds, type GhostRegion } from '../../../shared/game/grid/ghosts';
|
|
9
9
|
import { WORK_SLICE_MS, workSlice } from '@wildshard/engine/core/workSlice';
|
|
@@ -15,7 +15,6 @@ import type { HomeResidencyClaim } from './pageResidency';
|
|
|
15
15
|
import { ApproachInputsDeferredError } from './productInputs';
|
|
16
16
|
import { PRODUCT_DEFERRED } from './productLeases';
|
|
17
17
|
import { clientPreparationBatch } from '../shardfile/preparationTiming';
|
|
18
|
-
import { tileOf, type CellTile } from '../../../shared/game/shardfile/tileOrder';
|
|
19
18
|
import type { RegionShell } from './regionShell';
|
|
20
19
|
|
|
21
20
|
/** A region on a page: the world its traveller's motor walks in. The server runs it and keeps its save. */
|
|
@@ -59,19 +58,11 @@ export interface LiveGridPorts {
|
|
|
59
58
|
admit: (cell: GridCell, required?: boolean) => Promise<LiveGridAdmission>;
|
|
60
59
|
/** Actual world construction or a verified render approach outranks product-only prefetch until its finite preparation drains. */
|
|
61
60
|
prioritize?: (cell: GridCell) => () => void;
|
|
62
|
-
/** Render-only approach: the signal owns the pin, including after preparation completes. */
|
|
63
|
-
prepareNeighbour?: (cell: GridCell, start: { readonly x: number; readonly z: number }, signal: AbortSignal) => Promise<void>;
|
|
64
|
-
/** Verified, charged inputs for one named source-exit approach, held until
|
|
65
|
-
* abort. No regional world/readiness may publish from this IO-only port. */
|
|
66
|
-
prepareTransport?: (cell: GridCell, signal: AbortSignal) => Promise<void>;
|
|
67
61
|
/** Browser presentation boundary between admission batches; absent leaves the standalone Node scheduler unchanged. */
|
|
68
62
|
pause?: () => Promise<void>;
|
|
69
63
|
/** Metadata-only prefetch eligibility. Unsupported far proxies do not consume cold request slots; explicit transfers
|
|
70
64
|
* still run normal admission and readiness. Absent: every cell is a candidate, as in standalone Node drivers. */
|
|
71
65
|
prefetchable?: (cell: GridCell) => boolean;
|
|
72
|
-
/** GC5 / GC36 (J322: no hold at the line): on the road, build the world of the cell the traveller heads into, ahead of
|
|
73
|
-
* its line, so its entry finds it resident. Absent (standalone drivers): only actual entry builds a world (T7). */
|
|
74
|
-
buildAhead?: boolean;
|
|
75
66
|
/** Product-only prefetch waits while this is false (T10: the page's spawn settle); required entry never waits. Absent: always. */
|
|
76
67
|
backgroundReady?: () => boolean;
|
|
77
68
|
bindFrame: (frame: LiveGridFrame) => void;
|
|
@@ -115,50 +106,6 @@ interface RetiringRegion { readonly instance: string; readonly resident: Residen
|
|
|
115
106
|
readonly finished: Promise<void>; readonly settle: () => void }
|
|
116
107
|
interface Resident { region: LiveGridRegion; lease: ResidencyLease; reservations: number; evicting: boolean; retainable: boolean; evictionBound?: boolean; disposalFailed?: boolean }
|
|
117
108
|
|
|
118
|
-
// Contact corrections at a closed readiness wall are not a U-turn. Accumulate real horizontal travel
|
|
119
|
-
// before selecting another approach, so sub-centimetre capsule recoil cannot evict the world just prepared.
|
|
120
|
-
const APPROACH_TRAVEL_METRES = 0.1;
|
|
121
|
-
// GC5: the page pre-warms a neighbour's world from inside the source, at the distance the traveller covers at its speed in that
|
|
122
|
-
// world's last measured build time (2 s at least; before it is measured, the slowest build so far or 14 s, capped at 16 s), times a margin. Kept while the traveller stays within
|
|
123
|
-
// WARM_KEEP_METRES of it; the lead is capped below that, so a pre-warm never starts where it would be dropped.
|
|
124
|
-
const DEMAND_METRES = 80, HELD_RETRY_MS = 5000, HEADING_HOLD_MS = 600, FIXED_HZ = 60, WARM_DEFAULT_SECONDS = 14, WARM_MIN_SECONDS = 2, WARM_MAX_SECONDS = 16, WARM_MARGIN = 1.25, WARM_LEAD_METRES = 8, WARM_LEAD_CAP_METRES = 200, WARM_KEEP_METRES = 240;
|
|
125
|
-
const entryAxes = [['x', 'z'], ['z', 'x']] as const;
|
|
126
|
-
// Distance can decrease while passing parallel to a cell. Only a ray into its first boundary's midpoint mouth
|
|
127
|
-
// predicts entry; product downloads remain radial, but an unrelated native world must not block the real turn-in.
|
|
128
|
-
function headsToEntry(cell: GridCell, feet: GridPoint, previous: GridPoint): boolean {
|
|
129
|
-
const delta = { x: feet.x - previous.x, z: feet.z - previous.z };
|
|
130
|
-
let first = Infinity, offset = Infinity;
|
|
131
|
-
for (const [axis, other] of entryAxes) for (const side of [-1, 1]) {
|
|
132
|
-
const direction = delta[axis]; if (direction === 0) continue;
|
|
133
|
-
const time = (cell.origin[axis] + side * CHUNK_HALF - feet[axis]) / direction;
|
|
134
|
-
if (time < 0 || time >= first) continue;
|
|
135
|
-
const lateral = Math.abs(feet[other] + time * delta[other] - cell.origin[other]);
|
|
136
|
-
if (lateral <= CHUNK_HALF) { first = time; offset = lateral; }
|
|
137
|
-
}
|
|
138
|
-
return offset <= ENTRY_WIDTH / 2;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// A boulevard predicts its next midpoint turn, before the player aims at the perpendicular mouth.
|
|
142
|
-
// A small lateral turn names its side before the ray reaches the narrow mouth.
|
|
143
|
-
// Straight travel retains both sides, so an undecided junction remains ambiguous.
|
|
144
|
-
function boulevardApproachDistance(cell: GridCell, feet: GridPoint, previous: GridPoint, pitch: number): number | undefined {
|
|
145
|
-
const delta = { x: feet.x - previous.x, z: feet.z - previous.z };
|
|
146
|
-
for (const [axis, other] of entryAxes) for (const side of [-1, 1]) {
|
|
147
|
-
const road = cell.origin[axis] + side * pitch / 2, lateral = cell.origin[other] - feet[other];
|
|
148
|
-
if (Math.abs(feet[axis] - road) > ENTRY_WIDTH / 2 || Math.abs(delta[axis]) > Math.abs(delta[other]) / 4
|
|
149
|
-
|| delta[other] * lateral <= 0 || delta[axis] * side > Math.abs(delta[other]) / 20) continue;
|
|
150
|
-
return Math.abs(lateral) + pitch / 2 - CHUNK_HALF;
|
|
151
|
-
}
|
|
152
|
-
return undefined;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** Real background failures stay closed until retry. Expected optional headroom
|
|
156
|
-
* deferrals remain retryable after cost changes and never report a load failure. */
|
|
157
|
-
async function background(instance: string, admission: Promise<unknown>, alive: () => boolean): Promise<void> {
|
|
158
|
-
try { await admission; }
|
|
159
|
-
catch (error) { if (alive() && !(error instanceof ApproachInputsDeferredError)) console.error(`[grid] ${instance}: admission failed; it stays closed until a retry`, error); }
|
|
160
|
-
}
|
|
161
|
-
|
|
162
109
|
/** One page traveller with frozen owned regions. Borrowed homes keep the existing standalone composition;
|
|
163
110
|
* owned homes begin on neutral page physics and transfer the sole preallocation claim to their first runtime. */
|
|
164
111
|
export class LiveGridHost {
|
|
@@ -187,25 +134,9 @@ export class LiveGridHost {
|
|
|
187
134
|
private frameGeneration = 0;
|
|
188
135
|
private readonly transitions: { from: string | null; to: string | null }[] = [];
|
|
189
136
|
private crossings = 0;
|
|
190
|
-
private warms = 0;
|
|
191
|
-
/** QA row 43: when a traveller held at a cell's wall may next retry its failed build */
|
|
192
|
-
private readonly heldRetryAt = new Map<string, number>();
|
|
193
|
-
/** the other mouth the traveller inside the source turned to, and since when (HEADING_HOLD_MS) */
|
|
194
|
-
private turnedSince: { instance: string; at: number } | null = null;
|
|
195
|
-
/** GC5: why the last pre-warm the heading asked for did not start (its product still reading, an exclusive runtime, or the budget) */
|
|
196
|
-
private warmRefusal: string | null = null;
|
|
197
137
|
/** GC6: the neighbour whose product is read as demand (the nearest edge's, or the heading's) and not yet admitted: radial
|
|
198
138
|
* reads of other cells wait while it is missing, so they don't take back the headroom its read needs. */
|
|
199
139
|
private demanded: string | null = null;
|
|
200
|
-
private previousFeet: GridPoint | undefined;
|
|
201
|
-
/** fixed steps since `previousFeet` moved, for the traveller's speed (GC5) */
|
|
202
|
-
private stepsSincePrevious = 0;
|
|
203
|
-
/** GC5: each cell's last measured world build, in seconds (product to colliders and sim ready) */
|
|
204
|
-
private readonly builtSeconds = new Map<string, number>();
|
|
205
|
-
private readonly candidateDistances = new Map<GridCell,number>();
|
|
206
|
-
private readonly approachWork:{candidates:GridCell[];boulevard:GridCell[]}[]=[];
|
|
207
|
-
/** This host already owns the assembly and its frozen cells for its whole lifetime. */
|
|
208
|
-
private targetCells: readonly GridCell[] | undefined;
|
|
209
140
|
private initialHomePending: boolean;
|
|
210
141
|
private readonly highwayLease: ResidencyLease;
|
|
211
142
|
private readonly highway: LiveGridHighway;
|
|
@@ -250,13 +181,13 @@ export class LiveGridHost {
|
|
|
250
181
|
}
|
|
251
182
|
/** Render/global coordinates are derived, never written into an authored regional host. */
|
|
252
183
|
worldFeet(): GridPoint { const p = this.ports.player.position, origin = this.origin(this.active); return { x: p.x + origin.x, y: p.y, z: p.z + origin.z }; }
|
|
253
|
-
/**
|
|
184
|
+
/** Gate selects only the home and road. Worker retains the parked 6 m enter / 10 m leave selection. */
|
|
254
185
|
target(feet: Readonly<GridPoint>): string | null {
|
|
255
186
|
if (![feet.x, feet.y, feet.z].every(Number.isFinite)) throw new RangeError('Invalid live grid feet');
|
|
256
187
|
const distance = (cell: GridCell): number => Math.max(Math.abs(feet.x - cell.origin.x), Math.abs(feet.z - cell.origin.z)) - CHUNK_HALF;
|
|
257
188
|
if (this.active !== null && distance(this.assembly.cell(this.active)) <= 10) return this.active;
|
|
258
|
-
const
|
|
259
|
-
return
|
|
189
|
+
const home = this.assembly.cell(this.ports.home.instance);
|
|
190
|
+
return distance(home) <= 6 ? home.instance : null;
|
|
260
191
|
}
|
|
261
192
|
/** Admission includes colliders, initialized sim and parsed runtime module; entered hooks are a separate gameplay fence. */
|
|
262
193
|
ready(instance: string | null): boolean {
|
|
@@ -298,7 +229,6 @@ export class LiveGridHost {
|
|
|
298
229
|
this.deferredProducts.delete(instance); this.deferredDemand.delete(instance); this.products.set(instance, admission); return admission;
|
|
299
230
|
} catch (error) {
|
|
300
231
|
this.tileMetadata.delete(instance);
|
|
301
|
-
if (this.tileApproach?.instance === instance) { this.tileApproach.controller.abort(); this.tileApproach = null; }
|
|
302
232
|
const refused = error instanceof ApproachInputsDeferredError || (error instanceof Error && error.message.includes(PRODUCT_DEFERRED));
|
|
303
233
|
// GC6 (QA 11-14 row 6): inside Driftwood the page held 3 to 5 neighbours' radial products (1199 of 1200 MB), pinned
|
|
304
234
|
// while held, so Nalati's demand read was refused the whole approach and its world was built only on the road. A
|
|
@@ -318,7 +248,7 @@ export class LiveGridHost {
|
|
|
318
248
|
private releaseSpeculative(kept: string): number {
|
|
319
249
|
const feet = this.worldFeet(), keep = (id: string): boolean => id === kept || id === this.active || id === this.ahead
|
|
320
250
|
|| this.constructing.has(id) || this.requests.has(id) || this.residents.has(id)
|
|
321
|
-
|| id === this.
|
|
251
|
+
|| id === this.transportApproach?.instance;
|
|
322
252
|
const idle = [...this.products.keys()].filter(id => !keep(id))
|
|
323
253
|
.sort((a, b) => this.distance(this.assembly.cell(b), feet) - this.distance(this.assembly.cell(a), feet));
|
|
324
254
|
for (const id of idle) {
|
|
@@ -333,9 +263,6 @@ export class LiveGridHost {
|
|
|
333
263
|
/** GC5 / GC36: the cell whose world the road is building or built ahead of its line (`buildAhead`), kept until the
|
|
334
264
|
* traveller enters a cell or heads into another's mouth. */
|
|
335
265
|
private ahead: string | null = null;
|
|
336
|
-
/** GC9: the optional read last raised to demand, so a pending radial read is raised once, not every tick */
|
|
337
|
-
private raised: Promise<LiveGridAdmission> | null = null;
|
|
338
|
-
private tileApproach: { instance: string; tile: CellTile; controller: AbortController } | null = null;
|
|
339
266
|
private transportApproach: { instance: string; controller: AbortController; work: Promise<void> } | null = null;
|
|
340
267
|
private retiredTransport: Promise<void> = Promise.resolve();
|
|
341
268
|
private stopApproachTransport(): void {
|
|
@@ -343,40 +270,6 @@ export class LiveGridHost {
|
|
|
343
270
|
this.transportApproach = null; previous.controller.abort();
|
|
344
271
|
this.retiredTransport = this.settle(previous.work);
|
|
345
272
|
}
|
|
346
|
-
private prepareApproachTransport(cell: GridCell): void {
|
|
347
|
-
const prepare = this.ports.prepareTransport;
|
|
348
|
-
if (prepare === undefined || this.transportApproach?.instance === cell.instance) return;
|
|
349
|
-
this.stopApproachTransport();
|
|
350
|
-
const controller = new AbortController(), previous = this.retiredTransport;
|
|
351
|
-
// Acquire priority synchronously, before this tick's speculative IO runs.
|
|
352
|
-
// The old key keeps its own priority until its already-started reads drain.
|
|
353
|
-
const releasePriority = this.ports.prioritize?.(cell);
|
|
354
|
-
const work = (async (): Promise<void> => {
|
|
355
|
-
try { await previous; if (!this.disposed && !controller.signal.aborted) await prepare(cell, controller.signal); }
|
|
356
|
-
finally { releasePriority?.(); }
|
|
357
|
-
})();
|
|
358
|
-
const approach = { instance: cell.instance, controller, work }; this.transportApproach = approach;
|
|
359
|
-
void background(cell.instance, work, () => !this.disposed && !controller.signal.aborted);
|
|
360
|
-
}
|
|
361
|
-
private prepareNeighbour(cell: GridCell, feet: GridPoint): void {
|
|
362
|
-
const start = { x: Math.max(-CHUNK_HALF, Math.min(CHUNK_HALF, feet.x - cell.origin.x)),
|
|
363
|
-
z: Math.max(-CHUNK_HALF, Math.min(CHUNK_HALF, feet.z - cell.origin.z)) };
|
|
364
|
-
const tile = tileOf(start.x, start.z), prior = this.tileApproach;
|
|
365
|
-
if (prior?.instance === cell.instance && prior.tile.i === tile.i && prior.tile.j === tile.j) return;
|
|
366
|
-
// A diagonal approach can reach another mouth of the same destination.
|
|
367
|
-
// Retarget only across tile boundaries; keep exactly one speculative pin.
|
|
368
|
-
prior?.controller.abort();
|
|
369
|
-
const controller = new AbortController();
|
|
370
|
-
this.tileApproach = { instance: cell.instance, tile, controller };
|
|
371
|
-
const prepare = this.ports.prepareNeighbour;
|
|
372
|
-
if (prepare === undefined) return;
|
|
373
|
-
const pending = (async (): Promise<void> => {
|
|
374
|
-
const releasePriority = this.ports.prioritize?.(cell);
|
|
375
|
-
try { await prepare(cell, start, controller.signal); }
|
|
376
|
-
finally { releasePriority?.(); }
|
|
377
|
-
})();
|
|
378
|
-
void background(cell.instance, pending, () => !this.disposed && !controller.signal.aborted);
|
|
379
|
-
}
|
|
380
273
|
private ensure(instance: string): Promise<void> {
|
|
381
274
|
if (this.disposed) return Promise.reject(new Error('Live grid is disposed'));
|
|
382
275
|
const cell = this.assembly.cell(instance);
|
|
@@ -403,7 +296,6 @@ export class LiveGridHost {
|
|
|
403
296
|
await (timing === undefined ? previous : timing.run('queue', () => previous));
|
|
404
297
|
await this.retiredTransport;
|
|
405
298
|
this.assertAlive();
|
|
406
|
-
const buildStart = diagnosticNow();
|
|
407
299
|
const admitted = timing === undefined ? await this.prefetchProduct(instance, true) : await timing.run('metadata', () => this.prefetchProduct(instance, true));
|
|
408
300
|
admission = admitted;
|
|
409
301
|
this.assertAlive();
|
|
@@ -438,7 +330,6 @@ export class LiveGridHost {
|
|
|
438
330
|
this.assertAlive();
|
|
439
331
|
this.residents.set(instance, { region, lease, reservations: 0, evicting: false, retainable: admitted.isolatedPreparation === true });
|
|
440
332
|
this.readiness.complete(ticket, 'colliders'); this.readiness.complete(ticket, 'sim');
|
|
441
|
-
this.builtSeconds.set(instance, (diagnosticNow() - buildStart) / 1000);
|
|
442
333
|
lease.update({ needed: false, distance: this.distance(cell) });
|
|
443
334
|
} catch (error) {
|
|
444
335
|
try { region?.dispose(); }
|
|
@@ -510,13 +401,6 @@ export class LiveGridHost {
|
|
|
510
401
|
resident.lease.update({ needed: false, distance: this.distance(this.assembly.cell(instance)) });
|
|
511
402
|
return this.lastCell === last;
|
|
512
403
|
}
|
|
513
|
-
/** GC5: how far from a neighbour's square its world starts building at `speed` (m/s): its measured build time, or the
|
|
514
|
-
* slowest measured so far or the default, at least WARM_MIN_SECONDS, with a margin; capped below the keep distance. */
|
|
515
|
-
private warmLead(instance: string, speed: number): number {
|
|
516
|
-
const measured = this.builtSeconds.get(instance) ?? Math.max(WARM_DEFAULT_SECONDS, ...this.builtSeconds.values());
|
|
517
|
-
const seconds = Math.min(WARM_MAX_SECONDS, Math.max(WARM_MIN_SECONDS, measured));
|
|
518
|
-
return Math.min(WARM_LEAD_CAP_METRES, WARM_LEAD_METRES + speed * seconds * WARM_MARGIN);
|
|
519
|
-
}
|
|
520
404
|
private distance(cell: GridCell, p = this.worldFeet()): number { return Math.hypot(Math.max(0, Math.abs(p.x - cell.origin.x) - CHUNK_HALF), Math.max(0, Math.abs(p.z - cell.origin.z) - CHUNK_HALF)); }
|
|
521
405
|
/** Only the active/reserved world and one bounded departed world can remain.
|
|
522
406
|
* A different actual entry retires the departure before any new allocation. */
|
|
@@ -550,183 +434,11 @@ export class LiveGridHost {
|
|
|
550
434
|
/** Before the existing page physics/player step: radial requests are U-turn safe, and current-world walls synchronize first. */
|
|
551
435
|
beforeFixed(): void {
|
|
552
436
|
if (this.disposed) return;
|
|
553
|
-
|
|
554
|
-
try{this.beforeFixedWithWork(work);}
|
|
555
|
-
finally{work.candidates.length=0;work.boulevard.length=0;if(!this.disposed)this.approachWork.push(work);}
|
|
437
|
+
this.beforeFixedWithWork();
|
|
556
438
|
}
|
|
557
|
-
private beforeFixedWithWork(
|
|
558
|
-
|
|
559
|
-
this.tileApproach.controller.abort(); this.tileApproach = null;
|
|
560
|
-
}
|
|
561
|
-
const feet = this.worldFeet(), previous = this.previousFeet;
|
|
562
|
-
const travelledDistance = previous === undefined ? 0 : Math.hypot(feet.x - previous.x, feet.z - previous.z);
|
|
563
|
-
// More than a second of modeled travel between fixed samples is a pose/portal jump.
|
|
564
|
-
// Establish a new origin instead of spending a constructor on its accidental direction.
|
|
565
|
-
const travelled = previous !== undefined && travelledDistance >= APPROACH_TRAVEL_METRES && travelledDistance <= this.ports.readiness.link.speed;
|
|
566
|
-
const steps = ++this.stepsSincePrevious, speed = travelled ? travelledDistance * FIXED_HZ / steps : 0;
|
|
567
|
-
if (previous === undefined || travelledDistance >= APPROACH_TRAVEL_METRES) { this.previousFeet = feet; this.stepsSincePrevious = 0; }
|
|
568
|
-
// Prefetch the closest cells' products (never their worlds: G663). Unsupported far proxies do not consume the count
|
|
569
|
-
// before enterable cells inside the cold readiness bound.
|
|
570
|
-
const candidates=work.candidates,cells=this.assembly.cells;
|
|
571
|
-
for(let i=0,length=cells.length;i<length;i++){
|
|
572
|
-
const cell=cells[i];if(cell!==undefined&&cell.instance!==this.active&&(this.ports.prefetchable?.(cell)??true))candidates.push(cell);
|
|
573
|
-
}
|
|
574
|
-
// Fixed cell poses and this tick's captured feet: avoid repeating hypot inside every sort comparison.
|
|
575
|
-
for (const cell of candidates) this.candidateDistances.set(cell,this.distance(cell,feet));
|
|
576
|
-
candidates.sort((a,b) => (this.candidateDistances.get(a) ?? Infinity) - (this.candidateDistances.get(b) ?? Infinity) || a.instance.localeCompare(b.instance));
|
|
577
|
-
// Immutable products are selected by distance, without a whole-world count cap.
|
|
578
|
-
const nearby = candidates;
|
|
579
|
-
// The frame-transfer reservation protects an actual entry; inactive whole worlds retire in steps. A world built ahead
|
|
580
|
-
// (`buildAhead`) stays while the traveller is on the road and has not turned into another mouth (below); one pre-warmed
|
|
581
|
-
// from inside the source (GC5) stays while the traveller is within WARM_KEEP_METRES of it.
|
|
582
|
-
if (this.active !== null && this.ahead !== null && (this.ahead === this.active
|
|
583
|
-
|| this.distance(this.assembly.cell(this.ahead), feet) > WARM_KEEP_METRES)) this.ahead = null;
|
|
439
|
+
private beforeFixedWithWork():void{
|
|
440
|
+
// J353: the road and placeholders remain, but a page never reads, prepares or admits a second cell.
|
|
584
441
|
this.retireInactiveRegions();
|
|
585
|
-
// GC6: the demanded neighbour stays demanded until its product is in, it is entered, or the traveller is far from it
|
|
586
|
-
const demanded = this.demanded;
|
|
587
|
-
if (demanded !== null && (this.products.has(demanded) || this.residents.has(demanded) || demanded === this.active || this.issues.has(demanded)
|
|
588
|
-
|| this.distance(this.assembly.cell(demanded), feet) > DEMAND_METRES + WARM_LEAD_METRES * 4)) this.demanded = null;
|
|
589
|
-
for (const cell of nearby) {
|
|
590
|
-
const estimate = readinessModel(this.ports.readiness.bundle(cell), this.ports.readiness.link), distance = this.distance(cell, feet);
|
|
591
|
-
if (this.demanded !== null && this.demanded !== cell.instance) continue;
|
|
592
|
-
if (this.assembly.approaching(distance, estimate.distance) && !this.issues.has(cell.instance) && this.ports.backgroundReady?.() !== false) void background(cell.instance, this.prefetch([cell.instance], 'radial'), () => !this.disposed);
|
|
593
|
-
}
|
|
594
|
-
// GC5: the neighbour across the source's nearest edge, within DEMAND_METRES, has its product read as demand, standing or
|
|
595
|
-
// moving: a player at a cell's edge reaches it in seconds at a boost, and the radial read above is only a guess the shared
|
|
596
|
-
// budget declines while every neighbour competes for it (Pine's read alone is 6 to 8 s). One at a time, the nearest.
|
|
597
|
-
if (this.active !== null && this.ports.buildAhead === true) {
|
|
598
|
-
const near = candidates[0];
|
|
599
|
-
// GC9: a radial read already pending for it is raised to demand once (the budget declined Pine's radial read again and
|
|
600
|
-
// again while it stood pending, so the demand read never started inside Driftwood and Pine's world was built on the road)
|
|
601
|
-
const pending = near === undefined ? undefined : this.productRequests.get(near.instance);
|
|
602
|
-
if (near !== undefined && this.distance(near, feet) <= DEMAND_METRES && !this.products.has(near.instance) && !this.residents.has(near.instance)
|
|
603
|
-
&& (pending === undefined || !pending.required && this.raised !== pending.work) && !this.issues.has(near.instance) && !this.constructing.has(near.instance)
|
|
604
|
-
&& this.deferredDemand.get(near.instance) !== this.ports.allocator.revision && this.ports.backgroundReady?.() !== false) {
|
|
605
|
-
if (pending !== undefined) this.raised = pending.work;
|
|
606
|
-
this.demanded = near.instance;
|
|
607
|
-
void background(near.instance, this.prefetchProduct(near.instance, true, 'explicit', true), () => !this.disposed);
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
// Approach preparation owns render tiles only, never a regional world or gameplay hooks.
|
|
611
|
-
const moving = !travelled ? undefined : candidates.find(cell => headsToEntry(cell, feet, previous)
|
|
612
|
-
&& this.distance(cell, feet) < this.distance(cell, previous) - 0.000001);
|
|
613
|
-
const source = this.active === null ? undefined : this.assembly.cell(this.active);
|
|
614
|
-
const sourceDistance = source === undefined ? Infinity : Math.max(Math.abs(feet.x - source.origin.x), Math.abs(feet.z - source.origin.z));
|
|
615
|
-
const transportApproach = this.transportApproach;
|
|
616
|
-
if (transportApproach !== null) {
|
|
617
|
-
const cell = this.assembly.cell(transportApproach.instance);
|
|
618
|
-
if (moving !== undefined && moving.instance !== cell.instance
|
|
619
|
-
|| this.distance(cell, feet) >= this.assembly.pitch
|
|
620
|
-
|| source !== undefined && source.instance !== cell.instance && sourceDistance < CHUNK_HALF - 1) this.stopApproachTransport();
|
|
621
|
-
}
|
|
622
|
-
const tileApproach = this.tileApproach;
|
|
623
|
-
if (tileApproach !== null) {
|
|
624
|
-
const cell = this.assembly.cell(tileApproach.instance);
|
|
625
|
-
if (moving !== undefined && moving.instance !== cell.instance
|
|
626
|
-
|| this.distance(cell, feet) > readinessModel(this.ports.readiness.bundle(cell), this.ports.readiness.link).distance) {
|
|
627
|
-
tileApproach.controller.abort(); this.tileApproach = null;
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
// The world built ahead goes once the traveller is a pitch from it, or heads from the road into another mouth (a stop
|
|
631
|
-
// keeps it). Checked while a build runs too, which the gate below skips.
|
|
632
|
-
const wallReach = 6 + this.ports.player.motor.opts.radius + 0.5 + this.ports.readiness.link.speed / 60;
|
|
633
|
-
const departed = this.transitions.at(-1)?.from;
|
|
634
|
-
// QA 11-13 row 43: on the road within a cell's wall reach the traveller is at that cell's wall, whatever the heading: a
|
|
635
|
-
// jump or a recoil off the wall reads as a heading back into the cell just left, which let the world built ahead go.
|
|
636
|
-
const held = this.ports.buildAhead === true && this.active === null && this.assembly.at(feet.x, feet.z) === undefined
|
|
637
|
-
? nearby.find(cell => cell.instance !== departed && this.distance(cell, feet) <= wallReach) : undefined;
|
|
638
|
-
// Inside the source a new heading must hold HEADING_HOLD_MS before it retires the world built ahead: steering that
|
|
639
|
-
// wobbles near a corner would otherwise build and dispose a whole world per flip.
|
|
640
|
-
const turned = moving !== undefined && moving.instance !== this.ahead;
|
|
641
|
-
if (!turned || this.active === null) this.turnedSince = null;
|
|
642
|
-
else if (this.turnedSince?.instance !== moving.instance) this.turnedSince = { instance: moving.instance, at: diagnosticNow() };
|
|
643
|
-
const settledTurn = turned && (this.active === null || diagnosticNow() - (this.turnedSince?.at ?? 0) >= HEADING_HOLD_MS);
|
|
644
|
-
if (this.ahead !== null && (this.distance(this.assembly.cell(this.ahead), feet) >= this.assembly.pitch
|
|
645
|
-
|| held === undefined && settledTurn && (this.assembly.at(feet.x, feet.z) === undefined || this.active !== null))) this.ahead = null;
|
|
646
|
-
if (this.requests.size === 0) {
|
|
647
|
-
const boulevard=work.boulevard;
|
|
648
|
-
if(travelled&&moving===undefined)for(let i=0,length=candidates.length;i<length;i++){
|
|
649
|
-
const cell=candidates[i];if(cell!==undefined&&cell.instance!==departed
|
|
650
|
-
&&(boulevardApproachDistance(cell,feet,previous,this.assembly.pitch)??Infinity)
|
|
651
|
-
<=readinessModel(this.ports.readiness.bundle(cell),this.ports.readiness.link).distance)boulevard.push(cell);
|
|
652
|
-
}
|
|
653
|
-
// Product metadata identifies bounded native alternatives even when the nearer opaque product filled
|
|
654
|
-
// the radial prefetch count. This admits immutable products/modules, never their foundations.
|
|
655
|
-
for (const cell of boulevard) if (!this.issues.has(cell.instance)) void background(cell.instance, this.prefetch([cell.instance], 'boulevard'), () => !this.disposed);
|
|
656
|
-
// A unique next junction can prepare tiles. Equidistant sides wait for a turn.
|
|
657
|
-
let predicted: GridCell | undefined, nextDistance = Infinity;
|
|
658
|
-
for (const cell of boulevard) {
|
|
659
|
-
const distance = boulevardApproachDistance(cell, feet, previous ?? feet, this.assembly.pitch);
|
|
660
|
-
if (distance === undefined) continue;
|
|
661
|
-
if (distance < nextDistance - 0.000001) { predicted = cell; nextDistance = distance; }
|
|
662
|
-
else if (Math.abs(distance - nextDistance) <= 0.000001) predicted = undefined;
|
|
663
|
-
}
|
|
664
|
-
// A stationary sample is not a redirect. Keep the verified render owner
|
|
665
|
-
// until a named heading or the distance fence replaces it; the cell just
|
|
666
|
-
// left must not steal that pin merely because its wall is still nearest.
|
|
667
|
-
const heldApproach = this.tileApproach === null ? undefined : this.assembly.cell(this.tileApproach.instance);
|
|
668
|
-
const approach = moving ?? predicted ?? heldApproach
|
|
669
|
-
?? nearby.find(cell => cell.instance !== departed && this.distance(cell, feet) <= wallReach);
|
|
670
|
-
const named = moving ?? predicted, outsideSource = sourceDistance >= CHUNK_HALF;
|
|
671
|
-
if (named !== undefined && outsideSource && !this.residents.has(named.instance) && !this.issues.has(named.instance)
|
|
672
|
-
&& this.distance(named, feet) < this.assembly.pitch) this.prepareApproachTransport(named);
|
|
673
|
-
// GC5 / GC36 (J322: no walls, no hold at the line): on the road, a traveller heading into a cell's mouth builds that
|
|
674
|
-
// cell's world now, not at the line. Built on demand there, the walk stood 2 to 5 s at the neighbour's closed edge
|
|
675
|
-
// while its world was made (2 to 4 s in Chromium). The entry's own preparation then finds it resident. The departed
|
|
676
|
-
// cell retires first, as the entry would retire it; a U-turn builds it again, as any entry does.
|
|
677
|
-
// Only from the road itself: past a cell's line (inside its square, before the 6 m entry) the heading names the cell
|
|
678
|
-
// beyond it, which would retire the world just built for the one underfoot.
|
|
679
|
-
// QA 11-13 row 43 (Jake on staging: 11 s at Template's wall, "saved state and its systems", no progress): a traveller
|
|
680
|
-
// standing at a neighbour's closed wall makes no heading (under 0.1 m a sample), so a world built ahead and then let go
|
|
681
|
-
// was never asked for again, and online the server crosses only past the line the wall holds them short of. Held at
|
|
682
|
-
// a closed wall on the road, that cell's world is always building.
|
|
683
|
-
// A failed build is tried again while they stand there, at most every HELD_RETRY_MS (never on a cleanup failure).
|
|
684
|
-
if (held !== undefined && this.issues.has(held.instance) && !this.residents.has(held.instance) && !this.requests.has(held.instance) && !this.productRequests.has(held.instance)
|
|
685
|
-
&& diagnosticNow() >= (this.heldRetryAt.get(held.instance) ?? 0)) { this.heldRetryAt.set(held.instance, diagnosticNow() + HELD_RETRY_MS); this.retry(held.instance); }
|
|
686
|
-
if (held !== undefined && !this.residents.has(held.instance) && !this.issues.has(held.instance)) {
|
|
687
|
-
this.ahead = held.instance;
|
|
688
|
-
if (this.retireInactiveRegions(held.instance)) void background(held.instance, this.ensure(held.instance), () => !this.disposed);
|
|
689
|
-
}
|
|
690
|
-
else if (held === undefined && this.ports.buildAhead === true && moving !== undefined && this.active === null && this.assembly.at(feet.x, feet.z) === undefined
|
|
691
|
-
&& !this.residents.has(moving.instance) && !this.issues.has(moving.instance)
|
|
692
|
-
&& this.distance(moving, feet) < this.assembly.pitch && this.retireInactiveRegions(moving.instance)) {
|
|
693
|
-
this.ahead = moving.instance;
|
|
694
|
-
void background(moving.instance, this.ensure(moving.instance), () => !this.disposed);
|
|
695
|
-
}
|
|
696
|
-
// GC5 (QA 11-13 row 39: boosts held 4 to 7.6 s at the neighbour's loading wall, the road being under 3 s at 18 m/s):
|
|
697
|
-
// inside the source, heading into a neighbour's mouth, its world is built once the traveller is its measured build
|
|
698
|
-
// time away at this speed. Only beside an isolated source and for an isolated product (opaque runtimes stay exclusive,
|
|
699
|
-
// built only on the road), and only when both fit beside each other (G723); else the road builds it as before.
|
|
700
|
-
if (this.ports.buildAhead === true && moving !== undefined && this.active !== null && this.ahead === null
|
|
701
|
-
&& this.residents.get(this.active)?.retainable === true && !this.residents.has(moving.instance) && !this.issues.has(moving.instance)
|
|
702
|
-
&& this.distance(moving, feet) <= this.warmLead(moving.instance, speed)) {
|
|
703
|
-
const product = this.products.get(moving.instance);
|
|
704
|
-
// The heading names it: its product is read as demand (it may evict speculative neighbours' products), not as a radial
|
|
705
|
-
// guess, which the shared budget declines while the page's other neighbours compete for the same headroom.
|
|
706
|
-
if (product === undefined) {
|
|
707
|
-
this.warmRefusal = 'product';
|
|
708
|
-
this.demanded = moving.instance;
|
|
709
|
-
if (!this.productRequests.has(moving.instance) && this.deferredDemand.get(moving.instance) !== this.ports.allocator.revision)
|
|
710
|
-
void background(moving.instance, this.prefetchProduct(moving.instance, true, 'explicit', true), () => !this.disposed);
|
|
711
|
-
}
|
|
712
|
-
else if (product.isolatedPreparation !== true) this.warmRefusal = 'exclusive';
|
|
713
|
-
else if (!this.ports.allocator.canPrepareAlongside(this.active, moving.instance, product.bytes,
|
|
714
|
-
{ playing: this.ports.allocator.envelope(), loading: CONTENT_CAPS.loading })) this.warmRefusal = 'budget';
|
|
715
|
-
else {
|
|
716
|
-
this.ahead = moving.instance; this.warms++; this.warmRefusal = null;
|
|
717
|
-
void background(moving.instance, this.ensure(moving.instance), () => !this.disposed);
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
if (approach !== undefined && this.ports.prepareNeighbour !== undefined && this.tileMetadata.has(approach.instance)
|
|
721
|
-
&& !this.residents.has(approach.instance) && !this.issues.has(approach.instance)
|
|
722
|
-
&& (this.active === null || moving === approach)
|
|
723
|
-
// A held owner survives a stationary/teleported sample without moving
|
|
724
|
-
// its entry tile. Only a real named approach may retarget that pin.
|
|
725
|
-
&& (heldApproach === undefined || moving === approach || predicted === approach)
|
|
726
|
-
&& this.assembly.approaching(this.distance(approach, feet), readinessModel(this.ports.readiness.bundle(approach), this.ports.readiness.link).distance)) {
|
|
727
|
-
this.prepareNeighbour(approach, feet);
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
442
|
const walls = this.active === null ? this.highway.walls : this.region(this.active)?.walls;
|
|
731
443
|
walls?.sync(this.readiness);
|
|
732
444
|
}
|
|
@@ -887,7 +599,6 @@ export class LiveGridHost {
|
|
|
887
599
|
motors.commit();
|
|
888
600
|
this.ports.player.motor = rider.motor; this.active = to;
|
|
889
601
|
if (to !== null) this.forgetLastCell();
|
|
890
|
-
this.previousFeet = this.worldFeet(); // A committed spawn/frame placement is not the traveller's heading.
|
|
891
602
|
this.ports.bindFrame({ instance: to, physics: this.physics(to), motor: rider.motor, origin });
|
|
892
603
|
this.residents.get(to ?? '')?.lease.update({ needed: true }); this.residents.get(from ?? '')?.lease.update({ needed: to === null });
|
|
893
604
|
this.crossings++; this.transitions.push({ from, to }); if (this.transitions.length > 256) this.transitions.shift(); finish();
|
|
@@ -900,7 +611,7 @@ export class LiveGridHost {
|
|
|
900
611
|
playingBytes: this.ports.allocator.ownerCost(last.instance).playing, capBytes: Math.min(this.ports.allocator.envelope(), policy.playingBytes) };
|
|
901
612
|
}
|
|
902
613
|
/** Read-only crossing evidence and failures for the real grid physics harness. */
|
|
903
|
-
state(): LiveGridState { return { current: this.active, worldFeet: this.worldFeet(), crossings: this.crossings,
|
|
614
|
+
state(): LiveGridState { return { current: this.active, worldFeet: this.worldFeet(), crossings: this.crossings, transitions: this.transitions.map((row) => ({ ...row })), residents: [...this.residents.keys()].sort(), pending: [...new Set([...this.requests.keys(), ...this.productRequests.keys()])].sort(), pendingWork: [
|
|
904
615
|
...[...this.requests.keys()].sort().map(instance => ({ instance, kind: 'world' as const, trigger: 'entry' as const })),
|
|
905
616
|
...[...this.productRequests].sort(([a], [b]) => a.localeCompare(b)).map(([instance, request]) => ({ instance, kind: request.required ? 'required-metadata' as const : 'optional-metadata' as const, trigger: request.trigger })),
|
|
906
617
|
], issues: Object.fromEntries(this.issues), gameplayReady: this.active === null || this.ports.gameplayReady(this.active), ...(this.ports.lastCell === undefined ? {} : { retainedCell: this.retainedState() }), retirements: this.retirements.map(row => ({ ...row })), retiring: [...this.retiring.keys()], ghosts: { count: this.ghosts.count(), regions: this.ghosts.regions() } }; }
|
|
@@ -910,7 +621,6 @@ export class LiveGridHost {
|
|
|
910
621
|
this.disposed = true;
|
|
911
622
|
this.forgetLastCell();
|
|
912
623
|
this.stopApproachTransport();
|
|
913
|
-
this.tileApproach?.controller.abort(); this.tileApproach = null;
|
|
914
624
|
this.tileMetadata.clear();
|
|
915
625
|
for (const cancel of this.frames) cancel();
|
|
916
626
|
// Return the still-live page traveller before freeing a world that contains its current controller.
|