1
0

Merge branch 'chunksparsing/structs' into AllocationPool

This commit is contained in:
Tycho 2014-05-23 15:02:55 +01:00
commit 5a76eab4c0
16 changed files with 228 additions and 144 deletions

1
.gitignore vendored
View File

@ -48,6 +48,7 @@ world_nether
CMakeFiles/
cmake_install.cmake
CMakeCache.txt
CTestTestfile.cmake
Makefile
*.a

View File

@ -9,7 +9,7 @@
#include "OSSupport/GZipFile.h"
#include "Blocks/BlockHandler.h"
#include "Cuboid.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
@ -1835,10 +1835,10 @@ 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))
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::ChunkBuffer(const cChunkBuffer & 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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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))
bool hasChanged = m_ChunkData.SetMeta(a_RelX, a_RelY, a_RelZ, a_Meta);
if (hasChanged)
{
MarkDirty();
m_ChunkBuffer.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;

View File

@ -1,13 +1,13 @@
#include "Globals.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
cChunkBuffer cChunkBuffer::Copy() const
cChunkData cChunkData::Copy() const
{
cChunkBuffer copy;
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];
@ -20,7 +20,7 @@ cChunkBuffer cChunkBuffer::Copy() const
void cChunkBuffer::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length) 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++)
{
@ -30,7 +30,7 @@ void cChunkBuffer::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],
@ -54,17 +54,18 @@ void cChunkBuffer::CopyBlocks (BLOCKTYPE * a_dest, size_t a_Idx, size_t length
void cChunkBuffer::CopyMeta(NIBBLETYPE * a_dest) const
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],
&m_Sections[i]->m_BlockMeta,
sizeof(NIBBLETYPE) * segment_length);
sizeof(NIBBLETYPE) * segment_length
);
}
else
{
@ -81,12 +82,12 @@ void cChunkBuffer::CopyMeta(NIBBLETYPE * a_dest) const
void cChunkBuffer::CopyLight(NIBBLETYPE * a_dest) const
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],
@ -109,12 +110,12 @@ void cChunkBuffer::CopyLight(NIBBLETYPE * a_dest) const
void cChunkBuffer::CopySkyLight(NIBBLETYPE * a_dest) const
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],
@ -137,14 +138,18 @@ void cChunkBuffer::CopySkyLight(NIBBLETYPE * a_dest) const
void cChunkBuffer::SetBlocks(const BLOCKTYPE * a_src)
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);
memcpy(
&m_Sections[i]->m_BlockTypes,
&a_src[i * segment_length],
sizeof(BLOCKTYPE) * segment_length
);
}
else
{
@ -159,9 +164,21 @@ void cChunkBuffer::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
{
@ -175,14 +192,18 @@ void cChunkBuffer::SetBlocks(const BLOCKTYPE * a_src)
void cChunkBuffer::SetMeta(const NIBBLETYPE * a_src)
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);
memcpy(
&m_Sections[i]->m_BlockMeta,
&a_src[i * segment_length],
sizeof(NIBBLETYPE) * segment_length
);
}
else
{
@ -197,9 +218,21 @@ void cChunkBuffer::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
{
@ -213,15 +246,19 @@ void cChunkBuffer::SetMeta(const NIBBLETYPE * a_src)
void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
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])
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 +273,21 @@ void cChunkBuffer::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
{
@ -252,15 +301,19 @@ void cChunkBuffer::SetLight(const NIBBLETYPE * a_src)
void cChunkBuffer::SetSkyLight (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++)
{
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);
memcpy(
&m_Sections[i]->m_BlockSkyLight,
&a_src[i * segment_length],
sizeof(NIBBLETYPE) * segment_length
);
}
else
{
@ -275,9 +328,21 @@ void cChunkBuffer::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
{
@ -292,27 +357,43 @@ void cChunkBuffer::SetSkyLight (const NIBBLETYPE * a_src)
cChunkBuffer::sChunkSection * cChunkBuffer::Allocate() const
cChunkData::sChunkSection * cChunkData::Allocate() const
{
// TODO: use a allocation pool
return new cChunkBuffer::sChunkSection;
return new cChunkData::sChunkSection;
}
void cChunkBuffer::Free(cChunkBuffer::sChunkSection * ptr) const
void cChunkData::Free(cChunkData::sChunkSection * ptr) const
{
delete ptr;
}
void cChunkBuffer::ZeroSection(cChunkBuffer::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)
);
}

View File

