diff options
-rw-r--r-- | src/Map.cpp | 12 | ||||
-rw-r--r-- | src/Map.h | 24 | ||||
-rw-r--r-- | src/WorldStorage/MapSerializer.h | 2 |
3 files changed, 31 insertions, 7 deletions
diff --git a/src/Map.cpp b/src/Map.cpp index f32d232fa..4f8924af2 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -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); @@ -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 */ diff --git a/src/WorldStorage/MapSerializer.h b/src/WorldStorage/MapSerializer.h index 296cc92c8..85fe917f5 100644 --- a/src/WorldStorage/MapSerializer.h +++ b/src/WorldStorage/MapSerializer.h @@ -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: |