diff options
author | peterbell10 <peterbell10@live.co.uk> | 2017-09-06 19:40:04 +0200 |
---|---|---|
committer | Mattes D <github@xoft.cz> | 2017-09-11 23:20:12 +0200 |
commit | 4a0355f065a3be357cfb0e650224903f53e70913 (patch) | |
tree | 92a639bc1bf23b00beed43d8e9a7e16907de0f0a /src/BlockArea.h | |
parent | Add a test for cUUID (#4021) (diff) | |
download | cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar.gz cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar.bz2 cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar.lz cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar.xz cuberite-4a0355f065a3be357cfb0e650224903f53e70913.tar.zst cuberite-4a0355f065a3be357cfb0e650224903f53e70913.zip |
Diffstat (limited to '')
-rw-r--r-- | src/BlockArea.h | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/BlockArea.h b/src/BlockArea.h index 2e35b9436..94081f93f 100644 --- a/src/BlockArea.h +++ b/src/BlockArea.h @@ -63,7 +63,6 @@ public: } ; cBlockArea(void); - ~cBlockArea(); /** Returns true if the datatype combination is valid. Invalid combinations include BlockEntities without BlockTypes. */ @@ -366,10 +365,10 @@ public: // Clients can use these for faster access to all blocktypes. Be careful though! /** Returns the internal pointer to the block types */ - BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes; } - NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas; } // NOTE: one byte per block! - NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight; } // NOTE: one byte per block! - NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight; } // NOTE: one byte per block! + BLOCKTYPE * GetBlockTypes (void) const { return m_BlockTypes.get(); } + NIBBLETYPE * GetBlockMetas (void) const { return m_BlockMetas.get(); } // NOTE: one byte per block! + NIBBLETYPE * GetBlockLight (void) const { return m_BlockLight.get(); } // NOTE: one byte per block! + NIBBLETYPE * GetBlockSkyLight(void) const { return m_BlockSkyLight.get(); } // NOTE: one byte per block! size_t GetBlockCount(void) const { return static_cast<size_t>(m_Size.x * m_Size.y * m_Size.z); } int MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const; @@ -419,7 +418,43 @@ protected: virtual void BlockEntity(cBlockEntity * a_BlockEntity) override; } ; - typedef NIBBLETYPE * NIBBLEARRAY; + template <typename T> + class cDynArray: + public std::unique_ptr<T[]> + { + using Super = std::unique_ptr<T[]>; + public: + // using Super::Super; + cDynArray() = default; + cDynArray(cDynArray && a_Other) : Super(std::move(a_Other)) {} + cDynArray & operator = (cDynArray && a_Other) + { + Super::operator = (std::move(a_Other)); + return *this; + } + + cDynArray(std::nullptr_t) {} + + cDynArray(T * a_Ptr): + Super(a_Ptr) + { + } + + // Allow indexing with signed types + T & operator [] (int a_Idx) const + { + ASSERT(a_Idx >= 0); + return (Super::get())[a_Idx]; + } + + T & operator [] (size_t a_Idx) const + { + return (Super::get())[a_Idx]; + } + }; + + using NIBBLEARRAY = cDynArray<NIBBLETYPE>; + using BLOCKARRAY = cDynArray<BLOCKTYPE>; Vector3i m_Origin; @@ -429,15 +464,23 @@ protected: cBlockArea doesn't use this value in any way. */ Vector3i m_WEOffset; - BLOCKTYPE * m_BlockTypes; - NIBBLETYPE * m_BlockMetas; // Each meta is stored as a separate byte for faster access - NIBBLETYPE * m_BlockLight; // Each light value is stored as a separate byte for faster access - NIBBLETYPE * m_BlockSkyLight; // Each light value is stored as a separate byte for faster access + BLOCKARRAY m_BlockTypes; + NIBBLEARRAY m_BlockMetas; // Each meta is stored as a separate byte for faster access + NIBBLEARRAY m_BlockLight; // Each light value is stored as a separate byte for faster access + NIBBLEARRAY m_BlockSkyLight; // Each light value is stored as a separate byte for faster access + + /** Deleter to clear the block entities before deleting the container. */ + struct sBlockEntitiesDeleter + { + void operator () (cBlockEntities * a_BlockEntities); + }; + + using cBlockEntitiesPtr = std::unique_ptr<cBlockEntities, sBlockEntitiesDeleter>; /** The block entities contained within the area. Only valid if the area was created / read with the baBlockEntities flag. The block entities are owned by this object. */ - std::unique_ptr<cBlockEntities> m_BlockEntities; + cBlockEntitiesPtr m_BlockEntities; /** Clears the data stored and prepares a fresh new block area with the specified dimensions */ bool SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes); |