mirror of https://github.com/OpenTTD/OpenTTD
Codechange: Remove unused options from AyStar.
parent
53899c3c21
commit
97ead8e241
|
@ -49,7 +49,6 @@ void AyStar::CheckTile(AyStarNode *current, PathNode *parent)
|
||||||
assert(new_g >= 0);
|
assert(new_g >= 0);
|
||||||
/* Add the parent g-value to the new g-value */
|
/* Add the parent g-value to the new g-value */
|
||||||
new_g += parent->cost;
|
new_g += parent->cost;
|
||||||
if (this->max_path_cost != 0 && new_g > this->max_path_cost) return;
|
|
||||||
|
|
||||||
/* Calculate the h-value */
|
/* Calculate the h-value */
|
||||||
int new_h = this->CalculateH(this, current, parent);
|
int new_h = this->CalculateH(this, current, parent);
|
||||||
|
@ -116,7 +115,7 @@ AyStarStatus AyStar::Loop()
|
||||||
this->CheckTile(&neighbour, current);
|
this->CheckTile(&neighbour, current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->max_search_nodes != 0 && this->nodes.ClosedCount() >= this->max_search_nodes) {
|
if (this->nodes.ClosedCount() >= AYSTAR_DEF_MAX_SEARCH_NODES) {
|
||||||
/* We've expanded enough nodes */
|
/* We've expanded enough nodes */
|
||||||
return AyStarStatus::LimitReached;
|
return AyStarStatus::LimitReached;
|
||||||
} else {
|
} else {
|
||||||
|
@ -131,16 +130,13 @@ AyStarStatus AyStar::Loop()
|
||||||
* - #AyStarStatus::FoundEndNode
|
* - #AyStarStatus::FoundEndNode
|
||||||
* - #AyStarStatus::NoPath
|
* - #AyStarStatus::NoPath
|
||||||
* - #AyStarStatus::StillBusy
|
* - #AyStarStatus::StillBusy
|
||||||
* @note When the algorithm is done (when the return value is not #AyStarStatus::StillBusy) #Clear() is called automatically.
|
|
||||||
* When you stop the algorithm halfway, you should call #Clear() yourself!
|
|
||||||
*/
|
*/
|
||||||
AyStarStatus AyStar::Main()
|
AyStarStatus AyStar::Main()
|
||||||
{
|
{
|
||||||
AyStarStatus r = AyStarStatus::FoundEndNode;
|
AyStarStatus r;
|
||||||
int i = 0;
|
do {
|
||||||
/* Loop through the OpenList
|
r = this->Loop();
|
||||||
* Quit if result is no AyStarStatus::StillBusy or is more than loops_per_tick */
|
} while (r == AyStarStatus::StillBusy);
|
||||||
while ((r = this->Loop()) == AyStarStatus::StillBusy && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { }
|
|
||||||
#ifdef AYSTAR_DEBUG
|
#ifdef AYSTAR_DEBUG
|
||||||
switch (r) {
|
switch (r) {
|
||||||
case AyStarStatus::FoundEndNode: Debug(misc, 0, "[AyStar] Found path!"); break;
|
case AyStarStatus::FoundEndNode: Debug(misc, 0, "[AyStar] Found path!"); break;
|
||||||
|
@ -160,9 +156,7 @@ AyStarStatus AyStar::Main()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a node from where to start an algorithm. Multiple nodes can be added
|
* 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 wanted.
|
||||||
* if the #AyStar has been used before (though the normal main loop calls
|
|
||||||
* #Clear() automatically when the algorithm finishes.
|
|
||||||
* @param start_node Node to start with.
|
* @param start_node Node to start with.
|
||||||
* @param g the cost for starting with this node.
|
* @param g the cost for starting with this node.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -27,7 +27,7 @@ enum class AyStarStatus : uint8_t {
|
||||||
EmptyOpenList, ///< All items are tested, and no path has been found.
|
EmptyOpenList, ///< All items are tested, and no path has been found.
|
||||||
StillBusy, ///< Some checking was done, but no path found yet, and there are still items left to try.
|
StillBusy, ///< Some checking was done, but no path found yet, and there are still items left to try.
|
||||||
NoPath, ///< No path to the goal was found.
|
NoPath, ///< No path to the goal was found.
|
||||||
LimitReached, ///< The #AyStar::max_search_nodes limit has been reached, aborting search.
|
LimitReached, ///< The AYSTAR_DEF_MAX_SEARCH_NODES limit has been reached, aborting search.
|
||||||
Done, ///< Not an end-tile, or wrong direction.
|
Done, ///< Not an end-tile, or wrong direction.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -113,10 +113,6 @@ struct AyStar {
|
||||||
void *user_target;
|
void *user_target;
|
||||||
void *user_data;
|
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.
|
|
||||||
|
|
||||||
/* These should be filled with the neighbours of a tile by GetNeighbours */
|
/* These should be filled with the neighbours of a tile by GetNeighbours */
|
||||||
std::vector<AyStarNode> neighbours;
|
std::vector<AyStarNode> neighbours;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue