diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-04-04 14:01:05 +0200 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-04-04 14:01:05 +0200 |
commit | 15a0ceec2687c04191c41f7b103c26aeb98705ca (patch) | |
tree | 413b663cef87fbef4c09fa33aa5b1a85da8dbadb | |
parent | Merge remote-tracking branch 'origin/master' into chunkysparsing (diff) | |
download | cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar.gz cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar.bz2 cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar.lz cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar.xz cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.tar.zst cuberite-15a0ceec2687c04191c41f7b103c26aeb98705ca.zip |
-rw-r--r-- | src/Chunk.cpp | 75 | ||||
-rw-r--r-- | src/Chunk.h | 2 |
2 files changed, 15 insertions, 62 deletions
diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6e6b7ed20..c2caafe45 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -241,12 +241,7 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - std::vector<BLOCKTYPE> Blocks; - Blocks.reserve(NumBlocks); - for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector<BLOCKTYPE> Blocks = m_BlockTypes; Blocks.resize(NumBlocks); a_Callback.BlockTypes (Blocks.data()); @@ -288,46 +283,20 @@ void cChunk::SetAllData( } bool FoundNonAir = false; - int PosYWhereNonEmptyStarts = 0; + int IdxWhereNonEmptyStarts = 0; m_BlockTypes.clear(); - m_BlockTypes.reserve(Height / 2); - for (int y = Height - 1; y >= 0; y--) + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) { - for (int z = 0; z < Width; z++) + if (a_BlockTypes[Idx] != E_BLOCK_AIR) { - 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; - } - } + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; } } -foundair: - if (FoundNonAir) - { - for (int y = 0; y <= PosYWhereNonEmptyStarts; y++) - { - std::vector<BLOCKTYPE> Blocks; - Blocks.reserve(Width * Width); - for (int z = 0; z < Width; z++) - { - for (int x = 0; x < Width; x++) - { - int Index = MakeIndexNoCheck(x, y, z); - Blocks.push_back(a_BlockTypes[Index]); - } - } - m_BlockTypes.push_back(Blocks); - } // for y - } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) @@ -393,12 +362,7 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - std::vector<BLOCKTYPE> Blocks; - Blocks.reserve(NumBlocks); - for (std::vector<std::vector<BLOCKTYPE>>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector<BLOCKTYPE> Blocks = m_BlockTypes; Blocks.resize(NumBlocks); memcpy(a_BlockTypes, Blocks.data(), NumBlocks); @@ -1581,21 +1545,13 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT } MarkDirty(); - - int Layer = (int)index / (cChunkDef::Width * cChunkDef::Width); - int SubBlock = index % ((cChunkDef::Width * cChunkDef::Width) - 1); - if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { - m_BlockTypes.reserve(Layer - ((int)m_BlockTypes.size() - 1)); - std::vector<BLOCKTYPE> EmptyBlocks(cChunkDef::Width * cChunkDef::Width); - for (int lyr = ((int)m_BlockTypes.size() - 1); lyr <= Layer; ++lyr) - { - m_BlockTypes.push_back(EmptyBlocks); - } + m_BlockTypes.resize(index); } - m_BlockTypes[Layer][SubBlock] = a_BlockType; + m_BlockTypes[index] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: if ( @@ -2536,15 +2492,12 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - int Layer = (int)a_BlockIdx / (cChunkDef::Width * cChunkDef::Width); - int SubBlock = a_BlockIdx % ((cChunkDef::Width * cChunkDef::Width) - 1); - - if (m_BlockTypes.empty() || (Layer > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || (a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { return E_BLOCK_AIR; } - return m_BlockTypes[Layer][SubBlock]; + return m_BlockTypes[a_BlockIdx]; } diff --git a/src/Chunk.h b/src/Chunk.h index 1b83bc540..ef6a11006 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -421,7 +421,7 @@ private: cChunkMap * m_ChunkMap; // TODO: Make these pointers and don't allocate what isn't needed - std::vector<std::vector<BLOCKTYPE>> m_BlockTypes; + std::vector<BLOCKTYPE> m_BlockTypes; NIBBLETYPE m_BlockMeta [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockLight [cChunkDef::NumBlocks / 2]; NIBBLETYPE m_BlockSkyLight[cChunkDef::NumBlocks / 2]; |