@i7r.tech/moveby 0.0.0-stage → 0.21.1-ywc
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/LICENSE +202 -0
- package/README.md +67 -2
- package/bin/index.js +34557 -0
- package/bin/moveby.js +8994 -0
- package/bin/parse-worker.mjs +39 -0
- package/bin/tooling/wasm_engine.cjs +131 -0
- package/bin/tooling/wasm_engine_bg.wasm +0 -0
- package/dist/engine/wasm_engine.d.ts +358 -0
- package/dist/engine/wasm_engine.js +766 -0
- package/dist/engine/wasm_engine_bg.wasm +0 -0
- package/dist/errors.d.ts +16 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1942 -0
- package/dist/passes/backdrop.d.ts +9 -0
- package/dist/passes/field.d.ts +33 -0
- package/dist/passes/index.d.ts +5 -0
- package/dist/passes/road.d.ts +23 -0
- package/dist/passes/scenery.d.ts +30 -0
- package/dist/passes/sky.d.ts +12 -0
- package/dist/passes/text.d.ts +27 -0
- package/dist/scene-module.d.ts +165 -0
- package/dist/scene.d.ts +59 -0
- package/dist/utils.d.ts +22 -0
- package/docs/attribution.md +31 -0
- package/docs/decisions.md +26 -0
- package/package.json +33 -4
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The deep-parse fallback: parse and compile on a thread whose stack is sized for it.
|
|
2
|
+
//
|
|
3
|
+
// `compileSource` catches the RangeError a too-deep program raises on the main thread and
|
|
4
|
+
// hands the loaded texts of the program here. This file is plain JavaScript on purpose: a
|
|
5
|
+
// worker thread loads it before any TypeScript loader the parent registered can apply, so it
|
|
6
|
+
// sets up its own.
|
|
7
|
+
|
|
8
|
+
import { parentPort } from 'node:worker_threads';
|
|
9
|
+
|
|
10
|
+
// In a checkout the entry point is `src/index.ts`, and reading it needs the loader hooks
|
|
11
|
+
// that `tsx` provides. In a built package `./index.js` is plain JavaScript, and the first
|
|
12
|
+
// import already works. Either way `api` ends up as the front end of this same tree.
|
|
13
|
+
let api;
|
|
14
|
+
try {
|
|
15
|
+
api = await import('./index.js');
|
|
16
|
+
} catch {
|
|
17
|
+
const { register } = await import('tsx/esm/api');
|
|
18
|
+
register();
|
|
19
|
+
api = await import('./index.js');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
parentPort.on('message', async (program) => {
|
|
23
|
+
try {
|
|
24
|
+
parentPort.postMessage(await api.compileLoaded(program));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
parentPort.postMessage({
|
|
27
|
+
ok: false,
|
|
28
|
+
errors: [
|
|
29
|
+
{
|
|
30
|
+
message:
|
|
31
|
+
`the expression nests deeper than the compiler can read ` +
|
|
32
|
+
`(${error.message})`,
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
warnings: [],
|
|
36
|
+
links: [],
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* @ts-self-types="./wasm_engine.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The TOOLING export (road-file, decisions 8 and 79; moveby-build, decision 82): `encode_track` for
|
|
5
|
+
* the build, in Node. It is the one export of the `tooling` flavor, and no page's `.wasm` has it. The
|
|
6
|
+
* four numbers after the records are the field grid. Then the sprite grid (empty, or four numbers),
|
|
7
|
+
* then the font (empty, or its header and its glyphs).
|
|
8
|
+
* @param {Int32Array} route
|
|
9
|
+
* @param {Float32Array} lane_records
|
|
10
|
+
* @param {Float32Array} field_records
|
|
11
|
+
* @param {number} cols
|
|
12
|
+
* @param {number} rows
|
|
13
|
+
* @param {number} px_width
|
|
14
|
+
* @param {number} px_height
|
|
15
|
+
* @param {Uint32Array} sprite_grid
|
|
16
|
+
* @param {Float32Array} font
|
|
17
|
+
* @returns {Uint8Array}
|
|
18
|
+
*/
|
|
19
|
+
function encode_track_bytes(route, lane_records, field_records, cols, rows, px_width, px_height, sprite_grid, font) {
|
|
20
|
+
const ptr0 = passArray32ToWasm0(route, wasm.__wbindgen_malloc);
|
|
21
|
+
const len0 = WASM_VECTOR_LEN;
|
|
22
|
+
const ptr1 = passArrayF32ToWasm0(lane_records, wasm.__wbindgen_malloc);
|
|
23
|
+
const len1 = WASM_VECTOR_LEN;
|
|
24
|
+
const ptr2 = passArrayF32ToWasm0(field_records, wasm.__wbindgen_malloc);
|
|
25
|
+
const len2 = WASM_VECTOR_LEN;
|
|
26
|
+
const ptr3 = passArray32ToWasm0(sprite_grid, wasm.__wbindgen_malloc);
|
|
27
|
+
const len3 = WASM_VECTOR_LEN;
|
|
28
|
+
const ptr4 = passArrayF32ToWasm0(font, wasm.__wbindgen_malloc);
|
|
29
|
+
const len4 = WASM_VECTOR_LEN;
|
|
30
|
+
const ret = wasm.encode_track_bytes(ptr0, len0, ptr1, len1, ptr2, len2, cols, rows, px_width, px_height, ptr3, len3, ptr4, len4);
|
|
31
|
+
if (ret[3]) {
|
|
32
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
33
|
+
}
|
|
34
|
+
var v6 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
35
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
36
|
+
return v6;
|
|
37
|
+
}
|
|
38
|
+
exports.encode_track_bytes = encode_track_bytes;
|
|
39
|
+
function __wbg_get_imports() {
|
|
40
|
+
const import0 = {
|
|
41
|
+
__proto__: null,
|
|
42
|
+
__wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {
|
|
43
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
44
|
+
return ret;
|
|
45
|
+
},
|
|
46
|
+
__wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
|
|
47
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
48
|
+
},
|
|
49
|
+
__wbindgen_init_externref_table: function() {
|
|
50
|
+
const table = wasm.__wbindgen_externrefs;
|
|
51
|
+
const offset = table.grow(4);
|
|
52
|
+
table.set(0, undefined);
|
|
53
|
+
table.set(offset + 0, undefined);
|
|
54
|
+
table.set(offset + 1, null);
|
|
55
|
+
table.set(offset + 2, true);
|
|
56
|
+
table.set(offset + 3, false);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
return {
|
|
60
|
+
__proto__: null,
|
|
61
|
+
"./wasm_engine_bg.js": import0,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
66
|
+
ptr = ptr >>> 0;
|
|
67
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let cachedFloat32ArrayMemory0 = null;
|
|
71
|
+
function getFloat32ArrayMemory0() {
|
|
72
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
73
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
74
|
+
}
|
|
75
|
+
return cachedFloat32ArrayMemory0;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getStringFromWasm0(ptr, len) {
|
|
79
|
+
return decodeText(ptr >>> 0, len);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let cachedUint32ArrayMemory0 = null;
|
|
83
|
+
function getUint32ArrayMemory0() {
|
|
84
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
85
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
86
|
+
}
|
|
87
|
+
return cachedUint32ArrayMemory0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let cachedUint8ArrayMemory0 = null;
|
|
91
|
+
function getUint8ArrayMemory0() {
|
|
92
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
93
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
94
|
+
}
|
|
95
|
+
return cachedUint8ArrayMemory0;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
99
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
100
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
101
|
+
WASM_VECTOR_LEN = arg.length;
|
|
102
|
+
return ptr;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function passArrayF32ToWasm0(arg, malloc) {
|
|
106
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
107
|
+
getFloat32ArrayMemory0().set(arg, ptr / 4);
|
|
108
|
+
WASM_VECTOR_LEN = arg.length;
|
|
109
|
+
return ptr;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function takeFromExternrefTable0(idx) {
|
|
113
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
114
|
+
wasm.__externref_table_dealloc(idx);
|
|
115
|
+
return value;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
119
|
+
cachedTextDecoder.decode();
|
|
120
|
+
function decodeText(ptr, len) {
|
|
121
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let WASM_VECTOR_LEN = 0;
|
|
125
|
+
|
|
126
|
+
const wasmPath = `${__dirname}/wasm_engine_bg.wasm`;
|
|
127
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
128
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
129
|
+
let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
|
|
130
|
+
let wasm = wasmInstance.exports;
|
|
131
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The SHAPE of a lane divider (engine-lanes.v1.1 §4, lane-divider-type.md). `#[wasm_bindgen]` exports it to
|
|
6
|
+
* TS as a NUMERIC enum (`DividerPattern.Dashed = 0`, `Solid = 1`, `Double = 2`), so the JS config writes
|
|
7
|
+
* `dividerPattern: wasm.DividerPattern.Double`. The decoder reads that number through `TryFrom<u8>` (rejects
|
|
8
|
+
* out-of-range at the boundary — its validity IS the type, the `Side` precedent, no domain-error row). COLOUR
|
|
9
|
+
* and dash lengths are SEPARATE `LaneSpan` axes, not folded into this enum (option B of OQ#3).
|
|
10
|
+
*/
|
|
11
|
+
export enum DividerPattern {
|
|
12
|
+
Dashed = 0,
|
|
13
|
+
Solid = 1,
|
|
14
|
+
Double = 2,
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export class Engine {
|
|
18
|
+
private constructor();
|
|
19
|
+
free(): void;
|
|
20
|
+
[Symbol.dispose](): void;
|
|
21
|
+
/**
|
|
22
|
+
* The live viewport aspect (canvasW / canvasH), for the scenery vertex shader's `u_aspect` — the
|
|
23
|
+
* ONLY place project-in-shader lets aspect enter the scenery projection (never baked into
|
|
24
|
+
* the camera that `fill_camera` writes, so a stray second divide can't creep in). JS already knows this value locally (it
|
|
25
|
+
* computed it to call `set_aspect`); this getter exists so the scenery pass can read it back the
|
|
26
|
+
* same way every other per-frame uniform is read, off `&self`.
|
|
27
|
+
*/
|
|
28
|
+
aspect(): number;
|
|
29
|
+
/**
|
|
30
|
+
* The focal length (`CAMERA_DEPTH`, consts.rs) for the scenery vertex shader's `u_cameraDepth`
|
|
31
|
+
* uniform — sent so a FOV change in Rust can't silently desync from a hardcoded GLSL literal (OQ4,
|
|
32
|
+
* project-in-shader.md; the same precedent `depth_bounds` already set for `u_scaleNear/Far`).
|
|
33
|
+
*/
|
|
34
|
+
camera_depth(): number;
|
|
35
|
+
/**
|
|
36
|
+
* The byte address of the camera scratch in WebAssembly memory: six `f32`, written by `fill_camera`.
|
|
37
|
+
* A query (`&self`). The address does not move for the life of the engine, so JavaScript reads it
|
|
38
|
+
* once.
|
|
39
|
+
*/
|
|
40
|
+
camera_ptr(): number;
|
|
41
|
+
/**
|
|
42
|
+
* The JS entry of the frame's value block (lib-value-entry): check the staging block that
|
|
43
|
+
* `value_view` handed out; on success copy it into the live block and seat the camera from its
|
|
44
|
+
* slots 0 and 1 (decision 62). ALL-OR-NOTHING, like `set_value_block`: a bad value changes
|
|
45
|
+
* nothing — the live block AND the camera — so the next draw never mixes two frames' values and
|
|
46
|
+
* never rides a seat no good frame named. Returns −1 on success, else the first bad value's
|
|
47
|
+
* index in the block. A number only: the binding names the fault (`SCENE_VALUE`); the engine
|
|
48
|
+
* sends no prose across the seam.
|
|
49
|
+
*/
|
|
50
|
+
commit_value_block(): number;
|
|
51
|
+
/**
|
|
52
|
+
* Per-frame dash anchor for the road vertex shader's `u_dashAnchor` — the largest whole number of
|
|
53
|
+
* FULL dash periods at or below the PLAYER's road-SURFACE distance (not horizontal `position`: the
|
|
54
|
+
* dash ruler is `surface_length`, the slant distance, so a climbing road's stripes don't
|
|
55
|
+
* foreshorten). Thin wrapper on the existing free `dash_anchor` (layers/road.rs) — not re-derived.
|
|
56
|
+
*/
|
|
57
|
+
dash_anchor(): number;
|
|
58
|
+
/**
|
|
59
|
+
* The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, SCALE_FAR]`.
|
|
60
|
+
* The renderer feeds these to the vertex shader's `u_scaleNear` / `u_scaleFar` uniforms so
|
|
61
|
+
* the GLSL depth map reads the SAME source as the Rust `depth_ndc` mirror — no GLSL↔Rust
|
|
62
|
+
* constant can drift (unlike the DASH_* duplication). Static (derived from camera consts),
|
|
63
|
+
* so the renderer reads this ONCE and caches it — no per-frame marshalling. See depth-test.md.
|
|
64
|
+
*/
|
|
65
|
+
depth_bounds(): Float32Array;
|
|
66
|
+
/**
|
|
67
|
+
* v1.1 (scenery-atlas-cells) — ATLAS-CELL field draw buckets from the last `fill_field_*`: a flat
|
|
68
|
+
* `[u0, v0, u1, v1, start_vertex, count]` per bucket (the sub-rect as a per-draw `u_cellRect` uniform +
|
|
69
|
+
* the vertex range). The renderer draws these with the fract-tile program on the SHARED atlas (NEAREST/
|
|
70
|
+
* no-mips). CACHED like `field_draw_ranges` — valid only after this frame's `fill_field_*`, empty before.
|
|
71
|
+
*
|
|
72
|
+
* A VIEW, like `field_draw_ranges`: valid until the next call into WebAssembly.
|
|
73
|
+
*/
|
|
74
|
+
field_atlas_draw_ranges(): Float32Array;
|
|
75
|
+
/**
|
|
76
|
+
* Per-texture field draw buckets from the LAST `fill_field_*`: a flat `[texture_id, start_vertex,
|
|
77
|
+
* count, …]` triple per non-empty bucket, ascending by id (the renderer binds `registry[id]` then
|
|
78
|
+
* draws `count` verts from `start_vertex`, once per ground texture). **CACHED, not re-emitted** —
|
|
79
|
+
* a query whose validity depends on a prior `fill_field_*` (re-emitting would re-allocate a
|
|
80
|
+
* field-sized buffer every frame, the GC churn zero-copy kills): the CURRENT frame's buckets only
|
|
81
|
+
* after this frame's fill, **empty before the first fill**. Per-frame order:
|
|
82
|
+
* `seek → fill_field_and_view → bufferSubData → field_draw_ranges → bind+draw`.
|
|
83
|
+
*
|
|
84
|
+
* A VIEW of the cached list, not a copy (frame-static-memory): it aliases WebAssembly memory and is
|
|
85
|
+
* valid until the next call into WebAssembly. Read it at once, and take no engine call while a loop
|
|
86
|
+
* reads it. The Rust name has `_view` because the `cargo test` seam `EngineTestExt::field_draw_ranges`
|
|
87
|
+
* keeps the plain name and returns a `Vec`.
|
|
88
|
+
*/
|
|
89
|
+
field_draw_ranges(): Uint32Array;
|
|
90
|
+
fill_and_view(): Float32Array;
|
|
91
|
+
/**
|
|
92
|
+
* The per-frame camera basis for the scenery vertex shader's projection: `[pos.x,y,z, forward.x,y,z]`
|
|
93
|
+
* (6 floats — NOT the 12 a naive `{pos,forward,right,up}` flattening would send). `right` and
|
|
94
|
+
* world-`up` are deliberately NOT included: `Camera::right()` DERIVES right from forward
|
|
95
|
+
* (`(forward.z, 0, −forward.x)`, camera.rs) rather than storing it, and `Camera::project`'s `cy` is
|
|
96
|
+
* just `ray.y` (world-up is the constant (0,1,0), never dotted). Sending only the minimal
|
|
97
|
+
* independent basis means the GLSL `project()` must derive `right` the same way — which is exactly
|
|
98
|
+
* what keeps it an auditable line-for-line mirror of `Camera::project` (camera.rs) rather than a
|
|
99
|
+
* second copy that could silently drift out of orthogonality.
|
|
100
|
+
*
|
|
101
|
+
* This writes the six floats into the engine's own scratch; it returns nothing. JavaScript reads
|
|
102
|
+
* them through two views over that scratch (`camera_ptr`, `wasm_memory`), and calls this once per
|
|
103
|
+
* frame, after the frame's position is set. The views stay valid until WebAssembly memory grows.
|
|
104
|
+
*/
|
|
105
|
+
fill_camera(): void;
|
|
106
|
+
fill_field_and_view(): Float32Array;
|
|
107
|
+
fill_scenery_and_view(): Float32Array;
|
|
108
|
+
fill_text_and_view(): Float32Array;
|
|
109
|
+
/**
|
|
110
|
+
* The first asset of `rows` whose cell block does not fit the atlas grid of the track in
|
|
111
|
+
* `bytes`: its index among the rows' assets, or −1 when every one fits. A query: it builds
|
|
112
|
+
* nothing and consumes nothing. Construction refuses such an asset too (O12), with a code that
|
|
113
|
+
* names no asset; this lets the library name the record. `bytes` is a `Uint8Array`.
|
|
114
|
+
*/
|
|
115
|
+
static first_asset_outside_grid(bytes: Uint8Array, rows: Rows): number;
|
|
116
|
+
/**
|
|
117
|
+
* Construction from the **X2 binary wire** (`config_wire`, engine-config-wire.md) — the byte twin of
|
|
118
|
+
* `new`'s JS-object path, coexisting with it (additive, non-breaking). Decodes the (possibly
|
|
119
|
+
* UNTRUSTED) blob into the SAME `EngineConfig` and runs the SAME `from_parts` — so the two
|
|
120
|
+
* constructors CONVERGE by construction: ONLY field EXTRACTION differs (a bounds-checked byte cursor
|
|
121
|
+
* vs `Reflect::get`); the O-table validation + sizing + build are shared verbatim. A byte fault
|
|
122
|
+
* crosses the seam as a short STABLE code (`WireError::code()`, e.g. `WIRE_TRUNCATED`) — never a
|
|
123
|
+
* panic, never an empty-as-success render (Core Principle 3 / PRINCIPLES §7). A fetched blob is
|
|
124
|
+
* untrusted (unlike the build-baked polyline), so this is adversarial hardening
|
|
125
|
+
* (feedback_build_time_input_not_untrusted). `bytes` is a `Uint8Array` at the JS seam.
|
|
126
|
+
*/
|
|
127
|
+
static from_config_bytes(bytes: Uint8Array): Engine;
|
|
128
|
+
/**
|
|
129
|
+
* Construction from the track bytes AND the scene's placed rows (scene-wasm-handoff, decision
|
|
130
|
+
* 76). `rows` holds what a scene module declares: its assets, its objects and its labels. The
|
|
131
|
+
* track holds the rest — the route, the atlas grid, the font. The engine consumes `rows`. The
|
|
132
|
+
* track must declare no placed rows of its own, and must hold each section a row needs (the
|
|
133
|
+
* atlas grid for an asset or an object, the font for a label): else `SCENE_TRACK`. Then the same
|
|
134
|
+
* rules apply as for `from_config_bytes` (O12, O13, T6). `bytes` is a `Uint8Array`.
|
|
135
|
+
*/
|
|
136
|
+
static from_config_bytes_with_rows(bytes: Uint8Array, rows: Rows): Engine;
|
|
137
|
+
/**
|
|
138
|
+
* The screen height (ndc_y ∈ [-1, 1]) of the visible horizon: the HIGHEST point of the road
|
|
139
|
+
* ribbon (centre + both edges) over the visible window, projected. On a climb that is the far
|
|
140
|
+
* end; on a crest, the crest; on a descent, a near sample. The renderer fills the GROUND
|
|
141
|
+
* background up to this line and paints SKY above it — so the off-road region the field cannot
|
|
142
|
+
* reach (depth-capped, and folded on the inside of a bend) reads as ground, not as the sharp-bend
|
|
143
|
+
* sky slivers. Per-frame (depends on `position`) but cheap: ~3 projects per window sample, all
|
|
144
|
+
* flops, no allocation. Returns 0.0 when nothing is visible (player past the track end).
|
|
145
|
+
*/
|
|
146
|
+
horizon_ndc_y(): number;
|
|
147
|
+
/**
|
|
148
|
+
* The layers this track declares, as the track file's section tags, ascending: 1 ROUTE (always),
|
|
149
|
+
* 2 LANES, 3 FIELD, 4 SCENERY, 5 TEXT. A track built from a JS object answers the same way. The
|
|
150
|
+
* binding compares this list with the layers a page lists.
|
|
151
|
+
*/
|
|
152
|
+
layers(): Uint8Array;
|
|
153
|
+
max_draw_bytes(): number;
|
|
154
|
+
max_field_draw_bytes(): number;
|
|
155
|
+
max_scenery_draw_bytes(): number;
|
|
156
|
+
max_text_draw_bytes(): number;
|
|
157
|
+
/**
|
|
158
|
+
* The near-clip margin (`NEAR_PLANE`, consts.rs) for the scenery vertex shader's `u_nearPlane`
|
|
159
|
+
* uniform — the shader's per-vertex `step(u_nearPlane, cz)` defense-in-depth twin of the
|
|
160
|
+
* authoritative per-corner cull `SceneryLayer::emit` already applies before emitting a card at all
|
|
161
|
+
* (a GLSL vertex invocation can't see its quad's sibling corners, so it can't reject "if ANY corner
|
|
162
|
+
* is unsafe" — only flag its OWN). Sent as a uniform, not a GLSL literal, for the same reason
|
|
163
|
+
* `camera_depth()` is (OQ4) — a `NEAR_PLANE` tune in Rust can't silently desync from the shader.
|
|
164
|
+
*/
|
|
165
|
+
near_plane(): number;
|
|
166
|
+
position(): number;
|
|
167
|
+
/**
|
|
168
|
+
* Jump the vehicle to `meters` along the track, clamped to `[0, track_length]` — the timeline-scrub
|
|
169
|
+
* seam. The ONE way the playhead moves (lib-route-camera removed the integrator): a pure position
|
|
170
|
+
* setter (CQS command). A NaN target is ignored: the playhead keeps its position.
|
|
171
|
+
*/
|
|
172
|
+
seek(meters: number): void;
|
|
173
|
+
/**
|
|
174
|
+
* Set the viewport aspect ratio (canvasW / canvasH). The binding calls this each frame from the live
|
|
175
|
+
* canvas size so the projection corrects ndc_x (aspect-ratio-correction RFC). Fail-soft on a
|
|
176
|
+
* degenerate value (non-finite / ≤ 0, e.g. a 0-height frame): keep the prior aspect rather than
|
|
177
|
+
* poison the projection with NaN/∞.
|
|
178
|
+
*/
|
|
179
|
+
set_aspect(aspect: number): void;
|
|
180
|
+
/**
|
|
181
|
+
* Set the camera's ride offsets — `x` metres along the road's right vector, `y` metres above the
|
|
182
|
+
* route's surface (decisions 25–27, lib-route-camera). The camera's heading stays the road's
|
|
183
|
+
* tangent; only the eye's seat moves. A scene seats the camera through the value block:
|
|
184
|
+
* `commit_value_block` reads slots 0–1 (lib-value-entry, decision 62) and calls this. This
|
|
185
|
+
* method stays for a page with no scene; the last write of either wins, and a host that writes
|
|
186
|
+
* neither gets the centreline camera. Fail-soft on a non-finite value (either one): keep the
|
|
187
|
+
* prior offsets — a NaN here would put a NaN in the eye and garble every later frame (the
|
|
188
|
+
* `set_aspect` contract).
|
|
189
|
+
*/
|
|
190
|
+
set_camera_offset(x: number, y: number): void;
|
|
191
|
+
/**
|
|
192
|
+
* The sky pass's horizontal parallax offset (`u_skyOffset`, sky-cloud.md Decision 5) — a pure
|
|
193
|
+
* function of the camera's YAW (heading), never the wall clock (Core Principle 13), so `cargo
|
|
194
|
+
* test` can pin it exactly like `horizon_ndc_y()`.
|
|
195
|
+
*
|
|
196
|
+
* `heading` is the track's absolute turn angle (θ, `track.rs`: `tangent_x = sin θ`, `κ > 0` = a
|
|
197
|
+
* right turn increases θ). A cloud "at infinity" in a FIXED world direction has true screen
|
|
198
|
+
* position `-CAMERA_DEPTH·tan(θ)/aspect` (the same `Camera::project` limit as any far point) — this
|
|
199
|
+
* uses the bounded first-order term `-sin(θ)` instead: identical SIGN (a right turn still yaws the
|
|
200
|
+
* cloud negative ⇒ left on screen, matching the shader's `p = v_uv - vec2(u_skyOffset, 0)`
|
|
201
|
+
* convention), no pole at θ = ±90°, and `sin`/`tan` agree to within 3% under 30° — comfortably
|
|
202
|
+
* inside the shipped route's heading swing (`lib_test.rs`'s `sky_parallax` mod pins it with a tripwire).
|
|
203
|
+
*/
|
|
204
|
+
sky_parallax(): number;
|
|
205
|
+
/**
|
|
206
|
+
* Per-label text draw ranges from the LAST `fill_text_*`: a flat `[start_vertex, count, r, g, b, a]`
|
|
207
|
+
* 6-tuple per emitted label (road-anchored, depth-tested; `r,g,b,a` = the label's `u_color` —
|
|
208
|
+
* road labels carry a = 1.0, a placed label's `alpha` arrives in its record, lib-world-objects
|
|
209
|
+
* Decision 2). The renderer sets `u_color` and draws `count` verts from `start_vertex`. **CACHED, not re-emitted** (the
|
|
210
|
+
* `field_draw_ranges` idiom — re-emitting would re-allocate a text-sized buffer every frame): valid only
|
|
211
|
+
* after THIS frame's `fill_text_*`, **empty before the first fill**. Per-frame order:
|
|
212
|
+
* `seek → fill_text_and_view → bufferSubData → text_draw_ranges → draw`.
|
|
213
|
+
* sets `u_color` and draws `count` verts from `start_vertex`. **CACHED, not re-emitted** (the
|
|
214
|
+
* `field_draw_ranges` idiom — re-emitting would re-allocate a text-sized buffer every frame): valid only
|
|
215
|
+
* after THIS frame's `fill_text_*`, **empty before the first fill**. Per-frame order:
|
|
216
|
+
* `seek → fill_text_and_view → bufferSubData → text_draw_ranges → draw`.
|
|
217
|
+
*
|
|
218
|
+
* A VIEW, like `field_draw_ranges`: valid until the next call into WebAssembly.
|
|
219
|
+
*/
|
|
220
|
+
text_draw_ranges(): Float32Array;
|
|
221
|
+
/**
|
|
222
|
+
* Total HORIZONTAL arc length of the loaded track (metres) — the upper bound of any field
|
|
223
|
+
* span's `end` (contract §3.1). Pure query (CQS): the table is built once at construction and
|
|
224
|
+
* is never empty (`from_parts`/`demo` guarantee ≥ 1 sample), so the index never underflows.
|
|
225
|
+
*/
|
|
226
|
+
track_length(): number;
|
|
227
|
+
/**
|
|
228
|
+
* A `Float32Array` view of the frame's STAGING block (lib-value-entry) — the JS entry's write
|
|
229
|
+
* side. JavaScript writes one frame of values into it (`value_block_len()` long, the layout of
|
|
230
|
+
* `values`), then calls `commit_value_block`. A pure query (`&self`): it changes nothing. The
|
|
231
|
+
* view aliases WebAssembly memory and dies when that memory grows, so JavaScript takes a new
|
|
232
|
+
* view each frame (the `fill_*_and_view` contract). The block was sized by `install_layers`, so
|
|
233
|
+
* the view allocates nothing in WebAssembly memory.
|
|
234
|
+
*/
|
|
235
|
+
value_view(): Float32Array;
|
|
236
|
+
/**
|
|
237
|
+
* The memory of the WebAssembly module that this engine lives in. JavaScript builds views over its
|
|
238
|
+
* `buffer` (`camera_ptr`); the `buffer` is replaced when the memory grows, and the views of the old one
|
|
239
|
+
* then have length 0. A method, not a free function, so a scene reads it from the engine it was
|
|
240
|
+
* given and imports no module.
|
|
241
|
+
*/
|
|
242
|
+
wasm_memory(): WebAssembly.Memory;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* The placed rows of a scene before the engine is built: the assets, the placed objects in the
|
|
247
|
+
* engine's record order, and the placed labels in theirs. Each method appends one row, so an index
|
|
248
|
+
* is the order of the calls. The arguments inside a call are positional.
|
|
249
|
+
*/
|
|
250
|
+
export class Rows {
|
|
251
|
+
free(): void;
|
|
252
|
+
[Symbol.dispose](): void;
|
|
253
|
+
/**
|
|
254
|
+
* One asset: the atlas cell at its block's top-left, and the block's span in cells. Its index
|
|
255
|
+
* is the order of the `asset` calls — what an `image` call names, and what the scene module
|
|
256
|
+
* holds for it.
|
|
257
|
+
*/
|
|
258
|
+
asset(cell: number, cols: number, rows: number): void;
|
|
259
|
+
/**
|
|
260
|
+
* One placed object, bound to the asset at index `asset`. Its record (9 values a frame) follows
|
|
261
|
+
* the order of the `image` calls.
|
|
262
|
+
*/
|
|
263
|
+
image(asset: number): void;
|
|
264
|
+
/**
|
|
265
|
+
* No rows.
|
|
266
|
+
*/
|
|
267
|
+
constructor();
|
|
268
|
+
/**
|
|
269
|
+
* One placed label with its text. Its record (9 values a frame) follows the order of the `text`
|
|
270
|
+
* calls.
|
|
271
|
+
*/
|
|
272
|
+
text(text: string): void;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Which side(s) of the road a field span covers, in driving direction. `#[wasm_bindgen]` exports
|
|
277
|
+
* it to TS as a NUMERIC enum (`Side.Left = 0`, `Right = 1`, `Both = 2`), so the JS config writes
|
|
278
|
+
* `side: wasm.Side.Both`. The decoder reads that number and maps it through `TryFrom<u8>` below, which
|
|
279
|
+
* rejects an out-of-range value at the boundary (contract §5: `side` has no domain-error row; its
|
|
280
|
+
* validity IS the type).
|
|
281
|
+
*/
|
|
282
|
+
export enum Side {
|
|
283
|
+
Left = 0,
|
|
284
|
+
Right = 1,
|
|
285
|
+
Both = 2,
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
289
|
+
|
|
290
|
+
export interface InitOutput {
|
|
291
|
+
readonly memory: WebAssembly.Memory;
|
|
292
|
+
readonly __wbg_engine_free: (a: number, b: number) => void;
|
|
293
|
+
readonly __wbg_rows_free: (a: number, b: number) => void;
|
|
294
|
+
readonly engine_aspect: (a: number) => number;
|
|
295
|
+
readonly engine_camera_depth: (a: number) => number;
|
|
296
|
+
readonly engine_camera_ptr: (a: number) => number;
|
|
297
|
+
readonly engine_commit_value_block: (a: number) => number;
|
|
298
|
+
readonly engine_dash_anchor: (a: number) => number;
|
|
299
|
+
readonly engine_depth_bounds: (a: number) => [number, number];
|
|
300
|
+
readonly engine_field_atlas_draw_ranges: (a: number) => any;
|
|
301
|
+
readonly engine_field_draw_ranges: (a: number) => any;
|
|
302
|
+
readonly engine_fill_and_view: (a: number) => any;
|
|
303
|
+
readonly engine_fill_camera: (a: number) => void;
|
|
304
|
+
readonly engine_fill_field_and_view: (a: number) => any;
|
|
305
|
+
readonly engine_fill_scenery_and_view: (a: number) => any;
|
|
306
|
+
readonly engine_fill_text_and_view: (a: number) => any;
|
|
307
|
+
readonly engine_first_asset_outside_grid: (a: number, b: number, c: number) => [number, number, number];
|
|
308
|
+
readonly engine_from_config_bytes: (a: number, b: number) => [number, number, number];
|
|
309
|
+
readonly engine_from_config_bytes_with_rows: (a: number, b: number, c: number) => [number, number, number];
|
|
310
|
+
readonly engine_horizon_ndc_y: (a: number) => number;
|
|
311
|
+
readonly engine_layers: (a: number) => [number, number];
|
|
312
|
+
readonly engine_max_draw_bytes: (a: number) => number;
|
|
313
|
+
readonly engine_max_field_draw_bytes: (a: number) => number;
|
|
314
|
+
readonly engine_max_scenery_draw_bytes: (a: number) => number;
|
|
315
|
+
readonly engine_max_text_draw_bytes: (a: number) => number;
|
|
316
|
+
readonly engine_near_plane: (a: number) => number;
|
|
317
|
+
readonly engine_position: (a: number) => number;
|
|
318
|
+
readonly engine_seek: (a: number, b: number) => void;
|
|
319
|
+
readonly engine_set_aspect: (a: number, b: number) => void;
|
|
320
|
+
readonly engine_set_camera_offset: (a: number, b: number, c: number) => void;
|
|
321
|
+
readonly engine_sky_parallax: (a: number) => number;
|
|
322
|
+
readonly engine_text_draw_ranges: (a: number) => any;
|
|
323
|
+
readonly engine_track_length: (a: number) => number;
|
|
324
|
+
readonly engine_value_view: (a: number) => any;
|
|
325
|
+
readonly engine_wasm_memory: (a: number) => any;
|
|
326
|
+
readonly rows_asset: (a: number, b: number, c: number, d: number) => void;
|
|
327
|
+
readonly rows_image: (a: number, b: number) => void;
|
|
328
|
+
readonly rows_new: () => number;
|
|
329
|
+
readonly rows_text: (a: number, b: number, c: number) => void;
|
|
330
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
331
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
332
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
333
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
334
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
335
|
+
readonly __wbindgen_start: () => void;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
342
|
+
* a precompiled `WebAssembly.Module`.
|
|
343
|
+
*
|
|
344
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
345
|
+
*
|
|
346
|
+
* @returns {InitOutput}
|
|
347
|
+
*/
|
|
348
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
352
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
353
|
+
*
|
|
354
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
355
|
+
*
|
|
356
|
+
* @returns {Promise<InitOutput>}
|
|
357
|
+
*/
|
|
358
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|