diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-08-21 18:56:53 +0200 |
---|---|---|
committer | Alexander Harkness <me@bearbin.net> | 2017-08-21 18:56:53 +0200 |
commit | 096cdac80d222ac0be2a0554a759a0b16c1c34f6 (patch) | |
tree | 03190afb388f999bf9740fbae15d688780f036d5 /src/ChunkData.h | |
parent | Award player an achievement when creating a beacon (#3930) (diff) | |
download | cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar.gz cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar.bz2 cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar.lz cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar.xz cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.tar.zst cuberite-096cdac80d222ac0be2a0554a759a0b16c1c34f6.zip |
Diffstat (limited to '')
-rw-r--r-- | src/ChunkData.h | 66 |
1 files changed, 32 insertions, 34 deletions
diff --git a/src/ChunkData.h b/src/ChunkData.h index d63576f91..49a03fb4a 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -16,36 +16,37 @@ -#if __cplusplus < 201103L -// auto_ptr style interface for memory management -#else -// unique_ptr style interface for memory management -#endif - class cChunkData { -private: +public: static const int SectionHeight = 16; static const size_t NumSections = (cChunkDef::Height / SectionHeight); static const size_t SectionBlockCount = SectionHeight * cChunkDef::Width * cChunkDef::Width; -public: - - struct sChunkSection; + struct sChunkSection + { + BLOCKTYPE m_BlockTypes[SectionBlockCount]; + NIBBLETYPE m_BlockMetas[SectionBlockCount / 2]; + NIBBLETYPE m_BlockLight[SectionBlockCount / 2]; + NIBBLETYPE m_BlockSkyLight[SectionBlockCount / 2]; + }; - cChunkData(cAllocationPool<cChunkData::sChunkSection> & a_Pool); + cChunkData(cAllocationPool<sChunkSection> & a_Pool); + cChunkData(cChunkData && a_Other); ~cChunkData(); - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - cChunkData(const cChunkData & a_Other); - cChunkData & operator =(const cChunkData & a_Other); - #else - // unique_ptr style interface for memory management - cChunkData(cChunkData && a_Other); - cChunkData & operator =(cChunkData && a_ther); - #endif + cChunkData & operator = (cChunkData && a_Other) + { + Assign(std::move(a_Other)); + return *this; + } + + /** Copy assign from another cChunkData */ + void Assign(const cChunkData & a_Other); + + /** Move assign from another cChunkData */ + void Assign(cChunkData && a_Other); 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); @@ -57,8 +58,14 @@ public: NIBBLETYPE GetSkyLight(int a_RelX, int a_RelY, int a_RelZ) const; - /** Creates a (deep) copy of self. */ - cChunkData Copy(void) const; + /** Return a pointer to the chunk section or nullptr if all air */ + const sChunkSection * GetSection(size_t a_SectionNum) const; + + /** Returns a bitmask of chunk sections which are currently stored. */ + UInt16 GetSectionBitmask() const; + + /** Clears all data */ + void Clear(); /** 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. */ @@ -93,23 +100,14 @@ public: Allows a_Src to be nullptr, in which case it doesn't do anything. */ void SetSkyLight(const NIBBLETYPE * a_Src); - struct sChunkSection - { - 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]; - }; + /** Returns the number of sections present (i.e. non-air). */ + UInt32 NumPresentSections() const; private: - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - mutable bool m_IsOwner; - #endif sChunkSection * m_Sections[NumSections]; - cAllocationPool<cChunkData::sChunkSection> & m_Pool; + cAllocationPool<sChunkSection> & m_Pool; /** Allocates a new section. Entry-point to custom allocators. */ sChunkSection * Allocate(void); |