summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft <github@xoft.cz>2014-05-28 22:40:19 +0200
committermadmaxoft <github@xoft.cz>2014-05-28 22:40:19 +0200
commit81f756cbda76507cc676fd50f20f33483c4ce6f8 (patch)
tree90dae000306f1c9eefa124fb298ae67755468451
parentFixed cChunkData formatting. (diff)
downloadcuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar.gz
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar.bz2
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar.lz
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar.xz
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.tar.zst
cuberite-81f756cbda76507cc676fd50f20f33483c4ce6f8.zip
Diffstat (limited to '')
-rw-r--r--src/ChunkData.cpp168
-rw-r--r--src/ChunkData.h27
2 files changed, 106 insertions, 89 deletions
diff --git a/src/ChunkData.cpp b/src/ChunkData.cpp
index 8aed62000..beee6c64a 100644
--- a/src/ChunkData.cpp
+++ b/src/ChunkData.cpp
@@ -306,33 +306,33 @@ cChunkData cChunkData::Copy(void) const
-void cChunkData::CopyBlocks(BLOCKTYPE * a_dest, size_t a_Idx, size_t length) const
+void cChunkData::CopyBlocks(BLOCKTYPE * a_Dest, size_t a_Idx, size_t a_Length) const
{
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16;
+ const size_t SegmentLength = CHUNK_SECTION_HEIGHT * 16 * 16;
if (a_Idx > 0)
{
- a_Idx = std::max(a_Idx - length, (size_t) 0);
+ a_Idx = std::max(a_Idx - a_Length, (size_t) 0);
}
if (a_Idx == 0)
{
- size_t tocopy = std::min(segment_length, length);
- length -= tocopy;
+ size_t ToCopy = std::min(SegmentLength, a_Length);
+ length -= ToCopy;
if (m_Sections[i] != NULL)
{
memcpy(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
&m_Sections[i]->m_BlockTypes,
- sizeof(BLOCKTYPE) * tocopy
+ sizeof(BLOCKTYPE) * ToCopy
);
}
else
{
memset(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
0,
- sizeof(BLOCKTYPE) * tocopy
+ sizeof(BLOCKTYPE) * ToCopy
);
}
}
@@ -343,25 +343,25 @@ void cChunkData::CopyBlocks(BLOCKTYPE * a_dest, size_t a_Idx, size_t length) co
-void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const
+void cChunkData::CopyMeta(NIBBLETYPE * a_Dest) const
{
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
{
memcpy(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
&m_Sections[i]->m_BlockMeta,
- sizeof(NIBBLETYPE) * segment_length
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
else
{
memset(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
0,
- sizeof(BLOCKTYPE) * segment_length
+ sizeof(BLOCKTYPE) * SegmentLength
);
}
}
@@ -371,25 +371,25 @@ void cChunkData::CopyMeta(NIBBLETYPE * a_dest) const
-void cChunkData::CopyBlockLight(NIBBLETYPE * a_dest) const
+void cChunkData::CopyBlockLight(NIBBLETYPE * a_Dest) const
{
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
{
memcpy(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
&m_Sections[i]->m_BlockLight,
- sizeof(NIBBLETYPE) * segment_length
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
else
{
memset(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
0,
- sizeof(BLOCKTYPE) * segment_length
+ sizeof(BLOCKTYPE) * SegmentLength
);
}
}
@@ -399,25 +399,25 @@ void cChunkData::CopyBlockLight(NIBBLETYPE * a_dest) const
-void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const
+void cChunkData::CopySkyLight(NIBBLETYPE * a_Dest) const
{
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
if (m_Sections[i] != NULL)
{
memcpy(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
&m_Sections[i]->m_BlockSkyLight,
- sizeof(NIBBLETYPE) * segment_length
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
else
{
memset(
- &a_dest[i * segment_length],
+ &a_Dest[i * SegmentLength],
0xFF,
- sizeof(BLOCKTYPE) * segment_length
+ sizeof(BLOCKTYPE) * SegmentLength
);
}
}
@@ -427,34 +427,36 @@ void cChunkData::CopySkyLight(NIBBLETYPE * a_dest) const
-void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
+void cChunkData::SetBlocks(const BLOCKTYPE * a_Src)
{
+ ASSERT(a_Src != NULL);
+
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16;
+ const size_t SegmentLength = 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
+ &a_Src[i * SegmentLength],
+ sizeof(BLOCKTYPE) * SegmentLength
);
}
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
+ // if j == SegmentLength 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++);
- if (j != segment_length)
+ for (; (j < SegmentLength) && (a_Src[i * SegmentLength + j] == 0); j++);
+ if (j != SegmentLength)
{
m_Sections[i] = Allocate();
memcpy(
&m_Sections[i]->m_BlockTypes,
- &a_src[i * segment_length],
- sizeof(BLOCKTYPE) * segment_length
+ &a_Src[i * SegmentLength],
+ sizeof(BLOCKTYPE) * SegmentLength
);
memset(
m_Sections[i]->m_BlockMeta,
@@ -479,34 +481,36 @@ void cChunkData::SetBlocks(const BLOCKTYPE * a_src)
-void cChunkData::SetMeta(const NIBBLETYPE * a_src)
+void cChunkData::SetMeta(const NIBBLETYPE * a_Src)
{
+ ASSERT(a_Src != NULL);
+
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = 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
+ &a_Src[i * SegmentLength],
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
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
+ // if j == SegmentLength 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++);
- if (j != segment_length)
+ for (; (j < SegmentLength) && (a_Src[i * SegmentLength + j] == 0); j++);
+ if (j != SegmentLength)
{
m_Sections[i] = Allocate();
memcpy(
&m_Sections[i]->m_BlockMeta,
- &a_src[i * segment_length],
- sizeof(BLOCKTYPE) * segment_length
+ &a_Src[i * SegmentLength],
+ sizeof(BLOCKTYPE) * SegmentLength
);
memset(
m_Sections[i]->m_BlockTypes,
@@ -531,35 +535,38 @@ void cChunkData::SetMeta(const NIBBLETYPE * a_src)
-void cChunkData::SetBlockLight(const NIBBLETYPE * a_src)
+void cChunkData::SetBlockLight(const NIBBLETYPE * a_Src)
{
- if (!a_src) return;
+ if (a_Src == NULL)
+ {
+ return;
+ }
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = 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
+ &a_Src[i * SegmentLength],
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
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
+ // if j == SegmentLength 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++);
- if (j != segment_length)
+ for (; (j < SegmentLength) && (a_Src[i * SegmentLength + j] == 0); j++);
+ if (j != SegmentLength)
{
m_Sections[i] = Allocate();
memcpy(
&m_Sections[i]->m_BlockLight,
- &a_src[i * segment_length],
- sizeof(BLOCKTYPE) * segment_length
+ &a_Src[i * SegmentLength],
+ sizeof(BLOCKTYPE) * SegmentLength
);
memset(
m_Sections[i]->m_BlockTypes,
@@ -584,35 +591,39 @@ void cChunkData::SetBlockLight(const NIBBLETYPE * a_src)
-void cChunkData::SetSkyLight (const NIBBLETYPE * a_src)
+void cChunkData::SetSkyLight(const NIBBLETYPE * a_Src)
{
- if (!a_src) return;
+ if (a_Src == NULL)
+ {
+ return;
+ }
+
for (size_t i = 0; i < CHUNK_SECTION_COUNT; i++)
{
- const size_t segment_length = CHUNK_SECTION_HEIGHT * 16 * 16 / 2;
+ const size_t SegmentLength = 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
+ &a_Src[i * SegmentLength],
+ sizeof(NIBBLETYPE) * SegmentLength
);
}
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
+ // if j == SegmentLength 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++);
- if (j != segment_length)
+ for (; (j < SegmentLength) && (a_Src[i * SegmentLength + j]) == 0xFF; j++);
+ if (j != SegmentLength)
{
m_Sections[i] = Allocate();
memcpy(
&m_Sections[i]->m_BlockSkyLight,
- &a_src[i * segment_length],
- sizeof(BLOCKTYPE) * segment_length
+ &a_Src[i * SegmentLength],
+ sizeof(BLOCKTYPE) * SegmentLength
);
memset(
m_Sections[i]->m_BlockTypes,
@@ -638,9 +649,9 @@ void cChunkData::SetSkyLight (const NIBBLETYPE * a_src)
-cChunkData::sChunkSection * cChunkData::Allocate() const
+cChunkData::sChunkSection * cChunkData::Allocate(void) const
{
- // TODO: use a allocation pool
+ // TODO: Use an allocation pool
return new cChunkData::sChunkSection;
}
@@ -648,36 +659,37 @@ cChunkData::sChunkSection * cChunkData::Allocate() const
-void cChunkData::Free(cChunkData::sChunkSection * ptr) const
+void cChunkData::Free(cChunkData::sChunkSection * a_Section) const
{
- delete ptr;
+ // TODO: Use an allocation pool
+ delete a_Section;
}
-void cChunkData::ZeroSection(cChunkData::sChunkSection * ptr) const
+void cChunkData::ZeroSection(cChunkData::sChunkSection * a_Section) const
{
memset(
- ptr->m_BlockTypes,
+ a_Section->m_BlockTypes,
0x00,
- sizeof(ptr->m_BlockTypes)
+ sizeof(a_Section->m_BlockTypes)
);
memset(
- ptr->m_BlockMeta,
+ a_Section->m_BlockMeta,
0x00,
- sizeof(ptr->m_BlockMeta)
+ sizeof(a_Section->m_BlockMeta)
);
memset(
- ptr->m_BlockLight,
+ a_Section->m_BlockLight,
0x00,
- sizeof(ptr->m_BlockLight)
+ sizeof(a_Section->m_BlockLight)
);
memset(
- ptr->m_BlockSkyLight,
+ a_Section->m_BlockSkyLight,
0xFF,
- sizeof(ptr->m_BlockSkyLight)
+ sizeof(a_Section->m_BlockSkyLight)
);
}
diff --git a/src/ChunkData.h b/src/ChunkData.h
index 6544b246e..09b2cb563 100644
--- a/src/ChunkData.h
+++ b/src/ChunkData.h
@@ -25,12 +25,12 @@ public:
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
- cChunkData(const cChunkData & other);
- cChunkData & operator =(const cChunkData & other);
+ cChunkData(const cChunkData & a_Other);
+ cChunkData & operator =(const cChunkData & a_Other);
#else
// unique_ptr style interface for memory management
- cChunkData(cChunkData && other);
- cChunkData & operator =(cChunkData && other);
+ cChunkData(cChunkData && a_Other);
+ cChunkData & operator =(cChunkData && a_ther);
#endif
BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z) const;
@@ -44,10 +44,10 @@ public:
NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
cChunkData Copy(void) const;
- void CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx = 0, size_t length = cChunkDef::NumBlocks) const;
- void CopyMeta (NIBBLETYPE * a_dest) const;
- void CopyBlockLight(NIBBLETYPE * a_dest) const;
- void CopySkyLight (NIBBLETYPE * a_dest) const;
+ void CopyBlocks (BLOCKTYPE * a_Dest, size_t a_Idx = 0, size_t a_Length = cChunkDef::NumBlocks) const;
+ void CopyMeta (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);
@@ -73,10 +73,15 @@ private:
sChunkSection * m_Sections[CHUNK_SECTION_COUNT];
- sChunkSection * Allocate(void) const;
- void Free(sChunkSection * ptr) const;
+ /** Allocates a new section. Entry-point to custom allocators. */
+ static sChunkSection * Allocate(void);
- void ZeroSection(sChunkSection * ptr) const;
+ /** Frees the specified section, previously allocated using Allocate().
+ Note that a_Section may be NULL. */
+ static void Free(sChunkSection * a_Section);
+
+ /** Sets the data in the specified section to their default values. */
+ void ZeroSection(sChunkSection * a_Section) const;
};