1
0

cLightingThread: Faster chunk reading (#4185)

Profiled at a 10x speedup for cLightingThread::ReadChunks.
This commit is contained in:
peterbell10 2018-02-21 10:30:48 +00:00 committed by GitHub
parent 1ea36298d2
commit 999faa9d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,21 +20,31 @@ class cReader :
virtual void ChunkData(const cChunkData & a_ChunkBuffer) override
{
BLOCKTYPE * OutputRows = m_BlockTypes;
int InputIdx = 0;
int OutputIdx = m_ReadingChunkX + m_ReadingChunkZ * cChunkDef::Width * 3;
int MaxHeight = std::min(+cChunkDef::Height, m_MaxHeight + 16); // Need 16 blocks above the highest
for (int y = 0; y < MaxHeight; y++)
for (size_t i = 0; i != cChunkData::NumSections; ++i)
{
for (int z = 0; z < cChunkDef::Width; z++)
auto * Section = a_ChunkBuffer.GetSection(i);
if (Section == nullptr)
{
a_ChunkBuffer.CopyBlockTypes(OutputRows + OutputIdx * 16, static_cast<size_t>(InputIdx * 16), 16);
InputIdx++;
OutputIdx += 3;
} // for z
// Skip into the next y-level in the 3x3 chunk blob; each level has cChunkDef::Width * 9 rows
// We've already walked cChunkDef::Width * 3 in the "for z" cycle, that makes cChunkDef::Width * 6 rows left to skip
OutputIdx += cChunkDef::Width * 6;
} // for y
// Skip to the next section
OutputIdx += 9 * cChunkData::SectionHeight * cChunkDef::Width;
continue;
}
for (size_t OffsetY = 0; OffsetY != cChunkData::SectionHeight; ++OffsetY)
{
for (size_t Z = 0; Z != cChunkDef::Width; ++Z)
{
auto InPtr = Section->m_BlockTypes + Z * cChunkDef::Width + OffsetY * cChunkDef::Width * cChunkDef::Width;
std::copy_n(InPtr, cChunkDef::Width, OutputRows + OutputIdx * cChunkDef::Width);
OutputIdx += 3;
}
// Skip into the next y-level in the 3x3 chunk blob; each level has cChunkDef::Width * 9 rows
// We've already walked cChunkDef::Width * 3 in the "for z" cycle, that makes cChunkDef::Width * 6 rows left to skip
OutputIdx += cChunkDef::Width * 6;
}
}
} // BlockTypes()
@ -78,6 +88,7 @@ public:
m_BlockTypes(a_BlockTypes),
m_HeightMap(a_HeightMap)
{
std::fill_n(m_BlockTypes, cChunkDef::NumBlocks * 9, E_BLOCK_AIR);
}
} ;