@wildshard/engine 0.1.19 → 0.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lint/engine-sides.json +5 -0
- package/package.json +5 -2
- package/scripts/app-build/gen.ts +11 -0
- package/scripts/cell-mem-bench.mjs +2 -0
- package/scripts/chaos-proxy-core.mjs +14 -1
- package/scripts/chaos-proxy-proof.mjs +22 -0
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/failmode-cases.d.mts +8 -0
- package/scripts/failmode-cases.mjs +97 -0
- package/scripts/failmode-proof.mjs +532 -0
- package/scripts/grid-crossing-nightly.mjs +5 -4
- package/scripts/grid-crossing-report.mjs +5 -2
- package/scripts/grid-crossing-tour.mjs +36 -12
- package/scripts/grid-crossing-walk-proof.mjs +4 -2
- package/scripts/hover-speed-probe.mjs +136 -0
- package/scripts/land.mjs +2 -1
- package/scripts/loading-flow/benchmax.mjs +34 -11
- package/scripts/loading-flow/deskbench.mjs +276 -0
- package/scripts/loading-flow/stalls.d.mts +17 -3
- package/scripts/loading-flow/stalls.mjs +82 -3
- package/scripts/net-lag-proof.mjs +3 -2
- package/scripts/nightly-model.ts +9 -6
- package/scripts/offline-proof.mjs +7 -1
- package/scripts/online-rig.mjs +9 -7
- package/scripts/parity/boot-smoke.mjs +13 -2
- package/scripts/pin-format.ts +5 -2
- package/scripts/pins-reuse.d.mts +1 -0
- package/scripts/pins-reuse.mjs +22 -0
- package/scripts/release-cook.mjs +109 -0
- package/scripts/scratch-dir.mjs +95 -0
- package/scripts/scratch-sweep.mjs +182 -0
- package/scripts/tsconfig.json +2 -12
- package/scripts/vps/harden-prometheus.sh +3 -0
- package/scripts/vps/rebuild.sh +35 -9
- package/scripts/vps/wildshard-apply.mjs +5 -1
- package/scripts/vps/wildshard-config +117 -1
- package/scripts/worktree-reap.mjs +54 -8
- package/scripts/worktree.mjs +19 -5
- package/src/client/engine/anim/rigParser.ts +2 -2
- package/src/client/engine/boot/contentRead.ts +54 -5
- package/src/client/engine/boot/gpuFiles.ts +3 -3
- package/src/client/engine/boot/leaveAfterPaint.ts +4 -1
- package/src/client/engine/core/Game.ts +63 -19
- package/src/client/engine/core/gpuOnly.ts +10 -0
- package/src/client/engine/core/renderBudget.ts +134 -0
- package/src/client/engine/core/shadowLayer.ts +18 -0
- package/src/client/engine/explore/pick.ts +13 -1
- package/src/client/engine/net/predictor.ts +12 -4
- package/src/client/engine/net/redial.ts +40 -5
- package/src/client/engine/player/TouchControls.ts +3 -2
- package/src/client/engine/render/dataLook.ts +70 -7
- package/src/client/engine/render/families/pbr.ts +2 -0
- package/src/client/engine/render/families/registry.ts +11 -2
- package/src/client/engine/render/families/sceneSurface.ts +118 -0
- package/src/client/engine/render/look.ts +7 -1
- package/src/client/engine/render/precompile.ts +4 -2
- package/src/client/engine/render/tiers.ts +4 -1
- package/src/client/engine/telemetry/browserErrors.ts +3 -1
- package/src/client/engine/ui/ErrorModal.ts +1 -1
- package/src/client/engine/ui/Loading.ts +14 -2
- package/src/client/engine/ui/errorScreen.ts +51 -9
- package/src/client/engine/ui/hoverBoost.ts +31 -4
- package/src/client/engine/ui/styles/touch.css +6 -0
- package/src/client/engine/world/declaredProps.ts +5 -1
- package/src/client/engine/world/skyRig.ts +4 -1
- package/src/client/engine/world/terrainTileView.ts +64 -23
- package/src/client/game/boot/spawnDownload.ts +44 -6
- package/src/client/game/devScene/hook.ts +149 -12
- package/src/client/game/devScene/liveLook.ts +21 -0
- package/src/client/game/grid/live.ts +47 -10
- package/src/client/game/grid/liveSession.ts +25 -6
- package/src/client/game/grid/pageEntry.ts +12 -1
- package/src/client/game/grid/productInputs.ts +22 -11
- package/src/client/game/grid/session.ts +15 -4
- package/src/client/game/grid/shardfileFar.ts +13 -2
- package/src/client/game/session/finish.ts +4 -1
- package/src/client/game/shardfile/client.ts +24 -7
- package/src/client/game/shardfile/clientPropMaterials.ts +4 -1
- package/src/client/game/shardfile/clientSource.ts +7 -3
- package/src/client/game/shardfile/clientViews.ts +36 -8
- package/src/client/game/shardfile/clientWorker.ts +4 -4
- package/src/client/game/shardfile/constructionCheckpoint.ts +2 -2
- package/src/client/game/shardfile/groundMerge.ts +59 -5
- package/src/client/game/shardfile/hybrid.ts +2 -0
- package/src/client/game/shardfile/look.ts +1 -1
- package/src/client/game/shardfile/slabLibrary.ts +115 -49
- package/src/client/game/shardfile/tileContent.ts +1 -1
- package/src/client/game/shardfile/tileDriver.ts +38 -11
- package/src/client/game/shardfile/wirePage.ts +7 -3
- package/src/client/game/shardfile/worldScenes.ts +17 -10
- package/src/client/host/online/doctor.ts +20 -7
- package/src/client/host/online/doctorView.ts +2 -0
- package/src/client/host/online/linkScreens.ts +95 -11
- package/src/client/host/online/reconnectStrip.ts +3 -2
- package/src/client/host/online/release.ts +87 -16
- package/src/client/host/online/releaseScreens.ts +108 -0
- package/src/client/host/online/shell.ts +24 -5
- package/src/client/host/online/voice.ts +45 -1
- package/src/client/host/online/voiceUi.ts +24 -6
- package/src/client/host/standalone/shell.ts +37 -1
- package/src/server/engine/sim/playerSim.ts +1 -1
- package/src/server/game/grid/simulation.ts +12 -6
- package/src/server/game/quest/eliteDrops.ts +7 -3
- package/src/server/game/riding/nativeTaming.ts +13 -2
- package/src/server/host/dedicated/cellHost.ts +21 -2
- package/src/server/host/dedicated/cellProtocol.ts +2 -0
- package/src/server/host/dedicated/cellWorker.ts +1 -1
- package/src/server/host/dedicated/dedicatedRoom.ts +38 -8
- package/src/server/host/dedicated/roadRoom.ts +3 -0
- package/src/server/host/dedicated/serverMetrics.ts +9 -0
- package/src/server/host/dedicated/workerTable.ts +31 -24
- package/src/server/host/standalone/gridServer.ts +1 -1
- package/src/server/host/standalone/serverHost.ts +56 -10
- package/src/server/host/standalone/serverProduct.ts +9 -7
- package/src/server/host/standalone/serverRuntime.ts +1 -1
- package/src/shared/engine/boot/loadingWaits.ts +10 -2
- package/src/shared/engine/core/config.ts +3 -0
- package/src/shared/engine/core/framePacing.ts +12 -1
- package/src/shared/engine/physics/terrainTiles.ts +20 -4
- package/src/shared/engine/player/hoverSpeed.ts +3 -3
- package/src/shared/engine/strings.ts +12 -1
- package/src/shared/game/devColliders.ts +60 -0
- package/src/shared/game/devGameplay.ts +41 -0
- package/src/shared/game/grid/rules.ts +12 -0
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// FM5 (meta docs/plans/MMO-FAILURE-MODES-PLAN.md): what a player sees while the page has no release file to dial from. Modes 1, 11, 12,
|
|
2
|
+
// 37, 38 and 39 are **pages** (the plan's first style): before the world, over the loading card, the whole screen, one button that does
|
|
3
|
+
// something, and they move on by themselves when the file answers. Mode 46 is the staging **mark**: a quiet line for the session.
|
|
4
|
+
// The waits are release.ts's policy (`releaseRetryMs`); this file only says so and counts down the real scheduled read.
|
|
5
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
6
|
+
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
7
|
+
import { captureBrowserError } from '@wildshard/engine/telemetry/browserErrors';
|
|
8
|
+
import { buttons, card, linkStyle, make, ring } from './linkScreens';
|
|
9
|
+
import { releaseScreen, type ReleaseFault, type ReleaseScreen, type ReleaseWait } from './release';
|
|
10
|
+
|
|
11
|
+
/** The words of each page: a tag, a headline and the key line. No status code, address or exception is primary copy (Details holds them). */
|
|
12
|
+
const WORDS: Readonly<Record<ReleaseScreen, { readonly tag: string; readonly title: string; readonly body: string; readonly tone: 'warn' | 'bad' | 'info' }>> = {
|
|
13
|
+
'offline-launch': { tag: 'Offline', title: 'You\'re offline', body: 'We\'ll connect as soon as you\'re back.', tone: 'warn' },
|
|
14
|
+
'release-5xx': { tag: 'Can\'t find the world', title: 'Can\'t find the world', body: 'The world\'s information didn\'t arrive. We\'ll try again by ourselves.', tone: 'warn' },
|
|
15
|
+
'release-429': { tag: 'Busy', title: 'Lots of players joining', body: 'You don\'t need to do anything: we\'ll try again when the world says to.', tone: 'info' },
|
|
16
|
+
'release-404': { tag: 'Not available', title: 'World information isn\'t available', body: 'Check your connection, or try again later. We\'ll look again every minute.', tone: 'warn' },
|
|
17
|
+
'captive-portal': { tag: 'Network sign-in', title: 'This network may need sign-in', body: 'Something other than the world answered. If this network has a sign-in page, sign in, then try again.', tone: 'warn' },
|
|
18
|
+
'release-unsigned': { tag: 'Not verified', title: 'Couldn\'t check the world', body: 'We won\'t connect to a world we can\'t verify.', tone: 'bad' },
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/** Details: what was measured, never a guess (a browser can't tell DNS from TLS from a reset). */
|
|
22
|
+
function measured(fault: ReleaseFault): string {
|
|
23
|
+
if (fault.kind === 'offline') return 'The browser says this device is offline.';
|
|
24
|
+
if (fault.kind === 'network') return 'No HTTP response. Check the connection.';
|
|
25
|
+
if (fault.kind === 'timeout') return `No answer in ${String(Math.round(fault.ms / 1000))} s.`;
|
|
26
|
+
if (fault.kind === 'status') return `HTTP ${String(fault.status)}${fault.retryAfterMs === null ? '' : `, Retry-After ${String(Math.round(fault.retryAfterMs / 1000))} s`}.`;
|
|
27
|
+
if (fault.kind === 'unsigned') return 'The world\'s file failed its signature check.';
|
|
28
|
+
return fault.why === 'redirect' ? 'The read was sent to another address.' : fault.why === 'html' ? 'A web page answered instead of the world\'s file.' : 'The answer was not a signed world file.';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface ReleaseScreenHooks {
|
|
32
|
+
/** Open the Connection doctor (E7.5), naming the screen that asked. */
|
|
33
|
+
readonly doctor?: (from: string) => void;
|
|
34
|
+
/** Leave for the title screen. */
|
|
35
|
+
readonly title: () => void;
|
|
36
|
+
/** Where mode 39 reports (the browser error tracker; a test observes its own). */
|
|
37
|
+
readonly report?: typeof captureBrowserError;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* FM5: the release pages, as release.ts's `ReleaseWait`. Each failed read shows its page and settles when the page should read again:
|
|
42
|
+
* the policy's scheduled time (counted down on the page), Try again, the network coming back, or (a portal) the page coming into view.
|
|
43
|
+
* Title screen rejects, so the load stops and the player leaves. `done` closes the page.
|
|
44
|
+
*
|
|
45
|
+
* await releaseToDial(url, key, { keep, wait: releaseScreens(scope, { doctor, title }) });
|
|
46
|
+
*/
|
|
47
|
+
export function releaseScreens(scope: Scope, hooks: ReleaseScreenHooks, parent: HTMLElement = document.body): ReleaseWait {
|
|
48
|
+
const report = hooks.report ?? captureBrowserError;
|
|
49
|
+
let shown: Scope | null = null, reported = false;
|
|
50
|
+
const close = (): void => { shown?.dispose(); shown = null; };
|
|
51
|
+
scope.onDispose(close);
|
|
52
|
+
return {
|
|
53
|
+
done: close,
|
|
54
|
+
after: (fault, attempt, retryMs, detail) => new Promise<void>((resolve, reject) => {
|
|
55
|
+
close();
|
|
56
|
+
linkStyle();
|
|
57
|
+
const id = releaseScreen(fault), words = WORDS[id], page = new Scope(`online.release-${id}`, scope);
|
|
58
|
+
shown = page;
|
|
59
|
+
const { root, box } = card(page, id, words.tone, words.tag, words.title);
|
|
60
|
+
root.classList.add('ws-link-page');
|
|
61
|
+
box.append(make('p', 'ws-link-body', words.body));
|
|
62
|
+
let settled = false;
|
|
63
|
+
let trying = (): void => undefined;
|
|
64
|
+
const go = (): void => { if (settled) return; settled = true; trying(); resolve(); };
|
|
65
|
+
const leave = (): void => { if (settled) return; settled = true; reject(new Error('The player left the release wait for the title')); hooks.title(); };
|
|
66
|
+
page.onDispose(() => { if (!settled) { settled = true; resolve(); } });
|
|
67
|
+
// the next read, counted from what is actually scheduled: never a made-up clock
|
|
68
|
+
const status = make('p', 'ws-link-auto');
|
|
69
|
+
if (retryMs !== null) {
|
|
70
|
+
const due = diagnosticNow() + retryMs, line = make('span');
|
|
71
|
+
const tick = (): void => { const left = Math.max(0, Math.ceil((due - diagnosticNow()) / 1000)); line.textContent = `Next try in ${String(left)} s · ${attempt === 0 ? 'first try failed' : `${String(attempt + 1)} tries so far`}`; };
|
|
72
|
+
const counting = page.interval(500, tick);
|
|
73
|
+
trying = () => { page.cancelTimer(counting); line.textContent = 'Trying…'; };
|
|
74
|
+
tick(); page.timeout(retryMs, go);
|
|
75
|
+
status.append(ring(), line);
|
|
76
|
+
box.append(status);
|
|
77
|
+
} else if (id === 'offline-launch') {
|
|
78
|
+
status.append(ring(), make('span', '', 'Waiting for the network'));
|
|
79
|
+
box.append(status);
|
|
80
|
+
}
|
|
81
|
+
// the network back, or a portal's page back in view after a sign-in elsewhere: read again now
|
|
82
|
+
page.listen(window, 'online', go);
|
|
83
|
+
if (id === 'captive-portal') page.listen(document, 'visibilitychange', () => { if (document.visibilityState === 'visible') go(); });
|
|
84
|
+
const actions: { label: string; primary?: true; busy?: string; act: () => void }[] = [];
|
|
85
|
+
// mode 12 waits what the world asked; a tap doesn't jump that queue
|
|
86
|
+
if (id !== 'release-429') actions.push({ label: retryMs === null ? 'Try again' : 'Try now', primary: true, busy: 'Trying…', act: go });
|
|
87
|
+
if (hooks.doctor !== undefined && id !== 'offline-launch') { const { doctor } = hooks; actions.push({ label: 'Check connection', act: () => { doctor(id); } }); }
|
|
88
|
+
actions.push({ label: 'Title screen', act: leave });
|
|
89
|
+
box.append(buttons(page, actions));
|
|
90
|
+
const details = make('details'), summary = make('summary', '', 'Details');
|
|
91
|
+
details.append(summary, make('p', '', `${measured(fault)} ${detail}`));
|
|
92
|
+
box.append(details);
|
|
93
|
+
parent.append(root);
|
|
94
|
+
root.querySelector<HTMLButtonElement>('button')?.focus(); // the first action takes focus; card() keeps Tab inside
|
|
95
|
+
// mode 39 goes to the error report queue, once a page
|
|
96
|
+
if (id === 'release-unsigned' && !reported) { reported = true; try { report(new Error(`Release file failed its signature: ${detail}`), { system: 'link', build: '', shard: '', bootStage: 'loading', fatal: false, screen: 'release-unsigned', diagnostic: { detail } }); } catch { /* telemetry never stops the page */ } }
|
|
97
|
+
}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** FM5 mode 46: a page on the staging world says so, for the whole session. Returns its node (owned by `scope`). */
|
|
102
|
+
export function stagingMark(scope: Scope, parent: HTMLElement = document.body): HTMLElement {
|
|
103
|
+
linkStyle();
|
|
104
|
+
const mark = scope.ownNode(make('div', 'ws-link ws-link-mark', 'Staging · not the live world'));
|
|
105
|
+
mark.dataset['failmode'] = 'staging'; mark.dataset['tone'] = 'warn'; mark.setAttribute('role', 'status');
|
|
106
|
+
parent.append(mark);
|
|
107
|
+
return mark;
|
|
108
|
+
}
|
|
@@ -18,8 +18,10 @@ import { chatLines } from './chatLines';
|
|
|
18
18
|
import { VoiceChat, type VoiceHeard, type VoiceLink } from './voice';
|
|
19
19
|
import { voiceUi } from './voiceUi';
|
|
20
20
|
import { fetchSignedRelease, releaseToDial, type ReleaseKeep } from './release';
|
|
21
|
+
import { releaseScreens, stagingMark } from './releaseScreens';
|
|
21
22
|
import { newBuildPanel } from './reconnectStrip';
|
|
22
23
|
import { linkScreens } from './linkScreens';
|
|
24
|
+
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
23
25
|
|
|
24
26
|
/** `ready` with this byte is a clean quit: the door drops the body at once instead of holding it (server `socketPump.ts` `LEAVE_FLAG`). */
|
|
25
27
|
const LEAVE_FLAG = 1;
|
|
@@ -71,8 +73,8 @@ export interface OnlineShell {
|
|
|
71
73
|
readonly booted: Promise<{ readonly tick: number; readonly restored: boolean }>;
|
|
72
74
|
/** The page has loaded: the door may seat the body (E7.2's step 4). */
|
|
73
75
|
ready: () => void;
|
|
74
|
-
/** The page came back into view: check the link now. */
|
|
75
|
-
visible: () => void;
|
|
76
|
+
/** The page came back into view after `hiddenMs` out of it (FM4b mode 4): check the link now. */
|
|
77
|
+
visible: (hiddenMs?: number) => void;
|
|
76
78
|
retry: () => void;
|
|
77
79
|
/** FM4: the dial's progress and why the link is down, for the screens that show them; dial now, from a hold card. */
|
|
78
80
|
progress: () => LinkProgress;
|
|
@@ -153,7 +155,7 @@ export function connectOnline(config: OnlineConfig, view: OnlineView): OnlineShe
|
|
|
153
155
|
client.hello(config.build, config.identity);
|
|
154
156
|
const tickOf = (): number => client.latest?.tick ?? 0, idle = (): void => undefined;
|
|
155
157
|
return { client, voice, redials: true, booted, ready: () => { loaded = true; unseated?.control('ready'); unseated = null; },
|
|
156
|
-
visible:
|
|
158
|
+
visible: hiddenMs => { redial.check(hiddenMs); }, retry: () => { redial.retry(); }, progress: () => redial.progress, why: () => redial.why, dialNow: () => { redial.dialNow(); },
|
|
157
159
|
pause: idle, resume: idle, hold: idle, bossGod: idle, hardHits: idle, place: idle, raise: idle,
|
|
158
160
|
// The door hears a quit on any link of this build: seated, still admitted, or handed a held body back. A link that is down (a redial's
|
|
159
161
|
// wait) gets a fresh one to say it on, so a held body goes too. No redial follows: the page is going.
|
|
@@ -292,7 +294,14 @@ async function askWorld(config: { readonly release: string; readonly key: string
|
|
|
292
294
|
/** Enter the one world this build names. A stale tab reloads into the server's build once, and only then gives up. */
|
|
293
295
|
export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
294
296
|
// OF4: a verified kept release file dials at once (offline too), and the fresh read follows; with none, the page waits for the read
|
|
295
|
-
const { release: at, key, keep, identity, recordTag, grid, ...link } = config
|
|
297
|
+
const { release: at, key, keep, identity, recordTag, grid, ...link } = config;
|
|
298
|
+
// FM5: with no kept copy and no file, the page says why (offline, the file's server down or busy, a portal, a bad signature) and
|
|
299
|
+
// reads again by release.ts's policy until a verified file answers; Title screen stops the load
|
|
300
|
+
const waiting = new Scope('online.release-wait');
|
|
301
|
+
const toTitle = (): void => { markUnload('release page: title screen'); location.replace(new URL('/', location.origin).toString()); };
|
|
302
|
+
let dial: Awaited<ReturnType<typeof releaseToDial>>;
|
|
303
|
+
try { dial = await releaseToDial(at, key, { keep: keep ?? NO_KEEP, wait: releaseScreens(waiting, { doctor, title: toTitle }) }); } finally { waiting.dispose(); }
|
|
304
|
+
const { file: release, fresh } = dial, { socket } = release;
|
|
296
305
|
// QA row 16: a level page enters only from a tap. A reload this page makes itself carries the tap that brought it here.
|
|
297
306
|
const entering = (slug: string): void => { setTitleArrival({ slug, mode: 'enter' }, { tab: true }); };
|
|
298
307
|
const stale = async (): Promise<boolean> => { entering(link.loaded); const going = await reloadStale(); if (!going) dropTabArrival(); return going; };
|
|
@@ -300,6 +309,8 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
|
300
309
|
if (fresh === null && release.engineBuild !== link.build) await stale();
|
|
301
310
|
if (socket === undefined) throw new Error('The release file names no address');
|
|
302
311
|
const scope = new Scope('online.page');
|
|
312
|
+
// FM5 mode 46: the staging world says so for the session (the release file's own verified channel)
|
|
313
|
+
if (release.channel === 'staging') stagingMark(scope);
|
|
303
314
|
const goto = grid?.goto === true ? grid.cell : undefined;
|
|
304
315
|
let dialing = socket;
|
|
305
316
|
// MP2.4: the page asked for the Name before it got here (namePrompt.ts, once per device); Skip keeps the device's own (Guest)
|
|
@@ -312,6 +323,8 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
|
312
323
|
// Play here / Play again reload into the world: the tap that brought the player here comes along (QA row 16)
|
|
313
324
|
reload: () => { entering(link.loaded); void reloadByHand(); },
|
|
314
325
|
progress: () => shellNow?.progress() ?? { dials: 0, nextDialMs: null, downMs: 0 }, why: () => shellNow?.why() ?? 'closed',
|
|
326
|
+
// FM4b modes 21 and 22: the Slow and Unstable chips read the link's own measurements
|
|
327
|
+
stats: () => shellNow?.client.stats,
|
|
315
328
|
});
|
|
316
329
|
// `reload` is the one ending a screen doesn't answer: the page reloads into the world's build, once (J174)
|
|
317
330
|
const ended = async (): Promise<void> => { if (!await stale()) newBuildPanel(scope, stale, () => { entering(link.loaded); void reloadByHand(); }); };
|
|
@@ -342,6 +355,12 @@ export async function startOnline(config: StartOnline): Promise<OnlineShell> {
|
|
|
342
355
|
const chat = chatLines(scope, shell.client, document.body, screens.holdChat);
|
|
343
356
|
voiceUi(scope, new VoiceChat(scope, shell.voice), chat);
|
|
344
357
|
scope.listen(window,'pagehide',()=>{shell.flushRecords();});
|
|
345
|
-
|
|
358
|
+
// FM4b mode 4: how long the page was out of view rides the check, so a long absence back to a quiet link opens Welcome back
|
|
359
|
+
let hiddenAt: number | null = document.visibilityState === 'hidden' ? diagnosticNow() : null;
|
|
360
|
+
scope.listen(document, 'visibilitychange', () => {
|
|
361
|
+
if (document.visibilityState !== 'visible') { hiddenAt ??= diagnosticNow(); return; }
|
|
362
|
+
const hiddenMs = hiddenAt === null ? 0 : diagnosticNow() - hiddenAt;
|
|
363
|
+
hiddenAt = null; shell.visible(hiddenMs); screens.visible();
|
|
364
|
+
});
|
|
346
365
|
return { ...shell, dispose: () => { scope.dispose(); shell.dispose(); } };
|
|
347
366
|
}
|
|
@@ -30,12 +30,17 @@ export interface VoiceLink {
|
|
|
30
30
|
/** Where voice stands for this player. */
|
|
31
31
|
export type VoiceState = 'off' | 'asking' | 'joining' | 'on' | 'denied' | 'unsupported' | 'full' | 'failed';
|
|
32
32
|
/** One other player on voice; `body` is their player row's id (V7, V8), and `far` is out of earshot: 40 m or more away or out of sight. */
|
|
33
|
-
export interface VoicePeer { readonly id: string; readonly name: string; body?: string | null; speaking: boolean; muted: boolean; linked: boolean; far: boolean
|
|
33
|
+
export interface VoicePeer { readonly id: string; readonly name: string; body?: string | null; speaking: boolean; muted: boolean; linked: boolean; far: boolean;
|
|
34
|
+
/** FM8 mode 32: on voice, still not linked after every offer retry had its time (`VOICE_GIVE_UP_MS`). */
|
|
35
|
+
unreachable?: boolean }
|
|
34
36
|
|
|
35
37
|
/** A remote level past this is talking; held this long after it drops, so a word's gaps don't flicker. */
|
|
36
38
|
const SPEAKING_LEVEL = 0.03, SPEAKING_HOLD_MS = 450, LEVEL_POLL_MS = 150;
|
|
37
39
|
/** An offerer retries a failed or silent link this many times, the silent one after this long. */
|
|
38
40
|
const RETRIES = 3, UNANSWERED_MS = 15_000;
|
|
41
|
+
/** FM8 mode 32: a peer on voice still unlinked this long has had every retry (four offers, 15 s each) and some slack: voice can't
|
|
42
|
+
* reach it on this network. No peers, an empty room or a TURN list that didn't arrive is never this on its own. */
|
|
43
|
+
export const VOICE_GIVE_UP_MS: number = (RETRIES + 1) * UNANSWERED_MS + 10_000;
|
|
39
44
|
/** Signalling in pieces: a half-heard message is dropped after this long, and no peer holds more than a few at once. */
|
|
40
45
|
const PIECES_MS = 10_000, PIECES_PER_PEER = 4, MAX_PIECES = 64;
|
|
41
46
|
/** Pieces sent per 50 ms: signalling shares the game socket's message budget, so a burst is spread out. */
|
|
@@ -109,6 +114,8 @@ export class VoiceChat {
|
|
|
109
114
|
/** Bumped on every new seat, stop and disposal: an await that comes back to an older one does nothing. */
|
|
110
115
|
private session = 0;
|
|
111
116
|
private readonly muted = new Set<string>();
|
|
117
|
+
/** FM8 mode 32: since when each peer on voice has been unlinked */
|
|
118
|
+
private readonly waiting = new Map<string, number>();
|
|
112
119
|
private readonly changes = new Set<() => void>();
|
|
113
120
|
private me: string | null = null;
|
|
114
121
|
private mic: MediaStream | null = null;
|
|
@@ -308,6 +315,9 @@ export class VoiceChat {
|
|
|
308
315
|
return;
|
|
309
316
|
}
|
|
310
317
|
if (signal.sdp.type === 'offer') {
|
|
318
|
+
// Two offers crossed (both sides pressed FM8's Try again): the lower id keeps its own and the other side answers it.
|
|
319
|
+
const held = this.links.get(from);
|
|
320
|
+
if (held?.offerer === true && held.pc.signalingState === 'have-local-offer' && this.me !== null && this.me < from) return;
|
|
311
321
|
// A fresh offer replaces whatever link there was: the offerer started again.
|
|
312
322
|
this.drop(from);
|
|
313
323
|
const link = this.open(from, false);
|
|
@@ -447,9 +457,43 @@ export class VoiceChat {
|
|
|
447
457
|
if (speaking !== peer.speaking) { peer.speaking = speaking; moved = true; }
|
|
448
458
|
}
|
|
449
459
|
for (const peer of this.roster.values()) if (!this.links.has(peer.id)) { const far = voiceNear.gain(talker(peer)) === 0; if (far !== peer.far) { peer.far = far; moved = true; } }
|
|
460
|
+
if (this.reach(now)) moved = true;
|
|
450
461
|
this.tellTalking();
|
|
451
462
|
if (moved) this.changed();
|
|
452
463
|
}
|
|
464
|
+
/** FM8 mode 32: mark the peers voice can't reach. True when any mark changed. */
|
|
465
|
+
private reach(now: number): boolean {
|
|
466
|
+
let moved = false;
|
|
467
|
+
for (const id of this.waiting.keys()) if (!this.roster.has(id)) this.waiting.delete(id);
|
|
468
|
+
for (const peer of this.roster.values()) {
|
|
469
|
+
if (this.state !== 'on' || peer.linked) this.waiting.delete(peer.id);
|
|
470
|
+
else if (!this.waiting.has(peer.id)) this.waiting.set(peer.id, now);
|
|
471
|
+
const since = this.waiting.get(peer.id), unreachable = since !== undefined && now - since >= VOICE_GIVE_UP_MS;
|
|
472
|
+
if (unreachable !== (peer.unreachable === true)) { peer.unreachable = unreachable; moved = true; }
|
|
473
|
+
}
|
|
474
|
+
return moved;
|
|
475
|
+
}
|
|
476
|
+
/** FM8 mode 32: the peers on voice it couldn't reach on this network. */
|
|
477
|
+
get unreachable(): readonly VoicePeer[] { return [...this.roster.values()].filter(peer => peer.unreachable === true); }
|
|
478
|
+
/** FM8 mode 32's Try again: ask for the TURN list afresh, then offer again to each peer it couldn't reach
|
|
479
|
+
* (a fresh offer replaces whatever link the other side held, so this side may start it). Text chat never waited on any of it. */
|
|
480
|
+
async retryUnreachable(): Promise<void> {
|
|
481
|
+
const stuck = this.unreachable;
|
|
482
|
+
if (stuck.length === 0 || this.state !== 'on') return;
|
|
483
|
+
const session = this.session, me = this.me;
|
|
484
|
+
this.turn = null;
|
|
485
|
+
const fresh = await this.ask();
|
|
486
|
+
// voice off, or a new seat, while the list loaded: nothing of this attempt is anyone's any more
|
|
487
|
+
if (session !== this.session || me !== this.me || this.state !== 'on') return;
|
|
488
|
+
if (fresh !== null && fresh.length > 0) { this.turned = fresh; this.ice = fresh; }
|
|
489
|
+
const now = diagnosticNow();
|
|
490
|
+
for (const peer of stuck) {
|
|
491
|
+
if (this.roster.get(peer.id) !== peer) continue;
|
|
492
|
+
this.waiting.set(peer.id, now); peer.unreachable = false;
|
|
493
|
+
void this.offer(peer.id);
|
|
494
|
+
}
|
|
495
|
+
this.changed();
|
|
496
|
+
}
|
|
453
497
|
private set(state: VoiceState): void { this.state = state; this.changed(); }
|
|
454
498
|
private changed(): void { for (const listener of this.changes) listener(); }
|
|
455
499
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Scope } from '@wildshard/engine/app/scope';
|
|
2
2
|
import { diagnosticNow } from '@wildshard/engine/core/clock';
|
|
3
3
|
import { listenPage } from '@wildshard/engine/input/dom';
|
|
4
4
|
import type { ChatBox } from './chatLines';
|
|
@@ -22,7 +22,7 @@ import { voiceTalkKey, voiceTalkKeys } from '@wildshard/engine/ui/voiceSettings'
|
|
|
22
22
|
|
|
23
23
|
const CYAN = '#8fe3ff', NAVY = 'rgba(9,22,36,.86)', RED = '#ff7a7a', AMBER = '#ffc56b';
|
|
24
24
|
/** The first-time tip, the "you're on, alone" tip and the "voice off" tip go after this long. */
|
|
25
|
-
const FIRST_TIP_MS = 15_000, ALONE_TIP_MS = 5000, OFF_TIP_MS = 3000;
|
|
25
|
+
const FIRST_TIP_MS = 15_000, ALONE_TIP_MS = 5000, OFF_TIP_MS = 3000, BLOCKED_TIP_MS = 6000;
|
|
26
26
|
const CSS = `
|
|
27
27
|
#ws-voice{flex:none;position:relative;width:38px;height:38px;border-radius:50%;border:1.5px solid rgba(143,227,255,.5);background:${NAVY};color:#9fb3c8;display:grid;place-items:center;padding:0;pointer-events:auto;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation;transition:box-shadow .12s,background .2s,border-color .2s}
|
|
28
28
|
#ws-voice svg{width:20px;height:20px}
|
|
@@ -98,13 +98,19 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
98
98
|
chat.form.append(button); chat.box.append(tip, peers);
|
|
99
99
|
const touch = touchFirst(), act = (): string => touch ? 'Tap the mic' : `${voice.mode === 'hold' ? 'Hold' : 'Press'} ${voiceTalkKey()}`;
|
|
100
100
|
// the first-time tip's clock starts when the corner first shows (NaN: not yet)
|
|
101
|
-
let dismissed = '', firstUntil = voicePrefs.read().seen ? 0 : Number.NaN, aloneUntil = 0, offUntil = 0, was: VoiceState = voice.state;
|
|
101
|
+
let blockedUntil = 0, dismissed = '', firstUntil = voicePrefs.read().seen ? 0 : Number.NaN, aloneUntil = 0, offUntil = 0, was: VoiceState = voice.state;
|
|
102
102
|
const seen = (): void => { voicePrefs.write({ seen: true }); firstUntil = 0; };
|
|
103
103
|
// A press is a fresh question: whatever it leads to shows, even a tip the player closed before (a second "blocked").
|
|
104
104
|
const pressed = (): void => { seen(); dismissed = ''; voice.toggle(); };
|
|
105
105
|
scope.listen(button, 'click', event => { event.preventDefault(); pressed(); button.blur(); });
|
|
106
106
|
// V11: the key presses (toggle mode: on or off; hold mode: open while held), and its release closes a held mic wherever focus is
|
|
107
|
-
|
|
107
|
+
// FM8 32b: holding talk while voice reaches no one on voice says so (the voice-failed-blocked card); the mic still opens, so
|
|
108
|
+
// a link that comes up mid-hold carries the voice. Toggle mode's press turns voice off, which is 32's own recovery.
|
|
109
|
+
const press = (): void => {
|
|
110
|
+
seen(); dismissed = '';
|
|
111
|
+
if (voice.mode === 'hold' && voice.state === 'on' && voice.roster.size > 0 && voice.unreachable.length === voice.roster.size) blockedUntil = diagnosticNow() + BLOCKED_TIP_MS;
|
|
112
|
+
voice.press();
|
|
113
|
+
};
|
|
108
114
|
listenPage(scope, 'keydown', event => { if (voiceKey(event)) press(); }, { capture: true });
|
|
109
115
|
listenPage(scope, 'keyup', event => { if (isTalkKey(event.code)) voice.release(); }, { capture: true });
|
|
110
116
|
listenPage(scope, 'pointerdown', event => { if (event instanceof PointerEvent && event.pointerType === 'mouse' && isTalkKey(`Mouse${String(event.button)}`) && cornerShown(document.documentElement.dataset)) press(); }, { capture: true });
|
|
@@ -121,6 +127,10 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
121
127
|
if (state === 'denied') return { key: 'denied', text: deniedHelp(), tone: 'bad' };
|
|
122
128
|
if (state === 'failed') return { key: 'failed', text: 'No microphone was found. Check it is plugged in and allowed.', tone: 'bad' };
|
|
123
129
|
if (state === 'full') return { key: 'full', text: 'Voice is full here: 8 players are on it already.', tone: 'bad' };
|
|
130
|
+
// FM8 mode 32: a peer voice couldn't reach after every retry; text chat goes on, and Try again asks afresh
|
|
131
|
+
const stuck = voice.unreachable;
|
|
132
|
+
if (state === 'on' && stuck.length > 0 && now < blockedUntil) return { key: 'voice-failed-blocked', text: 'Voice can\'t connect here, so no one hears you. Text chat still works.', tone: 'bad' };
|
|
133
|
+
if (state === 'on' && stuck.length > 0) return { key: `voice-failed:${stuck.map(peer => peer.id).join(',')}`, text: `Voice couldn't connect${stuck.length === 1 ? ` to ${stuck[0]?.name ?? 'a player'}` : ` to ${String(stuck.length)} players`} on this network. Text chat still works.`, tone: 'bad' };
|
|
124
134
|
if (state === 'on') return others.length === 0 && now < aloneUntil ? { key: 'alone', text: voice.mode === 'hold' && !touch ? `You're on voice. Hold ${voiceTalkKey()} to talk.` : 'You\'re on voice. Players here hear you once they join.', tone: 'ok' } : null;
|
|
125
135
|
if (state !== 'off') return null;
|
|
126
136
|
if (now < offUntil) return { key: 'off', text: `Voice off. ${act()} to talk again.`, tone: 'ok' };
|
|
@@ -128,7 +138,7 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
128
138
|
if (now < firstUntil) return { key: 'first', text: touch ? 'Tap the mic to talk with players here.' : `${act()} (or click the mic) to talk with players here.`, tone: 'ok' };
|
|
129
139
|
return null;
|
|
130
140
|
};
|
|
131
|
-
let drawnOff: string | null = null, drawnTip: string | null = null;
|
|
141
|
+
let drawnOff: string | null = null, drawnTip: string | null = null, tipScope: Scope | null = null;
|
|
132
142
|
const chips = new Map<string, { readonly chip: HTMLButtonElement; readonly label: HTMLSpanElement; readonly action: HTMLElement }>();
|
|
133
143
|
const chipFor = (peer: VoicePeer): HTMLButtonElement => {
|
|
134
144
|
let held = chips.get(peer.id);
|
|
@@ -171,9 +181,17 @@ export function voiceUi(scope: Scope, voice: VoiceChat, chat: ChatBox): void {
|
|
|
171
181
|
tip.dataset['tone'] = shown.tone; tip.dataset['key'] = shown.key.split(':')[0] ?? shown.key;
|
|
172
182
|
const text = document.createElement('span'), close = document.createElement('button');
|
|
173
183
|
text.textContent = shown.text; close.type = 'button'; close.textContent = '×'; close.setAttribute('aria-label', 'Dismiss');
|
|
174
|
-
|
|
184
|
+
tipScope?.dispose(); tipScope = new Scope('voice-tip', scope);
|
|
185
|
+
tipScope.listen(close, 'click', () => { dismissed = shown.key; if (shown.key === 'first') seen(); render(); });
|
|
175
186
|
tip.replaceChildren(text, close);
|
|
187
|
+
if (tip.dataset['key'] === 'voice-failed' || tip.dataset['key'] === 'voice-failed-blocked') {
|
|
188
|
+
const again = document.createElement('button'); again.type = 'button'; again.textContent = 'Try again'; again.dataset['action'] = 'retry';
|
|
189
|
+
tipScope.listen(again, 'click', () => { again.disabled = true; again.textContent = 'Trying…'; void voice.retryUnreachable(); });
|
|
190
|
+
close.before(again);
|
|
191
|
+
}
|
|
176
192
|
}
|
|
193
|
+
const failmode = shown?.key.split(':')[0];
|
|
194
|
+
if (failmode === 'voice-failed' || failmode === 'voice-failed-blocked') tip.dataset['failmode'] = failmode; else delete tip.dataset['failmode'];
|
|
177
195
|
}
|
|
178
196
|
for (const id of chips.keys()) if (!voice.roster.has(id)) { chips.get(id)?.chip.remove(); chips.delete(id); }
|
|
179
197
|
peers.hidden = voice.state !== 'on' || voice.roster.size === 0;
|
|
@@ -12,10 +12,17 @@ import type { SaveStorage } from '@wildshard/engine/saves/store';
|
|
|
12
12
|
import { ServerMessageSchema, ShellMessageSchema, type ProbedRow, type ServerMessage, type ShellMessage } from '@wildshard/format/standaloneControl';
|
|
13
13
|
import { answerHeldReads, type HeldRead } from '../../../shared/host/standalone/heldReads';
|
|
14
14
|
import type { HarnessFlag, HarnessGod, HarnessHits, HarnessJoin, HarnessMove, HarnessPlace } from '../../../shared/host/standalone/harnessPlace';
|
|
15
|
-
import type { DevBox, DevCollidersMessage } from '@wildshard/engine/game/devColliders';
|
|
15
|
+
import type { DevBox, DevCollidersMessage, DevGround, DevGroundMessage } from '@wildshard/engine/game/devColliders';
|
|
16
|
+
import { isDevRestart, type DevGameplay, type DevPlace, type DevRestarted, type DevRestartMessage } from '@wildshard/engine/game/devGameplay';
|
|
16
17
|
import type { ServerWorkerStart } from '../../../server/host/standalone/serverRuntime';
|
|
17
18
|
import { WorkerLoopback } from '../../../shared/host/standalone/workerLoopback';
|
|
18
19
|
|
|
20
|
+
declare global { interface Window {
|
|
21
|
+
/** SHARD-SOURCE AP18 (DEVSERVER): the dev hook's ground for the in-page server */ __workerClientDevGround?: (ground: DevGround) => void;
|
|
22
|
+
/** SHARD-SOURCE AP19 (DEVSERVER): the dev hook's soft restart of the in-page server, on a new link this page's client rejoins */
|
|
23
|
+
__workerClientDevRestart?: (gameplay: DevGameplay, at: DevPlace | null) => Promise<DevRestarted>;
|
|
24
|
+
} }
|
|
25
|
+
|
|
19
26
|
/** What the server should run and where the page keeps saves. */
|
|
20
27
|
export interface StandaloneConfig {
|
|
21
28
|
readonly slug: string;
|
|
@@ -69,6 +76,8 @@ export interface StandaloneShell {
|
|
|
69
76
|
join: (id: string, x: number, y: number, z: number) => { readonly client: NetClient; readonly move: (x: number, y: number, z: number) => void };
|
|
70
77
|
/** SHARD-SOURCE AP5: a watched part's solid boxes for the server's world (DEVSERVER pages only; elsewhere it does nothing). */
|
|
71
78
|
devColliders: (name: string, boxes: readonly DevBox[]) => void;
|
|
79
|
+
/** SHARD-SOURCE AP19: restart the in-page server's world on new gameplay rows, its player at `at`; this client rejoins it (DEVSERVER pages only). */
|
|
80
|
+
devRestart: (gameplay: DevGameplay, at: DevPlace | null) => Promise<DevRestarted>;
|
|
72
81
|
dispose: () => void;
|
|
73
82
|
}
|
|
74
83
|
|
|
@@ -76,6 +85,8 @@ function applyWrite(storage: SaveStorage, key: string, value: string | null): bo
|
|
|
76
85
|
try { if (value === null) storage.removeItem(key); else storage.setItem(key, value); return true; } catch { return false; }
|
|
77
86
|
}
|
|
78
87
|
|
|
88
|
+
/** AP19: how long the page waits for the in-page server's answer to a soft restart before it counts as refused. */
|
|
89
|
+
const DEV_RESTART_TIMEOUT_MS = 20_000;
|
|
79
90
|
const SaveDocument = v.object({ keys: v.record(v.string(), v.unknown()), reset: v.optional(v.number()) });
|
|
80
91
|
/** Apply only entries the worker changed since its last document. The page owns discovery and cosmetic wear;
|
|
81
92
|
* a server pack/pending-drop write must leave those newer entries standing. Resets still replace the document. */
|
|
@@ -129,6 +140,30 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
|
|
|
129
140
|
const visibility = (): void => { if (!held) post({ kind: document.visibilityState === 'hidden' ? 'pause' : 'resume' }); };
|
|
130
141
|
const scope = new Scope('standalone.shell');
|
|
131
142
|
if (typeof document !== 'undefined') scope.listen(document, 'visibilitychange', visibility);
|
|
143
|
+
// SHARD-SOURCE AP18: `wildshard watch`'s ground for this server, from the page's dev hook (DEVSERVER pages only)
|
|
144
|
+
if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__ && harness !== undefined && typeof window !== 'undefined')
|
|
145
|
+
scope.expose(window, '__workerClientDevGround', (ground: DevGround) => { harness.postMessage({ wildshardDevGround: ground } satisfies DevGroundMessage, []); });
|
|
146
|
+
// SHARD-SOURCE AP19: the soft restart. The server takes a new link with the restart; this page's client rejoins on it at once
|
|
147
|
+
// (its hello waits in the port until the new world listens), as an online page does when its server comes back.
|
|
148
|
+
// One at a time, and only a message the worker takes: anything else answers `ok: false` before the client leaves its link, so
|
|
149
|
+
// the page reloads instead of sitting on a link nothing serves. A worker that never answers counts as a refusal too.
|
|
150
|
+
let restarting = false;
|
|
151
|
+
const devRestart = (gameplay: DevGameplay, at: DevPlace | null): Promise<DevRestarted> => new Promise<DevRestarted>(resolve => {
|
|
152
|
+
if (!(typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__) || harness === undefined) { resolve({ ok: false, ms: 0, reason: 'not a DEVSERVER page with an in-page server' }); return; }
|
|
153
|
+
const message: DevRestartMessage = { wildshardDevRestart: gameplay, at };
|
|
154
|
+
if (!isDevRestart(message)) { resolve({ ok: false, ms: 0, reason: 'the worker takes only the dev gameplay sections and a finite place' }); return; }
|
|
155
|
+
if (restarting) { resolve({ ok: false, ms: 0, reason: 'a restart is already running' }); return; }
|
|
156
|
+
restarting = true;
|
|
157
|
+
const line = new MessageChannel(), reply = new MessageChannel(), waiting: { timer?: ReturnType<typeof scope.timeout> } = {};
|
|
158
|
+
const settle = (answer: DevRestarted): void => { if (!restarting) return; restarting = false; scope.cancelTimer(waiting.timer); reply.port1.close(); resolve(answer); };
|
|
159
|
+
waiting.timer = scope.timeout(DEV_RESTART_TIMEOUT_MS, () => { settle({ ok: false, ms: DEV_RESTART_TIMEOUT_MS, reason: 'the in-page server did not answer the restart' }); });
|
|
160
|
+
reply.port1.onmessage = (event: MessageEvent<DevRestarted>): void => { settle(event.data); };
|
|
161
|
+
const link = new WorkerLoopback(line.port1);
|
|
162
|
+
link.onClose(reason => { if (reason === 'reload') config.refused?.(); });
|
|
163
|
+
client.rejoin(link);
|
|
164
|
+
harness.postMessage(message, [line.port2, reply.port2]);
|
|
165
|
+
});
|
|
166
|
+
if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__ && harness !== undefined && typeof window !== 'undefined') scope.expose(window, '__workerClientDevRestart', devRestart);
|
|
132
167
|
post({ kind: 'boot', slug: config.slug, base: config.base, build: config.serverBuild ?? config.build, savePrefix: config.savePrefix, saves: documents, ...(config.lone === true ? { lone: true } : {}) });
|
|
133
168
|
return { client, transport, booted: bootPromise,
|
|
134
169
|
ready: () => { post({ kind: 'ready' }); }, pause: () => { post({ kind: 'pause' }); }, resume: () => { post({ kind: 'resume' }); },
|
|
@@ -140,6 +175,7 @@ export function connectStandalone(config: StandaloneConfig, control: MessagePort
|
|
|
140
175
|
bossGod: () => { harness?.postMessage({ god: true } satisfies HarnessGod, []); },
|
|
141
176
|
raise: flag => { harness?.postMessage({ flag } satisfies HarnessFlag, []); },
|
|
142
177
|
devColliders: (name, boxes) => { if (typeof __DEVSERVER__ === 'boolean' && __DEVSERVER__) harness?.postMessage({ wildshardDevColliders: name, boxes } satisfies DevCollidersMessage, []); },
|
|
178
|
+
devRestart,
|
|
143
179
|
join: (id, x, y, z) => {
|
|
144
180
|
const line = new MessageChannel(), second = new NetClient(new WorkerLoopback(line.port1));
|
|
145
181
|
harness?.postMessage({ join: id, x, y, z } satisfies HarnessJoin, [line.port2]);
|
|
@@ -25,7 +25,7 @@ import type { SimCommand, SimExternalPlayer, SimHost, SimPlayerBody, SimPlayerDr
|
|
|
25
25
|
/** The world-space command a tick's input means. */
|
|
26
26
|
/** Developer boost is a Developer page's, on its own server: a standalone worker says so at boot, and any other host ignores the button. */
|
|
27
27
|
let developerBoost = false;
|
|
28
|
-
export function allowDeveloperBoost(): void { developerBoost =
|
|
28
|
+
export function allowDeveloperBoost(on = true): void { developerBoost = on; }
|
|
29
29
|
export function simCommandOf(input: SimTickCommand): SimCommand { return 'seq' in input ? netSimCommand(input) : input; }
|
|
30
30
|
/** A board whose "riding near the ride height" is the fall's ground. */
|
|
31
31
|
function boardOn(fall: { grounded: boolean }): BoardState & { on: boolean } {
|
|
@@ -9,7 +9,7 @@ import { mountedPlayerOf } from '@wildshard/engine/game/riding/native';
|
|
|
9
9
|
import type { GridAssembly, GridCell, GridPoint } from '../../../shared/game/grid/assembly';
|
|
10
10
|
import type { ResidencyAllocator } from '../../../shared/game/grid/allocator';
|
|
11
11
|
import { GridContinuationCache, GRID_CONTINUATION_CACHE_BYTES } from '../../../shared/game/grid/continuations';
|
|
12
|
-
import {
|
|
12
|
+
import { gridBoardLimitAt } from '../../../shared/game/grid/rules';
|
|
13
13
|
import { leadPlayer } from '@wildshard/engine/sim/leadPlayer';
|
|
14
14
|
|
|
15
15
|
/** Admission returns one owned, renderer-free regional host; its world is always in authored local coordinates. */
|
|
@@ -327,10 +327,7 @@ export class GridSimulation {
|
|
|
327
327
|
/** A seat's board cap, read in world space from wherever it stands: a resident host's feet are its cell's (P1-E5.3-A10). */
|
|
328
328
|
private boardLimit(player: string): number {
|
|
329
329
|
const site = this.current(player), seat = this.seat(this.hostAt(site), player), { assembly } = this;
|
|
330
|
-
|
|
331
|
-
const p = assembly.pitch, cx = Math.round(feet.x / p), cz = Math.round(feet.z / p), cell = assembly.cells.find(row => row.cell[0] === cx && row.cell[1] === cz);
|
|
332
|
-
return gridBoardLimit({ local: { x: feet.x - cx * p, y: feet.y, z: feet.z - cz * p }, shardCap: 14, onHighwayDeck: feet.y < 4,
|
|
333
|
-
speedClass: cell?.speedClass ?? 'shard' });
|
|
330
|
+
return gridBoardLimitAt(assembly, site === null ? seat.position : assembly.world(seat.position, assembly.cell(site)));
|
|
334
331
|
}
|
|
335
332
|
/** The empty seat a player takes on arrival. The lead's is always there; anyone else's is made for them. */
|
|
336
333
|
private arrivalSeat(host: SimHost, player: string, traveller: PlayerSim): PlayerSim {
|
|
@@ -345,7 +342,7 @@ export class GridSimulation {
|
|
|
345
342
|
/** One tick for every world with a player in it: each player's command goes to the host it stands in. */
|
|
346
343
|
stepAll(commands?: ReadonlyMap<string, SimTickCommand>): void {
|
|
347
344
|
if (this.disposed) throw new Error('Grid simulation is disposed');
|
|
348
|
-
|
|
345
|
+
this.capBoards();
|
|
349
346
|
const sites = new Set(this.sites.values());
|
|
350
347
|
for (const site of sites) {
|
|
351
348
|
const host = this.hostAt(site); this.ports.beforeMove?.(site, host);
|
|
@@ -358,8 +355,17 @@ export class GridSimulation {
|
|
|
358
355
|
/** One tick of one world, for a room stepping its own (`stepAll` does every world). */
|
|
359
356
|
stepSite(site: string | null, commands: ReadonlyMap<string, SimTickCommand>): void {
|
|
360
357
|
if (this.disposed) throw new Error('Grid simulation is disposed');
|
|
358
|
+
this.capBoards(site);
|
|
361
359
|
const host = this.hostAt(site); this.ports.beforeMove?.(site, host); host.step(commands);
|
|
362
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Every seat's board takes the page's grid cap (`boardLimit`) before its world steps, by whichever path steps it. QA 11-15 row 8:
|
|
363
|
+
* only `stepAll` installed it, so the in-page server's rooms (`stepSite`, and a cell world stepping itself) ran 14 m/s on the road
|
|
364
|
+
* and 56 boosted against the page's 30 and 60 (now 120). `site` limits it to that world's seats.
|
|
365
|
+
*/
|
|
366
|
+
capBoards(site?: string | null): void {
|
|
367
|
+
for (const [player, at] of this.sites) if (site === undefined || at === site) this.seat(this.hostAt(at), player).hoverSpeedLimit ??= () => this.boardLimit(player);
|
|
368
|
+
}
|
|
363
369
|
/** Every world with a player in it. */
|
|
364
370
|
occupiedSites(): ReadonlySet<string | null> { return new Set(this.sites.values()); }
|
|
365
371
|
/** Global render pose is derived from local feet and the current frame, never saved into an authored host. */
|
|
@@ -21,7 +21,7 @@ export const eliteSkinFlag = (id: string): string => `elite.${id}.skin`;
|
|
|
21
21
|
*
|
|
22
22
|
* SERVER-CELLS SC10 (J328): a served world is never rebuilt, so there the skin is each player's own: a kill lays the orb out while a
|
|
23
23
|
* player present has not taken it, a press takes it for the presser (a flag in their own book, which goes with their save), and an
|
|
24
|
-
* owner's press is refused. The lair's world record (`skinTaken`) is a page's or a tape's alone.
|
|
24
|
+
* owner's press is refused. The orb stays until every player present has taken theirs. The lair's world record (`skinTaken`) is a page's or a tape's alone.
|
|
25
25
|
*/
|
|
26
26
|
export function eliteDrops<S extends EliteCoreScript<Body>>(host: SimHost): { readonly hooks: EliteCoreHooks<S>; readonly bind: (core: EliteCore<S>) => void } {
|
|
27
27
|
const routes = actRoutes(host);
|
|
@@ -35,10 +35,14 @@ export function eliteDrops<S extends EliteCoreScript<Body>>(host: SimHost): { re
|
|
|
35
35
|
entry.drop = { x: at.x, y: at.y + ITEM_PICKUP_HOVER, z: at.z };
|
|
36
36
|
routes.claims.set(`${def.id}.reward`, player => {
|
|
37
37
|
const feet = host.players.get(player)?.position, { drop } = entry;
|
|
38
|
-
if (feet === undefined || drop === null
|
|
38
|
+
if (feet === undefined || drop === null) return;
|
|
39
|
+
// an owner's press takes nothing; once nobody present lacks the skin, it clears the orb (review SHOULD: no orb left standing)
|
|
40
|
+
if (served && owns(player, def.id)) { if (!lacking(def.id)) entry.drop = null; return; }
|
|
39
41
|
if (pickPrompt([{ position: { x: drop.x, y: drop.y + PROMPT_ABOVE, z: drop.z }, radius: PROMPT_RADIUS }], { x: feet.x, y: feet.y + REACH_EYE, z: feet.z }, host.physics) === undefined) return;
|
|
42
|
+
// SC10 review: in a served world the orb stays while anyone present still lacks the skin, so the first press takes it for the
|
|
43
|
+
// presser only, not for everyone who shared the kill
|
|
44
|
+
if (served) { questBooks(host).of(player).flags.set(eliteSkinFlag(def.id)); if (!lacking(def.id)) entry.drop = null; return; }
|
|
40
45
|
entry.drop = null;
|
|
41
|
-
if (served) { questBooks(host).of(player).flags.set(eliteSkinFlag(def.id)); return; }
|
|
42
46
|
const saved = core?.record(def.id);
|
|
43
47
|
if (saved !== undefined) saved.skinTaken = true;
|
|
44
48
|
core?.save();
|
|
@@ -46,6 +46,8 @@ export interface NativeTamingControls {
|
|
|
46
46
|
readonly press: (id: string, press: NativeTamingPress) => void;
|
|
47
47
|
/** A player's own session, once they have one. */
|
|
48
48
|
readonly sessionOf: (id: string) => NativeTamingOwner | undefined;
|
|
49
|
+
/** SC10 review: this player's seat emptied (a served world's lead seat, parked): its bonded horses go and its session starts wild. */
|
|
50
|
+
readonly release: (id: string) => void;
|
|
49
51
|
}
|
|
50
52
|
export interface NativeTamingOwner {
|
|
51
53
|
readonly scope: SimHost['scope'];
|
|
@@ -161,7 +163,9 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
|
|
|
161
163
|
};
|
|
162
164
|
const originalUpdate = law.update.bind(law);
|
|
163
165
|
const session: TamingSeat = { player, law, get shake() { return shake; }, get roll() { return roll; }, holdOffer: held => { heldOffer = held; },
|
|
164
|
-
|
|
166
|
+
// SC10 review: a bonded horse is a mountable too (`addMountable` on adoption); it leaves the mounted owner's rows before it retires,
|
|
167
|
+
// or the next mounted step finds its pose with no body ("Missing mounted pose actor") and fails the worker
|
|
168
|
+
release: () => { for (const id of mine) { const a = poseRows.find(row => row.entityId === id); if (a === undefined) { mine.delete(id); continue; } if (mounted.mountables.includes(a)) mounted.removeMountable(id); retireBonded(a); } }, whistle: () => {
|
|
165
169
|
const horse = law.companion;
|
|
166
170
|
if (!mounted.mounted && horse !== null && horse.mem['whistle'] === 1 && mounted.canRide(horse.entityId) && horse.position.distanceTo(player.position) < 150) calling = 30;
|
|
167
171
|
}, tick: (dt, read) => {
|
|
@@ -202,6 +206,8 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
|
|
|
202
206
|
sessions.set(player.id, session); return session;
|
|
203
207
|
};
|
|
204
208
|
const first = sessionFor(firstSeat.player), { law } = first;
|
|
209
|
+
// SC10 review: the lead seat's session as a fresh world gives it, for when its player leaves a served world (the seat is parked)
|
|
210
|
+
const fresh = first.save();
|
|
205
211
|
const others = (): TamingSeat[] => [...sessions.values()].filter(session => session !== first);
|
|
206
212
|
host.events.on('creature.signal', ({ name, x, z }) => { for (const session of sessions.values()) session.law.noteEvent(name, x, z); }, host.scope);
|
|
207
213
|
host.events.on('weapon.impact', ({ point }) => {
|
|
@@ -264,7 +270,12 @@ export function installNativeTaming(host: SimHost, context: NativeTamingContext,
|
|
|
264
270
|
},
|
|
265
271
|
}, 'afterBodies');
|
|
266
272
|
host.scope.onDispose(() => { for (let i = 0; i < 64; i++) { const actor = poseRows[i]; if (actor === undefined) break; poses.delete(actor.entityId); } poseRows.length = 0; installed.delete(host); });
|
|
267
|
-
controls.set(host, { sessionOf: id => sessions.get(id)?.law,
|
|
273
|
+
controls.set(host, { sessionOf: id => sessions.get(id)?.law, release: id => {
|
|
274
|
+
// an emptied seat keeps no one's taming: its horses go as any leaver's do, and the lead's own session starts wild again
|
|
275
|
+
const session = sessions.get(id); if (session === undefined) return;
|
|
276
|
+
session.release(); pending.delete(id);
|
|
277
|
+
if (session === first) first.load(fresh, []); else sessions.delete(id);
|
|
278
|
+
}, press: (id, press) => {
|
|
268
279
|
if (!host.players.has(id)) throw new RangeError(`Unknown taming player ${id}`);
|
|
269
280
|
pending.set(id, { ...pending.get(id), ...press });
|
|
270
281
|
} });
|
|
@@ -17,6 +17,7 @@ import { openRoad } from '../standalone/roadWorld';
|
|
|
17
17
|
import type { HeadlessRuntimeInput } from '../headlessRuntime';
|
|
18
18
|
import type { CellOrder, WorkerNews, WorkerReading, WorkerResident } from './cellProtocol';
|
|
19
19
|
import { SeatTransport } from './socketPump';
|
|
20
|
+
import { allowDeveloperBoost } from '@wildshard/engine/sim/playerSim';
|
|
20
21
|
|
|
21
22
|
/** How often a worker reads itself (E7.8). */
|
|
22
23
|
export const READING_MS = 10_000;
|
|
@@ -62,6 +63,8 @@ export interface CellHostOptions {
|
|
|
62
63
|
readonly booted?: (slug: string, room: DedicatedRoom) => void;
|
|
63
64
|
readonly roaded?: (road: RoadRoom) => void;
|
|
64
65
|
readonly playtest?:boolean;
|
|
66
|
+
/** QA 11-15 row 8 (G540): honour a Developer page's boost bit (on unless `WORLD_BOOST=off`, `cellWorker.ts`). */
|
|
67
|
+
readonly developerBoost?: boolean;
|
|
65
68
|
/**
|
|
66
69
|
* GC15 (`WORLD_CROSSING=worker`): the grid pack's road strips. Given, this worker hosts the road between its cells, each of its grid
|
|
67
70
|
* cells opens onto it instead of standing in lone walls, and a seat walks cell, road, cell on one socket. Left out, or no strips, every cell is lone.
|
|
@@ -82,8 +85,14 @@ function installCellIdentity(): void {
|
|
|
82
85
|
|
|
83
86
|
/** Run one worker's cells until it is told to close. Anything that ends it says `failed`, and the process ends (Q77). */
|
|
84
87
|
export function runCells(port: CellPort, options: CellHostOptions): { dispose: () => void } {
|
|
88
|
+
// QA 11-15 row 8 (G540: Developer boost "everywhere"): a Developer page's boost bit moves its board here too, to the shared speed
|
|
89
|
+
// law's 56 m/s in a shard and 120 on the road (4x, Jake 11-15), so the page's prediction and this authority agree. Replaces E7.7's "never installed";
|
|
90
|
+
// `WORLD_BOOST=off` on a box turns it back off. The server can't tell a Developer page from another, so this trusts the bit.
|
|
91
|
+
allowDeveloperBoost(options.developerBoost !== false);
|
|
85
92
|
const scope = new Scope('dedicated.worker'), started = diagnosticNow(), cells = new Map<string, Cell>();
|
|
86
93
|
let clock: ServerClock | undefined, disposed = false, ready = false, ticks: number[] = [], ticked = 0, readAt = started, dropsAt = 0;
|
|
94
|
+
/** SC8: each awake cell's own tick time since the last reading (ms summed, ticks counted), so a bench can weigh cells by awake cost. */
|
|
95
|
+
let spent = new Map<string, { ms: number; ticks: number }>();
|
|
87
96
|
const post = (news: WorkerNews): void => { port.postMessage(news); };
|
|
88
97
|
const fail = (error: unknown): void => { clock?.pause(); post({ kind: 'failed', reason: error instanceof Error ? error.message : String(error) }); };
|
|
89
98
|
// GC15: the road this worker hosts, once its cells are open, and what its cells need of it.
|
|
@@ -144,7 +153,16 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
144
153
|
};
|
|
145
154
|
const step = (): void => {
|
|
146
155
|
const begun = diagnosticNow();
|
|
147
|
-
try {
|
|
156
|
+
try {
|
|
157
|
+
for (const { slug, room } of cells.values()) {
|
|
158
|
+
if (room.taken === 0) continue;
|
|
159
|
+
const at = diagnosticNow();
|
|
160
|
+
room.tick();
|
|
161
|
+
const own = spent.get(slug) ?? { ms: 0, ticks: 0 };
|
|
162
|
+
own.ms += diagnosticNow() - at; own.ticks++; spent.set(slug, own);
|
|
163
|
+
}
|
|
164
|
+
if (road !== undefined && road.taken > 0) road.tick();
|
|
165
|
+
} catch (error) { fail(error); return; }
|
|
148
166
|
ticks.push(diagnosticNow() - begun); ticked++;
|
|
149
167
|
if (ticks.length > TICKS_KEPT) ticks.shift();
|
|
150
168
|
};
|
|
@@ -156,8 +174,9 @@ export function runCells(port: CellPort, options: CellHostOptions): { dispose: (
|
|
|
156
174
|
const row: WorkerReading = { cells: rooms.length, awake: rooms.filter(room => room.taken > 0).length, players: sum(room => room.taken - room.holding) + onRoad, held: sum(room => room.holding) + heldOnRoad, ticks: ticked, ticksPerSecond: ticks.length / ((now - readAt) / 1000),
|
|
157
175
|
p50: percentile(sorted, 0.5), p95: percentile(sorted, 0.95), p99: percentile(sorted, 0.99), max: sorted.at(-1) ?? 0, drops: (clock?.drops ?? 0) - dropsAt, rss: memory.rss, heap: memory.heapUsed,
|
|
158
176
|
refused: sum(room => room.net.stats.refused), dropped: sum(room => room.net.stats.dropped), frameBytes: sum(room => room.net.stats.frameBytes), eventBytes: sum(room => room.net.stats.eventBytes),
|
|
177
|
+
...(spent.size === 0 ? {} : { cellMs: Object.fromEntries([...spent].map(([slug, own]) => [slug, own.ms / own.ticks])) }),
|
|
159
178
|
...(memory.external === undefined ? {} : { external: memory.external }), ...(memory.arrayBuffers === undefined ? {} : { arrayBuffers: memory.arrayBuffers }), ...(options.lag === undefined ? {} : { lag: options.lag() }) };
|
|
160
|
-
readAt = now; dropsAt = clock?.drops ?? 0; ticks = [];
|
|
179
|
+
readAt = now; dropsAt = clock?.drops ?? 0; ticks = []; spent = new Map();
|
|
161
180
|
post({ kind: 'reading', reading: row });
|
|
162
181
|
};
|
|
163
182
|
/** One start-over at a time on this worker: each boot stalls the clock of every other cell here, so they never pile up. */
|