SDLGameEngine

SgePathFinder

A* path finding. More...

Data Structures

struct  SGEPATHFINDERINFO
 holds information about a possible path More...
struct  SGEPATHFINDER
 a pathfinder struct More...

Defines

#define DISABLE_DIAGONAL   0
#define ENABLE_DIAGONAL   1

Functions

SGEPATHFINDERsgePathFinderNew (int width, int height)
 create a new path finder with a grid of width x height, diagonal movement enabled
SGEPATHFINDERsgePathFinderNewDiagonal (int width, int height, int diagonal)
 create a new path finder with a grid of width x height
void sgePathFinderDestroy (SGEPATHFINDER *p)
 destroy a SGEPATHFINDER
SGEPATHFINDERINFOsgePathFinderInfoNew (int x, int y, int startWeight, int targetWeight, void *parent)
 create a new SGEPATHFINDERINFO
void sgePathFinderInfoDestroy (SGEPATHFINDERINFO *pi)
 destroy a SGEPATHFINDERINFO
void sgePathFinderDiagonal (SGEPATHFINDER *p, int diagonal)
 enable or disable diagonal movement
void sgePathFinderSet (SGEPATHFINDER *p, int x, int y, int value)
 set a position in the data grid
int sgePathFinderGet (SGEPATHFINDER *p, int x, int y)
 get the value of a position in the data grid
int sgePathFinderFind (SGEPATHFINDER *p, int startx, int starty, int destx, int desty)
 find a path between two points on the datagrid

Variables

int SGEPATHFINDERINFO::y
 the y position in the data grid
int SGEPATHFINDER::height
 The height of the grid.

Detailed Description

A* path finding.

Finds the shortest route between two points in a n by n grid.


Define Documentation

#define DISABLE_DIAGONAL   0

disable diagonal movement

Definition at line 33 of file sgepathfinder.h.

#define ENABLE_DIAGONAL   1

enable diagonal movement

Definition at line 38 of file sgepathfinder.h.


Function Documentation

void sgePathFinderDestroy ( SGEPATHFINDER p)

destroy a SGEPATHFINDER

Parameters:
pa pointer to SGEPATHFINDER

Definition at line 32 of file sgepathfinder.c.

void sgePathFinderDiagonal ( SGEPATHFINDER p,
int  diagonal 
) [inline]

enable or disable diagonal movement

Parameters:
pa pointer to SGEPATHFINDER
diagonalYES/NO to enable of disable diagonal movement

Definition at line 40 of file sgepathfinder.c.

int sgePathFinderFind ( SGEPATHFINDER p,
int  startx,
int  starty,
int  destx,
int  desty 
)

find a path between two points on the datagrid

Parameters:
pa pointer to SGEPATHFINDER
startxthe x position of the starting point
startythe y position of the starting point
destxthe x position of the destination point
destythe y position of the destination point
Returns:
YES/NO depending if there was a solution possible

The resulting path, if there was one, is saved as a SGEARRAY of SGEPATHFINDERINFO structures.

Definition at line 75 of file sgepathfinder.c.

int sgePathFinderGet ( SGEPATHFINDER p,
int  x,
int  y 
)

get the value of a position in the data grid

Parameters:
pa pointer to SGEPATHFINDER
xthe x position to get
ythe y position to get
Returns:
0 if the position is walkable, 1 if there is a obstacle on it

Definition at line 63 of file sgepathfinder.c.

void sgePathFinderInfoDestroy ( SGEPATHFINDERINFO pi)

destroy a SGEPATHFINDERINFO

Parameters:
pia pointer to SGEPATHFINDERINFO

Definition at line 55 of file sgepathfinder.c.

SGEPATHFINDERINFO* sgePathFinderInfoNew ( int  x,
int  y,
int  startWeight,
int  targetWeight,
void *  parent 
)

create a new SGEPATHFINDERINFO

Parameters:
xthe x position in the grid
ythe y position in the grid
startWeightthe weight to the start
targetWeightthe weight to the target
parentthe parent SGEPATHFINDERINFO
Returns:
a pointer to SGEPATHFINDERINFO

Definition at line 44 of file sgepathfinder.c.

SGEPATHFINDER* sgePathFinderNew ( int  width,
int  height 
)

create a new path finder with a grid of width x height, diagonal movement enabled

Parameters:
widththe width of the data grid
heightthe height of the data grid
Returns:
a pointer to SGEPATHFINDER

Definition at line 15 of file sgepathfinder.c.

SGEPATHFINDER* sgePathFinderNewDiagonal ( int  width,
int  height,
int  diagonal 
)

create a new path finder with a grid of width x height

Parameters:
widththe width of the data grid
heightthe height of the data grid
diagonalYES/NO if there should be diagonal movement between the grid fields
Returns:
a pointer to SGEPATHFINDER

Definition at line 26 of file sgepathfinder.c.

void sgePathFinderSet ( SGEPATHFINDER p,
int  x,
int  y,
int  value 
)

set a position in the data grid

Parameters:
pa pointer to SGEPATHFINDER
xthe x position to set
ythe y position to set
value0 or 1 depending on if it is walkable or a obstacle

Definition at line 59 of file sgepathfinder.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines