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 From 2a7d199df68d11f6fd1fa2b4186faa00d0e81676 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 25 May 2014 18:26:10 +0100 Subject: Fixed bad merge --- src/ChunkData.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/ChunkData.h') diff --git a/src/ChunkData.h b/src/ChunkData.h index 08f1603bb..637771741 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -19,6 +19,11 @@ class cChunkData { +private: + + static const size_t CHUNK_SECTION_HEIGHT = 16; + static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); + public: struct sChunkSection; @@ -65,10 +70,6 @@ public: }; private: - - static const size_t CHUNK_SECTION_HEIGHT = 16; - static const size_t CHUNK_SECTION_COUNT = (256 / CHUNK_SECTION_HEIGHT); - #if __cplusplus < 201103L // auto_ptr style interface for memory management mutable bool IsOwner; -- cgit v1.2.3 From 6b99e556462fdbdf6a265c014fb03f070b0f1b25 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:05:02 +0100 Subject: fixed spaces --- src/ChunkData.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/ChunkData.h') diff --git a/src/ChunkData.h b/src/ChunkData.h index aaefc4575..9dee78ad0 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool& a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -96,7 +96,8 @@ public: Allows a_Src to be NULL, in which case it doesn't do anything. */ void SetSkyLight(const NIBBLETYPE * a_Src); - struct sChunkSection { + struct sChunkSection + { BLOCKTYPE m_BlockTypes [SectionHeight * 16 * 16] ; NIBBLETYPE m_BlockMetas [SectionHeight * 16 * 16 / 2]; NIBBLETYPE m_BlockLight [SectionHeight * 16 * 16 / 2]; @@ -121,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool& m_Pool; + cAllocationPool & m_Pool; }; -- cgit v1.2.3 From 94c48febd2f596648fc2616a8a577316a219b581 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:46:34 +0100 Subject: Added generic Allocation Pool Interface --- src/ChunkData.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ChunkData.h') diff --git a/src/ChunkData.h b/src/ChunkData.h index 9dee78ad0..e3b36c581 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -37,7 +37,7 @@ public: struct sChunkSection; - cChunkData(cAllocationPool & a_Pool); + cChunkData(cAllocationPool & a_Pool); ~cChunkData(); #if __cplusplus < 201103L @@ -122,7 +122,7 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; + cAllocationPool & m_Pool; }; -- cgit v1.2.3 From 3efbdb1c9b8f83ecb28992282c08aa065e21e1f8 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sat, 14 Jun 2014 19:54:09 +0100 Subject: Moved m_Sections --- src/ChunkData.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/ChunkData.h') diff --git a/src/ChunkData.h b/src/ChunkData.h index e3b36c581..fe8b068a2 100644 --- a/src/ChunkData.h +++ b/src/ChunkData.h @@ -111,6 +111,8 @@ private: #endif sChunkSection * m_Sections[NumSections]; + + cAllocationPool & m_Pool; /** Allocates a new section. Entry-point to custom allocators. */ sChunkSection * Allocate(void); @@ -122,7 +124,6 @@ private: /** Sets the data in the specified section to their default values. */ void ZeroSection(sChunkSection * a_Section) const; - cAllocationPool & m_Pool; }; -- cgit v1.2.3