|
1 | | ----@diagnostic disable: missing-return, unused-local |
2 | | - |
3 | | ----@meta pathfinder |
4 | 1 | ---Defold Graph Pathfinder Extension |
5 | 2 | ---High-performance A* pathfinding library for real-time games and simulations. |
6 | 3 | ---@class pathfinder |
| 4 | +pathfinder = { |
| 5 | + INVALID_ID = 0xFFFFFFFF, -- Invalid ID constant for cells and nodes (UINT32_MAX) |
| 6 | + |
| 7 | + ---PathStatus enum - Status codes for pathfinding operations |
| 8 | + ---@enum PathStatus |
| 9 | + PathStatus = { |
| 10 | + SUCCESS = 0, -- Operation completed successfully |
| 11 | + SUCCESS_START_FALLBACK = 1, -- Success, but start position used fallback to nearest cell (navmesh only) |
| 12 | + SUCCESS_GOAL_FALLBACK = 2, -- Success, but goal position used fallback to nearest cell (navmesh only) |
| 13 | + ERROR_NO_PATH = -1, -- No valid path found between start and goal nodes |
| 14 | + ERROR_START_GOAL_NODE_SAME = -12, -- Start node ID and goal node ID are the same |
| 15 | + ERROR_START_NODE_INVALID = -2, -- Invalid or inactive start node ID |
| 16 | + ERROR_GOAL_NODE_INVALID = -3, -- Invalid or inactive goal node ID |
| 17 | + ERROR_START_NOT_IN_CELL = -13, -- Start position not in any cell, fallback disabled (navmesh only) |
| 18 | + ERROR_GOAL_NOT_IN_CELL = -14, -- Goal position not in any cell, fallback disabled (navmesh only) |
| 19 | + ERROR_NODE_FULL = -4, -- Node capacity reached, cannot add more nodes |
| 20 | + ERROR_EDGE_FULL = -5, -- Edge capacity reached, cannot add more edges |
| 21 | + ERROR_HEAP_FULL = -6, -- Heap pool exhausted during pathfinding |
| 22 | + ERROR_PATH_TOO_LONG = -7, -- Path exceeds maximum allowed length |
| 23 | + ERROR_GRAPH_CHANGED = -8, -- Graph modified during pathfinding (retrying) |
| 24 | + ERROR_GRAPH_CHANGED_TOO_OFTEN = -11, -- Graph changed too often during pathfinding |
| 25 | + ERROR_NO_PROJECTION = -9, -- Cannot project point onto graph (no edges exist) |
| 26 | + ERROR_VIRTUAL_NODE_FAILED = -10 -- Failed to create or connect virtual node |
| 27 | + }, |
| 28 | + |
| 29 | + ---PathSmoothStyle enum - Path smoothing algorithms |
| 30 | + ---@enum PathSmoothStyle |
| 31 | + PathSmoothStyle = { |
| 32 | + NONE = 0, -- No smoothing (angular paths, fastest) |
| 33 | + CATMULL_ROM = 1, -- Passes through all waypoints with smooth curves |
| 34 | + BEZIER_CUBIC = 2, -- Very smooth curves with two control points |
| 35 | + BEZIER_QUADRATIC = 3, -- Corner-only smoothing (recommended) |
| 36 | + BEZIER_ADAPTIVE = 4, -- Adaptive corner smoothing (highly customizable) |
| 37 | + CIRCULAR_ARC = 5 -- Perfect circular arcs (best for tile-based games) |
| 38 | + } |
| 39 | +} |
7 | 40 |
|
8 | 41 | ---@class PathNode |
9 | 42 | ---@field x number X coordinate of the node position |
|
25 | 58 | ---@field bezier_adaptive_max_corner_distance number Maximum corner distance for BEZIER_ADAPTIVE (default: 50.0) |
26 | 59 | ---@field bezier_arc_radius number Arc radius for CIRCULAR_ARC style (default: 60.0) |
27 | 60 |
|
28 | | ----PathStatus enum - Status codes for pathfinding operations |
29 | | ----@enum PathStatus |
30 | | -pathfinder.PathStatus = { |
31 | | - SUCCESS = 0, -- Operation completed successfully |
32 | | - SUCCESS_START_FALLBACK = 1, -- Success, but start position used fallback to nearest cell (navmesh only) |
33 | | - SUCCESS_GOAL_FALLBACK = 2, -- Success, but goal position used fallback to nearest cell (navmesh only) |
34 | | - ERROR_NO_PATH = -1, -- No valid path found between start and goal nodes |
35 | | - ERROR_START_GOAL_NODE_SAME = -12, -- Start node ID and goal node ID are the same |
36 | | - ERROR_START_NODE_INVALID = -2, -- Invalid or inactive start node ID |
37 | | - ERROR_GOAL_NODE_INVALID = -3, -- Invalid or inactive goal node ID |
38 | | - ERROR_START_NOT_IN_CELL = -13, -- Start position not in any cell, fallback disabled (navmesh only) |
39 | | - ERROR_GOAL_NOT_IN_CELL = -14, -- Goal position not in any cell, fallback disabled (navmesh only) |
40 | | - ERROR_NODE_FULL = -4, -- Node capacity reached, cannot add more nodes |
41 | | - ERROR_EDGE_FULL = -5, -- Edge capacity reached, cannot add more edges |
42 | | - ERROR_HEAP_FULL = -6, -- Heap pool exhausted during pathfinding |
43 | | - ERROR_PATH_TOO_LONG = -7, -- Path exceeds maximum allowed length |
44 | | - ERROR_GRAPH_CHANGED = -8, -- Graph modified during pathfinding (retrying) |
45 | | - ERROR_GRAPH_CHANGED_TOO_OFTEN = -11, -- Graph changed too often during pathfinding |
46 | | - ERROR_NO_PROJECTION = -9, -- Cannot project point onto graph (no edges exist) |
47 | | - ERROR_VIRTUAL_NODE_FAILED = -10 -- Failed to create or connect virtual node |
48 | | -} |
49 | | - |
50 | | ----PathSmoothStyle enum - Path smoothing algorithms |
51 | | ----@enum PathSmoothStyle |
52 | | -pathfinder.PathSmoothStyle = { |
53 | | - NONE = 0, -- No smoothing (angular paths, fastest) |
54 | | - CATMULL_ROM = 1, -- Passes through all waypoints with smooth curves |
55 | | - BEZIER_CUBIC = 2, -- Very smooth curves with two control points |
56 | | - BEZIER_QUADRATIC = 3, -- Corner-only smoothing (recommended) |
57 | | - BEZIER_ADAPTIVE = 4, -- Adaptive corner smoothing (highly customizable) |
58 | | - CIRCULAR_ARC = 5 -- Perfect circular arcs (best for tile-based games) |
59 | | -} |
60 | | - |
61 | 61 | ---Initialize the pathfinding system. Must be called before any other pathfinding operations. |
62 | 62 | ---@param max_nodes number Maximum number of nodes in the graph |
63 | 63 | ---@param max_gameobject_nodes number|nil Maximum number of game object nodes (optional, default: 0) |
@@ -305,5 +305,3 @@ function pathfinder.navmesh_get_spatial_index() end |
305 | 305 | ---Get comprehensive statistics about navmesh pathfinding caches. |
306 | 306 | ---@return table stats Table containing cache statistics with fields: path_cache, distance_cache |
307 | 307 | function pathfinder.navmesh_get_stats() end |
308 | | - |
309 | | -return pathfinder |
0 commit comments