@wildshard/shard-format 0.82.9 → 0.82.11

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.82.9",
3
+ "version": "0.82.11",
4
4
  "description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -30,6 +30,7 @@ import { preflightShardfile } from './preflight.ts';
30
30
 
31
31
  import { compendiumSketches } from './compendiumSketches.ts';
32
32
  import { assertCommonsCosts, type CommonsCosts } from './commonsCosts.ts';
33
+ import { coarseLibraryModel } from './coarse-library.ts';
33
34
  import { nearPlaceholderCost } from './nearPlaceholder.ts';
34
35
  import { validateNearPlaceholderAssets } from './nearPlaceholderAssets.ts';
35
36
 
@@ -188,7 +189,9 @@ function admitAfterFiles(state: AssetAdmission, assets: ReadonlyMap<string, Uint
188
189
  if (s.sim.scripts.some((id) => !id.startsWith('commons:') && files.get(id)?.kind !== 'wasm')) throw new Error('script reference is not an admitted Wasm file');
189
190
  for (const t of s.tiles) {
190
191
  const roots = closure(t.files);
191
- if (t.lod === 1 && [...roots].some((r) => library.has(r))) throw new Error('coarse dependency on library');
192
+ // Meta J551 (Jake, 2026-11-30): a texture shared by several tiles loads once, with the library, so a coarse tile may
193
+ // name a library image; a library model stays fine-only
194
+ if (t.lod === 1 && coarseLibraryModel(roots, library, (r) => files.get(r)?.kind)) throw new Error('coarse dependency on library');
192
195
  const cost = sum(t.files, library);
193
196
  if (cost.resident > t.decoded + t.gpu || cost.compressed > t.compressed || cost.triangles > t.triangles || cost.draws > t.draws) throw new Error('tile dependency cost understated');
194
197
  }
@@ -0,0 +1,16 @@
1
+ /** The file kinds a coarse tile may share with the library (meta J551): images, not models. */
2
+ const LIBRARY_IMAGE_KINDS: ReadonlySet<string> = new Set(['image', 'ktx2'])
3
+
4
+ /** True when a coarse tile's closure names a library file that is not an image (a model, a script): refused. */
5
+ export function coarseLibraryModel(
6
+ roots: Iterable<string>,
7
+ library: ReadonlySet<string>,
8
+ kindOf: (ref: string) => string | undefined,
9
+ ): boolean {
10
+ for (const ref of roots) {
11
+ if (library.has(ref) && !LIBRARY_IMAGE_KINDS.has(kindOf(ref) ?? '')) {
12
+ return true
13
+ }
14
+ }
15
+ return false
16
+ }
@@ -44,10 +44,11 @@ export const MEMORY_GATES: Readonly<{ reportOnly: boolean; explorerMB: number; l
44
44
  });
45
45
  /** Provisional phone content caps; shadow draws count in each draw cap. */
