Reserving space in vector instead of resizing it.

This commit is contained in:
2024-06-07 20:28:45 +02:00
parent 6c146078ec
commit f5fff89992
2 changed files with 2 additions and 8 deletions

View File

@@ -14,8 +14,6 @@ using std::vector;
static const int STRAIGHT_DISTANCE = 10;
static const int DIAGONAL_DISTANCE = 14;
Node::Node() { }
Node::Node(int x, int y)
{
this->hasUnit = false;
@@ -153,14 +151,13 @@ void MultilevelAStarEx::init(const Rect2i &region)
_height = region.get_size().height;
_trans = region.get_position();
_nodes.resize(_width * _height);
_nodes.reserve(_width * _height);
vector<Node>::iterator iter = _nodes.begin();
for (int y = 0; y < _height; y++)
{
for (int x = 0; x < _width; x++)
{
*iter++ = Node(x, y);
_nodes.push_back(Node(x, y));
}
}

View File

@@ -44,9 +44,6 @@ private:
void close(int pass);
NodeState state(int pass) const;
int total_cost() const;
public:
Node();
};
class MultilevelAStarEx : public godot::RefCounted