mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Moar optimization!
This commit is contained in:
parent
7f0b852449
commit
2bffd4e5c1
@ -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());
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
});
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user