@wildshard/engine 0.1.17 → 0.1.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/lint/engine-sides.json +7 -0
  3. package/lint/host-callback-syntax.mjs +2 -1
  4. package/lint/host-callbacks.mjs +3 -3
  5. package/lint/host-files.mjs +5 -4
  6. package/lint/no-base64.mjs +3 -1
  7. package/lint/shard-imports.mjs +6 -7
  8. package/lint/shard-source.d.mts +9 -0
  9. package/lint/shard-source.mjs +91 -0
  10. package/lint/shardfile-boundaries.mjs +10 -8
  11. package/lint/sim-closure.mjs +6 -3
  12. package/lint/wildshard-plugin.d.ts +4 -0
  13. package/lint/wildshard-plugin.js +22 -23
  14. package/package.json +9 -2
  15. package/scripts/app-build/outputProducts.d.mts +3 -0
  16. package/scripts/app-build/outputProducts.mjs +31 -0
  17. package/scripts/app-build-pipeline.mjs +3 -0
  18. package/scripts/check-devserver.mjs +1 -1
  19. package/scripts/chromium-keychain-check.mjs +4 -2
  20. package/scripts/chromium-keychain.mjs +3 -1
  21. package/scripts/cook.mjs +7 -3
  22. package/scripts/devices.d.mts +4 -0
  23. package/scripts/devices.mjs +39 -0
  24. package/scripts/devserver-client.d.mts +4 -2
  25. package/scripts/devserver-client.mjs +25 -8
  26. package/scripts/doctor-proof.mjs +1 -1
  27. package/scripts/e2e-faults.mjs +159 -0
  28. package/scripts/grid-crossing-walk-proof.mjs +14 -3
  29. package/scripts/memory-proof.mjs +158 -0
  30. package/scripts/offline-proof-rules.d.mts +4 -2
  31. package/scripts/offline-proof-rules.mjs +21 -5
  32. package/scripts/offline-proof.mjs +15 -6
  33. package/scripts/tier-textures-proof.mjs +101 -0
  34. package/scripts/tier-textures.mjs +60 -0
  35. package/scripts/tsconfig.json +1 -0
  36. package/scripts/vps/wildshard-config +79 -23
  37. package/scripts/worker-client-play.mjs +1 -0
  38. package/scripts/worker-client-proof.mjs +1 -1
  39. package/scripts/worker-client-slug.mjs +44 -0
  40. package/src/client/app/entry.ts +37 -10
  41. package/src/client/engine/boot/parsedPages.ts +127 -58
  42. package/src/client/engine/build.d.ts +2 -0
  43. package/src/client/engine/core/Game.ts +18 -0
  44. package/src/client/engine/core/bootstrap.ts +4 -1
  45. package/src/client/engine/debug/probe.ts +18 -1
  46. package/src/client/engine/fx/LightPool.ts +41 -1
  47. package/src/client/engine/pwa/sw.js +12 -3
  48. package/src/client/engine/render/precompile.ts +20 -14
  49. package/src/client/engine/telemetry/browserErrors.ts +4 -1
  50. package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
  51. package/src/client/game/boot/audio.generated.ts +0 -102
  52. package/src/client/game/boot/bytes.generated.ts +42 -60
  53. package/src/client/game/boot/versions.generated.ts +0 -2
  54. package/src/client/game/grid/area.ts +38 -0
  55. package/src/client/game/grid/live.ts +28 -2
  56. package/src/client/game/grid/liveSession.ts +14 -3
  57. package/src/client/game/grid/menu.ts +4 -0
  58. package/src/client/game/grid/neighbourPanels.ts +10 -1
  59. package/src/client/game/grid/placedCards.ts +55 -0
  60. package/src/client/game/grid/placedCells.ts +131 -0
  61. package/src/client/game/grid/regionalRuntime.ts +6 -0
  62. package/src/client/game/grid/regionalWorld.ts +15 -2
  63. package/src/client/game/grid/roadCull.ts +44 -14
  64. package/src/client/game/grid/roadTileBacking.ts +13 -3
  65. package/src/client/game/grid/session.ts +9 -0
  66. package/src/client/game/grid/shardfileFar.ts +9 -3
  67. package/src/client/game/session/finish.ts +5 -1
  68. package/src/client/game/shard/titleList.ts +6 -2
  69. package/src/client/game/shardfile/clientWorker.ts +2 -1
  70. package/src/client/game/titleDeck.ts +4 -3
  71. package/src/client/host/online/shell.ts +14 -0
  72. package/src/cook/game/shardCook.ts +38 -8
  73. package/src/cook/game/tierTextures.ts +276 -0
  74. package/src/e2e/smoke/game.ts +19 -14
  75. package/src/e2e/smoke/page-globals.d.ts +9 -8
  76. package/src/e2e/smoke/template2.spec.ts +8 -7
  77. package/src/server/host/dedicated/placementFile.ts +1 -17
  78. package/src/server/host/dedicated/socketTransport.ts +2 -1
  79. package/src/server/host/dedicated/world.ts +30 -1
  80. package/src/shared/engine/net/deviceWord.ts +138 -0
  81. package/src/shared/engine/net/socketFrames.ts +7 -4
  82. package/src/shared/game/grid/catalogueSlot.ts +7 -0
  83. package/src/shared/game/grid/placementRows.ts +33 -0
