@wildshard/shard-format 0.82.2 → 0.82.4
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 +1 -1
- package/src/format/boot-memory-cost.ts +19 -0
- package/src/format/cooked-image-cost.ts +144 -0
- package/src/format/deviceMemoryCost.ts +4 -0
- package/src/format/engine-art.ts +3 -0
- package/src/format/graphArmsRows.ts +5 -2
- package/src/format/memory-line.ts +3 -1
- package/src/format/phone-files.ts +8 -2
- package/src/format/shardfile-assets.ts +4 -1
- package/src/format/shardfileValidation.ts +26 -12
- package/src/format/standalone-art.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.82.
|
|
3
|
+
"version": "0.82.4",
|
|
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": {
|
|
@@ -203,6 +203,24 @@ function mountedImageBytes(path: string, bytes: Readonly<Uint8Array>): number {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
/** The phone loader substitutes a known `.phone.webp` mount for its desktop
|
|
207
|
+
* image. A direct read in the prepared phone fence still counts. */
|
|
208
|
+
function mountedImageOnPhone(
|
|
209
|
+
mount: Readonly<{ url: string; hash: string; keepImage?: boolean }>,
|
|
210
|
+
urls: ReadonlySet<string>,
|
|
211
|
+
phoneFence?: ReadonlySet<string>,
|
|
212
|
+
): boolean {
|
|
213
|
+
if (
|
|
214
|
+
phoneFence === undefined ||
|
|
215
|
+
phoneFence.has(mount.hash) ||
|
|
216
|
+
mount.keepImage === true
|
|
217
|
+
) {
|
|
218
|
+
return true
|
|
219
|
+
}
|
|
220
|
+
const phone = mount.url.replace(/\.(?:png|jpg|webp)$/u, '.phone.webp')
|
|
221
|
+
return phone === mount.url || !urls.has(phone)
|
|
222
|
+
}
|
|
223
|
+
|
|
206
224
|
/** MG6 epoch 4: the phone's playing (settled) and loading-peak estimates of a product's terms. */
|
|
207
225
|
function bootPhoneBytes(
|
|
208
226
|
terms: Readonly<PhoneTerms>,
|
|
@@ -261,6 +279,7 @@ export {
|
|
|
261
279
|
bootMemoryCosts,
|
|
262
280
|
bootPhoneBytes,
|
|
263
281
|
mountedImageBytes,
|
|
282
|
+
mountedImageOnPhone,
|
|
264
283
|
NO_BYTES,
|
|
265
284
|
type PhoneTerms,
|
|
266
285
|
phoneTerms,
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Shardfile } from './shardSchema.ts'
|
|
2
|
+
|
|
3
|
+
/** STANDALONE-SHARDFILES SF5g (J525): a shardfile carries images only, and the cook encodes each texture image to the
|
|
4
|
+
* KTX2 a page reads in its place (blobKtx2), so the memory estimate charges an image as that KTX2. An image row holds no
|
|
5
|
+
* width or height, only `gpu`, its RGBA texels (`stillImage` envelope); textures are square or 2:1, so the size is read
|
|
6
|
+
* back from it, and any other count is charged as the square that holds it. Pine Hollow 0.0.18 was refused at a 1.67 GB
|
|
7
|
+
* phone peak counted as source RGBA, where its hand-made KTX2 sets (0.0.17) had been 1.31 GB. */
|
|
8
|
+
|
|
9
|
+
const RGBA_BYTES = 4
|
|
10
|
+
const WIDE = 2
|
|
11
|
+
const NO_BYTES = 0
|
|
12
|
+
const BLOCK_BYTES = 16
|
|
13
|
+
const BC_BLOCK = 4
|
|
14
|
+
const ASTC_PHONE_BLOCK = 6
|
|
15
|
+
const TEXEL = 1
|
|
16
|
+
|
|
17
|
+
interface Chain {
|
|
18
|
+
readonly block: number
|
|
19
|
+
readonly bytes: number
|
|
20
|
+
}
|
|
21
|
+
const RGBA_CHAIN: Chain = { block: TEXEL, bytes: RGBA_BYTES }
|
|
22
|
+
const BLOCK_CHAIN: Chain = { block: BC_BLOCK, bytes: BLOCK_BYTES }
|
|
23
|
+
const PHONE_CHAIN: Chain = { block: ASTC_PHONE_BLOCK, bytes: BLOCK_BYTES }
|
|
24
|
+
|
|
25
|
+
/** The width and height of an image whose RGBA texels cost `rgba`. */
|
|
26
|
+
function imageSize(rgba: number): readonly [number, number] {
|
|
27
|
+
const texels = Math.ceil(rgba / RGBA_BYTES)
|
|
28
|
+
const side = Math.round(Math.sqrt(texels))
|
|
29
|
+
const wide = Math.round(Math.sqrt(texels * WIDE))
|
|
30
|
+
if (side * side === texels) {
|
|
31
|
+
return [side, side]
|
|
32
|
+
}
|
|
33
|
+
if (wide % WIDE === NO_BYTES && wide * (wide / WIDE) === texels) {
|
|
34
|
+
return [wide, wide / WIDE]
|
|
35
|
+
}
|
|
36
|
+
const square = Math.ceil(Math.sqrt(texels))
|
|
37
|
+
return [square, square]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A full mip chain's bytes, each level in the chain's blocks (a block of one 4-byte texel for RGBA). */
|
|
41
|
+
function mipChainBytes(rgba: number, chain: Chain): number {
|
|
42
|
+
const [width, height] = imageSize(rgba)
|
|
43
|
+
let total = NO_BYTES
|
|
44
|
+
let levelWidth = width
|
|
45
|
+
let levelHeight = height
|
|
46
|
+
for (;;) {
|
|
47
|
+
total +=
|
|
48
|
+
Math.ceil(levelWidth / chain.block) *
|
|
49
|
+
Math.ceil(levelHeight / chain.block) *
|
|
50
|
+
chain.bytes
|
|
51
|
+
if (levelWidth === TEXEL && levelHeight === TEXEL) {
|
|
52
|
+
return total
|
|
53
|
+
}
|
|
54
|
+
levelWidth = Math.max(TEXEL, Math.floor(levelWidth / WIDE))
|
|
55
|
+
levelHeight = Math.max(TEXEL, Math.floor(levelHeight / WIDE))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** What a library image no longer charges once charged as the KTX2 the cook makes from it (`parseKtx2`): its decoded
|
|
60
|
+
* copy, and its GPU bytes become a full mip chain, RGBA without a transcode, 4x4 blocks of 16 bytes with one. */
|
|
61
|
+
function cookedImageSaving(
|
|
62
|
+
file: Readonly<{ decoded: number; gpu: number }>,
|
|
63
|
+
transcodes: boolean,
|
|
64
|
+
): number {
|
|
65
|
+
const cooked = mipChainBytes(file.gpu, transcodes ? BLOCK_CHAIN : RGBA_CHAIN)
|
|
66
|
+
return Math.max(NO_BYTES, file.decoded + file.gpu - cooked)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type ShardFile = Shardfile['files'][number]
|
|
70
|
+
|
|
71
|
+
/** The shard's files by hash. */
|
|
72
|
+
function filesByHash(
|
|
73
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
74
|
+
source: Shardfile,
|
|
75
|
+
): Map<string, ShardFile> {
|
|
76
|
+
const files = new Map<string, ShardFile>()
|
|
77
|
+
for (const file of source.files) {
|
|
78
|
+
files.set(file.hash, file)
|
|
79
|
+
}
|
|
80
|
+
return files
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A file once: the first ask has it, later asks get none. */
|
|
84
|
+
function take(
|
|
85
|
+
files: Map<string, ShardFile>,
|
|
86
|
+
ref: string,
|
|
87
|
+
): ShardFile | undefined {
|
|
88
|
+
const file = files.get(ref)
|
|
89
|
+
files.delete(ref)
|
|
90
|
+
return file
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The library images the shard reaches, its library and their dependencies, each once. */
|
|
94
|
+
function libraryImages(
|
|
95
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
96
|
+
source: Shardfile,
|
|
97
|
+
): ShardFile[] {
|
|
98
|
+
const files = filesByHash(source)
|
|
99
|
+
const pending = [...source.library]
|
|
100
|
+
const images: ShardFile[] = []
|
|
101
|
+
for (let ref = pending.pop(); ref !== undefined; ref = pending.pop()) {
|
|
102
|
+
const file = take(files, ref)
|
|
103
|
+
pending.push(...(file?.dependencies ?? []))
|
|
104
|
+
if (file?.kind === 'image') {
|
|
105
|
+
images.push(file)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return images
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** The shard with every library image charged as the KTX2 the cook makes from it (`cookedImageSaving`, no transcode):
|
|
112
|
+
* what the offline memory lines and the validation receipt judge, as admission's `textureLibrarySource` does. */
|
|
113
|
+
function cookedImageSource(
|
|
114
|
+
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
115
|
+
source: Shardfile,
|
|
116
|
+
): Shardfile {
|
|
117
|
+
let saving = NO_BYTES
|
|
118
|
+
for (const file of libraryImages(source)) {
|
|
119
|
+
saving += cookedImageSaving(file, false)
|
|
120
|
+
}
|
|
121
|
+
if (saving === NO_BYTES) {
|
|
122
|
+
return source
|
|
123
|
+
}
|
|
124
|
+
const { library } = source.budgets
|
|
125
|
+
return {
|
|
126
|
+
...source,
|
|
127
|
+
budgets: {
|
|
128
|
+
...source.budgets,
|
|
129
|
+
library: {
|
|
130
|
+
...library,
|
|
131
|
+
resident: Math.max(NO_BYTES, library.resident - saving),
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The GPU bytes of the phone file the cook makes from an image whose RGBA texels cost `rgba` (an image row's `gpu`):
|
|
138
|
+
* ASTC 6x6, 16 bytes a 6x6 block, with its mip chain. Charged at the image's own size, though the cook trims most phone
|
|
139
|
+
* rows to 512 (`phoneTierSize`): a ground layer or a sky keeps its size, and a row can't tell them apart. */
|
|
140
|
+
function cookedPhoneGpu(rgba: number): number {
|
|
141
|
+
return mipChainBytes(rgba, PHONE_CHAIN)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { cookedImageSaving, cookedImageSource, cookedPhoneGpu }
|
|
@@ -4,6 +4,7 @@ import { worstContentCostSteps, type worstContentCost } from './budget.ts';
|
|
|
4
4
|
import type { Shardfile } from './shardSchema.ts';
|
|
5
5
|
import type { MemoryAdmission } from './memoryAdmission.ts';
|
|
6
6
|
import { parseKtx2, ktx2DeviceGpu, type Ktx2DeviceCosts } from './ktx2Cost.ts';
|
|
7
|
+
import { cookedImageSaving } from './cooked-image-cost.ts';
|
|
7
8
|
|
|
8
9
|
/** Apply the existing total-memory policy to declared or measured costs. */
|
|
9
10
|
export function acceptsShardfileCost(memory: MemoryAdmission | undefined, source: Shardfile, stage: 'declared' | 'actual', cost: ReturnType<typeof worstContentCost>): boolean {
|
|
@@ -30,6 +31,9 @@ export function textureLibrarySource(source: Shardfile, assets: ReadonlyMap<stri
|
|
|
30
31
|
seen.add(ref);
|
|
31
32
|
const file = files.get(ref); if (file === undefined) continue;
|
|
32
33
|
pending.push(...file.dependencies);
|
|
34
|
+
if (file.kind === 'image') {
|
|
35
|
+
saving += cookedImageSaving(file, transcodes);
|
|
36
|
+
}
|
|
33
37
|
if (file.kind !== 'ktx2') continue;
|
|
34
38
|
saving += file.decoded;
|
|
35
39
|
if (!transcodes) continue;
|
package/src/format/engine-art.ts
CHANGED
|
@@ -38,6 +38,9 @@ export const ENGINE_ART: ReadonlySet<string> = new Set([
|
|
|
38
38
|
'/assets/music/piano/sting-death-8ee9ff5d.m4a',
|
|
39
39
|
'/assets/music/piano/sting-pickup-5ba19a30.m4a',
|
|
40
40
|
'/assets/music/piano/title-7ce82663.m4a',
|
|
41
|
+
// The engine's build copies the physics binary here (engine vite/rapier.ts); it is gitignored, so not in SF1's list.
|
|
42
|
+
// A shard's boot rows name it through the SDK's sharedBootPhysics (opus-pine, Pine Hollow's shardVersion build).
|
|
43
|
+
'/assets/physics/rapier.wasm',
|
|
41
44
|
'/assets/practice/dummies/straw-cloth.glb',
|
|
42
45
|
'/assets/practice/dummies/unimate-motion.glb',
|
|
43
46
|
'/assets/practice/dummies/wood-steel.glb',
|
|
@@ -8,6 +8,7 @@ const names: v.GenericSchema<string[], string[]> & { readonly pipe: readonly [un
|
|
|
8
8
|
v.check(rows => new Set(rows).size === rows.length));
|
|
9
9
|
const count = v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(4096));
|
|
10
10
|
const bounded = <T extends v.GenericSchema>(schema: T, max: number) => v.pipe(v.array(schema), v.maxLength(max));
|
|
11
|
+
const imageExtension = v.exactOptional(v.picklist(['webp', 'png']));
|
|
11
12
|
/** G475 held arms drawn in graph looks: a skinned rig played by the shared arm player (its blade row is the hit sweep's
|
|
12
13
|
* and the swing trail's), its meshes dressed from rows, the trail sampled along the blade during each swing, and the
|
|
13
14
|
* per-frame look writes as named sources. Client-only presentation; ids only, no callbacks. */
|
|
@@ -23,8 +24,8 @@ export const GraphArmsSchema: v.StrictObjectSchema<{ readonly rig: v.GenericSche
|
|
|
23
24
|
/** every look's params, by look id; a frame source with no look writes each look that declares its param */
|
|
24
25
|
params: v.record(name, bounded(name, 128)),
|
|
25
26
|
meshes: bounded(v.strictObject({ name, channels: v.record(name, name), look: name, maps: v.exactOptional(name), hull: v.boolean(), doubleSide: v.boolean() }), 64),
|
|
26
|
-
/**
|
|
27
|
-
maps: v.strictObject({ base: name, names, kinds: v.strictObject({ maps: name, nrm: name }), anisotropy: finite }),
|
|
27
|
+
/** Per-mesh map pairs at `<base><name>-<kind>.<imageExtension>`, WebP for existing rows. */
|
|
28
|
+
maps: v.strictObject({ base: name, names, kinds: v.strictObject({ maps: name, nrm: name }), anisotropy: finite, imageExtension }),
|
|
28
29
|
/** an R8 repeating weave and per-tier lossless decal images, all named product files */
|
|
29
30
|
weave: v.strictObject({ file: name, size: count, param: name }),
|
|
30
31
|
decal: v.strictObject({ files: v.strictObject({ phone: name, desktop: name }), param: name }),
|
|
@@ -89,6 +90,7 @@ interface GraphArmsRowInputFields {
|
|
|
89
90
|
nrm: string;
|
|
90
91
|
};
|
|
91
92
|
anisotropy: number;
|
|
93
|
+
imageExtension?: 'webp' | 'png';
|
|
92
94
|
};
|
|
93
95
|
weave: {
|
|
94
96
|
file: string;
|
|
@@ -168,6 +170,7 @@ interface GraphArmsRowFields {
|
|
|
168
170
|
nrm: string;
|
|
169
171
|
};
|
|
170
172
|
anisotropy: number;
|
|
173
|
+
imageExtension?: 'webp' | 'png';
|
|
171
174
|
};
|
|
172
175
|
weave: {
|
|
173
176
|
file: string;
|
|
@@ -2,6 +2,7 @@ import { parse } from 'valibot'
|
|
|
2
2
|
|
|
3
3
|
import { bootMemoryCosts } from './boot-memory-cost.ts'
|
|
4
4
|
import { worstContentCost } from './budget.ts'
|
|
5
|
+
import { cookedImageSource } from './cooked-image-cost.ts'
|
|
5
6
|
import {
|
|
6
7
|
ARMED_LINES,
|
|
7
8
|
armedZone,
|
|
@@ -139,7 +140,8 @@ function offlineMemoryIssues(
|
|
|
139
140
|
(sum, row): number => sum + row.decoded + row.gpu,
|
|
140
141
|
EMPTY_BYTES,
|
|
141
142
|
)
|
|
142
|
-
|
|
143
|
+
// SF5g: a library image is charged as the KTX2 the cook makes from it (J525).
|
|
144
|
+
const cost = worstContentCost(cookedImageSource(source), {
|
|
143
145
|
commons: runtime + commons,
|
|
144
146
|
boot: bootMemoryCosts(source, sections, { mountedImages, index }),
|
|
145
147
|
})
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// MEMORY-GATES MG6 epoch 5 (mini-em11b): the files a phone never fetches, for the offline estimate's terms.
|
|
2
|
+
import { cookedPhoneGpu } from './cooked-image-cost.ts'
|
|
2
3
|
import { tierLibrarySteps } from './tierSelection.ts'
|
|
3
4
|
|
|
4
5
|
import type { Shardfile } from './shardSchema.ts'
|
|
@@ -51,8 +52,12 @@ function contentBytes(
|
|
|
51
52
|
let bytes = mountedImages
|
|
52
53
|
for (const file of shard.files) {
|
|
53
54
|
if (!inactive.has(file.hash)) {
|
|
55
|
+
// SF5g (J525): the cook encodes an image to the KTX2 a phone uploads, so the phone never decodes it.
|
|
54
56
|
bytes +=
|
|
55
|
-
file.compressed +
|
|
57
|
+
file.compressed +
|
|
58
|
+
(file.kind === 'audio' || file.kind === 'image'
|
|
59
|
+
? NO_BYTES
|
|
60
|
+
: file.decoded)
|
|
56
61
|
}
|
|
57
62
|
}
|
|
58
63
|
for (const wire of Object.values(shard.requires.commonsWire)) {
|
|
@@ -74,7 +79,8 @@ function gpuBytes(
|
|
|
74
79
|
let bytes = NO_BYTES
|
|
75
80
|
for (const file of shard.files) {
|
|
76
81
|
if (kinds.has(file.kind) && !inactive.has(file.hash)) {
|
|
77
|
-
|
|
82
|
+
// SF5g (J525): an image uploads as the cook's phone ASTC 6x6 file, not as RGBA.
|
|
83
|
+
bytes += file.kind === 'image' ? cookedPhoneGpu(file.gpu) : file.gpu
|
|
78
84
|
}
|
|
79
85
|
}
|
|
80
86
|
return bytes
|
|
@@ -19,6 +19,7 @@ import type { Judged } from './policy-verdict.ts';
|
|
|
19
19
|
import { staleRuntimeIssues } from './memory-epoch.ts';
|
|
20
20
|
import { MEMORY_HARD_BYTES, memoryLineIssues, runtimeOfflineBytes } from './memory-line.ts';
|
|
21
21
|
import { bootMemoryCosts } from './boot-memory-cost.ts';
|
|
22
|
+
import { cookedImageSource } from './cooked-image-cost.ts';
|
|
22
23
|
import type { TierIndex } from './phone-files.ts';
|
|
23
24
|
import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
|
|
24
25
|
import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
|
|
@@ -35,7 +36,9 @@ interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sect
|
|
|
35
36
|
function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number; index?: TierIndex }>): PerformanceReport['memory'] {
|
|
36
37
|
const commons = nativeBytes + Object.values(source.requires.commonsCosts).reduce((sum, row) => sum + row.decoded + row.gpu, 0);
|
|
37
38
|
const budget = { commons, boot: bootMemoryCosts(source, options.sections, options) };
|
|
38
|
-
|
|
39
|
+
// SF5g: a library image is charged as the KTX2 the cook makes from it (J525).
|
|
40
|
+
const cooked = cookedImageSource(source);
|
|
41
|
+
return { near: nearbyContentCost(cooked, source.spawn.x, source.spawn.z, budget), worst: worstContentCost(cooked, budget), playingLimit: ARMED_LINES.playing, loadingLimit: ARMED_LINES.loading };
|
|
39
42
|
}
|
|
40
43
|
/** A performance issue's code and its metric words. */
|
|
41
44
|
type Named = readonly [code: IssueCodeOf<'performance'>, metric: string];
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { assertShardMountUrls, assertStandaloneArt, readDiscoveryArt } from './standalone-art.ts';
|
|
2
2
|
import { cookMountPath, readCookData } from './cook-data.ts';
|
|
3
|
+
import type { CookData, CookMount } from './cook-data.ts';
|
|
3
4
|
import { checkDiscoveryMount, isDiscoveryMount } from './manifest-deprecations.ts';
|
|
4
|
-
import { requireCookPreparation } from './cook-preparation.ts';
|
|
5
|
+
import { isPreparedCook, requireCookPreparation } from './cook-preparation.ts';
|
|
5
6
|
import { declaredSourceMatches, parseIncomingIndex, validateIncomingSection } from './incoming.ts';
|
|
6
7
|
import { assembleOutputShardfile, type OutputFile, type OutputIndex } from './outputIndex.ts';
|
|
7
8
|
import { decisionModuleContracts, scriptAdmissionRows, type ScriptAdmissionRows, type ScriptContract } from './scriptContract.ts';
|
|
@@ -28,7 +29,7 @@ import { memoryContext, offlineMemoryIssues } from './memory-line.ts';
|
|
|
28
29
|
import { armedZone } from './memory-armed.ts';
|
|
29
30
|
import { runtimeTierIssues } from './runtime-tier.ts';
|
|
30
31
|
import type { MemoryContext } from './memory-line.ts';
|
|
31
|
-
import { mountedImageBytes, NO_BYTES } from './boot-memory-cost.ts';
|
|
32
|
+
import { mountedImageBytes, mountedImageOnPhone, NO_BYTES } from './boot-memory-cost.ts';
|
|
32
33
|
import { admittedVerdict, policyVerdict, recordVerdict } from './policy-verdict.ts';
|
|
33
34
|
import type { Judged, PolicyVerdict } from './policy-verdict.ts';
|
|
34
35
|
import { deprecationReport } from './deprecations.ts';
|
|
@@ -210,21 +211,34 @@ function checkServerAndKtx2(index: OutputIndex, read: ReadListed, assets: Readon
|
|
|
210
211
|
});
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
|
|
214
|
+
type MountInventory = Readonly<{ formatVersion: OutputIndex['formatVersion']; files: readonly Readonly<Pick<OutputFile, 'hash' | 'path' | 'compressed'>>[] }>;
|
|
215
|
+
|
|
216
|
+
/** C0 (J137): verify every cook mount, even a desktop image the phone never requests. */
|
|
217
|
+
function checkedMountImageBytes(index: MountInventory, mount: Readonly<CookMount>, options: Readonly<{ read: ReadListed; onPhone: boolean }>): number {
|
|
218
|
+
if (mountSharesBlob(mount, index.files)) { return NO_BYTES; }
|
|
219
|
+
if (mount.path !== cookMountPath(mount.url)) { throw new Error(`Mount path differs from its URL: ${mount.url}`); }
|
|
220
|
+
const bytes = checkDiscoveryMount(index.formatVersion, mount.path, options.read(mount));
|
|
221
|
+
return options.onPhone ? mountedImageBytes(mount.path, bytes) : NO_BYTES;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function checkedMountImages(index: MountInventory, read: ReadListed, cook: CookData | undefined): number {
|
|
225
|
+
const mounts = cook?.mounts ?? [];
|
|
226
|
+
const urls = new Set(mounts.map((mount): string => mount.url));
|
|
227
|
+
const phoneFence = isPreparedCook(cook) && cook?.fence !== undefined ? new Set(cook.fence) : undefined;
|
|
228
|
+
let mountedImages = NO_BYTES;
|
|
229
|
+
for (const mount of mounts) {
|
|
230
|
+
mountedImages += checkedMountImageBytes(index, mount, { read, onPhone: mountedImageOnPhone(mount, urls, phoneFence) });
|
|
231
|
+
}
|
|
232
|
+
return mountedImages;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** The cook file and the mounted engine images measured alongside its own images. */
|
|
214
236
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- valibot's output type, only read
|
|
215
237
|
function readCook(index: OutputIndex, read: ReadListed, ports: Pick<ShardfileValidationPorts, 'hash' | 'preparation'>): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } {
|
|
216
238
|
return coded('cook-invalid', (): { cook: ReturnType<typeof readCookData> | undefined; mountedImages: number } => {
|
|
217
239
|
const cook = index.cook === undefined ? undefined : readCookData(readCanonicalJson(read(index.cook)));
|
|
218
240
|
if (ports.preparation !== 'migrated') { coded('preparation-invalid', (): void => { requireCookPreparation(index, cook, ports.hash); }); }
|
|
219
|
-
|
|
220
|
-
for (const mount of cook?.mounts ?? []) {
|
|
221
|
-
if (!mountSharesBlob(mount, index.files)) {
|
|
222
|
-
if (mount.path !== cookMountPath(mount.url)) { throw new Error(`Mount path differs from its URL: ${mount.url}`); }
|
|
223
|
-
// MG6 epoch 3: the engine images a shard mounts decode at boot like its own (Far Reach's sky and textures).
|
|
224
|
-
mountedImages += mountedImageBytes(mount.path, checkDiscoveryMount(index.formatVersion, mount.path, read(mount)));
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return { cook, mountedImages };
|
|
241
|
+
return { cook, mountedImages: checkedMountImages(index, read, cook) };
|
|
228
242
|
});
|
|
229
243
|
}
|
|
230
244
|
|
|
@@ -40,7 +40,29 @@ function skyCovered(stem: string, mounts: ReadonlySet<string>): boolean {
|
|
|
40
40
|
)
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/** A URL template (`/assets/z/hdri/{id}_2k.key.jpg`, a keyed sky's files) names at least one supplied file. */
|
|
44
|
+
function templateCovered(url: string, mounts: ReadonlySet<string>): boolean {
|
|
45
|
+
const pattern = new RegExp(
|
|
46
|
+
`^${url
|
|
47
|
+
.split(/\{[a-z][a-zA-Z0-9]*\}/u)
|
|
48
|
+
.map((part: string): string =>
|
|
49
|
+
part.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`),
|
|
50
|
+
)
|
|
51
|
+
.join('[^/]+')}$`,
|
|
52
|
+
'u',
|
|
53
|
+
)
|
|
54
|
+
for (const path of [...mounts, ...ENGINE_ART]) {
|
|
55
|
+
if (pattern.test(path)) {
|
|
56
|
+
return true
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
|
|
43
62
|
function covered(url: string, mounts: ReadonlySet<string>): boolean {
|
|
63
|
+
if (/\{[a-z][a-zA-Z0-9]*\}/u.test(url)) {
|
|
64
|
+
return templateCovered(url, mounts)
|
|
65
|
+
}
|
|
44
66
|
if (
|
|
45
67
|
supplied(url, mounts) ||
|
|
46
68
|
(url.includes('/hdri/') && skyCovered(url, mounts))
|