소스 검색

Some more optimization.

DjWarmonger 11 년 전
부모
커밋
ec54381b12
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      lib/CGameState.cpp

+ 3 - 1
lib/CGameState.cpp

@@ -2094,6 +2094,7 @@ void CGameState::getNeighbours(const TerrainTile &srct, int3 tile, std::vector<i
 	static const int3 dirs[] = { int3(0,1,0),int3(0,-1,0),int3(-1,0,0),int3(+1,0,0),
 					int3(1,1,0),int3(-1,1,0),int3(1,-1,0),int3(-1,-1,0) };
 
+	//vec.reserve(8); //optimization
 	for (auto & dir : dirs)
 	{
 		const int3 hlp = tile + dir;
@@ -2171,6 +2172,7 @@ int CGameState::getMovementCost(const CGHeroInstance *h, const int3 &src, const
 	if(checkLast  &&  left > 0  &&  remainingMovePoints-ret < 250) //it might be the last tile - if no further move possible we take all move points
 	{
 		std::vector<int3> vec;
+		vec.reserve(8); //optimization
         getNeighbours(d, dest, vec, s.terType != ETerrainType::WATER, true);
 		for(auto & elem : vec)
 		{
@@ -2286,7 +2288,7 @@ int3 CGameState::guardingCreaturePosition (int3 pos) const
 				{
 					for (CGObjectInstance* obj : tile.visitableObjects)
 					{
-						if (obj->ID == Obj::MONSTER  &&  checkForVisitableDir(pos, &map->getTile(originalPos), originalPos)) // Monster being able to attack investigated tile
+						if (obj->ID == Obj::MONSTER  &&  checkForVisitableDir(pos, &posTile, originalPos)) // Monster being able to attack investigated tile
 						{
 							return pos;
 						}