27 m_Name(
fmt::format(FMT_STRING(
"map_{}"), m_ID))
36 cMap::cMap(
unsigned int a_ID,
int a_CenterX,
int a_CenterZ,
cWorld * a_World,
unsigned int a_Scale):
44 m_Name(
fmt::format(FMT_STRING(
"map_{}"), m_ID))
57 Client->SendMapData(*
this, 0, 0);
69 int PixelRadius =
static_cast<int>(a_Radius /
GetPixelWidth());
71 unsigned int StartX =
static_cast<unsigned int>(
Clamp(a_PixelX - PixelRadius, 0,
static_cast<int>(
m_Width)));
72 unsigned int StartZ =
static_cast<unsigned int>(
Clamp(a_PixelZ - PixelRadius, 0,
static_cast<int>(
m_Height)));
74 unsigned int EndX =
static_cast<unsigned int>(
Clamp(a_PixelX + PixelRadius, 0,
static_cast<int>(
m_Width)));
75 unsigned int EndZ =
static_cast<unsigned int>(
Clamp(a_PixelZ + PixelRadius, 0,
static_cast<int>(
m_Height)));
77 for (
unsigned int X = StartX; X < EndX; ++X)
79 for (
unsigned int Z = StartZ; Z < EndZ; ++Z)
81 int dX =
static_cast<int>(X) - a_PixelX;
82 int dZ =
static_cast<int>(Z) - a_PixelZ;
84 if ((dX * dX) + (dZ * dZ) < (PixelRadius * PixelRadius))
133 static const std::array<unsigned char, 4> BrightnessID = { { 3, 0, 1, 2 } };
137 auto Height = a_Chunk.
GetHeight(RelX, RelZ);
159 const int BrightnessIDSize =
static_cast<int>(BrightnessID.size());
160 PixelData =
ColourID * 4 + BrightnessID[
static_cast<size_t>(Clamp<int>((BrightnessIDSize * Height) / ChunkHeight, 0, BrightnessIDSize - 1))];
176 ASSERT(a_Player !=
nullptr);
267 int InsideWidth = (
GetWidth() / 2) - 1;
268 int InsideHeight = (
GetHeight() / 2) - 1;
277 if ((PixelX > -InsideWidth) && (PixelX <= InsideWidth) && (PixelZ > -InsideHeight) && (PixelZ <= InsideHeight))
279 double Yaw = a_TrackedEntity->
GetYaw();
288 Rot =
CeilC(((Yaw - 11.25) * 16) / 360);
299 if (PixelX <= -InsideWidth)
301 PixelX = -InsideWidth;
303 if (PixelZ <= -InsideHeight)
305 PixelZ = -InsideHeight;
307 if (PixelX > InsideWidth)
309 PixelX = InsideWidth;
311 if (PixelZ > InsideHeight)
313 PixelZ = InsideHeight;
317 return {
Type,
static_cast<unsigned>(2 * PixelX + 1),
static_cast<unsigned>(2 * PixelZ + 1), Rot};
326 return static_cast<unsigned int>(pow(2.0,
static_cast<double>(
m_Scale)));
bool IsBlockWater(BLOCKTYPE a_BlockType)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
eDimension
Dimension of a world.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
Implements custom fmtlib formatting for cChunkCoords.
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
static const cBlockHandler & For(BLOCKTYPE a_BlockType)
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
int GetHeight(int a_X, int a_Z) const
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Constants used throughout the code, useful typedefs and utility functions.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
double GetPosX(void) const
double GetPosZ(void) const
double GetYaw(void) const
cClientHandle * GetClientHandle(void) const
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
Encapsulates a map decorator.
@ E_TYPE_PLAYER_OUTSIDE
Player outside of the boundaries of the map.
eDimension GetDimension(void) const
unsigned int GetHeight(void) const
void Tick()
Sends a map update to all registered clients Clears the list holding registered clients and decorator...
unsigned int m_Scale
The zoom level, 2^scale square blocks per pixel.
cMapDecoratorList m_Decorators
ColorID GetPixel(unsigned int a_X, unsigned int a_Z)
unsigned int GetWidth(void) const
void SetPosition(int a_CenterX, int a_CenterZ)
void UpdateClient(cPlayer *a_Player)
Send next update packet to the specified player and remove invalid decorators / clients.
unsigned int GetNumPixels(void) const
cMapClientList m_ClientsInCurrentTick
int GetCenterZ(void) const
bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data)
int GetCenterX(void) const
void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius)
Update a circular region with the specified radius and center (in pixels).
void Resize(unsigned int a_Width, unsigned int a_Height)
@ E_BASE_COLOR_TRANSPARENT
bool UpdatePixel(unsigned int a_X, unsigned int a_Z)
Update the specified pixel.
const cMapDecorator CreateDecorator(const cEntity *a_TrackedEntity)
cMap(unsigned int a_ID, cWorld *a_World)
Construct an empty map.
cColorList m_Data
Column-major array of colours.
unsigned int GetPixelWidth(void) const
bool DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback a_Callback)
Calls the callback for the chunk specified, with ChunkMapCS locked.
virtual eDimension GetDimension(void) const override