2014-04-26 13:50:23 -04:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2014-05-03 09:02:51 -04:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
|
|
#include "ChunkDef.h"
|
|
|
|
|
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
|
|
|
|
#if __cplusplus < 201103L
|
|
|
|
// auto_ptr style interface for memory management
|
|
|
|
#else
|
|
|
|
// unique_ptr style interface for memory management
|
|
|
|
#endif
|
|
|
|
|
2014-05-21 14:58:48 -04:00
|
|
|
class cChunkData
|
2014-04-26 13:50:23 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-05-24 08:37:25 -04:00
|
|
|
cChunkData();
|
|
|
|
~cChunkData();
|
2014-04-26 13:50:23 -04:00
|
|
|
|
|
|
|
#if __cplusplus < 201103L
|
2014-05-24 08:33:40 -04:00
|
|
|
// auto_ptr style interface for memory management
|
2014-05-28 16:40:19 -04:00
|
|
|
cChunkData(const cChunkData & a_Other);
|
|
|
|
cChunkData & operator =(const cChunkData & a_Other);
|
2014-04-26 13:50:23 -04:00
|
|
|
#else
|
2014-05-24 08:33:40 -04:00
|
|
|
// unique_ptr style interface for memory management
|
2014-05-28 16:40:19 -04:00
|
|
|
cChunkData(cChunkData && a_Other);
|
|
|
|
cChunkData & operator =(cChunkData && a_ther);
|
2014-04-26 13:50:23 -04:00
|
|
|
#endif
|
|
|
|
|
2014-05-24 08:37:25 -04: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-04-26 13:50:23 -04:00
|
|
|
|
2014-05-24 08:37:25 -04: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-04-26 13:50:23 -04:00
|
|
|
|
2014-05-24 08:37:25 -04:00
|
|
|
NIBBLETYPE GetBlockLight(int a_RelX, int a_RelY, int a_RelZ) const;
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2014-05-24 08:37:25 -04:00
|
|
|
NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const;
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2014-05-28 05:35:55 -04:00
|
|
|
cChunkData Copy(void) const;
|
2014-05-28 16:40:19 -04:00
|
|
|
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;
|
2014-04-26 13:50:23 -04:00
|
|
|
|
|
|
|
void SetBlocks (const BLOCKTYPE * a_src);
|
|
|
|
void SetMeta (const NIBBLETYPE * a_src);
|
2014-05-28 05:35:55 -04:00
|
|
|
void SetBlockLight(const NIBBLETYPE * a_src);
|
2014-04-26 13:50:23 -04:00
|
|
|
void SetSkyLight (const NIBBLETYPE * a_src);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2014-05-24 08:33:40 -04:00
|
|
|
static const size_t CHUNK_SECTION_HEIGHT = 16;
|
|
|
|
static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT);
|
|
|
|
|
2014-04-26 13:50:23 -04:00
|
|
|
#if __cplusplus < 201103L
|
|
|
|
// auto_ptr style interface for memory management
|
2014-05-28 05:35:55 -04:00
|
|
|
mutable bool m_IsOwner;
|
2014-04-26 13:50:23 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct sChunkSection {
|
2014-05-28 05:35:55 -04:00
|
|
|
BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16];
|
2014-04-26 13:50:23 -04:00
|
|
|
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 05:35:55 -04:00
|
|
|
sChunkSection * m_Sections[CHUNK_SECTION_COUNT];
|
2014-04-26 13:50:23 -04:00
|
|
|
|
2014-05-28 16:40:19 -04:00
|
|
|
/** Allocates a new section. Entry-point to custom allocators. */
|
|
|
|
static sChunkSection * Allocate(void);
|
2014-05-11 10:52:02 -04:00
|
|
|
|
2014-05-28 16:40:19 -04:00
|
|
|
/** 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;
|
2014-04-26 13:50:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|