Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkDef.h
Go to the documentation of this file.
1 
2 // ChunkDef.h
3 
4 // Interfaces to helper types for chunk definitions. Most modules want to include this instead of cChunk.h
5 
6 
7 
8 
9 
10 #pragma once
11 
12 
13 
14 
15 
16 // Used to smoothly convert to new axis ordering. One will be removed when deemed stable.
17 #define AXIS_ORDER_YZX 1 // Original (1.1-)
18 #define AXIS_ORDER_XZY 2 // New (1.2+)
19 #define AXIS_ORDER AXIS_ORDER_XZY
20 
21 
22 
23 
24 
25 // fwd
26 class cBlockEntity;
27 class cEntity;
28 class cClientHandle;
29 class cBlockEntity;
30 class cChunkCoords;
31 
32 using OwnedEntity = std::unique_ptr<cEntity>;
33 using cEntityList = std::vector<OwnedEntity>;
34 using cBlockEntities = std::map<size_t, cBlockEntity *>;
35 
36 
37 
38 
39 // tolua_begin
40 
42 typedef unsigned char BLOCKTYPE;
43 
45 typedef unsigned char NIBBLETYPE;
46 
48 typedef unsigned char HEIGHTTYPE;
49 
50 // tolua_end
51 
52 
53 
54 
55 
57 {
58 public:
59  int m_ChunkX;
60  int m_ChunkZ;
61 
62  cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {}
63 
64 
65  bool operator == (const cChunkCoords & a_Other) const
66  {
67  return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ));
68  }
69 
70 
71  bool operator != (const cChunkCoords & a_Other) const
72  {
73  return !(operator == (a_Other));
74  }
75 
76 
78  bool operator < (const cChunkCoords & a_Other) const
79  {
80  if (a_Other.m_ChunkX == m_ChunkX)
81  {
82  return (m_ChunkZ < a_Other.m_ChunkZ);
83  }
84  else
85  {
86  return (m_ChunkX < a_Other.m_ChunkX);
87  }
88  }
89 
90 
92  AString ToString() const
93  {
94  return Printf("[%d, %d]", m_ChunkX, m_ChunkZ);
95  }
96 } ;
97 
98 
99 
100 
101 
104 {
105 public:
106  using const_iterator = std::vector<cClientHandle *>::const_iterator;
108 
109  explicit cChunkClientHandles(const std::vector<cClientHandle *> & a_Container):
110  m_Begin(a_Container.cbegin()),
111  m_End(a_Container.cend())
112  {
113  }
114 
115  const_iterator begin() const { return m_Begin; }
116  const_iterator cbegin() const { return m_Begin; }
117 
118  const_iterator end() const { return m_End; }
119  const_iterator cend() const { return m_End; }
120 
121 private:
123 };
124 
125 
126 
127 
128 
131 {
132 public:
133  // Chunk dimensions:
134  static const int Width = 16;
135  static const int Height = 256;
136  static const int NumBlocks = Width * Height * Width;
137 
139  static const int BlockDataSize = cChunkDef::NumBlocks * 2 + (cChunkDef::NumBlocks / 2); // 2.5 * numblocks
140 
142  typedef HEIGHTTYPE HeightMap[Width * Width];
143 
147  typedef EMCSBiome BiomeMap[Width * Width];
148 
150  typedef BLOCKTYPE BlockTypes[NumBlocks];
151 
153  typedef NIBBLETYPE BlockNibbles[NumBlocks / 2];
154 
156  typedef std::vector<BLOCKTYPE> COMPRESSED_BLOCKTYPE;
157 
159  typedef std::vector<NIBBLETYPE> COMPRESSED_NIBBLETYPE;
160 
161 
163  inline static void AbsoluteToRelative(/* in-out */ int & a_X, int & a_Y, int & a_Z, /* out */ int & a_ChunkX, int & a_ChunkZ)
164  {
165  UNUSED(a_Y);
166  BlockToChunk(a_X, a_Z, a_ChunkX, a_ChunkZ);
167 
168  a_X = a_X - a_ChunkX * Width;
169  a_Z = a_Z - a_ChunkZ * Width;
170  }
171 
172 
173 
174 
175 
178  inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition)
179  {
180  cChunkCoords chunkPos = BlockToChunk(a_BlockPosition);
181  return AbsoluteToRelative(a_BlockPosition, chunkPos);
182  }
183 
184 
185 
186 
187 
189  inline static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos)
190  {
191  return {a_BlockPosition.x - a_ChunkPos.m_ChunkX * Width, a_BlockPosition.y, a_BlockPosition.z - a_ChunkPos.m_ChunkZ * Width};
192  }
193 
194 
195 
196 
198  inline static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
199  {
200  return Vector3i(
201  a_RelBlockPosition.x + a_ChunkCoords.m_ChunkX * Width,
202  a_RelBlockPosition.y,
203  a_RelBlockPosition.z + a_ChunkCoords.m_ChunkZ * Width
204  );
205  }
206 
207 
208 
209 
210 
212  inline static bool IsValidHeight(int a_Height)
213  {
214  return ((a_Height >= 0) && (a_Height < Height));
215  }
216 
218  inline static bool IsValidWidth(int a_Width)
219  {
220  return ((a_Width >= 0) && (a_Width < Width));
221  }
222 
224  inline static bool IsValidRelPos(Vector3i a_RelPos)
225  {
226  return (
227  IsValidWidth(a_RelPos.x) &&
228  IsValidHeight(a_RelPos.y) &&
229  IsValidWidth(a_RelPos.z)
230  );
231  }
232 
234  inline static void BlockToChunk(int a_X, int a_Z, int & a_ChunkX, int & a_ChunkZ)
235  {
236  // This version is deprecated in favor of the vector version
237  // If you're developing new code, use the other version.
238  auto ChunkCoords = BlockToChunk({a_X, 0, a_Z});
239  a_ChunkX = ChunkCoords.m_ChunkX;
240  a_ChunkZ = ChunkCoords.m_ChunkZ;
241  }
242 
244  inline static cChunkCoords BlockToChunk(Vector3i a_Pos)
245  {
246  cChunkCoords Chunk(a_Pos.x / Width, a_Pos.z / Width);
247  if ((a_Pos.x < 0) && (a_Pos.x % Width != 0))
248  {
249  Chunk.m_ChunkX--;
250  }
251  if ((a_Pos.z < 0) && (a_Pos.z % Width != 0))
252  {
253  Chunk.m_ChunkZ--;
254  }
255  return Chunk;
256  }
257 
258 
259  inline static int MakeIndex(int x, int y, int z)
260  {
261  if (
262  (x < Width) && (x > -1) &&
263  (y < Height) && (y > -1) &&
264  (z < Width) && (z > -1)
265  )
266  {
267  return MakeIndexNoCheck(x, y, z);
268  }
269  FLOGERROR("cChunkDef::MakeIndex(): coords out of range: {0}; returning fake index 0", Vector3i{x, y, z});
270  ASSERT(!"cChunkDef::MakeIndex(): coords out of chunk range!");
271  return 0;
272  }
273 
274 
275  inline static int MakeIndexNoCheck(int x, int y, int z)
276  {
277  #if AXIS_ORDER == AXIS_ORDER_XZY
278  // For some reason, NOT using the Horner schema is faster. Weird.
279  return x + (z * cChunkDef::Width) + (y * cChunkDef::Width * cChunkDef::Width); // 1.2 uses XZY
280  #elif AXIS_ORDER == AXIS_ORDER_YZX
281  return y + (z * cChunkDef::Width) + (x * cChunkDef::Height * cChunkDef::Width); // 1.1 uses YZX
282  #endif
283  }
284 
285 
286 
287  inline static int MakeIndexNoCheck(Vector3i a_RelPos)
288  {
289  return MakeIndexNoCheck(a_RelPos.x, a_RelPos.y, a_RelPos.z);
290  }
291 
292 
293 
294  inline static Vector3i IndexToCoordinate(size_t index)
295  {
296  #if AXIS_ORDER == AXIS_ORDER_XZY
297  return Vector3i( // 1.2
298  static_cast<int>(index % cChunkDef::Width), // X
299  static_cast<int>(index / (cChunkDef::Width * cChunkDef::Width)), // Y
300  static_cast<int>((index / cChunkDef::Width) % cChunkDef::Width) // Z
301  );
302  #elif AXIS_ORDER == AXIS_ORDER_YZX
303  return Vector3i( // 1.1
304  static_cast<int>(index / (cChunkDef::Height * cChunkDef::Width)), // X
305  static_cast<int>(index % cChunkDef::Height), // Y
306  static_cast<int>((index / cChunkDef::Height) % cChunkDef::Width) // Z
307  );
308  #endif
309  }
310 
311 
312  inline static void SetBlock(BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
313  {
314  ASSERT((a_X >= 0) && (a_X < Width));
315  ASSERT((a_Y >= 0) && (a_Y < Height));
316  ASSERT((a_Z >= 0) && (a_Z < Width));
317  a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)] = a_Type;
318  }
319 
320 
321  inline static void SetBlock(BLOCKTYPE * a_BlockTypes, int a_Index, BLOCKTYPE a_Type)
322  {
323  ASSERT((a_Index >= 0) && (a_Index <= NumBlocks));
324  a_BlockTypes[a_Index] = a_Type;
325  }
326 
327 
328  inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, Vector3i a_RelPos)
329  {
330  ASSERT(IsValidRelPos(a_RelPos));
331  return a_BlockTypes[MakeIndexNoCheck(a_RelPos)];
332  }
333 
334 
335  inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_X, int a_Y, int a_Z)
336  {
337  ASSERT((a_X >= 0) && (a_X < Width));
338  ASSERT((a_Y >= 0) && (a_Y < Height));
339  ASSERT((a_Z >= 0) && (a_Z < Width));
340  return a_BlockTypes[MakeIndexNoCheck(a_X, a_Y, a_Z)];
341  }
342 
343 
344  inline static BLOCKTYPE GetBlock(const BLOCKTYPE * a_BlockTypes, int a_Idx)
345  {
346  ASSERT((a_Idx >= 0) && (a_Idx < NumBlocks));
347  return a_BlockTypes[a_Idx];
348  }
349 
350 
351  inline static HEIGHTTYPE GetHeight(const HeightMap & a_HeightMap, int a_X, int a_Z)
352  {
353  ASSERT((a_X >= 0) && (a_X < Width));
354  ASSERT((a_Z >= 0) && (a_Z < Width));
355  return a_HeightMap[a_X + Width * a_Z];
356  }
357 
358 
359  inline static void SetHeight(HeightMap & a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
360  {
361  ASSERT((a_X >= 0) && (a_X < Width));
362  ASSERT((a_Z >= 0) && (a_Z < Width));
363  a_HeightMap[a_X + Width * a_Z] = a_Height;
364  }
365 
366 
367  inline static EMCSBiome GetBiome(const BiomeMap & a_BiomeMap, int a_X, int a_Z)
368  {
369  ASSERT((a_X >= 0) && (a_X < Width));
370  ASSERT((a_Z >= 0) && (a_Z < Width));
371  return a_BiomeMap[a_X + Width * a_Z];
372  }
373 
374 
375  inline static void SetBiome(BiomeMap & a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
376  {
377  ASSERT((a_X >= 0) && (a_X < Width));
378  ASSERT((a_Z >= 0) && (a_Z < Width));
379  a_BiomeMap[a_X + Width * a_Z] = a_Biome;
380  }
381 
382 
383  static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble = false)
384  {
385  if ((a_BlockIdx > -1) && (a_BlockIdx < NumBlocks))
386  {
387  if (static_cast<size_t>(a_BlockIdx / 2) >= a_Buffer.size())
388  {
389  return (a_IsSkyLightNibble ? 0xff : 0);
390  }
391  return (a_Buffer[static_cast<size_t>(a_BlockIdx / 2)] >> ((a_BlockIdx & 1) * 4)) & 0x0f;
392  }
393  ASSERT(!"cChunkDef::GetNibble(): index out of chunk range!");
394  return 0;
395  }
396 
397 
398  static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble = false)
399  {
400  if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
401  {
402  size_t Index = static_cast<size_t>(MakeIndexNoCheck(x, y, z));
403  if ((Index / 2) >= a_Buffer.size())
404  {
405  return (a_IsSkyLightNibble ? 0xff : 0);
406  }
407  return ExpandNibble(a_Buffer, Index);
408  }
409  ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
410  return 0;
411  }
412 
413 
414  static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, Vector3i a_RelPos)
415  {
416  if (IsValidRelPos(a_RelPos))
417  {
418  auto Index = MakeIndexNoCheck(a_RelPos);
419  return (a_Buffer[static_cast<size_t>(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
420  }
421  ASSERT(!"Coords out of chunk range!");
422  return 0;
423  }
424 
425 
426  static NIBBLETYPE GetNibble(const NIBBLETYPE * a_Buffer, int x, int y, int z)
427  {
428  if ((x < Width) && (x > -1) && (y < Height) && (y > -1) && (z < Width) && (z > -1))
429  {
430  int Index = MakeIndexNoCheck(x, y, z);
431  return (a_Buffer[static_cast<size_t>(Index / 2)] >> ((Index & 1) * 4)) & 0x0f;
432  }
433  ASSERT(!"cChunkDef::GetNibble(): coords out of chunk range!");
434  return 0;
435  }
436 
437 
438  static void SetNibble(COMPRESSED_NIBBLETYPE & a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble)
439  {
440  if ((a_BlockIdx < 0) || (a_BlockIdx >= NumBlocks))
441  {
442  ASSERT(!"cChunkDef::SetNibble(): index out of range!");
443  return;
444  }
445  if (static_cast<size_t>(a_BlockIdx / 2) >= a_Buffer.size())
446  {
447  a_Buffer.resize(static_cast<size_t>((a_BlockIdx / 2) + 1));
448  }
449  a_Buffer[static_cast<size_t>(a_BlockIdx / 2)] = PackNibble(a_Buffer, static_cast<size_t>(a_BlockIdx), a_Nibble);
450  }
451 
452 
453  static void SetNibble(COMPRESSED_NIBBLETYPE & a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble)
454  {
455  if (
456  (x >= Width) || (x < 0) ||
457  (y >= Height) || (y < 0) ||
458  (z >= Width) || (z < 0)
459  )
460  {
461  ASSERT(!"cChunkDef::SetNibble(): index out of range!");
462  return;
463  }
464 
465  size_t Index = static_cast<size_t>(MakeIndexNoCheck(x, y, z));
466  if ((Index / 2) >= a_Buffer.size())
467  {
468  a_Buffer.resize(((Index / 2) + 1));
469  }
470  a_Buffer[(Index / 2)] = PackNibble(a_Buffer, Index, a_Nibble);
471  }
472 
473 
474 private:
475 
476 
477  inline static NIBBLETYPE PackNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, size_t a_Index, NIBBLETYPE a_Nibble)
478  {
479  return static_cast<NIBBLETYPE>(
480  (a_Buffer[a_Index / 2] & (0xf0 >> ((a_Index & 1) * 4))) | // The untouched nibble
481  ((a_Nibble & 0x0f) << ((a_Index & 1) * 4)) // The nibble being set
482  );
483  }
484 
485 
486  inline static NIBBLETYPE ExpandNibble(const COMPRESSED_NIBBLETYPE & a_Buffer, size_t a_Index)
487  {
488  return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f;
489  }
490 
491 
492 } ;
493 
494 
495 
496 
497 
501 {
502 public:
503 
504  virtual ~cClientDiffCallback() {}
505 
507  virtual void Removed(cClientHandle * a_Client) = 0;
508 
510  virtual void Added(cClientHandle * a_Client) = 0;
511 } ;
512 
513 
514 
515 
516 
517 struct sSetBlock
518 {
519  int m_RelX, m_RelY, m_RelZ;
523 
524  sSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta):
525  m_RelX(a_BlockX),
526  m_RelY(a_BlockY),
527  m_RelZ(a_BlockZ),
528  m_BlockType(a_BlockType),
529  m_BlockMeta(a_BlockMeta)
530  {
531  cChunkDef::AbsoluteToRelative(m_RelX, m_RelY, m_RelZ, m_ChunkX, m_ChunkZ);
532  }
533 
534  sSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
535  sSetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_BlockType, a_BlockMeta)
536  {
537  }
538 
539  sSetBlock(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) :
540  m_RelX(a_RelX), m_RelY(a_RelY), m_RelZ(a_RelZ),
541  m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ),
542  m_BlockType(a_BlockType),
543  m_BlockMeta(a_BlockMeta)
544  {
545  ASSERT((a_RelX >= 0) && (a_RelX < cChunkDef::Width));
546  ASSERT((a_RelZ >= 0) && (a_RelZ < cChunkDef::Width));
547  }
548 
550  int GetX(void) const { return m_RelX + cChunkDef::Width * m_ChunkX; }
551 
554  int GetY(void) const { return m_RelY; }
555 
557  int GetZ(void) const { return m_RelZ + cChunkDef::Width * m_ChunkZ; }
558 
560  Vector3i GetPos(void) const { return Vector3i(GetX(), GetY(), GetZ()); }
561 };
562 
563 typedef std::list<sSetBlock> sSetBlockList;
564 typedef std::vector<sSetBlock> sSetBlockVector;
565 
566 typedef std::list<cChunkCoords> cChunkCoordsList;
567 typedef std::vector<cChunkCoords> cChunkCoordsVector;
568 
569 
570 
571 
572 
576 {
577 public:
578  size_t operator () (const cChunkCoords & a_Coords) const
579  {
580  return (static_cast<size_t>(a_Coords.m_ChunkX) << 16) ^ static_cast<size_t>(a_Coords.m_ChunkZ);
581  }
582 };
583 
584 
585 
586 
587 
589 {
590 public:
591  int m_ChunkX;
592  int m_ChunkZ;
594 
595  cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_ForceGenerate(a_ForceGenerate){}
596 
597  bool operator == (const cChunkCoordsWithBool & a_Other) const
598  {
599  return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ) && (m_ForceGenerate == a_Other.m_ForceGenerate));
600  }
601 };
602 
603 typedef std::list<cChunkCoordsWithBool> cChunkCoordsWithBoolList;
604 
605 
606 
607 
608 
611 {
612 public:
613 
614  virtual ~cChunkCoordCallback() {}
615 
617  virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess) = 0;
618 } ;
619 
620 
621 
622 
623 
627 {
628 public:
629  cChunkCoordsWithCallback(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback * a_Callback):
630  m_ChunkX(a_ChunkX),
631  m_ChunkZ(a_ChunkZ),
632  m_Callback(a_Callback)
633  {
634  }
635 
636  int m_ChunkX;
637  int m_ChunkZ;
639 };
640 
641 
642 
643 
644 
646 template <typename X> class cCoordWithData
647 {
648 public:
649  int x;
650  int y;
651  int z;
652  X Data;
653 
654  cCoordWithData(int a_X, int a_Y, int a_Z) :
655  x(a_X), y(a_Y), z(a_Z), Data()
656  {
657  }
658 
659  cCoordWithData(int a_X, int a_Y, int a_Z, const X & a_Data) :
660  x(a_X), y(a_Y), z(a_Z), Data(a_Data)
661  {
662  }
663 } ;
664 
667 
668 typedef std::list<cCoordWithInt> cCoordWithIntList;
669 typedef std::vector<cCoordWithInt> cCoordWithIntVector;
std::map< size_t, cBlockEntity * > cBlockEntities
Definition: ChunkDef.h:34
cCoordWithData(int a_X, int a_Y, int a_Z)
Definition: ChunkDef.h:654
Generic template that can store any kind of data together with a triplet of 3 coords.
Definition: ChunkDef.h:646
T x
Definition: Vector3.h:17
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
int GetY(void) const
Returns the absolute Y coord of the stored block.
Definition: ChunkDef.h:554
static bool IsValidRelPos(Vector3i a_RelPos)
Validates a chunk relative coordinate.
Definition: ChunkDef.h:224
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
Definition: ChunkDef.h:312
std::list< cChunkCoordsWithBool > cChunkCoordsWithBoolList
Definition: ChunkDef.h:603
Provides storage for a set of chunk coords together with a callback.
Definition: ChunkDef.h:626
cCoordWithData< BLOCKTYPE > cCoordWithBlock
Definition: ChunkDef.h:666
static const int Width
Definition: ChunkDef.h:134
static const int NumBlocks
Definition: ChunkDef.h:136
static bool IsValidHeight(int a_Height)
Validates a height-coordinate.
Definition: ChunkDef.h:212
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Definition: ChunkDef.h:351
static int MakeIndex(int x, int y, int z)
Definition: ChunkDef.h:259
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Constants used throughout the code, useful typedefs and utility functions.
Definition: ChunkDef.h:130
static void SetNibble(COMPRESSED_NIBBLETYPE &a_Buffer, int a_BlockIdx, NIBBLETYPE a_Nibble)
Definition: ChunkDef.h:438
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:21
int GetZ(void) const
Returns the absolute Z coord of the stored block.
Definition: ChunkDef.h:557
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
Definition: ChunkDef.h:328
unsigned char HEIGHTTYPE
The type used by the heightmap.
Definition: ChunkDef.h:48
Vector3i GetPos(void) const
Returns the absolute position of the stored block.
Definition: ChunkDef.h:560
cChunkClientHandles(const std::vector< cClientHandle * > &a_Container)
Definition: ChunkDef.h:109
static int MakeIndexNoCheck(int x, int y, int z)
Definition: ChunkDef.h:275
static NIBBLETYPE ExpandNibble(const COMPRESSED_NIBBLETYPE &a_Buffer, size_t a_Index)
Definition: ChunkDef.h:486
T y
Definition: Vector3.h:17
sSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDef.h:534
static NIBBLETYPE GetNibble(const NIBBLETYPE *a_Buffer, Vector3i a_RelPos)
Definition: ChunkDef.h:414
T z
Definition: Vector3.h:17
void FLOGERROR(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:147
static const int Height
Definition: ChunkDef.h:135
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
Definition: ChunkDef.h:234
cChunkCoords(int a_ChunkX, int a_ChunkZ)
Definition: ChunkDef.h:62
BLOCKTYPE m_BlockType
Definition: ChunkDef.h:521
std::vector< OwnedEntity > cEntityList
Definition: ChunkDef.h:33
std::vector< cClientHandle * >::const_iterator const_iterator
Definition: ChunkDef.h:106
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos)
Converts the absolute coords into coords relative to the specified chunk.
Definition: ChunkDef.h:189
int GetX(void) const
Returns the absolute X coord of the stored block.
Definition: ChunkDef.h:550
std::vector< NIBBLETYPE > COMPRESSED_NIBBLETYPE
The storage wrapper used for compressed nibbledata residing in RAMz.
Definition: ChunkDef.h:159
sSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDef.h:524
Interface class used for comparing clients of two chunks.
Definition: ChunkDef.h:500
virtual ~cClientDiffCallback()
Definition: ChunkDef.h:504
static NIBBLETYPE GetNibble(const NIBBLETYPE *a_Buffer, int x, int y, int z)
Definition: ChunkDef.h:426
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
Definition: ChunkDef.h:163
const_iterator cbegin() const
Definition: ChunkDef.h:116
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
Definition: ChunkDef.h:375
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
Definition: StringUtils.cpp:55
static NIBBLETYPE PackNibble(const COMPRESSED_NIBBLETYPE &a_Buffer, size_t a_Index, NIBBLETYPE a_Nibble)
Definition: ChunkDef.h:477
std::list< sSetBlock > sSetBlockList
Definition: ChunkDef.h:563
#define ASSERT(x)
Definition: Globals.h:335
std::vector< BLOCKTYPE > COMPRESSED_BLOCKTYPE
The storage wrapper used for compressed blockdata residing in RAMz.
Definition: ChunkDef.h:156
std::list< cCoordWithInt > cCoordWithIntList
Definition: ChunkDef.h:668
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_Index, BLOCKTYPE a_Type)
Definition: ChunkDef.h:321
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
Definition: ChunkDef.h:198
int m_ChunkZ
Definition: ChunkDef.h:60
const_iterator m_End
Definition: ChunkDef.h:122
#define UNUSED
Definition: Globals.h:152
static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE &a_Buffer, int a_BlockIdx, bool a_IsSkyLightNibble=false)
Definition: ChunkDef.h:383
const_iterator begin() const
Definition: ChunkDef.h:115
const_iterator cend() const
Definition: ChunkDef.h:119
bool operator<(const cChunkCoords &a_Other) const
Simple comparison, to support ordering.
Definition: ChunkDef.h:78
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
Definition: ChunkDef.h:359
int m_ChunkX
Definition: ChunkDef.h:59
std::string AString
Definition: StringUtils.h:13
int m_ChunkZ
Definition: ChunkDef.h:520
int m_RelZ
Definition: ChunkDef.h:519
A simple hash function for chunk coords, we assume that chunk coords won&#39;t use more than 16 bits...
Definition: ChunkDef.h:575
std::vector< cCoordWithInt > cCoordWithIntVector
Definition: ChunkDef.h:669
bool operator==(const cChunkCoords &a_Other) const
Definition: ChunkDef.h:65
const_iterator iterator
Definition: ChunkDef.h:107
Interface class used as a callback for operations that involve chunk coords.
Definition: ChunkDef.h:610
const_iterator end() const
Definition: ChunkDef.h:118
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_Idx)
Definition: ChunkDef.h:344
Definition: Entity.h:73
bool operator!=(const cChunkCoords &a_Other) const
Definition: ChunkDef.h:71
std::vector< cChunkCoords > cChunkCoordsVector
Definition: ChunkDef.h:567
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z)
Definition: ChunkDef.h:335
AString ToString() const
Returns a string that describes the chunk coords, suitable for logging.
Definition: ChunkDef.h:92
std::unique_ptr< cEntity > OwnedEntity
Definition: ChunkDef.h:32
Vector3< int > Vector3i
Definition: Vector3.h:447
sSetBlock(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: ChunkDef.h:539
NIBBLETYPE m_BlockMeta
Definition: ChunkDef.h:522
cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate)
Definition: ChunkDef.h:595
cCoordWithData(int a_X, int a_Y, int a_Z, const X &a_Data)
Definition: ChunkDef.h:659
static bool IsValidWidth(int a_Width)
Validates a width-coordinate.
Definition: ChunkDef.h:218
std::list< cChunkCoords > cChunkCoordsList
Definition: ChunkDef.h:566
static int MakeIndexNoCheck(Vector3i a_RelPos)
Definition: ChunkDef.h:287
static NIBBLETYPE GetNibble(const COMPRESSED_NIBBLETYPE &a_Buffer, int x, int y, int z, bool a_IsSkyLightNibble=false)
Definition: ChunkDef.h:398
static cChunkCoords BlockToChunk(Vector3i a_Pos)
The Y coordinate of a_Pos is ignored.
Definition: ChunkDef.h:244
cChunkCoordCallback * m_Callback
Definition: ChunkDef.h:638
static void SetNibble(COMPRESSED_NIBBLETYPE &a_Buffer, int x, int y, int z, NIBBLETYPE a_Nibble)
Definition: ChunkDef.h:453
cChunkCoordsWithCallback(int a_ChunkX, int a_ChunkZ, cChunkCoordCallback *a_Callback)
Definition: ChunkDef.h:629
cCoordWithData< int > cCoordWithInt
Definition: ChunkDef.h:665
std::vector< sSetBlock > sSetBlockVector
Definition: ChunkDef.h:564
static Vector3i IndexToCoordinate(size_t index)
Definition: ChunkDef.h:294
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition)
Converts the specified absolute position into a relative position within its chunk.
Definition: ChunkDef.h:178
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
Definition: ChunkDef.h:367
virtual ~cChunkCoordCallback()
Definition: ChunkDef.h:614
Non-owning view of a chunk&#39;s client handles.
Definition: ChunkDef.h:103