37 cMap::cMap(
unsigned int a_ID,
int a_CenterX,
int a_CenterZ,
cWorld * a_World,
unsigned int a_Scale)
59 Client->SendMapData(*
this, 0, 0);
61 m_ClientsInCurrentTick.clear();
71 int PixelRadius =
static_cast<int>(a_Radius /
GetPixelWidth());
73 unsigned int StartX =
static_cast<unsigned int>(
Clamp(a_PixelX - PixelRadius, 0, static_cast<int>(
m_Width)));
74 unsigned int StartZ =
static_cast<unsigned int>(
Clamp(a_PixelZ - PixelRadius, 0, static_cast<int>(
m_Height)));
76 unsigned int EndX =
static_cast<unsigned int>(
Clamp(a_PixelX + PixelRadius, 0, static_cast<int>(
m_Width)));
77 unsigned int EndZ =
static_cast<unsigned int>(
Clamp(a_PixelZ + PixelRadius, 0, static_cast<int>(
m_Height)));
79 for (
unsigned int X = StartX; X < EndX; ++X)
81 for (
unsigned int Z = StartZ; Z < EndZ; ++Z)
83 int dX =
static_cast<int>(X) - a_PixelX;
84 int dZ =
static_cast<int>(Z) - a_PixelZ;
86 if ((dX * dX) + (dZ * dZ) < (PixelRadius * PixelRadius))
140 static const std::array<unsigned char, 4> BrightnessID = { { 3, 0, 1, 2 } };
144 auto Height = a_Chunk.
GetHeight(RelX, RelZ);
166 const int BrightnessIDSize =
static_cast<int>(BrightnessID.size());
167 PixelData =
ColourID * 4 + BrightnessID[
static_cast<size_t>(Clamp<int>((BrightnessIDSize * Height) / ChunkHeight, 0, BrightnessIDSize - 1))];
183 ASSERT(a_Player !=
nullptr);
274 int InsideWidth = (
GetWidth() / 2) - 1;
275 int InsideHeight = (
GetHeight() / 2) - 1;
284 if ((PixelX > -InsideWidth) && (PixelX <= InsideWidth) && (PixelZ > -InsideHeight) && (PixelZ <= InsideHeight))
286 double Yaw = a_TrackedEntity->
GetYaw();
295 Rot =
CeilC(((Yaw - 11.25) * 16) / 360);
306 if (PixelX <= -InsideWidth)
308 PixelX = -InsideWidth;
310 if (PixelZ <= -InsideHeight)
312 PixelZ = -InsideHeight;
314 if (PixelX > InsideWidth)
316 PixelX = InsideWidth;
318 if (PixelZ > InsideHeight)
320 PixelZ = InsideHeight;
324 return {Type,
static_cast<unsigned>(2 * PixelX + 1), static_cast<unsigned>(2 * PixelZ + 1), Rot};
333 return static_cast<unsigned int>(pow(2.0, static_cast<double>(
m_Scale)));
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
bool UpdatePixel(unsigned int a_X, unsigned int a_Z)
Update the specified pixel.
double GetPosX(void) const
eDimension GetDimension(void) const
eDimension
Dimension of a world.
bool IsBlockWater(BLOCKTYPE a_BlockType)
void UpdateClient(cPlayer *a_Player)
Send next update packet to the specified player and remove invalid decorators / clients.
ColorID GetPixel(unsigned int a_X, unsigned int a_Z)
void Resize(unsigned int a_Width, unsigned int a_Height)
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
unsigned char BLOCKTYPE
The datatype used by blockdata.
MTRand & GetRandomProvider()
Returns the current thread's random number source.
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta)
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
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.
unsigned int m_Scale
The zoom level, 2^scale square blocks per pixel.
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Constants used throughout the code, useful typedefs and utility functions.
cMapDecoratorList m_Decorators
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
cMapClientList m_ClientsInCurrentTick
cColorList m_Data
Column-major array of colours.
int GetCenterZ(void) const
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
void Tick()
Sends a map update to all registered clients Clears the list holding registered clients and decorator...
unsigned int GetNumPixels(void) const
AString & Printf(AString &str, const char *format, fmt::ArgList args)
Output the formatted text into the string.
bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data)
Player outside of the boundaries of the map.
virtual eDimension GetDimension(void) const override
cMap(unsigned int a_ID, cWorld *a_World)
Construct an empty map.
unsigned int GetHeight(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).
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
int GetHeight(int a_X, int a_Z)
cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
double GetYaw(void) const
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
const cMapDecorator CreateDecorator(const cEntity *a_TrackedEntity)
Encapsulates a map decorator.
double GetPosZ(void) const
void SetPosition(int a_CenterX, int a_CenterZ)
int GetCenterX(void) const
unsigned int GetWidth(void) const
cClientHandle * GetClientHandle(void) const
Returns the raw client handle associated with the player.
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)