1247: Optimize automapper a bit r=def- a=Aerll

Pretty simple yet super effective: 
If index rule has any `Pos 0 0` for non-empty tile, then it is flagged to skip all the empty tiles. And vice versa.

In many cases it will significantly speed up the process, especially when using big automappers on huge maps.

Co-authored-by: Aerll <31746984+aerll@users.noreply.github.com>
This commit is contained in:
bors[bot] 2018-08-11 09:26:27 +00:00
commit 6e0e127ff6
2 changed files with 37 additions and 9 deletions

View file

@ -75,6 +75,8 @@ void CAutoMapper::Load(const char* pTileName)
NewIndexRule.m_Flag = 0;
NewIndexRule.m_RandomProbability = 1.0;
NewIndexRule.m_DefaultRule = true;
NewIndexRule.m_SkipEmpty = false;
NewIndexRule.m_SkipFull = false;
if(str_length(aOrientation1) > 0)
{
@ -221,6 +223,16 @@ void CAutoMapper::Load(const char* pTileName)
if(Value != CPosRule::NORULE) {
CPosRule NewPosRule = {x, y, Value, NewIndexList};
pCurrentIndex->m_aRules.add(NewPosRule);
if(x == 0 && y == 0) {
for(int i = 0; i < NewIndexList.size(); ++i)
{
if(Value == CPosRule::INDEX && NewIndexList[i].m_ID == 0)
pCurrentIndex->m_SkipFull = true;
else
pCurrentIndex->m_SkipEmpty = true;
}
}
}
}
else if(str_startswith(pLine, "Random") && pCurrentIndex)
@ -255,23 +267,31 @@ void CAutoMapper::Load(const char* pTileName)
{
for(int i = 0; i < m_lConfigs[g].m_aRuns[h].m_aIndexRules.size(); ++i)
{
CIndexRule *pIndexRule = &m_lConfigs[g].m_aRuns[h].m_aIndexRules[i];
bool Found = false;
for(int j = 0; j < m_lConfigs[g].m_aRuns[h].m_aIndexRules[i].m_aRules.size(); ++j)
for(int j = 0; j < pIndexRule->m_aRules.size(); ++j)
{
CPosRule *pRule = &m_lConfigs[g].m_aRuns[h].m_aIndexRules[i].m_aRules[j];
CPosRule *pRule = &pIndexRule->m_aRules[j];
if(pRule && pRule->m_X == 0 && pRule->m_Y == 0)
{
Found = true;
break;
}
}
if(!Found && m_lConfigs[g].m_aRuns[h].m_aIndexRules[i].m_DefaultRule)
if(!Found && pIndexRule->m_DefaultRule)
{
array<CIndexInfo> NewIndexList;
CIndexInfo NewIndexInfo = {0, 0, false};
NewIndexList.add(NewIndexInfo);
CPosRule NewPosRule = {0, 0, CPosRule::NOTINDEX, NewIndexList};
m_lConfigs[g].m_aRuns[h].m_aIndexRules[i].m_aRules.add(NewPosRule);
pIndexRule->m_aRules.add(NewPosRule);
pIndexRule->m_SkipEmpty = true;
pIndexRule->m_SkipFull = false;
}
if(pIndexRule->m_SkipEmpty && pIndexRule->m_SkipFull)
{
pIndexRule->m_SkipFull = false;
}
}
}
@ -338,10 +358,16 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID)
for(int i = 0; i < pRun->m_aIndexRules.size(); ++i)
{
CIndexRule *pIndexRule = &pRun->m_aIndexRules[i];
if(pIndexRule->m_SkipEmpty && pTile->m_Index == 0) // skip empty tiles
continue;
if(pIndexRule->m_SkipFull && pTile->m_Index != 0) // skip full tiles
continue;
bool RespectRules = true;
for(int j = 0; j < pRun->m_aIndexRules[i].m_aRules.size() && RespectRules; ++j)
for(int j = 0; j < pIndexRule->m_aRules.size() && RespectRules; ++j)
{
CPosRule *pRule = &pRun->m_aIndexRules[i].m_aRules[j];
CPosRule *pRule = &pIndexRule->m_aRules[j];
int CheckIndex, CheckFlags;
int CheckX = x + pRule->m_X;
@ -379,10 +405,10 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID)
}
if(RespectRules &&
(pRun->m_aIndexRules[i].m_RandomProbability >= 1.0 || (float)rand() / ((float)RAND_MAX + 1) < pRun->m_aIndexRules[i].m_RandomProbability))
(pIndexRule->m_RandomProbability >= 1.0 || (float)rand() / ((float)RAND_MAX + 1) < pIndexRule->m_RandomProbability))
{
pTile->m_Index = pRun->m_aIndexRules[i].m_ID;
pTile->m_Flags = pRun->m_aIndexRules[i].m_Flag;
pTile->m_Index = pIndexRule->m_ID;
pTile->m_Flags = pIndexRule->m_Flag;
}
}
}

View file

@ -34,6 +34,8 @@ class CAutoMapper
int m_Flag;
float m_RandomProbability;
bool m_DefaultRule;
bool m_SkipEmpty;
bool m_SkipFull;
};
struct CRun