@wildshard/shard-format 0.25.0 → 0.27.0
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 +4 -1
- package/src/format/actorMoves.ts +32 -0
- package/src/format/audio-mp4.ts +1 -1
- package/src/format/audioProfiles.ts +1 -1
- package/src/format/boot-memory-cost.ts +93 -2
- package/src/format/brains.ts +3 -3
- package/src/format/budget-tiers.ts +62 -0
- package/src/format/builtIndexes.ts +2 -2
- package/src/format/clientChannels.ts +3 -3
- package/src/format/clientScripts.ts +1 -1
- package/src/format/contentBounds.ts +1 -1
- package/src/format/contentCost.ts +2 -1
- package/src/format/creature-layers.ts +13 -1
- package/src/format/creature-ranks.ts +37 -0
- package/src/format/creature-sizes.ts +45 -4
- package/src/format/creature-volumes.ts +5 -4
- package/src/format/creatures.ts +20 -3
- package/src/format/crowds.ts +1 -1
- package/src/format/deviceMemoryCost.ts +2 -2
- package/src/format/directorStages.ts +3 -3
- package/src/format/flyers.ts +2 -2
- package/src/format/grazers.ts +2 -2
- package/src/format/items.ts +1 -1
- package/src/format/materialGraph.ts +7 -7
- package/src/format/materials.ts +10 -10
- package/src/format/memory-epoch.ts +1 -1
- package/src/format/memory-line.ts +48 -5
- package/src/format/memoryAdmission.ts +1 -1
- package/src/format/namedJsonContracts.ts +1 -1
- package/src/format/nativeGround.ts +3 -3
- package/src/format/navigation.ts +2 -2
- package/src/format/parsed-json.ts +91 -0
- package/src/format/placement-page-text.ts +281 -0
- package/src/format/questHost.ts +1 -1
- package/src/format/rows.ts +18 -5
- package/src/format/runtime-tier.ts +56 -0
- package/src/format/runtimeBinds.ts +6 -6
- package/src/format/runtimeCost.ts +1 -1
- package/src/format/runtimeSpawns.ts +2 -2
- package/src/format/scaledPostContract.ts +2 -2
- package/src/format/scriptAbi.ts +1 -1
- package/src/format/scriptWireV2.ts +1 -1
- package/src/format/shardSchema.ts +2 -2
- package/src/format/shardSections.ts +7 -1
- package/src/format/shardfile-assets.ts +9 -10
- package/src/format/shardfileValidation.ts +17 -11
- package/src/format/skin-file.ts +3 -0
- package/src/format/skinData.ts +39 -19
- package/src/format/skins.ts +21 -2
- package/src/format/sourceResidency.ts +1 -1
- package/src/format/standalone-catalogue.ts +1 -1
- package/src/format/terrain.ts +1 -1
- package/src/format/validationReceipt.ts +2 -2
- package/src/format/weaponProfiles.ts +2 -2
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { fields, items, listOf, own, parsedJsonFits } from './parsed-json.ts'
|
|
2
|
+
import { parseWorldScenePlacementPage } from './worldScenePlacement.ts'
|
|
3
|
+
|
|
4
|
+
import type { Check, Fields } from './parsed-json.ts'
|
|
5
|
+
import type { WorldScenePlacementPage } from './worldScenePlacement.ts'
|
|
6
|
+
|
|
7
|
+
// MG10 / ENGINE-MEMORY EM17: a placement page read straight from its text.
|
|
8
|
+
// Nine's boot allocated about 110 MB parsing 6 MB of pages: the JSON guard's
|
|
9
|
+
// property descriptors, entry and item copies, valibot's rebuilt output and
|
|
10
|
+
// the failed branch of the pose union. A value fresh from `JSON.parse` is plain
|
|
11
|
+
// data by construction (own enumerable data properties, ordinary prototypes,
|
|
12
|
+
// dense arrays, no symbols, accessors or cycles), so the guard reduces to its
|
|
13
|
+
// node and depth bounds and canonical numbers. A page whose every object,
|
|
14
|
+
// tuple and record matches the schema exactly is already what valibot would
|
|
15
|
+
// rebuild, so it is admitted as it stands. Anything else takes
|
|
16
|
+
// `parseWorldScenePlacementPage`, which stays the contract and the only source
|
|
17
|
+
// of refusals: this path never admits a page that one refuses (the
|
|
18
|
+
// differential fuzz in the test).
|
|
19
|
+
|
|
20
|
+
type Entries = readonly (readonly [string, Check])[]
|
|
21
|
+
|
|
22
|
+
const NONE = 0
|
|
23
|
+
const ONE = 1
|
|
24
|
+
const COORD_LIMIT = 1e6
|
|
25
|
+
const ID_MAX = 256
|
|
26
|
+
const ROWS_MAX = 16
|
|
27
|
+
const POSES_MAX = 8192
|
|
28
|
+
const BOXES_MAX = 49_152
|
|
29
|
+
const BOX_STRIDE = 6
|
|
30
|
+
const COLLIDERS_MAX = 32_768
|
|
31
|
+
const FLOORS_MAX = 4096
|
|
32
|
+
const KNOTS_MIN = 2
|
|
33
|
+
const KNOTS_MAX = 8
|
|
34
|
+
const SPLIT_MAX = 2048
|
|
35
|
+
const PAIR = 2
|
|
36
|
+
const TRIPLE = 3
|
|
37
|
+
const MATRIX = 16
|
|
38
|
+
|
|
39
|
+
const has = (value: object, key: string): boolean => Object.hasOwn(value, key)
|
|
40
|
+
const poseFits = (pose: unknown): boolean => parsedJsonFits(pose)
|
|
41
|
+
|
|
42
|
+
/** `placementPageData`'s verdict for a `JSON.parse` value. */
|
|
43
|
+
function parsedPageData(page: unknown): boolean {
|
|
44
|
+
const rows = fields(page) ? items(own(page, 'rows')) : undefined
|
|
45
|
+
if (rows === undefined || rows.length > ROWS_MAX) {
|
|
46
|
+
return false
|
|
47
|
+
}
|
|
48
|
+
if (rows.length !== ONE) {
|
|
49
|
+
return parsedJsonFits(page)
|
|
50
|
+
}
|
|
51
|
+
const [row] = rows
|
|
52
|
+
return (
|
|
53
|
+
parsedJsonFits(page, 'rows') &&
|
|
54
|
+
fields(row) &&
|
|
55
|
+
parsedJsonFits(row, 'poses') &&
|
|
56
|
+
listOf(own(row, 'poses'), POSES_MAX, poseFits)
|
|
57
|
+
)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const idOk = (value: unknown): boolean =>
|
|
61
|
+
typeof value === 'string' && value.length > NONE && value.length <= ID_MAX
|
|
62
|
+
const finiteOk = (value: unknown): value is number =>
|
|
63
|
+
typeof value === 'number' &&
|
|
64
|
+
Number.isFinite(value) &&
|
|
65
|
+
value >= -COORD_LIMIT &&
|
|
66
|
+
value <= COORD_LIMIT
|
|
67
|
+
const distanceOk = (value: unknown): boolean => finiteOk(value) && value >= NONE
|
|
68
|
+
const boolOk = (value: unknown): boolean => typeof value === 'boolean'
|
|
69
|
+
const finites = (value: unknown, length: number): value is readonly number[] =>
|
|
70
|
+
Array.isArray(value) &&
|
|
71
|
+
value.length === length &&
|
|
72
|
+
listOf(value, length, finiteOk)
|
|
73
|
+
const pairOk = (value: unknown): boolean => finites(value, PAIR)
|
|
74
|
+
const tripleOk = (value: unknown): boolean => finites(value, TRIPLE)
|
|
75
|
+
const matrixOk = (value: unknown): boolean => finites(value, MATRIX)
|
|
76
|
+
const oneOf =
|
|
77
|
+
(...options: readonly unknown[]): Check =>
|
|
78
|
+
(value: unknown): boolean =>
|
|
79
|
+
options.includes(value)
|
|
80
|
+
|
|
81
|
+
/** Every key of `value`, inherited enumerable ones too (valibot's strict check reads them), is known. */
|
|
82
|
+
function keysWithin(value: Fields, known: ReadonlySet<string>): boolean {
|
|
83
|
+
for (const key in value) {
|
|
84
|
+
if (!known.has(key)) {
|
|
85
|
+
return false
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return true
|
|
89
|
+
}
|
|
90
|
+
/** Absent, or own and passing: an inherited value would be rebuilt as own. */
|
|
91
|
+
const optional = (value: Fields, key: string, check: Check): boolean =>
|
|
92
|
+
!(key in value) || (has(value, key) && check(value[key]))
|
|
93
|
+
function allPass(value: Fields, entries: Entries, need: boolean): boolean {
|
|
94
|
+
for (const [key, check] of entries) {
|
|
95
|
+
if (
|
|
96
|
+
need
|
|
97
|
+
? !has(value, key) || !check(value[key])
|
|
98
|
+
: !optional(value, key, check)
|
|
99
|
+
) {
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return true
|
|
104
|
+
}
|
|
105
|
+
/** A strict object of `need` and `may` fields, its key lists built once. */
|
|
106
|
+
function strictShape(
|
|
107
|
+
need: Readonly<Record<string, Check>>,
|
|
108
|
+
may: Readonly<Record<string, Check>>,
|
|
109
|
+
): Check {
|
|
110
|
+
const known = new Set([...Object.keys(need), ...Object.keys(may)])
|
|
111
|
+
const needed: Entries = Object.entries(need)
|
|
112
|
+
const allowed: Entries = Object.entries(may)
|
|
113
|
+
return (value: unknown): boolean =>
|
|
114
|
+
fields(value) &&
|
|
115
|
+
keysWithin(value, known) &&
|
|
116
|
+
allPass(value, needed, true) &&
|
|
117
|
+
allPass(value, allowed, false)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Valibot's record drops these keys from its output.
|
|
121
|
+
const DROPPED = new Set(['__proto__', 'prototype', 'constructor'])
|
|
122
|
+
function paramsOk(value: unknown): boolean {
|
|
123
|
+
if (!fields(value)) {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
126
|
+
for (const key in value) {
|
|
127
|
+
if (!has(value, key) || DROPPED.has(key) || !idOk(key)) {
|
|
128
|
+
return false
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return true
|
|
132
|
+
}
|
|
133
|
+
const AXES = ['x', 'y', 'z'] as const
|
|
134
|
+
const axes = (
|
|
135
|
+
...more: readonly (readonly [string, Check])[]
|
|
136
|
+
): Record<string, Check> =>
|
|
137
|
+
Object.fromEntries([
|
|
138
|
+
...AXES.map((axis): [string, Check] => [axis, finiteOk]),
|
|
139
|
+
...more,
|
|
140
|
+
])
|
|
141
|
+
const yxzOk = strictShape(
|
|
142
|
+
{ scale: finiteOk, yaw: finiteOk },
|
|
143
|
+
{ pitch: finiteOk, roll: finiteOk, yawAtan2: pairOk },
|
|
144
|
+
)
|
|
145
|
+
const POSE_MAY = { color: tripleOk, params: paramsOk, variant: idOk }
|
|
146
|
+
const matrixPoseOk = strictShape(axes(['matrix', matrixOk]), POSE_MAY)
|
|
147
|
+
const yxzPoseOk = strictShape(axes(['yxz', yxzOk]), POSE_MAY)
|
|
148
|
+
// The schema's pose union: one of its two strict objects, never both.
|
|
149
|
+
function poseOk(value: unknown): boolean {
|
|
150
|
+
if (!fields(value)) {
|
|
151
|
+
return false
|
|
152
|
+
}
|
|
153
|
+
const matrix = has(value, 'matrix')
|
|
154
|
+
if (matrix === has(value, 'yxz')) {
|
|
155
|
+
return false
|
|
156
|
+
}
|
|
157
|
+
return matrix ? matrixPoseOk(value) : yxzPoseOk(value)
|
|
158
|
+
}
|
|
159
|
+
const tierPairOk = strictShape({ desktop: distanceOk, phone: distanceOk }, {})
|
|
160
|
+
const tierNumberOk = (value: unknown): boolean =>
|
|
161
|
+
distanceOk(value) || tierPairOk(value)
|
|
162
|
+
const cullOk = strictShape(
|
|
163
|
+
{},
|
|
164
|
+
{
|
|
165
|
+
bounds: oneOf('sphere', 'box'),
|
|
166
|
+
far: tierNumberOk,
|
|
167
|
+
flat: boolOk,
|
|
168
|
+
from: oneOf('origin', 'bounds'),
|
|
169
|
+
frustum: boolOk,
|
|
170
|
+
keepNear: finiteOk,
|
|
171
|
+
lodBy: oneOf('copy', 'set'),
|
|
172
|
+
minAngular: tierNumberOk,
|
|
173
|
+
radiusBias: finiteOk,
|
|
174
|
+
step: distanceOk,
|
|
175
|
+
view: oneOf('forest'),
|
|
176
|
+
},
|
|
177
|
+
)
|
|
178
|
+
const boxesOk = (value: unknown): boolean =>
|
|
179
|
+
listOf(value, BOXES_MAX, finiteOk) &&
|
|
180
|
+
Array.isArray(value) &&
|
|
181
|
+
value.length % BOX_STRIDE === NONE
|
|
182
|
+
const drawnIntoOk = strictShape({ boxes: boxesOk, part: idOk }, {})
|
|
183
|
+
// Knots rise strictly along their first value; heights are distances.
|
|
184
|
+
function knotOk(knot: unknown): boolean {
|
|
185
|
+
if (!finites(knot, TRIPLE)) {
|
|
186
|
+
return false
|
|
187
|
+
}
|
|
188
|
+
const [, height] = knot
|
|
189
|
+
return distanceOk(height)
|
|
190
|
+
}
|
|
191
|
+
function rises(knots: readonly unknown[]): boolean {
|
|
192
|
+
let before = Number.NEGATIVE_INFINITY
|
|
193
|
+
for (const knot of knots) {
|
|
194
|
+
const [along = Number.NaN] = finites(knot, TRIPLE) ? knot : []
|
|
195
|
+
if (!(along > before)) {
|
|
196
|
+
return false
|
|
197
|
+
}
|
|
198
|
+
before = along
|
|
199
|
+
}
|
|
200
|
+
return true
|
|
201
|
+
}
|
|
202
|
+
function profileOk(value: unknown): boolean {
|
|
203
|
+
const knots = items(value)
|
|
204
|
+
return (
|
|
205
|
+
knots !== undefined &&
|
|
206
|
+
knots.length >= KNOTS_MIN &&
|
|
207
|
+
listOf(knots, KNOTS_MAX, knotOk) &&
|
|
208
|
+
rises(knots)
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
const floorOk = strictShape(
|
|
212
|
+
{ ...axes(), hd: distanceOk, hw: distanceOk },
|
|
213
|
+
{ profile: profileOk, rot: finiteOk, slope: finiteOk, tilt: finiteOk },
|
|
214
|
+
)
|
|
215
|
+
const splitOk = (value: unknown): boolean =>
|
|
216
|
+
typeof value === 'number' &&
|
|
217
|
+
Number.isInteger(value) &&
|
|
218
|
+
value >= ONE &&
|
|
219
|
+
value <= SPLIT_MAX
|
|
220
|
+
const pieceOk = strictShape(
|
|
221
|
+
{ id: idOk },
|
|
222
|
+
{
|
|
223
|
+
floorPolicy: oneOf('first', 'highest'),
|
|
224
|
+
floors: (value: unknown): boolean => listOf(value, FLOORS_MAX, floorOk),
|
|
225
|
+
follows: oneOf('copy'),
|
|
226
|
+
name: idOk,
|
|
227
|
+
solidFloor: boolOk,
|
|
228
|
+
split: splitOk,
|
|
229
|
+
},
|
|
230
|
+
)
|
|
231
|
+
const rowOk = strictShape(
|
|
232
|
+
{
|
|
233
|
+
draw: oneOf('single', 'instanced', 'batched', 'merged'),
|
|
234
|
+
id: idOk,
|
|
235
|
+
model: idOk,
|
|
236
|
+
poses: (value: unknown): boolean => listOf(value, POSES_MAX, poseOk),
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
batch: idOk,
|
|
240
|
+
colliders: (value: unknown): boolean =>
|
|
241
|
+
Array.isArray(value) && value.length <= COLLIDERS_MAX,
|
|
242
|
+
cull: cullOk,
|
|
243
|
+
drawnInto: drawnIntoOk,
|
|
244
|
+
name: idOk,
|
|
245
|
+
piece: pieceOk,
|
|
246
|
+
sortObjects: boolOk,
|
|
247
|
+
tier: oneOf('phone', 'desktop'),
|
|
248
|
+
},
|
|
249
|
+
)
|
|
250
|
+
const rowId = (row: unknown): unknown => (fields(row) ? own(row, 'id') : row)
|
|
251
|
+
const rowsOk = (value: unknown): boolean =>
|
|
252
|
+
listOf(value, ROWS_MAX, rowOk) &&
|
|
253
|
+
Array.isArray(value) &&
|
|
254
|
+
value.length > NONE &&
|
|
255
|
+
new Set(value.map((row: unknown): unknown => rowId(row))).size ===
|
|
256
|
+
value.length
|
|
257
|
+
const pageShapeOk = strictShape({ rows: rowsOk, version: oneOf(ONE) }, {})
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* True when `value`, fresh from `JSON.parse`, is a placement page
|
|
261
|
+
* `parseWorldScenePlacementPage` admits and would rebuild unchanged (key order
|
|
262
|
+
* aside). False is no verdict: the caller asks the schema. Only for
|
|
263
|
+
* `JSON.parse` output; another value may carry accessors or prototypes.
|
|
264
|
+
*/
|
|
265
|
+
function plainPlacementPage(value: unknown): value is WorldScenePlacementPage {
|
|
266
|
+
return parsedPageData(value) && pageShapeOk(value)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* A placement page from its JSON text, as the client reads it: admitted as it
|
|
271
|
+
* stands when it is plain and exact, otherwise through
|
|
272
|
+
* `parseWorldScenePlacementPage` (its output, or its refusal).
|
|
273
|
+
*/
|
|
274
|
+
function parseWorldScenePlacementPageText(
|
|
275
|
+
text: string,
|
|
276
|
+
): WorldScenePlacementPage {
|
|
277
|
+
const value: unknown = JSON.parse(text)
|
|
278
|
+
return plainPlacementPage(value) ? value : parseWorldScenePlacementPage(value)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export { parseWorldScenePlacementPageText, plainPlacementPage }
|
package/src/format/questHost.ts
CHANGED
|
@@ -105,7 +105,7 @@ export const QuestHostSchema: v.GenericSchema<unknown, QuestHostRow> = v.pipe(ra
|
|
|
105
105
|
/** Compile the bounded graph, command and stage composition without installing runtime services. */
|
|
106
106
|
export function parseQuestHost(input: unknown): QuestHostRow { return v.parse(QuestHostSchema, input); }
|
|
107
107
|
|
|
108
|
-
/** Root admission binds a native quest host to declared flags and its existing
|
|
108
|
+
/** Root admission binds a native quest host to declared flags and its existing runtime quest owner. */
|
|
109
109
|
export function questHostBindingRules(row: QuestHostRow | null | undefined, flags: readonly string[], bound: boolean): readonly string[] {
|
|
110
110
|
if (row === null || row === undefined) return [];
|
|
111
111
|
const errors: string[] = [];
|
package/src/format/rows.ts
CHANGED
|
@@ -8,8 +8,10 @@ import { isJsonData } from './json.ts';
|
|
|
8
8
|
import { sketchReference } from './sketch.ts';
|
|
9
9
|
import { JournalRowSchema, journalRowRules } from './compendiumRows.ts';
|
|
10
10
|
import { CreatureTypeSchema, CreatureBodySchema, CreatureTemperamentSchema, CreatureSensesSchema, CreatureAbilitySchema, CreaturePresentationSchema } from './creature-layers.ts';
|
|
11
|
-
import type { CreatureLayers } from './creature-layers.ts';
|
|
11
|
+
import type { CreatureAbilityInput, CreatureLayers } from './creature-layers.ts';
|
|
12
12
|
import { creatureSizeRules } from './creature-sizes.ts';
|
|
13
|
+
import { SKIN_CLIPS_RECIPE, SkinClipMapSchema } from './skins.ts';
|
|
14
|
+
import type { SkinClipMap } from './skins.ts';
|
|
13
15
|
|
|
14
16
|
const id = v.pipe(v.string(), v.regex(/^[a-z][a-zA-Z0-9.:-]*$/u), v.maxLength(128));
|
|
15
17
|
const text = v.pipe(v.string(), v.maxLength(4096));
|
|
@@ -52,8 +54,12 @@ const species = v.strictObject({ id, kind: id, label: text, capExempt: v.exactOp
|
|
|
52
54
|
temperament: v.exactOptional(CreatureTemperamentSchema), senses: v.exactOptional(CreatureSensesSchema),
|
|
53
55
|
abilities: v.exactOptional(abilities), presentation: v.exactOptional(CreaturePresentationSchema) });
|
|
54
56
|
const parameter = v.union([finite, v.boolean(), text, v.pipe(v.array(finite), v.maxLength(16))]);
|
|
57
|
+
const animationParameters = v.record(id, parameter);
|
|
58
|
+
const lookAnimation = v.strictObject({
|
|
59
|
+
recipe: id, parameters: animationParameters, clipMap: v.exactOptional(SkinClipMapSchema),
|
|
60
|
+
});
|
|
55
61
|
const look = v.strictObject({ id, species: id, recipe: id, material: v.optional(v.nullable(id), null), parameters: v.record(id, parameter),
|
|
56
|
-
animation:
|
|
62
|
+
animation: lookAnimation });
|
|
57
63
|
const basicCompendium = v.strictObject({ id, className: id, title: text, tabs: v.pipe(v.array(v.strictObject({ id, label: text })), v.maxLength(16)), stamp: text,
|
|
58
64
|
stats: v.pipe(v.array(v.strictObject({ label: text, value: text })), v.maxLength(8)),
|
|
59
65
|
entries: v.pipe(v.array(v.strictObject({ id, kind: v.literal('species'), tab: id, name: text, notes: text, sketch: v.pipe(text, v.check(sketchReference, 'bounded inert SVG data or admitted sketch hash')), species: id })), v.maxLength(256)) });
|
|
@@ -81,7 +87,12 @@ function rowRules(rows: ShardRows): string[] {
|
|
|
81
87
|
const strikeIds = new Set<string>();
|
|
82
88
|
for (const strikeRow of rows.strikes) { strikeIds.add(strikeRow.id); }
|
|
83
89
|
const lookIds = new Set<string>();
|
|
84
|
-
for (const lookRow of rows.looks) {
|
|
90
|
+
for (const lookRow of rows.looks) {
|
|
91
|
+
lookIds.add(lookRow.id);
|
|
92
|
+
if (lookRow.animation.clipMap !== undefined && lookRow.animation.recipe !== SKIN_CLIPS_RECIPE) {
|
|
93
|
+
errors.push('Clip maps require platform.clips');
|
|
94
|
+
}
|
|
95
|
+
}
|
|
85
96
|
for (const speciesRow of rows.species) {
|
|
86
97
|
for (const ability of speciesRow.abilities ?? []) {
|
|
87
98
|
if (!strikeIds.has(ability.use)) { errors.push(`Unknown creature ability: ${ability.use}`); }
|
|
@@ -109,9 +120,11 @@ function parseRows(input: unknown): ShardRows { return v.parse(RowsSchema, input
|
|
|
109
120
|
/** Admitted author data independent of validator implementation metadata. */
|
|
110
121
|
type StrikeRowsInput = StrikeRows;
|
|
111
122
|
interface StrikeRows { debris?: StrikeDebrisPolicy; id: string; shape: ({ kind: 'point'; radius: number; }) | ({ kind: 'sphere'; radius: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'arc'; radius: number; halfAngle: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'ring'; inner: number; outer: number; }); windup: number; active: number; recover: number; cooldown: number; range: number; damage: number; tags: (`${string}.${string}`)[]; weight: number; speed: number; }
|
|
112
|
-
interface ShardRowsInput { strikes: (StrikeRowsInput)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species:
|
|
123
|
+
interface ShardRowsInput { strikes: (StrikeRowsInput)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species: SpeciesRowInput[]; looks: ({ id: string; species: string; recipe: string; material?: (string) | null | undefined; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; animation: { recipe: string; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; clipMap?: SkinClipMap<string>; }; })[]; compendiums: (({ id: string; className: string; title: string; tabs: ({ id: string; label: string; })[]; stamp: string; stats: ({ label: string; value: string; })[]; entries: ({ id: string; kind: 'species'; tab: string; name: string; notes: string; sketch: string; species: string; })[]; }) | (v.InferInput<typeof JournalRowSchema>))[]; loot: (({ id: string; gear: 'purse.coins'; finds: null; marks: null; charted: boolean; chime: string; economy?: v.InferInput<typeof LootEconomySchema>; }) | ({ id: string; economy: v.InferInput<typeof BarterEconomySchema>; }))[]; }
|
|
113
124
|
// oxlint-disable-next-line typescript/consistent-type-definitions -- Object.values needs the original implicit dictionary contract for row validation.
|
|
114
|
-
type ShardRows = { strikes: (StrikeRows)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species: SpeciesRow[]; looks: ({ id: string; species: string; recipe: string; material: (string) | null; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; animation: { recipe: string; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; }; })[]; compendiums: (({ id: string; className: string; title: string; tabs: ({ id: string; label: string; })[]; stamp: string; stats: ({ label: string; value: string; })[]; entries: ({ id: string; kind: 'species'; tab: string; name: string; notes: string; sketch: string; species: string; })[]; }) | (v.InferOutput<typeof JournalRowSchema>))[]; loot: (({ id: string; gear: 'purse.coins'; finds: null; marks: null; charted: boolean; chime: string; economy?: v.InferOutput<typeof LootEconomySchema>; }) | ({ id: string; economy: v.InferOutput<typeof BarterEconomySchema>; }))[]; };
|
|
125
|
+
type ShardRows = { strikes: (StrikeRows)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species: SpeciesRow[]; looks: ({ id: string; species: string; recipe: string; material: (string) | null; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; animation: { recipe: string; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; clipMap?: SkinClipMap; }; })[]; compendiums: (({ id: string; className: string; title: string; tabs: ({ id: string; label: string; })[]; stamp: string; stats: ({ label: string; value: string; })[]; entries: ({ id: string; kind: 'species'; tab: string; name: string; notes: string; sketch: string; species: string; })[]; }) | (v.InferOutput<typeof JournalRowSchema>))[]; loot: (({ id: string; gear: 'purse.coins'; finds: null; marks: null; charted: boolean; chime: string; economy?: v.InferOutput<typeof LootEconomySchema>; }) | ({ id: string; economy: v.InferOutput<typeof BarterEconomySchema>; }))[]; };
|
|
126
|
+
|
|
127
|
+
type SpeciesRowInput = Omit<SpeciesRow, "abilities"> & { abilities?: CreatureAbilityInput[] };
|
|
115
128
|
|
|
116
129
|
/** A species keeps its old fields, with optional explicit creature layers. */
|
|
117
130
|
interface SpeciesRow extends CreatureLayers { capExempt?: boolean; harvest?: HarvestDrop[]; id: string; kind: string; label: string; aggressive: boolean; lockable: boolean; dims: { bodyY: number; bodyHalfLen: number; bodyRadius: number; headRadius: number; legLen: number; feet: ([number, number])[]; halfWidth: number; }; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; variants: ({ id: string; label: string; rarity: 'common' | 'uncommon' | 'rare' | 'legendary'; weight: number; scale: [number, number]; hp: number; mods: { speed: number; chargeDist: number; damageTaken: number; chargeDamage: number; relentless: boolean; }; })[]; }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { budgetTierLimits } from './budget-tiers.ts'
|
|
2
|
+
import { runtimeAccountedBytes } from './runtimeCost.ts'
|
|
3
|
+
|
|
4
|
+
import type { BudgetTier } from './budget-tiers.ts'
|
|
5
|
+
|
|
6
|
+
/** The tier an unnamed runtime is held to until OF10c1b names every runtime shard's tier. */
|
|
7
|
+
const UNNAMED_TIER: BudgetTier = 'large'
|
|
8
|
+
|
|
9
|
+
/** What the check reads of a shard: its runtime's reviewed cost and its budgets. */
|
|
10
|
+
type RuntimeTierSource = Readonly<{
|
|
11
|
+
runtime: Readonly<{ cost?: unknown }> | null
|
|
12
|
+
budgets: Readonly<{ client?: unknown; tier?: BudgetTier }>
|
|
13
|
+
}>
|
|
14
|
+
|
|
15
|
+
interface RuntimeTierIssue {
|
|
16
|
+
readonly code: 'runtime-tier-memory'
|
|
17
|
+
readonly metric: string
|
|
18
|
+
readonly actual: number
|
|
19
|
+
readonly limit: number
|
|
20
|
+
readonly severity: 'refusal'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ONE-FORMAT OF10c1a: a runtime fits its tier. A shard with a runtime and a reviewed cost (`runtime.cost`, else
|
|
25
|
+
* `budgets.client`) refuses at build and at upload when the runtime's accounted bytes (`runtimeAccountedBytes`: what
|
|
26
|
+
* it holds above the engine's resident base) exceed its tier's `memoryBytes`. A shard naming no tier is held to `large`
|
|
27
|
+
* until OF10c1b names a tier in each of our runtime shards' sources; then a runtime must name one.
|
|
28
|
+
*/
|
|
29
|
+
function runtimeTierIssues(source: RuntimeTierSource): RuntimeTierIssue[] {
|
|
30
|
+
const cost = source.runtime?.cost ?? source.budgets.client
|
|
31
|
+
if (source.runtime === null || cost === undefined) {
|
|
32
|
+
return []
|
|
33
|
+
}
|
|
34
|
+
const tier = source.budgets.tier ?? UNNAMED_TIER
|
|
35
|
+
const limit = budgetTierLimits({ tier }).memoryBytes
|
|
36
|
+
const actual = runtimeAccountedBytes(cost)
|
|
37
|
+
if (actual <= limit) {
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
code: 'runtime-tier-memory',
|
|
43
|
+
metric: `runtime accounted bytes over the ${tier} tier's memory (OF10c1a: name a larger tier or shrink the runtime)`,
|
|
44
|
+
actual,
|
|
45
|
+
limit,
|
|
46
|
+
severity: 'refusal',
|
|
47
|
+
},
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
UNNAMED_TIER,
|
|
53
|
+
type RuntimeTierIssue,
|
|
54
|
+
type RuntimeTierSource,
|
|
55
|
+
runtimeTierIssues,
|
|
56
|
+
}
|
|
@@ -2,11 +2,11 @@ import type { Shardfile } from './shardSchema.ts';
|
|
|
2
2
|
import * as v from 'valibot';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* The behaviour sections a
|
|
5
|
+
* The behaviour sections a native runtime may bind (SHARD-PLATFORM M3, the runtime-owner binding, E435). A runtime shard
|
|
6
6
|
* shard's runtime owns its world and its play scope; a section named here stays declared data in the shardfile, validated
|
|
7
7
|
* like every row, and the platform installs it into that runtime's play scope through the same installers the template
|
|
8
|
-
* uses (`@wildshard/game/shardfile/
|
|
9
|
-
* section's rows do not make a
|
|
8
|
+
* uses (`@wildshard/game/shardfile/runtimeBoundRows`). The data client never installs a bound section a second time, and a bound
|
|
9
|
+
* section's rows do not make a runtime shardfile "non-empty": only an unbound behaviour row sends a runtime shard down the
|
|
10
10
|
* full shardfile loader.
|
|
11
11
|
*
|
|
12
12
|
* - `quests`: quest graphs, flags and dialogue; the runtime supplies its flags and places world-piece markers.
|
|
@@ -25,14 +25,14 @@ import * as v from 'valibot';
|
|
|
25
25
|
* Its Wasm roots remain verified product files and never create a data-client host.
|
|
26
26
|
* - `clientChannels`: copied clock/state observations and bounded straight-line numeric expressions; the runtime
|
|
27
27
|
* binds private visual targets, never authoritative state or player objects.
|
|
28
|
-
* - `terrain`: a
|
|
28
|
+
* - `terrain`: a native runtime owns the terrain queries and draw construction. The data client omits those rows;
|
|
29
29
|
* unbound drawn tiles use the page's shared tile streamer. Edge rows remain platform data.
|
|
30
|
-
* - `loot`: the
|
|
30
|
+
* - `loot`: the native runtime consumes the original economy rows; only the secondary data client omits them.
|
|
31
31
|
* - `props` (G227): the compiled props section (tiles, library models, panels, far proxy), bound the same way; the
|
|
32
32
|
* runtime keeps the behaviour of the pieces it dresses.
|
|
33
33
|
*/
|
|
34
34
|
export const RUNTIME_BOUND_SECTIONS = ['quests', 'ledger', 'items', 'spawns', 'state', 'terrain', 'props', 'modes', 'clientChannels', 'movers', 'loot'] as const;
|
|
35
|
-
/** One section a
|
|
35
|
+
/** One section a native runtime binds rather than the data client. */
|
|
36
36
|
export type RuntimeBoundSection = (typeof RUNTIME_BOUND_SECTIONS)[number];
|
|
37
37
|
/** `runtime.binds`: the declared capability that replaces the implicit "empty apart from audio, edges and colliders" rule. */
|
|
38
38
|
export const RuntimeBindsSchema: v.GenericSchema<RuntimeBindsRowsInput, RuntimeBindsRows> = v.pipe(v.array(v.picklist(RUNTIME_BOUND_SECTIONS)), v.maxLength(RUNTIME_BOUND_SECTIONS.length),
|
|
@@ -4,7 +4,7 @@ import { RUNTIME_RESIDENT_FACTOR } from './wireLimits.ts';
|
|
|
4
4
|
const mb = v.pipe(v.number(), v.finite(), v.minValue(0));
|
|
5
5
|
const FIRST_EPOCH = 1;
|
|
6
6
|
const epochNumber = v.pipe(v.number(), v.integer(), v.minValue(FIRST_EPOCH));
|
|
7
|
-
/** Reviewed
|
|
7
|
+
/** Reviewed native-runtime measurements, kept with their shard rather than presenting an empty data budget as its cost. */
|
|
8
8
|
export const MemoryMeasurementSchema: v.StrictObjectSchema<{ readonly webContentMB: v.GenericSchema<MemoryMeasurementRowsInput['webContentMB'], MemoryMeasurementRows['webContentMB']>; readonly glMB: v.GenericSchema<MemoryMeasurementRowsInput['glMB'], MemoryMeasurementRows['glMB']>; readonly engineBaseMB: v.GenericSchema<MemoryMeasurementRowsInput['engineBaseMB'], MemoryMeasurementRows['engineBaseMB']>; readonly residentBaseMB: v.ExactOptionalSchema<v.GenericSchema<Exclude<MemoryMeasurementRowsInput['residentBaseMB'], undefined>, Exclude<MemoryMeasurementRows['residentBaseMB'], undefined>>, undefined>; readonly rev: v.GenericSchema<MemoryMeasurementRowsInput['rev'], MemoryMeasurementRows['rev']>; readonly device: v.GenericSchema<MemoryMeasurementRowsInput['device'], MemoryMeasurementRows['device']>; readonly evidence: v.GenericSchema<MemoryMeasurementRowsInput['evidence'], MemoryMeasurementRows['evidence']>; readonly epoch: v.ExactOptionalSchema<v.GenericSchema<Exclude<MemoryMeasurementRowsInput['epoch'], undefined>, Exclude<MemoryMeasurementRows['epoch'], undefined>>, undefined>; }, undefined> = v.strictObject({
|
|
9
9
|
webContentMB: mb, glMB: mb, engineBaseMB: mb,
|
|
10
10
|
/** Matched settled pre-entry resident set. When present, subtract it instead of the dated engine-only calibration. */
|
|
@@ -11,12 +11,12 @@ const home = v.strictObject({ id, kind, look: id, at, yaw: finite, respawn: v.pi
|
|
|
11
11
|
const boss = v.strictObject({ id, kind, look: id, at, yaw: finite });
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
* A
|
|
14
|
+
* A native runtime's creatures as declared rows (SHARD-PLATFORM M3 / SF50-p, E435), the `spawns` section of
|
|
15
15
|
* `runtime.binds`. The runtime keeps its own species (rigs, brains, the hard 20 %); the rows declare WHERE they live and
|
|
16
16
|
* WHO they are: each row's `id` is its stable declared key (a retained home uses it across respawn and cold restore).
|
|
17
17
|
* One-shot actors keep their runtime-allocated identities and spawn order; `kind` / `look` name the runtime's registered
|
|
18
18
|
* species and variant, and a home's `respawn` its refill delay.
|
|
19
|
-
* The platform keeps the homes (`bindRuntimeHomes`, `bindRuntimeBoss` in
|
|
19
|
+
* The platform keeps the homes (`bindRuntimeHomes`, `bindRuntimeBoss` in engine runtimeBoundRows); this is not the local sim's
|
|
20
20
|
* `creatures` section (no brain, strike or species-catalogue rows: those stay the runtime's).
|
|
21
21
|
*/
|
|
22
22
|
export const RuntimeSpawnsSchema: v.GenericSchema<RuntimeSpawnsInput, RuntimeSpawns> = v.pipe(v.strictObject({ homes: v.pipe(v.array(home), v.maxLength(256)), bosses: v.pipe(v.array(boss), v.maxLength(16)),
|
|
@@ -6,7 +6,7 @@ const number = v.pipe(v.number(), v.finite());
|
|
|
6
6
|
const name = v.pipe(v.string(), v.minLength(1), v.maxLength(256));
|
|
7
7
|
const storageSchema = v.picklist(['float16', 'unorm8']);
|
|
8
8
|
const graph = v.custom<GraphIr>(input => {
|
|
9
|
-
const checked = validateGraph(input, {
|
|
9
|
+
const checked = validateGraph(input, { declaredBudget: true });
|
|
10
10
|
return checked.ok && checked.graph.kind === 'post';
|
|
11
11
|
}, 'Invalid scaled post graph');
|
|
12
12
|
const term = v.union([number, name, v.null(), v.strictObject({ param: name }),
|
|
@@ -22,7 +22,7 @@ const schema: v.GenericSchema<unknown, ScaledPostRow> = v.strictObject({
|
|
|
22
22
|
settings: v.record(name, number), when: v.exactOptional(name), outputs: v.record(name, name), drawnOnly: v.exactOptional(v.boolean()),
|
|
23
23
|
});
|
|
24
24
|
|
|
25
|
-
/** Complete native post preflight. Graphs keep the executor's
|
|
25
|
+
/** Complete native post preflight. Graphs keep the executor's host-owned budget;
|
|
26
26
|
* target order, storage variants and draw/output references retain its rules.
|
|
27
27
|
* The executor still checks these contracts before allocating and compiling. */
|
|
28
28
|
export function parseScaledPostRow(input: unknown): ScaledPostRow {
|
package/src/format/scriptAbi.ts
CHANGED
|
@@ -10,5 +10,5 @@ export const SCRIPT_IMPORTS: Readonly<Record<string, readonly number[]>> = Objec
|
|
|
10
10
|
finite32: [0x7d, 0x7d], finite64: [0x7c, 0x7c],
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
/** Read-only declared numeric parameters; the host supplies the
|
|
13
|
+
/** Read-only declared numeric parameters; the host supplies the host-owned calling entity to the query adapter. */
|
|
14
14
|
export const SCRIPT_PARAMETER_QUERY = 410;
|
|
@@ -36,7 +36,7 @@ export function writeV2Frame(view: DataView,layout: V2Layout,frame: V2Frame,coun
|
|
|
36
36
|
}
|
|
37
37
|
/** Reuse the last immutable count shape within one existing owner. Every call
|
|
38
38
|
* validates current counts and captures a fresh detached header; no caller
|
|
39
|
-
* authority or mutable input is retained as a
|
|
39
|
+
* authority or mutable input is retained as a host-owned template. */
|
|
40
40
|
export function createV2FrameWriter(layout: V2Layout): (view: DataView,frame: V2Frame,counts: ReadonlyMap<number,number>) => V2FrameAuthority {
|
|
41
41
|
let previous: readonly number[] | undefined;
|
|
42
42
|
let available: number[] | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { creatureSizeRules } from './creature-sizes.ts';
|
|
1
|
+
import { creatureSizeRules, spawnCapacity } from './creature-sizes.ts';
|
|
2
2
|
import { readSpeciesPrograms } from './speciesPrograms.ts';
|
|
3
3
|
import type { StrikeDebrisPolicy } from './strike-debris.ts';
|
|
4
4
|
import { strikeDebrisCatalogueRules } from './strike-debris.ts';
|
|
@@ -367,7 +367,7 @@ export function shardfileRules(s: Shardfile, sections?: ReadonlyMap<string, unkn
|
|
|
367
367
|
const crowdMembers = s.crowds.reduce((sum, row) => sum + row.count, 0);
|
|
368
368
|
if (crowdMembers > 4096) errors.push('declared crowd member capacity');
|
|
369
369
|
if (s.crowds.some(row => Math.abs(row.x) > CHUNK_HALF || Math.abs(row.z) > CHUNK_HALF)) errors.push('declared crowd home in cell');
|
|
370
|
-
if (s.creatures.spawns
|
|
370
|
+
if (spawnCapacity(s.creatures.spawns) + crowdMembers > s.serverBudget.entities) errors.push('declared entity capacity');
|
|
371
371
|
errors.push(...creatureSizeRules(s.rows.species, s.creatures.spawns));
|
|
372
372
|
for (const spawn of s.creatures.spawns) if (!species.get(spawn.species)?.variants.some((row) => row.id === spawn.variant) || (spawn.strike !== null && !strikes.has(spawn.strike))) errors.push('declared spawn species/variant/strike');
|
|
373
373
|
errors.push(...encounterRules(s.encounters, s.creatures.spawns.map((spawn) => spawn.id), s.ui.filter((row) => row.kind === 'bossPanel')));
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/** Defining root wire sections shared by the authoring SDK and game admission.
|
|
2
2
|
* Native reference/asset/entry/allocator checks stay in game; look and material contracts await DS1.4. */
|
|
3
|
+
import { BudgetTierSchema } from './budget-tiers.ts';
|
|
4
|
+
import type { BudgetTier } from './budget-tiers.ts';
|
|
3
5
|
import * as v from 'valibot';
|
|
4
6
|
import { WIRE_CELL, WIRE_TILE_SIZES } from './wireLimits.ts';
|
|
5
7
|
import { SHARDFILE_ADMISSION_LIMITS as limits } from './admissionLimits.ts';
|
|
@@ -40,7 +42,9 @@ export const RequiresSchema: v.GenericSchema<ShardRequiresInput, ShardRequires>
|
|
|
40
42
|
/** Authored compressed and resident ceilings. */
|
|
41
43
|
export const BudgetsSchema: v.GenericSchema<ShardBudgetsInput, ShardBudgets> = v.strictObject({
|
|
42
44
|
/** Reviewed whole-client floor retained when an opaque runtime becomes declared data. */
|
|
43
|
-
client: v.exactOptional(RuntimeCostSchema),
|
|
45
|
+
client: v.exactOptional(RuntimeCostSchema),
|
|
46
|
+
/** ONE-FORMAT OF10c0: the budget tier this shard picks (`budgetTiers.ts`); none is `small`. */
|
|
47
|
+
tier: v.exactOptional(BudgetTierSchema), library: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema, downloadAllowance: v.exactOptional(ShardNaturalSchema) }), sim: v.strictObject({ resident: ShardNaturalSchema, compressed: ShardNaturalSchema }), overlap: ShardNaturalSchema });
|
|
44
48
|
/** Fixed-step simulation and admitted script binding declarations. */
|
|
45
49
|
export const SimSchema: v.GenericSchema<ShardSimInput, ShardSim> = v.strictObject({ fixedHz: v.literal(60), scriptTickDivisor: v.pipe(positive, v.check((n) => 60 % n === 0, 'script divisor divides 60')), commandVersion: v.literal(0), snapshotVersion: v.literal(0), scripts: ShardReferencesSchema, bindings: v.optional(ScriptBindingsSchema, []) });
|
|
46
50
|
/** Bounded player count and authored movement speed. */
|
|
@@ -233,6 +237,7 @@ interface ShardRequiresFields {
|
|
|
233
237
|
}
|
|
234
238
|
export type ShardRequires = { [Key in keyof ShardRequiresFields]: ShardRequiresFields[Key] };
|
|
235
239
|
interface ShardBudgetsInputFields {
|
|
240
|
+
tier?: BudgetTier;
|
|
236
241
|
client?: v.InferInput<typeof RuntimeCostSchema>;
|
|
237
242
|
library: {
|
|
238
243
|
resident: ShardNaturalInput;
|
|
@@ -248,6 +253,7 @@ interface ShardBudgetsInputFields {
|
|
|
248
253
|
export type ShardBudgetsInput = { [Key in keyof ShardBudgetsInputFields]: ShardBudgetsInputFields[Key] };
|
|
249
254
|
interface ShardBudgetsFields {
|
|
250
255
|
client?: v.InferOutput<typeof RuntimeCostSchema>;
|
|
256
|
+
tier?: BudgetTier;
|
|
251
257
|
library: {
|
|
252
258
|
resident: ShardNatural;
|
|
253
259
|
compressed: ShardNatural;
|
|
@@ -14,24 +14,23 @@ import type { ShardTerrain } from "./terrain.ts";
|
|
|
14
14
|
import { worstContentCost, memoryTargetWarnings, nearbyContentCost } from "./budget.ts";
|
|
15
15
|
import { CONTENT_CAPS as C, MEMORY_GATES } from './contentBounds.ts';
|
|
16
16
|
import { staleRuntimeIssues } from './memory-epoch.ts';
|
|
17
|
-
import { MEMORY_HARD_BYTES, hardLineIssue } from './memory-line.ts';
|
|
18
|
-
import { bootMemoryCosts } from './boot-memory-cost.ts';
|
|
17
|
+
import { MEMORY_HARD_BYTES, hardLineIssue, runtimeOfflineBytes } from './memory-line.ts';
|
|
18
|
+
import { bootMemoryCosts, NO_BYTES } from './boot-memory-cost.ts';
|
|
19
19
|
import { VIEW_DRAWS, viewDraws } from './view-draws.ts';
|
|
20
20
|
import { DEFAULT_GRAPH_BUDGET } from "./materialGraph.ts";
|
|
21
21
|
import { SCRIPT_LIMITS } from './scriptLimits.ts';
|
|
22
|
-
import { runtimeAccountedBytes } from "./runtimeCost.ts";
|
|
23
22
|
import { MemoryAdmission } from './memoryAdmission.ts';
|
|
24
23
|
import { nearPlaceholderRoots } from './nearPlaceholder.ts';
|
|
25
24
|
import type { IssueCodeOf } from './issue-codes.ts';
|
|
26
25
|
import { isNavigationData, navigationCost } from './navigationBytes.ts';
|
|
27
26
|
|
|
28
27
|
type PerformancePolicy = 'refuse' | 'warn';
|
|
29
|
-
interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown
|
|
28
|
+
interface PerformanceOptions { readonly policy: PerformancePolicy; readonly sections: ReadonlyMap<string, unknown>; readonly mountedImages?: number }
|
|
30
29
|
|
|
31
30
|
// oxlint-disable-next-line typescript/prefer-readonly-parameter-types -- format's shard row, only read
|
|
32
|
-
function reportMemory(source: Shardfile, nativeBytes: number, sections: ReadonlyMap<string, unknown>): PerformanceReport['memory'] {
|
|
31
|
+
function reportMemory(source: Shardfile, nativeBytes: number, options: Readonly<{ sections: ReadonlyMap<string, unknown>; mountedImages?: number }>): PerformanceReport['memory'] {
|
|
33
32
|
const commons = nativeBytes + Object.values(source.requires.commonsCosts).reduce((sum, row) => sum + row.decoded + row.gpu, 0);
|
|
34
|
-
const budget = { commons, boot: bootMemoryCosts(source, sections) };
|
|
33
|
+
const budget = { commons, boot: bootMemoryCosts(source, options.sections, options.mountedImages ?? NO_BYTES) };
|
|
35
34
|
return { near: nearbyContentCost(source, source.spawn.x, source.spawn.z, budget), worst: worstContentCost(source, budget), playingLimit: C.playing, loadingLimit: C.loading };
|
|
36
35
|
}
|
|
37
36
|
/** A performance issue's code and its metric words. */
|
|
@@ -306,11 +305,11 @@ export function validatePropDrawBounds(source: Shardfile, assets: ReadonlyMap<st
|
|
|
306
305
|
for (const ref of [...props.panels.map(row => row.file), ...props.wholeLibrary ?? [], ...props.far === null ? [] : [props.far]]) validate(ref);
|
|
307
306
|
}
|
|
308
307
|
|
|
309
|
-
/** Report deterministic declared bounds and measured native execution; the caller supplies
|
|
308
|
+
/** Report deterministic declared bounds and measured native execution; the caller supplies host-owned provenance policy. */
|
|
310
309
|
export function performanceReport(source: Shardfile, observations: PerformanceObservations, options: PerformancePolicy | PerformanceOptions = 'refuse'): PerformanceReport {
|
|
311
|
-
const
|
|
312
|
-
const native = { resident: source.runtime?.cost === undefined ? 0 :
|
|
313
|
-
const memory = reportMemory(source, native.resident,
|
|
310
|
+
const resolved: PerformanceOptions = typeof options === 'string' ? { policy: options, sections: new Map<string, unknown>() } : options, { policy } = resolved;
|
|
311
|
+
const native = { resident: source.runtime?.cost === undefined ? 0 : runtimeOfflineBytes(source.runtime.cost), evidence: source.runtime?.cost?.evidence ?? null, unmeasuredViewAndDownload: source.runtime !== null };
|
|
312
|
+
const memory = reportMemory(source, native.resident, resolved), { worst } = memory, spawn = source.spawn;
|
|
314
313
|
const issues: PerformanceIssue[] = memoryTargetWarnings(source).map(row => ({ code: 'perf-memory-target', metric: `${row.category} resident target (tradeable)`, actual: row.bytes, limit: row.target, severity: 'warning' }));
|
|
315
314
|
issues.push(...performanceTargetIssues(source, policy));
|
|
316
315
|
const check = ([code, metric]: Named, actual: number, limit: number): void => {
|