1
0
Fork 0

Documented cMap

This commit is contained in:
andrew 2014-02-19 15:28:48 +02:00
parent 393ca0221d
commit 4a1ac57408
3 changed files with 31 additions and 7 deletions

View File

@ -14,7 +14,7 @@
cMapDecorator::cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot)
cMapDecorator::cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, int a_Rot)
: m_Map(a_Map)
, m_Type(a_Type)
, m_PixelX(a_X)
@ -58,7 +58,7 @@ void cMapDecorator::Update(void)
int InsideWidth = (m_Map->GetWidth() / 2) - 1;
int InsideHeight = (m_Map->GetHeight() / 2) - 1;
if (m_Player)
if (m_Player != NULL)
{
int PixelX = (m_Player->GetPosX() - m_Map->GetCenterX()) / PixelWidth;
int PixelZ = (m_Player->GetPosZ() - m_Map->GetCenterZ()) / PixelWidth;
@ -200,7 +200,8 @@ void cMap::UpdateRadius(cPlayer & a_Player, unsigned int a_Radius)
bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
{
/*unsigned int PixelWidth = GetPixelWidth();
/*
unsigned int PixelWidth = GetPixelWidth();
int BlockX = m_CenterX + ((a_X - m_Width) * PixelWidth);
int BlockZ = m_CenterZ + ((a_Y - m_Height) * PixelWidth);
@ -258,7 +259,8 @@ bool cMap::UpdatePixel(unsigned int a_X, unsigned int a_Z)
} CalculatePixelCb(this, RelX, RelZ);
ASSERT(m_World != NULL);
m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);*/
m_World->DoWithChunk(ChunkX, ChunkZ, CalculatePixelCb);
*/
m_Data[a_Z + (a_X * m_Height)] = 4;
@ -346,6 +348,8 @@ void cMap::UpdateClient(cPlayer * a_Player)
if (it->m_NextDecoratorUpdate >= 4)
{
// TODO 2014-02-19 xdot
// This is dangerous as the player object may have been destroyed before the decorator is erased from the list
UpdateDecorators();
Handle->SendMapDecorators(m_ID, m_Decorators);

View File

@ -28,28 +28,36 @@ class cMap;
/** Encapsulates a map decorator. */
class cMapDecorator
{
public:
enum eType
{
E_TYPE_PLAYER = 0x00,
E_TYPE_ITEM_FRAME = 0x01,
/** Player outside of the boundaries of the map. */
E_TYPE_PLAYER_OUTSIDE = 0x06
};
public:
cMapDecorator(cMap * a_Map, eType a_Type, int a_X, int a_Z, unsigned int a_Rot);
/** 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);
/** Constructs a map decorator that tracks a player. */
cMapDecorator(cMap * a_Map, cPlayer * a_Player);
/** Updates the pixel coordinates of the decorator. */
void Update(void);
unsigned int GetPixelX(void) const { return m_PixelX; }
unsigned int GetPixelZ(void) const { return m_PixelZ; }
unsigned int GetRot(void) const { return m_Rot; }
int GetRot(void) const { return m_Rot; }
eType GetType(void) const { return m_Type; }
@ -68,6 +76,7 @@ protected:
unsigned int m_Rot;
cPlayer * m_Player;
};
typedef std::list<cMapDecorator> cMapDecoratorList;
@ -77,6 +86,8 @@ typedef std::list<cMapDecorator> cMapDecoratorList;
// tolua_begin
/** Encapsulates an in-game world map. */
class cMap
{
public:
@ -87,15 +98,20 @@ public:
typedef std::vector<ColorID> cColorList;
/** Encapsulates the state of a map client. */
struct cMapClient
{
cClientHandle * m_Handle;
/** Whether the map scale was modified and needs to be resent. */
bool m_SendInfo;
/** Ticks since last decorator update. */
unsigned int m_NextDecoratorUpdate;
/** Number of pixel data updates. */
Int64 m_DataUpdate;
Int64 m_LastUpdate;
};
@ -107,14 +123,16 @@ public:
/** Construct an empty map. */
cMap(unsigned int a_ID, cWorld * a_World);
/** Constructs an empty map at the specified coordinates. */
cMap(unsigned int a_ID, int a_CenterX, int a_CenterZ, cWorld * a_World, unsigned int a_Scale = 3);
/** Send this map to the specified client. */
/** Send this map to the specified client. WARNING: Slow */
void SendTo(cClientHandle & a_Client);
/** Update a circular region with the specified radius and center (in pixels). */
void UpdateRadius(int a_PixelX, int a_PixelZ, unsigned int a_Radius);
/** Update a circular region around the specified player. */
void UpdateRadius(cPlayer & a_Player, unsigned int a_Radius);
/** Send next update packet and remove invalid decorators */

View File

@ -21,6 +21,7 @@ class cMap;
/** Utility class used to serialize maps. */
class cMapSerializer
{
public:
@ -50,6 +51,7 @@ private:
/** Utility class used to serialize item ID counts. */
class cIDCountSerializer
{
public: