@bendyline/molen-ambient 0.0.12 → 0.0.13
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/dist/client.d.mts +8 -4
- package/dist/client.mjs +569 -139
- package/dist/{components-vzvNQczG.mjs → components-DJINUkXK.mjs} +192 -52
- package/dist/kernel.d.mts +66 -5
- package/dist/kernel.mjs +283 -71
- package/dist/{wildlife-B4EL0z-N.d.mts → wildlife-CvHzzI9m.d.mts} +1 -1
- package/package.json +7 -7
|
@@ -31,7 +31,7 @@ const KIND_SPEED = {
|
|
|
31
31
|
function classifyFeature(feature) {
|
|
32
32
|
const cls = feature.class.toLowerCase();
|
|
33
33
|
const sub = (feature.subclass ?? "").toLowerCase();
|
|
34
|
-
if (cls
|
|
34
|
+
if (/^(aeroway|runway|taxiway|taxilane|parking_position)$/.test(cls) || /^(runway|taxiway|taxilane|apron|parking_position)$/.test(sub)) return sub === "runway" || cls === "runway" ? "runway" : void 0;
|
|
35
35
|
if (cls === "ferry" || sub === "ferry") return {
|
|
36
36
|
class: "water",
|
|
37
37
|
kind: "ferry"
|
|
@@ -175,16 +175,38 @@ function roadLanes(feature, width) {
|
|
|
175
175
|
if (feature.oneway === true && feature.lanes === void 0) total = dmath.max(1, dmath.min(total, dmath.round(width / 3.3)));
|
|
176
176
|
return { total: dmath.max(minimum, total) };
|
|
177
177
|
}
|
|
178
|
-
/**
|
|
179
|
-
function
|
|
178
|
+
/** Whether a point belongs to a tile part: half-open, so a point on a shared border has one. */
|
|
179
|
+
function inPart(bounds, x, z) {
|
|
180
|
+
return x >= bounds[0] && x < bounds[2] && z >= bounds[1] && z < bounds[3];
|
|
181
|
+
}
|
|
182
|
+
function worldBox(points) {
|
|
183
|
+
const box = [
|
|
184
|
+
Number.POSITIVE_INFINITY,
|
|
185
|
+
Number.POSITIVE_INFINITY,
|
|
186
|
+
Number.NEGATIVE_INFINITY,
|
|
187
|
+
Number.NEGATIVE_INFINITY
|
|
188
|
+
];
|
|
189
|
+
for (const [x, z] of points) {
|
|
190
|
+
box[0] = dmath.min(box[0], x);
|
|
191
|
+
box[1] = dmath.min(box[1], z);
|
|
192
|
+
box[2] = dmath.max(box[2], x);
|
|
193
|
+
box[3] = dmath.max(box[3], z);
|
|
194
|
+
}
|
|
195
|
+
return box;
|
|
196
|
+
}
|
|
197
|
+
const PART_CELLS = 16;
|
|
198
|
+
/**
|
|
199
|
+
* Joined world lines per features list: a tile registered in parts (AmbientTileInput.bounds)
|
|
200
|
+
* grouped and joined all its lines again for every part, most of a part's drafting time.
|
|
201
|
+
*/
|
|
202
|
+
const preparedTiles = /* @__PURE__ */ new WeakMap();
|
|
203
|
+
function prepareTile(input, options) {
|
|
180
204
|
const { origin, tileSize } = input;
|
|
181
|
-
const
|
|
182
|
-
|
|
183
|
-
const maxX = origin[0] + tileSize;
|
|
184
|
-
const maxZ = origin[1] + tileSize;
|
|
185
|
-
const drafts = [];
|
|
186
|
-
const runways = [];
|
|
205
|
+
const cached = preparedTiles.get(input.features);
|
|
206
|
+
if (cached !== void 0 && cached.origin[0] === origin[0] && cached.origin[1] === origin[1] && cached.tileSize === tileSize && cached.tunnels === options.tunnels) return cached;
|
|
187
207
|
const toWorld = (line) => line.map((p) => [origin[0] + p[0] * tileSize, origin[1] + p[1] * tileSize]);
|
|
208
|
+
const features = [];
|
|
209
|
+
const runways = [];
|
|
188
210
|
for (const feature of groupTransportationFeatures(input.features)) {
|
|
189
211
|
const classified = classifyFeature(feature);
|
|
190
212
|
if (classified === void 0) continue;
|
|
@@ -202,28 +224,128 @@ function featureDrafts(input, options) {
|
|
|
202
224
|
const kind = transportKind(feature);
|
|
203
225
|
const width = classified.class === "water" ? feature.width ?? 60 : classified.class === "walk" ? dmath.max(1.2, feature.width ?? 2.4) : classified.class === "rail" ? 3 : transportWidth(feature, kind);
|
|
204
226
|
const lanes = classified.class === "road" ? roadLanes(feature, width).total : 2;
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
const draft = {
|
|
228
|
+
class: classified.class,
|
|
229
|
+
kind: classified.kind,
|
|
230
|
+
width,
|
|
231
|
+
lanes,
|
|
232
|
+
oneway: feature.oneway === true && (classified.class === "road" || classified.class === "water"),
|
|
233
|
+
layer: feature.layer ?? 0,
|
|
234
|
+
bridge: feature.bridge === true,
|
|
235
|
+
tunnel: feature.tunnel === true,
|
|
236
|
+
link: isTransportLink(feature),
|
|
237
|
+
...feature.name !== void 0 ? { name: feature.name } : {},
|
|
238
|
+
...feature.deckElevation !== void 0 ? { deckElevation: feature.deckElevation } : {}
|
|
239
|
+
};
|
|
240
|
+
if (feature.bridgeConnections !== void 0 && feature.bridgeConnections.length > 0) draft.bridgeConnections = feature.bridgeConnections.map((c) => ({
|
|
241
|
+
point: [origin[0] + c.point[0] * tileSize, origin[1] + c.point[1] * tileSize],
|
|
242
|
+
elevation: c.elevation,
|
|
243
|
+
radius: c.radius
|
|
244
|
+
}));
|
|
245
|
+
if (feature.bridgeApproachProfile?.length) draft.bridgeApproachProfile = feature.bridgeApproachProfile.map((sample) => ({
|
|
246
|
+
...sample,
|
|
247
|
+
point: [origin[0] + sample.point[0] * tileSize, origin[1] + sample.point[1] * tileSize]
|
|
248
|
+
}));
|
|
249
|
+
features.push({
|
|
250
|
+
draft,
|
|
251
|
+
source: feature
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
const prepared = {
|
|
255
|
+
origin,
|
|
256
|
+
tileSize,
|
|
257
|
+
tunnels: options.tunnels,
|
|
258
|
+
features,
|
|
259
|
+
runways
|
|
260
|
+
};
|
|
261
|
+
preparedTiles.set(input.features, prepared);
|
|
262
|
+
return prepared;
|
|
263
|
+
}
|
|
264
|
+
/** World bounds of each of a feature's source lines and of them all (see PreparedFeature). */
|
|
265
|
+
function lineBoxes(feature, origin, tileSize) {
|
|
266
|
+
if (feature.boxes !== void 0) return;
|
|
267
|
+
const source = feature.source.lines;
|
|
268
|
+
const boxes = new Float64Array(source.length * 4);
|
|
269
|
+
const all = [
|
|
270
|
+
Number.POSITIVE_INFINITY,
|
|
271
|
+
Number.POSITIVE_INFINITY,
|
|
272
|
+
Number.NEGATIVE_INFINITY,
|
|
273
|
+
Number.NEGATIVE_INFINITY
|
|
274
|
+
];
|
|
275
|
+
source.forEach((line, i) => {
|
|
276
|
+
const box = worldBox(line);
|
|
277
|
+
boxes[i * 4] = origin[0] + box[0] * tileSize;
|
|
278
|
+
boxes[i * 4 + 1] = origin[1] + box[1] * tileSize;
|
|
279
|
+
boxes[i * 4 + 2] = origin[0] + box[2] * tileSize;
|
|
280
|
+
boxes[i * 4 + 3] = origin[1] + box[3] * tileSize;
|
|
281
|
+
all[0] = dmath.min(all[0], boxes[i * 4]);
|
|
282
|
+
all[1] = dmath.min(all[1], boxes[i * 4 + 1]);
|
|
283
|
+
all[2] = dmath.max(all[2], boxes[i * 4 + 2]);
|
|
284
|
+
all[3] = dmath.max(all[3], boxes[i * 4 + 3]);
|
|
285
|
+
});
|
|
286
|
+
feature.boxes = boxes;
|
|
287
|
+
feature.box = all;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The prepared features whose boxes may reach a part, in their order (every one for a whole
|
|
291
|
+
* tile), boxes made. Each still checks its own box against the part.
|
|
292
|
+
*/
|
|
293
|
+
function partFeatures(prepared, origin, tileSize, bounds) {
|
|
294
|
+
const cell = (value, start) => dmath.clamp(dmath.floor((value - start) / tileSize * PART_CELLS), 0, PART_CELLS - 1);
|
|
295
|
+
if (bounds === void 0) {
|
|
296
|
+
for (const feature of prepared.features) lineBoxes(feature, origin, tileSize);
|
|
297
|
+
return prepared.features;
|
|
298
|
+
}
|
|
299
|
+
let cells = prepared.cells;
|
|
300
|
+
if (cells === void 0) {
|
|
301
|
+
const made = Array.from({ length: PART_CELLS * PART_CELLS }, () => []);
|
|
302
|
+
prepared.features.forEach((feature, index) => {
|
|
303
|
+
lineBoxes(feature, origin, tileSize);
|
|
304
|
+
const [x0, z0, x1, z1] = feature.box;
|
|
305
|
+
for (let row = cell(z0, origin[1]); row <= cell(z1, origin[1]); row++) for (let col = cell(x0, origin[0]); col <= cell(x1, origin[0]); col++) made[row * PART_CELLS + col].push(index);
|
|
306
|
+
});
|
|
307
|
+
prepared.cells = made;
|
|
308
|
+
cells = made;
|
|
309
|
+
}
|
|
310
|
+
const picked = /* @__PURE__ */ new Set();
|
|
311
|
+
for (let row = cell(bounds[1], origin[1]); row <= cell(bounds[3], origin[1]); row++) for (let col = cell(bounds[0], origin[0]); col <= cell(bounds[2], origin[0]); col++) for (const index of cells[row * PART_CELLS + col]) picked.add(index);
|
|
312
|
+
return [...picked].sort((a, b) => a - b).map((index) => prepared.features[index]);
|
|
313
|
+
}
|
|
314
|
+
/** Convert a tile's transportation features to clipped world-metre drafts. */
|
|
315
|
+
function featureDrafts(input, options) {
|
|
316
|
+
const { origin, tileSize, bounds } = input;
|
|
317
|
+
const minX = bounds?.[0] ?? origin[0];
|
|
318
|
+
const minZ = bounds?.[1] ?? origin[1];
|
|
319
|
+
const maxX = bounds?.[2] ?? origin[0] + tileSize;
|
|
320
|
+
const maxZ = bounds?.[3] ?? origin[1] + tileSize;
|
|
321
|
+
const prepared = prepareTile(input, options);
|
|
322
|
+
const drafts = [];
|
|
323
|
+
const runways = prepared.runways.filter(({ a, b }) => !bounds || inPart(bounds, (a[0] + b[0]) / 2, (a[1] + b[1]) / 2)).map(({ a, b }) => ({
|
|
324
|
+
a: [a[0], a[1]],
|
|
325
|
+
b: [b[0], b[1]]
|
|
326
|
+
}));
|
|
327
|
+
for (const feature of partFeatures(prepared, origin, tileSize, bounds)) {
|
|
328
|
+
const source = feature.source.lines;
|
|
329
|
+
const reach = feature.box;
|
|
330
|
+
if (reach[2] < minX || reach[0] > maxX || reach[3] < minZ || reach[1] > maxZ) continue;
|
|
331
|
+
const boxes = feature.boxes;
|
|
332
|
+
const reaching = source.filter((_, i) => !(boxes[i * 4 + 2] < minX || boxes[i * 4] > maxX || boxes[i * 4 + 3] < minZ || boxes[i * 4 + 1] > maxZ));
|
|
333
|
+
if (!reaching.length) continue;
|
|
334
|
+
const draft = feature.draft;
|
|
335
|
+
for (const line of joinTerrainLines(reaching, feature.source.oneway === true)) {
|
|
336
|
+
const points = line.map((p) => [origin[0] + p[0] * tileSize, origin[1] + p[1] * tileSize]);
|
|
337
|
+
for (const piece of clipPolyline(points, minX, minZ, maxX, maxZ)) drafts.push({
|
|
338
|
+
...draft,
|
|
339
|
+
points: piece.map((p) => [p[0], p[1]]),
|
|
340
|
+
...draft.bridgeConnections !== void 0 ? { bridgeConnections: draft.bridgeConnections.map((c) => ({
|
|
341
|
+
...c,
|
|
342
|
+
point: [c.point[0], c.point[1]]
|
|
343
|
+
})) } : {},
|
|
344
|
+
...draft.bridgeApproachProfile !== void 0 ? { bridgeApproachProfile: draft.bridgeApproachProfile.map((sample) => ({
|
|
345
|
+
...sample,
|
|
346
|
+
point: [sample.point[0], sample.point[1]]
|
|
347
|
+
})) } : {}
|
|
348
|
+
});
|
|
227
349
|
}
|
|
228
350
|
}
|
|
229
351
|
return {
|
|
@@ -243,28 +365,45 @@ const POI_KINDS = new Set([
|
|
|
243
365
|
"aerodrome"
|
|
244
366
|
]);
|
|
245
367
|
/** Convert a tile's POIs to world points (only those inside the tile). */
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
368
|
+
/**
|
|
369
|
+
* A tile's POIs matched and placed once: a tile registered in parts read and matched every one of
|
|
370
|
+
* them again for each part.
|
|
371
|
+
*/
|
|
372
|
+
const placedPois = /* @__PURE__ */ new WeakMap();
|
|
373
|
+
function tilePois(pois, origin, tileSize, bounds) {
|
|
374
|
+
if (pois === void 0) return [];
|
|
375
|
+
let placed = placedPois.get(pois);
|
|
376
|
+
if (placed === void 0 || placed.origin[0] !== origin[0] || placed.origin[1] !== origin[1] || placed.tileSize !== tileSize) {
|
|
377
|
+
const all = [];
|
|
378
|
+
for (const poi of pois) {
|
|
379
|
+
const kind = (poi.subclass ?? poi.class).toLowerCase();
|
|
380
|
+
const matched = POI_KINDS.has(kind) ? kind : POI_KINDS.has(poi.class) ? poi.class : void 0;
|
|
381
|
+
if (matched === void 0) continue;
|
|
382
|
+
if ([
|
|
383
|
+
"traffic_signals",
|
|
384
|
+
"stop",
|
|
385
|
+
"give_way"
|
|
386
|
+
].includes(matched) && (poi.bridge || poi.tunnel)) continue;
|
|
387
|
+
const [u, v] = poi.point;
|
|
388
|
+
if (u < 0 || u > 1 || v < 0 || v > 1) continue;
|
|
389
|
+
all.push({
|
|
390
|
+
kind: matched === "stop" ? "give_way" : matched,
|
|
391
|
+
x: origin[0] + u * tileSize,
|
|
392
|
+
z: origin[1] + v * tileSize,
|
|
393
|
+
...poi.name !== void 0 ? { name: poi.name } : {},
|
|
394
|
+
...poi.stop === "all" ? { allWay: true } : {},
|
|
395
|
+
layer: poi.layer ?? 0
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
placed = {
|
|
399
|
+
origin: [origin[0], origin[1]],
|
|
400
|
+
tileSize,
|
|
401
|
+
pois: all
|
|
402
|
+
};
|
|
403
|
+
placedPois.set(pois, placed);
|
|
267
404
|
}
|
|
405
|
+
const result = [];
|
|
406
|
+
for (const poi of placed.pois) if (!bounds || inPart(bounds, poi.x, poi.z)) result.push({ ...poi });
|
|
268
407
|
return result;
|
|
269
408
|
}
|
|
270
409
|
//#endregion
|
|
@@ -446,6 +585,7 @@ const ambientAgentSchema = z.strictObject({
|
|
|
446
585
|
lane: z.string().describe("Lane id the agent is on (\"\" for aircraft)."),
|
|
447
586
|
s: num.describe("Metres along the lane; negative while on the connector into it."),
|
|
448
587
|
speed: num.nonnegative().describe("Speed along the lane in m/s."),
|
|
588
|
+
boosted: z.boolean().optional().describe("Lane speed includes the 4× travel boost."),
|
|
449
589
|
cruise: num.positive().describe("Vessel cruise limit in m/s.").optional(),
|
|
450
590
|
prev: z.string().describe("Previous lane (its connector leads onto `lane`).").optional(),
|
|
451
591
|
next: z.string().describe("Chosen next lane.").optional(),
|
package/dist/kernel.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as WildlifeWorld, c as WILDLIFE_FAMILIES, d as WildlifeHabitat, f as WildlifeMotion, i as WildlifeBudget, l as WildlifeChoice, m as wildlifeSpeciesSchema, n as WILDLIFE_TICK_RATE, o as stepWildlife, p as WildlifeSpecies, r as WildlifeAgent, s as wildlifeCandidates, t as WILDLIFE_CELL_METERS, u as WildlifeFamily } from "./wildlife-
|
|
1
|
+
import { a as WildlifeWorld, c as WILDLIFE_FAMILIES, d as WildlifeHabitat, f as WildlifeMotion, i as WildlifeBudget, l as WildlifeChoice, m as wildlifeSpeciesSchema, n as WILDLIFE_TICK_RATE, o as stepWildlife, p as WildlifeSpecies, r as WildlifeAgent, s as wildlifeCandidates, t as WILDLIFE_CELL_METERS, u as WildlifeFamily } from "./wildlife-CvHzzI9m.mjs";
|
|
2
2
|
import { Quat } from "@bendyline/molen-kernel/determinism";
|
|
3
3
|
import { ComponentType, JsonObject, World } from "@bendyline/molen-kernel/world";
|
|
4
4
|
import { ComponentMap, EntityId, SceneManifest } from "@bendyline/molen-schema";
|
|
@@ -20,6 +20,8 @@ interface AmbientAirCorridor extends JsonObject {
|
|
|
20
20
|
length: number;
|
|
21
21
|
}
|
|
22
22
|
interface AmbientAgentData extends JsonObject {
|
|
23
|
+
/** Kernel-owned: the lane speed includes the world's 4× travel boost. */
|
|
24
|
+
boosted?: boolean;
|
|
23
25
|
kind: AmbientKind;
|
|
24
26
|
type: string;
|
|
25
27
|
color?: string;
|
|
@@ -365,6 +367,11 @@ interface EdgeDraft {
|
|
|
365
367
|
elevation: number;
|
|
366
368
|
radius: number;
|
|
367
369
|
}[];
|
|
370
|
+
bridgeApproachProfile?: {
|
|
371
|
+
point: Point2;
|
|
372
|
+
elevation: number;
|
|
373
|
+
flatness: number;
|
|
374
|
+
}[];
|
|
368
375
|
}
|
|
369
376
|
/** Design speeds in m/s by kind. */
|
|
370
377
|
declare const KIND_SPEED: Readonly<Record<RoadKind, number>>;
|
|
@@ -386,6 +393,8 @@ interface TileDraftInput {
|
|
|
386
393
|
origin: readonly [number, number];
|
|
387
394
|
tileSize: number;
|
|
388
395
|
features: readonly TerrainTransportationFeature[];
|
|
396
|
+
/** World X/Z part of the tile to keep (see AmbientTileInput.bounds); default the whole tile. */
|
|
397
|
+
bounds?: readonly [number, number, number, number];
|
|
389
398
|
}
|
|
390
399
|
interface TileDrafts {
|
|
391
400
|
drafts: EdgeDraft[];
|
|
@@ -492,6 +501,12 @@ declare function pseudoAngle(dx: number, dz: number): number;
|
|
|
492
501
|
declare const GRID_CELL = 64;
|
|
493
502
|
interface EdgeSpan {
|
|
494
503
|
readonly edge: string;
|
|
504
|
+
/**
|
|
505
|
+
* The edge itself and its lanes of each class, as inserted: a spawner weighs every span within
|
|
506
|
+
* reach, and looking both up by id for each was most of a run's few milliseconds.
|
|
507
|
+
*/
|
|
508
|
+
readonly ref: TransportEdge;
|
|
509
|
+
readonly lanes: Readonly<Record<TransportClass, number>>;
|
|
495
510
|
/** Edge-path distances bounding the span. */
|
|
496
511
|
readonly d0: number;
|
|
497
512
|
readonly d1: number;
|
|
@@ -500,13 +515,26 @@ interface EdgeSpan {
|
|
|
500
515
|
readonly z: number;
|
|
501
516
|
}
|
|
502
517
|
declare class LaneGrid {
|
|
503
|
-
|
|
518
|
+
/** Rows by cell z, then cells by cell x: integer keys, no string per probed cell. */
|
|
519
|
+
private readonly rows;
|
|
520
|
+
private cellCount;
|
|
504
521
|
private readonly edgeCells;
|
|
505
522
|
/** Bumped on every change; lets callers cache derived sums. */
|
|
506
523
|
version: number;
|
|
507
524
|
insert(edge: TransportEdge, laneCounts: Readonly<Record<TransportClass, number>>): void;
|
|
508
525
|
remove(edgeId: string): void;
|
|
509
|
-
/**
|
|
526
|
+
/**
|
|
527
|
+
* Remove edges together, each touched cell's spans filtered once: a tile's edges share its
|
|
528
|
+
* cells, and filtering a dense city cell again for each of its edges held a frame 5 ms as the
|
|
529
|
+
* tile left.
|
|
530
|
+
*/
|
|
531
|
+
removeAll(edgeIds: Iterable<string>): void;
|
|
532
|
+
/**
|
|
533
|
+
* Cells overlapping the disc of radius `r`, in row-major order (z, then x, ascending). A train
|
|
534
|
+
* or boat ring spans thousands of mostly empty cells: probing each one cost a fast flight
|
|
535
|
+
* several milliseconds per spawner run, so a disc larger than the populated grid walks the
|
|
536
|
+
* populated cells instead and sorts the matches into the same order.
|
|
537
|
+
*/
|
|
510
538
|
private cellsNear;
|
|
511
539
|
/** Lane-metres of a class in cells overlapping the disc. */
|
|
512
540
|
laneMeters(x: number, z: number, r: number, cls: TransportClass): number;
|
|
@@ -534,6 +562,12 @@ interface AmbientTileInput {
|
|
|
534
562
|
heightAt?: (x: number, z: number) => number;
|
|
535
563
|
/** Infer sidewalks along streets without mapped footways (default true). */
|
|
536
564
|
sidewalks?: boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Build only this world X/Z part of the tile, [minX, minZ, maxX, maxZ] (default: all of it).
|
|
567
|
+
* A large tile registered as parts, each under its own key, costs a tick a part instead of
|
|
568
|
+
* one long tick; edges stitch across part borders as across tile borders.
|
|
569
|
+
*/
|
|
570
|
+
bounds?: readonly [number, number, number, number];
|
|
537
571
|
}
|
|
538
572
|
interface TransportNetworkOptions {
|
|
539
573
|
traffic?: "right" | "left";
|
|
@@ -576,8 +610,14 @@ declare class TransportNetwork implements GraphStore {
|
|
|
576
610
|
private readonly nodes;
|
|
577
611
|
private readonly edges;
|
|
578
612
|
private readonly lanes;
|
|
613
|
+
/** Each edge's lane count per class (see lanesOfClass), kept with its lanes. */
|
|
614
|
+
private readonly classLanes;
|
|
579
615
|
private readonly junctions;
|
|
580
616
|
private readonly tiles;
|
|
617
|
+
/**
|
|
618
|
+
* Border nodes by class and layer, then by rounded position (see borderCell): stitching probes
|
|
619
|
+
* the 25 positions around each new border node, and a string key for each was most of it.
|
|
620
|
+
*/
|
|
581
621
|
private readonly borders;
|
|
582
622
|
private readonly crossings;
|
|
583
623
|
private readonly crossingsByEdge;
|
|
@@ -596,6 +636,11 @@ declare class TransportNetwork implements GraphStore {
|
|
|
596
636
|
node(id: string): TransportNode | undefined;
|
|
597
637
|
edge(id: string): TransportEdge | undefined;
|
|
598
638
|
lane(id: string): TransportLane | undefined;
|
|
639
|
+
/**
|
|
640
|
+
* How many of an edge's lanes are of `cls`. A city's spawn ring is tens of thousands of spans,
|
|
641
|
+
* and looking up every lane of each one held a spawning tick near 10 ms.
|
|
642
|
+
*/
|
|
643
|
+
lanesOfClass(edgeId: string, cls: TransportClass): number;
|
|
599
644
|
junction(id: string): TransportJunction | undefined;
|
|
600
645
|
setJunction(junction: TransportJunction): void;
|
|
601
646
|
deleteJunction(id: string): void;
|
|
@@ -643,6 +688,8 @@ declare class TransportNetwork implements GraphStore {
|
|
|
643
688
|
s: number;
|
|
644
689
|
distance: number;
|
|
645
690
|
} | undefined;
|
|
691
|
+
/** The network's sizes, without the walks `stats()` makes. */
|
|
692
|
+
sizes(): Pick<TransportNetworkStats, "tiles" | "nodes" | "edges" | "lanes" | "junctions">;
|
|
646
693
|
stats(): TransportNetworkStats;
|
|
647
694
|
/** Drop everything. */
|
|
648
695
|
clear(): void;
|
|
@@ -658,6 +705,8 @@ interface AmbientSolid {
|
|
|
658
705
|
radius: number;
|
|
659
706
|
}
|
|
660
707
|
interface AgentEnv {
|
|
708
|
+
/** Internal scale resolved from the world's boost setting by stepAgents. */
|
|
709
|
+
speedScale?: number;
|
|
661
710
|
net: TransportNetwork;
|
|
662
711
|
policy: AmbientPolicy;
|
|
663
712
|
tick: number;
|
|
@@ -673,7 +722,7 @@ declare function agentSample(net: TransportNetwork, agent: Readonly<AmbientAgent
|
|
|
673
722
|
/** Rotation for an agent facing along a sample (with pitch unless flat). */
|
|
674
723
|
declare function agentRotation(sample: LaneSample, pitch: boolean): Quat;
|
|
675
724
|
/** Advance every ambient agent one tick. */
|
|
676
|
-
declare function stepAgents(world: World,
|
|
725
|
+
declare function stepAgents(world: World, environment: AgentEnv): void;
|
|
677
726
|
/** Step back `distance` metres from a lane position along the lead's trail. */
|
|
678
727
|
declare function walkBack(net: TransportNetwork, laneId: string, s: number, prev: string | undefined, trail: readonly string[], distance: number): {
|
|
679
728
|
lane: string;
|
|
@@ -754,6 +803,18 @@ interface AmbientOptions {
|
|
|
754
803
|
seed?: string | number;
|
|
755
804
|
/** Cars yield to vehicles someone is driving (`mounted` riders); default true. */
|
|
756
805
|
yieldToDriven?: boolean;
|
|
806
|
+
/**
|
|
807
|
+
* Tile registrations a tick applies, in queue order (removals are not counted); default all.
|
|
808
|
+
* A dense tile's network takes tens of milliseconds to build, so a host streaming many tiles
|
|
809
|
+
* (or one tile in parts, see AmbientTileInput.bounds) passes 1 to keep each tick short.
|
|
810
|
+
*/
|
|
811
|
+
registrationsPerTick?: number;
|
|
812
|
+
/**
|
|
813
|
+
* Tile removals a tick applies, in queue order; default all. A tile streamed in parts leaves
|
|
814
|
+
* all at once, and removing every part (rebuilding the junctions they were stitched to) in one
|
|
815
|
+
* tick held it 10 ms.
|
|
816
|
+
*/
|
|
817
|
+
removalsPerTick?: number;
|
|
757
818
|
}
|
|
758
819
|
interface AmbientStats {
|
|
759
820
|
network: TransportNetworkStats;
|
|
@@ -774,7 +835,7 @@ interface AmbientBox {
|
|
|
774
835
|
interface AmbientHandle {
|
|
775
836
|
readonly world: World;
|
|
776
837
|
readonly network: TransportNetwork;
|
|
777
|
-
/** Queue a streamed tile (applied at
|
|
838
|
+
/** Queue a streamed tile (applied at a coming tick, see registrationsPerTick, or by `flush()`). */
|
|
778
839
|
registerTile(tile: AmbientTileInput): void;
|
|
779
840
|
unregisterTile(key: string): void;
|
|
780
841
|
/** Apply queued tile changes now (outside a tick). */
|