Reserving space in vector instead of resizing it.
This commit is contained in:
@@ -14,8 +14,6 @@ using std::vector;
|
|||||||
static const int STRAIGHT_DISTANCE = 10;
|
static const int STRAIGHT_DISTANCE = 10;
|
||||||
static const int DIAGONAL_DISTANCE = 14;
|
static const int DIAGONAL_DISTANCE = 14;
|
||||||
|
|
||||||
Node::Node() { }
|
|
||||||
|
|
||||||
Node::Node(int x, int y)
|
Node::Node(int x, int y)
|
||||||
{
|
{
|
||||||
this->hasUnit = false;
|
this->hasUnit = false;
|
||||||
@@ -153,14 +151,13 @@ void MultilevelAStarEx::init(const Rect2i ®ion)
|
|||||||
_height = region.get_size().height;
|
_height = region.get_size().height;
|
||||||
_trans = region.get_position();
|
_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 y = 0; y < _height; y++)
|
||||||
{
|
{
|
||||||
for (int x = 0; x < _width; x++)
|
for (int x = 0; x < _width; x++)
|
||||||
{
|
{
|
||||||
*iter++ = Node(x, y);
|
_nodes.push_back(Node(x, y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,6 @@ private:
|
|||||||
void close(int pass);
|
void close(int pass);
|
||||||
NodeState state(int pass) const;
|
NodeState state(int pass) const;
|
||||||
int total_cost() const;
|
int total_cost() const;
|
||||||
|
|
||||||
public:
|
|
||||||
Node();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MultilevelAStarEx : public godot::RefCounted
|
class MultilevelAStarEx : public godot::RefCounted
|
||||||
|
|||||||
Reference in New Issue
Block a user