OpenTTD Source
20241108-master-g80f628063a
|
AyStar search algorithm struct. More...
#include <aystar.h>
Public Member Functions | |
void | AddStartNode (AyStarNode *start_node, int g) |
Adds a node from where to start an algorithm. More... | |
int | Main () |
This is the function you call to run AyStar. More... | |
int | Loop () |
This function is the core of AyStar. More... | |
void | CheckTile (AyStarNode *current, PathNode *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_target |
void * | user_data |
uint8_t | loops_per_tick |
How many loops are there called before Main() gives control back to the caller. 0 = until done. | |
int | max_path_cost |
If the g-value goes over this number, it stops searching, 0 = infinite. | |
int | max_search_nodes = AYSTAR_DEF_MAX_SEARCH_NODES |
The maximum number of nodes that will be expanded, 0 = infinite. | |
std::vector< AyStarNode > | neighbours |
Protected Member Functions | |
void | OpenListAdd (PathNode *parent, const AyStarNode *node, int f, int g) |
Adds a node to the open list. More... | |
Protected Attributes | |
CNodeList_HashTableT< PathNode, 8, 10 > | nodes |
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, |
int | 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 168 of file aystar.cpp.
References Debug, OpenListAdd(), TileX(), and TileY().
int AyStar::Loop | ( | ) |
This function is the core of AyStar.
It handles one item and checks its neighbour items. If they are valid, they are added to be checked too.
Definition at line 92 of file aystar.cpp.
References AYSTAR_EMPTY_OPENLIST, AYSTAR_FOUND_END_NODE, AYSTAR_LIMIT_REACHED, AYSTAR_STILL_BUSY, CheckTile(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::ClosedCount(), CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::InsertClosedNode(), max_search_nodes, and CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::PopBestOpenNode().
Referenced by Main().
int AyStar::Main | ( | ) |
This is the function you call to run AyStar.
Definition at line 137 of file aystar.cpp.
References AYSTAR_EMPTY_OPENLIST, AYSTAR_FOUND_END_NODE, AYSTAR_LIMIT_REACHED, AYSTAR_NO_PATH, AYSTAR_STILL_BUSY, Debug, Loop(), and loops_per_tick.
|
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 25 of file aystar.cpp.
References CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::CreateNewNode(), and CNodeList_HashTableT< Titem_, Thash_bits_open_, Thash_bits_closed_ >::InsertOpenNode().
Referenced by AddStartNode(), and CheckTile().