1
0
Fork 0
cuberite-2a/src/Map.h

210 lines
3.8 KiB
C
Raw Normal View History

2014-02-13 15:13:09 +00:00
// Map.h
// Implementation of in-game coloured maps
#pragma once
#include "BlockID.h"
class cClientHandle;
class cWorld;
2014-02-15 18:06:47 +00:00
class cPlayer;
2014-02-18 18:50:08 +00:00
class cMap;
2014-02-19 13:28:48 +00:00
/** Encapsulates a map decorator. */
2014-02-18 18:50:08 +00:00
class cMapDecorator
{
public:
2014-02-19 13:28:48 +00:00
2014-02-18 18:50:08 +00:00
enum eType
{
E_TYPE_PLAYER = 0x00,
E_TYPE_ITEM_FRAME = 0x01,
2014-02-19 13:28:48 +00:00
/** Player outside of the boundaries of the map. */
2014-02-18 18:50:08 +00:00
E_TYPE_PLAYER_OUTSIDE = 0x06
};
public:
2014-02-19 13:28:48 +00:00
/** Constructs a map decorator fixed at the specified pixel coordinates. (DEBUG) */
cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, int a_Rot);
2014-02-18 18:50:08 +00:00
2014-02-19 13:28:48 +00:00
/** Constructs a map decorator that tracks a player. */
2014-02-18 18:50:08 +00:00
cMapDecorator(cMap * a_Map, cPlayer * a_Player);
2014-02-19 13:28:48 +00:00
/** Updates the pixel coordinates of the decorator. */
2014-02-18 18:50:08 +00:00
void Update(void);
unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; }
2014-02-19 13:28:48 +00:00
int GetRot(void) const { return m_Rot; }
2014-02-18 18:50:08 +00:00
eType GetType(void) const { return m_Type; }
cPlayer * GetPlayer(void) { return m_Player; }
protected:
cMap * m_Map;
eType m_Type;
unsigned int m_PixelX;
unsigned int m_PixelZ;
unsigned int m_Rot;
cPlayer * m_Player;
2014-02-19 13:28:48 +00:00
2014-02-18 18:50:08 +00:00
};
typedef std::list<cMapDecorator> cMapDecoratorList;
2014-02-13 15:13:09 +00:00
2014-02-14 14:21:16 +00:00
// tolua_begin
2014-02-19 13:28:48 +00:00
/** Encapsulates an in-game world map. */
2014-02-13 15:13:09 +00:00
class cMap
{
public:
typedef Byte ColorID;
2014-02-14 14:21:16 +00:00
// tolua_end
2014-02-13 15:13:09 +00:00
typedef std::vector<ColorID> cColorList;
2014-02-19 13:28:48 +00:00
/** Encapsulates the state of a map client. */
2014-02-18 18:50:08 +00:00
struct cMapClient
{
cClientHandle * m_Handle;
2014-02-19 13:28:48 +00:00
/** Whether the map scale was modified and needs to be resent. */
2014-02-18 18:50:08 +00:00
bool m_SendInfo;
2014-02-19 13:28:48 +00:00
/** Ticks since last decorator update. */
2014-02-18 18:50:08 +00:00
unsigned int m_NextDecoratorUpdate;
2014-02-19 13:28:48 +00:00
/** Number of pixel data updates. */
2014-02-18 18:50:08 +00:00
Int64 m_DataUpdate;
2014-02-19 13:28:48 +00:00
2014-02-18 18:50:08 +00:00
Int64 m_LastUpdate;
};
typedef std::list<cMapClient> cMapClientList;
2014-02-17 14:27:12 +00:00
2014-02-13 15:13:09 +00:00
public:
2014-02-14 14:21:16 +00:00
/** Construct an empty map. */
2014-02-13 19:36:24 +00:00
cMap(unsigned int a_ID, cWorld * a_World);
2014-02-19 13:28:48 +00:00
/** Constructs an empty map at the specified coordinates. */
2014-02-13 15:13:09 +00:00
cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);
2014-02-19 13:28:48 +00:00
/** Send this map to the specified client. WARNING: Slow */
2014-02-13 15:13:09 +00:00
void SendTo(cClientHandle & a_Client);
2014-02-15 18:06:47 +00:00
/** Update a circular region with the specified radius and center (in pixels). */
void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius);
2014-02-19 13:28:48 +00:00
/** Update a circular region around the specified player. */
2014-02-15 18:06:47 +00:00
void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius);
2014-02-18 18:50:08 +00:00
/** Send next update packet and remove invalid decorators */
void UpdateClient(cPlayer * a_Player);
2014-02-17 14:27:12 +00:00
2014-02-14 14:21:16 +00:00
// tolua_begin
/** Erase pixel data */
void EraseData(void);
2014-02-13 15:13:09 +00:00
void Resize(unsigned int a_Width, unsigned int a_Height);
void SetPosition(int a_CenterX, int a_CenterZ);
void SetScale(unsigned int a_Scale);
unsigned int GetWidth (void) const { return m_Width; }
unsigned int GetHeight(void) const { return m_Height; }
unsigned int GetScale(void) const { return m_Scale; }
int GetCenterX(void) const { return m_CenterX; }
int GetCenterZ(void) const { return m_CenterZ; }
unsigned int GetID(void) const { return m_ID; }
cWorld * GetWorld(void) { return m_World; }
2014-02-15 18:06:47 +00:00
AString GetName(void) { return m_Name; }
2014-02-13 15:13:09 +00:00
eDimension GetDimension(void) const;
const cColorList & GetData(void) const { return m_Data; }
unsigned int GetNumPixels(void) const;
2014-02-15 18:06:47 +00:00
unsigned int GetPixelWidth(void) const;
2014-02-13 15:13:09 +00:00
2014-02-14 14:21:16 +00:00
// tolua_end
2014-02-13 15:13:09 +00:00
private:
2014-02-18 18:50:08 +00:00
/** Update the associated decorators. */
void UpdateDecorators(void);
2014-02-14 14:21:16 +00:00
/** Update the specified pixel. */
2014-02-17 14:27:12 +00:00
bool UpdatePixel(unsigned int a_X, unsigned int a_Z);
2014-02-14 14:21:16 +00:00
2014-02-13 15:13:09 +00:00
unsigned int m_ID;
unsigned int m_Width;
unsigned int m_Height;
/** The zoom level, 2^scale square blocks per pixel */
unsigned int m_Scale;
int m_CenterX;
int m_CenterZ;
/** Column-major array of colours */
cColorList m_Data;
cWorld * m_World;
2014-02-18 18:50:08 +00:00
cMapDecoratorList m_Decorators;
2014-02-17 14:27:12 +00:00
2014-02-18 18:50:08 +00:00
cMapClientList m_Clients;
2014-02-15 18:06:47 +00:00
AString m_Name;
2014-02-13 15:13:09 +00:00
friend class cMapSerializer;
};