From f201f4f176fc908e9ddebfed86d4c8ef5582556c Mon Sep 17 00:00:00 2001 From: andrew Date: Thu, 20 Feb 2014 16:38:37 +0200 Subject: Thread safe cMap manager --- src/MapManager.h | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/MapManager.h (limited to 'src/MapManager.h') diff --git a/src/MapManager.h b/src/MapManager.h new file mode 100644 index 000000000..05673c694 --- /dev/null +++ b/src/MapManager.h @@ -0,0 +1,76 @@ + +// MapManager.h + + + + + +#pragma once + + + + + +#include "Map.h" + + + + +typedef cItemCallback cMapCallback; + + + + + +/** Manages the in-game maps of a single world - Thread safe. */ +class cMapManager +{ +public: + + cMapManager(cWorld * a_World); + + /** Returns the map with the specified ID, NULL if out of range. + * + * WARNING: The returned map object is not thread safe. + */ + cMap * GetMapData(unsigned int a_ID); + + /** Creates a new map. Returns NULL on error */ + cMap * CreateMap(int a_CenterX, int a_CenterY, int a_Scale = 3); + + /** Calls the callback for the map with the specified ID. + * + * Returns true if the map was found and the callback called, false if map not found. + * Callback return ignored. + */ + bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); + + /** Calls the callback for each map. + * + * Returns true if all maps processed, false if the callback aborted by returning true. + */ + bool ForEachMap(cMapCallback & a_Callback); + + unsigned int GetNumMaps(void) const; + + /** Loads the map data from the disk */ + void LoadMapData(void); + + /** Saves the map data to the disk */ + void SaveMapData(void); + + +private: + + typedef std::vector cMapList; + + cCriticalSection m_CS; + + cMapList m_MapData; + + cWorld * m_World; + +}; + + + -- cgit v1.2.3 From 9fa4fa1cc737a0cf9a078956def206c31a4ebd02 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 12:55:55 +0200 Subject: Documented and exported cMapManager --- src/MapManager.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/MapManager.h') diff --git a/src/MapManager.h b/src/MapManager.h index 05673c694..5da8be035 100644 --- a/src/MapManager.h +++ b/src/MapManager.h @@ -21,11 +21,13 @@ typedef cItemCallback cMapCallback; +// tolua_begin /** Manages the in-game maps of a single world - Thread safe. */ class cMapManager { public: + // tolua_end cMapManager(cWorld * a_World); @@ -43,7 +45,7 @@ public: * Returns true if the map was found and the callback called, false if map not found. * Callback return ignored. */ - bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); + bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); // tolua_export /** Calls the callback for each map. * @@ -51,7 +53,7 @@ public: */ bool ForEachMap(cMapCallback & a_Callback); - unsigned int GetNumMaps(void) const; + unsigned int GetNumMaps(void) const; // tolua_export /** Loads the map data from the disk */ void LoadMapData(void); @@ -70,7 +72,7 @@ private: cWorld * m_World; -}; +}; // tolua_export -- cgit v1.2.3 From 30b22e9f59e0873be84e80c83d274dbe5353b835 Mon Sep 17 00:00:00 2001 From: andrew Date: Sun, 23 Feb 2014 13:25:02 +0200 Subject: Manually exported DoWithMap --- src/MapManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/MapManager.h') diff --git a/src/MapManager.h b/src/MapManager.h index 5da8be035..80e6d16d1 100644 --- a/src/MapManager.h +++ b/src/MapManager.h @@ -45,7 +45,7 @@ public: * Returns true if the map was found and the callback called, false if map not found. * Callback return ignored. */ - bool DoWithMap(unsigned int a_ID, cMapCallback & a_Callback); // tolua_export + bool DoWithMap(int a_ID, cMapCallback & a_Callback); // Exported in ManualBindings.cpp /** Calls the callback for each map. * -- cgit v1.2.3