1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Reduced usage of TerrainViewPattern constructor for faster map generation.

This commit is contained in:
DjWarmonger 2014-07-24 20:36:52 +02:00
parent 156e19cdf6
commit c119ddf5ee
2 changed files with 10 additions and 6 deletions

View File

@ -638,10 +638,14 @@ ETerrainGroup::ETerrainGroup CDrawTerrainOperation::getTerrainGroup(ETerrainType
CDrawTerrainOperation::ValidationResult CDrawTerrainOperation::validateTerrainView(const int3 & pos, const TerrainViewPattern & pattern, int recDepth /*= 0*/) const
{
//constructor for pattern object is very expensive, but we can't manipulate const object :(
auto flippedPattern = pattern;
for(int flip = 0; flip < 4; ++flip)
{
auto valRslt = validateTerrainViewInner(pos, flip > 0 ? flipPattern(flippedPattern, flip) : pattern, recDepth);
if (flip > 0)
flipPattern (flippedPattern, flip);
auto valRslt = validateTerrainViewInner(pos, flippedPattern, recDepth);
if(valRslt.result)
{
valRslt.flip = flip;
@ -796,11 +800,13 @@ bool CDrawTerrainOperation::isSandType(ETerrainType terType) const
}
}
TerrainViewPattern CDrawTerrainOperation::flipPattern(TerrainViewPattern & pattern, int flip) const
void CDrawTerrainOperation::flipPattern(TerrainViewPattern & pattern, int flip) const
{
//flip in place to avoid expensive constructor. Seriously.
if(flip == 0)
{
return pattern;
return;
}
//always flip horizontal
@ -817,8 +823,6 @@ TerrainViewPattern CDrawTerrainOperation::flipPattern(TerrainViewPattern & patte
std::swap(pattern.data[i], pattern.data[6 + i]);
}
}
return pattern;
}
void CDrawTerrainOperation::invalidateTerrainViews(const int3 & centerPos)

View File

@ -334,7 +334,7 @@ private:
ValidationResult validateTerrainViewInner(const int3 & pos, const TerrainViewPattern & pattern, int recDepth = 0) const;
/// Tests whether the given terrain type is a sand type. Sand types are: Water, Sand and Rock
bool isSandType(ETerrainType terType) const;
TerrainViewPattern flipPattern(TerrainViewPattern & pattern, int flip) const;
void flipPattern(TerrainViewPattern & pattern, int flip) const;
static const int FLIP_PATTERN_HORIZONTAL = 1;
static const int FLIP_PATTERN_VERTICAL = 2;