summaryrefslogtreecommitdiffstats
path: root/src/ChunkData.h
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-21 23:14:23 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-21 23:14:23 +0200
commit7615ed90c020b88db52b0b094f00cd028e326b5a (patch)
treeca7f647e77195a6346a2333f3d9fe5292cd2ed40 /src/ChunkData.h
parentFixed invalid iterators (diff)
parentMerge branch 'master' of https://github.com/mc-server/MCServer (diff)
downloadcuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar.gz
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar.bz2
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar.lz
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar.xz
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.tar.zst
cuberite-7615ed90c020b88db52b0b094f00cd028e326b5a.zip
Diffstat (limited to 'src/ChunkData.h')
-rw-r--r--src/ChunkData.h54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/ChunkData.h b/src/ChunkData.h
index fef31b5ad..fe8b068a2 100644
--- a/src/ChunkData.h
+++ b/src/ChunkData.h
@@ -15,6 +15,7 @@
#include "ChunkDef.h"
+#include "AllocationPool.h"
@@ -26,9 +27,17 @@
class cChunkData
{
+private:
+
+ 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:
- cChunkData(void);
+ struct sChunkSection;
+
+ cChunkData(cAllocationPool<cChunkData::sChunkSection> & a_Pool);
~cChunkData();
#if __cplusplus < 201103L
@@ -53,17 +62,17 @@ public:
/** 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;
@@ -71,12 +80,12 @@ public:
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. */
@@ -86,36 +95,35 @@ public:
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 [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:
-
- static const size_t SectionHeight = 16;
- static const size_t NumSections = (cChunkDef::Height / SectionHeight);
- static const size_t SectionBlockCount = SectionHeight * cChunkDef::Width * cChunkDef::Width;
-
#if __cplusplus < 201103L
// auto_ptr style interface for memory management
mutable bool m_IsOwner;
#endif
-
- struct sChunkSection {
- BLOCKTYPE m_BlockTypes [SectionBlockCount];
- NIBBLETYPE m_BlockMetas [SectionBlockCount / 2];
- NIBBLETYPE m_BlockLight [SectionBlockCount / 2];
- NIBBLETYPE m_BlockSkyLight[SectionBlockCount / 2];
- };
-
+
sChunkSection * m_Sections[NumSections];
+
+ cAllocationPool<cChunkData::sChunkSection> & m_Pool;
/** Allocates a new section. Entry-point to custom allocators. */
- static sChunkSection * Allocate(void);
-
+ sChunkSection * Allocate(void);
+
/** Frees the specified section, previously allocated using Allocate().
Note that a_Section may be NULL. */
- static void Free(sChunkSection * a_Section);
+ void Free(sChunkSection * a_Section);
/** Sets the data in the specified section to their default values. */
void ZeroSection(sChunkSection * a_Section) const;
+
};