@esengine/pathfinding 12.0.0 → 12.1.2
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/IIncrementalPathfinding-3qs7e_pO.d.ts +450 -0
- package/dist/chunk-GTFFYRZM.js +36 -0
- package/dist/chunk-GTFFYRZM.js.map +1 -0
- package/dist/chunk-TPT7Q3E3.js +1648 -0
- package/dist/chunk-TPT7Q3E3.js.map +1 -0
- package/dist/ecs.d.ts +503 -0
- package/dist/ecs.js +1033 -0
- package/dist/ecs.js.map +1 -0
- package/dist/index.d.ts +886 -192
- package/dist/index.js +1650 -1066
- package/dist/index.js.map +1 -1
- package/dist/nodes.d.ts +143 -0
- package/dist/nodes.js +1174 -0
- package/dist/nodes.js.map +1 -0
- package/package.json +21 -5
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @zh 寻路系统核心接口
|
|
3
|
+
* @en Pathfinding System Core Interfaces
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @zh 2D 坐标点
|
|
7
|
+
* @en 2D coordinate point
|
|
8
|
+
*/
|
|
9
|
+
interface IPoint {
|
|
10
|
+
readonly x: number;
|
|
11
|
+
readonly y: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @zh 创建点
|
|
15
|
+
* @en Create a point
|
|
16
|
+
*/
|
|
17
|
+
declare function createPoint(x: number, y: number): IPoint;
|
|
18
|
+
/**
|
|
19
|
+
* @zh 路径节点
|
|
20
|
+
* @en Path node
|
|
21
|
+
*/
|
|
22
|
+
interface IPathNode {
|
|
23
|
+
/** @zh 节点唯一标识 @en Unique node identifier */
|
|
24
|
+
readonly id: string | number;
|
|
25
|
+
/** @zh 节点位置 @en Node position */
|
|
26
|
+
readonly position: IPoint;
|
|
27
|
+
/** @zh 移动代价 @en Movement cost */
|
|
28
|
+
readonly cost: number;
|
|
29
|
+
/** @zh 是否可通行 @en Is walkable */
|
|
30
|
+
readonly walkable: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @zh 路径结果
|
|
34
|
+
* @en Path result
|
|
35
|
+
*/
|
|
36
|
+
interface IPathResult {
|
|
37
|
+
/** @zh 是否找到路径 @en Whether path was found */
|
|
38
|
+
readonly found: boolean;
|
|
39
|
+
/** @zh 路径点列表 @en List of path points */
|
|
40
|
+
readonly path: readonly IPoint[];
|
|
41
|
+
/** @zh 路径总代价 @en Total path cost */
|
|
42
|
+
readonly cost: number;
|
|
43
|
+
/** @zh 搜索的节点数 @en Number of nodes searched */
|
|
44
|
+
readonly nodesSearched: number;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @zh 空路径结果
|
|
48
|
+
* @en Empty path result
|
|
49
|
+
*/
|
|
50
|
+
declare const EMPTY_PATH_RESULT: IPathResult;
|
|
51
|
+
/**
|
|
52
|
+
* @zh 寻路地图接口
|
|
53
|
+
* @en Pathfinding map interface
|
|
54
|
+
*/
|
|
55
|
+
interface IPathfindingMap {
|
|
56
|
+
/**
|
|
57
|
+
* @zh 获取节点的邻居
|
|
58
|
+
* @en Get neighbors of a node
|
|
59
|
+
*/
|
|
60
|
+
getNeighbors(node: IPathNode): IPathNode[];
|
|
61
|
+
/**
|
|
62
|
+
* @zh 获取指定位置的节点
|
|
63
|
+
* @en Get node at position
|
|
64
|
+
*/
|
|
65
|
+
getNodeAt(x: number, y: number): IPathNode | null;
|
|
66
|
+
/**
|
|
67
|
+
* @zh 计算两点间的启发式距离
|
|
68
|
+
* @en Calculate heuristic distance between two points
|
|
69
|
+
*/
|
|
70
|
+
heuristic(a: IPoint, b: IPoint): number;
|
|
71
|
+
/**
|
|
72
|
+
* @zh 计算两个邻居节点间的移动代价
|
|
73
|
+
* @en Calculate movement cost between two neighbor nodes
|
|
74
|
+
*/
|
|
75
|
+
getMovementCost(from: IPathNode, to: IPathNode): number;
|
|
76
|
+
/**
|
|
77
|
+
* @zh 检查位置是否可通行
|
|
78
|
+
* @en Check if position is walkable
|
|
79
|
+
*/
|
|
80
|
+
isWalkable(x: number, y: number): boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @zh 启发式函数类型
|
|
84
|
+
* @en Heuristic function type
|
|
85
|
+
*/
|
|
86
|
+
type HeuristicFunction = (a: IPoint, b: IPoint) => number;
|
|
87
|
+
/**
|
|
88
|
+
* @zh 曼哈顿距离(4方向移动)
|
|
89
|
+
* @en Manhattan distance (4-directional movement)
|
|
90
|
+
*/
|
|
91
|
+
declare function manhattanDistance(a: IPoint, b: IPoint): number;
|
|
92
|
+
/**
|
|
93
|
+
* @zh 欧几里得距离(任意方向移动)
|
|
94
|
+
* @en Euclidean distance (any direction movement)
|
|
95
|
+
*/
|
|
96
|
+
declare function euclideanDistance(a: IPoint, b: IPoint): number;
|
|
97
|
+
/**
|
|
98
|
+
* @zh 切比雪夫距离(8方向移动)
|
|
99
|
+
* @en Chebyshev distance (8-directional movement)
|
|
100
|
+
*/
|
|
101
|
+
declare function chebyshevDistance(a: IPoint, b: IPoint): number;
|
|
102
|
+
/**
|
|
103
|
+
* @zh 八角距离(8方向移动,对角线代价为 √2)
|
|
104
|
+
* @en Octile distance (8-directional, diagonal cost √2)
|
|
105
|
+
*/
|
|
106
|
+
declare function octileDistance(a: IPoint, b: IPoint): number;
|
|
107
|
+
/**
|
|
108
|
+
* @zh 寻路配置
|
|
109
|
+
* @en Pathfinding options
|
|
110
|
+
*/
|
|
111
|
+
interface IPathfindingOptions {
|
|
112
|
+
/** @zh 最大搜索节点数 @en Maximum nodes to search */
|
|
113
|
+
maxNodes?: number;
|
|
114
|
+
/** @zh 启发式权重 (>1 更快但可能非最优) @en Heuristic weight (>1 faster but may be suboptimal) */
|
|
115
|
+
heuristicWeight?: number;
|
|
116
|
+
/** @zh 是否允许对角移动 @en Allow diagonal movement */
|
|
117
|
+
allowDiagonal?: boolean;
|
|
118
|
+
/** @zh 是否避免穿角 @en Avoid corner cutting */
|
|
119
|
+
avoidCorners?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @zh 默认寻路配置
|
|
123
|
+
* @en Default pathfinding options
|
|
124
|
+
*/
|
|
125
|
+
declare const DEFAULT_PATHFINDING_OPTIONS: Required<IPathfindingOptions>;
|
|
126
|
+
/**
|
|
127
|
+
* @zh 寻路器接口
|
|
128
|
+
* @en Pathfinder interface
|
|
129
|
+
*/
|
|
130
|
+
interface IPathfinder {
|
|
131
|
+
/**
|
|
132
|
+
* @zh 查找路径
|
|
133
|
+
* @en Find path
|
|
134
|
+
*/
|
|
135
|
+
findPath(startX: number, startY: number, endX: number, endY: number, options?: IPathfindingOptions): IPathResult;
|
|
136
|
+
/**
|
|
137
|
+
* @zh 清理状态(用于重用)
|
|
138
|
+
* @en Clear state (for reuse)
|
|
139
|
+
*/
|
|
140
|
+
clear(): void;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* @zh 路径平滑器接口
|
|
144
|
+
* @en Path smoother interface
|
|
145
|
+
*/
|
|
146
|
+
interface IPathSmoother {
|
|
147
|
+
/**
|
|
148
|
+
* @zh 平滑路径
|
|
149
|
+
* @en Smooth path
|
|
150
|
+
*/
|
|
151
|
+
smooth(path: readonly IPoint[], map: IPathfindingMap): IPoint[];
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* @zh 视线检测函数类型
|
|
155
|
+
* @en Line of sight check function type
|
|
156
|
+
*/
|
|
157
|
+
type LineOfSightCheck = (x1: number, y1: number, x2: number, y2: number, map: IPathfindingMap) => boolean;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @zh 增量寻路系统接口
|
|
161
|
+
* @en Incremental Pathfinding System Interfaces
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @zh 增量寻路状态
|
|
166
|
+
* @en Incremental pathfinding state
|
|
167
|
+
*/
|
|
168
|
+
declare enum PathfindingState {
|
|
169
|
+
/** @zh 空闲,等待请求 @en Idle, waiting for request */
|
|
170
|
+
Idle = "idle",
|
|
171
|
+
/** @zh 正在搜索中 @en Search in progress */
|
|
172
|
+
InProgress = "in_progress",
|
|
173
|
+
/** @zh 已暂停 @en Paused */
|
|
174
|
+
Paused = "paused",
|
|
175
|
+
/** @zh 搜索完成,找到路径 @en Completed, path found */
|
|
176
|
+
Completed = "completed",
|
|
177
|
+
/** @zh 搜索失败,无法找到路径 @en Failed, no path found */
|
|
178
|
+
Failed = "failed",
|
|
179
|
+
/** @zh 已取消 @en Cancelled */
|
|
180
|
+
Cancelled = "cancelled"
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* @zh 增量寻路请求
|
|
184
|
+
* @en Incremental pathfinding request
|
|
185
|
+
*/
|
|
186
|
+
interface IPathRequest {
|
|
187
|
+
/**
|
|
188
|
+
* @zh 请求唯一标识符
|
|
189
|
+
* @en Unique request identifier
|
|
190
|
+
*/
|
|
191
|
+
readonly id: number;
|
|
192
|
+
/**
|
|
193
|
+
* @zh 起点 X 坐标
|
|
194
|
+
* @en Start X coordinate
|
|
195
|
+
*/
|
|
196
|
+
readonly startX: number;
|
|
197
|
+
/**
|
|
198
|
+
* @zh 起点 Y 坐标
|
|
199
|
+
* @en Start Y coordinate
|
|
200
|
+
*/
|
|
201
|
+
readonly startY: number;
|
|
202
|
+
/**
|
|
203
|
+
* @zh 终点 X 坐标
|
|
204
|
+
* @en End X coordinate
|
|
205
|
+
*/
|
|
206
|
+
readonly endX: number;
|
|
207
|
+
/**
|
|
208
|
+
* @zh 终点 Y 坐标
|
|
209
|
+
* @en End Y coordinate
|
|
210
|
+
*/
|
|
211
|
+
readonly endY: number;
|
|
212
|
+
/**
|
|
213
|
+
* @zh 寻路配置选项
|
|
214
|
+
* @en Pathfinding options
|
|
215
|
+
*/
|
|
216
|
+
readonly options?: IPathfindingOptions;
|
|
217
|
+
/**
|
|
218
|
+
* @zh 优先级(数值越小优先级越高)
|
|
219
|
+
* @en Priority (lower number = higher priority)
|
|
220
|
+
*/
|
|
221
|
+
readonly priority: number;
|
|
222
|
+
/**
|
|
223
|
+
* @zh 创建时间戳
|
|
224
|
+
* @en Creation timestamp
|
|
225
|
+
*/
|
|
226
|
+
readonly createdAt: number;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* @zh 增量寻路进度
|
|
230
|
+
* @en Incremental pathfinding progress
|
|
231
|
+
*/
|
|
232
|
+
interface IPathProgress {
|
|
233
|
+
/**
|
|
234
|
+
* @zh 当前寻路状态
|
|
235
|
+
* @en Current pathfinding state
|
|
236
|
+
*/
|
|
237
|
+
readonly state: PathfindingState;
|
|
238
|
+
/**
|
|
239
|
+
* @zh 已搜索的节点数量
|
|
240
|
+
* @en Number of nodes searched
|
|
241
|
+
*/
|
|
242
|
+
readonly nodesSearched: number;
|
|
243
|
+
/**
|
|
244
|
+
* @zh 开放列表当前大小
|
|
245
|
+
* @en Current open list size
|
|
246
|
+
*/
|
|
247
|
+
readonly openListSize: number;
|
|
248
|
+
/**
|
|
249
|
+
* @zh 估计的搜索进度 (0-1)
|
|
250
|
+
* @en Estimated search progress (0-1)
|
|
251
|
+
*/
|
|
252
|
+
readonly estimatedProgress: number;
|
|
253
|
+
/**
|
|
254
|
+
* @zh 当前最佳部分路径(可选)
|
|
255
|
+
* @en Current best partial path (optional)
|
|
256
|
+
*/
|
|
257
|
+
readonly partialPath?: readonly IPoint[];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* @zh 增量寻路结果(扩展自 IPathResult)
|
|
261
|
+
* @en Incremental pathfinding result (extends IPathResult)
|
|
262
|
+
*/
|
|
263
|
+
interface IIncrementalPathResult extends IPathResult {
|
|
264
|
+
/**
|
|
265
|
+
* @zh 关联的请求 ID
|
|
266
|
+
* @en Associated request ID
|
|
267
|
+
*/
|
|
268
|
+
readonly requestId: number;
|
|
269
|
+
/**
|
|
270
|
+
* @zh 完成搜索所用的帧数
|
|
271
|
+
* @en Number of frames used to complete search
|
|
272
|
+
*/
|
|
273
|
+
readonly framesUsed: number;
|
|
274
|
+
/**
|
|
275
|
+
* @zh 是否为部分路径(未到达终点)
|
|
276
|
+
* @en Whether this is a partial path (not reaching goal)
|
|
277
|
+
*/
|
|
278
|
+
readonly isPartial: boolean;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* @zh 增量寻路请求选项
|
|
282
|
+
* @en Incremental pathfinding request options
|
|
283
|
+
*/
|
|
284
|
+
interface IIncrementalPathfindingOptions extends IPathfindingOptions {
|
|
285
|
+
/**
|
|
286
|
+
* @zh 优先级(数值越小优先级越高,默认 50)
|
|
287
|
+
* @en Priority (lower = higher, default 50)
|
|
288
|
+
*/
|
|
289
|
+
priority?: number;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* @zh 增量寻路器接口
|
|
293
|
+
* @en Incremental pathfinder interface
|
|
294
|
+
*
|
|
295
|
+
* @zh 支持时间切片的寻路器,可跨多帧执行搜索
|
|
296
|
+
* @en Pathfinder with time slicing support, can execute search across multiple frames
|
|
297
|
+
*/
|
|
298
|
+
interface IIncrementalPathfinder {
|
|
299
|
+
/**
|
|
300
|
+
* @zh 请求寻路(非阻塞)
|
|
301
|
+
* @en Request pathfinding (non-blocking)
|
|
302
|
+
*
|
|
303
|
+
* @param startX - @zh 起点 X 坐标 @en Start X coordinate
|
|
304
|
+
* @param startY - @zh 起点 Y 坐标 @en Start Y coordinate
|
|
305
|
+
* @param endX - @zh 终点 X 坐标 @en End X coordinate
|
|
306
|
+
* @param endY - @zh 终点 Y 坐标 @en End Y coordinate
|
|
307
|
+
* @param options - @zh 寻路选项 @en Pathfinding options
|
|
308
|
+
* @returns @zh 寻路请求对象 @en Path request object
|
|
309
|
+
*/
|
|
310
|
+
requestPath(startX: number, startY: number, endX: number, endY: number, options?: IIncrementalPathfindingOptions): IPathRequest;
|
|
311
|
+
/**
|
|
312
|
+
* @zh 执行一步搜索
|
|
313
|
+
* @en Execute one step of search
|
|
314
|
+
*
|
|
315
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
316
|
+
* @param maxIterations - @zh 本步最大迭代次数 @en Maximum iterations this step
|
|
317
|
+
* @returns @zh 当前进度 @en Current progress
|
|
318
|
+
*/
|
|
319
|
+
step(requestId: number, maxIterations: number): IPathProgress;
|
|
320
|
+
/**
|
|
321
|
+
* @zh 暂停寻路
|
|
322
|
+
* @en Pause pathfinding
|
|
323
|
+
*
|
|
324
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
325
|
+
*/
|
|
326
|
+
pause(requestId: number): void;
|
|
327
|
+
/**
|
|
328
|
+
* @zh 恢复寻路
|
|
329
|
+
* @en Resume pathfinding
|
|
330
|
+
*
|
|
331
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
332
|
+
*/
|
|
333
|
+
resume(requestId: number): void;
|
|
334
|
+
/**
|
|
335
|
+
* @zh 取消寻路
|
|
336
|
+
* @en Cancel pathfinding
|
|
337
|
+
*
|
|
338
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
339
|
+
*/
|
|
340
|
+
cancel(requestId: number): void;
|
|
341
|
+
/**
|
|
342
|
+
* @zh 获取寻路结果(仅当状态为 Completed 或 Failed 时可用)
|
|
343
|
+
* @en Get pathfinding result (only available when state is Completed or Failed)
|
|
344
|
+
*
|
|
345
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
346
|
+
* @returns @zh 寻路结果或 null @en Path result or null
|
|
347
|
+
*/
|
|
348
|
+
getResult(requestId: number): IIncrementalPathResult | null;
|
|
349
|
+
/**
|
|
350
|
+
* @zh 获取当前进度
|
|
351
|
+
* @en Get current progress
|
|
352
|
+
*
|
|
353
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
354
|
+
* @returns @zh 当前进度或 null @en Current progress or null
|
|
355
|
+
*/
|
|
356
|
+
getProgress(requestId: number): IPathProgress | null;
|
|
357
|
+
/**
|
|
358
|
+
* @zh 清理已完成的请求(释放内存)
|
|
359
|
+
* @en Clean up completed request (release memory)
|
|
360
|
+
*
|
|
361
|
+
* @param requestId - @zh 请求 ID @en Request ID
|
|
362
|
+
*/
|
|
363
|
+
cleanup(requestId: number): void;
|
|
364
|
+
/**
|
|
365
|
+
* @zh 通知障碍物变化(用于动态重规划)
|
|
366
|
+
* @en Notify obstacle change (for dynamic replanning)
|
|
367
|
+
*
|
|
368
|
+
* @param minX - @zh 变化区域最小 X @en Changed area min X
|
|
369
|
+
* @param minY - @zh 变化区域最小 Y @en Changed area min Y
|
|
370
|
+
* @param maxX - @zh 变化区域最大 X @en Changed area max X
|
|
371
|
+
* @param maxY - @zh 变化区域最大 Y @en Changed area max Y
|
|
372
|
+
*/
|
|
373
|
+
notifyObstacleChange(minX: number, minY: number, maxX: number, maxY: number): void;
|
|
374
|
+
/**
|
|
375
|
+
* @zh 清理所有请求
|
|
376
|
+
* @en Clear all requests
|
|
377
|
+
*/
|
|
378
|
+
clear(): void;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* @zh 路径验证结果
|
|
382
|
+
* @en Path validation result
|
|
383
|
+
*/
|
|
384
|
+
interface IPathValidationResult {
|
|
385
|
+
/**
|
|
386
|
+
* @zh 路径是否有效
|
|
387
|
+
* @en Whether the path is valid
|
|
388
|
+
*/
|
|
389
|
+
readonly valid: boolean;
|
|
390
|
+
/**
|
|
391
|
+
* @zh 第一个无效点的索引(-1 表示全部有效)
|
|
392
|
+
* @en Index of first invalid point (-1 if all valid)
|
|
393
|
+
*/
|
|
394
|
+
readonly invalidIndex: number;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* @zh 路径验证器接口
|
|
398
|
+
* @en Path validator interface
|
|
399
|
+
*/
|
|
400
|
+
interface IPathValidator {
|
|
401
|
+
/**
|
|
402
|
+
* @zh 验证路径段的有效性
|
|
403
|
+
* @en Validate path segment validity
|
|
404
|
+
*
|
|
405
|
+
* @param path - @zh 要验证的路径 @en Path to validate
|
|
406
|
+
* @param fromIndex - @zh 起始索引 @en Start index
|
|
407
|
+
* @param toIndex - @zh 结束索引 @en End index
|
|
408
|
+
* @param map - @zh 地图实例 @en Map instance
|
|
409
|
+
* @returns @zh 验证结果 @en Validation result
|
|
410
|
+
*/
|
|
411
|
+
validatePath(path: readonly IPoint[], fromIndex: number, toIndex: number, map: IPathfindingMap): IPathValidationResult;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* @zh 动态重规划配置
|
|
415
|
+
* @en Dynamic replanning configuration
|
|
416
|
+
*/
|
|
417
|
+
interface IReplanningConfig {
|
|
418
|
+
/**
|
|
419
|
+
* @zh 是否启用动态重规划
|
|
420
|
+
* @en Whether dynamic replanning is enabled
|
|
421
|
+
*/
|
|
422
|
+
enabled: boolean;
|
|
423
|
+
/**
|
|
424
|
+
* @zh 路径检查间隔(帧数)
|
|
425
|
+
* @en Path check interval (in frames)
|
|
426
|
+
*/
|
|
427
|
+
checkInterval: number;
|
|
428
|
+
/**
|
|
429
|
+
* @zh 触发重规划的距离阈值
|
|
430
|
+
* @en Distance threshold to trigger replanning
|
|
431
|
+
*/
|
|
432
|
+
distanceThreshold: number;
|
|
433
|
+
/**
|
|
434
|
+
* @zh 向前探测的距离(路径点数)
|
|
435
|
+
* @en Lookahead distance (in path points)
|
|
436
|
+
*/
|
|
437
|
+
lookaheadDistance: number;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* @zh 默认重规划配置
|
|
441
|
+
* @en Default replanning configuration
|
|
442
|
+
*/
|
|
443
|
+
declare const DEFAULT_REPLANNING_CONFIG: IReplanningConfig;
|
|
444
|
+
/**
|
|
445
|
+
* @zh 空进度(用于无效请求)
|
|
446
|
+
* @en Empty progress (for invalid requests)
|
|
447
|
+
*/
|
|
448
|
+
declare const EMPTY_PROGRESS: IPathProgress;
|
|
449
|
+
|
|
450
|
+
export { DEFAULT_PATHFINDING_OPTIONS as D, EMPTY_PATH_RESULT as E, type HeuristicFunction as H, type IPathfinder as I, type LineOfSightCheck as L, PathfindingState as P, type IPathfindingMap as a, type IPathfindingOptions as b, type IPathResult as c, type IPathNode as d, type IPoint as e, type IIncrementalPathfinder as f, type IIncrementalPathfindingOptions as g, type IPathRequest as h, type IPathProgress as i, type IIncrementalPathResult as j, type IPathValidator as k, type IPathValidationResult as l, type IPathSmoother as m, createPoint as n, manhattanDistance as o, euclideanDistance as p, chebyshevDistance as q, octileDistance as r, type IReplanningConfig as s, DEFAULT_REPLANNING_CONFIG as t, EMPTY_PROGRESS as u };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
4
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
|
|
6
|
+
// src/core/IIncrementalPathfinding.ts
|
|
7
|
+
var PathfindingState = /* @__PURE__ */ (function(PathfindingState2) {
|
|
8
|
+
PathfindingState2["Idle"] = "idle";
|
|
9
|
+
PathfindingState2["InProgress"] = "in_progress";
|
|
10
|
+
PathfindingState2["Paused"] = "paused";
|
|
11
|
+
PathfindingState2["Completed"] = "completed";
|
|
12
|
+
PathfindingState2["Failed"] = "failed";
|
|
13
|
+
PathfindingState2["Cancelled"] = "cancelled";
|
|
14
|
+
return PathfindingState2;
|
|
15
|
+
})({});
|
|
16
|
+
var DEFAULT_REPLANNING_CONFIG = {
|
|
17
|
+
enabled: true,
|
|
18
|
+
checkInterval: 10,
|
|
19
|
+
distanceThreshold: 2,
|
|
20
|
+
lookaheadDistance: 5
|
|
21
|
+
};
|
|
22
|
+
var EMPTY_PROGRESS = {
|
|
23
|
+
state: "idle",
|
|
24
|
+
nodesSearched: 0,
|
|
25
|
+
openListSize: 0,
|
|
26
|
+
estimatedProgress: 0
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
__name,
|
|
31
|
+
__publicField,
|
|
32
|
+
PathfindingState,
|
|
33
|
+
DEFAULT_REPLANNING_CONFIG,
|
|
34
|
+
EMPTY_PROGRESS
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunk-GTFFYRZM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/IIncrementalPathfinding.ts"],"sourcesContent":["/**\n * @zh 增量寻路系统接口\n * @en Incremental Pathfinding System Interfaces\n */\n\nimport type { IPoint, IPathResult, IPathfindingOptions, IPathfindingMap } from './IPathfinding';\n\n// =============================================================================\n// 状态枚举 | State Enum\n// =============================================================================\n\n/**\n * @zh 增量寻路状态\n * @en Incremental pathfinding state\n */\nexport enum PathfindingState {\n /** @zh 空闲,等待请求 @en Idle, waiting for request */\n Idle = 'idle',\n /** @zh 正在搜索中 @en Search in progress */\n InProgress = 'in_progress',\n /** @zh 已暂停 @en Paused */\n Paused = 'paused',\n /** @zh 搜索完成,找到路径 @en Completed, path found */\n Completed = 'completed',\n /** @zh 搜索失败,无法找到路径 @en Failed, no path found */\n Failed = 'failed',\n /** @zh 已取消 @en Cancelled */\n Cancelled = 'cancelled'\n}\n\n// =============================================================================\n// 请求和进度接口 | Request and Progress Interfaces\n// =============================================================================\n\n/**\n * @zh 增量寻路请求\n * @en Incremental pathfinding request\n */\nexport interface IPathRequest {\n /**\n * @zh 请求唯一标识符\n * @en Unique request identifier\n */\n readonly id: number;\n\n /**\n * @zh 起点 X 坐标\n * @en Start X coordinate\n */\n readonly startX: number;\n\n /**\n * @zh 起点 Y 坐标\n * @en Start Y coordinate\n */\n readonly startY: number;\n\n /**\n * @zh 终点 X 坐标\n * @en End X coordinate\n */\n readonly endX: number;\n\n /**\n * @zh 终点 Y 坐标\n * @en End Y coordinate\n */\n readonly endY: number;\n\n /**\n * @zh 寻路配置选项\n * @en Pathfinding options\n */\n readonly options?: IPathfindingOptions;\n\n /**\n * @zh 优先级(数值越小优先级越高)\n * @en Priority (lower number = higher priority)\n */\n readonly priority: number;\n\n /**\n * @zh 创建时间戳\n * @en Creation timestamp\n */\n readonly createdAt: number;\n}\n\n/**\n * @zh 增量寻路进度\n * @en Incremental pathfinding progress\n */\nexport interface IPathProgress {\n /**\n * @zh 当前寻路状态\n * @en Current pathfinding state\n */\n readonly state: PathfindingState;\n\n /**\n * @zh 已搜索的节点数量\n * @en Number of nodes searched\n */\n readonly nodesSearched: number;\n\n /**\n * @zh 开放列表当前大小\n * @en Current open list size\n */\n readonly openListSize: number;\n\n /**\n * @zh 估计的搜索进度 (0-1)\n * @en Estimated search progress (0-1)\n */\n readonly estimatedProgress: number;\n\n /**\n * @zh 当前最佳部分路径(可选)\n * @en Current best partial path (optional)\n */\n readonly partialPath?: readonly IPoint[];\n}\n\n/**\n * @zh 增量寻路结果(扩展自 IPathResult)\n * @en Incremental pathfinding result (extends IPathResult)\n */\nexport interface IIncrementalPathResult extends IPathResult {\n /**\n * @zh 关联的请求 ID\n * @en Associated request ID\n */\n readonly requestId: number;\n\n /**\n * @zh 完成搜索所用的帧数\n * @en Number of frames used to complete search\n */\n readonly framesUsed: number;\n\n /**\n * @zh 是否为部分路径(未到达终点)\n * @en Whether this is a partial path (not reaching goal)\n */\n readonly isPartial: boolean;\n}\n\n// =============================================================================\n// 增量寻路器接口 | Incremental Pathfinder Interface\n// =============================================================================\n\n/**\n * @zh 增量寻路请求选项\n * @en Incremental pathfinding request options\n */\nexport interface IIncrementalPathfindingOptions extends IPathfindingOptions {\n /**\n * @zh 优先级(数值越小优先级越高,默认 50)\n * @en Priority (lower = higher, default 50)\n */\n priority?: number;\n}\n\n/**\n * @zh 增量寻路器接口\n * @en Incremental pathfinder interface\n *\n * @zh 支持时间切片的寻路器,可跨多帧执行搜索\n * @en Pathfinder with time slicing support, can execute search across multiple frames\n */\nexport interface IIncrementalPathfinder {\n /**\n * @zh 请求寻路(非阻塞)\n * @en Request pathfinding (non-blocking)\n *\n * @param startX - @zh 起点 X 坐标 @en Start X coordinate\n * @param startY - @zh 起点 Y 坐标 @en Start Y coordinate\n * @param endX - @zh 终点 X 坐标 @en End X coordinate\n * @param endY - @zh 终点 Y 坐标 @en End Y coordinate\n * @param options - @zh 寻路选项 @en Pathfinding options\n * @returns @zh 寻路请求对象 @en Path request object\n */\n requestPath(\n startX: number,\n startY: number,\n endX: number,\n endY: number,\n options?: IIncrementalPathfindingOptions\n ): IPathRequest;\n\n /**\n * @zh 执行一步搜索\n * @en Execute one step of search\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @param maxIterations - @zh 本步最大迭代次数 @en Maximum iterations this step\n * @returns @zh 当前进度 @en Current progress\n */\n step(requestId: number, maxIterations: number): IPathProgress;\n\n /**\n * @zh 暂停寻路\n * @en Pause pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n pause(requestId: number): void;\n\n /**\n * @zh 恢复寻路\n * @en Resume pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n resume(requestId: number): void;\n\n /**\n * @zh 取消寻路\n * @en Cancel pathfinding\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cancel(requestId: number): void;\n\n /**\n * @zh 获取寻路结果(仅当状态为 Completed 或 Failed 时可用)\n * @en Get pathfinding result (only available when state is Completed or Failed)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 寻路结果或 null @en Path result or null\n */\n getResult(requestId: number): IIncrementalPathResult | null;\n\n /**\n * @zh 获取当前进度\n * @en Get current progress\n *\n * @param requestId - @zh 请求 ID @en Request ID\n * @returns @zh 当前进度或 null @en Current progress or null\n */\n getProgress(requestId: number): IPathProgress | null;\n\n /**\n * @zh 清理已完成的请求(释放内存)\n * @en Clean up completed request (release memory)\n *\n * @param requestId - @zh 请求 ID @en Request ID\n */\n cleanup(requestId: number): void;\n\n /**\n * @zh 通知障碍物变化(用于动态重规划)\n * @en Notify obstacle change (for dynamic replanning)\n *\n * @param minX - @zh 变化区域最小 X @en Changed area min X\n * @param minY - @zh 变化区域最小 Y @en Changed area min Y\n * @param maxX - @zh 变化区域最大 X @en Changed area max X\n * @param maxY - @zh 变化区域最大 Y @en Changed area max Y\n */\n notifyObstacleChange(\n minX: number,\n minY: number,\n maxX: number,\n maxY: number\n ): void;\n\n /**\n * @zh 清理所有请求\n * @en Clear all requests\n */\n clear(): void;\n}\n\n// =============================================================================\n// 路径验证接口 | Path Validation Interface\n// =============================================================================\n\n/**\n * @zh 路径验证结果\n * @en Path validation result\n */\nexport interface IPathValidationResult {\n /**\n * @zh 路径是否有效\n * @en Whether the path is valid\n */\n readonly valid: boolean;\n\n /**\n * @zh 第一个无效点的索引(-1 表示全部有效)\n * @en Index of first invalid point (-1 if all valid)\n */\n readonly invalidIndex: number;\n}\n\n/**\n * @zh 路径验证器接口\n * @en Path validator interface\n */\nexport interface IPathValidator {\n /**\n * @zh 验证路径段的有效性\n * @en Validate path segment validity\n *\n * @param path - @zh 要验证的路径 @en Path to validate\n * @param fromIndex - @zh 起始索引 @en Start index\n * @param toIndex - @zh 结束索引 @en End index\n * @param map - @zh 地图实例 @en Map instance\n * @returns @zh 验证结果 @en Validation result\n */\n validatePath(\n path: readonly IPoint[],\n fromIndex: number,\n toIndex: number,\n map: IPathfindingMap\n ): IPathValidationResult;\n}\n\n// =============================================================================\n// 动态重规划配置 | Dynamic Replanning Configuration\n// =============================================================================\n\n/**\n * @zh 动态重规划配置\n * @en Dynamic replanning configuration\n */\nexport interface IReplanningConfig {\n /**\n * @zh 是否启用动态重规划\n * @en Whether dynamic replanning is enabled\n */\n enabled: boolean;\n\n /**\n * @zh 路径检查间隔(帧数)\n * @en Path check interval (in frames)\n */\n checkInterval: number;\n\n /**\n * @zh 触发重规划的距离阈值\n * @en Distance threshold to trigger replanning\n */\n distanceThreshold: number;\n\n /**\n * @zh 向前探测的距离(路径点数)\n * @en Lookahead distance (in path points)\n */\n lookaheadDistance: number;\n}\n\n/**\n * @zh 默认重规划配置\n * @en Default replanning configuration\n */\nexport const DEFAULT_REPLANNING_CONFIG: IReplanningConfig = {\n enabled: true,\n checkInterval: 10,\n distanceThreshold: 2,\n lookaheadDistance: 5\n};\n\n// =============================================================================\n// 空进度常量 | Empty Progress Constant\n// =============================================================================\n\n/**\n * @zh 空进度(用于无效请求)\n * @en Empty progress (for invalid requests)\n */\nexport const EMPTY_PROGRESS: IPathProgress = {\n state: PathfindingState.Idle,\n nodesSearched: 0,\n openListSize: 0,\n estimatedProgress: 0\n};\n"],"mappings":";;;;;;AAeO,IAAKA,mBAAAA,0BAAAA,mBAAAA;AACsC,EAAAA,kBAAA,MAAA,IAAA;AAET,EAAAA,kBAAA,YAAA,IAAA;AAEd,EAAAA,kBAAA,QAAA,IAAA;AAEqB,EAAAA,kBAAA,WAAA,IAAA;AAEE,EAAAA,kBAAA,QAAA,IAAA;AAEpB,EAAAA,kBAAA,WAAA,IAAA;SAXlBA;;AAsVL,IAAMC,4BAA+C;EACxDC,SAAS;EACTC,eAAe;EACfC,mBAAmB;EACnBC,mBAAmB;AACvB;AAUO,IAAMC,iBAAgC;EACzCC,OAAK;EACLC,eAAe;EACfC,cAAc;EACdC,mBAAmB;AACvB;","names":["PathfindingState","DEFAULT_REPLANNING_CONFIG","enabled","checkInterval","distanceThreshold","lookaheadDistance","EMPTY_PROGRESS","state","nodesSearched","openListSize","estimatedProgress"]}
|