diff options
author | Tycho <work.tycho+git@gmail.com> | 2014-06-14 18:19:28 +0200 |
---|---|---|
committer | Tycho <work.tycho+git@gmail.com> | 2014-06-14 18:19:28 +0200 |
commit | 039c1a75f391b078f2b27a388e73bb203afed58e (patch) | |
tree | f4f213b794eb0c3a2713358c3d5bdd3f0b931486 /src/ChunkData.h | |
parent | Fixed bad merge (diff) | |
parent | Merge pull request #1093 from mc-server/BindingsFix (diff) | |
download | cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar.gz cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar.bz2 cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar.lz cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar.xz cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.tar.zst cuberite-039c1a75f391b078f2b27a388e73bb203afed58e.zip |
Diffstat (limited to 'src/ChunkData.h')
-rw-r--r-- | src/ChunkData.h | 91 |
1 files changed, 65 insertions, 26 deletions
diff --git a/src/ChunkData.h b/src/ChunkData.h index 637771741..aaefc4575 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -1,4 +1,12 @@ +// ChunkData.h + +// Declares the cChunkData class that represents the block's type, meta, blocklight and skylight storage for a chunk + + + + + #pragma once @@ -21,8 +29,9 @@ class cChunkData { private: - static const size_t CHUNK_SECTION_HEIGHT = 16; - static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); + static const size_t SectionHeight = 16; + static const size_t NumSections = (cChunkDef::Height / SectionHeight); + static const size_t SectionBlockCount = SectionHeight * cChunkDef::Width * cChunkDef::Width; public: @@ -33,12 +42,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; @@ -51,37 +60,67 @@ public: NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) 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 CopyBlockLight (NIBBLETYPE * a_dest) const; - void CopySkyLight (NIBBLETYPE * a_dest) const; - - void SetBlocks (const BLOCKTYPE * a_src); - void SetMeta (const NIBBLETYPE * a_src); - void SetBlockLight (const NIBBLETYPE * a_src); - void SetSkyLight (const NIBBLETYPE * a_src); + /** Creates a (deep) copy of self. */ + cChunkData Copy(void) const; + + /** Copies the blocktype data into the specified flat array. + Optionally, only a part of the data is copied, as specified by the a_Idx and a_Length parameters. */ + void CopyBlockTypes(BLOCKTYPE * a_Dest, size_t a_Idx = 0, size_t a_Length = cChunkDef::NumBlocks) const; + + /** Copies the metadata into the specified flat array. */ + void CopyMetas(NIBBLETYPE * a_Dest) const; + + /** Copies the block light data into the specified flat array. */ + void CopyBlockLight(NIBBLETYPE * a_Dest) const; + + /** Copies the skylight data into the specified flat array. */ + void CopySkyLight (NIBBLETYPE * a_Dest) const; + /** Copies the blocktype data from the specified flat array into the internal representation. + Allocates sections that are needed for the operation. + Requires that a_Src is a valid pointer. */ + void SetBlockTypes(const BLOCKTYPE * a_Src); + + /** Copies the metadata from the specified flat array into the internal representation. + Allocates sectios that are needed for the operation. + Requires that a_Src is a valid pointer. */ + void SetMetas(const NIBBLETYPE * a_Src); + + /** Copies the blocklight data from the specified flat array into the internal representation. + Allocates sectios that are needed for the operation. + Allows a_Src to be NULL, in which case it doesn't do anything. */ + void SetBlockLight(const NIBBLETYPE * a_Src); + + /** Copies the skylight data from the specified flat array into the internal representation. + Allocates sectios that are needed for the operation. + Allows a_Src to be NULL, in which case it doesn't do anything. */ + void SetSkyLight(const NIBBLETYPE * a_Src); + struct sChunkSection { - 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]; + BLOCKTYPE m_BlockTypes [SectionHeight * 16 * 16] ; + NIBBLETYPE m_BlockMetas [SectionHeight * 16 * 16 / 2]; + NIBBLETYPE m_BlockLight [SectionHeight * 16 * 16 / 2]; + NIBBLETYPE m_BlockSkyLight[SectionHeight * 16 * 16 / 2]; }; private: #if __cplusplus < 201103L // auto_ptr style interface for memory management - mutable bool IsOwner; + mutable bool m_IsOwner; #endif - sChunkSection *m_Sections[CHUNK_SECTION_COUNT]; + sChunkSection * m_Sections[NumSections]; - sChunkSection * Allocate() const; - void Free(sChunkSection * ptr) const; - - void ZeroSection(sChunkSection * ptr) const; + /** Allocates a new section. Entry-point to custom allocators. */ + sChunkSection * Allocate(void); + + /** Frees the specified section, previously allocated using Allocate(). + Note that a_Section may be NULL. */ + void Free(sChunkSection * a_Section); + /** Sets the data in the specified section to their default values. */ + void ZeroSection(sChunkSection * a_Section) const; + cAllocationPool<cChunkData::sChunkSection, 1600>& m_Pool; }; |