@wildshard/shard-format 0.82.10 → 0.82.12
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.
|
|
3
|
+
"version": "0.82.12",
|
|
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": {
|
|
@@ -44,9 +44,10 @@ 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
|
-
// Meta J551 (Jake, 2026-11-30): the
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
// Meta J551 (Jake, 2026-11-30): the far target 2 MB and the library 28 MB; J557 (Jake, 2026-11-30): the fine-tile
|
|
48
|
+
// download line is 720 kB and the coarse 240 kB (Mossgate's 649 kB and 211 kB tiles plus 10%, J439)
|
|
49
|
+
l0: { size: 62.5, resident: 4 * CONTENT_MB, compressed: 0.72 * CONTENT_MB, triangles: 40_000, draws: 8 },
|
|
50
|
+
l1: { size: 125, resident: 2 * CONTENT_MB, compressed: 0.24 * CONTENT_MB, triangles: 10_000, draws: 2 },
|
|
50
51
|
far: { resident: 2 * CONTENT_MB, compressed: CONTENT_MB, triangles: 8_000, draws: 1 },
|
|
51
52
|
library: { resident: 28 * CONTENT_MB, compressed: 8 * CONTENT_MB },
|
|
52
53
|
sim: { resident: 25 * CONTENT_MB, compressed: 2 * CONTENT_MB },
|
|
@@ -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
|
-
|
|
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, vertices: v.exactOptional(v.array(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; vertices?: 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; vertices?: ShardNatural[] };
|
|
172
177
|
geometricError: ShardFinite;
|
|
173
178
|
files: ShardReferences;
|
|
174
179
|
}, keyof ({
|
package/src/format/view-draws.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CONTENT_CAPS } from './contentBounds.ts'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// Meta J557 (Jake, 2026-11-30): Mossgate's worst view count (287) plus 10%
|
|
4
|
+
const PHONE_VIEW = 320
|
|
4
5
|
const DESKTOP_VIEW = 400
|
|
5
6
|
const FINE = 0
|
|
6
7
|
const X_AXIS = 0
|
|
@@ -8,17 +9,32 @@ const Z_AXIS = 2
|
|
|
8
9
|
const HALF = 2
|
|
9
10
|
const SQUARE = 2
|
|
10
11
|
const NONE = 0
|
|
12
|
+
// The engine's view merge block (groundMerge's BLOCK) and the shard half width
|
|
13
|
+
// its blocks start from
|
|
14
|
+
const BLOCK = 250
|
|
15
|
+
const SHARD_HALF = 250
|
|
16
|
+
// The engine merges a key over the whole 500 m cell until that merge holds
|
|
17
|
+
// this many vertices, then by block (groundMerge's REGION_VERTICES, meta ZL31)
|
|
18
|
+
const REGION_VERTICES = 24_000
|
|
19
|
+
const CELL = 'cell'
|
|
11
20
|
|
|
12
21
|
/** The fields of a shardfile tile a view's draws read. */
|
|
13
22
|
interface ViewBox {
|
|
14
23
|
readonly max: readonly number[]
|
|
15
24
|
readonly min: readonly number[]
|
|
16
25
|
}
|
|
26
|
+
interface ViewMerged {
|
|
27
|
+
readonly draws: number
|
|
28
|
+
readonly keys: readonly string[]
|
|
29
|
+
readonly shadows: number
|
|
30
|
+
readonly vertices?: readonly number[] | undefined
|
|
31
|
+
}
|
|
17
32
|
interface ViewTile {
|
|
18
33
|
readonly bounds: ViewBox
|
|
19
34
|
readonly drawBounds?: ViewBox | undefined
|
|
20
35
|
readonly draws: number
|
|
21
36
|
readonly lod: number
|
|
37
|
+
readonly merged?: ViewMerged | undefined
|
|
22
38
|
}
|
|
23
39
|
|
|
24
40
|
/**
|
|
@@ -74,24 +90,104 @@ function isNear(tile: ViewTile, xAt: number, zAt: number): boolean {
|
|
|
74
90
|
return reach <= CONTENT_CAPS.nearRadius ** SQUARE
|
|
75
91
|
}
|
|
76
92
|
|
|
93
|
+
function blockAt(tile: ViewTile, axis: number): number {
|
|
94
|
+
const middle =
|
|
95
|
+
((tile.bounds.min[axis] ?? NONE) + (tile.bounds.max[axis] ?? NONE)) / HALF
|
|
96
|
+
return Math.floor((middle + SHARD_HALF) / BLOCK)
|
|
97
|
+
}
|
|
98
|
+
|
|
77
99
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
100
|
+
* Meta ZL29: a tile's merged draws are a fine tile's own, the shadows it keeps
|
|
101
|
+
* are within them, and each key is named once (true with none).
|
|
80
102
|
*/
|
|
81
|
-
function
|
|
82
|
-
|
|
83
|
-
|
|
103
|
+
function mergedWithinTile(tile: Readonly<ViewTile>): boolean {
|
|
104
|
+
const { merged } = tile
|
|
105
|
+
if (merged === undefined) {
|
|
106
|
+
return true
|
|
84
107
|
}
|
|
108
|
+
return (
|
|
109
|
+
tile.lod === FINE &&
|
|
110
|
+
merged.draws <= tile.draws &&
|
|
111
|
+
merged.shadows <= merged.draws &&
|
|
112
|
+
new Set(merged.keys).size === merged.keys.length &&
|
|
113
|
+
(merged.vertices === undefined ||
|
|
114
|
+
merged.vertices.length === merged.keys.length)
|
|
115
|
+
)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The fine tiles near fine tile `from`'s centre. */
|
|
119
|
+
function nearTiles(
|
|
120
|
+
tiles: readonly ViewTile[],
|
|
121
|
+
from: ViewTile,
|
|
122
|
+
): readonly ViewTile[] {
|
|
85
123
|
const xAt = centre(from, X_AXIS)
|
|
86
124
|
const zAt = centre(from, Z_AXIS)
|
|
87
|
-
|
|
125
|
+
const near: ViewTile[] = []
|
|
88
126
|
for (const tile of tiles) {
|
|
89
127
|
if (tile.lod === FINE && isNear(tile, xAt, zAt)) {
|
|
90
|
-
|
|
128
|
+
near.push(tile)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return near
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Meta ZL32: each merged key's vertices over the shard's fine tiles (its 500 m
|
|
136
|
+
* cell); a row with no vertices leaves its keys unbounded.
|
|
137
|
+
*/
|
|
138
|
+
function keyVertices(tiles: readonly ViewTile[]): Map<string, number> {
|
|
139
|
+
const totals = new Map<string, number>()
|
|
140
|
+
for (const { lod, merged } of tiles) {
|
|
141
|
+
if (lod === FINE && merged !== undefined) {
|
|
142
|
+
for (const [at, key] of merged.keys.entries()) {
|
|
143
|
+
const own = merged.vertices?.[at] ?? Number.POSITIVE_INFINITY
|
|
144
|
+
totals.set(key, (totals.get(key) ?? NONE) + own)
|
|
145
|
+
}
|
|
91
146
|
}
|
|
92
147
|
}
|
|
93
|
-
return
|
|
148
|
+
return totals
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* One near tile's own draws; its merged keys join `shared`: once the cell,
|
|
153
|
+
* and once a block as well when the key outgrows the cell merge.
|
|
154
|
+
*/
|
|
155
|
+
function tileDraws(
|
|
156
|
+
tile: ViewTile,
|
|
157
|
+
shared: Set<string>,
|
|
158
|
+
totals: ReadonlyMap<string, number>,
|
|
159
|
+
): number {
|
|
160
|
+
const { merged } = tile
|
|
161
|
+
const block = [blockAt(tile, X_AXIS), blockAt(tile, Z_AXIS)].join(',')
|
|
162
|
+
for (const key of merged?.keys ?? []) {
|
|
163
|
+
shared.add([key, CELL].join('@'))
|
|
164
|
+
if ((totals.get(key) ?? NONE) > REGION_VERTICES) {
|
|
165
|
+
shared.add([key, block].join('@'))
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return tile.draws - (merged?.draws ?? NONE) + (merged?.shadows ?? NONE)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The draws of a view from fine tile `from`: every fine tile near its centre
|
|
173
|
+
* at its reported draws, an upper bound. A tile's `merged` draws count as the
|
|
174
|
+
* engine draws them (meta ZONE-SIZE-LIMITS ZL28, ZL29, ZL31, ZL32): each key
|
|
175
|
+
* once the cell while its cell merge holds up to 24k vertices, else once the
|
|
176
|
+
* cell and once a 250 m block, plus the shadow draws the tile keeps for them.
|
|
177
|
+
* A coarse tile's view counts nothing.
|
|
178
|
+
*/
|
|
179
|
+
function viewDraws(tiles: readonly ViewTile[], from: ViewTile): number {
|
|
180
|
+
if (from.lod !== FINE) {
|
|
181
|
+
return NONE
|
|
182
|
+
}
|
|
183
|
+
const shared = new Set<string>()
|
|
184
|
+
const totals = keyVertices(tiles)
|
|
185
|
+
let draws = NONE
|
|
186
|
+
for (const tile of nearTiles(tiles, from)) {
|
|
187
|
+
draws += tileDraws(tile, shared, totals)
|
|
188
|
+
}
|
|
189
|
+
return draws + shared.size
|
|
94
190
|
}
|
|
95
191
|
|
|
96
|
-
export type { ViewTile }
|
|
97
|
-
export { TILE_TRIANGLES, VIEW_DRAWS, viewDraws }
|
|
192
|
+
export type { ViewMerged, ViewTile }
|
|
193
|
+
export { mergedWithinTile, TILE_TRIANGLES, VIEW_DRAWS, viewDraws }
|