@wildshard/shard-format 0.83.0 → 0.85.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 +3 -1
- package/src/format/assetAdmission.ts +5 -2
- package/src/format/decision-frame-v2.ts +22 -5
- package/src/format/decisionScripts.ts +16 -4
- package/src/format/headless-sections.ts +1 -0
- package/src/format/json-schema.ts +2 -0
- package/src/format/numeric-frame-v2.ts +143 -0
- package/src/format/outputFields.ts +1 -0
- package/src/format/platformDataSections.ts +3 -0
- package/src/format/script-fuel-path-v2.ts +189 -0
- package/src/format/scriptAbiV1.ts +5 -2
- package/src/format/scriptContract.ts +1 -1
- package/src/format/scriptFuelV2.ts +5 -2
- package/src/format/sections.ts +3 -1
- package/src/tools/runtime-hosts.json +6 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.85.0",
|
|
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": {
|
|
@@ -115,6 +115,7 @@
|
|
|
115
115
|
"./dayLook": "./src/format/dayLook.ts",
|
|
116
116
|
"./decisionBindings": "./src/format/decisionBindings.ts",
|
|
117
117
|
"./decisionFrameV2": "./src/format/decision-frame-v2.ts",
|
|
118
|
+
"./numericFrameV2": "./src/format/numeric-frame-v2.ts",
|
|
118
119
|
"./decisionPublication": "./src/format/decisionPublication.ts",
|
|
119
120
|
"./decisionScripts": "./src/format/decisionScripts.ts",
|
|
120
121
|
"./declaredQuestPage": "./src/format/declaredQuestPage.ts",
|
|
@@ -343,6 +344,7 @@
|
|
|
343
344
|
"./sectionVersions": "./src/format/section-versions.ts",
|
|
344
345
|
"./scriptContract": "./src/format/scriptContract.ts",
|
|
345
346
|
"./scriptFuelV2": "./src/format/scriptFuelV2.ts",
|
|
347
|
+
"./scriptFuelPathV2": "./src/format/script-fuel-path-v2.ts",
|
|
346
348
|
"./scriptGroupBankV2": "./src/format/scriptGroupBankV2.ts",
|
|
347
349
|
"./scriptGroupStepV2": "./src/format/scriptGroupStepV2.ts",
|
|
348
350
|
"./scriptInputStateV2": "./src/format/scriptInputStateV2.ts",
|
|
@@ -2,6 +2,7 @@ import { acceptsShardfileCost, textureLibrarySource } from './deviceMemoryCost.t
|
|
|
2
2
|
import { retainedActorIds } from './retained-actors.ts';
|
|
3
3
|
import { creaturePerchAdmissionRows } from './creature-perch.ts';
|
|
4
4
|
import { admitScriptContract, decisionModuleContracts, type ScriptAdmissionRows } from './scriptContract.ts';
|
|
5
|
+
import { isNumericContract, withoutNumericModules } from './numeric-frame-v2.ts';
|
|
5
6
|
import type { TextureTranscodeSupport } from './contentBounds.ts';
|
|
6
7
|
import { overHardLine } from './memory-line.ts';
|
|
7
8
|
import { admitScript } from './scriptAdmission.ts';
|
|
@@ -100,7 +101,8 @@ function assetAdmission(input: unknown, memory: MemoryAdmission | undefined, scr
|
|
|
100
101
|
const combined = [...scripts, ...perchRows];
|
|
101
102
|
const contracts = decisionModuleContracts(combined, s.files);
|
|
102
103
|
const legacyModules = new Set([...s.sim.scripts, ...s.clientScripts.bindings.map(row => row.module), ...s.movers.filter(row => row.execution !== 'native').map(row => row.module)]);
|
|
103
|
-
|
|
104
|
+
// WASM-HOST H13: a numeric host (script lane, client script, mover) runs ABI v2 modules over the numeric frame.
|
|
105
|
+
if ([...contracts.keys()].some(hash => legacyModules.has(hash) && !isNumericContract(contracts.get(hash) ?? { abi: 0 }))) throw new Error('Decision module cannot also use a legacy script host');
|
|
104
106
|
preflightAssetGraph(s);
|
|
105
107
|
const declared = preflightDeclaredCosts(s, memory).commons;
|
|
106
108
|
const closure = (roots: readonly string[]): Set<string> => {
|
|
@@ -235,7 +237,8 @@ function admitAfterFiles(state: AssetAdmission, assets: ReadonlyMap<string, Uint
|
|
|
235
237
|
scriptMemory += admission.maximumPages * 65536 * 3;
|
|
236
238
|
}
|
|
237
239
|
let decisionSim = 0, decisionView = 0;
|
|
238
|
-
|
|
240
|
+
// WASM-HOST H13: a numeric module keeps the placement and memory rules of the host that names it (above).
|
|
241
|
+
for (const [hash, contract] of withoutNumericModules(contracts)) {
|
|
239
242
|
if (scripts.some(row => row.module === `blobs/wasm/${hash}.wasm` && row.side === 'sim')) {
|
|
240
243
|
if (!critical.has(hash) || library.has(hash)) throw new Error('Decision sim module must be critical, outside the render library');
|
|
241
244
|
decisionSim += contract.pages * 65536 * 2;
|
|
@@ -26,16 +26,32 @@ for (const [kind, capacity] of Object.entries(CAPACITY)) {
|
|
|
26
26
|
capacities.set(Number(kind), capacity)
|
|
27
27
|
}
|
|
28
28
|
const DECISION_V2_CAPACITIES: ReadonlyMap<number, number> = capacities
|
|
29
|
+
/** WASM-HOST H8: a row with `inputs` adds the player bank (8 seats, W28) and 32 input edges to the frame. */
|
|
30
|
+
const INPUT_CAPACITY: Readonly<Record<number, number>> = {
|
|
31
|
+
...CAPACITY,
|
|
32
|
+
7: 8,
|
|
33
|
+
8: 32,
|
|
34
|
+
}
|
|
35
|
+
const inputCapacities = new Map<number, number>()
|
|
36
|
+
for (const [kind, capacity] of Object.entries(INPUT_CAPACITY)) {
|
|
37
|
+
inputCapacities.set(Number(kind), capacity)
|
|
38
|
+
}
|
|
39
|
+
const DECISION_V2_INPUT_CAPACITIES: ReadonlyMap<number, number> =
|
|
40
|
+
inputCapacities
|
|
29
41
|
/** List replies are keyed `DECISION_V2_LIST_KEY + list op`, apart from read ops. */
|
|
30
42
|
const DECISION_V2_LIST_KEY = 1000
|
|
31
43
|
const DECISION_V2_IO = 0
|
|
32
|
-
/** The I/O frame a decision module of `pages` pages admits under. */
|
|
33
|
-
function decisionLayoutV2(pages: number): V2Layout {
|
|
34
|
-
return layoutV2(
|
|
44
|
+
/** The I/O frame a decision module of `pages` pages admits under; `inputs` adds the seat and edge banks. */
|
|
45
|
+
function decisionLayoutV2(pages: number, inputs = false): V2Layout {
|
|
46
|
+
return layoutV2(
|
|
47
|
+
DECISION_V2_IO,
|
|
48
|
+
pages,
|
|
49
|
+
inputs ? DECISION_V2_INPUT_CAPACITIES : DECISION_V2_CAPACITIES,
|
|
50
|
+
)
|
|
35
51
|
}
|
|
36
52
|
/** A decision row's byte contract: ABI 1 by its pages, or (abi '2.0') the ABI 2 sim lane over its fixed decision frame. */
|
|
37
53
|
function decisionContract(
|
|
38
|
-
row: Readonly<Pick<DecisionScriptRow, 'abi' | 'pages'>>,
|
|
54
|
+
row: Readonly<Pick<DecisionScriptRow, 'abi' | 'inputs' | 'pages'>>,
|
|
39
55
|
): Extract<ScriptContract, { pages: number }> {
|
|
40
56
|
if (row.abi === '1.0') {
|
|
41
57
|
return { abi: 1, pages: row.pages }
|
|
@@ -44,7 +60,7 @@ function decisionContract(
|
|
|
44
60
|
abi: 2,
|
|
45
61
|
lane: 'sim',
|
|
46
62
|
pages: row.pages,
|
|
47
|
-
ioBytes: decisionLayoutV2(row.pages).bytes,
|
|
63
|
+
ioBytes: decisionLayoutV2(row.pages, row.inputs === true).bytes,
|
|
48
64
|
compilerRevision: SCRIPT_V2_REVISIONS.compiler,
|
|
49
65
|
admissionRevision: SCRIPT_V2_REVISIONS.admission,
|
|
50
66
|
}
|
|
@@ -52,6 +68,7 @@ function decisionContract(
|
|
|
52
68
|
|
|
53
69
|
export {
|
|
54
70
|
DECISION_V2_CAPACITIES,
|
|
71
|
+
DECISION_V2_INPUT_CAPACITIES,
|
|
55
72
|
DECISION_V2_IO,
|
|
56
73
|
DECISION_V2_LIST_KEY,
|
|
57
74
|
decisionContract,
|
|
@@ -11,6 +11,8 @@ const local = v.pipe(v.string(), v.regex(/^[A-Za-z_][A-Za-z0-9_.-]*$/u), v.maxLe
|
|
|
11
11
|
const finite = v.pipe(v.number(), v.finite());
|
|
12
12
|
const positive = v.pipe(finite, v.integer(), v.minValue(1), v.maxValue(0x7fffffff));
|
|
13
13
|
const HIT_TAG_LENGTH = 64;
|
|
14
|
+
/** WASM-HOST H8 (W9): the sim lane's fast rate, and the most a row writes for why it needs it. */
|
|
15
|
+
const SIM_RATE = { fast: 30, reason: 200 } as const;
|
|
14
16
|
const HIT_TAGS = 16;
|
|
15
17
|
const hitTag = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9_-]*(?:\.[a-z0-9_-]+)+$/u), v.maxLength(HIT_TAG_LENGTH));
|
|
16
18
|
const hitTags = v.pipe(v.record(local, hitTag), v.check((value: Readonly<Record<string, string>>): boolean => Object.keys(value).length <= HIT_TAGS, 'at most 16 hit tags'));
|
|
@@ -35,7 +37,11 @@ const rowEntries = {
|
|
|
35
37
|
binding: v.union([v.strictObject({ encounter: id }), v.strictObject({ quest: id }), v.strictObject({ zone: id }), v.strictObject({ shard: v.literal(true) }), v.strictObject({ spawnGroup: id }), v.strictObject({ brain: id })]),
|
|
36
38
|
pages: v.optional(v.pipe(positive, v.maxValue(4)), 1), onFail: v.picklist(['hold', 'reset', 'skip']),
|
|
37
39
|
on: v.pipe(v.array(v.picklist(keys(SCRIPT_V1_EVENTS))), v.minLength(1), v.maxLength(23), v.check(values => unique(values), 'unique subscribed events')),
|
|
38
|
-
|
|
40
|
+
// WASM-HOST H8 (W9): 10 Hz is the sim lane's rate; 30 Hz needs an ABI 2 row and its written reason.
|
|
41
|
+
tick: v.optional(v.nullable(v.picklist([1, 2, 5, 10, SIM_RATE.fast])), null),
|
|
42
|
+
tickReason: v.exactOptional(v.pipe(v.string(), v.nonEmpty(), v.maxLength(SIM_RATE.reason))),
|
|
43
|
+
// WASM-HOST H8: an ABI 2 row that reads its seats and their input edges (W28) in its v2 frame.
|
|
44
|
+
inputs: v.exactOptional(v.literal(true)),
|
|
39
45
|
reads: v.pipe(v.array(v.picklist(readNames)), v.maxLength(readNames.length), v.check(values => unique(values), 'unique script reads')),
|
|
40
46
|
commands: v.pipe(v.array(v.picklist(keys(SCRIPT_V1_COMMANDS))), v.maxLength(21), v.check(values => unique(values), 'unique script commands')),
|
|
41
47
|
actors: v.optional(aliases, {}), moves: v.optional(aliases, {}), strikes: v.optional(aliases, {}), cues: v.optional(aliases, {}),
|
|
@@ -72,7 +78,9 @@ export function decisionScriptRowRules(script: DecisionScriptRow): string[] {
|
|
|
72
78
|
const errors: string[] = [];
|
|
73
79
|
if ('spawnGroup' in script.binding && (Object.keys(script.actors).length === 0 || script.state.some(slot => slot.scope !== 'actor')))
|
|
74
80
|
errors.push('spawn groups declare members and actor-scoped simulation state');
|
|
75
|
-
if ((script.tick !== null) !== script.on.includes('tick')) errors.push('tick subscription has a declared 1/2/5/10 Hz rate');
|
|
81
|
+
if ((script.tick !== null) !== script.on.includes('tick')) errors.push('tick subscription has a declared 1/2/5/10/30 Hz rate');
|
|
82
|
+
if ((script.tick === SIM_RATE.fast) !== (script.tickReason !== undefined)) { errors.push('a 30 Hz row, and only one, gives its written reason (W9)'); }
|
|
83
|
+
if ((script.tick === SIM_RATE.fast || script.inputs === true) && script.abi !== '2.0') { errors.push('30 Hz and input edges are ABI 2 sim rows'); }
|
|
76
84
|
if ('brain' in script.binding && (!Object.values(script.actors).includes(script.binding.brain)
|
|
77
85
|
|| script.commands.some((name): boolean => name === 'move' || name === 'strike' || name === 'stop'))) {
|
|
78
86
|
errors.push('a brain hook names its creature and leaves move, strike and stop to the brain');
|
|
@@ -228,7 +236,9 @@ interface DecisionScriptRowInputFields {
|
|
|
228
236
|
pages?: number | undefined;
|
|
229
237
|
onFail: 'hold' | 'reset' | 'skip';
|
|
230
238
|
on: (keyof typeof SCRIPT_V1_EVENTS)[];
|
|
231
|
-
tick?: (1 | 2 | 5 | 10) | null | undefined;
|
|
239
|
+
tick?: (1 | 2 | 5 | 10 | typeof SIM_RATE.fast) | null | undefined;
|
|
240
|
+
tickReason?: string;
|
|
241
|
+
inputs?: true;
|
|
232
242
|
reads: ((typeof readNames)[number])[];
|
|
233
243
|
commands: (keyof typeof SCRIPT_V1_COMMANDS)[];
|
|
234
244
|
actors?: Record<string, string> | undefined;
|
|
@@ -286,7 +296,9 @@ interface DecisionScriptRowFields {
|
|
|
286
296
|
pages: number;
|
|
287
297
|
onFail: 'hold' | 'reset' | 'skip';
|
|
288
298
|
on: (keyof typeof SCRIPT_V1_EVENTS)[];
|
|
289
|
-
tick: (1 | 2 | 5 | 10) | null;
|
|
299
|
+
tick: (1 | 2 | 5 | 10 | typeof SIM_RATE.fast) | null;
|
|
300
|
+
tickReason?: string;
|
|
301
|
+
inputs?: true;
|
|
290
302
|
reads: ((typeof readNames)[number])[];
|
|
291
303
|
commands: (keyof typeof SCRIPT_V1_COMMANDS)[];
|
|
292
304
|
actors: Record<string, string>;
|
|
@@ -5,6 +5,7 @@ import { parsePlatformDataSection } from './platformDataSections.ts'
|
|
|
5
5
|
/** One defining context catalogue for author-build intake and worker transport. */
|
|
6
6
|
export const HEADLESS_CONTEXT_SECTIONS = [
|
|
7
7
|
'view/modules',
|
|
8
|
+
'sim/modules',
|
|
8
9
|
'sim/scripts',
|
|
9
10
|
'actors/spawn-scripts',
|
|
10
11
|
'actors/return-scripts',
|
|
@@ -192,6 +192,7 @@ import {
|
|
|
192
192
|
QuestNpcBindingSchema,
|
|
193
193
|
QuestNpcBindingsSchema,
|
|
194
194
|
} from './npcs.ts'
|
|
195
|
+
import { SimModulesSchema } from './numeric-frame-v2.ts'
|
|
195
196
|
import { PageLifeSchema } from './pageLife.ts'
|
|
196
197
|
import {
|
|
197
198
|
PaintedAirSchema,
|
|
@@ -572,6 +573,7 @@ const finiteNumbers = new Set<object>([
|
|
|
572
573
|
// Only the exact retained defining roots grant action bridges. A caller's new check or transform never joins.
|
|
573
574
|
const wireRoots: Readonly<Record<string, GenericSchema>> = {
|
|
574
575
|
'audioScene.AudioScene': AudioSceneSchema,
|
|
576
|
+
'numericFrameV2.SimModules': SimModulesSchema,
|
|
575
577
|
'forestPage.LivingPageSites': LivingPageSitesSchema,
|
|
576
578
|
'fixedDraws.FixedDrawRows': FixedDrawRowsSchema,
|
|
577
579
|
'forestPage.ForestPage': ForestPageSchema,
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { array, check, literal, maxLength, pipe, strictObject } from 'valibot'
|
|
2
|
+
|
|
3
|
+
import { SCRIPT_V2_REVISIONS } from './scriptAdmissionV2.ts'
|
|
4
|
+
import { ViewModuleSchema } from './scriptContract.ts'
|
|
5
|
+
import { layoutV2 } from './scriptWireV2.ts'
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
OwnedSimModuleRows,
|
|
9
|
+
OwnedSimModuleRowsInput,
|
|
10
|
+
ScriptV2ContractRows,
|
|
11
|
+
} from './scriptContract.ts'
|
|
12
|
+
import type { V2Layout } from './scriptWireV2.ts'
|
|
13
|
+
import type { GenericSchema } from 'valibot'
|
|
14
|
+
|
|
15
|
+
/** WASM-HOST H13: a numeric script (a script-lane binding, an item hook, a chapter director) on ABI v2. Its host keeps
|
|
16
|
+
* the numeric call it had (inputs, events, effect records, queries); the module runs one call per entry over this
|
|
17
|
+
* fixed frame, bank kind to row capacity: one binding, 16 state and candidate slots, 32 inputs (kind 6, field = input
|
|
18
|
+
* index), 32 events, 128 effect records (kind 10), 16 query misses with 16 replies of up to 96 values. Its I/O base
|
|
19
|
+
* is 0, so its I/O size follows from its pages alone. */
|
|
20
|
+
const CAPACITY: Readonly<Record<number, number>> = {
|
|
21
|
+
1: 1,
|
|
22
|
+
2: 16,
|
|
23
|
+
3: 16,
|
|
24
|
+
6: 32,
|
|
25
|
+
9: 32,
|
|
26
|
+
10: 128,
|
|
27
|
+
11: 16,
|
|
28
|
+
12: 16,
|
|
29
|
+
13: 1536,
|
|
30
|
+
}
|
|
31
|
+
const capacities = new Map<number, number>()
|
|
32
|
+
for (const [kind, capacity] of Object.entries(CAPACITY)) {
|
|
33
|
+
capacities.set(Number(kind), capacity)
|
|
34
|
+
}
|
|
35
|
+
const NUMERIC_V2_CAPACITIES: ReadonlyMap<number, number> = capacities
|
|
36
|
+
const NUMERIC_V2_IO = 0
|
|
37
|
+
/** The ABI a numeric module speaks. */
|
|
38
|
+
const NUMERIC_ABI = 2
|
|
39
|
+
/** At most this many numeric modules in one shard. */
|
|
40
|
+
const SIM_MODULE_LIMIT = 64
|
|
41
|
+
/** The I/O frame a numeric module of `pages` pages admits under. */
|
|
42
|
+
function numericLayoutV2(pages: number): V2Layout {
|
|
43
|
+
return layoutV2(NUMERIC_V2_IO, pages, NUMERIC_V2_CAPACITIES)
|
|
44
|
+
}
|
|
45
|
+
/** A numeric module's byte contract: the ABI 2 sim lane over the fixed numeric frame. */
|
|
46
|
+
function numericContract(pages: number): ScriptV2ContractRows {
|
|
47
|
+
return {
|
|
48
|
+
abi: NUMERIC_ABI,
|
|
49
|
+
lane: 'sim',
|
|
50
|
+
pages,
|
|
51
|
+
ioBytes: numericLayoutV2(pages).bytes,
|
|
52
|
+
compilerRevision: SCRIPT_V2_REVISIONS.compiler,
|
|
53
|
+
admissionRevision: SCRIPT_V2_REVISIONS.admission,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/** A contract a numeric host may run: ABI 2's sim lane over the numeric frame. */
|
|
57
|
+
function isNumericContract(
|
|
58
|
+
contract: Readonly<{
|
|
59
|
+
abi: number
|
|
60
|
+
lane?: string
|
|
61
|
+
pages?: number
|
|
62
|
+
ioBytes?: number
|
|
63
|
+
}>,
|
|
64
|
+
): boolean {
|
|
65
|
+
return (
|
|
66
|
+
contract.abi === NUMERIC_ABI &&
|
|
67
|
+
contract.lane === 'sim' &&
|
|
68
|
+
contract.pages !== undefined &&
|
|
69
|
+
contract.ioBytes === numericLayoutV2(contract.pages).bytes
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
/** The contracts that are not a numeric module's, as [hash, contract] pairs. */
|
|
73
|
+
function withoutNumericModules<
|
|
74
|
+
Contract extends Readonly<{
|
|
75
|
+
abi: number
|
|
76
|
+
lane?: string
|
|
77
|
+
pages?: number
|
|
78
|
+
ioBytes?: number
|
|
79
|
+
}>,
|
|
80
|
+
>(contracts: ReadonlyMap<string, Contract>): [string, Contract][] {
|
|
81
|
+
const out: [string, Contract][] = []
|
|
82
|
+
for (const [hash, contract] of contracts) {
|
|
83
|
+
if (!isNumericContract(contract)) {
|
|
84
|
+
out.push([hash, contract])
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return out
|
|
88
|
+
}
|
|
89
|
+
/** Each id and each module path once. */
|
|
90
|
+
function uniqueModules(rows: readonly Readonly<OwnedSimModuleRows>[]): boolean {
|
|
91
|
+
const ids = new Set<string>()
|
|
92
|
+
const modules = new Set<string>()
|
|
93
|
+
for (const row of rows) {
|
|
94
|
+
ids.add(row.id)
|
|
95
|
+
modules.add(row.module)
|
|
96
|
+
}
|
|
97
|
+
return ids.size === rows.length && modules.size === rows.length
|
|
98
|
+
}
|
|
99
|
+
/** Every row's contract is the numeric frame's for its pages. */
|
|
100
|
+
function onNumericFrame(
|
|
101
|
+
rows: readonly Readonly<OwnedSimModuleRows>[],
|
|
102
|
+
): boolean {
|
|
103
|
+
for (const row of rows) {
|
|
104
|
+
const want = numericContract(row.pages)
|
|
105
|
+
if (row.ioBytes !== want.ioBytes) {
|
|
106
|
+
return false
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return true
|
|
110
|
+
}
|
|
111
|
+
/** `sim/modules`: the ABI v2 modules numeric hosts run (a script-lane binding, an item hook, a chapter director, a
|
|
112
|
+
* brain, a mover, a client script), each a sim module over the numeric frame. */
|
|
113
|
+
const SimModuleSchema = strictObject({
|
|
114
|
+
...ViewModuleSchema.entries,
|
|
115
|
+
side: literal('sim'),
|
|
116
|
+
lane: literal('sim'),
|
|
117
|
+
})
|
|
118
|
+
const SimModuleListSchema = array(SimModuleSchema)
|
|
119
|
+
const SimModulesSchema: GenericSchema<
|
|
120
|
+
OwnedSimModuleRowsInput[],
|
|
121
|
+
OwnedSimModuleRows[]
|
|
122
|
+
> = pipe(
|
|
123
|
+
SimModuleListSchema,
|
|
124
|
+
maxLength(SIM_MODULE_LIMIT),
|
|
125
|
+
check<OwnedSimModuleRows[], string>(
|
|
126
|
+
uniqueModules,
|
|
127
|
+
'Unique sim module ids and paths',
|
|
128
|
+
),
|
|
129
|
+
check<OwnedSimModuleRows[], string>(
|
|
130
|
+
onNumericFrame,
|
|
131
|
+
'A sim module runs over the numeric frame',
|
|
132
|
+
),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
export {
|
|
136
|
+
isNumericContract,
|
|
137
|
+
NUMERIC_V2_CAPACITIES,
|
|
138
|
+
NUMERIC_V2_IO,
|
|
139
|
+
numericContract,
|
|
140
|
+
numericLayoutV2,
|
|
141
|
+
SimModulesSchema,
|
|
142
|
+
withoutNumericModules,
|
|
143
|
+
}
|
|
@@ -34,6 +34,7 @@ import { UiStringsSchema, type UiStrings } from './uiStrings.ts';
|
|
|
34
34
|
import { WorldPhysicsSchema, type WorldPhysics } from './worldPhysics.ts';
|
|
35
35
|
import { WorldTargetsSchema, type WorldTargets } from './worldTargets.ts';
|
|
36
36
|
import { WorldMoversSchema } from './movers.ts';
|
|
37
|
+
import { SimModulesSchema } from './numeric-frame-v2.ts';
|
|
37
38
|
import { ReturnModulesSchema, type ReturnModuleRow, ViewModulesSchema, type ViewModuleRow } from './scriptContract.ts';
|
|
38
39
|
import { NativeRuntimePlanSchema, type NativeRuntimePlanData } from './nativeRuntimePlan.ts';
|
|
39
40
|
import { TreeSetSchema, type TreeSetRows } from './treeSetRows.ts';
|
|
@@ -61,6 +62,7 @@ export interface PlatformDataSections {
|
|
|
61
62
|
'server/patrol': ServerHosts;
|
|
62
63
|
'server/world': ServerWorld;
|
|
63
64
|
'view/modules': ViewModuleRow[];
|
|
65
|
+
'sim/modules': v.InferOutput<typeof SimModulesSchema>;
|
|
64
66
|
'held/arms': HeldArmsRows;
|
|
65
67
|
'held/gear': HeldGearRows;
|
|
66
68
|
'held/finishes': HeldFinishesRows;
|
|
@@ -103,6 +105,7 @@ export const PLATFORM_DATA_SECTIONS: Readonly<{ [Name in keyof PlatformDataSecti
|
|
|
103
105
|
'server/patrol': { schema: ServerHostsSchema },
|
|
104
106
|
'server/world': { schema: ServerWorldSchema },
|
|
105
107
|
'view/modules': { schema: ViewModulesSchema },
|
|
108
|
+
'sim/modules': { schema: SimModulesSchema },
|
|
106
109
|
'held/arms': { schema: HeldArmsSchema },
|
|
107
110
|
'held/gear': { schema: HeldGearSchema },
|
|
108
111
|
'held/finishes': { schema: HeldFinishesSchema },
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
/* oxlint-disable complexity, curly, id-length, max-depth, max-lines-per-function, max-statements, no-continue, no-magic-numbers, no-nested-ternary, no-plusplus, sort-vars, typescript/explicit-function-return-type, typescript/prefer-readonly-parameter-types, unicorn/no-array-callback-reference, unicorn/no-array-reverse, unicorn/no-nested-ternary, unicorn/number-literal-case, import/exports-last, import/group-exports -- the region walk of scriptFuelV2.ts's v2BlockCosts, in its form; engine test/fixtures/v2Path.ts copies it line for line until engine takes this format */
|
|
2
|
+
/** WASM-HOST H2c: v2 fuel regions priced at their longest path, with split regions where a call may skip a big arm. */
|
|
3
|
+
import type { V2Instruction } from './scriptModuleV2.ts'
|
|
4
|
+
|
|
5
|
+
const EXIT = -1
|
|
6
|
+
interface Region {
|
|
7
|
+
readonly start: number
|
|
8
|
+
readonly close: number
|
|
9
|
+
readonly loop: boolean
|
|
10
|
+
}
|
|
11
|
+
interface Shape {
|
|
12
|
+
readonly next: readonly (readonly number[])[]
|
|
13
|
+
readonly closes: readonly number[]
|
|
14
|
+
readonly loops: readonly Region[]
|
|
15
|
+
readonly weight: readonly number[]
|
|
16
|
+
}
|
|
17
|
+
/** WASM-HOST H2c: the smallest own longest path a split region needs, by lane. A split's charge runs on every call that
|
|
18
|
+
* enters it; views loop over many small arms per frame, sims and projections over few big ones (engine
|
|
19
|
+
* `wasm-fuel-ratio --costs=path`, meta support/wasm-host/H2C-RATIOS-2026-12-06.md). */
|
|
20
|
+
export const V2_SPLIT_FLOORS: Readonly<{
|
|
21
|
+
sim: number
|
|
22
|
+
project: number
|
|
23
|
+
view: number
|
|
24
|
+
}> = Object.freeze({ sim: 512, project: 512, view: 136 })
|
|
25
|
+
|
|
26
|
+
/** Each instruction's successors (EXIT for a return, `unreachable`, a branch to a loop or to the body's own label), the
|
|
27
|
+
* close of each instruction's structural level, the loop bodies, and each instruction's price. */
|
|
28
|
+
function shape(
|
|
29
|
+
code: readonly V2Instruction[],
|
|
30
|
+
constantCalls: ReadonlyMap<number, number>,
|
|
31
|
+
): Shape {
|
|
32
|
+
const ends = new Map<number, number>(),
|
|
33
|
+
arms = new Map<number, number>(),
|
|
34
|
+
open: number[] = []
|
|
35
|
+
for (let i = 0; i < code.length; i++) {
|
|
36
|
+
const op = code[i]?.op
|
|
37
|
+
if (op === 0x02 || op === 0x03 || op === 0x04) open.push(i)
|
|
38
|
+
else if (op === 0x05) {
|
|
39
|
+
const at = open.at(-1)
|
|
40
|
+
if (at !== undefined) arms.set(at, i)
|
|
41
|
+
} else if (op === 0x0b) {
|
|
42
|
+
const at = open.pop()
|
|
43
|
+
if (at !== undefined) ends.set(at, i)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const end = (at: number): number => ends.get(at) ?? code.length - 1
|
|
47
|
+
const next: number[][] = [],
|
|
48
|
+
labels: number[] = [],
|
|
49
|
+
closes: number[] = []
|
|
50
|
+
const target = (depth: number): number => {
|
|
51
|
+
const at = labels[labels.length - 1 - depth]
|
|
52
|
+
return at === undefined || code[at]?.op === 0x03 ? EXIT : end(at) + 1
|
|
53
|
+
}
|
|
54
|
+
for (let i = 0; i < code.length; i++) {
|
|
55
|
+
const top = labels.at(-1),
|
|
56
|
+
arm = top === undefined ? undefined : arms.get(top)
|
|
57
|
+
closes.push(
|
|
58
|
+
top === undefined
|
|
59
|
+
? code.length - 1
|
|
60
|
+
: arm !== undefined && i <= arm
|
|
61
|
+
? arm
|
|
62
|
+
: end(top),
|
|
63
|
+
)
|
|
64
|
+
const value = code[i],
|
|
65
|
+
op = value?.op
|
|
66
|
+
if (op === 0x0c) next.push([target(value?.args[0] ?? 0)])
|
|
67
|
+
else if (op === 0x0d) next.push([i + 1, target(value?.args[0] ?? 0)])
|
|
68
|
+
else if (op === 0x0e) next.push((value?.args ?? []).map(target))
|
|
69
|
+
else if (op === 0x0f || op === 0x00) next.push([EXIT])
|
|
70
|
+
else if (op === 0x04) next.push([i + 1, (arms.get(i) ?? end(i)) + 1])
|
|
71
|
+
else if (op === 0x05) next.push([end(top ?? -1) + 1])
|
|
72
|
+
else next.push([i + 1])
|
|
73
|
+
if (op === 0x02 || op === 0x03 || op === 0x04) labels.push(i)
|
|
74
|
+
else if (op === 0x0b) labels.pop()
|
|
75
|
+
}
|
|
76
|
+
const loops = [...ends]
|
|
77
|
+
.filter(([at]) => code[at]?.op === 0x03)
|
|
78
|
+
.map(([at, last]) => ({ start: at + 1, close: last, loop: true }))
|
|
79
|
+
const weight = code.map(
|
|
80
|
+
value =>
|
|
81
|
+
1 +
|
|
82
|
+
(value.op === 0x10 ? (constantCalls.get(value.args[0] ?? -1) ?? 0) : 0),
|
|
83
|
+
)
|
|
84
|
+
return { next, closes, loops, weight }
|
|
85
|
+
}
|
|
86
|
+
/** The longest path through `region` from its start, each region in `inner` nested in it charged on its own: the path
|
|
87
|
+
* steps over such a region to wherever it can leave to (a loop's own op still counts here). */
|
|
88
|
+
function longestOf(s: Shape, region: Region, inner: readonly Region[]): number {
|
|
89
|
+
const nested = inner.filter(
|
|
90
|
+
row =>
|
|
91
|
+
row !== region && row.start >= region.start && row.close <= region.close,
|
|
92
|
+
)
|
|
93
|
+
const children = nested.filter(
|
|
94
|
+
row =>
|
|
95
|
+
!nested.some(
|
|
96
|
+
other =>
|
|
97
|
+
other !== row && other.start <= row.start && other.close >= row.close,
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
const entry = new Map<number, Region>(),
|
|
101
|
+
inside = new Set<number>()
|
|
102
|
+
for (const child of children) {
|
|
103
|
+
entry.set(child.loop ? child.start - 1 : child.start, child)
|
|
104
|
+
for (let at = child.start; at <= child.close; at++) inside.add(at)
|
|
105
|
+
}
|
|
106
|
+
const longest = new Map<number, number>()
|
|
107
|
+
for (let at = region.close; at >= region.start; at--) {
|
|
108
|
+
const child = entry.get(at)
|
|
109
|
+
if (child === undefined && inside.has(at)) continue
|
|
110
|
+
let after: readonly number[] = s.next[at] ?? [EXIT],
|
|
111
|
+
weight = s.weight[at] ?? 1
|
|
112
|
+
if (child !== undefined) {
|
|
113
|
+
const out = new Set<number>()
|
|
114
|
+
for (let j = child.start; j <= child.close; j++)
|
|
115
|
+
for (const to of s.next[j] ?? [])
|
|
116
|
+
if (to < child.start || to > child.close) out.add(to)
|
|
117
|
+
after = [...out]
|
|
118
|
+
if (!child.loop) weight = 0
|
|
119
|
+
}
|
|
120
|
+
let best = 0
|
|
121
|
+
for (const to of after)
|
|
122
|
+
if (to >= region.start && to <= region.close)
|
|
123
|
+
best = Math.max(best, longest.get(to) ?? 0)
|
|
124
|
+
longest.set(at, weight + best)
|
|
125
|
+
}
|
|
126
|
+
return longest.get(region.start) ?? 0
|
|
127
|
+
}
|
|
128
|
+
/** WASM-HOST H2c: where a charge may also stand. Each point is entered only from just before it (an `if` arm, an
|
|
129
|
+
* `else` arm, the fall-through of a `br_if`, the join after an `end`, where every branch to that label lands), and its
|
|
130
|
+
* region runs to the close of its level. */
|
|
131
|
+
export function v2SplitPoints(
|
|
132
|
+
code: readonly V2Instruction[],
|
|
133
|
+
): ReadonlySet<number> {
|
|
134
|
+
const points = new Set<number>()
|
|
135
|
+
for (let i = 0; i + 1 < code.length; i++) {
|
|
136
|
+
const op = code[i]?.op
|
|
137
|
+
if (op === 0x04 || op === 0x05 || op === 0x0d || op === 0x0b)
|
|
138
|
+
points.add(i + 1)
|
|
139
|
+
}
|
|
140
|
+
return points
|
|
141
|
+
}
|
|
142
|
+
/** WASM-HOST H2c: the split points a compiler charges, innermost first: each whose own longest path, past the splits
|
|
143
|
+
* already charged inside it and its loops, is `floor` or more (`V2_SPLIT_FLOORS` by lane). */
|
|
144
|
+
export function v2SplitStarts(
|
|
145
|
+
code: readonly V2Instruction[],
|
|
146
|
+
constantCalls: ReadonlyMap<number, number>,
|
|
147
|
+
floor: number,
|
|
148
|
+
): ReadonlySet<number> {
|
|
149
|
+
const s = shape(code, constantCalls),
|
|
150
|
+
chosen: Region[] = []
|
|
151
|
+
for (const at of [...v2SplitPoints(code)].reverse()) {
|
|
152
|
+
const region = {
|
|
153
|
+
start: at,
|
|
154
|
+
close: s.closes[at] ?? code.length - 1,
|
|
155
|
+
loop: false,
|
|
156
|
+
}
|
|
157
|
+
if (longestOf(s, region, [...s.loops, ...chosen]) >= floor)
|
|
158
|
+
chosen.push(region)
|
|
159
|
+
}
|
|
160
|
+
return new Set(chosen.map(region => region.start))
|
|
161
|
+
}
|
|
162
|
+
/** WASM-HOST H2c: each region (the body, each loop body, each split in `splits`) priced at its longest path, not every
|
|
163
|
+
* instruction it holds. A call that takes one `if` arm, one `br_table` case or an early exit runs no more than that
|
|
164
|
+
* path, so a charge of this price covers every instruction run; an if/else or a switch pays for its longest arm, and a
|
|
165
|
+
* split arm a call skips is not paid at all (H2b read up to 14x over-billing). Edges: fall-through, `if` to its arm or
|
|
166
|
+
* past it, `else` past its `end`, a branch to past its block's `end`, and from a nested loop or split to wherever it
|
|
167
|
+
* can leave to. A return, `unreachable`, a branch to a loop (the loop charges again) or past the region ends a path. */
|
|
168
|
+
export function v2PathCosts(
|
|
169
|
+
code: readonly V2Instruction[],
|
|
170
|
+
constantCalls: ReadonlyMap<number, number> = new Map(),
|
|
171
|
+
splits: ReadonlySet<number> = new Set(),
|
|
172
|
+
): ReadonlyMap<number, number> {
|
|
173
|
+
const points = v2SplitPoints(code)
|
|
174
|
+
if ([...splits].some(at => !points.has(at)))
|
|
175
|
+
throw new Error('V2 split outside a split point')
|
|
176
|
+
const s = shape(code, constantCalls)
|
|
177
|
+
const regions: Region[] = [
|
|
178
|
+
{ start: 0, close: code.length - 1, loop: true },
|
|
179
|
+
...s.loops,
|
|
180
|
+
...[...splits].map(at => ({
|
|
181
|
+
start: at,
|
|
182
|
+
close: s.closes[at] ?? code.length - 1,
|
|
183
|
+
loop: false,
|
|
184
|
+
})),
|
|
185
|
+
]
|
|
186
|
+
return new Map(
|
|
187
|
+
regions.map(region => [region.start, longestOf(s, region, regions)]),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
@@ -5,11 +5,14 @@ const CREATURE_COMMANDS = { lockable: 23, heal: 24, pull: 25, root: 26, ability:
|
|
|
5
5
|
/** ONE-FORMAT CC59: a brain hook hears `part.broken` [actor, volume index]; `ability` [own actor, strike] replaces its
|
|
6
6
|
* brain's next pick. A hit event's last slot is the mask of the row's `tags` the hit carried (bit i: i-th alias). */
|
|
7
7
|
const CREATURE_EVENTS = { 'part.broken': 19 } as const;
|
|
8
|
+
/** WASM-HOST H25 (Jake's W27): `wake` [0, seconds slept] reaches a subscribed sim binding once when its slept cell next
|
|
9
|
+
* seats a player. Timers keep counting sim ticks; the script decides its own catch-up. */
|
|
10
|
+
const WAKE_EVENTS = { wake: 20 } as const;
|
|
8
11
|
/** ABI-v1 numeric transport. These ids are shared by admission, generated bindings and the decision host. */
|
|
9
|
-
export const SCRIPT_V1_EVENTS: Readonly<{ start: 1; tick: 2; timer: 3; 'zone.enter': 4; 'zone.leave': 5; interact: 6; hit: 7; threshold: 8; death: 9; 'move.done': 10; 'strike.done': 11; flag: 12; signal: 13; 'strike.target': 14; 'player.join': 15; 'player.leave': 16; spawned: 17; stop: 18; field: 30; cue: 31; channel: 32; } & typeof CREATURE_EVENTS> = Object.freeze({
|
|
12
|
+
export const SCRIPT_V1_EVENTS: Readonly<{ start: 1; tick: 2; timer: 3; 'zone.enter': 4; 'zone.leave': 5; interact: 6; hit: 7; threshold: 8; death: 9; 'move.done': 10; 'strike.done': 11; flag: 12; signal: 13; 'strike.target': 14; 'player.join': 15; 'player.leave': 16; spawned: 17; stop: 18; field: 30; cue: 31; channel: 32; } & typeof CREATURE_EVENTS & typeof WAKE_EVENTS> = Object.freeze({
|
|
10
13
|
start: 1, tick: 2, timer: 3, 'zone.enter': 4, 'zone.leave': 5, interact: 6, hit: 7, threshold: 8,
|
|
11
14
|
death: 9, 'move.done': 10, 'strike.done': 11, flag: 12, signal: 13, 'strike.target': 14,
|
|
12
|
-
'player.join': 15, 'player.leave': 16, spawned: 17, stop: 18, ...CREATURE_EVENTS, field: 30, cue: 31, channel: 32,
|
|
15
|
+
'player.join': 15, 'player.leave': 16, spawned: 17, stop: 18, ...CREATURE_EVENTS, ...WAKE_EVENTS, field: 30, cue: 31, channel: 32,
|
|
13
16
|
});
|
|
14
17
|
/** Scalar reads; timer and random are answered by the host's own binding state. */
|
|
15
18
|
export const SCRIPT_V1_READS: Readonly<{ x: 1; y: 2; z: 3; yaw: 4; hpShare: 5; alive: 6; field: 7; distance: 8; nearestPlayer: 9; flag: 10; timerLeft: 11; random: 12; actorInZone: 13; playersInZone: 14; moving: 15; strikeState: 16; playerFlag: 17; spawnGroupAlive: 18; bearing: 19; bodyX: 20; bodyY: 21; bodyZ: 22; bodyAlive: 23; bodyYaw: 24; bodyVisible: 25; playerIntent: 26; }> = Object.freeze({
|
|
@@ -85,7 +85,7 @@ export function scriptAdmissionRows(sections?: ReadonlyMap<string, unknown>): Sc
|
|
|
85
85
|
const decisions = parseDecisionScripts([...decisionScriptsFromSections(sections), ...spawn.map(row => row.script),
|
|
86
86
|
...returns.filter(row=>row.abi!==2)]);
|
|
87
87
|
const owned = spawn.flatMap(row => row.v2 === undefined ? [] : [{ abi: 2 as const,id: `${row.step}:v2`,side: 'sim' as const,lane: 'sim' as const,module: `blobs/wasm/${row.v2.artifact.hash}.wasm`,pages: row.v2.artifact.pages,ioBytes: row.v2.artifact.ioBytes,compilerRevision: row.v2.artifact.compilerRevision,admissionRevision: row.v2.artifact.admissionRevision }]);
|
|
88
|
-
return [...decisions, ...v.parse(ViewModulesSchema, sections?.get('view/modules') ?? []),...owned,...returns.filter(row=>row.abi===2)];
|
|
88
|
+
return [...decisions, ...v.parse(ViewModulesSchema, sections?.get('view/modules') ?? []), ...v.parse(v.array(OwnedSimModuleSchema), sections?.get('sim/modules') ?? []),...owned,...returns.filter(row=>row.abi===2)];
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
/** Fresh v1 memory is consumed only by stateful sim decisions, once per module.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* not permission to instantiate an image by itself. */
|
|
3
3
|
import { SCRIPT_ABI } from './scriptAbi.ts';
|
|
4
4
|
import { readV2Module,type V2Instruction,type V2Module,type V2Signature } from './scriptModuleV2.ts';
|
|
5
|
+
import { v2PathCosts,v2SplitPoints } from './script-fuel-path-v2.ts';
|
|
5
6
|
|
|
6
7
|
export const V2_ENTRY_SIGNATURES: Readonly<Record<string,readonly number[]>> = Object.freeze({
|
|
7
8
|
ws_init: [0x7f,0x7f,0x7f], ws_step: [0x7f,0x7f], ws_project: [0x7f], ws_view: [0x7c,0x7c,0x7f],
|
|
@@ -107,8 +108,10 @@ export function inspectV2Fuel(bytes: Uint8Array,options: { readonly lane?: V2Lan
|
|
|
107
108
|
}
|
|
108
109
|
plain.push(value);
|
|
109
110
|
}
|
|
110
|
-
|
|
111
|
-
|
|
111
|
+
// H2c: each region, and each split a charge stands on, pays at least its longest path (script-fuel-path-v2.ts)
|
|
112
|
+
const points = v2SplitPoints(plain);
|
|
113
|
+
const costs = v2PathCosts(plain,new Map([...getters].map(target => [target,2])),new Set([...charges.keys()].filter((at: number): boolean => points.has(at))));
|
|
114
|
+
if (costs.size !== charges.size || [...costs].some(([at,cost]) => (charges.get(at) ?? Number.NEGATIVE_INFINITY) < cost)) throw new Error('Missing or underpriced v2 basic block region');
|
|
112
115
|
unmetered.push(plain); calls.push(edges);
|
|
113
116
|
}
|
|
114
117
|
const depths = new Map<number,number>(), active = new Set<number>();
|
package/src/format/sections.ts
CHANGED
|
@@ -13,7 +13,7 @@ import type { QuestServer } from './quest-server.ts';
|
|
|
13
13
|
import type { ServerHosts } from './server-hosts.ts';
|
|
14
14
|
import type { ServerWorld } from './server-world.ts';
|
|
15
15
|
import type { NativeSweptPolicyRows } from './items.ts';
|
|
16
|
-
import type { ReturnModuleRow, ViewModuleRow } from './scriptContract.ts';
|
|
16
|
+
import type { OwnedSimModuleRows, ReturnModuleRow, ViewModuleRow } from './scriptContract.ts';
|
|
17
17
|
import type { WorldScenesSection } from './worldScenes.ts';
|
|
18
18
|
import type { TreeSetRows } from './treeSetRows.ts';
|
|
19
19
|
import type { Vehicles } from './vehicles.ts';
|
|
@@ -54,6 +54,8 @@ export interface PlatformSections {
|
|
|
54
54
|
'models/island-library': ResolvedIslandLibraryRows;
|
|
55
55
|
'player/stealth':StealthRows;
|
|
56
56
|
'view/modules': ViewModuleRow[];
|
|
57
|
+
/** WASM-HOST H13: the ABI v2 modules numeric hosts run. */
|
|
58
|
+
'sim/modules': OwnedSimModuleRows[];
|
|
57
59
|
/** Client-only ordered model references, ignored by simulation. */
|
|
58
60
|
'explore/catalogue': ExplorerCatalogue;
|
|
59
61
|
'look/toon': ToonLookRow;
|
|
@@ -148,6 +148,12 @@
|
|
|
148
148
|
"sim/hooks": {
|
|
149
149
|
"hosts": ["server createShardfileScriptLane"]
|
|
150
150
|
},
|
|
151
|
+
"sim/modules": {
|
|
152
|
+
"hosts": [
|
|
153
|
+
"shard-format SimModulesSchema",
|
|
154
|
+
"shard-format admitScriptContract"
|
|
155
|
+
]
|
|
156
|
+
},
|
|
151
157
|
"sim/plumbing": {
|
|
152
158
|
"hosts": ["page installDeclaredPlumbing"]
|
|
153
159
|
},
|