@esengine/pathfinding 12.0.0 → 12.1.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/dist/index.d.ts CHANGED
@@ -1,176 +1,97 @@
1
- import { BlueprintNodeTemplate, INodeExecutor, BlueprintNode, ExecutionResult } from '@esengine/blueprint';
1
+ import { I as IPathfinder, a as IPathfindingMap, b as IPathfindingOptions, c as IPathResult, H as HeuristicFunction, d as IPathNode, e as IPoint, f as IIncrementalPathfinder, g as IIncrementalPathfindingOptions, h as IPathRequest, i as IPathProgress, j as IIncrementalPathResult, k as IPathValidator, l as IPathValidationResult, m as IPathSmoother } from './IIncrementalPathfinding-3qs7e_pO.js';
2
+ export { D as DEFAULT_PATHFINDING_OPTIONS, t as DEFAULT_REPLANNING_CONFIG, E as EMPTY_PATH_RESULT, u as EMPTY_PROGRESS, s as IReplanningConfig, L as LineOfSightCheck, P as PathfindingState, q as chebyshevDistance, n as createPoint, p as euclideanDistance, o as manhattanDistance, r as octileDistance } from './IIncrementalPathfinding-3qs7e_pO.js';
2
3
 
3
4
  /**
4
- * @zh 寻路系统核心接口
5
- * @en Pathfinding System Core Interfaces
6
- */
7
- /**
8
- * @zh 2D 坐标点
9
- * @en 2D coordinate point
10
- */
11
- interface IPoint {
12
- readonly x: number;
13
- readonly y: number;
14
- }
15
- /**
16
- * @zh 创建点
17
- * @en Create a point
18
- */
19
- declare function createPoint(x: number, y: number): IPoint;
20
- /**
21
- * @zh 路径节点
22
- * @en Path node
23
- */
24
- interface IPathNode {
25
- /** @zh 节点唯一标识 @en Unique node identifier */
26
- readonly id: string | number;
27
- /** @zh 节点位置 @en Node position */
28
- readonly position: IPoint;
29
- /** @zh 移动代价 @en Movement cost */
30
- readonly cost: number;
31
- /** @zh 是否可通行 @en Is walkable */
32
- readonly walkable: boolean;
33
- }
34
- /**
35
- * @zh 路径结果
36
- * @en Path result
37
- */
38
- interface IPathResult {
39
- /** @zh 是否找到路径 @en Whether path was found */
40
- readonly found: boolean;
41
- /** @zh 路径点列表 @en List of path points */
42
- readonly path: readonly IPoint[];
43
- /** @zh 路径总代价 @en Total path cost */
44
- readonly cost: number;
45
- /** @zh 搜索的节点数 @en Number of nodes searched */
46
- readonly nodesSearched: number;
47
- }
48
- /**
49
- * @zh 空路径结果
50
- * @en Empty path result
51
- */
52
- declare const EMPTY_PATH_RESULT: IPathResult;
53
- /**
54
- * @zh 寻路地图接口
55
- * @en Pathfinding map interface
5
+ * @zh 二叉堆(优先队列)
6
+ * @en Binary Heap (Priority Queue)
7
+ *
8
+ * @zh 用于 A* 算法的高效开放列表
9
+ * @en Efficient open list for A* algorithm
56
10
  */
