Cuberite
A lightweight, fast and extensible game server for Minecraft
Map.h
Go to the documentation of this file.
1 
2 // Map.h
3 
4 // Implementation of in-game coloured maps
5 
6 
7 
8 
9 
10 #pragma once
11 
12 #include "Defines.h"
13 #include "ChunkDef.h"
14 
15 
16 
17 
18 class cClientHandle;
19 class cWorld;
20 class cPlayer;
21 class cMap;
22 
23 
24 
25 
26 
35 {
36 public:
37 
38  enum class eType
39  {
40  E_TYPE_PLAYER = 0x00,
41  E_TYPE_ITEM_FRAME = 0x01,
42 
45  };
46 
47  cMapDecorator(eType a_Type, unsigned int a_X, unsigned int a_Z, int a_Rot) :
48  m_Type(a_Type),
49  m_PixelX(a_X),
50  m_PixelZ(a_Z),
51  m_Rot(a_Rot)
52  {
53  }
54 
55 public:
56 
57  unsigned int GetPixelX(void) const { return m_PixelX; }
58  unsigned int GetPixelZ(void) const { return m_PixelZ; }
59 
60  int GetRot(void) const { return m_Rot; }
61 
62  eType GetType(void) const { return m_Type; }
63 
64 private:
65 
67 
68  unsigned int m_PixelX;
69  unsigned int m_PixelZ;
70 
71  int m_Rot;
72 
73 };
74 
75 
76 
77 
78 
79 // tolua_begin
80 
82 class cMap
83 {
84 public:
85 
87  {
88  E_BASE_COLOR_TRANSPARENT = 0, /* Air */
89  E_BASE_COLOR_LIGHT_GREEN = 4, /* Grass */
91  E_BASE_COLOR_LIGHT_BROWN = 8, /* Sand */
92  E_BASE_COLOR_GRAY_1 = 12, /* Cloth */
93  E_BASE_COLOR_RED = 16, /* TNT */
94  E_BASE_COLOR_PALE_BLUE = 20, /* Ice */
95  E_BASE_COLOR_GRAY_2 = 24, /* Iron */
96  E_BASE_COLOR_DARK_GREEN = 28, /* Foliage */
97  E_BASE_COLOR_WHITE = 32, /* Snow */
98  E_BASE_COLOR_LIGHT_GRAY = 36, /* Clay */
99  E_BASE_COLOR_BROWN = 40, /* Dirt */
100  E_BASE_COLOR_DARK_GRAY = 44, /* Stone */
101  E_BASE_COLOR_BLUE = 48, /* Water */
102  E_BASE_COLOR_DARK_BROWN = 52 /* Wood */
103  };
104 
105  typedef Byte ColorID;
106 
107  // tolua_end
108 
109  typedef std::vector<ColorID> cColorList;
110  typedef std::vector<cClientHandle *> cMapClientList;
111  typedef std::vector<cMapDecorator> cMapDecoratorList;
112 
114  cMap(unsigned int a_ID, cWorld * a_World);
115 
117  cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);
118 
121  void Tick();
122 
124  void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius);
125 
127  void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius);
128 
130  void UpdateClient(cPlayer * a_Player);
131 
132  // tolua_begin
133 
134  void Resize(unsigned int a_Width, unsigned int a_Height);
135 
136  void SetPosition(int a_CenterX, int a_CenterZ);
137 
138  void SetScale(unsigned int a_Scale) { m_Scale = a_Scale; }
139 
140  bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data);
141 
142  ColorID GetPixel(unsigned int a_X, unsigned int a_Z);
143 
144  unsigned int GetWidth (void) const { return m_Width; }
145  unsigned int GetHeight(void) const { return m_Height; }
146 
147  unsigned int GetScale(void) const { return m_Scale; }
148 
149  int GetCenterX(void) const { return m_CenterX; }
150  int GetCenterZ(void) const { return m_CenterZ; }
151 
152  unsigned int GetID(void) const { return m_ID; }
153 
154  cWorld * GetWorld(void) { return m_World; }
155 
156  AString GetName(void) { return m_Name; }
157 
158  eDimension GetDimension(void) const;
159 
160  unsigned int GetNumPixels(void) const;
161 
162  unsigned int GetPixelWidth(void) const;
163 
164  // tolua_end
165 
166  const cMapDecorator CreateDecorator(const cEntity * a_TrackedEntity);
167 
168  const cMapDecoratorList GetDecorators(void) const { return m_Decorators; }
169 
170  const cColorList & GetData(void) const { return m_Data; }
171 
172 private:
173 
175  bool UpdatePixel(unsigned int a_X, unsigned int a_Z);
176 
177  unsigned int m_ID;
178 
179  unsigned int m_Width;
180  unsigned int m_Height;
181 
183  unsigned int m_Scale;
184 
187 
190 
192 
194 
196 
198 
199  friend class cMapSerializer;
200 
201 }; // tolua_export
202 
203 
204 
eDimension
Dimension of a world.
Definition: Defines.h:231
unsigned char Byte
Definition: Globals.h:161
std::string AString
Definition: StringUtils.h:11
Definition: Entity.h:76
Definition: Player.h:29
Encapsulates a map decorator.
Definition: Map.h:35
int m_Rot
Definition: Map.h:71
@ E_TYPE_PLAYER_OUTSIDE
Player outside of the boundaries of the map.
int GetRot(void) const
Definition: Map.h:60
unsigned int GetPixelX(void) const
Definition: Map.h:57
unsigned int m_PixelX
Definition: Map.h:68
eType m_Type
Definition: Map.h:66
eType GetType(void) const
Definition: Map.h:62
cMapDecorator(eType a_Type, unsigned int a_X, unsigned int a_Z, int a_Rot)
Definition: Map.h:47
unsigned int m_PixelZ
Definition: Map.h:69
unsigned int GetPixelZ(void) const
Definition: Map.h:58
Encapsulates an in-game world map.
Definition: Map.h:83
unsigned int m_Height
Definition: Map.h:180
eDimension GetDimension(void) const
Definition: Map.cpp:185
const cMapDecoratorList GetDecorators(void) const
Definition: Map.h:168
unsigned int GetHeight(void) const
Definition: Map.h:145
cWorld * GetWorld(void)
Definition: Map.h:154
int m_CenterX
Definition: Map.h:185
void Tick()
Sends a map update to all registered clients Clears the list holding registered clients and decorator...
Definition: Map.cpp:53
int m_CenterZ
Definition: Map.h:186
const cColorList & GetData(void) const
Definition: Map.h:170
unsigned int m_Scale
The zoom level, 2^scale square blocks per pixel.
Definition: Map.h:183
cMapDecoratorList m_Decorators
Definition: Map.h:195
ColorID GetPixel(unsigned int a_X, unsigned int a_Z)
Definition: Map.cpp:240
std::vector< cClientHandle * > cMapClientList
Definition: Map.h:110
unsigned int GetWidth(void) const
Definition: Map.h:144
cWorld * m_World
Definition: Map.h:191
void SetScale(unsigned int a_Scale)
Definition: Map.h:138
AString m_Name
Definition: Map.h:197
void SetPosition(int a_CenterX, int a_CenterZ)
Definition: Map.cpp:212
void UpdateClient(cPlayer *a_Player)
Send next update packet to the specified player and remove invalid decorators / clients.
Definition: Map.cpp:174
unsigned int GetNumPixels(void) const
Definition: Map.cpp:256
cMapClientList m_ClientsInCurrentTick
Definition: Map.h:193
int GetCenterZ(void) const
Definition: Map.h:150
bool SetPixel(unsigned int a_X, unsigned int a_Z, ColorID a_Data)
Definition: Map.cpp:222
unsigned int GetScale(void) const
Definition: Map.h:147
std::vector< cMapDecorator > cMapDecoratorList
Definition: Map.h:111
Byte ColorID
Definition: Map.h:105
int GetCenterX(void) const
Definition: Map.h:149
void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius)
Update a circular region with the specified radius and center (in pixels).
Definition: Map.cpp:67
void Resize(unsigned int a_Width, unsigned int a_Height)
Definition: Map.cpp:195
std::vector< ColorID > cColorList
Definition: Map.h:109
eBaseColor
Definition: Map.h:87
@ E_BASE_COLOR_RED
Definition: Map.h:93
@ E_BASE_COLOR_LIGHT_BROWN
Definition: Map.h:91
@ E_BASE_COLOR_DARK_BROWN
Definition: Map.h:102
@ E_BASE_COLOR_BLUE
Definition: Map.h:101
@ E_BASE_COLOR_LIGHT_GRAY
Definition: Map.h:98
@ E_BASE_COLOR_WHITE
Definition: Map.h:97
@ E_BASE_COLOR_PALE_BLUE
Definition: Map.h:94
@ E_BASE_COLOR_DARK_GRAY
Definition: Map.h:100
@ E_BASE_COLOR_GRAY_1
Definition: Map.h:92
@ E_BASE_COLOR_LIGHT_BLUE
Definition: Map.h:90
@ E_BASE_COLOR_DARK_GREEN
Definition: Map.h:96
@ E_BASE_COLOR_GRAY_2
Definition: Map.h:95
@ E_BASE_COLOR_TRANSPARENT
Definition: Map.h:88
@ E_BASE_COLOR_BROWN
Definition: Map.h:99
@ E_BASE_COLOR_LIGHT_GREEN
Definition: Map.h:89
bool UpdatePixel(unsigned int a_X, unsigned int a_Z)
Update the specified pixel.
Definition: Map.cpp:110
const cMapDecorator CreateDecorator(const cEntity *a_TrackedEntity)
Definition: Map.cpp:265
unsigned int m_ID
Definition: Map.h:177
AString GetName(void)
Definition: Map.h:156
cMap(unsigned int a_ID, cWorld *a_World)
Construct an empty map.
Definition: Map.cpp:19
unsigned int GetID(void) const
Definition: Map.h:152
unsigned int m_Width
Definition: Map.h:179
cColorList m_Data
Column-major array of colours.
Definition: Map.h:189
unsigned int GetPixelWidth(void) const
Definition: Map.cpp:324
Definition: World.h:53
Utility class used to serialize maps.
Definition: MapSerializer.h:26