OpenTTD
|
AyStar search algorithm struct. More...
#include <aystar.h>
Public Member Functions | |
void | Init (Hash_HashProc hash, uint num_buckets) |
Initialize an AyStar. | |
void | AddStartNode (AyStarNode *start_node, uint g) |
Adds a node from where to start an algorithm. | |
int | Main () |
This is the function you call to run AyStar. | |
int | Loop () |
This function is the core of AyStar. | |
void | Free () |
This function frees the memory it allocated. | |
void | Clear () |
This function make the memory go back to zero. | |
void | CheckTile (AyStarNode *current, OpenListNode *parent) |
Checks one tile and calculate its f-value. |
Data Fields | |
AyStar_CalculateG * | CalculateG |
AyStar_CalculateH * | CalculateH |
AyStar_GetNeighbours * | GetNeighbours |
AyStar_EndNodeCheck * | EndNodeCheck |
AyStar_FoundEndNode * | FoundEndNode |
void * | user_path |
void * | user_target |
uint | user_data [10] |
byte | loops_per_tick |
How many loops are there called before Main() gives control back to the caller. 0 = until done. | |
uint | max_path_cost |
If the g-value goes over this number, it stops searching, 0 = infinite. | |
uint | max_search_nodes |
The maximum number of nodes that will be expanded, 0 = infinite. | |
AyStarNode | neighbours [12] |
byte | num_neighbours |
Protected Member Functions | |
void | OpenListAdd (PathNode *parent, const AyStarNode *node, int f, int g) |
Adds a node to the open list. | |
OpenListNode * | OpenListIsInList (const AyStarNode *node) |
Check whether a node is in the open list. | |
OpenListNode * | OpenListPop () |
Gets the best node from the open list. | |
void | ClosedListAdd (const PathNode *node) |
This adds a node to the closed list. | |
PathNode * | ClosedListIsInList (const AyStarNode *node) |
This looks in the hash whether a node exists in the closed list. |
Protected Attributes | |
Hash | closedlist_hash |
The actual closed list. | |
BinaryHeap | openlist_queue |
The open queue. | |
Hash | openlist_hash |
An extra hash to speed up the process of looking up an element in the open list. |
AyStar search algorithm struct.
Before calling Init(), fill #CalculateG, #CalculateH, #GetNeighbours, #EndNodeCheck, and #FoundEndNode. If you want to change them after calling Init(), first call Free() !
The #user_path, #user_target, and #user_data[10] are intended to be used by the user routines. The data not accessed by the AyStar code itself. The user routines can change any moment they like.
void AyStar::AddStartNode | ( | AyStarNode * | start_node, |
uint | g | ||
) |
Adds a node from where to start an algorithm.
Multiple nodes can be added if wanted. You should make sure that Clear() is called before adding nodes if the AyStar has been used before (though the normal main loop calls Clear() automatically when the algorithm finishes.
start_node | Node to start with. |
g | the cost for starting with this node. |
Definition at line 282 of file aystar.cpp.
References OpenListAdd(), TileX(), and TileY().
Referenced by BuildRiver().
void AyStar::Clear | ( | ) |
This function make the memory go back to zero.
This function should be called when you are using the same instance again.
Definition at line 224 of file aystar.cpp.
References BinaryHeap::Clear(), Hash::Clear(), closedlist_hash, openlist_hash, and openlist_queue.
Referenced by Main().
|
protected |
This adds a node to the closed list.
It makes a copy of the data.
node | Node to add to the closed list. |
Definition at line 47 of file aystar.cpp.
References closedlist_hash, and Hash::Set().
Referenced by Loop().
|
protected |
This looks in the hash whether a node exists in the closed list.
node | Node to search. |
NULL
Definition at line 37 of file aystar.cpp.
References closedlist_hash, and Hash::Get().
Referenced by CheckTile().
void AyStar::Init | ( | Hash_HashProc | hash, |
uint | num_buckets | ||
) |
Initialize an AyStar.
You should fill all appropriate fields before calling Init (see the declaration of AyStar for which fields are internal).
Definition at line 295 of file aystar.cpp.
References closedlist_hash, BinaryHeap::Init(), Hash::Init(), openlist_hash, and openlist_queue.
Referenced by BuildRiver().
int AyStar::Loop | ( | ) |
This function is the core of AyStar.
It handles one item and checks his neighbour items. If they are valid, they are added to be checked too.
Definition at line 163 of file aystar.cpp.
References AYSTAR_EMPTY_OPENLIST, AYSTAR_FOUND_END_NODE, AYSTAR_LIMIT_REACHED, AYSTAR_STILL_BUSY, CheckTile(), closedlist_hash, ClosedListAdd(), free(), Hash::GetSize(), max_search_nodes, and OpenListPop().
Referenced by Main().
int AyStar::Main | ( | ) |
This is the function you call to run AyStar.
Definition at line 247 of file aystar.cpp.
References AYSTAR_EMPTY_OPENLIST, AYSTAR_FOUND_END_NODE, AYSTAR_LIMIT_REACHED, AYSTAR_NO_PATH, AYSTAR_STILL_BUSY, Clear(), Loop(), and loops_per_tick.
Referenced by BuildRiver().
|
protected |
Adds a node to the open list.
It makes a copy of node, and puts the pointer of parent in the struct.
Definition at line 85 of file aystar.cpp.
References openlist_hash, openlist_queue, PathNode::parent, BinaryHeap::Push(), and Hash::Set().
Referenced by AddStartNode(), and CheckTile().
|
protected |
Check whether a node is in the open list.
node | Node to search. |
NULL
is returned. Definition at line 60 of file aystar.cpp.
References Hash::Get(), and openlist_hash.
Referenced by CheckTile().
|
protected |
Gets the best node from the open list.
It deletes the returned node from the open list.
NULL
of none is found. Definition at line 70 of file aystar.cpp.
References Hash::DeleteValue(), openlist_hash, openlist_queue, and BinaryHeap::Pop().
Referenced by Loop().