Optimized MultilevelAStarEx::generate_path()
This commit is contained in:
@@ -222,11 +222,19 @@ bool MultilevelAStarEx::can_move(const Node *current, int x, int y) const
|
||||
|
||||
TypedArray<Vector2i> MultilevelAStarEx::generate_path(const Node *current) const
|
||||
{
|
||||
TypedArray<Vector2i> arr;
|
||||
// count the number of nodes in the path
|
||||
int cnt = 0;
|
||||
for (const Node *n = current; n != nullptr; n = n->parent) cnt++;
|
||||
|
||||
cnt--; // because we're not adding the starting node
|
||||
|
||||
TypedArray<Vector2i> arr;
|
||||
arr.resize(cnt);
|
||||
|
||||
int i = cnt;
|
||||
while (current->parent != nullptr)
|
||||
{
|
||||
arr.insert(0, Vector2i(current->x, current->y) + _trans);
|
||||
arr[--cnt] = Vector2i(current->x, current->y) + _trans;
|
||||
current = current->parent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user