46
46
  export const CONTENT_CAPS: { readonly l0: { readonly size: 62.5; readonly resident: number; readonly compressed: number; readonly triangles: 40000; readonly draws: 8; }; readonly l1: { readonly size: 125; readonly resident: number; readonly compressed: number; readonly triangles: 10000; readonly draws: 2; }; readonly far: { readonly resident: number; readonly compressed: 1000000; readonly triangles: 8000; readonly draws: 1; }; readonly library: { readonly resident: number; readonly compressed: number; }; readonly sim: { readonly resident: number; readonly compressed: number; }; readonly engineBase: number; readonly playing: number; readonly loading: number; readonly l0Count: 40; readonly l1Count: 32; readonly farCount: 9; readonly simCount: 4; readonly libraryCount: 4; readonly overlap: number; readonly residentFactor: 1.11; readonly nearRadius: 150; readonly shadowRadius: 80; readonly pitch: 562.5; } = {
47
- l0: { size: 62.5, resident: 4 * CONTENT_MB, compressed: 0.3 * CONTENT_MB, triangles: 40_000, draws: 8 },
47
+ // Meta J551 (Jake, 2026-11-30): the fine-tile download line is 600 kB, the far target 2 MB and the library 28 MB
48
+ l0: { size: 62.5, resident: 4 * CONTENT_MB, compressed: 0.6 * CONTENT_MB, triangles: 40_000, draws: 8 },
48
49
  l1: { size: 125, resident: 2 * CONTENT_MB, compressed: 0.2 * CONTENT_MB, triangles: 10_000, draws: 2 },
49
- far: { resident: 1.6 * CONTENT_MB, compressed: CONTENT_MB, triangles: 8_000, draws: 1 },
50
- library: { resident: 25 * CONTENT_MB, compressed: 8 * CONTENT_MB },
50
+ far: { resident: 2 * CONTENT_MB, compressed: CONTENT_MB, triangles: 8_000, draws: 1 },
51
+ library: { resident: 28 * CONTENT_MB, compressed: 8 * CONTENT_MB },
51
52
  sim: { resident: 25 * CONTENT_MB, compressed: 2 * CONTENT_MB },
52
53
  engineBase: ENGINE_BASE_BYTES, playing: MEMORY_GATES.explorerMB * CONTENT_MB, loading: MEMORY_GATES.loadingMB * CONTENT_MB,
53
54
  l0Count: 40, l1Count: 32, farCount: 9, simCount: 4, libraryCount: 4,
@@ -10,6 +10,7 @@ import { grazerPreset } from './grazers.ts';
10
10
  import { ShardFiniteSchema as finite, ShardReferenceSchema as ref, ShardNamesSchema as names, IdentitySchema, RequiresSchema, BudgetsSchema, SimSchema, AuthorCapsSchema, ServerBudgetSchema, FilesSchema, TilesSchema, LibrarySchema, CriticalSchema, FarSchema, SpawnSchema } from './shardSections.ts';
11
11
  import * as v from 'valibot';
12
12
  import { CELL_ABOVE, CELL_BELOW, CHUNK_HALF, CONTENT_CAPS } from './contentBounds.ts';
13
+ import { mergedWithinTile } from './view-draws.ts';
13
14
  import { jsonDataNodes } from './json.ts';
14
15
  import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
15
16
  import { preflightShardfile } from './preflight.ts';
@@ -307,6 +308,10 @@ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unkn
307
308
  if (margin === undefined || b.min[0] < -250 - margin || b.max[0] > 250 + margin || b.min[2] < -250 - margin || b.max[2] > 250 + margin || b.min.some((coordinate, i) => coordinate > (t.bounds.min[i] ?? -Infinity)) || b.max.some((coordinate, i) => coordinate < (t.bounds.max[i] ?? Infinity))) errors.push('declared prop draw bounds');
308
309
  }
309
310
  if (t.lod === 1 && t.files.some((r) => s.library.includes(r))) errors.push('self-contained coarse tile');
311
+ // Meta ZL29: a fine tile's merged draws are its own, its kept shadows within them, each key once
312
+ if (!mergedWithinTile(t)) {
313
+ errors.push('merged draws within the tile');
314
+ }
310
315
  }
311
316
  for (const f of s.files) if (f.critical !== s.critical.includes(f.hash)) errors.push('critical flags match roots');
