@i7r.tech/moveby 0.0.0-stage → 0.0.21-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 +8573 -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 +330 -0
- package/dist/engine/wasm_engine.js +733 -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 +1907 -0
- package/dist/passes/backdrop.d.ts +9 -0
- package/dist/passes/field.d.ts +30 -0
- package/dist/passes/index.d.ts +5 -0
- package/dist/passes/road.d.ts +21 -0
- package/dist/passes/scenery.d.ts +28 -0
- package/dist/passes/sky.d.ts +11 -0
- package/dist/passes/text.d.ts +26 -0
- package/dist/scene-module.d.ts +165 -0
- package/dist/scene.d.ts +59 -0
- package/dist/utils.d.ts +15 -0
- package/docs/attribution.md +31 -0
- package/docs/decisions.md +26 -0
- package/package.json +33 -4
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
/* @ts-self-types="./wasm_engine.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The SHAPE of a lane divider (engine-lanes.v1.1 §4, lane-divider-type.md). `#[wasm_bindgen]` exports it to
|
|
5
|
+
* TS as a NUMERIC enum (`DividerPattern.Dashed = 0`, `Solid = 1`, `Double = 2`), so the JS config writes
|
|
6
|
+
* `dividerPattern: wasm.DividerPattern.Double`. The decoder reads that number through `TryFrom<u8>` (rejects
|
|
7
|
+
* out-of-range at the boundary — its validity IS the type, the `Side` precedent, no domain-error row). COLOUR
|
|
8
|
+
* and dash lengths are SEPARATE `LaneSpan` axes, not folded into this enum (option B of OQ#3).
|
|
9
|
+
* @enum {0 | 1 | 2}
|
|
10
|
+
*/
|
|
11
|
+
export const DividerPattern = Object.freeze({
|
|
12
|
+
Dashed: 0, "0": "Dashed",
|
|
13
|
+
Solid: 1, "1": "Solid",
|
|
14
|
+
Double: 2, "2": "Double",
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export class Engine {
|
|
18
|
+
static __wrap(ptr) {
|
|
19
|
+
const obj = Object.create(Engine.prototype);
|
|
20
|
+
obj.__wbg_ptr = ptr;
|
|
21
|
+
EngineFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
22
|
+
return obj;
|
|
23
|
+
}
|
|
24
|
+
__destroy_into_raw() {
|
|
25
|
+
const ptr = this.__wbg_ptr;
|
|
26
|
+
this.__wbg_ptr = 0;
|
|
27
|
+
EngineFinalization.unregister(this);
|
|
28
|
+
return ptr;
|
|
29
|
+
}
|
|
30
|
+
free() {
|
|
31
|
+
const ptr = this.__destroy_into_raw();
|
|
32
|
+
wasm.__wbg_engine_free(ptr, 0);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The live viewport aspect (canvasW / canvasH), for the scenery vertex shader's `u_aspect` — the
|
|
36
|
+
* ONLY place project-in-shader lets aspect enter the scenery projection (never baked into
|
|
37
|
+
* `camera_basis`, so a stray second divide can't creep in). JS already knows this value locally (it
|
|
38
|
+
* computed it to call `set_aspect`); this getter exists so the scenery pass can read it back the
|
|
39
|
+
* same way every other per-frame uniform is read, off `&self`.
|
|
40
|
+
* @returns {number}
|
|
41
|
+
*/
|
|
42
|
+
aspect() {
|
|
43
|
+
const ret = wasm.engine_aspect(this.__wbg_ptr);
|
|
44
|
+
return ret;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The per-frame camera basis for the scenery vertex shader's projection: `[pos.x,y,z, forward.x,y,z]`
|
|
48
|
+
* (6 floats — NOT the 12 a naive `{pos,forward,right,up}` flattening would send). `right` and
|
|
49
|
+
* world-`up` are deliberately NOT included: `Camera::right()` DERIVES right from forward
|
|
50
|
+
* (`(forward.z, 0, −forward.x)`, camera.rs) rather than storing it, and `Camera::project`'s `cy` is
|
|
51
|
+
* just `ray.y` (world-up is the constant (0,1,0), never dotted). Sending only the minimal
|
|
52
|
+
* independent basis means the GLSL `project()` must derive `right` the same way — which is exactly
|
|
53
|
+
* what keeps it an auditable line-for-line mirror of `Camera::project` (camera.rs) rather than a
|
|
54
|
+
* second copy that could silently drift out of orthogonality.
|
|
55
|
+
* @returns {Float32Array}
|
|
56
|
+
*/
|
|
57
|
+
camera_basis() {
|
|
58
|
+
const ret = wasm.engine_camera_basis(this.__wbg_ptr);
|
|
59
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
60
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
61
|
+
return v1;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The focal length (`CAMERA_DEPTH`, consts.rs) for the scenery vertex shader's `u_cameraDepth`
|
|
65
|
+
* uniform — sent so a FOV change in Rust can't silently desync from a hardcoded GLSL literal (OQ4,
|
|
66
|
+
* project-in-shader.md; the same precedent `depth_bounds` already set for `u_scaleNear/Far`).
|
|
67
|
+
* @returns {number}
|
|
68
|
+
*/
|
|
69
|
+
camera_depth() {
|
|
70
|
+
const ret = wasm.engine_camera_depth(this.__wbg_ptr);
|
|
71
|
+
return ret;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The JS entry of the frame's value block (lib-value-entry): check the staging block that
|
|
75
|
+
* `value_view` handed out; on success copy it into the live block and seat the camera from its
|
|
76
|
+
* slots 0 and 1 (decision 62). ALL-OR-NOTHING, like `set_value_block`: a bad value changes
|
|
77
|
+
* nothing — the live block AND the camera — so the next draw never mixes two frames' values and
|
|
78
|
+
* never rides a seat no good frame named. Returns −1 on success, else the first bad value's
|
|
79
|
+
* index in the block. A number only: the binding names the fault (`SCENE_VALUE`); the engine
|
|
80
|
+
* sends no prose across the seam.
|
|
81
|
+
* @returns {number}
|
|
82
|
+
*/
|
|
83
|
+
commit_value_block() {
|
|
84
|
+
const ret = wasm.engine_commit_value_block(this.__wbg_ptr);
|
|
85
|
+
return ret;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Per-frame dash anchor for the road vertex shader's `u_dashAnchor` — the largest whole number of
|
|
89
|
+
* FULL dash periods at or below the PLAYER's road-SURFACE distance (not horizontal `position`: the
|
|
90
|
+
* dash ruler is `surface_length`, the slant distance, so a climbing road's stripes don't
|
|
91
|
+
* foreshorten). Thin wrapper on the existing free `dash_anchor` (layers/road.rs) — not re-derived.
|
|
92
|
+
* @returns {number}
|
|
93
|
+
*/
|
|
94
|
+
dash_anchor() {
|
|
95
|
+
const ret = wasm.engine_dash_anchor(this.__wbg_ptr);
|
|
96
|
+
return ret;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, SCALE_FAR]`.
|
|
100
|
+
* The renderer feeds these to the vertex shader's `u_scaleNear` / `u_scaleFar` uniforms so
|
|
101
|
+
* the GLSL depth map reads the SAME source as the Rust `depth_ndc` mirror — no GLSL↔Rust
|
|
102
|
+
* constant can drift (unlike the DASH_* duplication). Static (derived from camera consts),
|
|
103
|
+
* so the renderer reads this ONCE and caches it — no per-frame marshalling. See depth-test.md.
|
|
104
|
+
* @returns {Float32Array}
|
|
105
|
+
*/
|
|
106
|
+
depth_bounds() {
|
|
107
|
+
const ret = wasm.engine_depth_bounds(this.__wbg_ptr);
|
|
108
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
109
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
110
|
+
return v1;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* v1.1 (scenery-atlas-cells) — ATLAS-CELL field draw buckets from the last `fill_field_*`: a flat
|
|
114
|
+
* `[u0, v0, u1, v1, start_vertex, count]` per bucket (the sub-rect as a per-draw `u_cellRect` uniform +
|
|
115
|
+
* the vertex range). The renderer draws these with the fract-tile program on the SHARED atlas (NEAREST/
|
|
116
|
+
* no-mips). CACHED like `field_draw_ranges` — valid only after this frame's `fill_field_*`, empty before.
|
|
117
|
+
* @returns {Float32Array}
|
|
118
|
+
*/
|
|
119
|
+
field_atlas_draw_ranges() {
|
|
120
|
+
const ret = wasm.engine_field_atlas_draw_ranges(this.__wbg_ptr);
|
|
121
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
122
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
123
|
+
return v1;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Per-texture field draw buckets from the LAST `fill_field_*`: a flat `[texture_id, start_vertex,
|
|
127
|
+
* count, …]` triple per non-empty bucket, ascending by id (the renderer binds `registry[id]` then
|
|
128
|
+
* draws `count` verts from `start_vertex`, once per ground texture). **CACHED, not re-emitted** —
|
|
129
|
+
* a query whose validity depends on a prior `fill_field_*` (re-emitting would re-allocate a
|
|
130
|
+
* field-sized buffer every frame, the GC churn zero-copy kills): the CURRENT frame's buckets only
|
|
131
|
+
* after this frame's fill, **empty before the first fill**. Per-frame order:
|
|
132
|
+
* `seek → fill_field_and_view → bufferSubData → field_draw_ranges → bind+draw`.
|
|
133
|
+
* @returns {Uint32Array}
|
|
134
|
+
*/
|
|
135
|
+
field_draw_ranges() {
|
|
136
|
+
const ret = wasm.engine_field_draw_ranges(this.__wbg_ptr);
|
|
137
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
138
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
139
|
+
return v1;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* @returns {Float32Array}
|
|
143
|
+
*/
|
|
144
|
+
fill_and_view() {
|
|
145
|
+
const ret = wasm.engine_fill_and_view(this.__wbg_ptr);
|
|
146
|
+
return ret;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @returns {Float32Array}
|
|
150
|
+
*/
|
|
151
|
+
fill_field_and_view() {
|
|
152
|
+
const ret = wasm.engine_fill_field_and_view(this.__wbg_ptr);
|
|
153
|
+
return ret;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @returns {Float32Array}
|
|
157
|
+
*/
|
|
158
|
+
fill_scenery_and_view() {
|
|
159
|
+
const ret = wasm.engine_fill_scenery_and_view(this.__wbg_ptr);
|
|
160
|
+
return ret;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* @returns {Float32Array}
|
|
164
|
+
*/
|
|
165
|
+
fill_text_and_view() {
|
|
166
|
+
const ret = wasm.engine_fill_text_and_view(this.__wbg_ptr);
|
|
167
|
+
return ret;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The first asset of `rows` whose cell block does not fit the atlas grid of the track in
|
|
171
|
+
* `bytes`: its index among the rows' assets, or −1 when every one fits. A query: it builds
|
|
172
|
+
* nothing and consumes nothing. Construction refuses such an asset too (O12), with a code that
|
|
173
|
+
* names no asset; this lets the library name the record. `bytes` is a `Uint8Array`.
|
|
174
|
+
* @param {Uint8Array} bytes
|
|
175
|
+
* @param {Rows} rows
|
|
176
|
+
* @returns {number}
|
|
177
|
+
*/
|
|
178
|
+
static first_asset_outside_grid(bytes, rows) {
|
|
179
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
180
|
+
const len0 = WASM_VECTOR_LEN;
|
|
181
|
+
_assertClass(rows, Rows);
|
|
182
|
+
const ret = wasm.engine_first_asset_outside_grid(ptr0, len0, rows.__wbg_ptr);
|
|
183
|
+
if (ret[2]) {
|
|
184
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
185
|
+
}
|
|
186
|
+
return ret[0];
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Construction from the **X2 binary wire** (`config_wire`, engine-config-wire.md) — the byte twin of
|
|
190
|
+
* `new`'s JS-object path, coexisting with it (additive, non-breaking). Decodes the (possibly
|
|
191
|
+
* UNTRUSTED) blob into the SAME `EngineConfig` and runs the SAME `from_parts` — so the two
|
|
192
|
+
* constructors CONVERGE by construction: ONLY field EXTRACTION differs (a bounds-checked byte cursor
|
|
193
|
+
* vs `Reflect::get`); the O-table validation + sizing + build are shared verbatim. A byte fault
|
|
194
|
+
* crosses the seam as a short STABLE code (`WireError::code()`, e.g. `WIRE_TRUNCATED`) — never a
|
|
195
|
+
* panic, never an empty-as-success render (Core Principle 3 / PRINCIPLES §7). A fetched blob is
|
|
196
|
+
* untrusted (unlike the build-baked polyline), so this is adversarial hardening
|
|
197
|
+
* (feedback_build_time_input_not_untrusted). `bytes` is a `Uint8Array` at the JS seam.
|
|
198
|
+
* @param {Uint8Array} bytes
|
|
199
|
+
* @returns {Engine}
|
|
200
|
+
*/
|
|
201
|
+
static from_config_bytes(bytes) {
|
|
202
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
203
|
+
const len0 = WASM_VECTOR_LEN;
|
|
204
|
+
const ret = wasm.engine_from_config_bytes(ptr0, len0);
|
|
205
|
+
if (ret[2]) {
|
|
206
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
207
|
+
}
|
|
208
|
+
return Engine.__wrap(ret[0]);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Construction from the track bytes AND the scene's placed rows (scene-wasm-handoff, decision
|
|
212
|
+
* 76). `rows` holds what a scene module declares: its assets, its objects and its labels. The
|
|
213
|
+
* track holds the rest — the route, the atlas grid, the font. The engine consumes `rows`. The
|
|
214
|
+
* track must declare no placed rows of its own, and must hold each section a row needs (the
|
|
215
|
+
* atlas grid for an asset or an object, the font for a label): else `SCENE_TRACK`. Then the same
|
|
216
|
+
* rules apply as for `from_config_bytes` (O12, O13, T6). `bytes` is a `Uint8Array`.
|
|
217
|
+
* @param {Uint8Array} bytes
|
|
218
|
+
* @param {Rows} rows
|
|
219
|
+
* @returns {Engine}
|
|
220
|
+
*/
|
|
221
|
+
static from_config_bytes_with_rows(bytes, rows) {
|
|
222
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
223
|
+
const len0 = WASM_VECTOR_LEN;
|
|
224
|
+
_assertClass(rows, Rows);
|
|
225
|
+
var ptr1 = rows.__destroy_into_raw();
|
|
226
|
+
const ret = wasm.engine_from_config_bytes_with_rows(ptr0, len0, ptr1);
|
|
227
|
+
if (ret[2]) {
|
|
228
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
229
|
+
}
|
|
230
|
+
return Engine.__wrap(ret[0]);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* The screen height (ndc_y ∈ [-1, 1]) of the visible horizon: the HIGHEST point of the road
|
|
234
|
+
* ribbon (centre + both edges) over the visible window, projected. On a climb that is the far
|
|
235
|
+
* end; on a crest, the crest; on a descent, a near sample. The renderer fills the GROUND
|
|
236
|
+
* background up to this line and paints SKY above it — so the off-road region the field cannot
|
|
237
|
+
* reach (depth-capped, and folded on the inside of a bend) reads as ground, not as the sharp-bend
|
|
238
|
+
* sky slivers. Per-frame (depends on `position`) but cheap: ~3 projects per window sample, all
|
|
239
|
+
* flops, no allocation. Returns 0.0 when nothing is visible (player past the track end).
|
|
240
|
+
* @returns {number}
|
|
241
|
+
*/
|
|
242
|
+
horizon_ndc_y() {
|
|
243
|
+
const ret = wasm.engine_horizon_ndc_y(this.__wbg_ptr);
|
|
244
|
+
return ret;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* The layers this track declares, as the track file's section tags, ascending: 1 ROUTE (always),
|
|
248
|
+
* 2 LANES, 3 FIELD, 4 SCENERY, 5 TEXT. A track built from a JS object answers the same way. The
|
|
249
|
+
* binding compares this list with the layers a page lists.
|
|
250
|
+
* @returns {Uint8Array}
|
|
251
|
+
*/
|
|
252
|
+
layers() {
|
|
253
|
+
const ret = wasm.engine_layers(this.__wbg_ptr);
|
|
254
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
255
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
256
|
+
return v1;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* @returns {number}
|
|
260
|
+
*/
|
|
261
|
+
max_draw_bytes() {
|
|
262
|
+
const ret = wasm.engine_max_draw_bytes(this.__wbg_ptr);
|
|
263
|
+
return ret >>> 0;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* @returns {number}
|
|
267
|
+
*/
|
|
268
|
+
max_field_draw_bytes() {
|
|
269
|
+
const ret = wasm.engine_max_field_draw_bytes(this.__wbg_ptr);
|
|
270
|
+
return ret >>> 0;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* @returns {number}
|
|
274
|
+
*/
|
|
275
|
+
max_scenery_draw_bytes() {
|
|
276
|
+
const ret = wasm.engine_max_scenery_draw_bytes(this.__wbg_ptr);
|
|
277
|
+
return ret >>> 0;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* @returns {number}
|
|
281
|
+
*/
|
|
282
|
+
max_text_draw_bytes() {
|
|
283
|
+
const ret = wasm.engine_max_text_draw_bytes(this.__wbg_ptr);
|
|
284
|
+
return ret >>> 0;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* The near-clip margin (`NEAR_PLANE`, consts.rs) for the scenery vertex shader's `u_nearPlane`
|
|
288
|
+
* uniform — the shader's per-vertex `step(u_nearPlane, cz)` defense-in-depth twin of the
|
|
289
|
+
* authoritative per-corner cull `SceneryLayer::emit` already applies before emitting a card at all
|
|
290
|
+
* (a GLSL vertex invocation can't see its quad's sibling corners, so it can't reject "if ANY corner
|
|
291
|
+
* is unsafe" — only flag its OWN). Sent as a uniform, not a GLSL literal, for the same reason
|
|
292
|
+
* `camera_depth()` is (OQ4) — a `NEAR_PLANE` tune in Rust can't silently desync from the shader.
|
|
293
|
+
* @returns {number}
|
|
294
|
+
*/
|
|
295
|
+
near_plane() {
|
|
296
|
+
const ret = wasm.engine_near_plane(this.__wbg_ptr);
|
|
297
|
+
return ret;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* @returns {number}
|
|
301
|
+
*/
|
|
302
|
+
position() {
|
|
303
|
+
const ret = wasm.engine_position(this.__wbg_ptr);
|
|
304
|
+
return ret;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Jump the vehicle to `meters` along the track, clamped to `[0, track_length]` — the timeline-scrub
|
|
308
|
+
* seam. The ONE way the playhead moves (lib-route-camera removed the integrator): a pure position
|
|
309
|
+
* setter (CQS command). A NaN target is ignored: the playhead keeps its position.
|
|
310
|
+
* @param {number} meters
|
|
311
|
+
*/
|
|
312
|
+
seek(meters) {
|
|
313
|
+
wasm.engine_seek(this.__wbg_ptr, meters);
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Set the viewport aspect ratio (canvasW / canvasH). The binding calls this each frame from the live
|
|
317
|
+
* canvas size so the projection corrects ndc_x (aspect-ratio-correction RFC). Fail-soft on a
|
|
318
|
+
* degenerate value (non-finite / ≤ 0, e.g. a 0-height frame): keep the prior aspect rather than
|
|
319
|
+
* poison the projection with NaN/∞.
|
|
320
|
+
* @param {number} aspect
|
|
321
|
+
*/
|
|
322
|
+
set_aspect(aspect) {
|
|
323
|
+
wasm.engine_set_aspect(this.__wbg_ptr, aspect);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Set the camera's ride offsets — `x` metres along the road's right vector, `y` metres above the
|
|
327
|
+
* route's surface (decisions 25–27, lib-route-camera). The camera's heading stays the road's
|
|
328
|
+
* tangent; only the eye's seat moves. A scene seats the camera through the value block:
|
|
329
|
+
* `commit_value_block` reads slots 0–1 (lib-value-entry, decision 62) and calls this. This
|
|
330
|
+
* method stays for a page with no scene; the last write of either wins, and a host that writes
|
|
331
|
+
* neither gets the centreline camera. Fail-soft on a non-finite value (either one): keep the
|
|
332
|
+
* prior offsets — a NaN here would put a NaN in the eye and garble every later frame (the
|
|
333
|
+
* `set_aspect` contract).
|
|
334
|
+
* @param {number} x
|
|
335
|
+
* @param {number} y
|
|
336
|
+
*/
|
|
337
|
+
set_camera_offset(x, y) {
|
|
338
|
+
wasm.engine_set_camera_offset(this.__wbg_ptr, x, y);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* The sky pass's horizontal parallax offset (`u_skyOffset`, sky-cloud.md Decision 5) — a pure
|
|
342
|
+
* function of the camera's YAW (heading), never the wall clock (Core Principle 13), so `cargo
|
|
343
|
+
* test` can pin it exactly like `horizon_ndc_y()`.
|
|
344
|
+
*
|
|
345
|
+
* `heading` is the track's absolute turn angle (θ, `track.rs`: `tangent_x = sin θ`, `κ > 0` = a
|
|
346
|
+
* right turn increases θ). A cloud "at infinity" in a FIXED world direction has true screen
|
|
347
|
+
* position `-CAMERA_DEPTH·tan(θ)/aspect` (the same `Camera::project` limit as any far point) — this
|
|
348
|
+
* uses the bounded first-order term `-sin(θ)` instead: identical SIGN (a right turn still yaws the
|
|
349
|
+
* cloud negative ⇒ left on screen, matching the shader's `p = v_uv - vec2(u_skyOffset, 0)`
|
|
350
|
+
* convention), no pole at θ = ±90°, and `sin`/`tan` agree to within 3% under 30° — comfortably
|
|
351
|
+
* inside the shipped route's heading swing (`lib_test.rs`'s `sky_parallax` mod pins it with a tripwire).
|
|
352
|
+
* @returns {number}
|
|
353
|
+
*/
|
|
354
|
+
sky_parallax() {
|
|
355
|
+
const ret = wasm.engine_sky_parallax(this.__wbg_ptr);
|
|
356
|
+
return ret;
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Per-label text draw ranges from the LAST `fill_text_*`: a flat `[start_vertex, count, r, g, b, a]`
|
|
360
|
+
* 6-tuple per emitted label (road-anchored, depth-tested; `r,g,b,a` = the label's `u_color` —
|
|
361
|
+
* road labels carry a = 1.0, a placed label's `alpha` arrives in its record, lib-world-objects
|
|
362
|
+
* Decision 2). The renderer sets `u_color` and draws `count` verts from `start_vertex`. **CACHED, not re-emitted** (the
|
|
363
|
+
* `field_draw_ranges` idiom — re-emitting would re-allocate a text-sized buffer every frame): valid only
|
|
364
|
+
* after THIS frame's `fill_text_*`, **empty before the first fill**. Per-frame order:
|
|
365
|
+
* `seek → fill_text_and_view → bufferSubData → text_draw_ranges → draw`.
|
|
366
|
+
* sets `u_color` and draws `count` verts from `start_vertex`. **CACHED, not re-emitted** (the
|
|
367
|
+
* `field_draw_ranges` idiom — re-emitting would re-allocate a text-sized buffer every frame): valid only
|
|
368
|
+
* after THIS frame's `fill_text_*`, **empty before the first fill**. Per-frame order:
|
|
369
|
+
* `seek → fill_text_and_view → bufferSubData → text_draw_ranges → draw`.
|
|
370
|
+
* @returns {Float32Array}
|
|
371
|
+
*/
|
|
372
|
+
text_draw_ranges() {
|
|
373
|
+
const ret = wasm.engine_text_draw_ranges(this.__wbg_ptr);
|
|
374
|
+
var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
|
|
375
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
376
|
+
return v1;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* Total HORIZONTAL arc length of the loaded track (metres) — the upper bound of any field
|
|
380
|
+
* span's `end` (contract §3.1). Pure query (CQS): the table is built once at construction and
|
|
381
|
+
* is never empty (`from_parts`/`demo` guarantee ≥ 1 sample), so the index never underflows.
|
|
382
|
+
* @returns {number}
|
|
383
|
+
*/
|
|
384
|
+
track_length() {
|
|
385
|
+
const ret = wasm.engine_track_length(this.__wbg_ptr);
|
|
386
|
+
return ret;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* A `Float32Array` view of the frame's STAGING block (lib-value-entry) — the JS entry's write
|
|
390
|
+
* side. JavaScript writes one frame of values into it (`value_block_len()` long, the layout of
|
|
391
|
+
* `values`), then calls `commit_value_block`. A pure query (`&self`): it changes nothing. The
|
|
392
|
+
* view aliases WebAssembly memory and dies when that memory grows, so JavaScript takes a new
|
|
393
|
+
* view each frame (the `fill_*_and_view` contract). The block was sized by `install_layers`, so
|
|
394
|
+
* the view allocates nothing in WebAssembly memory.
|
|
395
|
+
* @returns {Float32Array}
|
|
396
|
+
*/
|
|
397
|
+
value_view() {
|
|
398
|
+
const ret = wasm.engine_value_view(this.__wbg_ptr);
|
|
399
|
+
return ret;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (Symbol.dispose) Engine.prototype[Symbol.dispose] = Engine.prototype.free;
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* The placed rows of a scene before the engine is built: the assets, the placed objects in the
|
|
406
|
+
* engine's record order, and the placed labels in theirs. Each method appends one row, so an index
|
|
407
|
+
* is the order of the calls. The arguments inside a call are positional.
|
|
408
|
+
*/
|
|
409
|
+
export class Rows {
|
|
410
|
+
__destroy_into_raw() {
|
|
411
|
+
const ptr = this.__wbg_ptr;
|
|
412
|
+
this.__wbg_ptr = 0;
|
|
413
|
+
RowsFinalization.unregister(this);
|
|
414
|
+
return ptr;
|
|
415
|
+
}
|
|
416
|
+
free() {
|
|
417
|
+
const ptr = this.__destroy_into_raw();
|
|
418
|
+
wasm.__wbg_rows_free(ptr, 0);
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* One asset: the atlas cell at its block's top-left, and the block's span in cells. Its index
|
|
422
|
+
* is the order of the `asset` calls — what an `image` call names, and what the scene module
|
|
423
|
+
* holds for it.
|
|
424
|
+
* @param {number} cell
|
|
425
|
+
* @param {number} cols
|
|
426
|
+
* @param {number} rows
|
|
427
|
+
*/
|
|
428
|
+
asset(cell, cols, rows) {
|
|
429
|
+
wasm.rows_asset(this.__wbg_ptr, cell, cols, rows);
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* One placed object, bound to the asset at index `asset`. Its record (9 values a frame) follows
|
|
433
|
+
* the order of the `image` calls.
|
|
434
|
+
* @param {number} asset
|
|
435
|
+
*/
|
|
436
|
+
image(asset) {
|
|
437
|
+
wasm.rows_image(this.__wbg_ptr, asset);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* No rows.
|
|
441
|
+
*/
|
|
442
|
+
constructor() {
|
|
443
|
+
const ret = wasm.rows_new();
|
|
444
|
+
this.__wbg_ptr = ret;
|
|
445
|
+
RowsFinalization.register(this, this.__wbg_ptr, this);
|
|
446
|
+
return this;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* One placed label with its text. Its record (9 values a frame) follows the order of the `text`
|
|
450
|
+
* calls.
|
|
451
|
+
* @param {string} text
|
|
452
|
+
*/
|
|
453
|
+
text(text) {
|
|
454
|
+
const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
455
|
+
const len0 = WASM_VECTOR_LEN;
|
|
456
|
+
wasm.rows_text(this.__wbg_ptr, ptr0, len0);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
if (Symbol.dispose) Rows.prototype[Symbol.dispose] = Rows.prototype.free;
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Which side(s) of the road a field span covers, in driving direction. `#[wasm_bindgen]` exports
|
|
463
|
+
* it to TS as a NUMERIC enum (`Side.Left = 0`, `Right = 1`, `Both = 2`), so the JS config writes
|
|
464
|
+
* `side: wasm.Side.Both`. The decoder reads that number and maps it through `TryFrom<u8>` below, which
|
|
465
|
+
* rejects an out-of-range value at the boundary (contract §5: `side` has no domain-error row; its
|
|
466
|
+
* validity IS the type).
|
|
467
|
+
* @enum {0 | 1 | 2}
|
|
468
|
+
*/
|
|
469
|
+
export const Side = Object.freeze({
|
|
470
|
+
Left: 0, "0": "Left",
|
|
471
|
+
Right: 1, "1": "Right",
|
|
472
|
+
Both: 2, "2": "Both",
|
|
473
|
+
});
|
|
474
|
+
function __wbg_get_imports() {
|
|
475
|
+
const import0 = {
|
|
476
|
+
__proto__: null,
|
|
477
|
+
__wbg_Error_fdd633d4bb5dd76a: function(arg0, arg1) {
|
|
478
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
479
|
+
return ret;
|
|
480
|
+
},
|
|
481
|
+
__wbg___wbindgen_throw_ea4887a5f8f9a9db: function(arg0, arg1) {
|
|
482
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
483
|
+
},
|
|
484
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
485
|
+
// Cast intrinsic for `Ref(Slice(F32)) -> NamedExternref("Float32Array")`.
|
|
486
|
+
const ret = getArrayF32FromWasm0(arg0, arg1);
|
|
487
|
+
return ret;
|
|
488
|
+
},
|
|
489
|
+
__wbindgen_init_externref_table: function() {
|
|
490
|
+
const table = wasm.__wbindgen_externrefs;
|
|
491
|
+
const offset = table.grow(4);
|
|
492
|
+
table.set(0, undefined);
|
|
493
|
+
table.set(offset + 0, undefined);
|
|
494
|
+
table.set(offset + 1, null);
|
|
495
|
+
table.set(offset + 2, true);
|
|
496
|
+
table.set(offset + 3, false);
|
|
497
|
+
},
|
|
498
|
+
};
|
|
499
|
+
return {
|
|
500
|
+
__proto__: null,
|
|
501
|
+
"./wasm_engine_bg.js": import0,
|
|
502
|
+
};
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const EngineFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
506
|
+
? { register: () => {}, unregister: () => {} }
|
|
507
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_engine_free(ptr, 1));
|
|
508
|
+
const RowsFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
509
|
+
? { register: () => {}, unregister: () => {} }
|
|
510
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_rows_free(ptr, 1));
|
|
511
|
+
|
|
512
|
+
function _assertClass(instance, klass) {
|
|
513
|
+
if (!(instance instanceof klass)) {
|
|
514
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
function getArrayF32FromWasm0(ptr, len) {
|
|
519
|
+
ptr = ptr >>> 0;
|
|
520
|
+
return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
524
|
+
ptr = ptr >>> 0;
|
|
525
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
529
|
+
ptr = ptr >>> 0;
|
|
530
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
let cachedFloat32ArrayMemory0 = null;
|
|
534
|
+
function getFloat32ArrayMemory0() {
|
|
535
|
+
if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
|
|
536
|
+
cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
|
|
537
|
+
}
|
|
538
|
+
return cachedFloat32ArrayMemory0;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function getStringFromWasm0(ptr, len) {
|
|
542
|
+
return decodeText(ptr >>> 0, len);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
let cachedUint32ArrayMemory0 = null;
|
|
546
|
+
function getUint32ArrayMemory0() {
|
|
547
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
548
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
549
|
+
}
|
|
550
|
+
return cachedUint32ArrayMemory0;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
let cachedUint8ArrayMemory0 = null;
|
|
554
|
+
function getUint8ArrayMemory0() {
|
|
555
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
556
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
557
|
+
}
|
|
558
|
+
return cachedUint8ArrayMemory0;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
562
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
563
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
564
|
+
WASM_VECTOR_LEN = arg.length;
|
|
565
|
+
return ptr;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
569
|
+
if (realloc === undefined) {
|
|
570
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
571
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
572
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
573
|
+
WASM_VECTOR_LEN = buf.length;
|
|
574
|
+
return ptr;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
let len = arg.length;
|
|
578
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
579
|
+
|
|
580
|
+
const mem = getUint8ArrayMemory0();
|
|
581
|
+
|
|
582
|
+
let offset = 0;
|
|
583
|
+
|
|
584
|
+
for (; offset < len; offset++) {
|
|
585
|
+
const code = arg.charCodeAt(offset);
|
|
586
|
+
if (code > 0x7F) break;
|
|
587
|
+
mem[ptr + offset] = code;
|
|
588
|
+
}
|
|
589
|
+
if (offset !== len) {
|
|
590
|
+
if (offset !== 0) {
|
|
591
|
+
arg = arg.slice(offset);
|
|
592
|
+
}
|
|
593
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
594
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
595
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
596
|
+
|
|
597
|
+
offset += ret.written;
|
|
598
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
WASM_VECTOR_LEN = offset;
|
|
602
|
+
return ptr;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function takeFromExternrefTable0(idx) {
|
|
606
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
607
|
+
wasm.__externref_table_dealloc(idx);
|
|
608
|
+
return value;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
612
|
+
cachedTextDecoder.decode();
|
|
613
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
614
|
+
let numBytesDecoded = 0;
|
|
615
|
+
function decodeText(ptr, len) {
|
|
616
|
+
numBytesDecoded += len;
|
|
617
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
618
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
619
|
+
cachedTextDecoder.decode();
|
|
620
|
+
numBytesDecoded = len;
|
|
621
|
+
}
|
|
622
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
const cachedTextEncoder = new TextEncoder();
|
|
626
|
+
|
|
627
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
628
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
629
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
630
|
+
view.set(buf);
|
|
631
|
+
return {
|
|
632
|
+
read: arg.length,
|
|
633
|
+
written: buf.length
|
|
634
|
+
};
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
let WASM_VECTOR_LEN = 0;
|
|
639
|
+
|
|
640
|
+
let wasmModule, wasmInstance, wasm;
|
|
641
|
+
function __wbg_finalize_init(instance, module) {
|
|
642
|
+
wasmInstance = instance;
|
|
643
|
+
wasm = instance.exports;
|
|
644
|
+
wasmModule = module;
|
|
645
|
+
cachedFloat32ArrayMemory0 = null;
|
|
646
|
+
cachedUint32ArrayMemory0 = null;
|
|
647
|
+
cachedUint8ArrayMemory0 = null;
|
|
648
|
+
wasm.__wbindgen_start();
|
|
649
|
+
return wasm;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
async function __wbg_load(module, imports) {
|
|
653
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
654
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
655
|
+
try {
|
|
656
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
657
|
+
} catch (e) {
|
|
658
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
659
|
+
|
|
660
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
661
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
662
|
+
|
|
663
|
+
} else { throw e; }
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
const bytes = await module.arrayBuffer();
|
|
668
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
669
|
+
} else {
|
|
670
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
671
|
+
|
|
672
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
673
|
+
return { instance, module };
|
|
674
|
+
} else {
|
|
675
|
+
return instance;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
|
|
679
|
+
function expectedResponseType(type) {
|
|
680
|
+
switch (type) {
|
|
681
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
682
|
+
}
|
|
683
|
+
return false;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
function initSync(module) {
|
|
688
|
+
if (wasm !== undefined) return wasm;
|
|
689
|
+
|
|
690
|
+
|
|
691
|
+
if (module !== undefined) {
|
|
692
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
693
|
+
({module} = module)
|
|
694
|
+
} else {
|
|
695
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const imports = __wbg_get_imports();
|
|
700
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
701
|
+
module = new WebAssembly.Module(module);
|
|
702
|
+
}
|
|
703
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
704
|
+
return __wbg_finalize_init(instance, module);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
async function __wbg_init(module_or_path) {
|
|
708
|
+
if (wasm !== undefined) return wasm;
|
|
709
|
+
|
|
710
|
+
|
|
711
|
+
if (module_or_path !== undefined) {
|
|
712
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
713
|
+
({module_or_path} = module_or_path)
|
|
714
|
+
} else {
|
|
715
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
if (module_or_path === undefined) {
|
|
720
|
+
module_or_path = new URL('wasm_engine_bg.wasm', import.meta.url);
|
|
721
|
+
}
|
|
722
|
+
const imports = __wbg_get_imports();
|
|
723
|
+
|
|
724
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
725
|
+
module_or_path = fetch(module_or_path);
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
729
|
+
|
|
730
|
+
return __wbg_finalize_init(instance, module);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
export { initSync, __wbg_init as default };
|