17 #define AXIS_ORDER_YZX 1
18 #define AXIS_ORDER_XZY 2
19 #define AXIS_ORDER AXIS_ORDER_XZY
109 return format_to(a_Ctx.out(),
"[{}, {}]", a_Coords.
m_ChunkX, a_Coords.
m_ChunkZ);
147 inline static void AbsoluteToRelative(
int & a_X,
int & a_Y,
int & a_Z,
int & a_ChunkX,
int & a_ChunkZ)
152 a_X = a_X - a_ChunkX *
Width;
153 a_Z = a_Z - a_ChunkZ *
Width;
178 a_RelBlockPosition.
y,
187 return ((a_BlockPosition.
y >= 0) && (a_BlockPosition.
y <
Height));
194 return ((a_Width >= 0) && (a_Width <
Width));
210 inline static void BlockToChunk(
int a_X,
int a_Z,
int & a_ChunkX,
int & a_ChunkZ)
215 a_ChunkX = ChunkCoords.m_ChunkX;
216 a_ChunkZ = ChunkCoords.m_ChunkZ;
231 #if AXIS_ORDER == AXIS_ORDER_XZY
234 #elif AXIS_ORDER == AXIS_ORDER_YZX
248 #if AXIS_ORDER == AXIS_ORDER_XZY
254 #elif AXIS_ORDER == AXIS_ORDER_YZX
269 a_BlockTypes[
MakeIndex(a_X, a_Y, a_Z)] = a_Type;
276 a_BlockTypes[a_Index] = a_Type;
283 return a_BlockTypes[
MakeIndex(a_RelPos)];
292 return a_BlockTypes[
MakeIndex(a_X, a_Y, a_Z)];
299 return a_BlockTypes[a_Idx];
307 return a_HeightMap[a_X +
Width * a_Z];
315 a_HeightMap[a_X +
Width * a_Z] = a_Height;
323 return a_BiomeMap[a_X +
Width * a_Z];
331 a_BiomeMap[a_X +
Width * a_Z] = a_Biome;
337 if ((x <
Width) && (x > -1) && (y <
Height) && (y > -1) && (z <
Width) && (z > -1))
341 ASSERT(!
"cChunkDef::GetNibble(): coords out of chunk range!");
348 ASSERT((a_Nibble & 0xF) == a_Nibble);
350 a_Buffer[a_Index / 2] =
static_cast<NIBBLETYPE>(
351 (a_Buffer[a_Index / 2] & (0xf0 >> ((a_Index & 1) * 4))) |
352 ((a_Nibble & 0x0f) << ((a_Index & 1) * 4))
359 return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f;
404 sSetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_BlockType, a_BlockMeta)
457 return (
static_cast<size_t>(a_Coords.
m_ChunkX) << 16) ^
static_cast<size_t>(a_Coords.
m_ChunkZ);
495 x(a_X),
y(a_Y),
z(a_Z),
Data(a_Data)
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
std::vector< cCoordWithInt > cCoordWithIntVector
std::vector< sSetBlock > sSetBlockVector
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char HEIGHTTYPE
The type used by the heightmap.
std::list< cChunkCoords > cChunkCoordsList
std::unique_ptr< cEntity > OwnedEntity
cCoordWithData< int > cCoordWithInt
std::vector< OwnedEntity > cEntityList
std::vector< cChunkCoords > cChunkCoordsVector
std::list< cCoordWithInt > cCoordWithIntList
unsigned char BLOCKTYPE
The datatype used by blockdata.
#define FAST_FLOOR_DIV(x, div)
Faster than (int)floorf((float)x / (float)div)
Implements custom fmtlib formatting for cChunkCoords.
Wraps the chunk coords into a single structure.
cChunkCoords(int a_ChunkX, int a_ChunkZ)
bool operator<(const cChunkCoords &a_Other) const
Simple comparison, to support ordering.
AString ToString() const
Returns a string that describes the chunk coords, suitable for logging.
bool operator!=(const cChunkCoords &a_Other) const
bool operator==(const cChunkCoords &a_Other) const
auto format(cChunkCoords a_Coords, format_context &a_Ctx)
Constants used throughout the code, useful typedefs and utility functions.
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z)
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_Idx)
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:
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
static bool IsValidWidth(int a_Width)
Validates a width-coordinate.
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
static NIBBLETYPE GetNibble(const NIBBLETYPE *a_Buffer, int x, int y, int z)
static cChunkCoords BlockToChunk(const Vector3i a_Position)
The Y coordinate of a_Pos is ignored.
static bool IsValidRelPos(Vector3i a_RelPos)
Validates a chunk relative coordinate.
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition)
Converts the specified absolute position into a relative position within its chunk.
static size_t MakeIndex(Vector3i a_RelPos)
static void PackNibble(NIBBLETYPE *const a_Buffer, const size_t a_Index, const NIBBLETYPE a_Nibble)
static size_t MakeIndex(int x, int y, int z)
static NIBBLETYPE ExpandNibble(const NIBBLETYPE *const a_Buffer, const size_t a_Index)
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static const size_t NumSections
static const int SectionHeight
static Vector3i IndexToCoordinate(size_t index)
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos)
Converts the absolute coords into coords relative to the specified chunk.
static const int NumBlocks
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_Index, BLOCKTYPE a_Type)
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Interface class used for comparing clients of two chunks.
virtual void Removed(cClientHandle *a_Client)=0
Called for clients that are in Chunk1 and not in Chunk2,.
virtual ~cClientDiffCallback()
virtual void Added(cClientHandle *a_Client)=0
Called for clients that are in Chunk2 and not in Chunk1.
sSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
int GetX(void) const
Returns the absolute X coord of the stored block.
sSetBlock(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
int GetY(void) const
Returns the absolute Y coord of the stored block.
Vector3i GetAbsolutePos() const
Returns the absolute coords of the stored block.
Vector3i GetRelativePos() const
Returns the relative position of the stored block within its chunk.
sSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
int GetZ(void) const
Returns the absolute Z coord of the stored block.
A simple hash function for chunk coords, we assume that chunk coords won't use more than 16 bits,...
size_t operator()(const cChunkCoords &a_Coords) const
Interface class used as a callback for operations that involve chunk coords.
virtual ~cChunkCoordCallback()
virtual void Call(cChunkCoords a_Coords, bool a_IsSuccess)=0
Called with the chunk's coords, and an optional operation status flag for operations that support it.
Generic template that can store any kind of data together with a triplet of 3 coords.
cCoordWithData(int a_X, int a_Y, int a_Z)
cCoordWithData(int a_X, int a_Y, int a_Z, const X &a_Data)