312
317
  if (s.near !== undefined) {
@@ -33,7 +33,10 @@ const vec3 = v.tuple([ShardFiniteSchema, ShardFiniteSchema, ShardFiniteSchema]);
33
33
  export const CellBoundsSchema: v.GenericSchema<CellBoundsInput, CellBounds> = v.pipe(v.strictObject({ min: vec3, max: vec3 }), v.check((b) => b.min.every((n, i) => n <= (b.max[i] ?? -Infinity)), 'ordered bounds'), v.check((b) => b.min[0] >= -CHUNK_HALF && b.max[0] <= CHUNK_HALF && b.min[2] >= -CHUNK_HALF && b.max[2] <= CHUNK_HALF && b.min[1] >= -CELL_BELOW && b.max[1] <= CELL_ABOVE, 'cell bounds'));
34
34
  const drawBounds = CellBoundsSchema;
35
35
  const costs = { compressed: ShardNaturalSchema, decoded: ShardNaturalSchema, gpu: ShardNaturalSchema, triangles: ShardNaturalSchema, draws: ShardNaturalSchema };
36
- const tile: v.GenericSchema<ShardTileRowsInput, ShardTileRows> = v.strictObject({ lod: v.picklist([0, 1]), x: ShardNaturalSchema, z: ShardNaturalSchema, bounds: CellBoundsSchema, drawBounds: v.exactOptional(drawBounds), geometricError: v.pipe(ShardFiniteSchema, v.minValue(0)), files: ShardReferencesSchema, ...costs });
36
+ /** Meta ZONE-SIZE-LIMITS ZL29 (J551): a fine tile's draws the engine merges for the view, one per (key, 250 m block) across
37
+ * resident tiles: their keys, the tile draws they account for and the shadow draws the tile keeps for them. */
38
+ const merged = v.strictObject({ keys: ShardNamesSchema, draws: ShardNaturalSchema, shadows: ShardNaturalSchema });
39
+ const tile: v.GenericSchema<ShardTileRowsInput, ShardTileRows> = v.strictObject({ lod: v.picklist([0, 1]), x: ShardNaturalSchema, z: ShardNaturalSchema, bounds: CellBoundsSchema, drawBounds: v.exactOptional(drawBounds), merged: v.exactOptional(merged), geometricError: v.pipe(ShardFiniteSchema, v.minValue(0)), files: ShardReferencesSchema, ...costs });
37
40
  const file: v.StrictObjectSchema<{ readonly hash: v.GenericSchema<ShardFileRowsInput['hash'], ShardFileRows['hash']>; readonly kind: v.GenericSchema<ShardFileRowsInput['kind'], ShardFileRows['kind']>; readonly compressed: v.GenericSchema<ShardFileRowsInput['compressed'], ShardFileRows['compressed']>; readonly decoded: v.GenericSchema<ShardFileRowsInput['decoded'], ShardFileRows['decoded']>; readonly gpu: v.GenericSchema<ShardFileRowsInput['gpu'], ShardFileRows['gpu']>; readonly triangles: v.GenericSchema<ShardFileRowsInput['triangles'], ShardFileRows['triangles']>; readonly draws: v.GenericSchema<ShardFileRowsInput['draws'], ShardFileRows['draws']>; readonly dependencies: v.GenericSchema<ShardFileRowsInput['dependencies'], ShardFileRows['dependencies']>; readonly critical: v.GenericSchema<ShardFileRowsInput['critical'], ShardFileRows['critical']>; }, undefined> = v.strictObject({ hash: ShardHashSchema, kind: v.picklist(['glb', 'ktx2', 'audio', 'json', 'wasm', 'binary', 'image']), ...costs, dependencies: ShardReferencesSchema, critical: v.boolean() });
38
41
  const tileCount = (2 * CHUNK_HALF / WIRE_TILE_SIZES.l0) ** 2 + (2 * CHUNK_HALF / WIRE_TILE_SIZES.l1) ** 2;
39
42
 
@@ -148,6 +151,7 @@ export type ShardTileRowsInput = Omit<{
148
151
  z: ShardNaturalInput;
149
152
  bounds: CellBoundsInput;
150
153
  drawBounds?: CellBoundsInput;
154
+ merged?: { keys: ShardNamesInput; draws: ShardNaturalInput; shadows: ShardNaturalInput };
151
155
  geometricError: ShardFiniteInput;
152
156
  files: ShardReferencesInput;
153
157
  }, keyof ({
@@ -169,6 +173,7 @@ export type ShardTileRows = Omit<{
169
173
  z: ShardNatural;
170
174
  bounds: CellBounds;
171
175
  drawBounds?: CellBounds;
176
+ merged?: { keys: ShardNames; draws: ShardNatural; shadows: ShardNatural };
172
177
  geometricError: ShardFinite;
173
178
  files: ShardReferences;
174
179
  }, keyof ({
@@ -21,7 +21,7 @@ import { MEMORY_HARD_BYTES, memoryLineIssues, runtimeOfflineBytes } from './memo
21
21
  import { bootMemoryCosts } from './boot-memory-cost.ts';
22
22
  import { cookedImageSource } from './cooked-image-cost.ts';
23
23
  import type { TierIndex } from './phone-files.ts';
24
- import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
24
+ import { TILE_TRIANGLES, VIEW_DRAWS, viewDraws } from './view-draws.ts';
25
25
  import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
26
26
  import { SCRIPT_LIMITS } from './scriptLimits.ts';
27
27
  import { MemoryAdmission } from './memoryAdmission.ts';
@@ -253,7 +253,9 @@ export function performanceTargetIssues(source: Shardfile, policy: 'refuse' | 'w
253
253
  check(['perf-critical-download', 'critical download bytes'], totals(source, reportCardClosure(source, source.critical)).bytes, C.sim.compressed);
254
254
  for (const tile of source.tiles) {
255
255
  const cap = tile.lod === 0 ? C.l0 : C.l1, id = `tile ${tile.lod}/${tile.x}/${tile.z}`;
256
- check(['perf-tile-download', `${id} download bytes`], tile.compressed, cap.compressed, true); check(['perf-tile-triangles', `${id} triangles`], tile.triangles, cap.triangles, true);
256
+ // J544: a fine tile's phone triangle line is TILE_TRIANGLES.phone (40k); CONTENT_CAPS.l0's stays the residency rig's
257
+ const triangleLine = cap === C.l0 ? TILE_TRIANGLES.phone : cap.triangles;
258
+ check(['perf-tile-download', `${id} download bytes`], tile.compressed, cap.compressed, true); check(['perf-tile-triangles', `${id} triangles`], tile.triangles, triangleLine, true);
257
259
  check(['perf-tile-draws', `view at ${id} draws`], viewDraws(source.tiles, tile), VIEW_DRAWS.phone, true);
258
260
  }
259
261
  if (source.far !== null) {
@@ -8,17 +8,27 @@ const Z_AXIS = 2
8
8
  const HALF = 2
9
9
  const SQUARE = 2
10
10
  const NONE = 0
11
+ // The engine's view merge block (groundMerge's BLOCK) and the shard half width
12
+ // its blocks start from
13
+ const BLOCK = 250
14
+ const SHARD_HALF = 250
11
15
 
12
16
  /** The fields of a shardfile tile a view's draws read. */
13
17
  interface ViewBox {
14
18
  readonly max: readonly number[]
15
19
  readonly min: readonly number[]
16
20
  }
21
+ interface ViewMerged {
22
+ readonly draws: number
23
+ readonly keys: readonly string[]
24
+ readonly shadows: number
25
+ }
17
26
  interface ViewTile {
18
27
  readonly bounds: ViewBox
19
28
  readonly drawBounds?: ViewBox | undefined
20
29
  readonly draws: number
21
30
  readonly lod: number
31
+ readonly merged?: ViewMerged | undefined
22
32
  }
23
33
 
24
34
  /**
@@ -33,15 +43,25 @@ const VIEW_DRAWS: { readonly phone: number; readonly desktop: number } =
33
43
  /** Desktop's fine-tile triangles: Mossgate's fullest tile (364,625) holds the 60 fps cap on desktop. */
34
44
  const DESKTOP_TILE_TRIANGLES = 400_000
35
45
 
46
+ /**
47
+ * The phone's fine-tile triangle line: 40k, the same figure as
48
+ * `CONTENT_CAPS.l0.triangles`, which stays the residency rig's own. J537
49
+ * (Jake, 2026-11-28) raised it to 120k; J544 (Jake, 2026-11-29: "Respect 40k:
50
+ * flatten the stones") keeps it at 40k, and the starter template's tiles are
51
+ * cut to fit it (meta ZONE-SIZE-LIMITS ZL2, ZL3).
52
+ */
53
+ const PHONE_TILE_TRIANGLES = 40_000
54
+
36
55
  /**
37
56
  * SHARD-SOURCE AP9b: one fine (L0) tile's triangles per tier. The phone's is
38
- * `CONTENT_CAPS.l0.triangles`; desktop's is raised under J338 (look first).
39
- * Both are reported, not enforced: the sdk's budget table reads them.
57
+ * J544's line; desktop's is raised under J338 (look first). Both are
58
+ * reported, not enforced: the sdk's budget table and the performance card's
59
+ * `perf-tile-triangles` warning read them.
40
60
  */
41
61
  const TILE_TRIANGLES: { readonly phone: number; readonly desktop: number } =
42
62
  Object.freeze({
43
63
  desktop: DESKTOP_TILE_TRIANGLES,
44
- phone: CONTENT_CAPS.l0.triangles,
64
+ phone: PHONE_TILE_TRIANGLES,
45
65
  })
46
66
 
47
67
  function centre(tile: ViewTile, axis: number): number {
@@ -64,9 +84,45 @@ function isNear(tile: ViewTile, xAt: number, zAt: number): boolean {
64
84
  return reach <= CONTENT_CAPS.nearRadius ** SQUARE
65
85
  }
66
86
 
87
+ function blockAt(tile: ViewTile, axis: number): number {
88
+ const middle =
89
+ ((tile.bounds.min[axis] ?? NONE) + (tile.bounds.max[axis] ?? NONE)) / HALF
90
+ return Math.floor((middle + SHARD_HALF) / BLOCK)
91
+ }
92
+
93
+ /**
94
+ * Meta ZL29: a tile's merged draws are a fine tile's own, the shadows it keeps
95
+ * are within them, and each key is named once (true with none).
96
+ */
97
+ function mergedWithinTile(tile: Readonly<ViewTile>): boolean {
98
+ const { merged } = tile
99
+ if (merged === undefined) {
100
+ return true
101
+ }
102
+ return (
103
+ tile.lod === FINE &&
104
+ merged.draws <= tile.draws &&
105
+ merged.shadows <= merged.draws &&
106
+ new Set(merged.keys).size === merged.keys.length
107
+ )
108
+ }
109
+
110
+ /** One near tile's own draws; its merged keys join `shared` by block. */
111
+ function tileDraws(tile: ViewTile, shared: Set<string>): number {
112
+ const { merged } = tile
113
+ const block = [blockAt(tile, X_AXIS), blockAt(tile, Z_AXIS)].join(',')
114
+ for (const key of merged?.keys ?? []) {
115
+ shared.add([key, block].join('@'))
116
+ }
117
+ return tile.draws - (merged?.draws ?? NONE) + (merged?.shadows ?? NONE)
118
+ }
119
+
67
120
  /**
68
121
  * The draws of a view from fine tile `from`: every fine tile near its centre
69
- * at its reported draws, an upper bound. A coarse tile's view counts nothing.
122
+ * at its reported draws, an upper bound. A tile's `merged` draws count as the
123
+ * engine draws them (meta ZONE-SIZE-LIMITS ZL28, ZL29): each key once a 250 m
124
+ * block across the view's tiles, plus the shadow draws the tile keeps for
125
+ * them. A coarse tile's view counts nothing.
70
126
  */
71
127
  function viewDraws(tiles: readonly ViewTile[], from: ViewTile): number {
72
128
  if (from.lod !== FINE) {
@@ -74,14 +130,15 @@ function viewDraws(tiles: readonly ViewTile[], from: ViewTile): number {
74
130
  }
75
131
  const xAt = centre(from, X_AXIS)
76
132
  const zAt = centre(from, Z_AXIS)
133
+ const shared = new Set<string>()
77
134
  let draws = NONE
78
135
  for (const tile of tiles) {
79
136
  if (tile.lod === FINE && isNear(tile, xAt, zAt)) {
80
- draws += tile.draws
137
+ draws += tileDraws(tile, shared)
81
138
  }
82
139
  }
83
- return draws
140
+ return draws + shared.size
84
141
  }
85
142
 
86
- export type { ViewTile }
87
- export { TILE_TRIANGLES, VIEW_DRAWS, viewDraws }
143
+ export type { ViewMerged, ViewTile }
144
+ export { mergedWithinTile, TILE_TRIANGLES, VIEW_DRAWS, viewDraws }