@daneren2005/shared-memory-physics 1.8.0 → 1.9.0
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 +110 -2
- package/dist/components/navigation-component-constants.d.ts +11 -0
- package/dist/components/navigation-component.d.ts +31 -0
- package/dist/components/registry.d.ts +9 -0
- package/dist/index.d.ts +24 -2
- package/dist/index.js +1011 -310
- package/dist/index.js.map +1 -1
- package/dist/pathfinding/follow-path.d.ts +9 -0
- package/dist/pathfinding/grid-a-star.d.ts +29 -0
- package/dist/pathfinding/line-of-sight.d.ts +2 -0
- package/dist/pathfinding/min-heap.d.ts +14 -0
- package/dist/pathfinding/nav-grid.d.ts +42 -0
- package/dist/pathfinding/navigation-state.d.ts +20 -0
- package/dist/pathfinding/path-blockers.d.ts +29 -0
- package/dist/pathfinding/path-search.d.ts +27 -0
- package/dist/pathfinding/pathfinding-system.d.ts +27 -0
- package/dist/pathfinding/pathfinding-update.d.ts +36 -0
- package/dist/pathfinding/smooth-path.d.ts +3 -0
- package/package.json +3 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Point } from './path-search';
|
|
2
|
+
export declare const FollowStep: {
|
|
3
|
+
readonly Waiting: 0;
|
|
4
|
+
readonly Waypoint: 1;
|
|
5
|
+
readonly Goal: 2;
|
|
6
|
+
readonly Stuck: 3;
|
|
7
|
+
};
|
|
8
|
+
export type FollowStepValue = typeof FollowStep[keyof typeof FollowStep];
|
|
9
|
+
export declare function followPath(navigation: Int32Array, x: number, y: number, arriveDistance: number, target: Point): FollowStepValue;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type NavGrid from './nav-grid';
|
|
2
|
+
import { type PathRequest, type PathResult, type PathSearch } from './path-search';
|
|
3
|
+
export interface GridAStarOptions {
|
|
4
|
+
diagonal?: boolean;
|
|
5
|
+
maxIterations?: number;
|
|
6
|
+
smooth?: boolean;
|
|
7
|
+
clearance?: number;
|
|
8
|
+
relocateRadius?: number;
|
|
9
|
+
}
|
|
10
|
+
export default class GridAStar implements PathSearch {
|
|
11
|
+
private readonly diagonal;
|
|
12
|
+
private readonly maxIterations;
|
|
13
|
+
private readonly smooth;
|
|
14
|
+
private readonly clearance;
|
|
15
|
+
private readonly relocateRadius;
|
|
16
|
+
private readonly heap;
|
|
17
|
+
private cost;
|
|
18
|
+
private parent;
|
|
19
|
+
private seen;
|
|
20
|
+
private closed;
|
|
21
|
+
private stamp;
|
|
22
|
+
constructor(options?: GridAStarOptions);
|
|
23
|
+
findPath(grid: NavGrid, request: PathRequest): PathResult;
|
|
24
|
+
private relocate;
|
|
25
|
+
private search;
|
|
26
|
+
private relax;
|
|
27
|
+
private trace;
|
|
28
|
+
private prepare;
|
|
29
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default class MinHeap {
|
|
2
|
+
private ids;
|
|
3
|
+
private primary;
|
|
4
|
+
private secondary;
|
|
5
|
+
private count;
|
|
6
|
+
constructor(capacity?: number);
|
|
7
|
+
get size(): number;
|
|
8
|
+
clear(): void;
|
|
9
|
+
push(id: number, primary: number, secondary?: number): void;
|
|
10
|
+
pop(): number;
|
|
11
|
+
private less;
|
|
12
|
+
private set;
|
|
13
|
+
private grow;
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface Rect {
|
|
2
|
+
minX: number;
|
|
3
|
+
minY: number;
|
|
4
|
+
maxX: number;
|
|
5
|
+
maxY: number;
|
|
6
|
+
}
|
|
7
|
+
export interface TileRange {
|
|
8
|
+
fromX: number;
|
|
9
|
+
fromY: number;
|
|
10
|
+
toX: number;
|
|
11
|
+
toY: number;
|
|
12
|
+
}
|
|
13
|
+
export default class NavGrid {
|
|
14
|
+
readonly tilesWide: number;
|
|
15
|
+
readonly tilesHigh: number;
|
|
16
|
+
readonly cellSize: number;
|
|
17
|
+
private blockers;
|
|
18
|
+
private speeds;
|
|
19
|
+
private fastestSpeed;
|
|
20
|
+
private regions;
|
|
21
|
+
private regionsDirty;
|
|
22
|
+
constructor(tilesWide: number, tilesHigh: number, cellSize: number);
|
|
23
|
+
clone(): NavGrid;
|
|
24
|
+
get tileCount(): number;
|
|
25
|
+
get maxSpeed(): number;
|
|
26
|
+
inBounds(tileX: number, tileY: number): boolean;
|
|
27
|
+
index(tileX: number, tileY: number): number;
|
|
28
|
+
tileOf(world: number): number;
|
|
29
|
+
tileCenter(tile: number): number;
|
|
30
|
+
isBlocked(tileX: number, tileY: number): boolean;
|
|
31
|
+
isAreaClear(tileX: number, tileY: number, tilesWide: number, tilesHigh: number): boolean;
|
|
32
|
+
blockerCount(tileX: number, tileY: number): number;
|
|
33
|
+
tilesIn(rect: Rect): TileRange;
|
|
34
|
+
addBlocker(rect: Rect): void;
|
|
35
|
+
removeBlocker(rect: Rect): void;
|
|
36
|
+
setTerrainSpeed(tileX: number, tileY: number, speed: number): void;
|
|
37
|
+
terrainSpeed(tileX: number, tileY: number): number;
|
|
38
|
+
cost(tileX: number, tileY: number): number;
|
|
39
|
+
region(tileX: number, tileY: number): number;
|
|
40
|
+
private rebuildRegions;
|
|
41
|
+
private flood;
|
|
42
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import NavGrid, { type Rect } from './nav-grid';
|
|
2
|
+
import { type PathBlockerDelta } from './path-blockers';
|
|
3
|
+
interface Gate {
|
|
4
|
+
rect: Rect;
|
|
5
|
+
category: number;
|
|
6
|
+
}
|
|
7
|
+
export interface NavigationState {
|
|
8
|
+
grid: NavGrid;
|
|
9
|
+
blockers: Map<number, Rect>;
|
|
10
|
+
gateCategories: number;
|
|
11
|
+
gates: Map<number, Gate>;
|
|
12
|
+
gatedGrids: Map<number, NavGrid>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createNavigationState(tilesWide: number, tilesHigh: number, cellSize: number, gateCategories?: number): NavigationState;
|
|
15
|
+
export declare function navigationGridFor(state: NavigationState, collideMask: number): NavGrid;
|
|
16
|
+
export declare function blockingRects(state: NavigationState, collideMask: number): Array<Rect>;
|
|
17
|
+
export declare function setNavigationTerrainSpeed(state: NavigationState, tileX: number, tileY: number, speed: number): void;
|
|
18
|
+
export declare function applyPathBlockerChanges(state: NavigationState, delta: PathBlockerDelta): boolean;
|
|
19
|
+
export declare function applyPathGateChanges(state: NavigationState, delta: PathBlockerDelta): boolean;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BaseEntity, ComponentMap, EntityWorkerSystemQuery } from '@daneren2005/shared-memory-ecs';
|
|
2
|
+
import type { BodyComponent } from '../components/body-component';
|
|
3
|
+
import type { TransformComponent } from '../components/transform-component';
|
|
4
|
+
import type NavGrid from './nav-grid';
|
|
5
|
+
import type { Rect } from './nav-grid';
|
|
6
|
+
export declare const PATH_BLOCKERS_QUERY = "pathBlockers";
|
|
7
|
+
export declare const PATH_GATES_QUERY = "pathGates";
|
|
8
|
+
export type PathBlockerComponents = {
|
|
9
|
+
transform: TransformComponent;
|
|
10
|
+
body: BodyComponent;
|
|
11
|
+
};
|
|
12
|
+
export interface PathBlockerDelta {
|
|
13
|
+
added: ReadonlyArray<{
|
|
14
|
+
entityId: number;
|
|
15
|
+
components: {
|
|
16
|
+
transform?: unknown;
|
|
17
|
+
body?: unknown;
|
|
18
|
+
};
|
|
19
|
+
}>;
|
|
20
|
+
removed: ReadonlyArray<number>;
|
|
21
|
+
}
|
|
22
|
+
export interface PathBlockerQueryOptions<C extends ComponentMap> {
|
|
23
|
+
gateCategories?: number;
|
|
24
|
+
not?: Array<keyof C>;
|
|
25
|
+
filter?: (entity: BaseEntity<C>) => boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare function pathBlockerQueries<C extends ComponentMap & PathBlockerComponents>(options?: PathBlockerQueryOptions<C>): Record<string, EntityWorkerSystemQuery<C>>;
|
|
28
|
+
export declare function blockerRect(transform: Float32Array, body: Uint32Array): Rect;
|
|
29
|
+
export declare function applyRectChanges(rects: Map<number, Rect>, grids: Iterable<NavGrid>, delta: PathBlockerDelta): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type NavGrid from './nav-grid';
|
|
2
|
+
export interface Point {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
}
|
|
6
|
+
export interface PathRequest {
|
|
7
|
+
startX: number;
|
|
8
|
+
startY: number;
|
|
9
|
+
goalX: number;
|
|
10
|
+
goalY: number;
|
|
11
|
+
agentWidth: number;
|
|
12
|
+
agentHeight: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const PathStatus: {
|
|
15
|
+
readonly Found: 1;
|
|
16
|
+
readonly Incomplete: 2;
|
|
17
|
+
readonly Unreachable: 3;
|
|
18
|
+
};
|
|
19
|
+
export type PathStatusValue = typeof PathStatus[keyof typeof PathStatus];
|
|
20
|
+
export interface PathResult {
|
|
21
|
+
status: PathStatusValue;
|
|
22
|
+
points: Array<Point>;
|
|
23
|
+
iterations: number;
|
|
24
|
+
}
|
|
25
|
+
export interface PathSearch {
|
|
26
|
+
findPath(grid: NavGrid, request: PathRequest): PathResult;
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EntityWorkerSystem } from '@daneren2005/shared-memory-ecs';
|
|
2
|
+
import type { BaseEntity, BaseWorld, ComponentDefinitionMap, ComponentMap, EntityUpdateComponents, EntityWorkerSystemQuery, SystemConfig } from '@daneren2005/shared-memory-ecs';
|
|
3
|
+
import type { NavigationComponents } from '../components/registry';
|
|
4
|
+
import { type PathfindingInitData, type PathfindingUpdateComponents, type PathfindingUpdateFunction, type PathfindingWorld } from './pathfinding-update';
|
|
5
|
+
export interface PathfindingSystemConfig<C extends ComponentMap & NavigationComponents, T extends PathfindingUpdateComponents & EntityUpdateComponents<C>, W extends PathfindingWorld, D extends PathfindingInitData> extends Partial<SystemConfig> {
|
|
6
|
+
getInitData: () => D;
|
|
7
|
+
getWorker?: () => Worker;
|
|
8
|
+
forceMainThread?: boolean;
|
|
9
|
+
updateFunction?: PathfindingUpdateFunction<C, T, W, D>;
|
|
10
|
+
blockers?: {
|
|
11
|
+
not?: Array<keyof C>;
|
|
12
|
+
filter?: (entity: BaseEntity<C>) => boolean;
|
|
13
|
+
};
|
|
14
|
+
queries?: {
|
|
15
|
+
[key: string]: EntityWorkerSystemQuery<C>;
|
|
16
|
+
};
|
|
17
|
+
optional?: Array<keyof C & string>;
|
|
18
|
+
iterationBudget?: number;
|
|
19
|
+
}
|
|
20
|
+
export default class PathfindingSystem<C extends ComponentMap & NavigationComponents, T extends PathfindingUpdateComponents & EntityUpdateComponents<C> = PathfindingUpdateComponents & EntityUpdateComponents<C>, W extends PathfindingWorld = PathfindingWorld, D extends PathfindingInitData = PathfindingInitData> extends EntityWorkerSystem<C, T, W, D> {
|
|
21
|
+
iterationBudget: number | undefined;
|
|
22
|
+
constructor(world: BaseWorld<ComponentDefinitionMap, C>, options: PathfindingSystemConfig<C, T, W, D>);
|
|
23
|
+
addDataToWorld(world: W): void;
|
|
24
|
+
private loaded;
|
|
25
|
+
init(): Promise<void>;
|
|
26
|
+
finishLoading(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ComponentMap, EntityQueryChangedFunction, EntityQueryComponents, EntityUpdateComponents, EntityUpdateFunction, EntityUpdatePreRunFunction, EntityWorkerSystemWorld } from '@daneren2005/shared-memory-ecs';
|
|
2
|
+
import { type NavigationState } from './navigation-state';
|
|
3
|
+
import { type PathSearch } from './path-search';
|
|
4
|
+
export declare const DEFAULT_PATH_SEARCH_ITERATION_BUDGET = 16000;
|
|
5
|
+
export type PathfindingUpdateComponents = {
|
|
6
|
+
navigation: Int32Array;
|
|
7
|
+
transform: Float32Array;
|
|
8
|
+
body?: Uint32Array;
|
|
9
|
+
};
|
|
10
|
+
export interface PathfindingInitData {
|
|
11
|
+
tilesWide: number;
|
|
12
|
+
tilesHigh: number;
|
|
13
|
+
cellSize: number;
|
|
14
|
+
}
|
|
15
|
+
export interface PathfindingWorld extends EntityWorkerSystemWorld {
|
|
16
|
+
navigation: NavigationState;
|
|
17
|
+
blockersAdded?: boolean;
|
|
18
|
+
searchIterations?: number;
|
|
19
|
+
iterationBudget?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface PathfindingUpdateOptions<C extends ComponentMap, T extends PathfindingUpdateComponents & EntityUpdateComponents<C>, W extends PathfindingWorld, D extends PathfindingInitData> {
|
|
22
|
+
search?: PathSearch;
|
|
23
|
+
iterationBudget?: number;
|
|
24
|
+
gateCategories?: number;
|
|
25
|
+
init?: (navigation: NavigationState, data: D | undefined, queries: EntityQueryComponents<C>) => Partial<W> | void;
|
|
26
|
+
queryChanged?: EntityQueryChangedFunction<C, W>;
|
|
27
|
+
preRun?: EntityUpdatePreRunFunction<C, T, W>;
|
|
28
|
+
}
|
|
29
|
+
export interface PathfindingUpdateMetadata {
|
|
30
|
+
gateCategories: number;
|
|
31
|
+
}
|
|
32
|
+
export type PathfindingUpdateFunction<C extends ComponentMap, T extends PathfindingUpdateComponents & EntityUpdateComponents<C>, W extends PathfindingWorld, D extends PathfindingInitData> = EntityUpdateFunction<C, T, W, D> & {
|
|
33
|
+
pathfinding: PathfindingUpdateMetadata;
|
|
34
|
+
};
|
|
35
|
+
export declare function createPathfindingUpdate<C extends ComponentMap = ComponentMap, T extends PathfindingUpdateComponents & EntityUpdateComponents<C> = PathfindingUpdateComponents & EntityUpdateComponents<C>, W extends PathfindingWorld = PathfindingWorld, D extends PathfindingInitData = PathfindingInitData>(options?: PathfindingUpdateOptions<C, T, W, D>): PathfindingUpdateFunction<C, T, W, D>;
|
|
36
|
+
export declare const pathfindingUpdate: PathfindingUpdateFunction<ComponentMap, PathfindingUpdateComponents & EntityUpdateComponents<ComponentMap>, PathfindingWorld, PathfindingInitData>;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@daneren2005/shared-memory-physics",
|
|
3
3
|
"description": "2D physics components and systems built on the shared-memory ECS.",
|
|
4
4
|
"author": "Scott Jackson",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.9.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"sideEffects": false,
|
|
8
8
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"prepare": "husky"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@daneren2005/shared-memory-ecs": "^1.
|
|
45
|
+
"@daneren2005/shared-memory-ecs": "^1.10.2",
|
|
46
46
|
"@daneren2005/shared-memory-objects": "^1.6.0",
|
|
47
47
|
"@semantic-release/git": "^10.0.1",
|
|
48
48
|
"@stylistic/eslint-plugin": "^5.10.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"vitest": "^5.0.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
|
-
"@daneren2005/shared-memory-ecs": "^1.
|
|
63
|
+
"@daneren2005/shared-memory-ecs": "^1.10.0",
|
|
64
64
|
"@daneren2005/shared-memory-objects": "^1.1.0"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|