mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use std::vector for the available neighbours
parent
2864f3b3eb
commit
31085230a6
|
@ -1223,13 +1223,13 @@ static void River_GetNeighbours(AyStar *aystar, PathNode *current)
|
|||
{
|
||||
TileIndex tile = current->GetTile();
|
||||
|
||||
aystar->num_neighbours = 0;
|
||||
aystar->neighbours.clear();
|
||||
for (DiagDirection d = DIAGDIR_BEGIN; d < DIAGDIR_END; d++) {
|
||||
TileIndex t2 = tile + TileOffsByDiagDir(d);
|
||||
if (IsValidTile(t2) && FlowsDown(tile, t2)) {
|
||||
aystar->neighbours[aystar->num_neighbours].m_tile = t2;
|
||||
aystar->neighbours[aystar->num_neighbours].m_td = INVALID_TRACKDIR;
|
||||
aystar->num_neighbours++;
|
||||
auto &neighbour = aystar->neighbours.emplace_back();
|
||||
neighbour.m_tile = t2;
|
||||
neighbour.m_td = INVALID_TRACKDIR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,9 +111,9 @@ int AyStar::Loop()
|
|||
this->GetNeighbours(this, current);
|
||||
|
||||
/* Go through all neighbours */
|
||||
for (int i = 0; i < this->num_neighbours; i++) {
|
||||
for (auto &neighbour : this->neighbours) {
|
||||
/* Check and add them to the OpenList if needed */
|
||||
this->CheckTile(&this->neighbours[i], current);
|
||||
this->CheckTile(&neighbour, current);
|
||||
}
|
||||
|
||||
if (this->max_search_nodes != 0 && this->nodes.ClosedCount() >= this->max_search_nodes) {
|
||||
|
|
|
@ -125,10 +125,8 @@ struct AyStar {
|
|||
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 */
|
||||
AyStarNode neighbours[12];
|
||||
uint8_t num_neighbours;
|
||||
/* These should be filled with the neighbours of a tile by GetNeighbours */
|
||||
std::vector<AyStarNode> neighbours;
|
||||
|
||||
/* These will contain the methods for manipulating the AyStar. Only
|
||||
* Main() should be called externally */
|
||||
|
|
Loading…
Reference in New Issue