@i7r.tech/moveby 0.21.2-ywc → 0.21.3-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/README.md CHANGED
@@ -46,6 +46,20 @@ The layer list is the page's choice; the library draws the layers in its own ord
46
46
  list against the track. `scene.draw({ … })` runs one frame of the scene module, then the passes.
47
47
  Types are included: `track.d.ts` (written by `moveby build`) types the scene's own inputs.
48
48
 
49
+ ## How far the road draws
50
+
51
+ The engine draws the road, the ground and the objects up to a view distance ahead of the camera.
52
+ The default is 200 metres. Three sources give it, and the first one that sets it wins:
53
+
54
+ 1. the page: `loadTrack(trackBytes, sceneBytes, { viewDistance: 250 })`
55
+ 2. the road file: `"viewDistance": 250` in `road.json` (it rides the track file)
56
+ 3. the library's default, 200
57
+
58
+ A value that is not a number above 0 rejects the load with `VIEW_DISTANCE`, and nothing is built.
59
+ The stores are sized from the view distance, so a large value on a dense track can outgrow one
60
+ draw: the load succeeds, and the first `createScene` throws `ROAD_CAPACITY` (or `FIELD_CAPACITY`).
61
+ Lower the view distance, or make the track sparser.
62
+
49
63
  ## An atlas is a URL or an image
50
64
 
51
65
  `scenery`, `text` and `field` take an atlas. An image (`TexImageSource`) uploads at once. A URL
package/bin/moveby.js CHANGED
@@ -7240,7 +7240,8 @@ var CORE_ERRORS = {
7240
7240
  WIRE_ROUTE: "The track file has no route section. Build the file again.",
7241
7241
  WIRE_UNSUPPORTED: "The track file cannot carry a field span with a texture ground. Use an atlas cell for the span.",
7242
7242
  WIRE_ANIM: "The track file holds animation. Animation moved to the scene module. Build the file again without it.",
7243
- WIRE_GLYPH_METRIC: "A glyph of the font does not fit the track file: the atlas sides are powers of two, and each glyph rectangle is whole pixels."
7243
+ WIRE_GLYPH_METRIC: "A glyph of the font does not fit the track file: the atlas sides are powers of two, and each glyph rectangle is whole pixels.",
7244
+ VIEW_DISTANCE: "The view distance must be a number above 0, in metres. Nothing was built."
7244
7245
  };
7245
7246
 
7246
7247
  // ../moveby-build/src/atlas.ts
@@ -7467,7 +7468,7 @@ function gridNumbers(grid) {
7467
7468
  }
7468
7469
  function encodeTrack(road, parts) {
7469
7470
  const fields = parts.fields ?? { cols: 0, rows: 0, pxWidth: 0, pxHeight: 0 };
7470
- return encode_track_bytes(road.route, road.laneRecords, road.fieldRecords, fields.cols, fields.rows, fields.pxWidth, fields.pxHeight, gridNumbers(parts.sprites), parts.font ?? new Float32Array);
7471
+ return encode_track_bytes(road.route, road.laneRecords, road.fieldRecords, fields.cols, fields.rows, fields.pxWidth, fields.pxHeight, gridNumbers(parts.sprites), parts.font ?? new Float32Array, road.viewDistance);
7471
7472
  }
7472
7473
 
7473
7474
  // ../moveby-build/src/png.ts
@@ -7794,6 +7795,11 @@ var road_schema_default = {
7794
7795
  properties: {
7795
7796
  $schema: { type: "string" },
7796
7797
  version: { type: "integer", const: 1 },
7798
+ viewDistance: {
7799
+ description: "How far ahead the road draws, in metres. The default is 200. A page can change it per load with loadTrack's viewDistance.",
7800
+ type: "number",
7801
+ exclusiveMinimum: 0
7802
+ },
7797
7803
  route: { $ref: "#/$defs/route" },
7798
7804
  lanes: { $ref: "#/$defs/lanes" },
7799
7805
  fields: { $ref: "#/$defs/fields" }
@@ -7941,7 +7947,13 @@ function readRoad(json) {
7941
7947
  const [route, length] = packRoute(doc);
7942
7948
  checkChangeLists(doc, length);
7943
7949
  checkTiles(doc);
7944
- return { route, length, laneRecords: laneRecords(doc), fieldRecords: fieldRecords(doc) };
7950
+ return {
7951
+ route,
7952
+ length,
7953
+ laneRecords: laneRecords(doc),
7954
+ fieldRecords: fieldRecords(doc),
7955
+ viewDistance: doc.viewDistance
7956
+ };
7945
7957
  }
7946
7958
  function laneRecords(doc) {
7947
7959
  const entries = doc.lanes ?? [];
@@ -14,9 +14,10 @@
14
14
  * @param {number} px_height
15
15
  * @param {Uint32Array} sprite_grid
16
16
  * @param {Float32Array} font
17
+ * @param {number | null} [view_distance]
17
18
  * @returns {Uint8Array}
18
19
  */
19
- function encode_track_bytes(route, lane_records, field_records, cols, rows, px_width, px_height, sprite_grid, font) {
20
+ function encode_track_bytes(route, lane_records, field_records, cols, rows, px_width, px_height, sprite_grid, font, view_distance) {
20
21
  const ptr0 = passArray32ToWasm0(route, wasm.__wbindgen_malloc);
21
22
  const len0 = WASM_VECTOR_LEN;
22
23
  const ptr1 = passArrayF32ToWasm0(lane_records, wasm.__wbindgen_malloc);
@@ -27,7 +28,7 @@ function encode_track_bytes(route, lane_records, field_records, cols, rows, px_w
27
28
  const len3 = WASM_VECTOR_LEN;
28
29
  const ptr4 = passArrayF32ToWasm0(font, wasm.__wbindgen_malloc);
29
30
  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
+ const ret = wasm.encode_track_bytes(ptr0, len0, ptr1, len1, ptr2, len2, cols, rows, px_width, px_height, ptr3, len3, ptr4, len4, isLikeNone(view_distance) ? Number.MAX_SAFE_INTEGER : Math.fround(view_distance));
31
32
  if (ret[3]) {
32
33
  throw takeFromExternrefTable0(ret[2]);
33
34
  }
@@ -95,6 +96,10 @@ function getUint8ArrayMemory0() {
95
96
  return cachedUint8ArrayMemory0;
96
97
  }
97
98
 
99
+ function isLikeNone(x) {
100
+ return x === undefined || x === null;
101
+ }
102
+
98
103
  function passArray32ToWasm0(arg, malloc) {
99
104
  const ptr = malloc(arg.length * 4, 4) >>> 0;
100
105
  getUint32ArrayMemory0().set(arg, ptr / 4);
Binary file
@@ -56,11 +56,13 @@ export class Engine {
56
56
  */
57
57
  dash_anchor(): number;
58
58
  /**
59
- * The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, SCALE_FAR]`.
59
+ * The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, the far scale]`.
60
60
  * The renderer feeds these to the vertex shader's `u_scaleNear` / `u_scaleFar` uniforms so
61
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.
62
+ * constant can drift (unlike the DASH_* duplication). The far scale derives from this
63
+ * engine's own view distance (`ViewDistance::scale_far`), set at construction — so the pair
64
+ * is static for one engine and the renderer reads this ONCE and caches it — no per-frame
65
+ * marshalling. See depth-test.md.
64
66
  */
65
67
  depth_bounds(): Float32Array;
66
68
  /**
@@ -132,8 +134,10 @@ export class Engine {
132
134
  * track must declare no placed rows of its own, and must hold each section a row needs (the
133
135
  * atlas grid for an asset or an object, the font for a label): else `SCENE_TRACK`. Then the same
134
136
  * rules apply as for `from_config_bytes` (O12, O13, T6). `bytes` is a `Uint8Array`.
137
+ * `view_distance` is the page's override (view-distance.md): `Some(metres)` replaces what the
138
+ * track carries; `None` leaves the track's own value, or the default when the track names none.
135
139
  */
136
- static from_config_bytes_with_rows(bytes: Uint8Array, rows: Rows): Engine;
140
+ static from_config_bytes_with_rows(bytes: Uint8Array, rows: Rows, view_distance?: number | null): Engine;
137
141
  /**
138
142
  * The screen height (ndc_y ∈ [-1, 1]) of the visible horizon: the HIGHEST point of the road
139
143
  * ribbon (centre + both edges) over the visible window, projected. On a climb that is the far
@@ -306,7 +310,7 @@ export interface InitOutput {
306
310
  readonly engine_fill_text_and_view: (a: number) => any;
307
311
  readonly engine_first_asset_outside_grid: (a: number, b: number, c: number) => [number, number, number];
308
312
  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];
313
+ readonly engine_from_config_bytes_with_rows: (a: number, b: number, c: number, d: number) => [number, number, number];
310
314
  readonly engine_horizon_ndc_y: (a: number) => number;
311
315
  readonly engine_layers: (a: number) => [number, number];
312
316
  readonly engine_max_draw_bytes: (a: number) => number;
@@ -89,11 +89,13 @@ export class Engine {
89
89
  return ret;
90
90
  }
91
91
  /**
92
- * The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, SCALE_FAR]`.
92
+ * The two perspective-scale bounds the depth map brackets: `[SCALE_NEAR, the far scale]`.
93
93
  * The renderer feeds these to the vertex shader's `u_scaleNear` / `u_scaleFar` uniforms so
94
94
  * the GLSL depth map reads the SAME source as the Rust `depth_ndc` mirror — no GLSL↔Rust
95
- * constant can drift (unlike the DASH_* duplication). Static (derived from camera consts),
96
- * so the renderer reads this ONCE and caches it — no per-frame marshalling. See depth-test.md.
95
+ * constant can drift (unlike the DASH_* duplication). The far scale derives from this
96
+ * engine's own view distance (`ViewDistance::scale_far`), set at construction — so the pair
97
+ * is static for one engine and the renderer reads this ONCE and caches it — no per-frame
98
+ * marshalling. See depth-test.md.
97
99
  * @returns {Float32Array}
98
100
  */
99
101
  depth_bounds() {
@@ -227,16 +229,19 @@ export class Engine {
227
229
  * track must declare no placed rows of its own, and must hold each section a row needs (the
228
230
  * atlas grid for an asset or an object, the font for a label): else `SCENE_TRACK`. Then the same
229
231
  * rules apply as for `from_config_bytes` (O12, O13, T6). `bytes` is a `Uint8Array`.
232
+ * `view_distance` is the page's override (view-distance.md): `Some(metres)` replaces what the
233
+ * track carries; `None` leaves the track's own value, or the default when the track names none.
230
234
  * @param {Uint8Array} bytes
231
235
  * @param {Rows} rows
236
+ * @param {number | null} [view_distance]
232
237
  * @returns {Engine}
233
238
  */
234
- static from_config_bytes_with_rows(bytes, rows) {
239
+ static from_config_bytes_with_rows(bytes, rows, view_distance) {
235
240
  const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
236
241
  const len0 = WASM_VECTOR_LEN;
237
242
  _assertClass(rows, Rows);
238
243
  var ptr1 = rows.__destroy_into_raw();
239
- const ret = wasm.engine_from_config_bytes_with_rows(ptr0, len0, ptr1);
244
+ const ret = wasm.engine_from_config_bytes_with_rows(ptr0, len0, ptr1, isLikeNone(view_distance) ? Number.MAX_SAFE_INTEGER : Math.fround(view_distance));
240
245
  if (ret[2]) {
241
246
  throw takeFromExternrefTable0(ret[1]);
242
247
  }
@@ -591,6 +596,10 @@ function getUint8ArrayMemory0() {
591
596
  return cachedUint8ArrayMemory0;
592
597
  }
593
598
 
599
+ function isLikeNone(x) {
600
+ return x === undefined || x === null;
601
+ }
602
+
594
603
  function passArray8ToWasm0(arg, malloc) {
595
604
  const ptr = malloc(arg.length * 1, 1) >>> 0;
596
605
  getUint8ArrayMemory0().set(arg, ptr / 1);
Binary file
package/dist/errors.d.ts CHANGED
@@ -13,4 +13,5 @@ export declare const CORE_ERRORS: {
13
13
  readonly WIRE_UNSUPPORTED: "The track file cannot carry a field span with a texture ground. Use an atlas cell for the span.";
14
14
  readonly WIRE_ANIM: "The track file holds animation. Animation moved to the scene module. Build the file again without it.";
15
15
  readonly WIRE_GLYPH_METRIC: "A glyph of the font does not fit the track file: the atlas sides are powers of two, and each glyph rectangle is whole pixels.";
16
+ readonly VIEW_DISTANCE: "The view distance must be a number above 0, in metres. Nothing was built.";
16
17
  };
package/dist/index.js CHANGED
@@ -25,7 +25,8 @@ var CORE_ERRORS = {
25
25
  WIRE_ROUTE: "The track file has no route section. Build the file again.",
26
26
  WIRE_UNSUPPORTED: "The track file cannot carry a field span with a texture ground. Use an atlas cell for the span.",
27
27
  WIRE_ANIM: "The track file holds animation. Animation moved to the scene module. Build the file again without it.",
28
- WIRE_GLYPH_METRIC: "A glyph of the font does not fit the track file: the atlas sides are powers of two, and each glyph rectangle is whole pixels."
28
+ WIRE_GLYPH_METRIC: "A glyph of the font does not fit the track file: the atlas sides are powers of two, and each glyph rectangle is whole pixels.",
29
+ VIEW_DISTANCE: "The view distance must be a number above 0, in metres. Nothing was built."
29
30
  };
30
31
 
31
32
  // ../engine-binding/src/shaders/backdrop.vert.glsl
@@ -1818,7 +1819,7 @@ async function loadTrack(trackBytes, sceneBytes, inputs = {}) {
1818
1819
  const record = records[outside];
1819
1820
  throw sceneError("SCENE_ASSET", `${record.name}: cell ${record.cell} with a block of ${record.cols} × ${record.rows} is outside the track's atlas`);
1820
1821
  }
1821
- const engine = Engine.from_config_bytes_with_rows(trackBytes, rows);
1822
+ const engine = Engine.from_config_bytes_with_rows(trackBytes, rows, inputs.viewDistance);
1822
1823
  const out = new Float32Array(scene.$memory.buffer, table.outOffset, table.leaves.length);
1823
1824
  return new Track(engine, scene, table, plan, records, out);
1824
1825
  }
@@ -110,6 +110,12 @@ export interface LoadInputs<Using extends object = object> {
110
110
  readonly assets?: readonly Asset[];
111
111
  /** Every using input outside `moveby.asset`, by path: `{ lamp: { start: 3 } }` for `lamp.start`. */
112
112
  readonly using?: Using;
113
+ /**
114
+ * How far ahead the road draws, in metres (view-distance.md). The page's value wins over the
115
+ * track's own (`viewDistance` in `road.json`); when neither sets one, the library draws to 200.
116
+ * A value that is not a number above 0 rejects the load with `VIEW_DISTANCE`, and nothing is built.
117
+ */
118
+ readonly viewDistance?: number;
113
119
  }
114
120
  /**
115
121
  * A track with its scene module: what `loadTrack` gives a page. The engine draws the track; the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i7r.tech/moveby",
3
- "version": "0.21.2-ywc",
3
+ "version": "0.21.3-ywc",
4
4
  "description": "A 3D road renderer: a Rust engine compiled to WebAssembly, raw WebGL passes, and a small scene language",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",