@@ -5,6 +5,7 @@ import { app } from '../app/runtime';
5
5
  import type * as THREE from 'three';
6
6
  import { Game } from './Game';
7
7
  import { applyLevelTier, TIER } from './tier';
8
+ import { noteDeviceGpu } from '../telemetry/deviceSnapshot';
8
9
  import { readyWebGLContext } from './webglStartup';
9
10
  import { recordBootCheckpoint } from '../boot/bootTrace';
10
11
  import { issueBakedPrograms } from '../boot/earlyPrograms';
@@ -74,7 +75,9 @@ export async function bootstrap(step: StepRunner, level: LevelSpec, inputContext
74
75
  progress.detail('Waiting for graphics to recover');
75
76
  recordBootCheckpoint('renderer:waiting', { ...state });
76
77
  });
77
- return new Game(canvas, context, level);
78
+ const made = new Game(canvas, context, level);
79
+ noteDeviceGpu(context); // DEVICE-TELEMETRY DT1: the game's own context names its GPU for the device snapshot
80
+ return made;
78
81
  });
79
82
  game.app.clock.setCapture(harnessPins()?.capture ?? null);
80
83
  issueBakedPrograms(game); // DL10 (Debug 'Early shader compile'): a queued list of the level's entry programs starts linking
@@ -123,8 +123,22 @@ export interface Fingerprint {
123
123
  facade?: { multiDraw: boolean; batches: number; instances: number };
124
124
  playMs: number; heapMB: number;
125
125
  }
126
+ /** A door or gate panel the area declares: drawn, and whether its colliders stand. */
127
+ export interface ProbeAreaTarget { readonly panel: string; readonly visible: boolean; readonly solid: boolean }
128
+ /** T2E-1b: the area the player is in. On a grid page that is the current cell, not the page shell (`platform.grid`). */
129
+ export interface ProbeArea {
130
+ /** the area's shard slug */
131
+ readonly slug: string;
132
+ /** the grid cell's instance; null on a one-shard page */
133
+ readonly instance: string | null;
134
+ readonly targets: readonly ProbeAreaTarget[];
135
+ /** every quest flag the player holds in this area, sorted */
136
+ readonly flags: readonly string[];
137
+ }
126
138
  export interface ProbeDeps {
127
139
  health: () => number; quest: () => unknown;
140
+ /** The area the player is in; null between areas (a grid page's road). */
141
+ area: () => ProbeArea | null;
128
142
  /** The retained level world used for leak counts when active frame worlds can be replaced and freed. */
129
143
  leakPhysics?: World['physics'];
130
144
  }
@@ -162,6 +176,8 @@ export interface EngineProbe<W extends ProbeWorld = ProbeWorld> {
162
176
  hold: (animal: CombatTarget, on: boolean) => void; hits: { kind: string; amount: number }[]; kills: string[] };
163
177
  arena: () => void;
164
178
  state: () => GameplayState;
179
+ /** T2E-1b: the area the player is in, with its door targets and quest flags; null between areas. */
180
+ area: () => ProbeArea | null;
165
181
  onResume: (fn: () => void) => void;
166
182
  saves: Saves;
167
183
  sounds: () => SoundLog;
@@ -510,6 +526,7 @@ export function installProbe<W extends ProbeWorld>(world: W, deps: ProbeDeps): E
510
526
  creatures: world.animals.animals.map((a, i) => ({ id: `${a.kind}:${i}`, kind: a.kind, pos: point(a.position), hp: a.hp, brain: a.state })).sort((a, b) => a.id.localeCompare(b.id)),
511
527
  quest: { adventure: deps.quest(), level: authoredQuestFlags(world) },
512
528
  }),
529
+ area: () => deps.area(),
513
530
  onResume: (fn) => { requireHarness(); resume = fn; }, saves,
514
531
  sounds: () => { const log = { event: events, ambient: [...ambient].sort() }; events = {}; ambient.clear(); return log; },
515
532
  used: () => labels.splice(0),
