@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/ecs.d.ts ADDED
@@ -0,0 +1,503 @@
1
+ import { Component, EntitySystem, Entity } from '@esengine/ecs-framework';
2
+ import { P as PathfindingState, e as IPoint, a as IPathfindingMap, f as IIncrementalPathfinder, m as IPathSmoother } from './IIncrementalPathfinding-3qs7e_pO.js';
3
+
4
+ /**
5
+ * @zh 寻路代理组件
6
+ * @en Pathfinding Agent Component
7
+ */
8
+
9
+ /**
10
+ * @zh 寻路代理组件
11
+ * @en Pathfinding Agent Component
12
+ *
13
+ * @zh 附加到需要寻路的实体上,管理寻路请求和结果
14
+ * @en Attach to entities that need pathfinding, manages path requests and results
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * const entity = scene.createEntity('Agent');
19
+ * const agent = entity.addComponent(new PathfindingAgentComponent());
20
+ *
21
+ * // Set initial position
22
+ * agent.x = 10;
23
+ * agent.y = 10;
24
+ *
25
+ * // Request path to target
26
+ * agent.requestPathTo(50, 50);
27
+ *
28
+ * // In movement system, follow the path
29
+ * const waypoint = agent.getNextWaypoint();
30
+ * if (waypoint) {
31
+ * // Move towards waypoint
32
+ * // When reached, call agent.advanceWaypoint()
33
+ * }
34
+ * ```
35
+ */
36
+ declare class PathfindingAgentComponent extends Component {
37
+ /**
38
+ * @zh 当前位置 X 坐标
39
+ * @en Current position X coordinate
40
+ */
41
+ x: number;
42
+ /**
43
+ * @zh 当前位置 Y 坐标
44
+ * @en Current position Y coordinate
45
+ */
46
+ y: number;
47
+ /**
48
+ * @zh 目标位置 X 坐标
49
+ * @en Target position X coordinate
50
+ */
51
+ targetX: number;
52
+ /**
53
+ * @zh 目标位置 Y 坐标
54
+ * @en Target position Y coordinate
55
+ */
56
+ targetY: number;
57
+ /**
58
+ * @zh 是否有新的寻路请求待处理
59
+ * @en Whether there is a new path request pending
60
+ */
61
+ hasRequest: boolean;
62
+ /**
63
+ * @zh 寻路优先级(数值越小优先级越高)
64
+ * @en Pathfinding priority (lower number = higher priority)
65
+ */
66
+ priority: number;
67
+ /**
68
+ * @zh 每帧最大迭代次数
69
+ * @en Maximum iterations per frame
70
+ */
71
+ maxIterationsPerFrame: number;
72
+ /**
73
+ * @zh 是否启用动态重规划
74
+ * @en Whether dynamic replanning is enabled
75
+ */
76
+ enableDynamicReplan: boolean;
77
+ /**
78
+ * @zh 向前探测距离(用于障碍物检测)
79
+ * @en Lookahead distance for obstacle detection
80
+ */
81
+ lookaheadDistance: number;
82
+ /**
83
+ * @zh 路径验证间隔(帧数)
84
+ * @en Path validation interval (in frames)
85
+ */
86
+ validationInterval: number;
87
+ /**
88
+ * @zh 当前寻路状态
89
+ * @en Current pathfinding state
90
+ */
91
+ state: PathfindingState;
92
+ /**
93
+ * @zh 当前请求 ID
94
+ * @en Current request ID
95
+ */
96
+ currentRequestId: number;
97
+ /**
98
+ * @zh 当前路径点列表
99
+ * @en Current path waypoints
100
+ */
101
+ path: IPoint[];
102
+ /**
103
+ * @zh 当前路径索引
104
+ * @en Current path index
105
+ */
106
+ pathIndex: number;
107
+ /**
108
+ * @zh 路径总代价
109
+ * @en Total path cost
110
+ */
111
+ pathCost: number;
112
+ /**
113
+ * @zh 寻路进度 (0-1)
114
+ * @en Pathfinding progress (0-1)
115
+ */
116
+ progress: number;
117
+ /**
118
+ * @zh 上次验证的帧号
119
+ * @en Last validation frame number
120
+ */
121
+ lastValidationFrame: number;
122
+ /**
123
+ * @zh 寻路完成回调
124
+ * @en Pathfinding complete callback
125
+ */
126
+ onPathComplete?: (found: boolean, path: readonly IPoint[]) => void;
127
+ /**
128
+ * @zh 寻路进度回调
129
+ * @en Pathfinding progress callback
130
+ */
131
+ onPathProgress?: (progress: number) => void;
132
+ /**
133
+ * @zh 请求寻路到目标位置
134
+ * @en Request path to target position
135
+ *
136
+ * @param targetX - @zh 目标 X 坐标 @en Target X coordinate
137
+ * @param targetY - @zh 目标 Y 坐标 @en Target Y coordinate
138
+ */
139
+ requestPathTo(targetX: number, targetY: number): void;
140
+ /**
141
+ * @zh 取消当前寻路
142
+ * @en Cancel current pathfinding
143
+ */
144
+ cancelPath(): void;
145
+ /**
146
+ * @zh 获取下一个路径点
147
+ * @en Get next waypoint
148
+ *
149
+ * @returns @zh 下一个路径点或 null @en Next waypoint or null
150
+ */
151
+ getNextWaypoint(): IPoint | null;
152
+ /**
153
+ * @zh 前进到下一个路径点
154
+ * @en Advance to next waypoint
155
+ */
156
+ advanceWaypoint(): void;
157
+ /**
158
+ * @zh 检查是否到达路径终点
159
+ * @en Check if reached path end
160
+ *
161
+ * @returns @zh 是否到达终点 @en Whether reached end
162
+ */
163
+ isPathComplete(): boolean;
164
+ /**
165
+ * @zh 检查是否正在寻路
166
+ * @en Check if pathfinding is in progress
167
+ *
168
+ * @returns @zh 是否正在寻路 @en Whether pathfinding is in progress
169
+ */
170
+ isSearching(): boolean;
171
+ /**
172
+ * @zh 检查是否有有效路径
173
+ * @en Check if has valid path
174
+ *
175
+ * @returns @zh 是否有有效路径 @en Whether has valid path
176
+ */
177
+ hasValidPath(): boolean;
178
+ /**
179
+ * @zh 获取剩余路径点数量
180
+ * @en Get remaining waypoint count
181
+ *
182
+ * @returns @zh 剩余路径点数量 @en Remaining waypoint count
183
+ */
184
+ getRemainingWaypointCount(): number;
185
+ /**
186
+ * @zh 获取当前路径的总长度
187
+ * @en Get total path length
188
+ *
189
+ * @returns @zh 路径总长度 @en Total path length
190
+ */
191
+ getPathLength(): number;
192
+ /**
193
+ * @zh 重置组件状态
194
+ * @en Reset component state
195
+ */
196
+ reset(): void;
197
+ /**
198
+ * @zh 组件从实体移除时调用
199
+ * @en Called when component is removed from entity
200
+ */
201
+ onRemovedFromEntity(): void;
202
+ }
203
+
204
+ /**
205
+ * @zh 寻路地图组件
206
+ * @en Pathfinding Map Component
207
+ */
208
+
209
+ /**
210
+ * @zh 地图类型
211
+ * @en Map type
212
+ */
213
+ type PathfindingMapType = 'grid' | 'navmesh';
214
+ /**
215
+ * @zh 寻路地图组件
216
+ * @en Pathfinding Map Component
217
+ *
218
+ * @zh 挂载在场景实体上,持有地图实例和增量寻路器
219
+ * @en Attached to scene entity, holds map instance and incremental pathfinder
220
+ *
221
+ * @example
222
+ * ```typescript
223
+ * const mapEntity = scene.createEntity('PathfindingMap');
224
+ * const mapComp = mapEntity.addComponent(new PathfindingMapComponent());
225
+ *
226
+ * // Configure map
227
+ * mapComp.width = 100;
228
+ * mapComp.height = 100;
229
+ * mapComp.iterationsBudget = 2000;
230
+ *
231
+ * // Map and pathfinder will be initialized by PathfindingSystem
232
+ * ```
233
+ */
234
+ declare class PathfindingMapComponent extends Component {
235
+ /**
236
+ * @zh 地图类型
237
+ * @en Map type
238
+ */
239
+ mapType: PathfindingMapType;
240
+ /**
241
+ * @zh 网格宽度(仅 grid 类型)
242
+ * @en Grid width (grid type only)
243
+ */
244
+ width: number;
245
+ /**
246
+ * @zh 网格高度(仅 grid 类型)
247
+ * @en Grid height (grid type only)
248
+ */
249
+ height: number;
250
+ /**
251
+ * @zh 是否允许对角移动
252
+ * @en Whether diagonal movement is allowed
253
+ */
254
+ allowDiagonal: boolean;
255
+ /**
256
+ * @zh 是否避免穿角
257
+ * @en Whether to avoid corner cutting
258
+ */
259
+ avoidCorners: boolean;
260
+ /**
261
+ * @zh 每帧处理的最大代理数
262
+ * @en Maximum agents processed per frame
263
+ */
264
+ maxAgentsPerFrame: number;
265
+ /**
266
+ * @zh 每帧总迭代次数预算
267
+ * @en Total iterations budget per frame
268
+ */
269
+ iterationsBudget: number;
270
+ /**
271
+ * @zh 是否启用路径平滑
272
+ * @en Whether path smoothing is enabled
273
+ */
274
+ enableSmoothing: boolean;
275
+ /**
276
+ * @zh 路径平滑类型
277
+ * @en Path smoothing type
278
+ */
279
+ smoothingType: 'los' | 'catmullrom' | 'combined';
280
+ /**
281
+ * @zh 是否启用路径缓存
282
+ * @en Whether path caching is enabled
283
+ */
284
+ enableCache: boolean;
285
+ /**
286
+ * @zh 缓存最大条目数
287
+ * @en Maximum cache entries
288
+ */
289
+ cacheMaxEntries: number;
290
+ /**
291
+ * @zh 缓存过期时间(毫秒),0 表示不过期
292
+ * @en Cache TTL in milliseconds, 0 means no expiration
293
+ */
294
+ cacheTtlMs: number;
295
+ /**
296
+ * @zh 是否显示调试信息
297
+ * @en Whether to show debug info
298
+ */
299
+ debugMode: boolean;
300
+ /**
301
+ * @zh 是否显示网格
302
+ * @en Whether to show grid
303
+ */
304
+ showGrid: boolean;
305
+ /**
306
+ * @zh 是否显示路径
307
+ * @en Whether to show paths
308
+ */
309
+ showPaths: boolean;
310
+ /**
311
+ * @zh 地图实例
312
+ * @en Map instance
313
+ */
314
+ map: IPathfindingMap | null;
315
+ /**
316
+ * @zh 增量寻路器实例
317
+ * @en Incremental pathfinder instance
318
+ */
319
+ pathfinder: IIncrementalPathfinder | null;
320
+ /**
321
+ * @zh 路径平滑器实例
322
+ * @en Path smoother instance
323
+ */
324
+ smoother: IPathSmoother | null;
325
+ /**
326
+ * @zh 是否已初始化
327
+ * @en Whether initialized
328
+ */
329
+ initialized: boolean;
330
+ /**
331
+ * @zh 当前活跃请求数
332
+ * @en Current active request count
333
+ */
334
+ activeRequests: number;
335
+ /**
336
+ * @zh 本帧使用的迭代次数
337
+ * @en Iterations used this frame
338
+ */
339
+ iterationsUsedThisFrame: number;
340
+ /**
341
+ * @zh 本帧处理的代理数
342
+ * @en Agents processed this frame
343
+ */
344
+ agentsProcessedThisFrame: number;
345
+ /**
346
+ * @zh 缓存命中次数
347
+ * @en Cache hit count
348
+ */
349
+ cacheHits: number;
350
+ /**
351
+ * @zh 缓存未命中次数
352
+ * @en Cache miss count
353
+ */
354
+ cacheMisses: number;
355
+ /**
356
+ * @zh 设置网格单元格是否可通行
357
+ * @en Set grid cell walkability
358
+ *
359
+ * @param x - @zh X 坐标 @en X coordinate
360
+ * @param y - @zh Y 坐标 @en Y coordinate
361
+ * @param walkable - @zh 是否可通行 @en Is walkable
362
+ */
363
+ setWalkable(x: number, y: number, walkable: boolean): void;
364
+ /**
365
+ * @zh 设置矩形区域是否可通行
366
+ * @en Set rectangular area walkability
367
+ *
368
+ * @param x - @zh 起始 X @en Start X
369
+ * @param y - @zh 起始 Y @en Start Y
370
+ * @param width - @zh 宽度 @en Width
371
+ * @param height - @zh 高度 @en Height
372
+ * @param walkable - @zh 是否可通行 @en Is walkable
373
+ */
374
+ setRectWalkable(x: number, y: number, rectWidth: number, rectHeight: number, walkable: boolean): void;
375
+ /**
376
+ * @zh 检查位置是否可通行
377
+ * @en Check if position is walkable
378
+ *
379
+ * @param x - @zh X 坐标 @en X coordinate
380
+ * @param y - @zh Y 坐标 @en Y coordinate
381
+ * @returns @zh 是否可通行 @en Is walkable
382
+ */
383
+ isWalkable(x: number, y: number): boolean;
384
+ /**
385
+ * @zh 重置统计信息
386
+ * @en Reset statistics
387
+ */
388
+ resetStats(): void;
389
+ /**
390
+ * @zh 获取剩余迭代预算
391
+ * @en Get remaining iteration budget
392
+ *
393
+ * @returns @zh 剩余预算 @en Remaining budget
394
+ */
395
+ getRemainingBudget(): number;
396
+ /**
397
+ * @zh 获取缓存统计信息
398
+ * @en Get cache statistics
399
+ *
400
+ * @returns @zh 缓存统计 @en Cache statistics
401
+ */
402
+ getCacheStats(): {
403
+ enabled: boolean;
404
+ hits: number;
405
+ misses: number;
406
+ hitRate: number;
407
+ };
408
+ /**
409
+ * @zh 组件从实体移除时调用
410
+ * @en Called when component is removed from entity
411
+ */
412
+ onRemovedFromEntity(): void;
413
+ }
414
+
415
+ /**
416
+ * @zh 寻路系统
417
+ * @en Pathfinding System
418
+ */
419
+
420
+ /**
421
+ * @zh 寻路系统
422
+ * @en Pathfinding System
423
+ *
424
+ * @zh 处理所有 PathfindingAgentComponent,支持时间切片和动态重规划
425
+ * @en Processes all PathfindingAgentComponents, supports time slicing and dynamic replanning
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * // Add system to scene
430
+ * scene.addSystem(new PathfindingSystem());
431
+ *
432
+ * // Create map entity
433
+ * const mapEntity = scene.createEntity('Map');
434
+ * mapEntity.addComponent(new PathfindingMapComponent());
435
+ *
436
+ * // Create agents
437
+ * const agent = scene.createEntity('Agent');
438
+ * const pathAgent = agent.addComponent(new PathfindingAgentComponent());
439
+ * pathAgent.requestPathTo(50, 50);
440
+ *
441
+ * // System handles pathfinding automatically each frame
442
+ * ```
443
+ */
444
+ declare class PathfindingSystem extends EntitySystem {
445
+ private mapEntity;
446
+ private mapComponent;
447
+ private pathValidator;
448
+ private agentQueue;
449
+ private frameCounter;
450
+ constructor();
451
+ /**
452
+ * @zh 系统初始化
453
+ * @en System initialization
454
+ */
455
+ protected onInitialize(): void;
456
+ /**
457
+ * @zh 系统激活时调用
458
+ * @en Called when system is enabled
459
+ */
460
+ protected onEnable(): void;
461
+ /**
462
+ * @zh 处理实体
463
+ * @en Process entities
464
+ */
465
+ protected process(entities: readonly Entity[]): void;
466
+ /**
467
+ * @zh 查找地图实体
468
+ * @en Find map entity
469
+ */
470
+ private findMapEntity;
471
+ /**
472
+ * @zh 初始化地图
473
+ * @en Initialize map
474
+ */
475
+ private initializeMap;
476
+ /**
477
+ * @zh 构建代理优先级队列
478
+ * @en Build agent priority queue
479
+ */
480
+ private buildAgentQueue;
481
+ /**
482
+ * @zh 使用预算处理代理
483
+ * @en Process agents with budget
484
+ */
485
+ private processAgentsWithBudget;
486
+ /**
487
+ * @zh 启动新的寻路请求
488
+ * @en Start new pathfinding request
489
+ */
490
+ private startNewRequest;
491
+ /**
492
+ * @zh 从进度更新代理状态
493
+ * @en Update agent state from progress
494
+ */
495
+ private updateAgentFromProgress;
496
+ /**
497
+ * @zh 周期性验证路径有效性
498
+ * @en Periodically validate path validity
499
+ */
500
+ private validatePaths;
501
+ }
502
+
503
+ export { PathfindingAgentComponent, PathfindingMapComponent, type PathfindingMapType, PathfindingSystem };