wallhammer-web 0.0.0-stage → 0.4.1
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 +21 -0
- package/README.md +92 -2
- package/dist/base/data.d.ts +67 -0
- package/dist/base/data.js +10 -0
- package/dist/base/destructible.d.ts +167 -0
- package/dist/base/destructible.js +47 -0
- package/dist/base/env-slot.d.ts +101 -0
- package/dist/base/env-slot.js +8 -0
- package/dist/base/frames.d.ts +138 -0
- package/dist/base/frames.js +459 -0
- package/dist/base/index.d.ts +21 -0
- package/dist/base/index.js +11 -0
- package/dist/base/mat34.d.ts +46 -0
- package/dist/base/mat34.js +173 -0
- package/dist/base/material.d.ts +87 -0
- package/dist/base/material.js +6 -0
- package/dist/base/math.d.ts +27 -0
- package/dist/base/math.js +60 -0
- package/dist/base/progress.d.ts +38 -0
- package/dist/base/progress.js +81 -0
- package/dist/base/rig.d.ts +177 -0
- package/dist/base/rig.js +97 -0
- package/dist/base/trig.d.ts +29 -0
- package/dist/base/trig.js +169 -0
- package/dist/base/up.d.ts +26 -0
- package/dist/base/up.js +40 -0
- package/dist/base/view.d.ts +128 -0
- package/dist/base/view.js +136 -0
- package/dist/camera/camera.d.ts +99 -0
- package/dist/camera/camera.js +228 -0
- package/dist/camera/follow.d.ts +120 -0
- package/dist/camera/follow.js +320 -0
- package/dist/camera/free.d.ts +153 -0
- package/dist/camera/free.js +359 -0
- package/dist/camera/index.d.ts +10 -0
- package/dist/camera/index.js +6 -0
- package/dist/camera/orbit.d.ts +93 -0
- package/dist/camera/orbit.js +261 -0
- package/dist/camera/path.d.ts +48 -0
- package/dist/camera/path.js +179 -0
- package/dist/core/ballistic.d.ts +66 -0
- package/dist/core/ballistic.js +104 -0
- package/dist/core/bodies.d.ts +77 -0
- package/dist/core/bodies.js +125 -0
- package/dist/core/clock.d.ts +37 -0
- package/dist/core/clock.js +87 -0
- package/dist/core/cover-fade.d.ts +14 -0
- package/dist/core/cover-fade.js +38 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.js +8 -0
- package/dist/core/kepler.d.ts +74 -0
- package/dist/core/kepler.js +108 -0
- package/dist/core/level-fade.d.ts +66 -0
- package/dist/core/level-fade.js +123 -0
- package/dist/core/palette.d.ts +15 -0
- package/dist/core/palette.js +47 -0
- package/dist/env/atmosphere.d.ts +129 -0
- package/dist/env/atmosphere.js +707 -0
- package/dist/env/cloud-field.d.ts +44 -0
- package/dist/env/cloud-field.js +111 -0
- package/dist/env/environment.d.ts +217 -0
- package/dist/env/environment.js +441 -0
- package/dist/env/frame-block.d.ts +29 -0
- package/dist/env/frame-block.js +152 -0
- package/dist/env/glsl.d.ts +35 -0
- package/dist/env/glsl.js +246 -0
- package/dist/env/index.d.ts +13 -0
- package/dist/env/index.js +9 -0
- package/dist/env/sky.d.ts +48 -0
- package/dist/env/sky.js +227 -0
- package/dist/env/sun.d.ts +31 -0
- package/dist/env/sun.js +42 -0
- package/dist/gen-arch/build.d.ts +17 -0
- package/dist/gen-arch/build.js +414 -0
- package/dist/gen-arch/damage/damaged.d.ts +44 -0
- package/dist/gen-arch/damage/damaged.js +1119 -0
- package/dist/gen-arch/damage/fall-material.d.ts +10 -0
- package/dist/gen-arch/damage/fall-material.js +47 -0
- package/dist/gen-arch/damage/fall.d.ts +78 -0
- package/dist/gen-arch/damage/fall.js +797 -0
- package/dist/gen-arch/damage/rubble.d.ts +22 -0
- package/dist/gen-arch/damage/rubble.js +188 -0
- package/dist/gen-arch/index.d.ts +25 -0
- package/dist/gen-arch/index.js +16 -0
- package/dist/gen-arch/interior/interior-plan.d.ts +114 -0
- package/dist/gen-arch/interior/interior-plan.js +615 -0
- package/dist/gen-arch/interior/interior.d.ts +97 -0
- package/dist/gen-arch/interior/interior.js +966 -0
- package/dist/gen-arch/structure/building-shader.d.ts +25 -0
- package/dist/gen-arch/structure/building-shader.js +946 -0
- package/dist/gen-arch/structure/buildings.d.ts +248 -0
- package/dist/gen-arch/structure/buildings.js +294 -0
- package/dist/gen-arch/structure/dims.d.ts +77 -0
- package/dist/gen-arch/structure/dims.js +39 -0
- package/dist/gen-arch/structure/distant.d.ts +62 -0
- package/dist/gen-arch/structure/distant.js +316 -0
- package/dist/gen-arch/structure/env-slots.d.ts +18 -0
- package/dist/gen-arch/structure/env-slots.js +47 -0
- package/dist/gen-arch/structure/facade.d.ts +193 -0
- package/dist/gen-arch/structure/facade.js +159 -0
- package/dist/gen-arch/structure/parts.d.ts +31 -0
- package/dist/gen-arch/structure/parts.js +69 -0
- package/dist/gen-arch/structure/roof.d.ts +76 -0
- package/dist/gen-arch/structure/roof.js +568 -0
- package/dist/gen-arch/structure/structure-material.d.ts +23 -0
- package/dist/gen-arch/structure/structure-material.js +55 -0
- package/dist/gen-arch/structure/writer.d.ts +94 -0
- package/dist/gen-arch/structure/writer.js +195 -0
- package/dist/gen-core/cell.d.ts +138 -0
- package/dist/gen-core/cell.js +150 -0
- package/dist/gen-core/cube-sphere.d.ts +57 -0
- package/dist/gen-core/cube-sphere.js +159 -0
- package/dist/gen-core/field.d.ts +55 -0
- package/dist/gen-core/field.js +154 -0
- package/dist/gen-core/geometry.d.ts +31 -0
- package/dist/gen-core/geometry.js +231 -0
- package/dist/gen-core/hash.d.ts +18 -0
- package/dist/gen-core/hash.js +58 -0
- package/dist/gen-core/height-field.d.ts +33 -0
- package/dist/gen-core/height-field.js +137 -0
- package/dist/gen-core/index.d.ts +22 -0
- package/dist/gen-core/index.js +17 -0
- package/dist/gen-core/instance-cells.d.ts +37 -0
- package/dist/gen-core/instance-cells.js +72 -0
- package/dist/gen-core/near-scatter.d.ts +56 -0
- package/dist/gen-core/near-scatter.js +120 -0
- package/dist/gen-core/noise.d.ts +23 -0
- package/dist/gen-core/noise.js +72 -0
- package/dist/gen-core/occupancy.d.ts +21 -0
- package/dist/gen-core/occupancy.js +104 -0
- package/dist/gen-core/sphere-patch.d.ts +138 -0
- package/dist/gen-core/sphere-patch.js +544 -0
- package/dist/gen-core/strip-surface.d.ts +34 -0
- package/dist/gen-core/strip-surface.js +246 -0
- package/dist/gen-core/strip.d.ts +102 -0
- package/dist/gen-core/strip.js +817 -0
- package/dist/gen-ground/env-slots.d.ts +48 -0
- package/dist/gen-ground/env-slots.js +78 -0
- package/dist/gen-ground/ground.d.ts +78 -0
- package/dist/gen-ground/ground.js +208 -0
- package/dist/gen-ground/index.d.ts +9 -0
- package/dist/gen-ground/index.js +7 -0
- package/dist/gen-ground/markings.d.ts +46 -0
- package/dist/gen-ground/markings.js +124 -0
- package/dist/gen-ground/materials.d.ts +18 -0
- package/dist/gen-ground/materials.js +22 -0
- package/dist/gen-ground/terrain-shader.d.ts +5 -0
- package/dist/gen-ground/terrain-shader.js +151 -0
- package/dist/gen-mesh/bare-shapes.d.ts +194 -0
- package/dist/gen-mesh/bare-shapes.js +596 -0
- package/dist/gen-mesh/bisect-surface.d.ts +47 -0
- package/dist/gen-mesh/bisect-surface.js +261 -0
- package/dist/gen-mesh/box.d.ts +18 -0
- package/dist/gen-mesh/box.js +2 -0
- package/dist/gen-mesh/cell-morph-mesh.d.ts +52 -0
- package/dist/gen-mesh/cell-morph-mesh.js +258 -0
- package/dist/gen-mesh/cell-surface-mesh.d.ts +32 -0
- package/dist/gen-mesh/cell-surface-mesh.js +140 -0
- package/dist/gen-mesh/chunk-mesh.d.ts +25 -0
- package/dist/gen-mesh/chunk-mesh.js +112 -0
- package/dist/gen-mesh/drape-mesh.d.ts +36 -0
- package/dist/gen-mesh/drape-mesh.js +98 -0
- package/dist/gen-mesh/height-field-mesh.d.ts +14 -0
- package/dist/gen-mesh/height-field-mesh.js +98 -0
- package/dist/gen-mesh/index.d.ts +26 -0
- package/dist/gen-mesh/index.js +15 -0
- package/dist/gen-mesh/line-mesh.d.ts +25 -0
- package/dist/gen-mesh/line-mesh.js +62 -0
- package/dist/gen-mesh/mesh-builder.d.ts +115 -0
- package/dist/gen-mesh/mesh-builder.js +315 -0
- package/dist/gen-mesh/packed-mesh.d.ts +53 -0
- package/dist/gen-mesh/packed-mesh.js +205 -0
- package/dist/gen-mesh/prism-mesh.d.ts +33 -0
- package/dist/gen-mesh/prism-mesh.js +176 -0
- package/dist/gen-mesh/rig-mesh.d.ts +9 -0
- package/dist/gen-mesh/rig-mesh.js +135 -0
- package/dist/gen-mesh/strip-mesh.d.ts +45 -0
- package/dist/gen-mesh/strip-mesh.js +258 -0
- package/dist/gen-plan/drain.d.ts +58 -0
- package/dist/gen-plan/drain.js +270 -0
- package/dist/gen-plan/grid.d.ts +37 -0
- package/dist/gen-plan/grid.js +182 -0
- package/dist/gen-plan/horizon.d.ts +50 -0
- package/dist/gen-plan/horizon.js +185 -0
- package/dist/gen-plan/index.d.ts +15 -0
- package/dist/gen-plan/index.js +13 -0
- package/dist/gen-plan/line-tiles.d.ts +35 -0
- package/dist/gen-plan/line-tiles.js +190 -0
- package/dist/gen-plan/lines.d.ts +31 -0
- package/dist/gen-plan/lines.js +183 -0
- package/dist/gen-plan/plots.d.ts +40 -0
- package/dist/gen-plan/plots.js +282 -0
- package/dist/gen-plan/route.d.ts +55 -0
- package/dist/gen-plan/route.js +297 -0
- package/dist/gen-plan/sites.d.ts +32 -0
- package/dist/gen-plan/sites.js +209 -0
- package/dist/gen-tex/code-stamp.d.ts +31 -0
- package/dist/gen-tex/code-stamp.js +137 -0
- package/dist/gen-tex/index.d.ts +7 -0
- package/dist/gen-tex/index.js +5 -0
- package/dist/gen-tex/light-horizon.d.ts +47 -0
- package/dist/gen-tex/light-horizon.js +180 -0
- package/dist/gen-tex/textures.d.ts +8 -0
- package/dist/gen-tex/textures.js +49 -0
- package/dist/gen-tex/value-textures.d.ts +46 -0
- package/dist/gen-tex/value-textures.js +102 -0
- package/dist/gen-vegetation/env-slots.d.ts +20 -0
- package/dist/gen-vegetation/env-slots.js +29 -0
- package/dist/gen-vegetation/index.d.ts +8 -0
- package/dist/gen-vegetation/index.js +7 -0
- package/dist/gen-vegetation/materials.d.ts +7 -0
- package/dist/gen-vegetation/materials.js +17 -0
- package/dist/gen-vegetation/planting.d.ts +170 -0
- package/dist/gen-vegetation/planting.js +363 -0
- package/dist/gen-vegetation/tree-shader.d.ts +23 -0
- package/dist/gen-vegetation/tree-shader.js +229 -0
- package/dist/gen-vegetation/trees.d.ts +59 -0
- package/dist/gen-vegetation/trees.js +329 -0
- package/dist/gpu/device.d.ts +286 -0
- package/dist/gpu/device.js +1157 -0
- package/dist/gpu/gl.d.ts +134 -0
- package/dist/gpu/gl.js +276 -0
- package/dist/gpu/index.d.ts +4 -0
- package/dist/gpu/index.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/dist/motion/graph.d.ts +244 -0
- package/dist/motion/graph.js +739 -0
- package/dist/motion/index.d.ts +8 -0
- package/dist/motion/index.js +8 -0
- package/dist/motion/pose-ops.d.ts +30 -0
- package/dist/motion/pose-ops.js +232 -0
- package/dist/motion/reach.d.ts +45 -0
- package/dist/motion/reach.js +264 -0
- package/dist/motion/skeleton.d.ts +49 -0
- package/dist/motion/skeleton.js +99 -0
- package/dist/platform/byte-store.d.ts +21 -0
- package/dist/platform/byte-store.js +137 -0
- package/dist/platform/canvas.d.ts +29 -0
- package/dist/platform/canvas.js +76 -0
- package/dist/platform/context-loss.d.ts +8 -0
- package/dist/platform/context-loss.js +17 -0
- package/dist/platform/free-input.d.ts +51 -0
- package/dist/platform/free-input.js +100 -0
- package/dist/platform/index.d.ts +18 -0
- package/dist/platform/index.js +10 -0
- package/dist/platform/input.d.ts +48 -0
- package/dist/platform/input.js +117 -0
- package/dist/platform/keys.d.ts +12 -0
- package/dist/platform/keys.js +29 -0
- package/dist/platform/loop.d.ts +41 -0
- package/dist/platform/loop.js +84 -0
- package/dist/platform/walk-input.d.ts +74 -0
- package/dist/platform/walk-input.js +226 -0
- package/dist/platform/worker.d.ts +51 -0
- package/dist/platform/worker.js +170 -0
- package/dist/render/bone-instances.d.ts +24 -0
- package/dist/render/bone-instances.js +74 -0
- package/dist/render/cells.d.ts +70 -0
- package/dist/render/cells.js +144 -0
- package/dist/render/glsl.d.ts +66 -0
- package/dist/render/glsl.js +173 -0
- package/dist/render/index.d.ts +26 -0
- package/dist/render/index.js +16 -0
- package/dist/render/instance-sets.d.ts +97 -0
- package/dist/render/instance-sets.js +241 -0
- package/dist/render/near-instances.d.ts +75 -0
- package/dist/render/near-instances.js +219 -0
- package/dist/render/particles.d.ts +63 -0
- package/dist/render/particles.js +215 -0
- package/dist/render/pieces.d.ts +57 -0
- package/dist/render/pieces.js +151 -0
- package/dist/render/point-lights.d.ts +97 -0
- package/dist/render/point-lights.js +243 -0
- package/dist/render/renderer.d.ts +447 -0
- package/dist/render/renderer.js +1100 -0
- package/dist/render/rig.d.ts +74 -0
- package/dist/render/rig.js +576 -0
- package/dist/render/shadow-areas.d.ts +49 -0
- package/dist/render/shadow-areas.js +125 -0
- package/dist/render/shadow-glsl.d.ts +12 -0
- package/dist/render/shadow-glsl.js +146 -0
- package/dist/render/transient.d.ts +61 -0
- package/dist/render/transient.js +213 -0
- package/dist/render/value-glsl.d.ts +17 -0
- package/dist/render/value-glsl.js +208 -0
- package/dist/render/value-layers.d.ts +180 -0
- package/dist/render/value-layers.js +333 -0
- package/dist/runtime/atmosphere.d.ts +37 -0
- package/dist/runtime/atmosphere.js +304 -0
- package/dist/runtime/cloud-shell.d.ts +29 -0
- package/dist/runtime/cloud-shell.js +158 -0
- package/dist/runtime/engine.d.ts +155 -0
- package/dist/runtime/engine.js +305 -0
- package/dist/runtime/environment-link.d.ts +22 -0
- package/dist/runtime/environment-link.js +49 -0
- package/dist/runtime/index.d.ts +13 -0
- package/dist/runtime/index.js +12 -0
- package/dist/runtime/precipitation-glsl.d.ts +2 -0
- package/dist/runtime/precipitation-glsl.js +70 -0
- package/dist/runtime/precipitation.d.ts +11 -0
- package/dist/runtime/precipitation.js +78 -0
- package/dist/runtime/sky.d.ts +30 -0
- package/dist/runtime/sky.js +114 -0
- package/dist/runtime/streaming.d.ts +245 -0
- package/dist/runtime/streaming.js +602 -0
- package/dist/sim/agenda.d.ts +167 -0
- package/dist/sim/agenda.js +425 -0
- package/dist/sim/bytes.d.ts +34 -0
- package/dist/sim/bytes.js +125 -0
- package/dist/sim/destruction/apply.d.ts +59 -0
- package/dist/sim/destruction/apply.js +243 -0
- package/dist/sim/destruction/cell-states.d.ts +54 -0
- package/dist/sim/destruction/cell-states.js +198 -0
- package/dist/sim/destruction/index.d.ts +11 -0
- package/dist/sim/destruction/index.js +10 -0
- package/dist/sim/destruction/int-geometry.d.ts +17 -0
- package/dist/sim/destruction/int-geometry.js +131 -0
- package/dist/sim/destruction/pick.d.ts +13 -0
- package/dist/sim/destruction/pick.js +59 -0
- package/dist/sim/destruction/rubble.d.ts +8 -0
- package/dist/sim/destruction/rubble.js +159 -0
- package/dist/sim/destruction/state.d.ts +15 -0
- package/dist/sim/destruction/state.js +83 -0
- package/dist/sim/destruction/structure.d.ts +30 -0
- package/dist/sim/destruction/structure.js +139 -0
- package/dist/sim/events.d.ts +37 -0
- package/dist/sim/events.js +106 -0
- package/dist/sim/fixed.d.ts +21 -0
- package/dist/sim/fixed.js +64 -0
- package/dist/sim/flow-probe.d.ts +58 -0
- package/dist/sim/flow-probe.js +158 -0
- package/dist/sim/flow.d.ts +257 -0
- package/dist/sim/flow.js +967 -0
- package/dist/sim/index.d.ts +28 -0
- package/dist/sim/index.js +20 -0
- package/dist/sim/interlock.d.ts +47 -0
- package/dist/sim/interlock.js +252 -0
- package/dist/sim/movers.d.ts +228 -0
- package/dist/sim/movers.js +1083 -0
- package/dist/sim/nav.d.ts +72 -0
- package/dist/sim/nav.js +292 -0
- package/dist/sim/paths.d.ts +80 -0
- package/dist/sim/paths.js +197 -0
- package/dist/sim/regions.d.ts +87 -0
- package/dist/sim/regions.js +517 -0
- package/dist/sim/simulation.d.ts +114 -0
- package/dist/sim/simulation.js +291 -0
- package/dist/sim/states.d.ts +23 -0
- package/dist/sim/states.js +54 -0
- package/dist/sim/table.d.ts +49 -0
- package/dist/sim/table.js +126 -0
- package/dist/sim/zones.d.ts +11 -0
- package/dist/sim/zones.js +196 -0
- package/dist/tools/collision-lines.d.ts +12 -0
- package/dist/tools/collision-lines.js +50 -0
- package/dist/tools/data-view-glsl.d.ts +3 -0
- package/dist/tools/data-view-glsl.js +63 -0
- package/dist/tools/data-view-layers.d.ts +20 -0
- package/dist/tools/data-view-layers.js +60 -0
- package/dist/tools/debug-view.d.ts +30 -0
- package/dist/tools/debug-view.js +4 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +7 -0
- package/dist/tools/mesh-checks.d.ts +67 -0
- package/dist/tools/mesh-checks.js +188 -0
- package/dist/tools/profile.d.ts +85 -0
- package/dist/tools/profile.js +173 -0
- package/dist/world/cell-cache.d.ts +32 -0
- package/dist/world/cell-cache.js +60 -0
- package/dist/world/cell-format.d.ts +25 -0
- package/dist/world/cell-format.js +232 -0
- package/dist/world/collide.d.ts +192 -0
- package/dist/world/collide.js +822 -0
- package/dist/world/index.d.ts +16 -0
- package/dist/world/index.js +12 -0
- package/dist/world/mesh-solids.d.ts +48 -0
- package/dist/world/mesh-solids.js +169 -0
- package/dist/world/pick.d.ts +34 -0
- package/dist/world/pick.js +177 -0
- package/dist/world/providers.d.ts +66 -0
- package/dist/world/providers.js +83 -0
- package/dist/world/sphere.d.ts +69 -0
- package/dist/world/sphere.js +271 -0
- package/dist/world/streaming.d.ts +288 -0
- package/dist/world/streaming.js +801 -0
- package/dist/world/walker.d.ts +145 -0
- package/dist/world/walker.js +502 -0
- package/docs/architecture.md +111 -0
- package/docs/cameras.md +302 -0
- package/docs/concepts.md +123 -0
- package/docs/destruction.md +127 -0
- package/docs/frames.md +199 -0
- package/docs/generators.md +575 -0
- package/docs/getting-started.md +123 -0
- package/docs/headless.md +50 -0
- package/docs/motion.md +160 -0
- package/docs/planet.md +152 -0
- package/docs/recipes.md +521 -0
- package/docs/reference.md +364 -0
- package/docs/rendering.md +823 -0
- package/docs/rigs.md +203 -0
- package/docs/simulation.md +235 -0
- package/docs/streaming.md +590 -0
- package/docs/system.md +166 -0
- package/docs/tools.md +175 -0
- package/docs/walking.md +262 -0
- package/package.json +131 -3
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { NavGraph } from './nav.ts';
|
|
2
|
+
export interface RegionNavOptions {
|
|
3
|
+
/** Side of the square regions, metres. Default 400. */
|
|
4
|
+
cell?: number;
|
|
5
|
+
/** A region per node instead of the grid: any non-negative integers, equal for nodes of one region. */
|
|
6
|
+
regionOf?: ArrayLike<number>;
|
|
7
|
+
/** Most routes kept in the cache; when it is full it starts over. Default 65536. */
|
|
8
|
+
cacheLimit?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class RegionNav {
|
|
11
|
+
readonly nav: NavGraph;
|
|
12
|
+
readonly regionCount: number;
|
|
13
|
+
readonly gateCount: number;
|
|
14
|
+
/** Region of each node. */
|
|
15
|
+
readonly region: Int32Array;
|
|
16
|
+
/** Index of each node inside its region. */
|
|
17
|
+
private readonly local;
|
|
18
|
+
/** Gates of region r: the gate indices `gateStart[r] … gateStart[r + 1]`, ascending by node. */
|
|
19
|
+
private readonly gateStart;
|
|
20
|
+
private readonly gateNode;
|
|
21
|
+
/** Gate index of a node, or -1. */
|
|
22
|
+
private readonly gateOf;
|
|
23
|
+
private readonly regionSize;
|
|
24
|
+
private readonly mmX;
|
|
25
|
+
private readonly mmZ;
|
|
26
|
+
/** Outgoing and incoming edges per node, by edge index. */
|
|
27
|
+
private readonly outStart;
|
|
28
|
+
private readonly outEdges;
|
|
29
|
+
private readonly inStart;
|
|
30
|
+
private readonly inEdges;
|
|
31
|
+
/** Tables per gate: cost and edge per node of the region, away from the gate (`fwd`) and towards it (`rev`). */
|
|
32
|
+
private readonly fwdCost;
|
|
33
|
+
private readonly fwdVia;
|
|
34
|
+
private readonly revCost;
|
|
35
|
+
private readonly revVia;
|
|
36
|
+
private readonly built;
|
|
37
|
+
private unbuilt;
|
|
38
|
+
private nextUnbuilt;
|
|
39
|
+
private costPerMm;
|
|
40
|
+
private readonly cache;
|
|
41
|
+
private readonly cacheLimit;
|
|
42
|
+
/** Search over the gates: cost, where it came from, and which query the values belong to. */
|
|
43
|
+
private readonly gCost;
|
|
44
|
+
private readonly viaGate;
|
|
45
|
+
private readonly viaEdge;
|
|
46
|
+
private readonly seen;
|
|
47
|
+
private readonly closed;
|
|
48
|
+
private query;
|
|
49
|
+
private readonly heap;
|
|
50
|
+
private readonly wayHeap;
|
|
51
|
+
/** Routes searched (cache misses) and routes answered from the cache. */
|
|
52
|
+
searches: number;
|
|
53
|
+
hits: number;
|
|
54
|
+
constructor(nav: NavGraph, options?: RegionNavOptions);
|
|
55
|
+
private updateHeuristic;
|
|
56
|
+
/** Regions whose tables are not built yet. */
|
|
57
|
+
get pending(): number;
|
|
58
|
+
/** Are all regions built (no query has to build one)? */
|
|
59
|
+
get ready(): boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Builds the tables of up to `maxRegions` regions and returns how many are still missing. Call it with a small
|
|
62
|
+
* number from every frame to spread the work; queries build the regions they need themselves, so the routes are the
|
|
63
|
+
* same whether this was called or not.
|
|
64
|
+
*/
|
|
65
|
+
prepare(maxRegions?: number): number;
|
|
66
|
+
/** Forgets every table and cached route: call after costs or blocked flags of the graph changed. */
|
|
67
|
+
rebuild(): void;
|
|
68
|
+
private buildRegion;
|
|
69
|
+
private ensure;
|
|
70
|
+
/**
|
|
71
|
+
* Cheapest ways inside region `r` from `root` to every node (or, reversed, from every node to `root`): the cost per
|
|
72
|
+
* local node and the edge that reaches it (reversed: the edge that leaves it towards the root). `goal` ends the
|
|
73
|
+
* search early.
|
|
74
|
+
*/
|
|
75
|
+
private ways;
|
|
76
|
+
/**
|
|
77
|
+
* A route as a list of edges (empty when from = to), or null when the goal cannot be reached. Cached; do not change
|
|
78
|
+
* the returned array.
|
|
79
|
+
*/
|
|
80
|
+
find(from: number, to: number): Int32Array | null;
|
|
81
|
+
private heuristic;
|
|
82
|
+
private search;
|
|
83
|
+
/** Summed cost of a route's edges. */
|
|
84
|
+
cost(route: ArrayLike<number>): number;
|
|
85
|
+
/** Routes in the cache now. */
|
|
86
|
+
get cached(): number;
|
|
87
|
+
}
|
|
@@ -0,0 +1,517 @@
|
|
|
1
|
+
// Route search on two levels over a navigation graph (in the spirit of HPA*).
|
|
2
|
+
//
|
|
3
|
+
// The nodes are split into regions (a square grid, or any partition the caller gives). A node with an edge to or from
|
|
4
|
+
// another region is a gate. For every gate the cheapest ways inside its region are precomputed as two tables of ways: from the
|
|
5
|
+
// gate to every node of the region and from every node to the gate. A query then searches only the small graph of
|
|
6
|
+
// gates (edges between regions, plus gate to gate inside a region at the precomputed cost) and stitches the route
|
|
7
|
+
// together from the tables. Routes are kept in a cache.
|
|
8
|
+
//
|
|
9
|
+
// A route is a pure function of the graph and the two nodes: integer costs, a fixed tie-break (cost, then index), and
|
|
10
|
+
// regions built on demand give the same tables as regions built ahead. So preparing ahead in pieces (`prepare`) only
|
|
11
|
+
// moves the work, it never changes a route. Every way between two regions passes gates and the ways between the
|
|
12
|
+
// gates of a region are exact, so a route costs what the plain A* of the graph finds; among equally cheap routes it
|
|
13
|
+
// may pick another one.
|
|
14
|
+
//
|
|
15
|
+
// Not simulation state: it only reads the graph. After costs or blocked flags of the graph change, call `rebuild`.
|
|
16
|
+
import { lengthMm, mm } from './fixed.js';
|
|
17
|
+
/** Binary heap of (key, id) pairs ordered by key, then id: the same pops on every machine. */
|
|
18
|
+
class Heap {
|
|
19
|
+
key = [];
|
|
20
|
+
id = [];
|
|
21
|
+
get size() {
|
|
22
|
+
return this.key.length;
|
|
23
|
+
}
|
|
24
|
+
/** The smallest key (only when `size` > 0). */
|
|
25
|
+
get min() {
|
|
26
|
+
return this.key[0];
|
|
27
|
+
}
|
|
28
|
+
clear() {
|
|
29
|
+
this.key.length = 0;
|
|
30
|
+
this.id.length = 0;
|
|
31
|
+
}
|
|
32
|
+
less(i, j) {
|
|
33
|
+
return this.key[i] < this.key[j] || (this.key[i] === this.key[j] && this.id[i] < this.id[j]);
|
|
34
|
+
}
|
|
35
|
+
swap(i, j) {
|
|
36
|
+
const k = this.key[i];
|
|
37
|
+
this.key[i] = this.key[j];
|
|
38
|
+
this.key[j] = k;
|
|
39
|
+
const d = this.id[i];
|
|
40
|
+
this.id[i] = this.id[j];
|
|
41
|
+
this.id[j] = d;
|
|
42
|
+
}
|
|
43
|
+
push(key, id) {
|
|
44
|
+
this.key.push(key);
|
|
45
|
+
this.id.push(id);
|
|
46
|
+
let i = this.key.length - 1;
|
|
47
|
+
while (i > 0) {
|
|
48
|
+
const p = (i - 1) >> 1;
|
|
49
|
+
if (!this.less(i, p))
|
|
50
|
+
break;
|
|
51
|
+
this.swap(i, p);
|
|
52
|
+
i = p;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/** Removes the smallest pair and returns its id; its key is in `popped`. */
|
|
56
|
+
popped = 0;
|
|
57
|
+
pop() {
|
|
58
|
+
const top = this.id[0];
|
|
59
|
+
this.popped = this.key[0];
|
|
60
|
+
const last = this.key.length - 1;
|
|
61
|
+
this.swap(0, last);
|
|
62
|
+
this.key.pop();
|
|
63
|
+
this.id.pop();
|
|
64
|
+
let i = 0;
|
|
65
|
+
for (;;) {
|
|
66
|
+
const l = i * 2 + 1;
|
|
67
|
+
const r = l + 1;
|
|
68
|
+
let m = i;
|
|
69
|
+
if (l < last && this.less(l, m))
|
|
70
|
+
m = l;
|
|
71
|
+
if (r < last && this.less(r, m))
|
|
72
|
+
m = r;
|
|
73
|
+
if (m === i)
|
|
74
|
+
break;
|
|
75
|
+
this.swap(i, m);
|
|
76
|
+
i = m;
|
|
77
|
+
}
|
|
78
|
+
return top;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const EMPTY = new Int32Array(0);
|
|
82
|
+
/** `viaGate` of a gate reached straight from the start node. */
|
|
83
|
+
const FROM_START = -1;
|
|
84
|
+
export class RegionNav {
|
|
85
|
+
nav;
|
|
86
|
+
regionCount;
|
|
87
|
+
gateCount;
|
|
88
|
+
/** Region of each node. */
|
|
89
|
+
region;
|
|
90
|
+
/** Index of each node inside its region. */
|
|
91
|
+
local;
|
|
92
|
+
/** Gates of region r: the gate indices `gateStart[r] … gateStart[r + 1]`, ascending by node. */
|
|
93
|
+
gateStart;
|
|
94
|
+
gateNode;
|
|
95
|
+
/** Gate index of a node, or -1. */
|
|
96
|
+
gateOf;
|
|
97
|
+
regionSize;
|
|
98
|
+
mmX;
|
|
99
|
+
mmZ;
|
|
100
|
+
/** Outgoing and incoming edges per node, by edge index. */
|
|
101
|
+
outStart;
|
|
102
|
+
outEdges;
|
|
103
|
+
inStart;
|
|
104
|
+
inEdges;
|
|
105
|
+
/** Tables per gate: cost and edge per node of the region, away from the gate (`fwd`) and towards it (`rev`). */
|
|
106
|
+
fwdCost;
|
|
107
|
+
fwdVia;
|
|
108
|
+
revCost;
|
|
109
|
+
revVia;
|
|
110
|
+
built;
|
|
111
|
+
unbuilt;
|
|
112
|
+
nextUnbuilt = 0;
|
|
113
|
+
costPerMm = 1;
|
|
114
|
+
cache = new Map();
|
|
115
|
+
cacheLimit;
|
|
116
|
+
/** Search over the gates: cost, where it came from, and which query the values belong to. */
|
|
117
|
+
gCost;
|
|
118
|
+
viaGate;
|
|
119
|
+
viaEdge;
|
|
120
|
+
seen;
|
|
121
|
+
closed;
|
|
122
|
+
query = 0;
|
|
123
|
+
heap = new Heap();
|
|
124
|
+
wayHeap = new Heap();
|
|
125
|
+
/** Routes searched (cache misses) and routes answered from the cache. */
|
|
126
|
+
searches = 0;
|
|
127
|
+
hits = 0;
|
|
128
|
+
constructor(nav, options = {}) {
|
|
129
|
+
this.nav = nav;
|
|
130
|
+
this.cacheLimit = Math.max(1, options.cacheLimit ?? 65536);
|
|
131
|
+
const n = nav.nodeCount;
|
|
132
|
+
const m = nav.edgeCount;
|
|
133
|
+
this.mmX = new Int32Array(n);
|
|
134
|
+
this.mmZ = new Int32Array(n);
|
|
135
|
+
for (let i = 0; i < n; i++) {
|
|
136
|
+
this.mmX[i] = mm(nav.nodeX[i]);
|
|
137
|
+
this.mmZ[i] = mm(nav.nodeZ[i]);
|
|
138
|
+
}
|
|
139
|
+
// Regions: the caller's partition or grid squares, numbered in the order nodes first name them.
|
|
140
|
+
const raw = new Float64Array(n);
|
|
141
|
+
if (options.regionOf) {
|
|
142
|
+
if (options.regionOf.length !== n)
|
|
143
|
+
throw new Error('RegionNav: regionOf needs one entry per node');
|
|
144
|
+
for (let i = 0; i < n; i++)
|
|
145
|
+
raw[i] = options.regionOf[i];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const cell = Math.max(1, mm(options.cell ?? 400));
|
|
149
|
+
let minX = Infinity;
|
|
150
|
+
let minZ = Infinity;
|
|
151
|
+
let maxX = -Infinity;
|
|
152
|
+
for (let i = 0; i < n; i++) {
|
|
153
|
+
minX = Math.min(minX, this.mmX[i]);
|
|
154
|
+
maxX = Math.max(maxX, this.mmX[i]);
|
|
155
|
+
minZ = Math.min(minZ, this.mmZ[i]);
|
|
156
|
+
}
|
|
157
|
+
const cols = n > 0 ? Math.floor((maxX - minX) / cell) + 1 : 1;
|
|
158
|
+
for (let i = 0; i < n; i++)
|
|
159
|
+
raw[i] = Math.floor((this.mmZ[i] - minZ) / cell) * cols + Math.floor((this.mmX[i] - minX) / cell);
|
|
160
|
+
}
|
|
161
|
+
const ids = new Map();
|
|
162
|
+
this.region = new Int32Array(n);
|
|
163
|
+
this.local = new Int32Array(n);
|
|
164
|
+
const sizes = [];
|
|
165
|
+
for (let i = 0; i < n; i++) {
|
|
166
|
+
let r = ids.get(raw[i]);
|
|
167
|
+
if (r === undefined) {
|
|
168
|
+
r = sizes.length;
|
|
169
|
+
ids.set(raw[i], r);
|
|
170
|
+
sizes.push(0);
|
|
171
|
+
}
|
|
172
|
+
this.region[i] = r;
|
|
173
|
+
this.local[i] = sizes[r];
|
|
174
|
+
sizes[r] = sizes[r] + 1;
|
|
175
|
+
}
|
|
176
|
+
const regions = sizes.length;
|
|
177
|
+
this.regionCount = regions;
|
|
178
|
+
this.regionSize = Int32Array.from(sizes);
|
|
179
|
+
// Adjacency in both directions.
|
|
180
|
+
this.outStart = new Int32Array(n + 1);
|
|
181
|
+
this.inStart = new Int32Array(n + 1);
|
|
182
|
+
for (let e = 0; e < m; e++) {
|
|
183
|
+
this.outStart[nav.edgeFrom[e] + 1]++;
|
|
184
|
+
this.inStart[nav.edgeTo[e] + 1]++;
|
|
185
|
+
}
|
|
186
|
+
for (let i = 0; i < n; i++) {
|
|
187
|
+
this.outStart[i + 1] = this.outStart[i + 1] + this.outStart[i];
|
|
188
|
+
this.inStart[i + 1] = this.inStart[i + 1] + this.inStart[i];
|
|
189
|
+
}
|
|
190
|
+
this.outEdges = new Int32Array(m);
|
|
191
|
+
this.inEdges = new Int32Array(m);
|
|
192
|
+
const outFill = this.outStart.slice(0, n);
|
|
193
|
+
const inFill = this.inStart.slice(0, n);
|
|
194
|
+
for (let e = 0; e < m; e++) {
|
|
195
|
+
const a = nav.edgeFrom[e];
|
|
196
|
+
const b = nav.edgeTo[e];
|
|
197
|
+
this.outEdges[outFill[a]] = e;
|
|
198
|
+
outFill[a] = outFill[a] + 1;
|
|
199
|
+
this.inEdges[inFill[b]] = e;
|
|
200
|
+
inFill[b] = inFill[b] + 1;
|
|
201
|
+
}
|
|
202
|
+
// Gates: nodes on an edge between two regions. Numbered region by region, ascending by node.
|
|
203
|
+
const isGate = new Uint8Array(n);
|
|
204
|
+
for (let e = 0; e < m; e++) {
|
|
205
|
+
const a = nav.edgeFrom[e];
|
|
206
|
+
const b = nav.edgeTo[e];
|
|
207
|
+
if (this.region[a] !== this.region[b]) {
|
|
208
|
+
isGate[a] = 1;
|
|
209
|
+
isGate[b] = 1;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
this.gateStart = new Int32Array(regions + 1);
|
|
213
|
+
for (let i = 0; i < n; i++)
|
|
214
|
+
if (isGate[i])
|
|
215
|
+
this.gateStart[this.region[i] + 1]++;
|
|
216
|
+
for (let r = 0; r < regions; r++)
|
|
217
|
+
this.gateStart[r + 1] = this.gateStart[r + 1] + this.gateStart[r];
|
|
218
|
+
const gates = this.gateStart[regions];
|
|
219
|
+
this.gateCount = gates;
|
|
220
|
+
this.gateNode = new Int32Array(gates);
|
|
221
|
+
this.gateOf = new Int32Array(n).fill(-1);
|
|
222
|
+
const gateFill = this.gateStart.slice(0, regions);
|
|
223
|
+
for (let i = 0; i < n; i++) {
|
|
224
|
+
if (!isGate[i])
|
|
225
|
+
continue;
|
|
226
|
+
const r = this.region[i];
|
|
227
|
+
const g = gateFill[r];
|
|
228
|
+
gateFill[r] = g + 1;
|
|
229
|
+
this.gateNode[g] = i;
|
|
230
|
+
this.gateOf[i] = g;
|
|
231
|
+
}
|
|
232
|
+
this.fwdCost = new Array(gates);
|
|
233
|
+
this.fwdVia = new Array(gates);
|
|
234
|
+
this.revCost = new Array(gates);
|
|
235
|
+
this.revVia = new Array(gates);
|
|
236
|
+
this.built = new Uint8Array(regions);
|
|
237
|
+
this.unbuilt = regions;
|
|
238
|
+
this.gCost = new Float64Array(gates);
|
|
239
|
+
this.viaGate = new Int32Array(gates);
|
|
240
|
+
this.viaEdge = new Int32Array(gates);
|
|
241
|
+
this.seen = new Int32Array(gates);
|
|
242
|
+
this.closed = new Int32Array(gates);
|
|
243
|
+
this.updateHeuristic();
|
|
244
|
+
}
|
|
245
|
+
updateHeuristic() {
|
|
246
|
+
const nav = this.nav;
|
|
247
|
+
let r = Infinity;
|
|
248
|
+
for (let e = 0; e < nav.edgeCount; e++)
|
|
249
|
+
r = Math.min(r, nav.edgeCost[e] / nav.edgeLength[e]);
|
|
250
|
+
this.costPerMm = Number.isFinite(r) ? r : 1;
|
|
251
|
+
}
|
|
252
|
+
// --- Preparation -----------------------------------------------------------------------------------------------
|
|
253
|
+
/** Regions whose tables are not built yet. */
|
|
254
|
+
get pending() {
|
|
255
|
+
return this.unbuilt;
|
|
256
|
+
}
|
|
257
|
+
/** Are all regions built (no query has to build one)? */
|
|
258
|
+
get ready() {
|
|
259
|
+
return this.unbuilt === 0;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Builds the tables of up to `maxRegions` regions and returns how many are still missing. Call it with a small
|
|
263
|
+
* number from every frame to spread the work; queries build the regions they need themselves, so the routes are the
|
|
264
|
+
* same whether this was called or not.
|
|
265
|
+
*/
|
|
266
|
+
prepare(maxRegions = Infinity) {
|
|
267
|
+
let done = 0;
|
|
268
|
+
while (this.unbuilt > 0 && done < maxRegions && this.nextUnbuilt < this.regionCount) {
|
|
269
|
+
const r = this.nextUnbuilt++;
|
|
270
|
+
if (this.built[r])
|
|
271
|
+
continue;
|
|
272
|
+
this.buildRegion(r);
|
|
273
|
+
done++;
|
|
274
|
+
}
|
|
275
|
+
return this.unbuilt;
|
|
276
|
+
}
|
|
277
|
+
/** Forgets every table and cached route: call after costs or blocked flags of the graph changed. */
|
|
278
|
+
rebuild() {
|
|
279
|
+
this.built.fill(0);
|
|
280
|
+
this.unbuilt = this.regionCount;
|
|
281
|
+
this.nextUnbuilt = 0;
|
|
282
|
+
for (let g = 0; g < this.gateCount; g++) {
|
|
283
|
+
this.fwdCost[g] = undefined;
|
|
284
|
+
this.fwdVia[g] = undefined;
|
|
285
|
+
this.revCost[g] = undefined;
|
|
286
|
+
this.revVia[g] = undefined;
|
|
287
|
+
}
|
|
288
|
+
this.cache.clear();
|
|
289
|
+
this.updateHeuristic();
|
|
290
|
+
}
|
|
291
|
+
buildRegion(r) {
|
|
292
|
+
for (let g = this.gateStart[r]; g < this.gateStart[r + 1]; g++) {
|
|
293
|
+
const node = this.gateNode[g];
|
|
294
|
+
const fwd = this.ways(r, node, false);
|
|
295
|
+
this.fwdCost[g] = fwd.cost;
|
|
296
|
+
this.fwdVia[g] = fwd.via;
|
|
297
|
+
const rev = this.ways(r, node, true);
|
|
298
|
+
this.revCost[g] = rev.cost;
|
|
299
|
+
this.revVia[g] = rev.via;
|
|
300
|
+
}
|
|
301
|
+
this.built[r] = 1;
|
|
302
|
+
this.unbuilt--;
|
|
303
|
+
}
|
|
304
|
+
ensure(r) {
|
|
305
|
+
if (!this.built[r])
|
|
306
|
+
this.buildRegion(r);
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Cheapest ways inside region `r` from `root` to every node (or, reversed, from every node to `root`): the cost per
|
|
310
|
+
* local node and the edge that reaches it (reversed: the edge that leaves it towards the root). `goal` ends the
|
|
311
|
+
* search early.
|
|
312
|
+
*/
|
|
313
|
+
ways(r, root, reverse, goal = -1) {
|
|
314
|
+
const nav = this.nav;
|
|
315
|
+
const size = this.regionSize[r];
|
|
316
|
+
const cost = new Float64Array(size).fill(Infinity);
|
|
317
|
+
const via = new Int32Array(size).fill(-1);
|
|
318
|
+
const start = reverse ? this.inStart : this.outStart;
|
|
319
|
+
const list = reverse ? this.inEdges : this.outEdges;
|
|
320
|
+
const far = reverse ? nav.edgeFrom : nav.edgeTo;
|
|
321
|
+
const heap = this.wayHeap;
|
|
322
|
+
heap.clear();
|
|
323
|
+
cost[this.local[root]] = 0;
|
|
324
|
+
heap.push(0, root);
|
|
325
|
+
while (heap.size > 0) {
|
|
326
|
+
const u = heap.pop();
|
|
327
|
+
const cu = heap.popped;
|
|
328
|
+
if (cu > cost[this.local[u]])
|
|
329
|
+
continue;
|
|
330
|
+
if (u === goal)
|
|
331
|
+
break;
|
|
332
|
+
for (let k = start[u]; k < start[u + 1]; k++) {
|
|
333
|
+
const e = list[k];
|
|
334
|
+
if (nav.blocked[e])
|
|
335
|
+
continue;
|
|
336
|
+
const v = far[e];
|
|
337
|
+
if (this.region[v] !== r)
|
|
338
|
+
continue;
|
|
339
|
+
const cv = cu + nav.edgeCost[e];
|
|
340
|
+
const lv = this.local[v];
|
|
341
|
+
if (cv < cost[lv]) {
|
|
342
|
+
cost[lv] = cv;
|
|
343
|
+
via[lv] = e;
|
|
344
|
+
heap.push(cv, v);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
heap.clear();
|
|
349
|
+
return { cost, via };
|
|
350
|
+
}
|
|
351
|
+
// --- Queries ---------------------------------------------------------------------------------------------------
|
|
352
|
+
/**
|
|
353
|
+
* A route as a list of edges (empty when from = to), or null when the goal cannot be reached. Cached; do not change
|
|
354
|
+
* the returned array.
|
|
355
|
+
*/
|
|
356
|
+
find(from, to) {
|
|
357
|
+
if (from === to)
|
|
358
|
+
return EMPTY;
|
|
359
|
+
const key = from * this.nav.nodeCount + to;
|
|
360
|
+
const hit = this.cache.get(key);
|
|
361
|
+
if (hit !== undefined) {
|
|
362
|
+
this.hits++;
|
|
363
|
+
return hit;
|
|
364
|
+
}
|
|
365
|
+
this.searches++;
|
|
366
|
+
const route = this.search(from, to);
|
|
367
|
+
if (this.cache.size >= this.cacheLimit)
|
|
368
|
+
this.cache.clear();
|
|
369
|
+
this.cache.set(key, route);
|
|
370
|
+
return route;
|
|
371
|
+
}
|
|
372
|
+
heuristic(node, to) {
|
|
373
|
+
return Math.floor(lengthMm(this.mmX[to] - this.mmX[node], this.mmZ[to] - this.mmZ[node]) * this.costPerMm);
|
|
374
|
+
}
|
|
375
|
+
search(from, to) {
|
|
376
|
+
const nav = this.nav;
|
|
377
|
+
const rs = this.region[from];
|
|
378
|
+
const rt = this.region[to];
|
|
379
|
+
this.ensure(rs);
|
|
380
|
+
this.ensure(rt);
|
|
381
|
+
const q = ++this.query;
|
|
382
|
+
const lFrom = this.local[from];
|
|
383
|
+
const lTo = this.local[to];
|
|
384
|
+
// The cheapest known way to the goal: through the gate `goalGate`, or (-1) the way that stays inside the region.
|
|
385
|
+
let best = Infinity;
|
|
386
|
+
let goalGate = -1;
|
|
387
|
+
let direct = null;
|
|
388
|
+
if (rs === rt) {
|
|
389
|
+
direct = this.ways(rs, from, false, to);
|
|
390
|
+
best = direct.cost[lTo];
|
|
391
|
+
}
|
|
392
|
+
const heap = this.heap;
|
|
393
|
+
heap.clear();
|
|
394
|
+
for (let g = this.gateStart[rs]; g < this.gateStart[rs + 1]; g++) {
|
|
395
|
+
const c = this.revCost[g][lFrom];
|
|
396
|
+
if (c === Infinity)
|
|
397
|
+
continue;
|
|
398
|
+
this.seen[g] = q;
|
|
399
|
+
this.gCost[g] = c;
|
|
400
|
+
this.viaGate[g] = FROM_START;
|
|
401
|
+
this.viaEdge[g] = -1;
|
|
402
|
+
heap.push(c + this.heuristic(this.gateNode[g], to), g);
|
|
403
|
+
}
|
|
404
|
+
while (heap.size > 0 && heap.min < best) {
|
|
405
|
+
const g = heap.pop();
|
|
406
|
+
if (this.closed[g] === q)
|
|
407
|
+
continue;
|
|
408
|
+
this.closed[g] = q;
|
|
409
|
+
const c = this.gCost[g];
|
|
410
|
+
const node = this.gateNode[g];
|
|
411
|
+
const r = this.region[node];
|
|
412
|
+
this.ensure(r);
|
|
413
|
+
const fc = this.fwdCost[g];
|
|
414
|
+
if (r === rt) {
|
|
415
|
+
const t = c + fc[lTo];
|
|
416
|
+
if (t < best) {
|
|
417
|
+
best = t;
|
|
418
|
+
goalGate = g;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
// Edges into other regions.
|
|
422
|
+
for (let k = this.outStart[node]; k < this.outStart[node + 1]; k++) {
|
|
423
|
+
const e = this.outEdges[k];
|
|
424
|
+
if (nav.blocked[e])
|
|
425
|
+
continue;
|
|
426
|
+
const v = nav.edgeTo[e];
|
|
427
|
+
if (this.region[v] === r)
|
|
428
|
+
continue;
|
|
429
|
+
const g2 = this.gateOf[v];
|
|
430
|
+
if (this.closed[g2] === q)
|
|
431
|
+
continue;
|
|
432
|
+
const c2 = c + nav.edgeCost[e];
|
|
433
|
+
if (this.seen[g2] !== q || c2 < this.gCost[g2]) {
|
|
434
|
+
this.seen[g2] = q;
|
|
435
|
+
this.gCost[g2] = c2;
|
|
436
|
+
this.viaGate[g2] = g;
|
|
437
|
+
this.viaEdge[g2] = e;
|
|
438
|
+
heap.push(c2 + this.heuristic(v, to), g2);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// The other gates of this region, at the precomputed cost.
|
|
442
|
+
for (let g2 = this.gateStart[r]; g2 < this.gateStart[r + 1]; g2++) {
|
|
443
|
+
if (g2 === g || this.closed[g2] === q)
|
|
444
|
+
continue;
|
|
445
|
+
const v = this.gateNode[g2];
|
|
446
|
+
const w = fc[this.local[v]];
|
|
447
|
+
if (w === Infinity)
|
|
448
|
+
continue;
|
|
449
|
+
const c2 = c + w;
|
|
450
|
+
if (this.seen[g2] !== q || c2 < this.gCost[g2]) {
|
|
451
|
+
this.seen[g2] = q;
|
|
452
|
+
this.gCost[g2] = c2;
|
|
453
|
+
this.viaGate[g2] = g;
|
|
454
|
+
this.viaEdge[g2] = -1;
|
|
455
|
+
heap.push(c2 + this.heuristic(v, to), g2);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
heap.clear();
|
|
460
|
+
if (best === Infinity)
|
|
461
|
+
return null;
|
|
462
|
+
// Stitch the route, goal first.
|
|
463
|
+
const back = [];
|
|
464
|
+
const walkBack = (gate, node) => {
|
|
465
|
+
const via = this.fwdVia[gate];
|
|
466
|
+
const root = this.gateNode[gate];
|
|
467
|
+
for (let v = node; v !== root;) {
|
|
468
|
+
const e = via[this.local[v]];
|
|
469
|
+
back.push(e);
|
|
470
|
+
v = nav.edgeFrom[e];
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
if (goalGate < 0) {
|
|
474
|
+
for (let v = to; v !== from;) {
|
|
475
|
+
const e = direct.via[this.local[v]];
|
|
476
|
+
back.push(e);
|
|
477
|
+
v = nav.edgeFrom[e];
|
|
478
|
+
}
|
|
479
|
+
return Int32Array.from(back.reverse());
|
|
480
|
+
}
|
|
481
|
+
walkBack(goalGate, to);
|
|
482
|
+
let g = goalGate;
|
|
483
|
+
while (this.viaGate[g] !== FROM_START) {
|
|
484
|
+
const p = this.viaGate[g];
|
|
485
|
+
if (this.viaEdge[g] >= 0)
|
|
486
|
+
back.push(this.viaEdge[g]);
|
|
487
|
+
else
|
|
488
|
+
walkBack(p, this.gateNode[g]);
|
|
489
|
+
g = p;
|
|
490
|
+
}
|
|
491
|
+
// From the start node to the first gate along that gate's table of ways towards it.
|
|
492
|
+
const head = [];
|
|
493
|
+
const first = this.gateNode[g];
|
|
494
|
+
const toGate = this.revVia[g];
|
|
495
|
+
for (let v = from; v !== first;) {
|
|
496
|
+
const e = toGate[this.local[v]];
|
|
497
|
+
head.push(e);
|
|
498
|
+
v = nav.edgeTo[e];
|
|
499
|
+
}
|
|
500
|
+
const out = new Int32Array(head.length + back.length);
|
|
501
|
+
out.set(head);
|
|
502
|
+
for (let i = 0; i < back.length; i++)
|
|
503
|
+
out[head.length + i] = back[back.length - 1 - i];
|
|
504
|
+
return out;
|
|
505
|
+
}
|
|
506
|
+
/** Summed cost of a route's edges. */
|
|
507
|
+
cost(route) {
|
|
508
|
+
let c = 0;
|
|
509
|
+
for (let i = 0; i < route.length; i++)
|
|
510
|
+
c += this.nav.edgeCost[route[i]];
|
|
511
|
+
return c;
|
|
512
|
+
}
|
|
513
|
+
/** Routes in the cache now. */
|
|
514
|
+
get cached() {
|
|
515
|
+
return this.cache.size;
|
|
516
|
+
}
|
|
517
|
+
}
|