@@ -545,7 +562,7 @@ function scopedProbe<W extends ProbeWorld>(source: EngineProbe<W>, scope: Scope)
545
562
  get app() { return read().app; },
546
563
  fingerprint: () => read().fingerprint(), pose: (value) => read().pose(value),
547
564
  walkLeg: (leg) => read().walkLeg(leg), arena: () => { read().arena(); },
548
- state: () => read().state(), onResume: (fn) => { read().onResume(fn); },
565
+ state: () => read().state(), area: () => read().area(), onResume: (fn) => { read().onResume(fn); },
549
566
  sounds: () => read().sounds(), used: () => read().used(), budgets: (poses) => read().budgets(poses),
550
567
  leak: async () => {
551
568
  if (live === undefined) {
@@ -57,6 +57,8 @@ export class LightPool {
57
57
  private readonly yielding = new Set<THREE.PointLight>();
58
58
  /** A borrowed light and the yielding light whose place in the scene it holds. */
59
59
  private readonly lent = new Map<THREE.PointLight, THREE.PointLight>();
60
+ /** RP4: this nested pool's scene lights taken out of three's count (`adopt`), with the layer mask each gets back */
61
+ private readonly adopted = new Map<THREE.PointLight, number>();
60
62
 
61
63
  private constructor(scene: THREE.Scene) {
62
64
  this.group.name = 'light-pool';
@@ -87,7 +89,31 @@ export class LightPool {
87
89
  if (page === this) throw new Error('A light pool cannot mirror into itself');
88
90
  this.mirroredBy = page; page.sources.add(this);
89
91
  for (const light of this.lights) light.layers.disableAll();
90
- scope.onDispose(() => { page.sources.delete(this); if (this.mirroredBy === page) this.mirroredBy = null; for (const light of this.lights) light.layers.enable(0); });
92
+ scope.onDispose(() => {
93
+ page.sources.delete(this); if (this.mirroredBy === page) this.mirroredBy = null; for (const light of this.lights) light.layers.enable(0);
94
+ for (const [light, mask] of this.adopted) light.layers.mask = mask;
95
+ this.adopted.clear();
96
+ });
97
+ }
98
+
99
+ /** RP4: a mirrored pool also takes the plain point lights its content put under `root` (a region's site and signal
100
+ * lights, `new PointLight` in its own tree): each leaves three's light count and shows through the page's reserved
101
+ * lights as a pooled one does, while it and its ancestors show. Only as many as the reserve can show alongside this
102
+ * pool's own lights; a shadow caster, or one past that, stays counted as before, and so does one that finds the shared
103
+ * reserve full when it shows (another region's lights took it: `showMirrors` gives it back to three's count). Again on the same root takes only new
104
+ * ones. Returns how many it took. Sunscar's two counted whenever its region showed: arriving moved the page from 6 to
105
+ * 7 and 8 point lights and every lit program in view linked again (Chromium, 117 to 216 ms a link). */
106
+ adopt(root: THREE.Object3D): number {
107
+ const page = this.mirroredBy;
108
+ if (page === null) return 0;
109
+ let taken = 0;
110
+ for (const light of this.adopted.keys()) if (light.parent === null) this.adopted.delete(light); // gone with its content
111
+ root.traverse(object => {
112
+ if (!(object instanceof THREE.PointLight) || object.castShadow || object.layers.mask === 0 || this.adopted.has(object)) return;
113
+ if (this.lights.length + this.adopted.size >= page.reserved.length) return;
114
+ this.adopted.set(object, object.layers.mask); object.layers.disableAll(); taken++;
115
+ });
116
+ return taken;
91
117
  }
92
118
 
93
119
  /** Make `count` free dark lights now (counted, never mirrored), for content known to ask after the first render: a
@@ -166,6 +192,20 @@ export class LightPool {
166
192
  // three posed the scene before this hook: the slot's world matrix is set here, from the light's
167
193
  slot.position.setFromMatrixPosition(light.matrixWorld); slot.updateMatrixWorld();
168
194
  }
195
+ for (const [light, mask] of source.adopted) {
196
+ if (light.intensity <= 0 || !shownUnder(light, this.group.parent)) continue;
197
+ const slot = this.reserved[next];
198
+ if (slot === undefined) {
199
+ // the reserve is shared by every shown region: one with no slot left is counted again, as before it was adopted
200
+ // (the count moves, every lit program links again, but it lights), never left dark
201
+ if (!this.warnedMirror) { this.warnedMirror = true; console.warn(`[LightPool] more shown region lights than the ${String(this.reserved.length)} reserved: an adopted light counts again`); }
202
+ light.layers.mask = mask; source.adopted.delete(light);
203
+ continue;
204
+ }
205
+ next++;
206
+ slot.color.copy(light.color); slot.intensity = light.intensity; slot.distance = light.distance; slot.decay = light.decay;
207
+ slot.position.setFromMatrixPosition(light.matrixWorld); slot.updateMatrixWorld();
208
+ }
169
209
  }
170
210
  for (; next < this.reserved.length; next++) { const slot = this.reserved[next]; if (slot !== undefined) slot.intensity = 0; }
171
211
  }
@@ -140,15 +140,24 @@ const inflight = new Set(), controlled = new Set(), loading = new Set(), nonLoad
140
140
  const isDoctorDocument = url => url.origin === self.location.origin
141
141
  && (url.pathname === '/doctor' || url.pathname === '/doctor/' || url.pathname === '/doctor/index.html'
142
142
  || (url.pathname === '/' || url.pathname === '/index.html') && url.searchParams.has('doctor'));
143
+ // OF6: only a page we can see loads. A client `clients.get` doesn't list (a dedicated worker some browsers don't) is not one.
143
144
  function isNonLoadingClient(id) {
144
145
  if (typeof self.clients?.get !== 'function') return Promise.resolve(false);
145
146
  let known = nonLoadingClients.get(id);
146
- if (known === undefined) { known = self.clients.get(id).then(client => client?.type === 'worker'
147
- || client?.type === 'window' && isDoctorDocument(new URL(client.url)), () => false); nonLoadingClients.set(id, known); }
147
+ if (known === undefined) {
148
+ known = self.clients.get(id).then(client => {
149
+ // unseen now may be a page a browser lists late: not kept, so its next read asks again
150
+ if (client === undefined) { nonLoadingClients.delete(id); return true; }
151
+ return client.type === 'worker' || client.type === 'sharedworker' || client.type === 'window' && isDoctorDocument(new URL(client.url));
152
+ }, () => false);
153
+ nonLoadingClients.set(id, known);
154
+ }
148
155
  return known;
149
156
  }
157
+ // OF6: a read with no client id (a worker's own script) is no loading page; a navigation pauses through its own branch. Before,
158
+ // such reads paused the precache and aborted its fetches on every read, so a page's workers held it paused while they read.
150
159
  async function pauseForClient(id) {
151
- if (typeof id === 'string' && id !== '' && await isNonLoadingClient(id)) return;
160
+ if (typeof id !== 'string' || id === '' || await isNonLoadingClient(id)) return;
152
161
  pausePrecache(id);
153
162
  }
154
163
  function pausePrecache(client) {
@@ -158,9 +158,13 @@ function* exteriorJobSteps(scene: THREE.Scene, rt: THREE.WebGLRenderTarget | nul
158
158
  const target = createCompileScene(scene);
159
159
  const lights = new CompileLights();
160
160
  // the road draws with the page's own environment (a layer swaps a cell's in only while it renders, `BackdropLayer.apply`):
161
- // with none declared, the live page environment keys the exterior variant (G639: a null one keyed Driftwood's road
162
- // programs without the page PMREM, so they all linked on the first road frame)
163
- target.fog = scene.fog; target.environment = state.environment ?? scene.environment;
161
+ // the declared one keys the exterior variant, and the live one (a cell's PMREM, swapped in by its layer at half weight, so
162
+ // drawn on the road beside the cell; G639: Driftwood's road programs linked on the first road frame without it) one more
163
+ // below. RP4: keyed with the live PMREM alone, between frames inside a cell, a grid page (declared none) had no variant
164
+ // for the road past the layer's half weight, and every program of the cell linked again 2 m before its edge (Driftwood's
165
+ // west edge: about 17 links in one frame, 2.5 to 4.3 s in Chromium)
166
+ target.fog = scene.fog; target.environment = state.environment;
167
+ const live = scene.environment;
164
168
  const pending: THREE.Object3D[] = [scene];
165
169
  while (pending.length > 0) {
166
170
  const object = pending.pop();
@@ -183,17 +187,19 @@ function* exteriorJobSteps(scene: THREE.Scene, rt: THREE.WebGLRenderTarget | nul
183
187
  : exterior;
184
188
  // Passes with their own scene keep their authored state. Only the page world/depth variants transition outside.
185
189
  for (const job of jobs) if (job.target === scene) { job.target = target; job.lights = lights; }
186
- // A view root's warm-up (`roots`): also the variant for every other environment the road may draw with, one per cube
187
- // height (a cell's layer swaps its PMREM in by weight; G639: Driftwood's, Nalati's and Pine's ring and road views linked
188
- // their 256 / 512 / 1024 variants on the first road frame beside each, 150-270 ms each with a cold shader cache)
189
- if (roots !== undefined) {
190
- const own = target.environment, height = (t: THREE.Texture | null): unknown => (t === null ? null : Reflect.get(t.image ?? {}, 'height'));
191
- for (const environment of pageEnvironments()) {
192
- if (height(environment) === height(own)) continue;
193
- const lit = (yield* sceneJobSteps(scene, rt, 1, roots, state.roots)).jobs;
194
- for (const job of lit) if (job.target === scene) { job.target = target; job.lights = lights; job.environment = environment; }
195
- jobs.push(...lit);
196
- }
190
+ // Also the variant for every other environment the road may draw with, one per cube height (three keys a program by the
191
+ // PMREM's height, and by none): the live one, and for a view root's warm-up (`roots`) every one the page recorded (a
192
+ // cell's layer swaps its PMREM in by weight; G639: Driftwood's, Nalati's and Pine's ring and road views linked their
193
+ // 256 / 512 / 1024 variants on the first road frame beside each, 150-270 ms each with a cold shader cache)
194
+ const height = (t: THREE.Texture | null): unknown => (t === null ? null : Reflect.get(t.image ?? {}, 'height'));
195
+ const keyed = new Set<unknown>([height(target.environment)]);
196
+ for (const environment of [...live === null ? [] : [live], ...roots === undefined ? [] : pageEnvironments()]) {
197
+ if (keyed.has(height(environment))) continue;
198
+ keyed.add(height(environment));
199
+ const lit = [...(yield* sceneJobSteps(scene, rt, roots === undefined ? per : 1, roots ?? [scene], state.roots, undefined, from)).jobs,
200
+ ...roots === undefined ? familyCompileJobs(scene, rt, per, excludedMaterials) : []];
201
+ for (const job of lit) if (job.target === scene) { job.target = target; job.lights = lights; job.environment = environment; }
202
+ jobs.push(...lit);
197
203
  }
198
204
  return jobs;
199
205
  }
@@ -117,7 +117,7 @@ function productionPage(): boolean {
117
117
 
118
118
  function loadSdk(): Promise<BrowserSdk | null> {
119
119
  if (!productionPage()) return Promise.resolve(null);
120
- sdk ??= import('@sentry/browser').then((sentry) => {
120
+ sdk ??= import('@sentry/browser').then(async (sentry) => {
121
121
  const environment = browserErrorEnvironment(location.origin, installedIdentity()?.errorReportEnvironments ?? {});
122
122
  const version = typeof __ENGINE_RELEASE__ === 'object' ? __ENGINE_RELEASE__.version : undefined;
123
123
  sentry.init({
@@ -148,6 +148,9 @@ function loadSdk(): Promise<BrowserSdk | null> {
148
148
  return event;
149
149
  },
150
150
  });
151
+ // DEVICE-TELEMETRY DT2: the device's snapshot as the `device` context and `device.*` tags, loaded with the SDK (never on the title)
152
+ try { const { applySentryDevice, deviceSnapshot } = await import('./deviceSnapshot'); applySentryDevice(sentry, await deviceSnapshot(), dsn); }
153
+ catch { /* a report goes without it */ }
151
154
  return sentry;
152
155
  // S13: a failed chunk load (a stale page, the network) must not silence every later report on this page; the next one tries again
153
156
  }).catch(() => { sdk = null; return null; });
@@ -0,0 +1,155 @@
1
+ // DEVICE-TELEMETRY DT1 (meta docs/plans/DEVICE-TELEMETRY-PLAN.md): one snapshot of the device this page runs on, gathered once per page,
2
+ // for the door's `client.device` line (shell.ts sends it on each socket) and Sentry's `device` context (browserErrors.ts).
3
+ // Every field is optional and every read is failure-safe: a browser without an API gives fewer fields, never a throw.
4
+ // Privacy line: device characteristics only, the ones any page can read. No IP address, no new persistent identifier, no fingerprint
5
+ // hash, and nothing that reads files, contacts, sensors, the camera, the microphone or location.
6
+ import { Scope } from '../../../shared/engine/app/scope';
7
+ import { cleanDevice, deviceTags, type DeviceSnapshot } from '../../../shared/engine/net/deviceWord';
8
+
9
+ declare const __BUILD_ID__: string | undefined;
10
+
11
+ /** What the snapshot reads; the page's globals by default, fakes in a test. */
12
+ export interface DeviceSources {
13
+ readonly navigator?: unknown;
14
+ readonly screen?: unknown;
15
+ readonly devicePixelRatio?: unknown;
16
+ readonly matchMedia?: (query: string) => { readonly matches: boolean };
17
+ readonly timeZone?: () => string | undefined;
18
+ readonly build?: string;
19
+ }
20
+
21
+ /** What the game's own WebGL context says (never a new context). */
22
+ export type DeviceGpu = Pick<DeviceSnapshot, 'gpu' | 'gpuVendor' | 'maxTexture' | 'astc' | 'etc2' | 'bptc'>;
23
+
24
+ const HIGH_ENTROPY = ['model', 'platform', 'platformVersion', 'architecture', 'bitness', 'fullVersionList', 'formFactors', 'wow64'];
25
+ /** Client Hints can hang on a browser that never answers; the snapshot waits at most this long for them. */
26
+ const HINTS_WAIT_MS = 1500;
27
+
28
+ type Rec = Record<string, unknown>;
29
+ /** A property read that never throws (a getter may). */
30
+ const read = (from: unknown, key: string): unknown => {
31
+ if (typeof from !== 'object' && typeof from !== 'function') return undefined;
32
+ if (from === null) return undefined;
33
+ try { return (from as Rec)[key]; } catch { return undefined; }
34
+ };
35
+ const said = (value: unknown): string => typeof value === 'string' || typeof value === 'number' ? String(value) : '';
36
+ const brandList = (value: unknown): string[] | undefined => Array.isArray(value)
37
+ ? value.map(entry => `${said(read(entry, 'brand'))} ${said(read(entry, 'version'))}`.trim()).filter(Boolean) : undefined;
38
+
39
+ async function hints(nav: unknown): Promise<Rec> {
40
+ const data = read(nav, 'userAgentData');
41
+ const out: Rec = { brands: brandList(read(data, 'brands')), mobile: read(data, 'mobile'), platform: read(data, 'platform') };
42
+ const ask = read(data, 'getHighEntropyValues');
43
+ if (typeof ask !== 'function') return out;
44
+ const scope = new Scope('device.hints');
45
+ try {
46
+ const asked = Promise.resolve((ask as (hints: string[]) => unknown).call(data, HIGH_ENTROPY));
47
+ const values = await Promise.race([asked, new Promise(resolve => { scope.timeout(HINTS_WAIT_MS, () => { resolve(null); }); })]);
48
+ if (values === null || typeof values !== 'object') return out;
49
+ for (const key of ['model', 'platform', 'platformVersion', 'architecture', 'bitness', 'wow64', 'formFactors']) {
50
+ const value = read(values, key);
51
+ if (value !== undefined && value !== '') out[key] = value;
52
+ }
53
+ out['fullVersionList'] = brandList(read(values, 'fullVersionList'));
54
+ } catch { /* a refused hint leaves the low-entropy ones */ } finally { scope.dispose(); }
55
+ return out;
56
+ }
57
+
58
+ function media(sources: DeviceSources, query: string): boolean | undefined {
59
+ try { return sources.matchMedia?.(query).matches; } catch { return undefined; }
60
+ }
61
+
62
+ /** The snapshot from `sources`, without the GPU. Never throws. */
63
+ export async function collectDevice(sources: DeviceSources): Promise<DeviceSnapshot> {
64
+ const nav = sources.navigator, screen = sources.screen, out: Rec = { build: sources.build };
65
+ try { Object.assign(out, await hints(nav)); } catch { /* none */ }
66
+ out['ua'] = read(nav, 'userAgent');
67
+ out['screenW'] = read(screen, 'width'); out['screenH'] = read(screen, 'height');
68
+ out['availW'] = read(screen, 'availWidth'); out['availH'] = read(screen, 'availHeight');
69
+ out['orientation'] = read(read(screen, 'orientation'), 'type');
70
+ out['dpr'] = sources.devicePixelRatio;
71
+ out['cores'] = read(nav, 'hardwareConcurrency'); out['memory'] = read(nav, 'deviceMemory'); out['touch'] = read(nav, 'maxTouchPoints');
72
+ out['pointer'] = media(sources, '(pointer: coarse)') === true ? 'coarse' : media(sources, '(pointer: fine)') === true ? 'fine' : media(sources, '(pointer: none)') === true ? 'none' : undefined;
73
+ out['hover'] = media(sources, '(hover: hover)');
74
+ out['language'] = read(nav, 'language');
75
+ const languages = read(nav, 'languages');
76
+ out['languages'] = Array.isArray(languages) ? [...languages as unknown[]] : undefined;
77
+ try { out['timeZone'] = sources.timeZone?.(); } catch { /* none */ }
78
+ const connection = read(nav, 'connection');
79
+ out['net'] = read(connection, 'effectiveType'); out['downlink'] = read(connection, 'downlink'); out['saveData'] = read(connection, 'saveData');
80
+ out['display'] = (['standalone', 'fullscreen', 'minimal-ui', 'browser'] as const).find(mode => media(sources, `(display-mode: ${mode})`) === true);
81
+ return cleanDevice(out);
82
+ }
83
+
84
+ /** What the game's own context says about its GPU: the unmasked names, the largest texture, and the compressed forms it takes. Never throws. */
85
+ export function gpuFacts(gl: Pick<WebGLRenderingContext, 'getExtension' | 'getParameter' | 'RENDERER' | 'VENDOR' | 'MAX_TEXTURE_SIZE'>): DeviceGpu {
86
+ const out: Rec = {};
87
+ try {
88
+ const info: { UNMASKED_RENDERER_WEBGL: number; UNMASKED_VENDOR_WEBGL: number } | null = gl.getExtension('WEBGL_debug_renderer_info');
89
+ out['gpu'] = gl.getParameter(info === null ? gl.RENDERER : info.UNMASKED_RENDERER_WEBGL);
90
+ out['gpuVendor'] = gl.getParameter(info === null ? gl.VENDOR : info.UNMASKED_VENDOR_WEBGL);
91
+ } catch { /* a lost context names nothing */ }
92
+ try { out['maxTexture'] = gl.getParameter(gl.MAX_TEXTURE_SIZE); } catch { /* none */ }
93
+ const has = (name: string): boolean | undefined => { try { return gl.getExtension(name) !== null; } catch { return undefined; } };
94
+ out['astc'] = has('WEBGL_compressed_texture_astc'); out['etc2'] = has('WEBGL_compressed_texture_etc'); out['bptc'] = has('EXT_texture_compression_bptc');
95
+ return cleanDevice(out);
96
+ }
97
+
98
+ /** The noted GPU lives on the window, not in this module: the online shell and the game can be separate bundles of the engine. */
99
+ const GPU_KEY = Symbol.for('wildshard.deviceGpu');
100
+ interface GpuHolder { [GPU_KEY]?: { facts: DeviceGpu | null; waiting: ((facts: DeviceGpu) => void)[] } }
101
+ const holder = (): NonNullable<GpuHolder[typeof GPU_KEY]> => {
102
+ const host = globalThis as GpuHolder;
103
+ host[GPU_KEY] ??= { facts: null, waiting: [] };
104
+ return host[GPU_KEY];
105
+ };
106
+
107
+ /** The renderer's context is up (bootstrap.ts): note what it says, once per page. */
108
+ export function noteDeviceGpu(gl: Parameters<typeof gpuFacts>[0]): void {
109
+ try {
110
+ const held = holder();
111
+ if (held.facts !== null) return;
112
+ held.facts = gpuFacts(gl);
113
+ for (const wake of held.waiting.splice(0)) wake(held.facts);
114
+ } catch { /* telemetry never disrupts the boot */ }
115
+ }
116
+
117
+ /** The GPU noted so far, waiting at most `waitMs` for the renderer. */
118
+ function noted(waitMs: number): Promise<DeviceGpu> {
119
+ const held = holder();
120
+ if (held.facts !== null || waitMs <= 0) return Promise.resolve(held.facts ?? {});
121
+ const scope = new Scope('device.gpu');
122
+ return new Promise<DeviceGpu>(resolve => {
123
+ const wake = (facts: DeviceGpu): void => { scope.dispose(); resolve(facts); };
124
+ scope.timeout(waitMs, () => { held.waiting = held.waiting.filter(entry => entry !== wake); scope.dispose(); resolve({}); });
125
+ held.waiting.push(wake);
126
+ });
127
+ }
128
+
129
+ let page: Promise<DeviceSnapshot> | null = null;
130
+ /** This page's snapshot: gathered once, with the GPU once the renderer has said it (at most `gpuWaitMs`). Never rejects. */
131
+ export async function deviceSnapshot(gpuWaitMs = 0): Promise<DeviceSnapshot> {
132
+ page ??= collectDevice(pageSources()).catch(() => ({}));
133
+ const [device, gpu] = await Promise.all([page, noted(gpuWaitMs)]);
134
+ return { ...device, ...gpu };
135
+ }
136
+
137
+ function pageSources(): DeviceSources {
138
+ const scope = globalThis as unknown as { navigator?: unknown; screen?: unknown; devicePixelRatio?: unknown; matchMedia?: (query: string) => { matches: boolean } };
139
+ const matchMedia = scope.matchMedia;
140
+ return {
141
+ navigator: scope.navigator, screen: scope.screen, devicePixelRatio: scope.devicePixelRatio,
142
+ ...(typeof matchMedia === 'function' ? { matchMedia: (query: string) => matchMedia.call(globalThis, query) } : {}),
143
+ timeZone: () => Intl.DateTimeFormat().resolvedOptions().timeZone,
144
+ ...(typeof __BUILD_ID__ === 'string' ? { build: __BUILD_ID__ } : {}),
145
+ };
146
+ }
147
+
148
+ /** The part of the Sentry SDK the device context needs. */
149
+ export interface SentryDeviceSink { setContext: (name: string, context: Record<string, unknown> | null) => void; setTags: (tags: Record<string, string>) => void }
150
+ /** DT2: Sentry's `device` context holds the whole snapshot, and its searchable tags are set (`device.model:*`). Only with a DSN built
151
+ * in, as every Sentry call; without one nothing is called. Never throws. */
152
+ export function applySentryDevice(sentry: SentryDeviceSink, device: DeviceSnapshot, dsn: string): boolean {
153
+ if (dsn === '') return false;
154
+ try { sentry.setContext('device', { ...device }); sentry.setTags(deviceTags(device)); return true; } catch { return false; }
155
+ }
@@ -2841,108 +2841,6 @@ export const MUSIC_MANIFESTS: Readonly<Record<string, unknown>> = {
2841
2841
  "pickup": "sting-pickup-6ed91318.m4a"
2842
2842
  }
2843
2843
  },