57
- interface IPathfindingMap {
11
+ declare class BinaryHeap<T> {
12
+ private heap;
13
+ private readonly compare;
58
14
  /**
59
- * @zh 获取节点的邻居
60
- * @en Get neighbors of a node
15
+ * @zh 创建二叉堆
16
+ * @en Create binary heap
17
+ *
18
+ * @param compare - @zh 比较函数,返回负数表示 a < b @en Compare function, returns negative if a < b
61
19
  */
62
- getNeighbors(node: IPathNode): IPathNode[];
20
+ constructor(compare: (a: T, b: T) => number);
63
21
  /**
64
- * @zh 获取指定位置的节点
65
- * @en Get node at position
22
+ * @zh 堆大小
23
+ * @en Heap size
66
24
  */
67
- getNodeAt(x: number, y: number): IPathNode | null;
25
+ get size(): number;
68
26
  /**
69
- * @zh 计算两点间的启发式距离
70
- * @en Calculate heuristic distance between two points
27
+ * @zh 是否为空
28
+ * @en Is empty
71
29
  */
72
- heuristic(a: IPoint, b: IPoint): number;
30
+ get isEmpty(): boolean;
73
31
  /**
74
- * @zh 计算两个邻居节点间的移动代价
75
- * @en Calculate movement cost between two neighbor nodes
32
+ * @zh 插入元素
33
+ * @en Push element
76
34
  */
77
- getMovementCost(from: IPathNode, to: IPathNode): number;
35
+ push(item: T): void;
78
36
  /**
79
- * @zh 检查位置是否可通行
80
- * @en Check if position is walkable
37
+ * @zh 弹出最小元素
38
+ * @en Pop minimum element
81
39
  */
82
- isWalkable(x: number, y: number): boolean;
83
- }
84
- /**
85
- * @zh 启发式函数类型
86
- * @en Heuristic function type
87
- */
88
- type HeuristicFunction = (a: IPoint, b: IPoint) => number;
89
- /**
90
- * @zh 曼哈顿距离(4方向移动)
91
- * @en Manhattan distance (4-directional movement)
92
- */
93
- declare function manhattanDistance(a: IPoint, b: IPoint): number;
94
- /**
95
- * @zh 欧几里得距离(任意方向移动)
96
- * @en Euclidean distance (any direction movement)
97
- */
98
- declare function euclideanDistance(a: IPoint, b: IPoint): number;
99
- /**
100
- * @zh 切比雪夫距离(8方向移动)
101
- * @en Chebyshev distance (8-directional movement)
102
- */
103
- declare function chebyshevDistance(a: IPoint, b: IPoint): number;
104
- /**
105
- * @zh 八角距离(8方向移动,对角线代价为 √2)
106
- * @en Octile distance (8-directional, diagonal cost √2)
107
- */
108
- declare function octileDistance(a: IPoint, b: IPoint): number;
109
- /**
110
- * @zh 寻路配置
111
- * @en Pathfinding options
112
- */
113
- interface IPathfindingOptions {
114
- /** @zh 最大搜索节点数 @en Maximum nodes to search */
115
- maxNodes?: number;
116
- /** @zh 启发式权重 (>1 更快但可能非最优) @en Heuristic weight (>1 faster but may be suboptimal) */
117
- heuristicWeight?: number;
118
- /** @zh 是否允许对角移动 @en Allow diagonal movement */
119
- allowDiagonal?: boolean;
120
- /** @zh 是否避免穿角 @en Avoid corner cutting */
121
- avoidCorners?: boolean;
122
- }
123
- /**
124
- * @zh 默认寻路配置
125
- * @en Default pathfinding options
126
- */
127
- declare const DEFAULT_PATHFINDING_OPTIONS: Required<IPathfindingOptions>;
128
- /**
129
- * @zh 寻路器接口
130
- * @en Pathfinder interface
131
- */
132
- interface IPathfinder {
40
+ pop(): T | undefined;
133
41
  /**
134
- * @zh 查找路径
135
- * @en Find path
42
+ * @zh 查看最小元素(不移除)
43
+ * @en Peek minimum element (without removing)
136
44
  */
137
- findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
45
+ peek(): T | undefined;
138
46
  /**
139
- * @zh 清理状态(用于重用)
140
- * @en Clear state (for reuse)
47
+ * @zh 更新元素(重新排序)
48
+ * @en Update element (re-sort)
49
+ */
50
+ update(item: T): void;
51
+ /**
52
+ * @zh 检查是否包含元素
53
+ * @en Check if contains element
54
+ */
55
+ contains(item: T): boolean;
56
+ /**
57
+ * @zh 清空堆
58
+ * @en Clear heap
141
59
  */
142
60
  clear(): void;
143
- }
144
- /**
145
- * @zh 路径平滑器接口
146
- * @en Path smoother interface
147
- */
148
- interface IPathSmoother {
149
61
  /**
150
- * @zh 平滑路径
151
- * @en Smooth path
62
+ * @zh 上浮操作
63
+ * @en Bubble up operation
152
64
  */
153
- smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
65
+ private bubbleUp;
66
+ /**
67
+ * @zh 下沉操作
68
+ * @en Sink down operation
69
+ */
70
+ private sinkDown;
154
71
  }
72
+
155
73
  /**
156
- * @zh 视线检测函数类型
157
- * @en Line of sight check function type
74
+ * @zh 带索引追踪的二叉堆(优先队列)
75
+ * @en Indexed Binary Heap (Priority Queue) with index tracking
158
76
  */
159
- type LineOfSightCheck = (x1: number, y1: number, x2: number, y2: number, map: IPathfindingMap) => boolean;
160
-
161
77
  /**
162
- * @zh 二叉堆(优先队列)
163
- * @en Binary Heap (Priority Queue)
164
- *
165
- * @zh 用于 A* 算法的高效开放列表
166
- * @en Efficient open list for A* algorithm
78
+ * @zh 可索引的堆元素接口
79
+ * @en Interface for indexable heap elements
167
80
  */
168
- declare class BinaryHeap<T> {
81
+ interface IHeapIndexable {
82
+ /** @zh 堆中的索引位置 @en Index position in heap */
83
+ heapIndex: number;
84
+ }
85
+ /**
86
+ * @zh 带索引追踪的二叉堆
87
+ * @en Binary Heap with index tracking
88
+ */
89
+ declare class IndexedBinaryHeap<T extends IHeapIndexable> {
169
90
  private heap;
170
91
  private readonly compare;
171
92
  /**
172
- * @zh 创建二叉堆
173
- * @en Create binary heap
93
+ * @zh 创建带索引追踪的二叉堆
94
+ * @en Create indexed binary heap
174
95
  *
175
96
  * @param compare - @zh 比较函数,返回负数表示 a < b @en Compare function, returns negative if a < b
176
97
  */
@@ -201,8 +122,8 @@ declare class BinaryHeap<T> {
201
122
  */
202
123
  peek(): T | undefined;
203
124
  /**
204
- * @zh 更新元素(重新排序)
205
- * @en Update element (re-sort)
125
+ * @zh 更新元素
126
+ * @en Update element
206
127
  */
207
128
  update(item: T): void;
208
129
  /**
@@ -210,6 +131,11 @@ declare class BinaryHeap<T> {
210
131
  * @en Check if contains element
211
132
  */
212
133
  contains(item: T): boolean;
134
+ /**
135
+ * @zh 从堆中移除指定元素
136
+ * @en Remove specific element from heap
137
+ */
138
+ remove(item: T): boolean;
213
139
  /**
214
140
  * @zh 清空堆
215
141
  * @en Clear heap
@@ -291,13 +217,13 @@ declare function createAStarPathfinder(map: IPathfindingMap): AStarPathfinder;
291
217
  * @en Grid node
292
218
  */
293
219
  declare class GridNode implements IPathNode {
294
- readonly id: string;
220
+ readonly id: number;
295
221
  readonly position: IPoint;
296
222
  readonly x: number;
297
223
  readonly y: number;
298
224
  cost: number;
299
225
  walkable: boolean;
300
- constructor(x: number, y: number, walkable?: boolean, cost?: number);
226
+ constructor(x: number, y: number, width: number, walkable?: boolean, cost?: number);
301
227
  }
302
228
  /**
303
229
  * @zh 4方向偏移 (上下左右)
@@ -426,6 +352,11 @@ declare class GridMap implements IPathfindingMap {
426
352
  * @en Get neighbors of a node
427
353
  */
428
354
  getNeighbors(node: IPathNode): GridNode[];
355
+ /**
356
+ * @zh 遍历节点的邻居(零分配)
357
+ * @en Iterate over neighbors (zero allocation)
358
+ */
359
+ forEachNeighbor(node: IPathNode, callback: (neighbor: GridNode) => boolean | void): void;
429
360
  /**
430
361
  * @zh 计算启发式距离
431
362
  * @en Calculate heuristic distance
@@ -472,6 +403,811 @@ declare class GridMap implements IPathfindingMap {
472
403
  */
473
404
  declare function createGridMap(width: number, height: number, options?: IGridMapOptions): GridMap;
474
405
 
406
+ /**
407
+ * @zh 网格寻路器(统一实现)
408
+ * @en Grid Pathfinder (unified implementation)
409
+ */
410
+
411
+ /**
412
+ * @zh 寻路模式
413
+ * @en Pathfinding mode
414
+ */
415
+ type GridPathfinderMode = 'standard' | 'fast' | 'bidirectional';
416
+ /**
417
+ * @zh 网格寻路器配置
418
+ * @en Grid pathfinder configuration
419
+ */
420
+ interface IGridPathfinderConfig {
421
+ /**
422
+ * @zh 寻路模式
423
+ * @en Pathfinding mode
424
+ *
425
+ * - standard: 标准A*,适合小地图
426
+ * - fast: TypedArray优化,适合中大地图
427
+ * - bidirectional: 双向搜索,适合超大地图
428
+ */
429
+ mode?: GridPathfinderMode;
430
+ }
431
+ /**
432
+ * @zh 网格寻路器
433
+ * @en Grid Pathfinder
434
+ */
435
+ declare class GridPathfinder implements IPathfinder {
436
+ private readonly map;
437
+ private readonly mode;
438
+ private readonly state;
439
+ private readonly openList;
440
+ private readonly openListBack;
441
+ constructor(map: GridMap, config?: IGridPathfinderConfig);
442
+ findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
443
+ private findPathUnidirectional;
444
+ private findPathBidirectional;
445
+ private validate;
446
+ private buildPath;
447
+ private buildPathBidirectional;
448
+ clear(): void;
449
+ }
450
+ /**
451
+ * @zh 创建网格寻路器
452
+ * @en Create grid pathfinder
453
+ */
454
+ declare function createGridPathfinder(map: GridMap, config?: IGridPathfinderConfig): GridPathfinder;
455
+
456
+ /**
457
+ * @zh 路径缓存模块
458
+ * @en Path Cache Module
459
+ *
460
+ * @zh 缓存已计算的路径,避免重复计算相同起点终点的路径
461
+ * @en Cache computed paths to avoid recalculating paths with the same start and end points
462
+ */
463
+
464
+ /**
465
+ * @zh 缓存配置
466
+ * @en Cache configuration
467
+ */
468
+ interface IPathCacheConfig {
469
+ /**
470
+ * @zh 最大缓存条目数
471
+ * @en Maximum number of cache entries
472
+ */
473
+ maxEntries: number;
474
+ /**
475
+ * @zh 缓存过期时间(毫秒),0 表示不过期
476
+ * @en Cache expiration time in milliseconds, 0 means no expiration
477
+ */
478
+ ttlMs: number;
479
+ /**
480
+ * @zh 是否启用近似匹配(在一定范围内的起点/终点视为相同)
481
+ * @en Whether to enable approximate matching (start/end within range considered same)
482
+ */
483
+ enableApproximateMatch: boolean;
484
+ /**
485
+ * @zh 近似匹配范围
486
+ * @en Approximate matching range
487
+ */
488
+ approximateRange: number;
489
+ }
490
+ /**
491
+ * @zh 默认缓存配置
492
+ * @en Default cache configuration
493
+ */
494
+ declare const DEFAULT_PATH_CACHE_CONFIG: IPathCacheConfig;
495
+ /**
496
+ * @zh 路径缓存
497
+ * @en Path Cache
498
+ *
499
+ * @zh 缓存已计算的路径,支持 LRU 淘汰策略和 TTL 过期
500
+ * @en Cache computed paths with LRU eviction and TTL expiration
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * const cache = new PathCache({ maxEntries: 500 });
505
+ * const cached = cache.get(0, 0, 10, 10, mapVersion);
506
+ * if (!cached) {
507
+ * const result = pathfinder.findPath(0, 0, 10, 10);
508
+ * cache.set(0, 0, 10, 10, result, mapVersion);
509
+ * }
510
+ * ```
511
+ */
512
+ declare class PathCache {
513
+ private readonly config;
514
+ private readonly cache;
515
+ private readonly accessOrder;
516
+ constructor(config?: Partial<IPathCacheConfig>);
517
+ /**
518
+ * @zh 获取缓存的路径
519
+ * @en Get cached path
520
+ *
521
+ * @param startX - @zh 起点 X 坐标 @en Start X coordinate
522
+ * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
523
+ * @param endX - @zh 终点 X 坐标 @en End X coordinate
524
+ * @param endY - @zh 终点 Y 坐标 @en End Y coordinate
525
+ * @param mapVersion - @zh 地图版本号 @en Map version number
526
+ * @returns @zh 缓存的路径结果或 null @en Cached path result or null
527
+ */
528
+ get(startX: number, startY: number, endX: number, endY: number, mapVersion: number): IPathResult | null;
529
+ /**
530
+ * @zh 设置缓存路径
531
+ * @en Set cached path
532
+ *
533
+ * @param startX - @zh 起点 X 坐标 @en Start X coordinate
534
+ * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
535
+ * @param endX - @zh 终点 X 坐标 @en End X coordinate
536
+ * @param endY - @zh 终点 Y 坐标 @en End Y coordinate
537
+ * @param result - @zh 路径结果 @en Path result
538
+ * @param mapVersion - @zh 地图版本号 @en Map version number
539
+ */
540
+ set(startX: number, startY: number, endX: number, endY: number, result: IPathResult, mapVersion: number): void;
541
+ /**
542
+ * @zh 使所有缓存失效
543
+ * @en Invalidate all cache
544
+ */
545
+ invalidateAll(): void;
546
+ /**
547
+ * @zh 使指定区域的缓存失效
548
+ * @en Invalidate cache for specified region
549
+ *
550
+ * @param minX - @zh 最小 X 坐标 @en Minimum X coordinate
551
+ * @param minY - @zh 最小 Y 坐标 @en Minimum Y coordinate
552
+ * @param maxX - @zh 最大 X 坐标 @en Maximum X coordinate
553
+ * @param maxY - @zh 最大 Y 坐标 @en Maximum Y coordinate
554
+ */
555
+ invalidateRegion(minX: number, minY: number, maxX: number, maxY: number): void;
556
+ /**
557
+ * @zh 获取缓存统计信息
558
+ * @en Get cache statistics
559
+ */
560
+ getStats(): {
561
+ size: number;
562
+ maxSize: number;
563
+ hitRate?: number;
564
+ };
565
+ /**
566
+ * @zh 清理过期条目
567
+ * @en Clean up expired entries
568
+ */
569
+ cleanup(): void;
570
+ private generateKey;
571
+ private isValid;
572
+ private getApproximate;
573
+ private adjustPathForApproximate;
574
+ private updateAccessOrder;
575
+ private removeFromAccessOrder;
576
+ private evictLRU;
577
+ }
578
+ /**
579
+ * @zh 创建路径缓存
580
+ * @en Create path cache
581
+ *
582
+ * @param config - @zh 缓存配置 @en Cache configuration
583
+ * @returns @zh 路径缓存实例 @en Path cache instance
584
+ */
585
+ declare function createPathCache(config?: Partial<IPathCacheConfig>): PathCache;
586
+
587
+ /**
588
+ * @zh 增量 A* 寻路算法实现
589
+ * @en Incremental A* Pathfinding Algorithm Implementation
590
+ */
591
+
592
+ /**
593
+ * @zh 增量寻路器配置
594
+ * @en Incremental pathfinder configuration
595
+ */
596
+ interface IIncrementalPathfinderConfig {
597
+ /**
598
+ * @zh 是否启用路径缓存
599
+ * @en Whether to enable path caching
600
+ */
601
+ enableCache?: boolean;
602
+ /**
603
+ * @zh 缓存配置
604
+ * @en Cache configuration
605
+ */
606
+ cacheConfig?: Partial<IPathCacheConfig>;
607
+ }
608
+ /**
609
+ * @zh 增量 A* 寻路器
610
+ * @en Incremental A* Pathfinder
611
+ *
612
+ * @zh 支持时间切片的 A* 算法实现,可跨多帧执行搜索
613
+ * @en A* algorithm implementation with time slicing, can execute search across multiple frames
614
+ *
615
+ * @example
616
+ * ```typescript
617
+ * const map = createGridMap(100, 100);
618
+ * const pathfinder = createIncrementalAStarPathfinder(map);
619
+ *
620
+ * // Request path (non-blocking)
621
+ * const request = pathfinder.requestPath(0, 0, 99, 99);
622
+ *
623
+ * // Process over multiple frames
624
+ * function gameLoop() {
625
+ * const progress = pathfinder.step(request.id, 100);
626
+ *
627
+ * if (progress.state === PathfindingState.Completed) {
628
+ * const result = pathfinder.getResult(request.id);
629
+ * console.log('Path found:', result?.path);
630
+ * } else if (progress.state === PathfindingState.InProgress) {
631
+ * requestAnimationFrame(gameLoop);
632
+ * }
633
+ * }
634
+ * gameLoop();
635
+ * ```
636
+ */
637
+ declare class IncrementalAStarPathfinder implements IIncrementalPathfinder {
638
+ private readonly map;
639
+ private readonly sessions;
640
+ private nextRequestId;
641
+ private readonly affectedRegions;
642
+ private readonly maxRegionAge;
643
+ private readonly cache;
644
+ private readonly enableCache;
645
+ private mapVersion;
646
+ private cacheHits;
647
+ private cacheMisses;
648
+ /**
649
+ * @zh 创建增量 A* 寻路器
650
+ * @en Create incremental A* pathfinder
651
+ *
652
+ * @param map - @zh 寻路地图实例 @en Pathfinding map instance
653
+ * @param config - @zh 配置选项 @en Configuration options
654
+ */
655
+ constructor(map: IPathfindingMap, config?: IIncrementalPathfinderConfig);
656
+ /**
657
+ * @zh 请求寻路(非阻塞)
658
+ * @en Request pathfinding (non-blocking)
659
+ */
660
+ requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
661
+ /**
662
+ * @zh 执行一步搜索
663
+ * @en Execute one step of search
664
+ */
665
+ step(requestId: number, maxIterations: number): IPathProgress;
666
+ /**
667
+ * @zh 暂停寻路
668
+ * @en Pause pathfinding
669
+ */
670
+ pause(requestId: number): void;
671
+ /**
672
+ * @zh 恢复寻路
673
+ * @en Resume pathfinding
674
+ */
675
+ resume(requestId: number): void;
676
+ /**
677
+ * @zh 取消寻路
678
+ * @en Cancel pathfinding
679
+ */
680
+ cancel(requestId: number): void;
681
+ /**
682
+ * @zh 获取寻路结果
683
+ * @en Get pathfinding result
684
+ */
685
+ getResult(requestId: number): IIncrementalPathResult | null;
686
+ /**
687
+ * @zh 获取当前进度
688
+ * @en Get current progress
689
+ */
690
+ getProgress(requestId: number): IPathProgress | null;
691
+ /**
692
+ * @zh 清理已完成的请求
693
+ * @en Clean up completed request
694
+ */
695
+ cleanup(requestId: number): void;
696
+ /**
697
+ * @zh 通知障碍物变化
698
+ * @en Notify obstacle change
699
+ */
700
+ notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
701
+ /**
702
+ * @zh 清理所有请求
703
+ * @en Clear all requests
704
+ */
705
+ clear(): void;
706
+ /**
707
+ * @zh 清空路径缓存
708
+ * @en Clear path cache
709
+ */
710
+ clearCache(): void;
711
+ /**
712
+ * @zh 获取缓存统计信息
713
+ * @en Get cache statistics
714
+ */
715
+ getCacheStats(): {
716
+ enabled: boolean;
717
+ hits: number;
718
+ misses: number;
719
+ hitRate: number;
720
+ size: number;
721
+ };
722
+ /**
723
+ * @zh 检查会话是否被障碍物变化影响
724
+ * @en Check if session is affected by obstacle change
725
+ */
726
+ isAffectedByChange(requestId: number): boolean;
727
+ /**
728
+ * @zh 清除会话的变化标记
729
+ * @en Clear session's change flag
730
+ */
731
+ clearChangeFlag(requestId: number): void;
732
+ /**
733
+ * @zh 展开邻居节点
734
+ * @en Expand neighbor nodes
735
+ */
736
+ private expandNeighbors;
737
+ /**
738
+ * @zh 创建进度对象
739
+ * @en Create progress object
740
+ */
741
+ private createProgress;
742
+ /**
743
+ * @zh 构建路径结果
744
+ * @en Build path result
745
+ */
746
+ private buildResult;
747
+ /**
748
+ * @zh 创建空结果
749
+ * @en Create empty result
750
+ */
751
+ private createEmptyResult;
752
+ /**
753
+ * @zh 检查会话是否被区域影响
754
+ * @en Check if session is affected by region
755
+ */
756
+ private sessionAffectedByRegion;
757
+ /**
758
+ * @zh 清理过期的变化区域
759
+ * @en Clean up expired change regions
760
+ */
761
+ private cleanupOldRegions;
762
+ }
763
+ /**
764
+ * @zh 创建增量 A* 寻路器
765
+ * @en Create incremental A* pathfinder
766
+ *
767
+ * @param map - @zh 寻路地图实例 @en Pathfinding map instance
768
+ * @returns @zh 增量 A* 寻路器实例 @en Incremental A* pathfinder instance
769
+ */
770
+ declare function createIncrementalAStarPathfinder(map: IPathfindingMap): IncrementalAStarPathfinder;
771
+
772
+ /**
773
+ * @zh 路径验证器
774
+ * @en Path Validator
775
+ */
776
+
777
+ /**
778
+ * @zh 路径验证器
779
+ * @en Path Validator
780
+ *
781
+ * @zh 用于检查现有路径在地图变化后是否仍然有效
782
+ * @en Used to check if an existing path is still valid after map changes
783
+ *
784
+ * @example
785
+ * ```typescript
786
+ * const validator = new PathValidator();
787
+ * const result = validator.validatePath(path, 0, path.length, map);
788
+ *
789
+ * if (!result.valid) {
790
+ * console.log('Path invalid at index:', result.invalidIndex);
791
+ * // Trigger replanning from current position
792
+ * }
793
+ * ```
794
+ */
795
+ declare class PathValidator implements IPathValidator {
796
+ /**
797
+ * @zh 验证路径段的有效性
798
+ * @en Validate path segment validity
799
+ *
800
+ * @param path - @zh 要验证的路径 @en Path to validate
801
+ * @param fromIndex - @zh 起始索引 @en Start index
802
+ * @param toIndex - @zh 结束索引 @en End index
803
+ * @param map - @zh 地图实例 @en Map instance
804
+ * @returns @zh 验证结果 @en Validation result
805
+ */
806
+ validatePath(path: readonly IPoint[], fromIndex: number, toIndex: number, map: IPathfindingMap): IPathValidationResult;
807
+ /**
808
+ * @zh 检查两点之间的视线(使用 Bresenham 算法)
809
+ * @en Check line of sight between two points (using Bresenham algorithm)
810
+ *
811
+ * @param x1 - @zh 起点 X @en Start X
812
+ * @param y1 - @zh 起点 Y @en Start Y
813
+ * @param x2 - @zh 终点 X @en End X
814
+ * @param y2 - @zh 终点 Y @en End Y
815
+ * @param map - @zh 地图实例 @en Map instance
816
+ * @returns @zh 是否有视线 @en Whether there is line of sight
817
+ */
818
+ private checkLineOfSight;
819
+ }
820
+ /**
821
+ * @zh 障碍物变化记录
822
+ * @en Obstacle change record
823
+ */
824
+ interface IObstacleChange {
825
+ /**
826
+ * @zh X 坐标
827
+ * @en X coordinate
828
+ */
829
+ readonly x: number;
830
+ /**
831
+ * @zh Y 坐标
832
+ * @en Y coordinate
833
+ */
834
+ readonly y: number;
835
+ /**
836
+ * @zh 变化前是否可通行
837
+ * @en Was walkable before change
838
+ */
839
+ readonly wasWalkable: boolean;
840
+ /**
841
+ * @zh 变化时间戳
842
+ * @en Change timestamp
843
+ */
844
+ readonly timestamp: number;
845
+ }
846
+ /**
847
+ * @zh 障碍物变化区域
848
+ * @en Obstacle change region
849
+ */
850
+ interface IChangeRegion {
851
+ /**
852
+ * @zh 最小 X 坐标
853
+ * @en Minimum X coordinate
854
+ */
855
+ readonly minX: number;
856
+ /**
857
+ * @zh 最小 Y 坐标
858
+ * @en Minimum Y coordinate
859
+ */
860
+ readonly minY: number;
861
+ /**
862
+ * @zh 最大 X 坐标
863
+ * @en Maximum X coordinate
864
+ */
865
+ readonly maxX: number;
866
+ /**
867
+ * @zh 最大 Y 坐标
868
+ * @en Maximum Y coordinate
869
+ */
870
+ readonly maxY: number;
871
+ }
872
+ /**
873
+ * @zh 障碍物变化管理器
874
+ * @en Obstacle Change Manager
875
+ *
876
+ * @zh 跟踪地图障碍物变化,用于触发动态重规划
877
+ * @en Tracks map obstacle changes, used to trigger dynamic replanning
878
+ *
879
+ * @example
880
+ * ```typescript
881
+ * const manager = new ObstacleChangeManager();
882
+ *
883
+ * // Record change when obstacle is added/removed
884
+ * manager.recordChange(10, 20, true); // Was walkable, now blocked
885
+ *
886
+ * // Get affected region for notification
887
+ * const region = manager.getAffectedRegion();
888
+ * if (region) {
889
+ * pathfinder.notifyObstacleChange(
890
+ * region.minX, region.minY,
891
+ * region.maxX, region.maxY
892
+ * );
893
+ * }
894
+ *
895
+ * // Clear after notification
896
+ * manager.flush();
897
+ * ```
898
+ */
899
+ declare class ObstacleChangeManager {
900
+ private readonly changes;
901
+ private epoch;
902
+ /**
903
+ * @zh 记录障碍物变化
904
+ * @en Record obstacle change
905
+ *
906
+ * @param x - @zh X 坐标 @en X coordinate
907
+ * @param y - @zh Y 坐标 @en Y coordinate
908
+ * @param wasWalkable - @zh 变化前是否可通行 @en Was walkable before change
909
+ */
910
+ recordChange(x: number, y: number, wasWalkable: boolean): void;
911
+ /**
912
+ * @zh 获取影响区域
913
+ * @en Get affected region
914
+ *
915
+ * @returns @zh 影响区域或 null(如果没有变化)@en Affected region or null if no changes
916
+ */
917
+ getAffectedRegion(): IChangeRegion | null;
918
+ /**
919
+ * @zh 获取所有变化
920
+ * @en Get all changes
921
+ *
922
+ * @returns @zh 变化列表 @en List of changes
923
+ */
924
+ getChanges(): IObstacleChange[];
925
+ /**
926
+ * @zh 检查是否有变化
927
+ * @en Check if there are changes
928
+ *
929
+ * @returns @zh 是否有变化 @en Whether there are changes
930
+ */
931
+ hasChanges(): boolean;
932
+ /**
933
+ * @zh 获取当前 epoch
934
+ * @en Get current epoch
935
+ *
936
+ * @returns @zh 当前 epoch @en Current epoch
937
+ */
938
+ getEpoch(): number;
939
+ /**
940
+ * @zh 清空变化记录并推进 epoch
941
+ * @en Clear changes and advance epoch
942
+ */
943
+ flush(): void;
944
+ /**
945
+ * @zh 清空所有状态
946
+ * @en Clear all state
947
+ */
948
+ clear(): void;
949
+ }
950
+ /**
951
+ * @zh 创建路径验证器
952
+ * @en Create path validator
953
+ *
954
+ * @returns @zh 路径验证器实例 @en Path validator instance
955
+ */
956
+ declare function createPathValidator(): PathValidator;
957
+ /**
958
+ * @zh 创建障碍物变化管理器
959
+ * @en Create obstacle change manager
960
+ *
961
+ * @returns @zh 障碍物变化管理器实例 @en Obstacle change manager instance
962
+ */
963
+ declare function createObstacleChangeManager(): ObstacleChangeManager;
964
+
965
+ /**
966
+ * @zh JPS (Jump Point Search) 寻路算法实现
967
+ * @en JPS (Jump Point Search) Pathfinding Algorithm Implementation
968
+ *
969
+ * @zh JPS 是 A* 的优化版本,通过跳跃点剪枝大幅提升开放地形的搜索效率
970
+ * @en JPS is an optimized version of A* that significantly improves search efficiency on open terrain through jump point pruning
971
+ */
972
+
973
+ /**
974
+ * @zh JPS 寻路器
975
+ * @en JPS Pathfinder
976
+ *
977
+ * @zh 适用于均匀代价网格地图,在开放地形上比标准 A* 快 10-100 倍
978
+ * @en Suitable for uniform cost grid maps, 10-100x faster than standard A* on open terrain
979
+ *
980
+ * @example
981
+ * ```typescript
982
+ * const map = createGridMap(100, 100);
983
+ * const pathfinder = new JPSPathfinder(map);
984
+ * const result = pathfinder.findPath(0, 0, 99, 99);
985
+ * ```
986
+ */
987
+ declare class JPSPathfinder implements IPathfinder {
988
+ private readonly map;
989
+ private readonly width;
990
+ private readonly height;
991
+ private openList;
992
+ private nodeGrid;
993
+ constructor(map: IPathfindingMap);
994
+ /**
995
+ * @zh 寻找路径
996
+ * @en Find path
997
+ */
998
+ findPath(startX: number, startY: number, endX: number, endY: number, options?: Partial<IPathfindingOptions>): IPathResult;
999
+ /**
1000
+ * @zh 清理状态
1001
+ * @en Clear state
1002
+ */
1003
+ clear(): void;
1004
+ /**
1005
+ * @zh 获取地图边界
1006
+ * @en Get map bounds
1007
+ */
1008
+ private getMapBounds;
1009
+ /**
1010
+ * @zh 初始化节点网格
1011
+ * @en Initialize node grid
1012
+ */
1013
+ private initGrid;
1014
+ /**
1015
+ * @zh 获取或创建节点
1016
+ * @en Get or create node
1017
+ */
1018
+ private getOrCreateNode;
1019
+ /**
1020
+ * @zh 启发式函数(八方向距离)
1021
+ * @en Heuristic function (octile distance)
1022
+ */
1023
+ private heuristic;
1024
+ /**
1025
+ * @zh 识别后继节点(跳跃点)
1026
+ * @en Identify successors (jump points)
1027
+ */
1028
+ private identifySuccessors;
1029
+ /**
1030
+ * @zh 查找邻居(根据父节点方向剪枝)
1031
+ * @en Find neighbors (pruned based on parent direction)
1032
+ */
1033
+ private findNeighbors;
1034
+ /**
1035
+ * @zh 跳跃函数(迭代版本,避免递归开销)
1036
+ * @en Jump function (iterative version to avoid recursion overhead)
1037
+ */
1038
+ private jump;
1039
+ /**
1040
+ * @zh 直线跳跃(水平或垂直方向)
1041
+ * @en Straight jump (horizontal or vertical direction)
1042
+ */
1043
+ private jumpStraight;
1044
+ /**
1045
+ * @zh 检查位置是否可通行
1046
+ * @en Check if position is walkable
1047
+ */
1048
+ private isWalkableAt;
1049
+ /**
1050
+ * @zh 构建路径
1051
+ * @en Build path
1052
+ */
1053
+ private buildPath;
1054
+ /**
1055
+ * @zh 插值路径(在跳跃点之间填充中间点)
1056
+ * @en Interpolate path (fill intermediate points between jump points)
1057
+ */
1058
+ private interpolatePath;
1059
+ }
1060
+ /**
1061
+ * @zh 创建 JPS 寻路器
1062
+ * @en Create JPS pathfinder
1063
+ *
1064
+ * @param map - @zh 寻路地图实例 @en Pathfinding map instance
1065
+ * @returns @zh JPS 寻路器实例 @en JPS pathfinder instance
1066
+ */
1067
+ declare function createJPSPathfinder(map: IPathfindingMap): JPSPathfinder;
1068
+
1069
+ /**
1070
+ * @zh HPA* (Hierarchical Pathfinding A*) 寻路算法实现
1071
+ * @en HPA* (Hierarchical Pathfinding A*) Pathfinding Algorithm Implementation
1072
+ *
1073
+ * @zh HPA* 是一种分层寻路算法,适用于超大地图 (1000x1000+)
1074
+ * @en HPA* is a hierarchical pathfinding algorithm suitable for very large maps (1000x1000+)
1075
+ *
1076
+ * @zh 工作原理:
1077
+ * 1. 将地图划分为集群 (clusters)
1078
+ * 2. 在集群边界检测入口点 (entrances)
1079
+ * 3. 构建抽象图 (abstract graph) 连接入口点
1080
+ * 4. 先在抽象图上寻路,再细化为详细路径
1081
+ *
1082
+ * @en How it works:
1083
+ * 1. Divide map into clusters
1084
+ * 2. Detect entrances at cluster boundaries
1085
+ * 3. Build abstract graph connecting entrances
1086
+ * 4. First find path on abstract graph, then refine to detailed path
1087
+ */
1088
+
1089
+ /**
1090
+ * @zh HPA* 配置
1091
+ * @en HPA* Configuration
1092
+ */
1093
+ interface IHPAConfig {
1094
+ /**
1095
+ * @zh 集群大小(边长)
1096
+ * @en Cluster size (side length)
1097
+ */
1098
+ clusterSize: number;
1099
+ /**
1100
+ * @zh 最大入口宽度(超过此宽度会拆分为多个入口)
1101
+ * @en Maximum entrance width (entrances wider than this will be split)
1102
+ */
1103
+ maxEntranceWidth: number;
1104
+ /**
1105
+ * @zh 是否启用内部路径缓存
1106
+ * @en Whether to enable internal path caching
1107
+ */
1108
+ cacheInternalPaths: boolean;
1109
+ }
1110
+ /**
1111
+ * @zh 默认 HPA* 配置
1112
+ * @en Default HPA* configuration
1113
+ */
1114
+ declare const DEFAULT_HPA_CONFIG: IHPAConfig;
1115
+ /**
1116
+ * @zh HPA* 寻路器
1117
+ * @en HPA* Pathfinder
1118
+ *
1119
+ * @zh 适用于超大地图的分层寻路算法
1120
+ * @en Hierarchical pathfinding algorithm for very large maps
1121
+ *
1122
+ * @example
1123
+ * ```typescript
1124
+ * const map = createGridMap(1000, 1000);
1125
+ * const pathfinder = new HPAPathfinder(map, { clusterSize: 20 });
1126
+ *
1127
+ * // Preprocess (do once after map changes)
1128
+ * pathfinder.preprocess();
1129
+ *
1130
+ * // Find path
1131
+ * const result = pathfinder.findPath(0, 0, 999, 999);
1132
+ * ```
1133
+ */
1134
+ declare class HPAPathfinder implements IPathfinder {
1135
+ private readonly map;
1136
+ private readonly config;
1137
+ private readonly width;
1138
+ private readonly height;
1139
+ private clusters;
1140
+ private entrances;
1141
+ private abstractNodes;
1142
+ private clusterGrid;
1143
+ private nextEntranceId;
1144
+ private nextNodeId;
1145
+ private internalPathCache;
1146
+ private localPathfinder;
1147
+ private preprocessed;
1148
+ constructor(map: IPathfindingMap, config?: Partial<IHPAConfig>);
1149
+ /**
1150
+ * @zh 预处理地图(构建抽象图)
1151
+ * @en Preprocess map (build abstract graph)
1152
+ *
1153
+ * @zh 在地图变化后需要重新调用
1154
+ * @en Need to call again after map changes
1155
+ */
1156
+ preprocess(): void;
1157
+ /**
1158
+ * @zh 寻找路径
1159
+ * @en Find path
1160
+ */
1161
+ findPath(startX: number, startY: number, endX: number, endY: number, options?: Partial<IPathfindingOptions>): IPathResult;
1162
+ /**
1163
+ * @zh 清理状态
1164
+ * @en Clear state
1165
+ */
1166
+ clear(): void;
1167
+ /**
1168
+ * @zh 通知地图区域变化
1169
+ * @en Notify map region change
1170
+ */
1171
+ notifyRegionChange(minX: number, minY: number, maxX: number, maxY: number): void;
1172
+ /**
1173
+ * @zh 获取预处理统计信息
1174
+ * @en Get preprocessing statistics
1175
+ */
1176
+ getStats(): {
1177
+ clusters: number;
1178
+ entrances: number;
1179
+ abstractNodes: number;
1180
+ cacheSize: number;
1181
+ };
1182
+ private getMapBounds;
1183
+ private buildClusters;
1184
+ private findEntrances;
1185
+ private findEntrancesBetween;
1186
+ private createEntrance;
1187
+ private buildAbstractGraph;
1188
+ private createAbstractNode;
1189
+ private connectIntraClusterNodes;
1190
+ private getClusterAt;
1191
+ private insertTemporaryNode;
1192
+ private removeTemporaryNodes;
1193
+ private searchAbstractGraph;
1194
+ private reconstructAbstractPath;
1195
+ private refinePath;
1196
+ private findLocalPath;
1197
+ private findInternalPath;
1198
+ private calculatePathCost;
1199
+ private heuristic;
1200
+ }
1201
+ /**
1202
+ * @zh 创建 HPA* 寻路器
1203
+ * @en Create HPA* pathfinder
1204
+ *
1205
+ * @param map - @zh 寻路地图实例 @en Pathfinding map instance
1206
+ * @param config - @zh HPA* 配置 @en HPA* configuration
1207
+ * @returns @zh HPA* 寻路器实例 @en HPA* pathfinder instance
1208
+ */
1209
+ declare function createHPAPathfinder(map: IPathfindingMap, config?: Partial<IHPAConfig>): HPAPathfinder;
1210
+
475
1211
  /**
476
1212
  * @zh 导航网格实现
477
1213
  * @en NavMesh Implementation
@@ -695,46 +1431,4 @@ declare function createCatmullRomSmoother(segments?: number, tension?: number):
695
1431
  */
696
1432
  declare function createCombinedSmoother(curveSegments?: number, tension?: number): CombinedSmoother;
697
1433
 
698
- /**
699
- * @zh 寻路系统蓝图节点
700
- * @en Pathfinding System Blueprint Nodes
701
- */
702
-
703
- declare const FindPathTemplate: BlueprintNodeTemplate;
704
- declare class FindPathExecutor implements INodeExecutor {
705
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
706
- }
707
- declare const FindPathSmoothTemplate: BlueprintNodeTemplate;
708
- declare class FindPathSmoothExecutor implements INodeExecutor {
709
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
710
- }
711
- declare const IsWalkableTemplate: BlueprintNodeTemplate;
712
- declare class IsWalkableExecutor implements INodeExecutor {
713
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
714
- }
715
- declare const GetPathLengthTemplate: BlueprintNodeTemplate;
716
- declare class GetPathLengthExecutor implements INodeExecutor {
717
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
718
- }
719
- declare const GetPathDistanceTemplate: BlueprintNodeTemplate;
720
- declare class GetPathDistanceExecutor implements INodeExecutor {
721
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
722
- }
723
- declare const GetPathPointTemplate: BlueprintNodeTemplate;
724
- declare class GetPathPointExecutor implements INodeExecutor {
725
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
726
- }
727
- declare const MoveAlongPathTemplate: BlueprintNodeTemplate;
728
- declare class MoveAlongPathExecutor implements INodeExecutor {
729
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
730
- }
731
- declare const HasLineOfSightTemplate: BlueprintNodeTemplate;
732
- declare class HasLineOfSightExecutor implements INodeExecutor {
733
- execute(node: BlueprintNode, context: unknown): ExecutionResult;
734
- }
735
- declare const PathfindingNodeDefinitions: {
736
- templates: BlueprintNodeTemplate[];
737
- executors: Map<string, INodeExecutor>;
738
- };
739
-
740
- export { AStarPathfinder, BinaryHeap, CatmullRomSmoother, CombinedSmoother, DEFAULT_GRID_OPTIONS, DEFAULT_PATHFINDING_OPTIONS, DIRECTIONS_4, DIRECTIONS_8, EMPTY_PATH_RESULT, FindPathExecutor, FindPathSmoothExecutor, FindPathSmoothTemplate, FindPathTemplate, GetPathDistanceExecutor, GetPathDistanceTemplate, GetPathLengthExecutor, GetPathLengthTemplate, GetPathPointExecutor, GetPathPointTemplate, GridMap, GridNode, HasLineOfSightExecutor, HasLineOfSightTemplate, type HeuristicFunction, type IGridMapOptions, type INavPolygon, type IPathNode, type IPathResult, type IPathSmoother, type IPathfinder, type IPathfindingMap, type IPathfindingOptions, type IPoint, type IPortal, IsWalkableExecutor, IsWalkableTemplate, type LineOfSightCheck, LineOfSightSmoother, MoveAlongPathExecutor, MoveAlongPathTemplate, NavMesh, PathfindingNodeDefinitions, bresenhamLineOfSight, chebyshevDistance, createAStarPathfinder, createCatmullRomSmoother, createCombinedSmoother, createGridMap, createLineOfSightSmoother, createNavMesh, createPoint, euclideanDistance, manhattanDistance, octileDistance, raycastLineOfSight };
1434
+ export { AStarPathfinder, BinaryHeap, CatmullRomSmoother, CombinedSmoother, DEFAULT_GRID_OPTIONS, DEFAULT_HPA_CONFIG, DEFAULT_PATH_CACHE_CONFIG, DIRECTIONS_4, DIRECTIONS_8, GridMap, GridNode, GridPathfinder, type GridPathfinderMode, HPAPathfinder, HeuristicFunction, type IChangeRegion, type IGridMapOptions, type IGridPathfinderConfig, type IHPAConfig, type IHeapIndexable, IIncrementalPathResult, IIncrementalPathfinder, type IIncrementalPathfinderConfig, IIncrementalPathfindingOptions, type INavPolygon, type IObstacleChange, type IPathCacheConfig, IPathNode, IPathProgress, IPathRequest, IPathResult, IPathSmoother, IPathValidationResult, IPathValidator, IPathfinder, IPathfindingMap, IPathfindingOptions, IPoint, type IPortal, IncrementalAStarPathfinder, IndexedBinaryHeap, JPSPathfinder, LineOfSightSmoother, NavMesh, ObstacleChangeManager, PathCache, PathValidator, bresenhamLineOfSight, createAStarPathfinder, createCatmullRomSmoother, createCombinedSmoother, createGridMap, createGridPathfinder, createHPAPathfinder, createIncrementalAStarPathfinder, createJPSPathfinder, createLineOfSightSmoother, createNavMesh, createObstacleChangeManager, createPathCache, createPathValidator, raycastLineOfSight };