From 945631ba06fcba24c84017f36544667299c591fb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 23 Mar 2014 14:34:19 +0000 Subject: Sort of implementation of chunk sparsing Issues: * Chunks are flipped * Slow/inefficient/badly coded * Only blocktypes are 'compressed' --- src/Chunk.cpp | 109 +++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 92 insertions(+), 17 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 957d7d575..adbe94cd0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -239,8 +239,18 @@ void cChunk::MarkLoadFailed(void) void cChunk::GetAllData(cChunkDataCallback & a_Callback) { a_Callback.HeightMap (&m_HeightMap); - a_Callback.BiomeData (&m_BiomeMap); - a_Callback.BlockTypes (m_BlockTypes); + a_Callback.BiomeData(&m_BiomeMap); + + std::vector Blocks; + Blocks.reserve(cChunkDef::NumBlocks); + for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) + { + for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) + { + Blocks.push_back(*dataitr); + } + } + a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); a_Callback.LightIsValid (m_IsLightValid); a_Callback.BlockLight (m_BlockLight); @@ -277,8 +287,42 @@ void cChunk::SetAllData( { memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } + + bool FoundNonAir = false; + m_BlockTypes.clear(); + for (int y = cChunkDef::Height - 1; y >= 0; y--) + { + 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)) + { + FoundNonAir = true; + } + } + } + } + + if (FoundNonAir) + { + std::vector Blocks; + for (int x = 0; x < cChunkDef::Width; x++) + { + for (int z = 0; z < cChunkDef::Width; z++) + { + int Index = cChunkDef::MakeIndexNoCheck(x, y, z); + Blocks.insert(Blocks.begin(), a_BlockTypes[Index]); + } + } + m_BlockTypes.insert(m_BlockTypes.begin(), Blocks); + } + } // for y - memcpy(m_BlockTypes, a_BlockTypes, sizeof(m_BlockTypes)); memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) { @@ -343,7 +387,17 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - memcpy(a_BlockTypes, m_BlockTypes, NumBlocks); + std::vector Blocks; + Blocks.reserve(cChunkDef::NumBlocks); + for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) + { + for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) + { + Blocks.push_back(*dataitr); + } + } + + memcpy(a_BlockTypes, Blocks.data(), NumBlocks); } @@ -630,7 +684,7 @@ void cChunk::Tick(float a_Dt) void cChunk::TickBlock(int a_RelX, int a_RelY, int a_RelZ) { unsigned Index = MakeIndex(a_RelX, a_RelY, a_RelZ); - cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); + cBlockHandler * Handler = BlockHandler(GetBlock(Index)); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 cChunkInterface ChunkInterface(this->GetWorld()->GetChunkMap()); cBlockInServerPluginInterface PluginInterface(*this->GetWorld()); @@ -811,7 +865,7 @@ void cChunk::TickBlocks(void) } unsigned int Index = MakeIndexNoCheck(m_BlockTickX, m_BlockTickY, m_BlockTickZ); - cBlockHandler * Handler = BlockHandler(m_BlockTypes[Index]); + cBlockHandler * Handler = BlockHandler(GetBlock(Index)); ASSERT(Handler != NULL); // Happenned on server restart, FS #243 Handler->OnUpdate(ChunkInterface, *this->GetWorld(), PluginInterface, *this, m_BlockTickX, m_BlockTickY, m_BlockTickZ); } // for i - tickblocks @@ -1296,7 +1350,7 @@ void cChunk::CreateBlockEntities(void) { for (int y = 0; y < Height; y++) { - BLOCKTYPE BlockType = cChunkDef::GetBlock(m_BlockTypes, x, y, z); + BLOCKTYPE BlockType = GetBlock(x, y, z); switch (BlockType) { case E_BLOCK_CHEST: @@ -1348,7 +1402,7 @@ void cChunk::WakeUpSimulators(void) int BlockZ = z + BaseZ; for (int y = GetHeight(x, z); y >= 0; y--) { - BLOCKTYPE Block = cChunkDef::GetBlock(m_BlockTypes, x, y, z); + BLOCKTYPE Block = GetBlock(x, y, z); // The redstone sim takes multiple blocks, use the inbuilt checker if (RedstoneSimulator->IsAllowedBlock(Block)) @@ -1392,7 +1446,7 @@ void cChunk::CalculateHeightmap() for (int y = Height - 1; y > -1; y--) { int index = MakeIndex( x, y, z ); - if (m_BlockTypes[index] != E_BLOCK_AIR) + if (GetBlock(index) != E_BLOCK_AIR) { m_HeightMap[x + z * Width] = (unsigned char)y; break; @@ -1515,7 +1569,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT ASSERT(IsValid()); const int index = MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - const BLOCKTYPE OldBlockType = cChunkDef::GetBlock(m_BlockTypes, index); + const BLOCKTYPE OldBlockType = GetBlock(index); const BLOCKTYPE OldBlockMeta = GetNibble(m_BlockMeta, index); if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta)) { @@ -1524,7 +1578,20 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - m_BlockTypes[index] = a_BlockType; + 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 */) + { + m_BlockTypes.reserve(Layer - ((int)m_BlockTypes.size() - 1)); + std::vector EmptyBlocks(cChunkDef::Width * cChunkDef::Width); + for (int lyr = ((int)m_BlockTypes.size() - 1); lyr <= Layer; ++lyr) + { + m_BlockTypes.push_back(EmptyBlocks); + } + } + + m_BlockTypes[Layer][SubBlock] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: if ( @@ -1563,7 +1630,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT { for (int y = a_RelY - 1; y > 0; --y) { - if (m_BlockTypes[MakeIndexNoCheck(a_RelX, y, a_RelZ)] != E_BLOCK_AIR) + if (GetBlock(MakeIndexNoCheck(a_RelX, y, a_RelZ)) != E_BLOCK_AIR) { m_HeightMap[a_RelX + a_RelZ * Width] = (unsigned char)y; break; @@ -2450,7 +2517,7 @@ BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const return 0; // Clip } - return m_BlockTypes[MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ)]; + return GetBlock(MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ)); } @@ -2464,8 +2531,16 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const ASSERT(!"GetBlock(idx) out of bounds!"); return 0; } - - return m_BlockTypes[ a_BlockIdx ]; + + 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 */) + { + return E_BLOCK_AIR; + } + + return m_BlockTypes[Layer][SubBlock]; } @@ -2475,7 +2550,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockType = GetBlock(Idx); a_BlockMeta = cChunkDef::GetNibble(m_BlockMeta, Idx); } @@ -2486,7 +2561,7 @@ void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_ void cChunk::GetBlockInfo(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight) { int Idx = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY, a_RelZ); - a_BlockType = cChunkDef::GetBlock (m_BlockTypes, Idx); + a_BlockType = GetBlock(Idx); a_Meta = cChunkDef::GetNibble(m_BlockMeta, Idx); a_SkyLight = cChunkDef::GetNibble(m_BlockSkyLight, Idx); a_BlockLight = cChunkDef::GetNibble(m_BlockLight, Idx); -- cgit v1.2.3 From 357411a48978d6a672e4694edfa1ff87d57cfcfb Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Wed, 2 Apr 2014 22:53:03 +0100 Subject: Performance improvements and chunk flipping fixed --- src/Chunk.cpp | 62 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index adbe94cd0..a73bf7ca9 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -239,17 +239,15 @@ void cChunk::MarkLoadFailed(void) void cChunk::GetAllData(cChunkDataCallback & a_Callback) { a_Callback.HeightMap (&m_HeightMap); - a_Callback.BiomeData(&m_BiomeMap); + a_Callback.BiomeData (&m_BiomeMap); std::vector Blocks; Blocks.reserve(cChunkDef::NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { - for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) - { - Blocks.push_back(*dataitr); - } + Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); a_Callback.LightIsValid (m_IsLightValid); @@ -272,56 +270,63 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) void cChunk::SetAllData( - const BLOCKTYPE * a_BlockTypes, + const BLOCKTYPE * a_BlockTypes, const NIBBLETYPE * a_BlockMeta, const NIBBLETYPE * a_BlockLight, const NIBBLETYPE * a_BlockSkyLight, const HeightMap * a_HeightMap, const BiomeMap & a_BiomeMap, cBlockEntityList & a_BlockEntities -) + ) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); - + if (a_HeightMap != NULL) { memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } bool FoundNonAir = false; + int PosYWhereNonEmptyStarts = 0; m_BlockTypes.clear(); - for (int y = cChunkDef::Height - 1; y >= 0; y--) + m_BlockTypes.reserve(Height / 2); + + for (int y = Height; y >= 0; y--) { - if (!FoundNonAir) + for (int z = 0; z < Width; z++) { - for (int x = 0; x < cChunkDef::Width; x++) + for (int x = 0; x < Width; x++) { - for (int z = 0; z < cChunkDef::Width; z++) - { - int Index = cChunkDef::MakeIndexNoCheck(x, y, z); + int Index = MakeIndexNoCheck(x, y, z); - if (!FoundNonAir && (a_BlockTypes[Index] != E_BLOCK_AIR)) - { - FoundNonAir = true; - } + 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 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); - Blocks.insert(Blocks.begin(), a_BlockTypes[Index]); + int Index = MakeIndexNoCheck(x, y, z); + Blocks.push_back(a_BlockTypes[Index]); } } - m_BlockTypes.insert(m_BlockTypes.begin(), Blocks); - } - } // for y + m_BlockTypes.push_back(Blocks); + } // for y + } memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) @@ -391,10 +396,7 @@ void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) Blocks.reserve(cChunkDef::NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { - for (std::vector::const_iterator dataitr = itr->begin(); dataitr != itr->end(); ++dataitr) - { - Blocks.push_back(*dataitr); - } + Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } memcpy(a_BlockTypes, Blocks.data(), NumBlocks); -- cgit v1.2.3 From d5faf5a38ebe164d705cc67baaa4b3c9d7eb6159 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 3 Apr 2014 19:17:04 +0100 Subject: Fixed some bugs * Fixed undefined behaviour * Fixed compression failure --- src/Chunk.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a73bf7ca9..d80e93702 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -242,11 +242,12 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.BiomeData (&m_BiomeMap); std::vector Blocks; - Blocks.reserve(cChunkDef::NumBlocks); + Blocks.reserve(NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + Blocks.resize(NumBlocks); a_Callback.BlockTypes (Blocks.data()); a_Callback.BlockMeta (m_BlockMeta); @@ -291,7 +292,7 @@ void cChunk::SetAllData( m_BlockTypes.clear(); m_BlockTypes.reserve(Height / 2); - for (int y = Height; y >= 0; y--) + for (int y = Height - 1; y >= 0; y--) { for (int z = 0; z < Width; z++) { @@ -393,11 +394,12 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { std::vector Blocks; - Blocks.reserve(cChunkDef::NumBlocks); + Blocks.reserve(NumBlocks); for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) { Blocks.insert(Blocks.end(), itr->begin(), itr->end()); } + Blocks.resize(NumBlocks); memcpy(a_BlockTypes, Blocks.data(), NumBlocks); } -- cgit v1.2.3 From 15a0ceec2687c04191c41f7b103c26aeb98705ca Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 4 Apr 2014 13:01:05 +0100 Subject: Speed and memory improvements * Changed array to be continuous, so no more layer splitting --- src/Chunk.cpp | 75 +++++++++++------------------------------------------------ 1 file changed, 14 insertions(+), 61 deletions(-) (limited to 'src/Chunk.cpp') 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 Blocks; - Blocks.reserve(NumBlocks); - for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector 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 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 Blocks; - Blocks.reserve(NumBlocks); - for (std::vector>::const_iterator itr = m_BlockTypes.begin(); itr != m_BlockTypes.end(); ++itr) - { - Blocks.insert(Blocks.end(), itr->begin(), itr->end()); - } + std::vector 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 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]; } -- cgit v1.2.3 From 3201d1bf169ca99e4cdbfad7601f6aed89b3c76c Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 4 Apr 2014 23:16:52 +0100 Subject: Nibbletypes are compressed + Added nibble compression * Fixed an off by one --- src/Chunk.cpp | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index c2caafe45..97822048d 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -243,9 +243,12 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - a_Callback.BlockTypes (Blocks.data()); - a_Callback.BlockMeta (m_BlockMeta); + + std::vector Metas = m_BlockMeta; + Metas.resize(NumBlocks / 2); + a_Callback.BlockMeta (Metas.data()); + a_Callback.LightIsValid (m_IsLightValid); a_Callback.BlockLight (m_BlockLight); a_Callback.BlockSkyLight(m_BlockSkyLight); @@ -282,23 +285,40 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } - bool FoundNonAir = false; - int IdxWhereNonEmptyStarts = 0; - m_BlockTypes.clear(); + { // Blocktype compression + bool FoundNonAir = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockTypes.clear(); - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) - { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) { - FoundNonAir = true; - IdxWhereNonEmptyStarts = Idx; - break; + if (a_BlockTypes[Idx] != E_BLOCK_AIR) + { + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; + } } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + { // Blockmeta compression + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockMeta.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_BlockMeta[Idx] != 0) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts + 1]); + } - memcpy(m_BlockMeta, a_BlockMeta, sizeof(m_BlockMeta)); if (a_BlockLight != NULL) { memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); @@ -1548,9 +1568,8 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { - m_BlockTypes.resize(index); + m_BlockTypes.resize(index + 1); } - m_BlockTypes[index] = a_BlockType; // The client doesn't need to distinguish between stationary and nonstationary fluids: -- cgit v1.2.3 From a42d1f851748c0cca542d1b0038318d0cbff9fd3 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Sun, 6 Apr 2014 23:30:21 +0100 Subject: Blocklight and skylight now compressed --- src/Chunk.cpp | 106 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 82 insertions(+), 24 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 97822048d..7a3e63bd0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -250,8 +250,14 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.BlockMeta (Metas.data()); a_Callback.LightIsValid (m_IsLightValid); - a_Callback.BlockLight (m_BlockLight); - a_Callback.BlockSkyLight(m_BlockSkyLight); + + std::vector BlockLights = m_BlockLight; + BlockLights.resize(NumBlocks / 2); + a_Callback.BlockLight (BlockLights.data()); + + std::vector BlockSkyLights = m_BlockSkyLight; + BlockSkyLights.resize(NumBlocks / 2, 0xff); + a_Callback.BlockSkyLight(BlockSkyLights.data()); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -285,47 +291,66 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } - { // Blocktype compression - bool FoundNonAir = false; + { + int IdxWhereNonEmptyStarts = 0; + { // Blocktype compression + bool FoundNonAir = false; + m_BlockTypes.clear(); + + for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + { + if (a_BlockTypes[Idx] != E_BLOCK_AIR) + { + FoundNonAir = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + } + + { // Blockmeta compression + m_BlockMeta.clear(); + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[(IdxWhereNonEmptyStarts + 1) / 2]); + } + } + + if (a_BlockLight != NULL) + { + // Compress blocklight + bool FoundNonEmpty = false; int IdxWhereNonEmptyStarts = 0; - m_BlockTypes.clear(); + m_BlockLight.clear(); - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + if (a_BlockLight[Idx] != 0) { - FoundNonAir = true; + FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); } - { // Blockmeta compression + if (a_BlockSkyLight != NULL) + { + // Compress skylight bool FoundNonEmpty = false; int IdxWhereNonEmptyStarts = 0; - m_BlockMeta.clear(); + m_BlockSkyLight.clear(); for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { - if (a_BlockMeta[Idx] != 0) + if (a_BlockSkyLight[Idx] != 0xff) { FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } } - m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts + 1]); - } - - if (a_BlockLight != NULL) - { - memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); - } - if (a_BlockSkyLight != NULL) - { - memcpy(m_BlockSkyLight, a_BlockSkyLight, sizeof(m_BlockSkyLight)); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts + 1]); } m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL); @@ -371,8 +396,41 @@ void cChunk::SetLight( { // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) - memcpy(m_BlockLight, a_BlockLight, sizeof(m_BlockLight)); - memcpy(m_BlockSkyLight, a_SkyLight, sizeof(m_BlockSkyLight)); + + { // Compress blocklight + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockLight.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_BlockLight[Idx] != 0) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + } + + { // Compress skylight + bool FoundNonEmpty = false; + int IdxWhereNonEmptyStarts = 0; + m_BlockSkyLight.clear(); + + for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) + { + if (a_SkyLight[Idx] != 0xff) + { + FoundNonEmpty = true; + IdxWhereNonEmptyStarts = Idx; + break; + } + } + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); + } + m_IsLightValid = true; } -- cgit v1.2.3 From 74c4789c6f8f42c6df45ed1e355e562bdced908d Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Apr 2014 12:43:43 +0100 Subject: Attempt to fix errors --- src/Chunk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7a3e63bd0..ede01a6cc 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -1624,7 +1624,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || (index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { m_BlockTypes.resize(index + 1); } @@ -2569,7 +2569,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || (a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) { return E_BLOCK_AIR; } -- cgit v1.2.3 From f13cf1a0217437113ad5372ef971c3903d55a9c6 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Mon, 7 Apr 2014 20:57:14 +0100 Subject: Maybe speed improvements? * Use a single index to determine from when to begin copying data * Use heightmap to determine first nonair block --- src/Chunk.cpp | 75 ++++++++++++++++++++++------------------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ede01a6cc..7b49862f0 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -291,74 +291,55 @@ void cChunk::SetAllData( memcpy(m_HeightMap, a_HeightMap, sizeof(m_HeightMap)); } + if (a_HeightMap == NULL) { - int IdxWhereNonEmptyStarts = 0; - { // Blocktype compression - bool FoundNonAir = false; - m_BlockTypes.clear(); + CalculateHeightmap(a_BlockTypes); + } - for (int Idx = NumBlocks - 1; Idx >= 0; Idx--) + int IdxWhereNonEmptyStarts = 0; + { // Blocktype compression + unsigned char Highest = 0; + int X = 0, Z = 0; + m_BlockTypes.clear(); + + for (int x = 0; x < Width; x++) + { + for (int z = 0; z < Width; z++) { - if (a_BlockTypes[Idx] != E_BLOCK_AIR) + unsigned char Height = m_HeightMap[x + z * Width]; + if (Height > Highest) { - FoundNonAir = true; - IdxWhereNonEmptyStarts = Idx; - break; + Highest = Height; + X = x; Z = z; } } - m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts + 1]); } - { // Blockmeta compression - m_BlockMeta.clear(); - m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[(IdxWhereNonEmptyStarts + 1) / 2]); - } + IdxWhereNonEmptyStarts = MakeIndexNoCheck(X, Highest + 1, Z); + + m_BlockTypes.insert(m_BlockTypes.end(), &a_BlockTypes[0], &a_BlockTypes[IdxWhereNonEmptyStarts]); + } + + { // Blockmeta compression + m_BlockMeta.clear(); + m_BlockMeta.insert(m_BlockMeta.end(), &a_BlockMeta[0], &a_BlockMeta[IdxWhereNonEmptyStarts / 2]); } if (a_BlockLight != NULL) { // Compress blocklight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockLight[Idx] != 0) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts / 2]); } if (a_BlockSkyLight != NULL) { // Compress skylight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockSkyLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockSkyLight[Idx] != 0xff) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts + 1]); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_BlockSkyLight[0], &a_BlockSkyLight[IdxWhereNonEmptyStarts / 2]); } m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL); - - if (a_HeightMap == NULL) - { - CalculateHeightmap(); - } // Clear the block entities present - either the loader / saver has better, or we'll create empty ones: for (cBlockEntityList::iterator itr = m_BlockEntities.begin(); itr != m_BlockEntities.end(); ++itr) @@ -1483,7 +1464,7 @@ void cChunk::WakeUpSimulators(void) -void cChunk::CalculateHeightmap() +void cChunk::CalculateHeightmap(const BLOCKTYPE * a_BlockTypes) { for (int x = 0; x < Width; x++) { @@ -1492,7 +1473,7 @@ void cChunk::CalculateHeightmap() for (int y = Height - 1; y > -1; y--) { int index = MakeIndex( x, y, z ); - if (GetBlock(index) != E_BLOCK_AIR) + if (a_BlockTypes[index] != E_BLOCK_AIR) { m_HeightMap[x + z * Width] = (unsigned char)y; break; -- cgit v1.2.3 From 01546020fc70a940f2644e9c8f58c26b754bc653 Mon Sep 17 00:00:00 2001 From: Tycho Date: Thu, 10 Apr 2014 12:12:36 -0700 Subject: Replaced all the .data() calls so the code compiles in VS2008 --- src/Chunk.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7b49862f0..ee1531b5c 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -243,21 +243,21 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - a_Callback.BlockTypes (Blocks.data()); + a_Callback.BlockTypes (&Blocks[0]); std::vector Metas = m_BlockMeta; Metas.resize(NumBlocks / 2); - a_Callback.BlockMeta (Metas.data()); + a_Callback.BlockMeta (&Metas[0]); a_Callback.LightIsValid (m_IsLightValid); std::vector BlockLights = m_BlockLight; BlockLights.resize(NumBlocks / 2); - a_Callback.BlockLight (BlockLights.data()); + a_Callback.BlockLight (&BlockLights[0]); std::vector BlockSkyLights = m_BlockSkyLight; BlockSkyLights.resize(NumBlocks / 2, 0xff); - a_Callback.BlockSkyLight(BlockSkyLights.data()); + a_Callback.BlockSkyLight(&BlockSkyLights[0]); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -424,7 +424,7 @@ void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) std::vector Blocks = m_BlockTypes; Blocks.resize(NumBlocks); - memcpy(a_BlockTypes, Blocks.data(), NumBlocks); + memcpy(a_BlockTypes, &Blocks[0], NumBlocks); } -- cgit v1.2.3 From ffce8d6907b8b93a2764a67766a40901bcad0835 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:49:56 +0100 Subject: Implemented suggestions --- src/Chunk.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index ee1531b5c..6c35f7f47 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,16 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) + int IdxWhereNonEmptyStarts = 0; { // Compress blocklight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockLight.clear(); for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) { if (a_BlockLight[Idx] != 0) { - FoundNonEmpty = true; IdxWhereNonEmptyStarts = Idx; break; } @@ -396,19 +394,7 @@ void cChunk::SetLight( } { // Compress skylight - bool FoundNonEmpty = false; - int IdxWhereNonEmptyStarts = 0; m_BlockSkyLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_SkyLight[Idx] != 0xff) - { - FoundNonEmpty = true; - IdxWhereNonEmptyStarts = Idx; - break; - } - } m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); } @@ -421,10 +407,8 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - std::vector Blocks = m_BlockTypes; - Blocks.resize(NumBlocks); - - memcpy(a_BlockTypes, &Blocks[0], NumBlocks); + std::copy(m_BlockTypes.begin(), m_BlockTypes.end(), a_BlockTypes); + std::fill_n(&a_BlockTypes[m_BlockTypes.size()], NumBlocks - m_BlockTypes.size(), E_BLOCK_AIR); } @@ -832,7 +816,7 @@ void cChunk::BroadcastPendingBlockChanges(void) void cChunk::CheckBlocks() { - if (m_ToTickBlocks.size() == 0) + if (m_ToTickBlocks.empty()) { return; } @@ -1605,7 +1589,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) { m_BlockTypes.resize(index + 1); } @@ -2550,7 +2534,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx > m_BlockTypes.size() - 1) /* Vector starts from zero, .size() starts from 1 */) + if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) { return E_BLOCK_AIR; } -- cgit v1.2.3 From acbd4e6503a8da6645c97dbe010eed7f37386194 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 21:52:01 +0100 Subject: Another small speed improvement? --- src/Chunk.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 6c35f7f47..7af1820d2 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -378,24 +378,14 @@ void cChunk::SetLight( // TODO: We might get cases of wrong lighting when a chunk changes in the middle of a lighting calculation. // Postponing until we see how bad it is :) - int IdxWhereNonEmptyStarts = 0; { // Compress blocklight m_BlockLight.clear(); - - for (int Idx = (NumBlocks / 2) - 1; Idx >= 0; Idx--) - { - if (a_BlockLight[Idx] != 0) - { - IdxWhereNonEmptyStarts = Idx; - break; - } - } - m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[IdxWhereNonEmptyStarts + 1]); + m_BlockLight.insert(m_BlockLight.end(), &a_BlockLight[0], &a_BlockLight[m_BlockTypes.size()]); } { // Compress skylight m_BlockSkyLight.clear(); - m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[IdxWhereNonEmptyStarts + 1]); + m_BlockSkyLight.insert(m_BlockSkyLight.end(), &a_SkyLight[0], &a_SkyLight[m_BlockTypes.size()]); } m_IsLightValid = true; -- cgit v1.2.3 From 3397f9faec43ac288fa9e7f1f555a1309a4e47a5 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 24 Apr 2014 22:07:20 +0100 Subject: Fixed indent --- src/Chunk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 7af1820d2..97a8ba88b 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -282,7 +282,7 @@ void cChunk::SetAllData( const HeightMap * a_HeightMap, const BiomeMap & a_BiomeMap, cBlockEntityList & a_BlockEntities - ) +) { memcpy(m_BiomeMap, a_BiomeMap, sizeof(m_BiomeMap)); -- cgit v1.2.3 From 05f52192c9389f0c28cc6d772f3625c9588273a1 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Fri, 25 Apr 2014 21:22:43 +0100 Subject: Implemented comments --- src/Chunk.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Chunk.cpp') diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 97a8ba88b..652f56905 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -241,21 +241,21 @@ void cChunk::GetAllData(cChunkDataCallback & a_Callback) a_Callback.HeightMap (&m_HeightMap); a_Callback.BiomeData (&m_BiomeMap); - std::vector Blocks = m_BlockTypes; + COMPRESSED_BLOCKTYPE Blocks = m_BlockTypes; Blocks.resize(NumBlocks); a_Callback.BlockTypes (&Blocks[0]); - std::vector Metas = m_BlockMeta; + COMPRESSED_NIBBLETYPE Metas = m_BlockMeta; Metas.resize(NumBlocks / 2); a_Callback.BlockMeta (&Metas[0]); a_Callback.LightIsValid (m_IsLightValid); - std::vector BlockLights = m_BlockLight; + COMPRESSED_NIBBLETYPE BlockLights = m_BlockLight; BlockLights.resize(NumBlocks / 2); a_Callback.BlockLight (&BlockLights[0]); - std::vector BlockSkyLights = m_BlockSkyLight; + COMPRESSED_NIBBLETYPE BlockSkyLights = m_BlockSkyLight; BlockSkyLights.resize(NumBlocks / 2, 0xff); a_Callback.BlockSkyLight(&BlockSkyLights[0]); @@ -1579,7 +1579,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - if (m_BlockTypes.empty() || ((size_t)index >= m_BlockTypes.size())) + if ((size_t)index >= m_BlockTypes.size()) { m_BlockTypes.resize(index + 1); } @@ -2524,7 +2524,7 @@ BLOCKTYPE cChunk::GetBlock(int a_BlockIdx) const return 0; } - if (m_BlockTypes.empty() || ((size_t)a_BlockIdx >= m_BlockTypes.size())) + if ((size_t)a_BlockIdx >= m_BlockTypes.size()) { return E_BLOCK_AIR; } -- cgit v1.2.3