1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-10-31 00:07:39 +02:00

CPathfinder::addNeighbours: avoid allocating new vector each time

This commit is contained in:
ArseniyShestakov
2015-11-22 07:32:33 +03:00
parent e1a360408d
commit 6dacb84404
2 changed files with 6 additions and 5 deletions

View File

@@ -53,6 +53,7 @@ CPathfinder::CPathfinder(CPathsInfo & _out, CGameState * _gs, const CGHeroInstan
hlp = make_unique<CPathfinderHelper>(hero, options);
initializeGraph();
neighbourTiles.reserve(8);
neighbours.reserve(16);
}
@@ -192,19 +193,18 @@ void CPathfinder::calculatePaths()
void CPathfinder::addNeighbours()
{
neighbours.clear();
std::vector<int3> tiles;
tiles.reserve(8);
CPathfinderHelper::getNeighbours(gs->map, *ct, cp->coord, tiles, boost::logic::indeterminate, cp->layer == ELayer::SAIL);
neighbourTiles.clear();
CPathfinderHelper::getNeighbours(gs->map, *ct, cp->coord, neighbourTiles, boost::logic::indeterminate, cp->layer == ELayer::SAIL);
if(isSourceVisitableObj())
{
for(int3 tile: tiles)
for(int3 tile: neighbourTiles)
{
if(canMoveBetween(tile, ctObj->visitablePos()))
neighbours.push_back(tile);
}
}
else
vstd::concatenate(neighbours, tiles);
vstd::concatenate(neighbours, neighbourTiles);
}
void CPathfinder::addTeleportExits()

View File

@@ -169,6 +169,7 @@ private:
};
boost::heap::priority_queue<CGPathNode *, boost::heap::compare<NodeComparer> > pq;
std::vector<int3> neighbourTiles;
std::vector<int3> neighbours;
CGPathNode * cp; //current (source) path node -> we took it from the queue