Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkDataCallback.h
Go to the documentation of this file.
1 
2 // ChunkDataCallback.h
3 
4 // Declares the cChunkDataCallback interface and several trivial descendants, for reading chunk data
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "ChunkData.h"
13 
14 
15 
16 
17 
21 class cChunkDataCallback abstract
22 {
23 public:
24 
25  virtual ~cChunkDataCallback() {}
26 
30  virtual bool Coords(int a_ChunkX, int a_ChunkZ) { UNUSED(a_ChunkX); UNUSED(a_ChunkZ); return true; }
31 
33  virtual void HeightMap(const cChunkDef::HeightMap * a_HeightMap) { UNUSED(a_HeightMap); }
34 
36  virtual void BiomeData(const cChunkDef::BiomeMap * a_BiomeMap) { UNUSED(a_BiomeMap); }
37 
39  virtual void LightIsValid(bool a_IsLightValid) { UNUSED(a_IsLightValid); }
40 
42  virtual void ChunkData(const cChunkData & a_Buffer) { UNUSED(a_Buffer); }
43 
45  virtual void Entity(cEntity * a_Entity) { UNUSED(a_Entity); }
46 
48  virtual void BlockEntity(cBlockEntity * a_Entity) { UNUSED(a_Entity); }
49 } ;
50 
51 
52 
53 
54 
57  public cChunkDataCallback
58 {
59 public:
60 
61  // Must be unsigned char instead of BLOCKTYPE or NIBBLETYPE, because it houses both.
62  unsigned char m_BlockData[cChunkDef::BlockDataSize];
63 
64 protected:
65 
66  virtual void ChunkData(const cChunkData & a_ChunkBuffer) override
67  {
68  a_ChunkBuffer.CopyBlockTypes(m_BlockData);
69  a_ChunkBuffer.CopyMetas(m_BlockData + cChunkDef::NumBlocks);
70  a_ChunkBuffer.CopyBlockLight(m_BlockData + 3 * cChunkDef::NumBlocks / 2);
71  a_ChunkBuffer.CopySkyLight(m_BlockData + 2 * cChunkDef::NumBlocks);
72  }
73 };
74 
75 
76 
77 
78 
81  public cChunkDataCallback
82 {
83 public:
84 
89 
90 protected:
91 
92  virtual void ChunkData(const cChunkData & a_ChunkBuffer) override
93  {
94  a_ChunkBuffer.CopyBlockTypes(m_BlockTypes);
95  a_ChunkBuffer.CopyMetas(m_BlockMetas);
96  a_ChunkBuffer.CopyBlockLight(m_BlockLight);
97  a_ChunkBuffer.CopySkyLight(m_BlockSkyLight);
98  }
99 } ;
100 
101 
102 
103 
106  public cChunkDataCallback
107 {
108 public:
109  struct MemCallbacks:
110  cAllocationPool<cChunkData::sChunkSection>::cStarvationCallbacks
111  {
112  virtual void OnStartUsingReserve() override {}
113  virtual void OnEndUsingReserve() override {}
114  virtual void OnOutOfReserve() override {}
115  };
116 
118  m_Pool(cpp14::make_unique<MemCallbacks>(), 0, cChunkData::NumSections), // Keep 1 chunk worth of reserve
119  m_Data(m_Pool)
120  {
121  }
122 
123 
126 
127 protected:
128 
129  virtual void ChunkData(const cChunkData & a_ChunkBuffer) override
130  {
131  m_Data.Assign(a_ChunkBuffer);
132  }
133 };
134 
135 
136 
137 
void CopyMetas(NIBBLETYPE *a_Dest) const
Copies the metadata into the specified flat array.
Definition: ChunkData.cpp:366
virtual void ChunkData(const cChunkData &a_ChunkBuffer) override
virtual void ChunkData(const cChunkData &a_ChunkBuffer) override
virtual void OnEndUsingReserve() override
Is called once the reserve buffer has returned to normal size.
cChunkDef::BlockNibbles m_BlockSkyLight
virtual void OnStartUsingReserve() override
Is called when the reserve buffer starts to be used.
cChunkDef::BlockNibbles m_BlockLight
std::unique_ptr< T > make_unique(Args &&...args)
Definition: Globals.h:381
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
Definition: ChunkDef.h:150
void CopyBlockLight(NIBBLETYPE *a_Dest) const
Copies the block light data into the specified flat array.
Definition: ChunkData.cpp:385
static const int NumBlocks
Definition: ChunkDef.h:136
void CopySkyLight(NIBBLETYPE *a_Dest) const
Copies the skylight data into the specified flat array.
Definition: ChunkData.cpp:404
A simple implementation of the cChunkDataCallback interface that just copies the cChunkData.
cChunkDef::BlockNibbles m_BlockMetas
cListAllocationPool< cChunkData::sChunkSection > m_Pool
cChunkDef::BlockTypes m_BlockTypes
void CopyBlockTypes(BLOCKTYPE *a_Dest, size_t a_Idx=0, size_t a_Length=cChunkDef::NumBlocks) const
Copies the blocktype data into the specified flat array.
Definition: ChunkData.cpp:333
virtual void OnOutOfReserve() override
Is called when the allocation pool is unable to allocate memory.
static const int BlockDataSize
If the data is collected into a single buffer, how large it needs to be:
Definition: ChunkDef.h:139
virtual void ChunkData(const cChunkData &a_ChunkBuffer) override
A simple implementation of the cChunkDataCallback interface that collects all block data into a singl...
#define UNUSED
Definition: Globals.h:152
void Assign(const cChunkData &a_Other)
Copy assign from another cChunkData.
Definition: ChunkData.cpp:86
Definition: Entity.h:73
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
Definition: ChunkDef.h:153
Definition: Globals.h:378
A simple implementation of the cChunkDataCallback interface that collects all block data into separat...
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
Definition: ChunkDef.h:142
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:147