From 024027db89ca833406147b79b7be74fc92906bbe Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 19:58:48 +0100 Subject: Renamed cChunkBuffer to cChunkData --- src/BlockArea.cpp | 4 +- src/BlockArea.h | 2 +- src/Chunk.cpp | 38 ++--- src/Chunk.h | 12 +- src/ChunkBuffer.cpp | 320 ------------------------------------- src/ChunkBuffer.h | 279 -------------------------------- src/ChunkData.cpp | 320 +++++++++++++++++++++++++++++++++++++ src/ChunkData.h | 279 ++++++++++++++++++++++++++++++++ src/ChunkDataCallback.h | 18 +-- src/LightingThread.cpp | 2 +- src/WorldStorage/WSSCompact.h | 2 +- tests/CMakeLists.txt | 2 +- tests/ChunkBuffer/ArraytoCoord.cpp | 116 -------------- tests/ChunkBuffer/CMakeLists.txt | 25 --- tests/ChunkBuffer/Coordinates.cpp | 143 ----------------- tests/ChunkBuffer/Copies.cpp | 193 ---------------------- tests/ChunkBuffer/creatable.cpp | 9 -- tests/ChunkData/ArraytoCoord.cpp | 116 ++++++++++++++ tests/ChunkData/CMakeLists.txt | 25 +++ tests/ChunkData/Coordinates.cpp | 143 +++++++++++++++++ tests/ChunkData/Copies.cpp | 193 ++++++++++++++++++++++ tests/ChunkData/creatable.cpp | 9 ++ 22 files changed, 1125 insertions(+), 1125 deletions(-) delete mode 100644 src/ChunkBuffer.cpp delete mode 100644 src/ChunkBuffer.h create mode 100644 src/ChunkData.cpp create mode 100644 src/ChunkData.h delete mode 100644 tests/ChunkBuffer/ArraytoCoord.cpp delete mode 100644 tests/ChunkBuffer/CMakeLists.txt delete mode 100644 tests/ChunkBuffer/Coordinates.cpp delete mode 100644 tests/ChunkBuffer/Copies.cpp delete mode 100644 tests/ChunkBuffer/creatable.cpp create mode 100644 tests/ChunkData/ArraytoCoord.cpp create mode 100644 tests/ChunkData/CMakeLists.txt create mode 100644 tests/ChunkData/Coordinates.cpp create mode 100644 tests/ChunkData/Copies.cpp create mode 100644 tests/ChunkData/creatable.cpp diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 5e41b135c..0c46e59e5 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -9,7 +9,7 @@ #include "OSSupport/GZipFile.h" #include "Blocks/BlockHandler.h" #include "Cuboid.h" -#include "ChunkBuffer.h" +#include "ChunkData.h" @@ -1835,7 +1835,7 @@ bool cBlockArea::cChunkReader::Coords(int a_ChunkX, int a_ChunkZ) -void cBlockArea::cChunkReader::ChunkBuffer(const cChunkBuffer & a_BlockBuffer) +void cBlockArea::cChunkReader::ChunkData(const cChunkData & a_BlockBuffer) { { if (!(m_Area.m_BlockTypes == NULL)) diff --git a/src/BlockArea.h b/src/BlockArea.h index 6b3bdf337..2bd26facd 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -318,7 +318,7 @@ protected: // cChunkDataCallback overrides: virtual bool Coords(int a_ChunkX, int a_ChunkZ) override; - virtual void ChunkBuffer(const cChunkBuffer & a_BlockTypes) override; + virtual void ChunkData(const cChunkData & a_BlockTypes) override; } ; typedef NIBBLETYPE * NIBBLEARRAY; diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 00ea33e16..a45ed32c1 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -238,12 +238,12 @@ void cChunk::MarkLoadFailed(void) void cChunk::GetAllData(cChunkDataCallback & a_Callback) { - a_Callback.HeightMap (&m_HeightMap); - a_Callback.BiomeData (&m_BiomeMap); + a_Callback.HeightMap(&m_HeightMap); + a_Callback.BiomeData(&m_BiomeMap); - a_Callback.LightIsValid (m_IsLightValid); + a_Callback.LightIsValid(m_IsLightValid); - a_Callback.ChunkBuffer (m_ChunkBuffer); + a_Callback.ChunkData(m_ChunkData); for (cEntityList::iterator itr = m_Entities.begin(); itr != m_Entities.end(); ++itr) { @@ -282,10 +282,10 @@ void cChunk::SetAllData( CalculateHeightmap(a_BlockTypes); } - m_ChunkBuffer.SetBlocks(a_BlockTypes); - m_ChunkBuffer.SetMeta(a_BlockMeta); - m_ChunkBuffer.SetLight(a_BlockLight); - m_ChunkBuffer.SetSkyLight(a_BlockSkyLight); + m_ChunkData.SetBlocks(a_BlockTypes); + m_ChunkData.SetMeta(a_BlockMeta); + m_ChunkData.SetLight(a_BlockLight); + m_ChunkData.SetSkyLight(a_BlockSkyLight); m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL); @@ -326,9 +326,9 @@ 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 :) - m_ChunkBuffer.SetLight (a_BlockLight); + m_ChunkData.SetLight (a_BlockLight); - m_ChunkBuffer.SetSkyLight (a_SkyLight); + m_ChunkData.SetSkyLight (a_SkyLight); m_IsLightValid = true; } @@ -339,7 +339,7 @@ void cChunk::SetLight( void cChunk::GetBlockTypes(BLOCKTYPE * a_BlockTypes) { - m_ChunkBuffer.CopyBlocks(a_BlockTypes); + m_ChunkData.CopyBlocks(a_BlockTypes); } @@ -1507,7 +1507,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT ASSERT(IsValid()); const BLOCKTYPE OldBlockType = GetBlock(a_RelX, a_RelY, a_RelZ); - const BLOCKTYPE OldBlockMeta = m_ChunkBuffer.GetMeta(a_RelX, a_RelY, a_RelZ); + const BLOCKTYPE OldBlockMeta = m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ); if ((OldBlockType == a_BlockType) && (OldBlockMeta == a_BlockMeta)) { return; @@ -1515,7 +1515,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT MarkDirty(); - m_ChunkBuffer.SetBlock(a_RelX, a_RelY, a_RelZ, a_BlockType); + m_ChunkData.SetBlock(a_RelX, a_RelY, a_RelZ, a_BlockType); // The client doesn't need to distinguish between stationary and nonstationary fluids: if ( @@ -1531,7 +1531,7 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT m_PendingSendBlocks.push_back(sSetBlock(m_PosX, m_PosZ, a_RelX, a_RelY, a_RelZ, a_BlockType, a_BlockMeta)); } - m_ChunkBuffer.SetMeta(a_RelX, a_RelY, a_RelZ, a_BlockMeta); + m_ChunkData.SetMeta(a_RelX, a_RelY, a_RelZ, a_BlockMeta); // ONLY recalculate lighting if it's necessary! if ( @@ -2438,7 +2438,7 @@ BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const return 0; // Clip } - return m_ChunkBuffer.GetBlock(a_RelX, a_RelY, a_RelZ); + return m_ChunkData.GetBlock(a_RelX, a_RelY, a_RelZ); } @@ -2448,7 +2448,7 @@ BLOCKTYPE cChunk::GetBlock(int a_RelX, int a_RelY, int a_RelZ) const void cChunk::GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) { a_BlockType = GetBlock(a_RelX, a_RelY, a_RelZ); - a_BlockMeta = m_ChunkBuffer.GetMeta(a_RelX, a_RelY, a_RelZ); + a_BlockMeta = m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ); } @@ -2458,9 +2458,9 @@ 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) { a_BlockType = GetBlock(a_RelX, a_RelY, a_RelZ); - a_Meta = m_ChunkBuffer.GetMeta(a_RelX, a_RelY, a_RelZ); - a_SkyLight = m_ChunkBuffer.GetSkyLight(a_RelX, a_RelY, a_RelZ); - a_BlockLight = m_ChunkBuffer.GetBlockLight(a_RelX, a_RelY, a_RelZ); + a_Meta = m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ); + a_SkyLight = m_ChunkData.GetSkyLight(a_RelX, a_RelY, a_RelZ); + a_BlockLight = m_ChunkData.GetBlockLight(a_RelX, a_RelY, a_RelZ); } diff --git a/src/Chunk.h b/src/Chunk.h index 038be42de..4f6c4cf0a 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -3,7 +3,7 @@ #include "Entities/Entity.h" #include "ChunkDef.h" -#include "ChunkBuffer.h" +#include "ChunkData.h" #include "Simulator/FireSimulator.h" #include "Simulator/SandSimulator.h" @@ -324,21 +324,21 @@ public: inline NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const { - return m_ChunkBuffer.GetMeta(a_RelX, a_RelY, a_RelZ); + return m_ChunkData.GetMeta(a_RelX, a_RelY, a_RelZ); } inline void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta) { if (!(GetMeta(a_RelX, a_RelY, a_RelZ) == a_Meta)) { MarkDirty(); - m_ChunkBuffer.SetMeta(a_RelX, a_RelY, a_RelZ, a_Meta); + m_ChunkData.SetMeta(a_RelX, a_RelY, a_RelZ, a_Meta); m_PendingSendBlocks.push_back(sSetBlock(m_PosX, m_PosZ, a_RelX, a_RelY, a_RelZ, GetBlock(a_RelX, a_RelY, a_RelZ), a_Meta)); } } - inline NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const {return m_ChunkBuffer.GetBlockLight(a_RelX, a_RelY, a_RelZ); } - inline NIBBLETYPE GetSkyLight (int a_RelX, int a_RelY, int a_RelZ) const {return m_ChunkBuffer.GetSkyLight(a_RelX, a_RelY, a_RelZ); } + inline NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const {return m_ChunkData.GetBlockLight(a_RelX, a_RelY, a_RelZ); } + inline NIBBLETYPE GetSkyLight (int a_RelX, int a_RelY, int a_RelZ) const {return m_ChunkData.GetSkyLight(a_RelX, a_RelY, a_RelZ); } /** Same as GetBlock(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap in such a case); returns true on success */ bool UnboundedRelGetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta) const; @@ -430,7 +430,7 @@ private: cWorld * m_World; cChunkMap * m_ChunkMap; - cChunkBuffer m_ChunkBuffer; + cChunkData m_ChunkData; cChunkDef::HeightMap m_HeightMap; cChunkDef::BiomeMap m_BiomeMap; diff --git a/src/ChunkBuffer.cpp b/src/ChunkBuffer.cpp deleted file mode 100644 index 99bcdebef..000000000 --- a/src/ChunkBuffer.cpp +++ /dev/null @@ -1,320 +0,0 @@ - -#include "Globals.h" -#include "ChunkBuffer.h" - -cChunkBuffer cChunkBuffer::Copy() const -{ - cChunkBuffer copy; - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - if(m_Sections[i]) - { - copy.m_Sections[i] = Allocate(); - *copy.m_Sections[i] = *m_Sections[i]; - } - } - return copy; -} - - - - - -void cChunkBuffer::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) const -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; - if (a_Idx > 0) a_Idx = a_Idx > length ? a_Idx - length : 0; - if (a_Idx == 0) - { - size_t tocopy = length > segment_length ? segment_length : length; - length -= tocopy; - if(m_Sections[i]) - { - memcpy( - &a_dest[i * segment_length], - &m_Sections[i]->m_BlockTypes, - sizeof(BLOCKTYPE) * tocopy - ); - } - else - { - memset( - &a_dest[i * segment_length], - 0, - sizeof(BLOCKTYPE) * tocopy - ); - } - } - } -} - - - - - -void cChunkBuffer::CopyMeta(NIBBLETYPE * a_dest) const -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) - { - memcpy( - &a_dest[i * segment_length], - &m_Sections[i]->m_BlockMeta, - sizeof(NIBBLETYPE) * segment_length); - } - else - { - memset( - &a_dest[i * segment_length], - 0, - sizeof(BLOCKTYPE) * segment_length - ); - } - } -} - - - - - -void cChunkBuffer::CopyLight(NIBBLETYPE * a_dest) const -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) - { - memcpy( - &a_dest[i * segment_length], - &m_Sections[i]->m_BlockLight, - sizeof(NIBBLETYPE) * segment_length - ); - } - else - { - memset( - &a_dest[i * segment_length], - 0, - sizeof(BLOCKTYPE) * segment_length - ); - } - } -} - - - - - -void cChunkBuffer::CopySkyLight(NIBBLETYPE * a_dest) const -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) - { - memcpy( - &a_dest[i * segment_length], - &m_Sections[i]->m_BlockSkyLight, - sizeof(NIBBLETYPE) * segment_length - ); - } - else - { - memset( - &a_dest[i * segment_length], - 0xFF, - sizeof(BLOCKTYPE) * segment_length - ); - } - } -} - - - - - -void cChunkBuffer::SetBlocks(const BLOCKTYPE * a_src) -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; - if (m_Sections[i]) - { - memcpy(&m_Sections[i]->m_BlockTypes, &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length); - } - else - { - size_t j = 0; - // do nothing whilst 0 - for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); - if (j != segment_length) - { - m_Sections[i] = Allocate(); - memcpy( - &m_Sections[i]->m_BlockTypes, - &a_src[i * segment_length], - sizeof(BLOCKTYPE) * segment_length - ); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); - } - else - { - Free(m_Sections[i]); - m_Sections[i] = 0; - } - } - } -} - - - - -void cChunkBuffer::SetMeta(const NIBBLETYPE * a_src) -{ - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) - { - memcpy(&m_Sections[i]->m_BlockMeta, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); - } - else - { - size_t j = 0; - // do nothing whilst 0 - for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); - if (j != segment_length) - { - m_Sections[i] = Allocate(); - memcpy( - &m_Sections[i]->m_BlockMeta, - &a_src[i * segment_length], - sizeof(BLOCKTYPE) * segment_length - ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); - } - else - { - Free(m_Sections[i]); - m_Sections[i] = 0; - } - } - } -} - - - - -void cChunkBuffer::SetLight(const NIBBLETYPE * a_src) -{ - if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) - { - memcpy(&m_Sections[i]->m_BlockLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); - } - else - { - size_t j = 0; - // do nothing whilst 0 - for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); - if (j != segment_length) - { - m_Sections[i] = Allocate(); - memcpy( - &m_Sections[i]->m_BlockLight, - &a_src[i * segment_length], - sizeof(BLOCKTYPE) * segment_length - ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); - } - else - { - Free(m_Sections[i]); - m_Sections[i] = 0; - } - } - } -} - - - - -void cChunkBuffer::SetSkyLight (const NIBBLETYPE * a_src) -{ - if (!a_src) return; - for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) - { - const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) - { - memcpy(&m_Sections[i]->m_BlockSkyLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); - } - else - { - size_t j = 0; - // do nothing whilst 0 - for (; j < segment_length && a_src[i * segment_length + j] == 0xFF; j++); - if (j != segment_length) - { - m_Sections[i] = Allocate(); - memcpy( - &m_Sections[i]->m_BlockSkyLight, - &a_src[i * segment_length], - sizeof(BLOCKTYPE) * segment_length - ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); - } - else - { - Free(m_Sections[i]); - m_Sections[i] = 0; - } - } - } -} - - - - - -cChunkBuffer::sChunkSection * cChunkBuffer::Allocate() const -{ - // TODO: use a allocation pool - return new cChunkBuffer::sChunkSection; -} - - - -void cChunkBuffer::Free(cChunkBuffer::sChunkSection * ptr) const -{ - delete ptr; -} - - - -void cChunkBuffer::ZeroSection(cChunkBuffer::sChunkSection * ptr) const -{ - memset(ptr->m_BlockTypes,0x00,sizeof(ptr->m_BlockTypes)); - memset(ptr->m_BlockMeta,0x00,sizeof(ptr->m_BlockMeta)); - memset(ptr->m_BlockLight,0x00,sizeof(ptr->m_BlockLight)); - memset(ptr->m_BlockSkyLight,0xFF,sizeof(ptr->m_BlockSkyLight)); -} - - - - diff --git a/src/ChunkBuffer.h b/src/ChunkBuffer.h deleted file mode 100644 index 266df2332..000000000 --- a/src/ChunkBuffer.h +++ /dev/null @@ -1,279 +0,0 @@ - -#pragma once - - -#include - - -#include "ChunkDef.h" - - -#define CHUNK_SECTION_HEIGHT 16 -#define CHUNK_SECTION_NUM (256 / CHUNK_SECTION_HEIGHT) - -#if __cplusplus < 201103L -// auto_ptr style interface for memory management -#else -// unique_ptr style interface for memory management -#endif - -class cChunkBuffer -{ -public: - - cChunkBuffer() - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - : IsOwner(true) - #endif - { - memset(m_Sections, 0, sizeof(m_Sections)); - } - ~cChunkBuffer() - { - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - if(!IsOwner) return; - #endif - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - if(m_Sections[i]) Free(m_Sections[i]);; - } - } - - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - cChunkBuffer(const cChunkBuffer& other) : - IsOwner(true) - { - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - m_Sections[i] = other.m_Sections[i]; - } - other.IsOwner = false; - } - - cChunkBuffer& operator=(const cChunkBuffer& other) - { - if(&other != this) - { - if(IsOwner) - { - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - if(m_Sections[i]) Free(m_Sections[i]);; - } - } - IsOwner = true; - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - m_Sections[i] = other.m_Sections[i]; - } - other.IsOwner = false; - } - return *this; - - } - #else - // unique_ptr style interface for memory management - cChunkBuffer(cChunkBuffer&& other) - { - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - m_Sections[i] = other.m_Sections[i]; - other.m_Sections[i] = 0; - } - } - - cChunkBuffer& operator=(cChunkBuffer&& other) - { - if(&other != this) - { - for (int i = 0; i < CHUNK_SECTION_NUM; i++) - { - if(m_Sections[i]) Free(m_Sections[i]);; - m_Sections[i] = other.m_Sections[i]; - other.m_Sections[i] = 0; - } - } - return *this; - } - #endif - - BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z) const - { - ASSERT((a_X >= 0) && (a_X < cChunkDef::Width)); - ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); - ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); - int Section = a_Y / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) - { - int Index = cChunkDef::MakeIndexNoCheck(a_X, a_Y - (Section * CHUNK_SECTION_HEIGHT), a_Z); - return m_Sections[Section]->m_BlockTypes[Index]; - } - else - { - return 0; - } - } - - void SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block) - { - if ( - (a_RelX >= cChunkDef::Width) || (a_RelX < 0) || - (a_RelY >= cChunkDef::Height) || (a_RelY < 0) || - (a_RelZ >= cChunkDef::Width) || (a_RelZ < 0) - ) - { - ASSERT(!"cChunkBuffer::SetMeta(): index out of range!"); - return; - } - - int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(!m_Sections[Section]) - { - if(a_Block == 0x00) - { - return; - } - m_Sections[Section] = Allocate(); - if(!m_Sections[Section]) - { - ASSERT(!"Failed to allocate a new section in Chunkbuffer"); - return; - } - ZeroSection(m_Sections[Section]); - } - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); - m_Sections[Section]->m_BlockTypes[Index] = a_Block; - } - - NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const - { - if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) - { - int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) - { - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); - return (m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4)) & 0x0f; - } - else - { - return 0; - } - } - ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!"); - return 0; - } - - void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Nibble) - { - if ( - (a_RelX >= cChunkDef::Width) || (a_RelX < 0) || - (a_RelY >= cChunkDef::Height) || (a_RelY < 0) || - (a_RelZ >= cChunkDef::Width) || (a_RelZ < 0) - ) - { - ASSERT(!"cChunkBuffer::SetMeta(): index out of range!"); - return; - } - - int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(!m_Sections[Section]) - { - if((a_Nibble & 0xf) == 0x00) - { - return; - } - m_Sections[Section] = Allocate(); - if(!m_Sections[Section]) - { - ASSERT(!"Failed to allocate a new section in Chunkbuffer"); - return; - } - ZeroSection(m_Sections[Section]); - } - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); - m_Sections[Section]->m_BlockMeta[Index / 2] = static_cast( - (m_Sections[Section]->m_BlockMeta[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble - ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set - ); - } - - NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const - { - if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) - { - int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) - { - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); - return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; - } - else - { - return 0; - } - } - ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!"); - return 0; - } - - NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const - { - if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) - { - int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) - { - int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); - return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; - } - else - { - return 0xF; - } - } - ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!"); - return 0; - } - - cChunkBuffer Copy() const; - void CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx = 0, size_t length = cChunkDef::NumBlocks) const; - void CopyMeta (NIBBLETYPE * a_dest) const; - void CopyLight (NIBBLETYPE * a_dest) const; - void CopySkyLight (NIBBLETYPE * a_dest) const; - - void SetBlocks (const BLOCKTYPE * a_src); - void SetMeta (const NIBBLETYPE * a_src); - void SetLight (const NIBBLETYPE * a_src); - void SetSkyLight (const NIBBLETYPE * a_src); - -private: - - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - mutable bool IsOwner; - #endif - - struct sChunkSection { - BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16] ; - NIBBLETYPE m_BlockMeta [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; - NIBBLETYPE m_BlockLight [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; - NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; - }; - - sChunkSection *m_Sections[CHUNK_SECTION_NUM]; - - sChunkSection * Allocate() const; - void Free(sChunkSection * ptr) const; - - void ZeroSection(sChunkSection * ptr) const; -}; - - - - - - diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp new file mode 100644 index 000000000..160d118ad --- /dev/null +++ b/src/ChunkData.cpp @@ -0,0 +1,320 @@ + +#include "Globals.h" +#include "ChunkData.h" + +cChunkData cChunkData::Copy() const +{ + cChunkData copy; + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + if(m_Sections[i]) + { + copy.m_Sections[i] = Allocate(); + *copy.m_Sections[i] = *m_Sections[i]; + } + } + return copy; +} + + + + + +void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) const +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; + if (a_Idx > 0) a_Idx = a_Idx > length ? a_Idx - length : 0; + if (a_Idx == 0) + { + size_t tocopy = length > segment_length ? segment_length : length; + length -= tocopy; + if(m_Sections[i]) + { + memcpy( + &a_dest[i * segment_length], + &m_Sections[i]->m_BlockTypes, + sizeof(BLOCKTYPE) * tocopy + ); + } + else + { + memset( + &a_dest[i * segment_length], + 0, + sizeof(BLOCKTYPE) * tocopy + ); + } + } + } +} + + + + + +void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if(m_Sections[i]) + { + memcpy( + &a_dest[i * segment_length], + &m_Sections[i]->m_BlockMeta, + sizeof(NIBBLETYPE) * segment_length); + } + else + { + memset( + &a_dest[i * segment_length], + 0, + sizeof(BLOCKTYPE) * segment_length + ); + } + } +} + + + + + +void cChunkData::CopyLight(NIBBLETYPE * a_dest) const +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if(m_Sections[i]) + { + memcpy( + &a_dest[i * segment_length], + &m_Sections[i]->m_BlockLight, + sizeof(NIBBLETYPE) * segment_length + ); + } + else + { + memset( + &a_dest[i * segment_length], + 0, + sizeof(BLOCKTYPE) * segment_length + ); + } + } +} + + + + + +void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if(m_Sections[i]) + { + memcpy( + &a_dest[i * segment_length], + &m_Sections[i]->m_BlockSkyLight, + sizeof(NIBBLETYPE) * segment_length + ); + } + else + { + memset( + &a_dest[i * segment_length], + 0xFF, + sizeof(BLOCKTYPE) * segment_length + ); + } + } +} + + + + + +void cChunkData::SetBlocks(const BLOCKTYPE * a_src) +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; + if (m_Sections[i]) + { + memcpy(&m_Sections[i]->m_BlockTypes, &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length); + } + else + { + size_t j = 0; + // do nothing whilst 0 + for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); + if (j != segment_length) + { + m_Sections[i] = Allocate(); + memcpy( + &m_Sections[i]->m_BlockTypes, + &a_src[i * segment_length], + sizeof(BLOCKTYPE) * segment_length + ); + memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); + memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); + memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + } + else + { + Free(m_Sections[i]); + m_Sections[i] = 0; + } + } + } +} + + + + +void cChunkData::SetMeta(const NIBBLETYPE * a_src) +{ + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if (m_Sections[i]) + { + memcpy(&m_Sections[i]->m_BlockMeta, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + } + else + { + size_t j = 0; + // do nothing whilst 0 + for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); + if (j != segment_length) + { + m_Sections[i] = Allocate(); + memcpy( + &m_Sections[i]->m_BlockMeta, + &a_src[i * segment_length], + sizeof(BLOCKTYPE) * segment_length + ); + memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); + memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); + memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + } + else + { + Free(m_Sections[i]); + m_Sections[i] = 0; + } + } + } +} + + + + +void cChunkData::SetLight(const NIBBLETYPE * a_src) +{ + if (!a_src) return; + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if (m_Sections[i]) + { + memcpy(&m_Sections[i]->m_BlockLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + } + else + { + size_t j = 0; + // do nothing whilst 0 + for (; j < segment_length && a_src[i * segment_length + j] == 0; j++); + if (j != segment_length) + { + m_Sections[i] = Allocate(); + memcpy( + &m_Sections[i]->m_BlockLight, + &a_src[i * segment_length], + sizeof(BLOCKTYPE) * segment_length + ); + memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); + memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); + memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + } + else + { + Free(m_Sections[i]); + m_Sections[i] = 0; + } + } + } +} + + + + +void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) +{ + if (!a_src) return; + for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) + { + const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; + if (m_Sections[i]) + { + memcpy(&m_Sections[i]->m_BlockSkyLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + } + else + { + size_t j = 0; + // do nothing whilst 0 + for (; j < segment_length && a_src[i * segment_length + j] == 0xFF; j++); + if (j != segment_length) + { + m_Sections[i] = Allocate(); + memcpy( + &m_Sections[i]->m_BlockSkyLight, + &a_src[i * segment_length], + sizeof(BLOCKTYPE) * segment_length + ); + memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); + memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); + memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); + } + else + { + Free(m_Sections[i]); + m_Sections[i] = 0; + } + } + } +} + + + + + +cChunkData::sChunkSection * cChunkData::Allocate() const +{ + // TODO: use a allocation pool + return new cChunkData::sChunkSection; +} + + + +void cChunkData::Free(cChunkData::sChunkSection * ptr) const +{ + delete ptr; +} + + + +void cChunkData::ZeroSection(cChunkData::sChunkSection * ptr) const +{ + memset(ptr->m_BlockTypes,0x00,sizeof(ptr->m_BlockTypes)); + memset(ptr->m_BlockMeta,0x00,sizeof(ptr->m_BlockMeta)); + memset(ptr->m_BlockLight,0x00,sizeof(ptr->m_BlockLight)); + memset(ptr->m_BlockSkyLight,0xFF,sizeof(ptr->m_BlockSkyLight)); +} + + + + diff --git a/src/ChunkData.h b/src/ChunkData.h new file mode 100644 index 000000000..809f3cdf2 --- /dev/null +++ b/src/ChunkData.h @@ -0,0 +1,279 @@ + +#pragma once + + +#include + + +#include "ChunkDef.h" + + +#define CHUNK_SECTION_HEIGHT 16 +#define CHUNK_SECTION_NUM (256 / CHUNK_SECTION_HEIGHT) + +#if __cplusplus < 201103L +// auto_ptr style interface for memory management +#else +// unique_ptr style interface for memory management +#endif + +class cChunkData +{ +public: + + cChunkData() + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + : IsOwner(true) + #endif + { + memset(m_Sections, 0, sizeof(m_Sections)); + } + ~cChunkData() + { + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + if(!IsOwner) return; + #endif + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + if(m_Sections[i]) Free(m_Sections[i]);; + } + } + + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + cChunkData(const cChunkData& other) : + IsOwner(true) + { + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + m_Sections[i] = other.m_Sections[i]; + } + other.IsOwner = false; + } + + cChunkData& operator=(const cChunkData& other) + { + if(&other != this) + { + if(IsOwner) + { + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + if(m_Sections[i]) Free(m_Sections[i]);; + } + } + IsOwner = true; + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + m_Sections[i] = other.m_Sections[i]; + } + other.IsOwner = false; + } + return *this; + + } + #else + // unique_ptr style interface for memory management + cChunkData(cChunkData&& other) + { + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + m_Sections[i] = other.m_Sections[i]; + other.m_Sections[i] = 0; + } + } + + cChunkData& operator=(cChunkData&& other) + { + if(&other != this) + { + for (int i = 0; i < CHUNK_SECTION_NUM; i++) + { + if(m_Sections[i]) Free(m_Sections[i]);; + m_Sections[i] = other.m_Sections[i]; + other.m_Sections[i] = 0; + } + } + return *this; + } + #endif + + BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z) const + { + ASSERT((a_X >= 0) && (a_X < cChunkDef::Width)); + ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); + ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); + int Section = a_Y / CHUNK_SECTION_HEIGHT; + if(m_Sections[Section]) + { + int Index = cChunkDef::MakeIndexNoCheck(a_X, a_Y - (Section * CHUNK_SECTION_HEIGHT), a_Z); + return m_Sections[Section]->m_BlockTypes[Index]; + } + else + { + return 0; + } + } + + void SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block) + { + if ( + (a_RelX >= cChunkDef::Width) || (a_RelX < 0) || + (a_RelY >= cChunkDef::Height) || (a_RelY < 0) || + (a_RelZ >= cChunkDef::Width) || (a_RelZ < 0) + ) + { + ASSERT(!"cChunkData::SetMeta(): index out of range!"); + return; + } + + int Section = a_RelY / CHUNK_SECTION_HEIGHT; + if(!m_Sections[Section]) + { + if(a_Block == 0x00) + { + return; + } + m_Sections[Section] = Allocate(); + if(!m_Sections[Section]) + { + ASSERT(!"Failed to allocate a new section in Chunkbuffer"); + return; + } + ZeroSection(m_Sections[Section]); + } + int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + m_Sections[Section]->m_BlockTypes[Index] = a_Block; + } + + NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const + { + if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) + { + int Section = a_RelY / CHUNK_SECTION_HEIGHT; + if(m_Sections[Section]) + { + int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + return (m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + } + else + { + return 0; + } + } + ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!"); + return 0; + } + + void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Nibble) + { + if ( + (a_RelX >= cChunkDef::Width) || (a_RelX < 0) || + (a_RelY >= cChunkDef::Height) || (a_RelY < 0) || + (a_RelZ >= cChunkDef::Width) || (a_RelZ < 0) + ) + { + ASSERT(!"cChunkData::SetMeta(): index out of range!"); + return; + } + + int Section = a_RelY / CHUNK_SECTION_HEIGHT; + if(!m_Sections[Section]) + { + if((a_Nibble & 0xf) == 0x00) + { + return; + } + m_Sections[Section] = Allocate(); + if(!m_Sections[Section]) + { + ASSERT(!"Failed to allocate a new section in Chunkbuffer"); + return; + } + ZeroSection(m_Sections[Section]); + } + int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + m_Sections[Section]->m_BlockMeta[Index / 2] = static_cast( + (m_Sections[Section]->m_BlockMeta[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble + ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set + ); + } + + NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const + { + if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) + { + int Section = a_RelY / CHUNK_SECTION_HEIGHT; + if(m_Sections[Section]) + { + int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + } + else + { + return 0; + } + } + ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!"); + return 0; + } + + NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const + { + if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) + { + int Section = a_RelY / CHUNK_SECTION_HEIGHT; + if(m_Sections[Section]) + { + int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; + } + else + { + return 0xF; + } + } + ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!"); + return 0; + } + + cChunkData Copy() const; + void CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx = 0, size_t length = cChunkDef::NumBlocks) const; + void CopyMeta (NIBBLETYPE * a_dest) const; + void CopyLight (NIBBLETYPE * a_dest) const; + void CopySkyLight (NIBBLETYPE * a_dest) const; + + void SetBlocks (const BLOCKTYPE * a_src); + void SetMeta (const NIBBLETYPE * a_src); + void SetLight (const NIBBLETYPE * a_src); + void SetSkyLight (const NIBBLETYPE * a_src); + +private: + + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + mutable bool IsOwner; + #endif + + struct sChunkSection { + BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16] ; + NIBBLETYPE m_BlockMeta [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; + NIBBLETYPE m_BlockLight [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; + NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; + }; + + sChunkSection *m_Sections[CHUNK_SECTION_NUM]; + + sChunkSection * Allocate() const; + void Free(sChunkSection * ptr) const; + + void ZeroSection(sChunkSection * ptr) const; +}; + + + + + + diff --git a/src/ChunkDataCallback.h b/src/ChunkDataCallback.h index 76c45040e..340582885 100644 --- a/src/ChunkDataCallback.h +++ b/src/ChunkDataCallback.h @@ -3,7 +3,7 @@ #pragma once -#include "ChunkBuffer.h" +#include "ChunkData.h" /** Interface class used for getting data out of a chunk using the GetAllData() function. @@ -26,13 +26,13 @@ public: virtual void HeightMap(const cChunkDef::HeightMap * a_HeightMap) {UNUSED(a_HeightMap); }; /// Called once to provide biome data - virtual void BiomeData (const cChunkDef::BiomeMap * a_BiomeMap) {UNUSED(a_BiomeMap); }; + virtual void BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) {UNUSED(a_BiomeMap); }; /// Called once to let know if the chunk lighting is valid. Return value is ignored virtual void LightIsValid(bool a_IsLightValid) {UNUSED(a_IsLightValid); }; /// Called once to export block info - virtual void ChunkBuffer (const cChunkBuffer & a_Buffer) {UNUSED(a_Buffer); }; + virtual void ChunkData(const cChunkData & a_Buffer) {UNUSED(a_Buffer); }; /// Called for each entity in the chunk virtual void Entity(cEntity * a_Entity) {UNUSED(a_Entity); }; @@ -43,16 +43,16 @@ public: /** A simple implementation of the cChunkDataCallback interface that collects all block data into a buffer */ -class cChunkBufferCollector : +class cChunkDataCollector : public cChunkDataCallback { public: - cChunkBuffer m_BlockData; + cChunkData m_BlockData; protected: - virtual void ChunkBuffer(const cChunkBuffer & a_BlockData) override + virtual void ChunkData(const cChunkData & a_BlockData) override { m_BlockData = a_BlockData.Copy(); } @@ -61,7 +61,7 @@ protected: /** A simple implementation of the cChunkDataCallback interface that collects all block data into a single buffer */ -class cChunkDataCollector : +class cChunkDataArrayCollector : public cChunkDataCallback { public: @@ -71,7 +71,7 @@ public: protected: - virtual void ChunkBuffer(const cChunkBuffer & a_ChunkBuffer) override + virtual void ChunkData(const cChunkData & a_ChunkBuffer) override { a_ChunkBuffer.CopyBlocks(m_BlockData); a_ChunkBuffer.CopyMeta(m_BlockData + cChunkDef::NumBlocks); @@ -94,7 +94,7 @@ public: protected: - virtual void ChunkBuffer(const cChunkBuffer & a_ChunkBuffer) override + virtual void ChunkData(const cChunkData & a_ChunkBuffer) override { a_ChunkBuffer.CopyBlocks(m_BlockTypes); a_ChunkBuffer.CopyMeta(m_BlockMetas); diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index f961e35c6..879252c34 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -18,7 +18,7 @@ class cReader : public cChunkDataCallback { - virtual void ChunkBuffer(const cChunkBuffer & a_ChunkBuffer) override + virtual void ChunkData(const cChunkData & a_ChunkBuffer) override { BLOCKTYPE * OutputRows = m_BlockTypes; int InputIdx = 0; diff --git a/src/WorldStorage/WSSCompact.h b/src/WorldStorage/WSSCompact.h index 6c363d5ac..b148005f6 100644 --- a/src/WorldStorage/WSSCompact.h +++ b/src/WorldStorage/WSSCompact.h @@ -22,7 +22,7 @@ /// Helper class for serializing a chunk into Json class cJsonChunkSerializer : - public cChunkDataCollector + public cChunkDataArrayCollector { public: diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1e3a01dc8..1fbd88f04 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -4,4 +4,4 @@ enable_testing() include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_subdirectory(ChunkBuffer) +add_subdirectory(ChunkData) diff --git a/tests/ChunkBuffer/ArraytoCoord.cpp b/tests/ChunkBuffer/ArraytoCoord.cpp deleted file mode 100644 index 5563a3f86..000000000 --- a/tests/ChunkBuffer/ArraytoCoord.cpp +++ /dev/null @@ -1,116 +0,0 @@ - -#include "TestGlobals.h" -#include "ChunkBuffer.h" - - - -int main(int argc, char** argv) -{ - { - // Test first segment - cChunkBuffer buffer; - - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7+4*16+5*16*16] = 0xCD; - buffer.SetBlocks(SrcBlockBuffer); - testassert(buffer.GetBlock(7,5,4) == 0xCD); - delete SrcBlockBuffer; - SrcBlockBuffer = NULL; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; - buffer.SetMeta(SrcNibbleBuffer); - testassert(buffer.GetMeta(6,2,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; - buffer.SetLight(SrcNibbleBuffer); - testassert(buffer.GetBlockLight(6,2,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; - buffer.SetSkyLight(SrcNibbleBuffer); - testassert(buffer.GetSkyLight(6,2,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - } - - { - // test following segment - cChunkBuffer buffer; - - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - SrcBlockBuffer[7+4*16+24*16*16] = 0xCD; - buffer.SetBlocks(SrcBlockBuffer); - testassert(buffer.GetBlock(7,24,4) == 0xCD); - delete SrcBlockBuffer; - SrcBlockBuffer = NULL; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; - buffer.SetMeta(SrcNibbleBuffer); - testassert(buffer.GetMeta(6,24,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; - buffer.SetLight(SrcNibbleBuffer); - testassert(buffer.GetBlockLight(6,24,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; - buffer.SetSkyLight(SrcNibbleBuffer); - testassert(buffer.GetSkyLight(6,24,1) == 0xE); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - } - - { - // test zeros - cChunkBuffer buffer; - - BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - buffer.SetBlocks(SrcBlockBuffer); - testassert(buffer.GetBlock(7,24,4) == 0x00); - delete SrcBlockBuffer; - SrcBlockBuffer = NULL; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - buffer.SetMeta(SrcNibbleBuffer); - testassert(buffer.GetMeta(6,24,1) == 0x0); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - buffer.SetLight(SrcNibbleBuffer); - testassert(buffer.GetBlockLight(6,24,1) == 0x0); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); - buffer.SetSkyLight(SrcNibbleBuffer); - testassert(buffer.GetSkyLight(6,24,1) == 0xF); - delete SrcNibbleBuffer; - SrcNibbleBuffer = NULL; - } -} - diff --git a/tests/ChunkBuffer/CMakeLists.txt b/tests/ChunkBuffer/CMakeLists.txt deleted file mode 100644 index b216b1d39..000000000 --- a/tests/ChunkBuffer/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -cmake_minimum_required (VERSION 2.6) - -enable_testing() - -include_directories(${CMAKE_SOURCE_DIR}/src/) - -add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkBuffer.cpp) - - -add_executable(creatable-exe creatable.cpp) -target_link_libraries(creatable-exe ChunkBuffer) -add_test(NAME creatable-test COMMAND creatable-exe) - -add_executable(coordinates-exe Coordinates.cpp) -target_link_libraries(coordinates-exe ChunkBuffer) -add_test(NAME coordinates-test COMMAND coordinates-exe) - -add_executable(copies-exe Copies.cpp) -target_link_libraries(copies-exe ChunkBuffer) -add_test(NAME copies-test COMMAND copies-exe) - -add_executable(arraystocoords-exe ArraytoCoord.cpp) -target_link_libraries(arraystocoords-exe ChunkBuffer) -add_test(NAME arraystocoords-test COMMAND arraystocoords-exe) - diff --git a/tests/ChunkBuffer/Coordinates.cpp b/tests/ChunkBuffer/Coordinates.cpp deleted file mode 100644 index bed61d5dc..000000000 --- a/tests/ChunkBuffer/Coordinates.cpp +++ /dev/null @@ -1,143 +0,0 @@ - -#include "TestGlobals.h" -#include "ChunkBuffer.h" - - - -int main(int argc, char** argv) -{ - { - cChunkBuffer buffer; - - // Empty chunks - buffer.SetBlock(0,0,0, 0xAB); - testassert(buffer.GetBlock(0,0,0) == 0xAB); - buffer.SetMeta(0,16,0, 0xC); - testassert(buffer.GetMeta(0,16,0) == 0xC); - - // loaded but not written segments - testassert(buffer.GetBlock(1,0,0) == 0x0); - testassert(buffer.GetMeta(1,16,0) == 0x0); - - // Notloaded segments - testassert(buffer.GetBlock(0,32,0) == 0x0); - testassert(buffer.GetMeta(0,48,0) == 0x0); - - // Out of Range - CheckAsserts( - buffer.SetBlock(-1, 0, 0, 0); - ); - CheckAsserts( - buffer.SetBlock(0, -1, 0, 0); - ); - CheckAsserts( - buffer.SetBlock(0, 0, -1, 0); - ); - CheckAsserts( - buffer.SetBlock(256, 0, 0, 0); - ); - CheckAsserts( - buffer.SetBlock(0, 256, 0, 0); - ); - CheckAsserts( - buffer.SetBlock(0, 0, 256, 0); - ); - - // Out of Range - CheckAsserts( - buffer.GetBlock(-1, 0, 0); - ); - CheckAsserts( - buffer.GetBlock(0, -1, 0); - ); - CheckAsserts( - buffer.GetBlock(0, 0, -1); - ); - CheckAsserts( - buffer.GetBlock(256, 0, 0); - ); - CheckAsserts( - buffer.GetBlock(0, 256, 0); - ); - CheckAsserts( - buffer.GetBlock(0, 0, 256); - ); - - // Out of Range - CheckAsserts( - buffer.SetMeta(-1, 0, 0, 0); - ); - CheckAsserts( - buffer.SetMeta(0, -1, 0, 0); - ); - CheckAsserts( - buffer.SetMeta(0, 0, -1, 0); - ); - CheckAsserts( - buffer.SetMeta(256, 0, 0, 0); - ); - CheckAsserts( - buffer.SetMeta(0, 256, 0, 0); - ); - CheckAsserts( - buffer.SetMeta(0, 0, 256, 0); - ); - - // Out of Range - CheckAsserts( - buffer.GetMeta(-1, 0, 0); - ); - CheckAsserts( - buffer.GetMeta(0, -1, 0); - ); - CheckAsserts( - buffer.GetMeta(0, 0, -1); - ); - CheckAsserts( - buffer.GetMeta(256, 0, 0); - ); - CheckAsserts( - buffer.GetMeta(0, 256, 0); - ); - CheckAsserts( - buffer.GetMeta(0, 0, 256); - ); - } - - { - cChunkBuffer buffer; - - // Zero's - buffer.SetBlock(0,0,0, 0x0); - buffer.SetBlock(0,0,1, 0xAB); - testassert(buffer.GetBlock(0,0,0) == 0x0); - testassert(buffer.GetBlock(0,0,1) == 0xAB); - - buffer.SetMeta(0,16,0, 0x0); - buffer.SetMeta(0,16,1, 0xC); - testassert(buffer.GetMeta(0,16,0) == 0x0); - testassert(buffer.GetMeta(0,16,1) == 0xC); - } - - - { - // Operator = - cChunkBuffer buffer; - buffer.SetBlock(0,0,0,0x42); - cChunkBuffer copy; - #if __cplusplus < 201103L - copy = buffer; - #else - copy = std::move(buffer); - #endif - testassert(copy.GetBlock(0,0,0) == 0x42); - #if __cplusplus < 201103L - copy = copy; - #else - copy = std::move(copy); - #endif - testassert(copy.GetBlock(0,0,0) == 0x42); - } - - return 0; -} diff --git a/tests/ChunkBuffer/Copies.cpp b/tests/ChunkBuffer/Copies.cpp deleted file mode 100644 index 76af81496..000000000 --- a/tests/ChunkBuffer/Copies.cpp +++ /dev/null @@ -1,193 +0,0 @@ - -#include "TestGlobals.h" -#include "ChunkBuffer.h" - - - -int main(int argc, char** argv) -{ - { - cChunkBuffer buffer; - - buffer.SetBlock(3,1,4,0xDE); - buffer.SetMeta(3,1,4,0xA); - - cChunkBuffer copy = buffer.Copy(); - testassert(copy.GetBlock(3,1,4) == 0xDE); - testassert(copy.GetMeta(3,1,4) == 0xA); - - BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - for (int i = 0; i < 16 * 16 * 256; i += 4) - { - SrcBlockBuffer[i+0] = 0xDE; - SrcBlockBuffer[i+1] = 0xAD; - SrcBlockBuffer[i+2] = 0xBE; - SrcBlockBuffer[i+3] = 0xEF; - } - - buffer.SetBlocks(SrcBlockBuffer); - BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - buffer.CopyBlocks(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); - delete SrcBlockBuffer; - delete DstBlockBuffer; - SrcBlockBuffer = NULL; - DstBlockBuffer = NULL; - - SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - buffer.SetBlocks(SrcBlockBuffer); - DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - buffer.CopyBlocks(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); - delete SrcBlockBuffer; - delete DstBlockBuffer; - SrcBlockBuffer = NULL; - DstBlockBuffer = NULL; - - } - { - cChunkBuffer buffer; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) - { - SrcNibbleBuffer[i+0] = 0xEF; - SrcNibbleBuffer[i+1] = 0xDE; - SrcNibbleBuffer[i+2] = 0xAD; - SrcNibbleBuffer[i+3] = 0xBE; - } - - buffer.SetMeta(SrcNibbleBuffer); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyMeta(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - buffer.SetMeta(SrcNibbleBuffer); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyMeta(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - } - { - cChunkBuffer buffer; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) - { - SrcNibbleBuffer[i+0] = 0xDE; - SrcNibbleBuffer[i+1] = 0xAD; - SrcNibbleBuffer[i+2] = 0xBE; - SrcNibbleBuffer[i+3] = 0xEF; - } - - buffer.SetLight(SrcNibbleBuffer); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - buffer.SetLight(SrcNibbleBuffer); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - - } - { - cChunkBuffer buffer; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) - { - SrcNibbleBuffer[i+0] = 0xAD; - SrcNibbleBuffer[i+1] = 0xBE; - SrcNibbleBuffer[i+2] = 0xEF; - SrcNibbleBuffer[i+3] = 0xDE; - } - - buffer.SetSkyLight(SrcNibbleBuffer); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopySkyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); - buffer.SetSkyLight(SrcNibbleBuffer); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopySkyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - } - { - cChunkBuffer buffer; - - BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); - BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; - buffer.CopyBlocks(DstBlockBuffer); - testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); - delete SrcBlockBuffer; - delete DstBlockBuffer; - SrcBlockBuffer = NULL; - DstBlockBuffer = NULL; - - NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyMeta(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - - SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; - memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); - DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; - buffer.CopySkyLight(DstNibbleBuffer); - testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); - delete SrcNibbleBuffer; - delete DstNibbleBuffer; - SrcNibbleBuffer = NULL; - DstNibbleBuffer = NULL; - } -} diff --git a/tests/ChunkBuffer/creatable.cpp b/tests/ChunkBuffer/creatable.cpp deleted file mode 100644 index 49204c879..000000000 --- a/tests/ChunkBuffer/creatable.cpp +++ /dev/null @@ -1,9 +0,0 @@ - -#include "TestGlobals.h" -#include "ChunkBuffer.h" - -int main(int argc, char** argv) -{ - cChunkBuffer buffer; - return 0; -} diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp new file mode 100644 index 000000000..fe82a3a7b --- /dev/null +++ b/tests/ChunkData/ArraytoCoord.cpp @@ -0,0 +1,116 @@ + +#include "TestGlobals.h" +#include "ChunkData.h" + + + +int main(int argc, char** argv) +{ + { + // Test first segment + cChunkData buffer; + + BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + SrcBlockBuffer[7+4*16+5*16*16] = 0xCD; + buffer.SetBlocks(SrcBlockBuffer); + testassert(buffer.GetBlock(7,5,4) == 0xCD); + delete SrcBlockBuffer; + SrcBlockBuffer = NULL; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; + buffer.SetMeta(SrcNibbleBuffer); + testassert(buffer.GetMeta(6,2,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; + buffer.SetLight(SrcNibbleBuffer); + testassert(buffer.GetBlockLight(6,2,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE; + buffer.SetSkyLight(SrcNibbleBuffer); + testassert(buffer.GetSkyLight(6,2,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + } + + { + // test following segment + cChunkData buffer; + + BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + SrcBlockBuffer[7+4*16+24*16*16] = 0xCD; + buffer.SetBlocks(SrcBlockBuffer); + testassert(buffer.GetBlock(7,24,4) == 0xCD); + delete SrcBlockBuffer; + SrcBlockBuffer = NULL; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; + buffer.SetMeta(SrcNibbleBuffer); + testassert(buffer.GetMeta(6,24,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; + buffer.SetLight(SrcNibbleBuffer); + testassert(buffer.GetBlockLight(6,24,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE; + buffer.SetSkyLight(SrcNibbleBuffer); + testassert(buffer.GetSkyLight(6,24,1) == 0xE); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + } + + { + // test zeros + cChunkData buffer; + + BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + buffer.SetBlocks(SrcBlockBuffer); + testassert(buffer.GetBlock(7,24,4) == 0x00); + delete SrcBlockBuffer; + SrcBlockBuffer = NULL; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + buffer.SetMeta(SrcNibbleBuffer); + testassert(buffer.GetMeta(6,24,1) == 0x0); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + buffer.SetLight(SrcNibbleBuffer); + testassert(buffer.GetBlockLight(6,24,1) == 0x0); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); + buffer.SetSkyLight(SrcNibbleBuffer); + testassert(buffer.GetSkyLight(6,24,1) == 0xF); + delete SrcNibbleBuffer; + SrcNibbleBuffer = NULL; + } +} + diff --git a/tests/ChunkData/CMakeLists.txt b/tests/ChunkData/CMakeLists.txt new file mode 100644 index 000000000..3f6653bb5 --- /dev/null +++ b/tests/ChunkData/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required (VERSION 2.6) + +enable_testing() + +include_directories(${CMAKE_SOURCE_DIR}/src/) + +add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp) + + +add_executable(creatable-exe creatable.cpp) +target_link_libraries(creatable-exe ChunkBuffer) +add_test(NAME creatable-test COMMAND creatable-exe) + +add_executable(coordinates-exe Coordinates.cpp) +target_link_libraries(coordinates-exe ChunkBuffer) +add_test(NAME coordinates-test COMMAND coordinates-exe) + +add_executable(copies-exe Copies.cpp) +target_link_libraries(copies-exe ChunkBuffer) +add_test(NAME copies-test COMMAND copies-exe) + +add_executable(arraystocoords-exe ArraytoCoord.cpp) +target_link_libraries(arraystocoords-exe ChunkBuffer) +add_test(NAME arraystocoords-test COMMAND arraystocoords-exe) + diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp new file mode 100644 index 000000000..c0c46000e --- /dev/null +++ b/tests/ChunkData/Coordinates.cpp @@ -0,0 +1,143 @@ + +#include "TestGlobals.h" +#include "ChunkData.h" + + + +int main(int argc, char** argv) +{ + { + cChunkData buffer; + + // Empty chunks + buffer.SetBlock(0,0,0, 0xAB); + testassert(buffer.GetBlock(0,0,0) == 0xAB); + buffer.SetMeta(0,16,0, 0xC); + testassert(buffer.GetMeta(0,16,0) == 0xC); + + // loaded but not written segments + testassert(buffer.GetBlock(1,0,0) == 0x0); + testassert(buffer.GetMeta(1,16,0) == 0x0); + + // Notloaded segments + testassert(buffer.GetBlock(0,32,0) == 0x0); + testassert(buffer.GetMeta(0,48,0) == 0x0); + + // Out of Range + CheckAsserts( + buffer.SetBlock(-1, 0, 0, 0); + ); + CheckAsserts( + buffer.SetBlock(0, -1, 0, 0); + ); + CheckAsserts( + buffer.SetBlock(0, 0, -1, 0); + ); + CheckAsserts( + buffer.SetBlock(256, 0, 0, 0); + ); + CheckAsserts( + buffer.SetBlock(0, 256, 0, 0); + ); + CheckAsserts( + buffer.SetBlock(0, 0, 256, 0); + ); + + // Out of Range + CheckAsserts( + buffer.GetBlock(-1, 0, 0); + ); + CheckAsserts( + buffer.GetBlock(0, -1, 0); + ); + CheckAsserts( + buffer.GetBlock(0, 0, -1); + ); + CheckAsserts( + buffer.GetBlock(256, 0, 0); + ); + CheckAsserts( + buffer.GetBlock(0, 256, 0); + ); + CheckAsserts( + buffer.GetBlock(0, 0, 256); + ); + + // Out of Range + CheckAsserts( + buffer.SetMeta(-1, 0, 0, 0); + ); + CheckAsserts( + buffer.SetMeta(0, -1, 0, 0); + ); + CheckAsserts( + buffer.SetMeta(0, 0, -1, 0); + ); + CheckAsserts( + buffer.SetMeta(256, 0, 0, 0); + ); + CheckAsserts( + buffer.SetMeta(0, 256, 0, 0); + ); + CheckAsserts( + buffer.SetMeta(0, 0, 256, 0); + ); + + // Out of Range + CheckAsserts( + buffer.GetMeta(-1, 0, 0); + ); + CheckAsserts( + buffer.GetMeta(0, -1, 0); + ); + CheckAsserts( + buffer.GetMeta(0, 0, -1); + ); + CheckAsserts( + buffer.GetMeta(256, 0, 0); + ); + CheckAsserts( + buffer.GetMeta(0, 256, 0); + ); + CheckAsserts( + buffer.GetMeta(0, 0, 256); + ); + } + + { + cChunkData buffer; + + // Zero's + buffer.SetBlock(0,0,0, 0x0); + buffer.SetBlock(0,0,1, 0xAB); + testassert(buffer.GetBlock(0,0,0) == 0x0); + testassert(buffer.GetBlock(0,0,1) == 0xAB); + + buffer.SetMeta(0,16,0, 0x0); + buffer.SetMeta(0,16,1, 0xC); + testassert(buffer.GetMeta(0,16,0) == 0x0); + testassert(buffer.GetMeta(0,16,1) == 0xC); + } + + + { + // Operator = + cChunkData buffer; + buffer.SetBlock(0,0,0,0x42); + cChunkData copy; + #if __cplusplus < 201103L + copy = buffer; + #else + copy = std::move(buffer); + #endif + testassert(copy.GetBlock(0,0,0) == 0x42); + #if __cplusplus < 201103L + copy = copy; + #else + copy = std::move(copy); + #endif + testassert(copy.GetBlock(0,0,0) == 0x42); + } + + return 0; +} diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp new file mode 100644 index 000000000..145ffd8e0 --- /dev/null +++ b/tests/ChunkData/Copies.cpp @@ -0,0 +1,193 @@ + +#include "TestGlobals.h" +#include "ChunkData.h" + + + +int main(int argc, char** argv) +{ + { + cChunkData buffer; + + buffer.SetBlock(3,1,4,0xDE); + buffer.SetMeta(3,1,4,0xA); + + cChunkData copy = buffer.Copy(); + testassert(copy.GetBlock(3,1,4) == 0xDE); + testassert(copy.GetMeta(3,1,4) == 0xA); + + BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + for (int i = 0; i < 16 * 16 * 256; i += 4) + { + SrcBlockBuffer[i+0] = 0xDE; + SrcBlockBuffer[i+1] = 0xAD; + SrcBlockBuffer[i+2] = 0xBE; + SrcBlockBuffer[i+3] = 0xEF; + } + + buffer.SetBlocks(SrcBlockBuffer); + BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + buffer.CopyBlocks(DstBlockBuffer); + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); + delete SrcBlockBuffer; + delete DstBlockBuffer; + SrcBlockBuffer = NULL; + DstBlockBuffer = NULL; + + SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + buffer.SetBlocks(SrcBlockBuffer); + DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + buffer.CopyBlocks(DstBlockBuffer); + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); + delete SrcBlockBuffer; + delete DstBlockBuffer; + SrcBlockBuffer = NULL; + DstBlockBuffer = NULL; + + } + { + cChunkData buffer; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) + { + SrcNibbleBuffer[i+0] = 0xEF; + SrcNibbleBuffer[i+1] = 0xDE; + SrcNibbleBuffer[i+2] = 0xAD; + SrcNibbleBuffer[i+3] = 0xBE; + } + + buffer.SetMeta(SrcNibbleBuffer); + NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyMeta(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + buffer.SetMeta(SrcNibbleBuffer); + DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyMeta(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + } + { + cChunkData buffer; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) + { + SrcNibbleBuffer[i+0] = 0xDE; + SrcNibbleBuffer[i+1] = 0xAD; + SrcNibbleBuffer[i+2] = 0xBE; + SrcNibbleBuffer[i+3] = 0xEF; + } + + buffer.SetLight(SrcNibbleBuffer); + NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + buffer.SetLight(SrcNibbleBuffer); + DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + + } + { + cChunkData buffer; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + for (int i = 0; i < 16 * 16 * 256 / 2; i += 4) + { + SrcNibbleBuffer[i+0] = 0xAD; + SrcNibbleBuffer[i+1] = 0xBE; + SrcNibbleBuffer[i+2] = 0xEF; + SrcNibbleBuffer[i+3] = 0xDE; + } + + buffer.SetSkyLight(SrcNibbleBuffer); + NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopySkyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); + buffer.SetSkyLight(SrcNibbleBuffer); + DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopySkyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + } + { + cChunkData buffer; + + BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + memset(SrcBlockBuffer, 0x00, 16 * 16 * 256); + BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256]; + buffer.CopyBlocks(DstBlockBuffer); + testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0); + delete SrcBlockBuffer; + delete DstBlockBuffer; + SrcBlockBuffer = NULL; + DstBlockBuffer = NULL; + + NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyMeta(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2); + DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + + SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2]; + memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2); + DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2]; + buffer.CopySkyLight(DstNibbleBuffer); + testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) -1) == 0); + delete SrcNibbleBuffer; + delete DstNibbleBuffer; + SrcNibbleBuffer = NULL; + DstNibbleBuffer = NULL; + } +} diff --git a/tests/ChunkData/creatable.cpp b/tests/ChunkData/creatable.cpp new file mode 100644 index 000000000..74025cb14 --- /dev/null +++ b/tests/ChunkData/creatable.cpp @@ -0,0 +1,9 @@ + +#include "TestGlobals.h" +#include "ChunkData.h" + +int main(int argc, char** argv) +{ + cChunkData buffer; + return 0; +} -- cgit v1.2.3 From 5929ffbc40d24f4e69cf12c8495d194407547c9c Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 20:08:34 +0100 Subject: Fixed stylistic issues --- src/BlockArea.cpp | 8 ++++---- src/Chunk.cpp | 4 ++-- src/ChunkData.cpp | 18 +++++++++--------- src/ChunkData.h | 20 ++++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index 0c46e59e5..abbfca767 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -1838,7 +1838,7 @@ bool cBlockArea::cChunkReader::Coords(int a_ChunkX, int a_ChunkZ) void cBlockArea::cChunkReader::ChunkData(const cChunkData & a_BlockBuffer) { { - if (!(m_Area.m_BlockTypes == NULL)) + if (m_Area.m_BlockTypes != NULL) { int SizeY = m_Area.m_Size.y; int MinY = m_Origin.y; @@ -1901,17 +1901,17 @@ void cBlockArea::cChunkReader::ChunkData(const cChunkData & a_BlockBuffer) } } - if (m_Area.m_BlockMetas) + if (m_Area.m_BlockMetas != NULL) { a_BlockBuffer.CopyMeta(m_Area.m_BlockMetas); } - if (m_Area.m_BlockLight) + if (m_Area.m_BlockLight != NULL) { a_BlockBuffer.CopyLight(m_Area.m_BlockLight); } - if (m_Area.m_BlockSkyLight) + if (m_Area.m_BlockSkyLight != NULL) { a_BlockBuffer.CopySkyLight(m_Area.m_BlockSkyLight); } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index a45ed32c1..d85b44607 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -326,9 +326,9 @@ 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 :) - m_ChunkData.SetLight (a_BlockLight); + m_ChunkData.SetLight(a_BlockLight); - m_ChunkData.SetSkyLight (a_SkyLight); + m_ChunkData.SetSkyLight(a_SkyLight); m_IsLightValid = true; } diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 160d118ad..7194eca92 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -7,7 +7,7 @@ cChunkData cChunkData::Copy() const cChunkData copy; for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i]) + if(m_Sections[i] == NULL) { copy.m_Sections[i] = Allocate(); *copy.m_Sections[i] = *m_Sections[i]; @@ -30,7 +30,7 @@ void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) { size_t tocopy = length > segment_length ? segment_length : length; length -= tocopy; - if(m_Sections[i]) + if(m_Sections[i] == NULL) { memcpy( &a_dest[i * segment_length], @@ -59,7 +59,7 @@ void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) + if(m_Sections[i] == NULL) { memcpy( &a_dest[i * segment_length], @@ -86,7 +86,7 @@ void cChunkData::CopyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) + if(m_Sections[i] == NULL) { memcpy( &a_dest[i * segment_length], @@ -114,7 +114,7 @@ void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i]) + if(m_Sections[i] == NULL) { memcpy( &a_dest[i * segment_length], @@ -142,7 +142,7 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; - if (m_Sections[i]) + if (m_Sections[i] == NULL) { memcpy(&m_Sections[i]->m_BlockTypes, &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length); } @@ -180,7 +180,7 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) + if (m_Sections[i] == NULL) { memcpy(&m_Sections[i]->m_BlockMeta, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); } @@ -219,7 +219,7 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) + if (m_Sections[i] == NULL) { memcpy(&m_Sections[i]->m_BlockLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); } @@ -258,7 +258,7 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i]) + if (m_Sections[i] == NULL) { memcpy(&m_Sections[i]->m_BlockSkyLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); } diff --git a/src/ChunkData.h b/src/ChunkData.h index 809f3cdf2..24a437629 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: #endif for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i]) Free(m_Sections[i]);; + if(m_Sections[i] == NULL) Free(m_Sections[i]);; } } @@ -91,7 +91,7 @@ public: { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i]) Free(m_Sections[i]);; + Free(m_Sections[i]);; m_Sections[i] = other.m_Sections[i]; other.m_Sections[i] = 0; } @@ -106,7 +106,7 @@ public: ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); int Section = a_Y / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) + if(m_Sections[Section] == NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_X, a_Y - (Section * CHUNK_SECTION_HEIGHT), a_Z); return m_Sections[Section]->m_BlockTypes[Index]; @@ -130,14 +130,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(!m_Sections[Section]) + if(m_Sections[Section] != NULL) { if(a_Block == 0x00) { return; } m_Sections[Section] = Allocate(); - if(!m_Sections[Section]) + if(m_Sections[Section] != NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return; @@ -153,7 +153,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) + if(m_Sections[Section] == NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -180,14 +180,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(!m_Sections[Section]) + if(m_Sections[Section] != NULL) { if((a_Nibble & 0xf) == 0x00) { return; } m_Sections[Section] = Allocate(); - if(!m_Sections[Section]) + if(m_Sections[Section] != NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return; @@ -206,7 +206,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) + if(m_Sections[Section] == NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -225,7 +225,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section]) + if(m_Sections[Section] == NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; -- cgit v1.2.3 From bd880603a560160d247d79a2fdeb3fbab26994f0 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 20:18:09 +0100 Subject: Changed cChunkData::SetMeta to return a bool indicating whether the value changed --- src/Chunk.h | 6 +++--- src/ChunkData.h | 10 ++++++---- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Chunk.h b/src/Chunk.h index 4f6c4cf0a..2de45919e 100644 --- a/src/Chunk.h +++ b/src/Chunk.h @@ -328,11 +328,11 @@ public: } inline void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta) { - if (!(GetMeta(a_RelX, a_RelY, a_RelZ) == a_Meta)) + bool hasChanged = m_ChunkData.SetMeta(a_RelX, a_RelY, a_RelZ, a_Meta); + if (hasChanged) { MarkDirty(); - m_ChunkData.SetMeta(a_RelX, a_RelY, a_RelZ, a_Meta); - + m_PendingSendBlocks.push_back(sSetBlock(m_PosX, m_PosZ, a_RelX, a_RelY, a_RelZ, GetBlock(a_RelX, a_RelY, a_RelZ), a_Meta)); } } diff --git a/src/ChunkData.h b/src/ChunkData.h index 24a437629..73b1e8c6a 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -167,7 +167,7 @@ public: return 0; } - void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Nibble) + bool SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Nibble) { if ( (a_RelX >= cChunkDef::Width) || (a_RelX < 0) || @@ -176,7 +176,7 @@ public: ) { ASSERT(!"cChunkData::SetMeta(): index out of range!"); - return; + return false; } int Section = a_RelY / CHUNK_SECTION_HEIGHT; @@ -184,21 +184,23 @@ public: { if((a_Nibble & 0xf) == 0x00) { - return; + return false; } m_Sections[Section] = Allocate(); if(m_Sections[Section] != NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); - return; + return false; } ZeroSection(m_Sections[Section]); } int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); + NIBBLETYPE oldval = m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4) & 0xf; m_Sections[Section]->m_BlockMeta[Index / 2] = static_cast( (m_Sections[Section]->m_BlockMeta[Index / 2] & (0xf0 >> ((Index & 1) * 4))) | // The untouched nibble ((a_Nibble & 0x0f) << ((Index & 1) * 4)) // The nibble being set ); + return oldval == a_Nibble; } NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const -- cgit v1.2.3 From 93c0dcb1feb6daebbea586e750b586ec6588bfa2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 20:26:43 +0100 Subject: Added space to ChunkData.cpp --- src/ChunkData.cpp | 120 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 100 insertions(+), 20 deletions(-) diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 7194eca92..f8c4a851d 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -144,7 +144,11 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; if (m_Sections[i] == NULL) { - memcpy(&m_Sections[i]->m_BlockTypes, &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length); + memcpy( + &m_Sections[i]->m_BlockTypes, + &a_src[i * segment_length], + sizeof(BLOCKTYPE) * segment_length + ); } else { @@ -159,9 +163,21 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length ); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + memset( + m_Sections[i]->m_BlockMeta, + 0x00, + sizeof(m_Sections[i]->m_BlockMeta) + ); + memset( + m_Sections[i]->m_BlockLight, + 0x00, + sizeof(m_Sections[i]->m_BlockLight) + ); + memset( + m_Sections[i]->m_BlockSkyLight, + 0xFF, + sizeof(m_Sections[i]->m_BlockSkyLight) + ); } else { @@ -182,7 +198,11 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] == NULL) { - memcpy(&m_Sections[i]->m_BlockMeta, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + memcpy( + &m_Sections[i]->m_BlockMeta, + &a_src[i * segment_length], + sizeof(NIBBLETYPE) * segment_length + ); } else { @@ -197,9 +217,21 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + memset( + m_Sections[i]->m_BlockTypes, + 0x00, + sizeof(m_Sections[i]->m_BlockTypes) + ); + memset( + m_Sections[i]->m_BlockLight, + 0x00, + sizeof(m_Sections[i]->m_BlockLight) + ); + memset( + m_Sections[i]->m_BlockSkyLight, + 0xFF, + sizeof(m_Sections[i]->m_BlockSkyLight) + ); } else { @@ -221,7 +253,11 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] == NULL) { - memcpy(&m_Sections[i]->m_BlockLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + memcpy( + &m_Sections[i]->m_BlockLight, + &a_src[i * segment_length], + sizeof(NIBBLETYPE) * segment_length + ); } else { @@ -236,9 +272,21 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockSkyLight,0xFF,sizeof(m_Sections[i]->m_BlockSkyLight)); + memset( + m_Sections[i]->m_BlockTypes, + 0x00, + sizeof(m_Sections[i]->m_BlockTypes) + ); + memset( + m_Sections[i]->m_BlockMeta, + 0x00, + sizeof(m_Sections[i]->m_BlockMeta) + ); + memset( + m_Sections[i]->m_BlockSkyLight, + 0xFF, + sizeof(m_Sections[i]->m_BlockSkyLight) + ); } else { @@ -260,7 +308,11 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; if (m_Sections[i] == NULL) { - memcpy(&m_Sections[i]->m_BlockSkyLight, &a_src[i * segment_length], sizeof(NIBBLETYPE) * segment_length); + memcpy( + &m_Sections[i]->m_BlockSkyLight, + &a_src[i * segment_length], + sizeof(NIBBLETYPE) * segment_length + ); } else { @@ -275,9 +327,21 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) &a_src[i * segment_length], sizeof(BLOCKTYPE) * segment_length ); - memset(m_Sections[i]->m_BlockTypes,0x00,sizeof(m_Sections[i]->m_BlockTypes)); - memset(m_Sections[i]->m_BlockMeta,0x00,sizeof(m_Sections[i]->m_BlockMeta)); - memset(m_Sections[i]->m_BlockLight,0x00,sizeof(m_Sections[i]->m_BlockLight)); + memset( + m_Sections[i]->m_BlockTypes, + 0x00, + sizeof(m_Sections[i]->m_BlockTypes) + ); + memset( + m_Sections[i]->m_BlockMeta, + 0x00, + sizeof(m_Sections[i]->m_BlockMeta) + ); + memset( + m_Sections[i]->m_BlockLight, + 0x00, + sizeof(m_Sections[i]->m_BlockLight) + ); } else { @@ -309,10 +373,26 @@ void cChunkData::Free(cChunkData::sChunkSection * ptr) const void cChunkData::ZeroSection(cChunkData::sChunkSection * ptr) const { - memset(ptr->m_BlockTypes,0x00,sizeof(ptr->m_BlockTypes)); - memset(ptr->m_BlockMeta,0x00,sizeof(ptr->m_BlockMeta)); - memset(ptr->m_BlockLight,0x00,sizeof(ptr->m_BlockLight)); - memset(ptr->m_BlockSkyLight,0xFF,sizeof(ptr->m_BlockSkyLight)); + memset( + ptr->m_BlockTypes, + 0x00, + sizeof(ptr->m_BlockTypes) + ); + memset( + ptr->m_BlockMeta, + 0x00, + sizeof(ptr->m_BlockMeta) + ); + memset( + ptr->m_BlockLight, + 0x00, + sizeof(ptr->m_BlockLight) + ); + memset( + ptr->m_BlockSkyLight, + 0xFF, + sizeof(ptr->m_BlockSkyLight) + ); } -- cgit v1.2.3 From 88c61a2e96af9c7d1b173c0b580cef2c348850d7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 21:18:14 +0100 Subject: Fixed reversed comparisons to null --- src/ChunkData.cpp | 18 +++++++++--------- src/ChunkData.h | 16 ++++++++-------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index f8c4a851d..0cacaf02d 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -7,7 +7,7 @@ cChunkData cChunkData::Copy() const cChunkData copy; for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i] == NULL) + if(m_Sections[i] != NULL) { copy.m_Sections[i] = Allocate(); *copy.m_Sections[i] = *m_Sections[i]; @@ -30,7 +30,7 @@ void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) { size_t tocopy = length > segment_length ? segment_length : length; length -= tocopy; - if(m_Sections[i] == NULL) + if(m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -59,7 +59,7 @@ void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] == NULL) + if(m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -86,7 +86,7 @@ void cChunkData::CopyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] == NULL) + if(m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -114,7 +114,7 @@ void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] == NULL) + if(m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -142,7 +142,7 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16; - if (m_Sections[i] == NULL) + if (m_Sections[i] != NULL) { memcpy( &m_Sections[i]->m_BlockTypes, @@ -196,7 +196,7 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i] == NULL) + if (m_Sections[i] != NULL) { memcpy( &m_Sections[i]->m_BlockMeta, @@ -251,7 +251,7 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i] == NULL) + if (m_Sections[i] != NULL) { memcpy( &m_Sections[i]->m_BlockLight, @@ -306,7 +306,7 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src) for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if (m_Sections[i] == NULL) + if (m_Sections[i] != NULL) { memcpy( &m_Sections[i]->m_BlockSkyLight, diff --git a/src/ChunkData.h b/src/ChunkData.h index 73b1e8c6a..51244225b 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -106,7 +106,7 @@ public: ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); int Section = a_Y / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if(m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_X, a_Y - (Section * CHUNK_SECTION_HEIGHT), a_Z); return m_Sections[Section]->m_BlockTypes[Index]; @@ -130,14 +130,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if(m_Sections[Section] == NULL) { if(a_Block == 0x00) { return; } m_Sections[Section] = Allocate(); - if(m_Sections[Section] != NULL) + if(m_Sections[Section] == NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return; @@ -153,7 +153,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if(m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -180,14 +180,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if(m_Sections[Section] == NULL) { if((a_Nibble & 0xf) == 0x00) { return false; } m_Sections[Section] = Allocate(); - if(m_Sections[Section] != NULL) + if(m_Sections[Section] == NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return false; @@ -208,7 +208,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if(m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -227,7 +227,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if(m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; -- cgit v1.2.3 From 4b23472097fa2daee464b6c5d73da56a0706731c Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 21 May 2014 21:46:20 +0100 Subject: Fixed if spaces --- src/ChunkData.cpp | 13 +++++++------ src/ChunkData.h | 32 ++++++++++++++++---------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp index 0cacaf02d..86b0c431c 100644 --- a/src/ChunkData.cpp +++ b/src/ChunkData.cpp @@ -7,7 +7,7 @@ cChunkData cChunkData::Copy() const cChunkData copy; for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i] != NULL) + if (m_Sections[i] != NULL) { copy.m_Sections[i] = Allocate(); *copy.m_Sections[i] = *m_Sections[i]; @@ -30,7 +30,7 @@ void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) { size_t tocopy = length > segment_length ? segment_length : length; length -= tocopy; - if(m_Sections[i] != NULL) + if (m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -59,12 +59,13 @@ void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] != NULL) + if (m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], &m_Sections[i]->m_BlockMeta, - sizeof(NIBBLETYPE) * segment_length); + sizeof(NIBBLETYPE) * segment_length + ); } else { @@ -86,7 +87,7 @@ void cChunkData::CopyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] != NULL) + if (m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], @@ -114,7 +115,7 @@ void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const for (size_t i = 0; i < CHUNK_SECTION_NUM; i++) { const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2; - if(m_Sections[i] != NULL) + if (m_Sections[i] != NULL) { memcpy( &a_dest[i * segment_length], diff --git a/src/ChunkData.h b/src/ChunkData.h index 51244225b..9c852ee24 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -33,11 +33,11 @@ public: { #if __cplusplus < 201103L // auto_ptr style interface for memory management - if(!IsOwner) return; + if (!IsOwner) return; #endif for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i] == NULL) Free(m_Sections[i]);; + if (m_Sections[i] == NULL) Free(m_Sections[i]);; } } @@ -55,13 +55,13 @@ public: cChunkData& operator=(const cChunkData& other) { - if(&other != this) + if (&other != this) { - if(IsOwner) + if (IsOwner) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { - if(m_Sections[i]) Free(m_Sections[i]);; + if (m_Sections[i]) Free(m_Sections[i]);; } } IsOwner = true; @@ -87,7 +87,7 @@ public: cChunkData& operator=(cChunkData&& other) { - if(&other != this) + if (&other != this) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -106,7 +106,7 @@ public: ASSERT((a_Y >= 0) && (a_Y < cChunkDef::Height)); ASSERT((a_Z >= 0) && (a_Z < cChunkDef::Width)); int Section = a_Y / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if (m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_X, a_Y - (Section * CHUNK_SECTION_HEIGHT), a_Z); return m_Sections[Section]->m_BlockTypes[Index]; @@ -130,14 +130,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if (m_Sections[Section] == NULL) { - if(a_Block == 0x00) + if (a_Block == 0x00) { return; } m_Sections[Section] = Allocate(); - if(m_Sections[Section] == NULL) + if (m_Sections[Section] == NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return; @@ -153,7 +153,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if (m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockMeta[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -180,14 +180,14 @@ public: } int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] == NULL) + if (m_Sections[Section] == NULL) { - if((a_Nibble & 0xf) == 0x00) + if ((a_Nibble & 0xf) == 0x00) { return false; } m_Sections[Section] = Allocate(); - if(m_Sections[Section] == NULL) + if (m_Sections[Section] == NULL) { ASSERT(!"Failed to allocate a new section in Chunkbuffer"); return false; @@ -208,7 +208,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if (m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; @@ -227,7 +227,7 @@ public: if ((a_RelX < cChunkDef::Width) && (a_RelX > -1) && (a_RelY < cChunkDef::Height) && (a_RelY > -1) && (a_RelZ < cChunkDef::Width) && (a_RelZ > -1)) { int Section = a_RelY / CHUNK_SECTION_HEIGHT; - if(m_Sections[Section] != NULL) + if (m_Sections[Section] != NULL) { int Index = cChunkDef::MakeIndexNoCheck(a_RelX, a_RelY - (Section * CHUNK_SECTION_HEIGHT), a_RelZ); return (m_Sections[Section]->m_BlockLight[Index / 2] >> ((Index & 1) * 4)) & 0x0f; -- cgit v1.2.3 From 41692da30c9985ea1b5aa7430cb582997293bdd7 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 15:01:27 +0100 Subject: Ignore CTest files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c544f394d..859ef28ea 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ world_nether CMakeFiles/ cmake_install.cmake CMakeCache.txt +CTestTestfile.cmake Makefile *.a -- cgit v1.2.3