|
Cuberite
A lightweight, fast and extensible game server for Minecraft
|
Go to the documentation of this file.
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
130 inline static void AbsoluteToRelative(
int & a_X,
int & a_Y,
int & a_Z,
int & a_ChunkX,
int & a_ChunkZ)
135 a_X = a_X - a_ChunkX *
Width;
136 a_Z = a_Z - a_ChunkZ *
Width;
161 a_RelBlockPosition.
y,
170 return ((a_BlockPosition.
y >= 0) && (a_BlockPosition.
y <
Height));
177 return ((a_Width >= 0) && (a_Width <
Width));
193 inline static void BlockToChunk(
int a_X,
int a_Z,
int & a_ChunkX,
int & a_ChunkZ)
198 a_ChunkX = ChunkCoords.m_ChunkX;
199 a_ChunkZ = ChunkCoords.m_ChunkZ;
214 #if AXIS_ORDER == AXIS_ORDER_XZY
217 #elif AXIS_ORDER == AXIS_ORDER_YZX
231 #if AXIS_ORDER == AXIS_ORDER_XZY
237 #elif AXIS_ORDER == AXIS_ORDER_YZX
252 a_BlockTypes[
MakeIndex(a_X, a_Y, a_Z)] = a_Type;
259 a_BlockTypes[a_Index] = a_Type;
266 return a_BlockTypes[
MakeIndex(a_RelPos)];
275 return a_BlockTypes[
MakeIndex(a_X, a_Y, a_Z)];
282 return a_BlockTypes[a_Idx];
290 return a_HeightMap[a_X +
Width * a_Z];
298 a_HeightMap[a_X +
Width * a_Z] = a_Height;
306 return a_BiomeMap[a_X +
Width * a_Z];
314 a_BiomeMap[a_X +
Width * a_Z] = a_Biome;
320 if ((x <
Width) && (x > -1) && (y <
Height) && (y > -1) && (z <
Width) && (z > -1))
324 ASSERT(!
"cChunkDef::GetNibble(): coords out of chunk range!");
331 ASSERT((a_Nibble & 0xF) == a_Nibble);
333 a_Buffer[a_Index / 2] =
static_cast<NIBBLETYPE>(
334 (a_Buffer[a_Index / 2] & (0xf0 >> ((a_Index & 1) * 4))) |
335 ((a_Nibble & 0x0f) << ((a_Index & 1) * 4))
342 return (a_Buffer[a_Index / 2] >> ((a_Index & 1) * 4)) & 0x0f;
387 sSetBlock(a_BlockPos.x, a_BlockPos.y, a_BlockPos.z, a_BlockType, a_BlockMeta)
440 return (
static_cast<size_t>(a_Coords.
m_ChunkX) << 16) ^
static_cast<size_t>(a_Coords.
m_ChunkZ);
478 x(a_X),
y(a_Y),
z(a_Z),
Data(a_Data)
static const size_t NumSections
std::vector< sSetBlock > sSetBlockVector
sSetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Constants used throughout the code, useful typedefs and utility functions.
static const int NumBlocks
static void SetBiome(BiomeMap &a_BiomeMap, int a_X, int a_Z, EMCSBiome a_Biome)
static cChunkCoords BlockToChunk(const Vector3i a_Position)
The Y coordinate of a_Pos is ignored.
cChunkCoords(int a_ChunkX, int a_ChunkZ)
static void SetHeight(HeightMap &a_HeightMap, int a_X, int a_Z, HEIGHTTYPE a_Height)
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
std::unique_ptr< cEntity > OwnedEntity
virtual void Removed(cClientHandle *a_Client)=0
Called for clients that are in Chunk1 and not in Chunk2,.
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_Index, BLOCKTYPE a_Type)
std::list< cChunkCoords > cChunkCoordsList
std::vector< cChunkCoords > cChunkCoordsVector
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_Idx)
static void PackNibble(NIBBLETYPE *const a_Buffer, const size_t a_Index, const NIBBLETYPE a_Nibble)
static BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z)
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.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
bool operator==(const cChunkCoords &a_Other) const
static bool IsValidRelPos(Vector3i a_RelPos)
Validates a chunk relative coordinate.
static NIBBLETYPE GetNibble(const NIBBLETYPE *a_Buffer, int x, int y, int z)
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 BLOCKTYPE GetBlock(const BLOCKTYPE *a_BlockTypes, Vector3i a_RelPos)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
cCoordWithData(int a_X, int a_Y, int a_Z, const X &a_Data)
static void SetBlock(BLOCKTYPE *a_BlockTypes, int a_X, int a_Y, int a_Z, BLOCKTYPE a_Type)
int GetX(void) const
Returns the absolute X coord of the stored block.
bool operator!=(const cChunkCoords &a_Other) const
Interface class used as a callback for operations that involve chunk coords.
static HEIGHTTYPE GetHeight(const HeightMap &a_HeightMap, int a_X, int a_Z)
Interface class used for comparing clients of two chunks.
unsigned char HEIGHTTYPE
The type used by the heightmap.
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
size_t operator()(const cChunkCoords &a_Coords) const
std::list< cCoordWithInt > cCoordWithIntList
static const int SectionHeight
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
sSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
AString ToString() const
Returns a string that describes the chunk coords, suitable for logging.
HEIGHTTYPE HeightMap[Width *Width]
The type used for any heightmap operations and storage; idx = x + Width * z; Height points to the hig...
virtual ~cClientDiffCallback()
BLOCKTYPE BlockTypes[NumBlocks]
The type used for block type operations and storage, AXIS_ORDER ordering.
unsigned char BLOCKTYPE
The datatype used by blockdata.
static NIBBLETYPE ExpandNibble(const NIBBLETYPE *const a_Buffer, const size_t a_Index)
AString & Printf(AString &a_Dst, const char *a_Format, const Args &... a_Args)
virtual ~cChunkCoordCallback()
int GetY(void) const
Returns the absolute Y coord of the stored block.
cCoordWithData< int > cCoordWithInt
Vector3i GetRelativePos() const
Returns the relative position of the stored block within its chunk.
static size_t MakeIndex(int x, int y, int z)
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition, cChunkCoords a_ChunkPos)
Converts the absolute coords into coords relative to the specified chunk.
#define FAST_FLOOR_DIV(x, div)
Faster than (int)floorf((float)x / (float)div)
A simple hash function for chunk coords, we assume that chunk coords won't use more than 16 bits,...
bool operator<(const cChunkCoords &a_Other) const
Simple comparison, to support ordering.
NIBBLETYPE BlockNibbles[NumBlocks/2]
The type used for block data in nibble format, AXIS_ORDER ordering.
static bool IsValidWidth(int a_Width)
Validates a width-coordinate.
sSetBlock(int a_ChunkX, int a_ChunkZ, int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
cCoordWithData(int a_X, int a_Y, int a_Z)
int GetZ(void) const
Returns the absolute Z coord of the stored block.
Vector3i GetAbsolutePos() const
Returns the absolute coords of the stored block.
static size_t MakeIndex(Vector3i a_RelPos)
static Vector3i AbsoluteToRelative(Vector3i a_BlockPosition)
Converts the specified absolute position into a relative position within its chunk.
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
virtual void Added(cClientHandle *a_Client)=0
Called for clients that are in Chunk2 and not in Chunk1.
std::vector< OwnedEntity > cEntityList
Generic template that can store any kind of data together with a triplet of 3 coords.
std::vector< cCoordWithInt > cCoordWithIntVector
static Vector3i IndexToCoordinate(size_t index)