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:
		| @@ -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() | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user