Table of Contents
- ASTAR: A* pathfinding for 2D/3D grids
- Structures
- Types
- Functions
- Defines
- Types Documentation
- Functions Documentation
- function n_astar_path_free
- function n_astar_heuristic
- function n_astar_grid_set_walkable
- function n_astar_grid_set_rect_blocked
- function n_astar_grid_set_cost
- function n_astar_grid_new
- function n_astar_grid_get_walkable
- function n_astar_grid_get_cost
- function n_astar_grid_free
- function n_astar_find_path
- Macros Documentation
ASTAR: A* pathfinding for 2D/3D grids
Structures
| Name | |
|---|---|
| struct | ASTAR_PATH The computed path result. |
| struct | ASTAR_NODE A single node in the resulting path. |
| struct | ASTAR_HEAP_NODE Min-heap entry for the open list priority queue. |
| struct | ASTAR_HEAP Binary min-heap (priority queue) for the open list. |
| struct | ASTAR_GRID Grid structure holding walkability, costs, and dimensions. |
| struct | ASTAR_CELL Internal node data used during pathfinding. |
Types
| Name | |
|---|---|
| enum | ASTAR_HEURISTIC { ASTAR_HEURISTIC_MANHATTAN = 0, ASTAR_HEURISTIC_EUCLIDEAN, ASTAR_HEURISTIC_CHEBYSHEV} Heuristic function selection for h(n) estimation. |
Functions
| Name | |
|---|---|
| void | n_astar_path_free(ASTAR_PATH * path) free a path returned by n_astar_find_path |
| int | n_astar_heuristic(int x1, int y1, int z1, int x2, int y2, int z2, ASTAR_HEURISTIC heuristic) compute heuristic distance between two points (x1000) |
| void | n_astar_grid_set_walkable(ASTAR_GRID * grid, int x, int y, int z, uint8_t walkable) set a cell's walkability (1=passable, 0=blocked) |
| void | n_astar_grid_set_rect_blocked(ASTAR_GRID * grid, int x1, int y1, int z1, int x2, int y2, int z2) set a rectangular region as blocked |
| void | n_astar_grid_set_cost(ASTAR_GRID * grid, int x, int y, int z, int cost) set a cell's movement cost multiplier (x1000) |
| ASTAR_GRID * | n_astar_grid_new(int width, int height, int depth) create a new grid for pathfinding, all cells default to walkable |
| uint8_t | n_astar_grid_get_walkable(const ASTAR_GRID * grid, int x, int y, int z) get a cell's walkability (1=passable, 0=blocked, 0 if out of bounds) |
| int | n_astar_grid_get_cost(const ASTAR_GRID * grid, int x, int y, int z) get a cell's movement cost multiplier (x1000) |
| void | n_astar_grid_free(ASTAR_GRID * grid) free a grid and all its internal data |
| ASTAR_PATH * | n_astar_find_path(const ASTAR_GRID * grid, int sx, int sy, int sz, int gx, int gy, int gz, int diagonal, ASTAR_HEURISTIC heuristic) find a path using A* search, returns NULL if no path exists |
Defines
| Name | |
|---|---|
| ASTAR_SEARCH_MARGIN Search-window margin (in cells) added around the bounding box of the start and goal. |
|
| ASTAR_NODE_OPEN Node is in the open list. |
|
| ASTAR_NODE_NONE Node has not been visited. |
|
| ASTAR_NODE_CLOSED Node has been fully evaluated. |
|
| ASTAR_COST_DIAGONAL3D Default cost for 3D diagonal movement (sqrt(3)*1000). |
|
| ASTAR_COST_DIAGONAL Default cost for 2D diagonal movement (sqrt(2)*1000). |
|
| ASTAR_COST_CARDINAL Default cost for straight movement (fixed-point x1000). |
|
| ASTAR_CARDINAL_ONLY Movement mode: 4-dir (2D) or 6-dir (3D). |
|
| ASTAR_ALLOW_DIAGONAL Movement mode: 8-dir (2D) or 26-dir (3D). |
Types Documentation
enum ASTAR_HEURISTIC
| Enumerator | Value | Description |
|---|---|---|
| ASTAR_HEURISTIC_MANHATTAN | 0 | sum of axis deltas (optimal for 4-dir) |
| ASTAR_HEURISTIC_EUCLIDEAN | straight-line distance | |
| ASTAR_HEURISTIC_CHEBYSHEV | max of axis deltas (optimal for 8-dir) |
Heuristic function selection for h(n) estimation.
Functions Documentation
function n_astar_path_free
void n_astar_path_free(
ASTAR_PATH * path
)
free a path returned by n_astar_find_path
Parameters:
- path path to free (safe to pass NULL)
Free a path returned by n_astar_find_path.
free a path returned by n_astar_find_path
function n_astar_heuristic
int n_astar_heuristic(
int x1,
int y1,
int z1,
int x2,
int y2,
int z2,
ASTAR_HEURISTIC heuristic
)
compute heuristic distance between two points (x1000)
Parameters:
- x1 first point X
- y1 first point Y
- z1 first point Z
- x2 second point X
- y2 second point Y
- z2 second point Z
- heuristic the heuristic to use
Return: estimated distance in fixed-point (x1000)
Compute heuristic distance between two 3D points.
compute heuristic distance between two points (x1000)
function n_astar_grid_set_walkable
void n_astar_grid_set_walkable(
ASTAR_GRID * grid,
int x,
int y,
int z,
uint8_t walkable
)
set a cell's walkability (1=passable, 0=blocked)
Parameters:
- grid the grid
- x cell X coordinate
- y cell Y coordinate
- z cell Z coordinate
- walkable 1=passable, 0=blocked
Set a cell's walkability.
set a cell's walkability (1=passable, 0=blocked)
function n_astar_grid_set_rect_blocked
void n_astar_grid_set_rect_blocked(
ASTAR_GRID * grid,
int x1,
int y1,
int z1,
int x2,
int y2,
int z2
)
set a rectangular region as blocked
Parameters:
- grid the grid
- x1 start corner X (inclusive)
- y1 start corner Y (inclusive)
- z1 start corner Z (inclusive)
- x2 end corner X (inclusive)
- y2 end corner Y (inclusive)
- z2 end corner Z (inclusive)
Set a rectangular region as blocked (wall).
set a rectangular region as blocked
function n_astar_grid_set_cost
void n_astar_grid_set_cost(
ASTAR_GRID * grid,
int x,
int y,
int z,
int cost
)
set a cell's movement cost multiplier (x1000)
Parameters:
- grid the grid
- x cell X coordinate
- y cell Y coordinate
- z cell Z coordinate
- cost cost multiplier (x1000)
Set a cell's movement cost multiplier.
set a cell's movement cost multiplier (x1000)
function n_astar_grid_new
ASTAR_GRID * n_astar_grid_new(
int width,
int height,
int depth
)
create a new grid for pathfinding, all cells default to walkable
Parameters:
- width grid width (X)
- height grid height (Y)
- depth grid depth (Z, use 1 for 2D)
Return: new grid or NULL. All cells default to walkable with cost 1000.
Create a new grid for A* pathfinding.
create a new grid for pathfinding, all cells default to walkable
function n_astar_grid_get_walkable
uint8_t n_astar_grid_get_walkable(
const ASTAR_GRID * grid,
int x,
int y,
int z
)
get a cell's walkability (1=passable, 0=blocked, 0 if out of bounds)
Parameters:
- grid the grid
- x cell X coordinate
- y cell Y coordinate
- z cell Z coordinate
Return: 1 if passable, 0 if blocked or out of bounds
Get a cell's walkability.
get a cell's walkability (1=passable, 0=blocked, 0 if out of bounds)
function n_astar_grid_get_cost
int n_astar_grid_get_cost(
const ASTAR_GRID * grid,
int x,
int y,
int z
)
get a cell's movement cost multiplier (x1000)
Parameters:
- grid the grid
- x cell X coordinate
- y cell Y coordinate
- z cell Z coordinate
Return: cost multiplier (x1000), or 0 if out of bounds
Get a cell's movement cost multiplier.
get a cell's movement cost multiplier (x1000)
function n_astar_grid_free
void n_astar_grid_free(
ASTAR_GRID * grid
)
free a grid and all its internal data
Parameters:
- grid grid to free (safe to pass NULL)
Free a grid and all its internal data.
free a grid and all its internal data
function n_astar_find_path
ASTAR_PATH * n_astar_find_path(
const ASTAR_GRID * grid,
int sx,
int sy,
int sz,
int gx,
int gy,
int gz,
int diagonal,
ASTAR_HEURISTIC heuristic
)
find a path using A* search, returns NULL if no path exists
Parameters:
- grid the grid to search
- sx start X
- sy start Y
- sz start Z
- gx goal X
- gy goal Y
- gz goal Z
- diagonal ASTAR_CARDINAL_ONLY or ASTAR_ALLOW_DIAGONAL
- heuristic heuristic function to use
Return: path from start to goal, or NULL if no path exists. Caller must free with n_astar_path_free().
Find a path using A* search.
find a path using A* search, returns NULL if no path exists
Macros Documentation
define ASTAR_SEARCH_MARGIN
#define ASTAR_SEARCH_MARGIN 128
Search-window margin (in cells) added around the bounding box of the start and goal.
n_astar_find_path() allocates its per-call working set for this window only, not the whole grid, so a short path on a huge map costs a few KB instead of widthheightdepth cells. A route that must detour more than this many cells outside the start-goal box will not be found (the call returns NULL). Raise it if you need wider detours at the cost of a larger per-call allocation.
define ASTAR_NODE_OPEN
#define ASTAR_NODE_OPEN 1
Node is in the open list.
define ASTAR_NODE_NONE
#define ASTAR_NODE_NONE 0
Node has not been visited.
define ASTAR_NODE_CLOSED
#define ASTAR_NODE_CLOSED 2
Node has been fully evaluated.
define ASTAR_COST_DIAGONAL3D
#define ASTAR_COST_DIAGONAL3D 1732
Default cost for 3D diagonal movement (sqrt(3)*1000).
define ASTAR_COST_DIAGONAL
#define ASTAR_COST_DIAGONAL 1414
Default cost for 2D diagonal movement (sqrt(2)*1000).
define ASTAR_COST_CARDINAL
#define ASTAR_COST_CARDINAL 1000
Default cost for straight movement (fixed-point x1000).
define ASTAR_CARDINAL_ONLY
#define ASTAR_CARDINAL_ONLY 0
Movement mode: 4-dir (2D) or 6-dir (3D).
define ASTAR_ALLOW_DIAGONAL
#define ASTAR_ALLOW_DIAGONAL 1
Movement mode: 8-dir (2D) or 26-dir (3D).
Modules
- AABB3D
- ACCEPT_POOL
- ALLEGRO4
- ALLEGRO5
- ANIM_LIB
- ASTAR
- ATLAS_LIB
- AVRO
- CLOCK_SYNC
- COMMONS
- CONFIGFILE
- CYPHER_BASE64
- CYPHER_VIGENERE
- DEAD_RECKONING
- ENUMS
- EXCEPTIONS
- GAME_ENV
- GIT
- GUI
- HASH_TABLE
- ISOMETRIC_ENGINE
- LIST
- LOG
- LOGNODUP
- LZ4
- NETWORKING
- NETWORK_MSG
- N_COOKIES
- N_DIFF
- N_DIGEST
- N_DISK_CACHE
- N_DNS
- N_ECC
- N_ENTROPY
- N_FILES
- N_FLUIDS
- N_GUI_COLOR
- N_GUI_COLORWHEEL
- N_GUI_CURVE
- N_GUI_GRID
- N_GUI_POPUP
- N_HEX
- N_HTTP3
- N_HTTP_COOKIE
- N_HTTP_FORM
- N_HTTP_MIME
- N_HTTP_REQ
- N_HTTP_RESP
- N_HTTP_ROUTER
- N_HTTP_SERVER
- N_ICC
- N_JSON
- N_KAFKA
- N_LINALG
- N_MODULE
- N_OPENSSL_COMPAT
- N_PRETTY
- N_PTH
- N_QUERY
- N_RANDOM
- N_SHA256
- N_STR
- N_TIFF
- N_TIME
- N_USER
- N_X509
- N_ZIP
- PARTICLES
- PCRE
- PHYSICS
- SIGNALS
- STACK
- THREADS
- TRAJECTORY
- TREE
- ZLIB