1
0
Fork 0
cuberite-2a/src/ChunkData.h

87 lines
2.1 KiB
C
Raw Normal View History

#pragma once
#include <cstring>
#include "ChunkDef.h"
2014-05-24 12:33:40 +00:00
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
#else
// unique_ptr style interface for memory management
#endif
2014-05-21 18:58:48 +00:00
class cChunkData
{
public:
2014-05-24 12:37:25 +00:00
cChunkData();
~cChunkData();
#if __cplusplus < 201103L
2014-05-24 12:33:40 +00:00
// auto_ptr style interface for memory management
2014-05-28 09:35:55 +00:00
cChunkData(const cChunkData & other);
cChunkData & operator =(const cChunkData & other);
#else
2014-05-24 12:33:40 +00:00
// unique_ptr style interface for memory management
2014-05-28 09:35:55 +00:00
cChunkData(cChunkData && other);
cChunkData & operator =(cChunkData && other);
#endif
2014-05-24 12:37:25 +00:00
BLOCKTYPE GetBlock(int a_X, int a_Y, int a_Z) const;
void SetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_Block);
2014-05-24 12:37:25 +00:00
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const;
bool SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Nibble);
2014-05-24 12:37:25 +00:00
NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const;
2014-05-24 12:37:25 +00:00
NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
2014-05-28 09:35:55 +00:00
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;
2014-05-28 09:35:55 +00:00
void CopyBlockLight(NIBBLETYPE * a_dest) const;
void CopySkyLight (NIBBLETYPE * a_dest) const;
void SetBlocks (const BLOCKTYPE * a_src);
void SetMeta (const NIBBLETYPE * a_src);
2014-05-28 09:35:55 +00:00
void SetBlockLight(const NIBBLETYPE * a_src);
void SetSkyLight (const NIBBLETYPE * a_src);
private:
2014-05-24 12:33:40 +00:00
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
2014-05-28 09:35:55 +00:00
mutable bool m_IsOwner;
#endif
struct sChunkSection {
2014-05-28 09:35:55 +00:00
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];
};
2014-05-28 09:35:55 +00:00
sChunkSection * m_Sections[CHUNK_SECTION_COUNT];
2014-05-28 09:35:55 +00:00
sChunkSection * Allocate(void) const;
void Free(sChunkSection * ptr) const;
void ZeroSection(sChunkSection * ptr) const;
};