From 8be3a8f7dc10dbc49dfcdeca572677ef1e00f714 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 23 May 2014 17:18:11 +0100 Subject: Implemented Allocation Pool use by cChunkData --- src/ChunkData.h | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/ChunkData.h') diff --git a/src/ChunkData.h b/src/ChunkData.h index 9c852ee24..527c5b2ae 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -7,6 +7,8 @@ #include "ChunkDef.h" +#include "AllocationPool.h" + #define CHUNK_SECTION_HEIGHT 16 #define CHUNK_SECTION_NUM (256 / CHUNK_SECTION_HEIGHT) @@ -21,11 +23,14 @@ class cChunkData { public: - cChunkData() + struct sChunkSection; + + cChunkData(cAllocationPool& a_Pool) : #if __cplusplus < 201103L // auto_ptr style interface for memory management - : IsOwner(true) + IsOwner(true), #endif + m_Pool(a_Pool) { memset(m_Sections, 0, sizeof(m_Sections)); } @@ -44,7 +49,8 @@ public: #if __cplusplus < 201103L // auto_ptr style interface for memory management cChunkData(const cChunkData& other) : - IsOwner(true) + IsOwner(true), + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -70,13 +76,15 @@ public: m_Sections[i] = other.m_Sections[i]; } other.IsOwner = false; + ASSERT(&m_Pool == &other.m_Pool); } return *this; } #else // unique_ptr style interface for memory management - cChunkData(cChunkData&& other) + cChunkData(cChunkData&& other) : + m_Pool(other.m_Pool) { for (int i = 0; i < CHUNK_SECTION_NUM; i++) { @@ -95,6 +103,7 @@ public: m_Sections[i] = other.m_Sections[i]; other.m_Sections[i] = 0; } + ASSERT(&m_Pool == &other.m_Pool); } return *this; } @@ -252,13 +261,6 @@ public: void SetLight (const NIBBLETYPE * a_src); void SetSkyLight (const NIBBLETYPE * a_src); -private: - - #if __cplusplus < 201103L - // auto_ptr style interface for memory management - mutable bool IsOwner; - #endif - struct sChunkSection { BLOCKTYPE m_BlockTypes [CHUNK_SECTION_HEIGHT * 16 * 16] ; NIBBLETYPE m_BlockMeta [CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; @@ -266,12 +268,21 @@ private: NIBBLETYPE m_BlockSkyLight[CHUNK_SECTION_HEIGHT * 16 * 16 / 2]; }; +private: + + #if __cplusplus < 201103L + // auto_ptr style interface for memory management + mutable bool IsOwner; + #endif + sChunkSection *m_Sections[CHUNK_SECTION_NUM]; sChunkSection * Allocate() const; void Free(sChunkSection * ptr) const; void ZeroSection(sChunkSection * ptr) const; + + cAllocationPool& m_Pool; }; -- cgit v1.2.3