1
0

Performance improvements and chunk flipping fixed

This commit is contained in:
Tiger Wang 2014-04-02 22:53:03 +01:00
parent 945631ba06
commit 357411a489

View File

@ -239,17 +239,15 @@ void cChunk::MarkLoadFailed(void)
void cChunk::GetAllData(cChunkDataCallback & a_Callback) void cChunk::GetAllData(cChunkDataCallback & a_Callback)
{ {
a_Callback.HeightMap (&m_HeightMap); a_Callback.HeightMap (&m_HeightMap);
a_Callback.BiomeData(&m_BiomeMap); a_Callback.BiomeData (&m_BiomeMap);
std::vector<BLOCKTYPE> Blocks; std::vector<BLOCKTYPE> Blocks;
Blocks.reserve(cChunkDef::NumBlocks); Blocks.reserve(cChunkDef::NumBlocks);
for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr)
{ {
for (std::vector<BLOCKTYPE>::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) Blocks.insert(Blocks.end(), itr->begin(), itr->end());
{
Blocks.push_back(*dataitr);
}
} }
a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockTypes (Blocks.data());
a_Callback.BlockMeta (m_BlockMeta); a_Callback.BlockMeta (m_BlockMeta);
a_Callback.LightIsValid (m_IsLightValid); a_Callback.LightIsValid (m_IsLightValid);
@ -272,56 +270,63 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback)
void cChunk::SetAllData( void cChunk::SetAllData(
const BLOCKTYPE * a_BlockTypes, const BLOCKTYPE * a_BlockTypes,
const NIBBLETYPE * a_BlockMeta, const NIBBLETYPE * a_BlockMeta,
const NIBBLETYPE * a_BlockLight, const NIBBLETYPE * a_BlockLight,
const NIBBLETYPE * a_BlockSkyLight, const NIBBLETYPE * a_BlockSkyLight,
const HeightMap * a_HeightMap, const HeightMap * a_HeightMap,
const BiomeMap & a_BiomeMap, const BiomeMap & a_BiomeMap,
cBlockEntityList & a_BlockEntities cBlockEntityList & a_BlockEntities
) )
{ {
memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap));
if (a_HeightMap != NULL) if (a_HeightMap != NULL)
{ {
memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap));
} }
bool FoundNonAir = false; bool FoundNonAir = false;
int PosYWhereNonEmptyStarts = 0;
m_BlockTypes.clear(); m_BlockTypes.clear();
for (int y = cChunkDef::Height - 1; y >= 0; y--) m_BlockTypes.reserve(Height / 2);
{
if (!FoundNonAir)
{
for (int x = 0; x < cChunkDef::Width; x++)
{
for (int z = 0; z < cChunkDef::Width; z++)
{
int Index = cChunkDef::MakeIndexNoCheck(x, y, z);
if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) for (int y = Height; y >= 0; y--)
{ {
FoundNonAir = true; for (int z = 0; z < Width; z++)
} {
for (int x = 0; x < Width; x++)
{
int Index = MakeIndexNoCheck(x, y, z);
if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR))
{
FoundNonAir = true;
PosYWhereNonEmptyStarts = y;
goto foundair;
} }
} }
} }
}
if (FoundNonAir) foundair:
if (FoundNonAir)
{
for (int y = 0; y <= PosYWhereNonEmptyStarts; y++)
{ {
std::vector<BLOCKTYPE> Blocks; std::vector<BLOCKTYPE> Blocks;
for (int x = 0; x < cChunkDef::Width; x++) Blocks.reserve(Width * Width);
for (int z = 0; z < Width; z++)
{ {
for (int z = 0; z < cChunkDef::Width; z++) for (int x = 0; x < Width; x++)
{ {
int Index = cChunkDef::MakeIndexNoCheck(x, y, z); int Index = MakeIndexNoCheck(x, y, z);
Blocks.insert(Blocks.begin(), a_BlockTypes[Index]); Blocks.push_back(a_BlockTypes[Index]);
} }
} }
m_BlockTypes.insert(m_BlockTypes.begin(), Blocks); m_BlockTypes.push_back(Blocks);
} } // for y
} // for y }
memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta));
if (a_BlockLight != NULL) if (a_BlockLight != NULL)
@ -391,10 +396,7 @@ void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes)
Blocks.reserve(cChunkDef::NumBlocks); Blocks.reserve(cChunkDef::NumBlocks);
for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr)
{ {
for (std::vector<BLOCKTYPE>::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) Blocks.insert(Blocks.end(), itr->begin(), itr->end());
{
Blocks.push_back(*dataitr);
}
} }
memcpy(a_BlockTypes, Blocks.data(), NumBlocks); memcpy(a_BlockTypes, Blocks.data(), NumBlocks);