summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTycho <work.tycho+git@gmail.com>2014-05-24 14:33:40 +0200
committerTycho <work.tycho+git@gmail.com>2014-05-24 14:33:40 +0200
commit8f964886e0ccbf51dac07227f0ac4c739b47d3a5 (patch)
tree534fec1ed8061513b67d8504a95f2bd926416d53
parentMerge branch 'master' into chunksparsing/structs (diff)
downloadcuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar.gz
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar.bz2
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar.lz
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar.xz
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.tar.zst
cuberite-8f964886e0ccbf51dac07227f0ac4c739b47d3a5.zip
-rw-r--r--src/BlockArea.cpp2
-rw-r--r--src/Chunk.cpp4
-rw-r--r--src/Chunk.h4
-rw-r--r--src/ChunkData.cpp61
-rw-r--r--src/ChunkData.h108
-rw-r--r--src/ChunkDataCallback.h8
-rw-r--r--tests/ChunkData/ArraytoCoord.cpp90
-rw-r--r--tests/ChunkData/Coordinates.cpp38
-rw-r--r--tests/ChunkData/Copies.cpp135
9 files changed, 182 insertions, 268 deletions
diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp
index 87236957a..11bd76e6c 100644
--- a/src/BlockArea.cpp
+++ b/src/BlockArea.cpp
@@ -1908,7 +1908,7 @@ void cBlockArea::cChunkReader::ChunkData(const cChunkData & a_BlockBuffer)
if (m_Area.m_BlockLight != NULL)
{
- a_BlockBuffer.CopyLight(m_Area.m_BlockLight);
+ a_BlockBuffer.CopyBlockLight(m_Area.m_BlockLight);
}
if (m_Area.m_BlockSkyLight != NULL)
diff --git a/src/Chunk.cpp b/src/Chunk.cpp
index d85b44607..e5f8f1e29 100644
--- a/src/Chunk.cpp
+++ b/src/Chunk.cpp
@@ -284,7 +284,7 @@ void cChunk::SetAllData(
m_ChunkData.SetBlocks(a_BlockTypes);
m_ChunkData.SetMeta(a_BlockMeta);
- m_ChunkData.SetLight(a_BlockLight);
+ m_ChunkData.SetBlockLight(a_BlockLight);
m_ChunkData.SetSkyLight(a_BlockSkyLight);
m_IsLightValid = (a_BlockLight != NULL) && (a_BlockSkyLight != NULL);
@@ -326,7 +326,7 @@ 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.SetBlockLight(a_BlockLight);
m_ChunkData.SetSkyLight(a_SkyLight);
diff --git a/src/Chunk.h b/src/Chunk.h
index 2de45919e..d95537acf 100644
--- a/src/Chunk.h
+++ b/src/Chunk.h
@@ -67,7 +67,7 @@ public:
cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP // Neighbor chunks
);
- cChunk(cChunk& other);
+ cChunk(cChunk & other);
~cChunk();
bool IsValid(void) const {return m_IsValid; } // Returns true if the chunk block data is valid (loaded / generated)
@@ -156,7 +156,7 @@ public:
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta ); // Doesn't force block updates on neighbors, use for simple changes such as grass growing etc.
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const;
- BLOCKTYPE GetBlock(Vector3i a_cords) const { return GetBlock(a_cords.x,a_cords.y,a_cords.z);}
+ BLOCKTYPE GetBlock(Vector3i a_cords) const { return GetBlock(a_cords.x, a_cords.y, a_cords.z);}
void GetBlockTypeMeta(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);
void GetBlockInfo (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_Meta, NIBBLETYPE & a_SkyLight, NIBBLETYPE & a_BlockLight);
diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp
index 86b0c431c..098f436f8 100644
--- a/src/ChunkData.cpp
+++ b/src/ChunkData.cpp
@@ -5,7 +5,7 @@
cChunkData cChunkData::Copy() const
{
cChunkData copy;
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
if (m_Sections[i] != NULL)
{
@@ -22,13 +22,16 @@ cChunkData cChunkData::Copy() const
void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) const
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; 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)
+ {
+ a_Idx = std::max(a_Idx - length, (size_t) 0);
+ }
if (a_Idx == 0)
{
- size_t tocopy = length > segment_length ? segment_length : length;
+ size_t tocopy = std::min(segment_length, length);
length -= tocopy;
if (m_Sections[i] != NULL)
{
@@ -56,7 +59,7 @@ void cChunkData::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length)
void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -82,9 +85,9 @@ void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const
-void cChunkData::CopyLight(NIBBLETYPE * a_dest) const
+void cChunkData::CopyBlockLight(NIBBLETYPE * a_dest) const
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -112,7 +115,7 @@ void cChunkData::CopyLight(NIBBLETYPE * a_dest) const
void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -140,7 +143,7 @@ void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const
void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16;
if (m_Sections[i] != NULL)
@@ -153,6 +156,9 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
}
else
{
+ // j counts how many of leading zeros the buffer has
+ // if j == segment_length then the buffer is all zeros so there is no point
+ // creating the buffer.
size_t j = 0;
// do nothing whilst 0
for (; j < segment_length && a_src[i * segment_length + j] == 0; j++);
@@ -180,11 +186,6 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
sizeof(m_Sections[i]->m_BlockSkyLight)
);
}
- else
- {
- Free(m_Sections[i]);
- m_Sections[i] = 0;
- }
}
}
}
@@ -194,7 +195,7 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
void cChunkData::SetMeta(const NIBBLETYPE * a_src)
{
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -207,6 +208,9 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src)
}
else
{
+ // j counts how many of leading zeros the buffer has
+ // if j == segment_length then the buffer is all zeros so there is no point
+ // creating the buffer.
size_t j = 0;
// do nothing whilst 0
for (; j < segment_length && a_src[i * segment_length + j] == 0; j++);
@@ -234,11 +238,6 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src)
sizeof(m_Sections[i]->m_BlockSkyLight)
);
}
- else
- {
- Free(m_Sections[i]);
- m_Sections[i] = 0;
- }
}
}
}
@@ -246,10 +245,10 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src)
-void cChunkData::SetLight(const NIBBLETYPE * a_src)
+void cChunkData::SetBlockLight(const NIBBLETYPE * a_src)
{
if (!a_src) return;
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -262,6 +261,9 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src)
}
else
{
+ // j counts how many of leading zeros the buffer has
+ // if j == segment_length then the buffer is all zeros so there is no point
+ // creating the buffer.
size_t j = 0;
// do nothing whilst 0
for (; j < segment_length && a_src[i * segment_length + j] == 0; j++);
@@ -289,11 +291,6 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src)
sizeof(m_Sections[i]->m_BlockSkyLight)
);
}
- else
- {
- Free(m_Sections[i]);
- m_Sections[i] = 0;
- }
}
}
}
@@ -304,7 +301,7 @@ void cChunkData::SetLight(const NIBBLETYPE * a_src)
void cChunkData::SetSkyLight (const NIBBLETYPE * a_src)
{
if (!a_src) return;
- for (size_t i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
@@ -317,6 +314,9 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src)
}
else
{
+ // j counts how many of leading zeros the buffer has
+ // if j == segment_length then the buffer is all zeros so there is no point
+ // creating the buffer.
size_t j = 0;
// do nothing whilst 0
for (; j < segment_length && a_src[i * segment_length + j] == 0xFF; j++);
@@ -344,11 +344,6 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src)
sizeof(m_Sections[i]->m_BlockLight)
);
}
- else
- {
- Free(m_Sections[i]);
- m_Sections[i] = 0;
- }
}
}
}
diff --git a/src/ChunkData.h b/src/ChunkData.h
index 9c852ee24..5a149f95f 100644
--- a/src/ChunkData.h
+++ b/src/ChunkData.h
@@ -8,8 +8,7 @@
#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
@@ -23,8 +22,8 @@ public:
cChunkData()
#if __cplusplus < 201103L
- // auto_ptr style interface for memory management
- : IsOwner(true)
+ // auto_ptr style interface for memory management
+ : IsOwner(true)
#endif
{
memset(m_Sections, 0, sizeof(m_Sections));
@@ -32,72 +31,75 @@ public:
~cChunkData()
{
#if __cplusplus < 201103L
- // auto_ptr style interface for memory management
- if (!IsOwner) return;
+ // auto_ptr style interface for memory management
+ if (!IsOwner)
+ {
+ return;
+ }
#endif
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
if (m_Sections[i] == NULL) 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++)
+ // auto_ptr style interface for memory management
+ cChunkData(const cChunkData& other) :
+ IsOwner(true)
{
- m_Sections[i] = other.m_Sections[i];
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
+ {
+ m_Sections[i] = other.m_Sections[i];
+ }
+ other.IsOwner = false;
}
- other.IsOwner = false;
- }
- cChunkData& operator=(const cChunkData& other)
- {
- if (&other != this)
+ cChunkData& operator=(const cChunkData& other)
{
- if (IsOwner)
+ if (&other != this)
{
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
+ if (IsOwner)
{
- if (m_Sections[i]) Free(m_Sections[i]);;
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
+ {
+ if (m_Sections[i]) Free(m_Sections[i]);;
+ }
}
+ IsOwner = true;
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
+ {
+ m_Sections[i] = other.m_Sections[i];
+ }
+ other.IsOwner = false;
}
- IsOwner = true;
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
- {
- m_Sections[i] = other.m_Sections[i];
- }
- other.IsOwner = false;
- }
- return *this;
+ return *this;
- }
+ }
#else
- // unique_ptr style interface for memory management
- cChunkData(cChunkData&& other)
- {
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
+ // unique_ptr style interface for memory management
+ cChunkData(cChunkData&& other)
{
- m_Sections[i] = other.m_Sections[i];
- other.m_Sections[i] = 0;
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
+ {
+ m_Sections[i] = other.m_Sections[i];
+ other.m_Sections[i] = NULL;
+ }
}
- }
- cChunkData& operator=(cChunkData&& other)
- {
- if (&other != this)
+ cChunkData& operator=(cChunkData&& other)
{
- for (int i = 0; i < CHUNK_SECTION_NUM; i++)
+ if (&other != this)
{
- Free(m_Sections[i]);;
- m_Sections[i] = other.m_Sections[i];
- other.m_Sections[i] = 0;
+ for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
+ {
+ Free(m_Sections[i]);;
+ m_Sections[i] = other.m_Sections[i];
+ other.m_Sections[i] = NULL;
+ }
}
+ return *this;
}
- return *this;
- }
#endif
BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z) const
@@ -150,7 +152,10 @@ public:
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))
+ 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)
@@ -244,16 +249,19 @@ public:
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 CopyBlockLight (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 SetBlockLight (const NIBBLETYPE * a_src);
void SetSkyLight (const NIBBLETYPE * a_src);
private:
+ static const size_t CHUNK_SECTION_HEIGHT = 16;
+ static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT);
+
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
mutable bool IsOwner;
@@ -266,7 +274,7 @@ private:
NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2];
};
- sChunkSection *m_Sections[CHUNK_SECTION_NUM];
+ sChunkSection *m_Sections[CHUNK_SECTION_COUNT];
sChunkSection * Allocate() const;
void Free(sChunkSection * ptr) const;
diff --git a/src/ChunkDataCallback.h b/src/ChunkDataCallback.h
index 340582885..e916d6486 100644
--- a/src/ChunkDataCallback.h
+++ b/src/ChunkDataCallback.h
@@ -62,7 +62,7 @@ protected:
/** A simple implementation of the cChunkDataCallback interface that collects all block data into a single buffer
*/
class cChunkDataArrayCollector :
-public cChunkDataCallback
+ public cChunkDataCallback
{
public:
@@ -75,7 +75,7 @@ protected:
{
a_ChunkBuffer.CopyBlocks(m_BlockData);
a_ChunkBuffer.CopyMeta(m_BlockData + cChunkDef::NumBlocks);
- a_ChunkBuffer.CopyLight(m_BlockData + 3 * cChunkDef::NumBlocks / 2);
+ a_ChunkBuffer.CopyBlockLight(m_BlockData + 3 * cChunkDef::NumBlocks / 2);
a_ChunkBuffer.CopySkyLight(m_BlockData + 2 * cChunkDef::NumBlocks);
}
};
@@ -83,7 +83,7 @@ protected:
/** A simple implementation of the cChunkDataCallback interface that collects all block data into a separate buffers
*/
class cChunkDataSeparateCollector :
-public cChunkDataCallback
+ public cChunkDataCallback
{
public:
@@ -98,7 +98,7 @@ protected:
{
a_ChunkBuffer.CopyBlocks(m_BlockTypes);
a_ChunkBuffer.CopyMeta(m_BlockMetas);
- a_ChunkBuffer.CopyLight(m_BlockLight);
+ a_ChunkBuffer.CopyBlockLight(m_BlockLight);
a_ChunkBuffer.CopySkyLight(m_BlockSkyLight);
}
} ;
diff --git a/tests/ChunkData/ArraytoCoord.cpp b/tests/ChunkData/ArraytoCoord.cpp
index fe82a3a7b..1138fb5b6 100644
--- a/tests/ChunkData/ArraytoCoord.cpp
+++ b/tests/ChunkData/ArraytoCoord.cpp
@@ -10,107 +10,77 @@ int main(int argc, char** argv)
// Test first segment
cChunkData buffer;
- BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- SrcBlockBuffer[7+4*16+5*16*16] = 0xCD;
+ 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;
+ NIBBLETYPE SrcNibbleBuffer[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;
+ testassert(buffer.GetMeta(6, 2, 1) == 0xE);
- 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;
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
+ SrcNibbleBuffer[(6 + (1 * 16) + (2 * 16 * 16)) / 2] = 0xE;
+ buffer.SetBlockLight(SrcNibbleBuffer);
+ testassert(buffer.GetBlockLight(6, 2, 1) == 0xE);
- SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- SrcNibbleBuffer[(6+1*16+2*16*16)/2] = 0xE;
+ 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;
+ testassert(buffer.GetSkyLight(6, 2, 1) == 0xE);
}
{
// test following segment
cChunkData buffer;
- BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- SrcBlockBuffer[7+4*16+24*16*16] = 0xCD;
+ SrcBlockBuffer[7 + (4 * 16) + (24 * 16 * 16)] = 0xCD;
buffer.SetBlocks(SrcBlockBuffer);
- testassert(buffer.GetBlock(7,24,4) == 0xCD);
- delete SrcBlockBuffer;
- SrcBlockBuffer = NULL;
+ testassert(buffer.GetBlock(7, 24, 4) == 0xCD);
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- SrcNibbleBuffer[(6+1*16+24*16*16)/2] = 0xE;
+ NIBBLETYPE SrcNibbleBuffer[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;
+ testassert(buffer.GetMeta(6, 24, 1) == 0xE);
- 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);
+ buffer.SetBlockLight(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;
+ memset(SrcNibbleBuffer, 0xFF, 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;
+ testassert(buffer.GetSkyLight(6, 24, 1) == 0xE);
}
{
// test zeros
cChunkData buffer;
- BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
buffer.SetBlocks(SrcBlockBuffer);
- testassert(buffer.GetBlock(7,24,4) == 0x00);
- delete SrcBlockBuffer;
- SrcBlockBuffer = NULL;
+ testassert(buffer.GetBlock(7, 24, 4) == 0x00);
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ NIBBLETYPE SrcNibbleBuffer[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;
+ testassert(buffer.GetMeta(6, 24, 1) == 0x0);
- SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- buffer.SetLight(SrcNibbleBuffer);
+ buffer.SetBlockLight(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;
+ testassert(buffer.GetSkyLight(6, 24, 1) == 0xF);
}
}
diff --git a/tests/ChunkData/Coordinates.cpp b/tests/ChunkData/Coordinates.cpp
index c0c46000e..f02b68d40 100644
--- a/tests/ChunkData/Coordinates.cpp
+++ b/tests/ChunkData/Coordinates.cpp
@@ -10,18 +10,18 @@ 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);
+ 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);
+ 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);
+ testassert(buffer.GetBlock(0, 32, 0) == 0x0);
+ testassert(buffer.GetMeta(0, 48, 0) == 0x0);
// Out of Range
CheckAsserts(
@@ -108,35 +108,35 @@ int main(int argc, char** argv)
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.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);
+ 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);
+ 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);
+ 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);
+ testassert(copy.GetBlock(0, 0, 0) == 0x42);
}
return 0;
diff --git a/tests/ChunkData/Copies.cpp b/tests/ChunkData/Copies.cpp
index 145ffd8e0..b10ddb759 100644
--- a/tests/ChunkData/Copies.cpp
+++ b/tests/ChunkData/Copies.cpp
@@ -9,14 +9,14 @@ int main(int argc, char** argv)
{
cChunkData buffer;
- buffer.SetBlock(3,1,4,0xDE);
- buffer.SetMeta(3,1,4,0xA);
+ 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);
+ testassert(copy.GetBlock(3, 1, 4) == 0xDE);
+ testassert(copy.GetMeta(3, 1, 4) == 0xA);
- BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
for (int i = 0; i < 16 * 16 * 256; i += 4)
{
SrcBlockBuffer[i+0] = 0xDE;
@@ -26,30 +26,20 @@ int main(int argc, char** argv)
}
buffer.SetBlocks(SrcBlockBuffer);
- BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
buffer.CopyBlocks(DstBlockBuffer);
- testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0);
- delete SrcBlockBuffer;
- delete DstBlockBuffer;
- SrcBlockBuffer = NULL;
- DstBlockBuffer = NULL;
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
- 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;
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
}
{
cChunkData buffer;
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
SrcNibbleBuffer[i+0] = 0xEF;
@@ -59,30 +49,21 @@ int main(int argc, char** argv)
}
buffer.SetMeta(SrcNibbleBuffer);
- NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ NIBBLETYPE DstNibbleBuffer[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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
- 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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
+
}
{
cChunkData buffer;
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
SrcNibbleBuffer[i+0] = 0xDE;
@@ -91,32 +72,22 @@ int main(int argc, char** argv)
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;
+ buffer.SetBlockLight(SrcNibbleBuffer);
+ NIBBLETYPE DstNibbleBuffer[16 * 16 * 256 / 2];
+ buffer.CopyBlockLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0);
- 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;
+ buffer.SetBlockLight(SrcNibbleBuffer);
+ buffer.CopyBlockLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 /2) - 1) == 0);
}
{
cChunkData buffer;
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
{
SrcNibbleBuffer[i+0] = 0xAD;
@@ -126,68 +97,38 @@ int main(int argc, char** argv)
}
buffer.SetSkyLight(SrcNibbleBuffer);
- NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ NIBBLETYPE DstNibbleBuffer[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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
- SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0xFF, 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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
}
{
cChunkData buffer;
- BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE SrcBlockBuffer[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
- BLOCKTYPE * DstBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
+ BLOCKTYPE DstBlockBuffer[16 * 16 * 256];
buffer.CopyBlocks(DstBlockBuffer);
- testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) -1) == 0);
- delete SrcBlockBuffer;
- delete DstBlockBuffer;
- SrcBlockBuffer = NULL;
- DstBlockBuffer = NULL;
+ testassert(memcmp(SrcBlockBuffer, DstBlockBuffer, (16 * 16 * 256) - 1) == 0);
- NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 /2);
- NIBBLETYPE * DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ NIBBLETYPE SrcNibbleBuffer[16 * 16 * 256 / 2];
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
+ NIBBLETYPE DstNibbleBuffer[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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
- 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;
+ memset(SrcNibbleBuffer, 0x00, 16 * 16 * 256 / 2);
+ buffer.CopyBlockLight(DstNibbleBuffer);
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
- SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
- memset(SrcNibbleBuffer, 0xFF, 16 * 16 * 256 /2);
- DstNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/ 2];
+ memset(SrcNibbleBuffer, 0xFF, 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;
+ testassert(memcmp(SrcNibbleBuffer, DstNibbleBuffer, (16 * 16 * 256 / 2) - 1) == 0);
}
}