Browse Source

Moar optimization!

DjWarmonger 9 years ago
parent
commit
2bffd4e5c1

+ 2 - 1
lib/mapObjects/ObjectTemplate.cpp

@@ -348,8 +348,9 @@ void ObjectTemplate::writeJson(JsonNode & node, const bool withTerrain) const
 ui32 ObjectTemplate::getWidth() const
 {
 	//TODO: Use 2D array
+	//TODO: better precalculate and store constant value
 	ui32 ret = 0;
-	for (auto row : usedTiles)
+	for (auto const &row : usedTiles) //copy is expensive
 	{
 		ret = std::max<ui32>(ret, row.size());
 	}

+ 1 - 0
lib/mapping/CMapEditManager.cpp

@@ -934,6 +934,7 @@ void CDrawTerrainOperation::invalidateTerrainViews(const int3 & centerPos)
 
 CDrawTerrainOperation::InvalidTiles CDrawTerrainOperation::getInvalidTiles(const int3 & centerPos) const
 {
+	//TODO: this is very expensive function for RMG, needs optimization
 	InvalidTiles tiles;
 	auto centerTerType = map->getTile(centerPos).terType;
 	auto rect = extendTileAround(centerPos);

+ 9 - 7
lib/rmg/CMapGenerator.cpp

@@ -479,6 +479,8 @@ void CMapGenerator::createConnections()
 
 		int3 posA = zoneA->getPos();
 		int3 posB = zoneB->getPos();
+		auto zoneAid = zoneA->getId();
+		auto zoneBid = zoneB->getId();
 
 		if (posA.z == posB.z)
 		{
@@ -487,9 +489,9 @@ void CMapGenerator::createConnections()
 			{
 				if (isBlocked(tile)) //tiles may be occupied by subterranean gates already placed
 					continue;
-				foreachDirectNeighbour (tile, [&guardPos, tile, &otherZoneTiles, &middleTiles, this](int3 &pos) //must be direct since paths also also generated between direct neighbours
+				foreachDirectNeighbour (tile, [&guardPos, tile, &otherZoneTiles, &middleTiles, this, zoneBid](int3 &pos) //must be direct since paths also also generated between direct neighbours
 				{
-					if (vstd::contains(otherZoneTiles, pos))
+					if (getZoneID(pos) == zoneBid)
 						middleTiles.push_back(tile);
 				});
 			}
@@ -572,18 +574,18 @@ void CMapGenerator::createConnections()
 					distanceFromB > 5 && (!posB.z || distanceFromB < zoneB->getSize() - 3))
 				{
 					//all neightbouring tiles also belong to zone
-					if (vstd::contains(tiles, tile) && vstd::contains(otherZoneTiles, otherTile))
+					if (getZoneID(tile) ==  zoneAid && getZoneID(otherTile) == zoneBid)
 					{
 						bool withinZone = true;
 
-						foreach_neighbour (tile, [&withinZone, &tiles](int3 &pos)
+						foreach_neighbour (tile, [&withinZone, &tiles, zoneAid, this](int3 &pos)
 						{
-							if (!vstd::contains(tiles, pos))
+							if (getZoneID(pos) != zoneAid)
 								withinZone = false;
 						});
-						foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles](int3 &pos)
+						foreach_neighbour (otherTile, [&withinZone, &otherZoneTiles, zoneBid, this](int3 &pos)
 						{
-							if (!vstd::contains(otherZoneTiles, pos))
+							if (getZoneID(pos) != zoneBid)
 								withinZone = false;
 						});
 

+ 2 - 1
lib/rmg/CRmgTemplateZone.cpp

@@ -2326,7 +2326,8 @@ ObjectInfo CRmgTemplateZone::getRandomObject(CMapGenerator* gen, CTreasurePileIn
 				continue;
 
 			total += oi.probability;
-			//assert (oi.value > 0);
+			
+			//FIXME: apparently this is quite expensive operation
 			thresholds.push_back (std::make_pair (total, oi));
 		}
 	}