2844
- "pine-hollow-folk": {
2845
- "style": "folk",
2846
- "set": "pine-hollow",
2847
- "model": "MiniMax-Music3",
2848
- "credit": "Music: MiniMax-Music3",
2849
- "slots": {
2850
- "night": {
2851
- "calm": "night-calm-e5eeff22.m4a",
2852
- "bpm": 86.006,
2853
- "beatsPerBar": 4,
2854
- "loopStart": 24.1952,
2855
- "loopEnd": 71.6336,
2856
- "duration": 74.432,
2857
- "tension": "night-tension-0071c7a3.m4a"
2858
- },
2859
- "boss": {
2860
- "calm": "boss-base-1ad74736.m4a",
2861
- "bpm": 85.562,
2862
- "beatsPerBar": 4,
2863
- "loopStart": 15.2787,
2864
- "loopEnd": 57.3533,
2865
- "duration": 60.16,
2866
- "layers": [
2867
- "boss-bass-2f96accb.m4a",
2868
- "boss-drums-90b1e7cb.m4a"
2869
- ],
2870
- "phases": {
2871
- "1": [
2872
- 0.6,
2873
- 0
2874
- ],
2875
- "2": [
2876
- 1,
2877
- 0.55
2878
- ],
2879
- "3": [
2880
- 1,
2881
- 1
2882
- ]
2883
- },
2884
- "phaseNames": {
2885
- "1": "I - the Warden",
2886
- "2": "II - Lanterns Fall",
2887
- "3": "III - the Last Light"
2888
- }
2889
- }
2890
- },
2891
- "stings": {
2892
- "dawn": "sting-dawn-35a7550c.m4a"
2893
- }
2894
- },
2895
- "pine-hollow-orchestral": {
2896
- "style": "orchestral",
2897
- "set": "pine-hollow",
2898
- "model": "MiniMax-Music3",
2899
- "credit": "Music: MiniMax-Music3",
2900
- "slots": {
2901
- "night": {
2902
- "calm": "night-calm-da54e0eb.m4a",
2903
- "bpm": 85.421,
2904
- "beatsPerBar": 4,
2905
- "loopStart": 7.4072,
2906
- "loopEnd": 41.1225,
2907
- "duration": 43.9467,
2908
- "tension": "night-tension-ba25e774.m4a"
2909
- },
2910
- "boss": {
2911
- "calm": "boss-base-d7203ec0.m4a",
2912
- "bpm": 89.221,
2913
- "beatsPerBar": 4,
2914
- "loopStart": 24.381,
2915
- "loopEnd": 59.3502,
2916
- "duration": 62.0587,
2917
- "layers": [
2918
- "boss-bass-c368d6c3.m4a",
2919
- "boss-drums-4c4efeb7.m4a"
2920
- ],
2921
- "phases": {
2922
- "1": [
2923
- 0.6,
2924
- 0
2925
- ],
2926
- "2": [
2927
- 1,
2928
- 0.55
2929
- ],
2930
- "3": [
2931
- 1,
2932
- 1
2933
- ]
2934
- },
2935
- "phaseNames": {
2936
- "1": "I - the Warden",
2937
- "2": "II - Lanterns Fall",
2938
- "3": "III - the Last Light"
2939
- }
2940
- }
2941
- },
2942
- "stings": {
2943
- "dawn": "sting-dawn-eafd4a6d.m4a"
2944
- }
2945
- },
2946
2844
  "pine-hollow-piano": {
2947
2845
  "style": "piano",
2948
2846
  "set": "pine-hollow",