@ -17,11 +17,11 @@
// unique_ptr style interface for memory management
#endif
class cChunkBuffer
class cChunkData
{
public:
cChunkBuffer()
cChunkData()
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
: IsOwner(true)
@ -29,21 +29,21 @@ public:
{
memset(m_Sections, 0, sizeof(m_Sections));
}
~cChunkBuffer()
~cChunkData()
{
#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]) Free(m_Sections[i]);;
if (m_Sections[i] == NULL) Free(m_Sections[i]);;
}
}
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
cChunkBuffer(const cChunkBuffer& other) :
cChunkData(const cChunkData& other) :
IsOwner(true)
{
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
@ -53,15 +53,15 @@ public:
other.IsOwner = false;
}
cChunkBuffer& operator=(const cChunkBuffer& other)
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;
@ -76,7 +76,7 @@ public:
}
#else
// unique_ptr style interface for memory management
cChunkBuffer(cChunkBuffer&& other)
cChunkData(cChunkData&& other)
{
for (int i = 0; i < CHUNK_SECTION_NUM; i++)
{
@ -85,13 +85,13 @@ public:
}
}
cChunkBuffer& operator=(cChunkBuffer&& other)
cChunkData& operator=(cChunkData&& other)
{
if(&other != this)
if (&other != this)
{
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];
@ -125,19 +125,19 @@ public:
(a_RelZ >= cChunkDef::Width) || (a_RelZ < 0)
)
{
ASSERT(!"cChunkBuffer::SetMeta(): index out of range!");
ASSERT(!"cChunkData::SetMeta(): index out of range!");
return;
}
int Section = a_RelY / CHUNK_SECTION_HEIGHT;
if(!m_Sections[Section])
if (m_Sections[Section] == NULL)
{
if(a_Block == 0x00)
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;
@ -163,11 +163,11 @@ public:
return 0;
}
}
ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!");
ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!");
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) ||
@ -175,30 +175,32 @@ public:
(a_RelZ >= cChunkDef::Width) || (a_RelZ < 0)
)
{
ASSERT(!"cChunkBuffer::SetMeta(): index out of range!");
return;
ASSERT(!"cChunkData::SetMeta(): index out of range!");
return false;
}
int Section = a_RelY / CHUNK_SECTION_HEIGHT;
if(!m_Sections[Section])
if (m_Sections[Section] == NULL)
{
if((a_Nibble & 0xf) == 0x00)
if ((a_Nibble & 0xf) == 0x00)
{
return;
return false;
}
m_Sections[Section] = Allocate();
if(!m_Sections[Section])
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<NIBBLETYPE>(
(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
@ -206,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])
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;
@ -216,7 +218,7 @@ public:
return 0;
}
}
ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!");
ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!");
return 0;
}
@ -225,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])
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;
@ -235,11 +237,11 @@ public:
return 0xF;
}
}
ASSERT(!"cChunkBuffer::GetMeta(): coords out of chunk range!");
ASSERT(!"cChunkData::GetMeta(): coords out of chunk range!");
return 0;
}
cChunkBuffer Copy() const;
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;

View File

@ -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);

View File

@ -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;

View File

@ -22,7 +22,7 @@
/// Helper class for serializing a chunk into Json
class cJsonChunkSerializer :
public cChunkDataCollector
public cChunkDataArrayCollector
{
public:

View File

@ -4,4 +4,4 @@ enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(ChunkBuffer)
add_subdirectory(ChunkData)

View File

@ -1,6 +1,6 @@
#include "TestGlobals.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
@ -8,7 +8,7 @@ int main(int argc, char** argv)
{
{
// Test first segment
cChunkBuffer buffer;
cChunkData buffer;
BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
@ -45,7 +45,7 @@ int main(int argc, char** argv)
{
// test following segment
cChunkBuffer buffer;
cChunkData buffer;
BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);
@ -82,7 +82,7 @@ int main(int argc, char** argv)
{
// test zeros
cChunkBuffer buffer;
cChunkData buffer;
BLOCKTYPE* SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);

View File

@ -4,7 +4,7 @@ enable_testing()
include_directories(${CMAKE_SOURCE_DIR}/src/)
add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkBuffer.cpp)
add_library(ChunkBuffer ${CMAKE_SOURCE_DIR}/src/ChunkData.cpp)
add_executable(creatable-exe creatable.cpp)

View File

@ -1,13 +1,13 @@
#include "TestGlobals.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
int main(int argc, char** argv)
{
{
cChunkBuffer buffer;
cChunkData buffer;
// Empty chunks
buffer.SetBlock(0,0,0, 0xAB);
@ -105,7 +105,7 @@ int main(int argc, char** argv)
}
{
cChunkBuffer buffer;
cChunkData buffer;
// Zero's
buffer.SetBlock(0,0,0, 0x0);
@ -122,9 +122,9 @@ int main(int argc, char** argv)
{
// Operator =
cChunkBuffer buffer;
cChunkData buffer;
buffer.SetBlock(0,0,0,0x42);
cChunkBuffer copy;
cChunkData copy;
#if __cplusplus < 201103L
copy = buffer;
#else

View File

@ -1,18 +1,18 @@
#include "TestGlobals.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
int main(int argc, char** argv)
{
{
cChunkBuffer buffer;
cChunkData buffer;
buffer.SetBlock(3,1,4,0xDE);
buffer.SetMeta(3,1,4,0xA);
cChunkBuffer copy = buffer.Copy();
cChunkData copy = buffer.Copy();
testassert(copy.GetBlock(3,1,4) == 0xDE);
testassert(copy.GetMeta(3,1,4) == 0xA);
@ -47,7 +47,7 @@ int main(int argc, char** argv)
}
{
cChunkBuffer buffer;
cChunkData buffer;
NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
@ -80,7 +80,7 @@ int main(int argc, char** argv)
}
{
cChunkBuffer buffer;
cChunkData buffer;
NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
@ -114,7 +114,7 @@ int main(int argc, char** argv)
}
{
cChunkBuffer buffer;
cChunkData buffer;
NIBBLETYPE * SrcNibbleBuffer = new NIBBLETYPE[16 * 16 * 256/2];
for (int i = 0; i < 16 * 16 * 256 / 2; i += 4)
@ -148,7 +148,7 @@ int main(int argc, char** argv)
}
{
cChunkBuffer buffer;
cChunkData buffer;
BLOCKTYPE * SrcBlockBuffer = new BLOCKTYPE[16 * 16 * 256];
memset(SrcBlockBuffer, 0x00, 16 * 16 * 256);

View File

@ -1,9 +1,9 @@
#include "TestGlobals.h"
#include "ChunkBuffer.h"
#include "ChunkData.h"
int main(int argc, char** argv)
{
cChunkBuffer buffer;
cChunkData buffer;
return 0;
}