diff options
author | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-10-17 15:51:44 -0700 |
commit | e585187b248f48b3c6e9247b49fa07c6565d65e5 (patch) | |
tree | 637c5b7ddacf41040bef4ea4f75a97da64c6a9bc /src/game/InstanceSaveMgr.h | |
parent | 26b5e033ffde3d161382fc9addbfa99738379641 (diff) |
*Backed out changeset 3be01fb200a5
--HG--
branch : trunk
Diffstat (limited to 'src/game/InstanceSaveMgr.h')
-rw-r--r-- | src/game/InstanceSaveMgr.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/game/InstanceSaveMgr.h b/src/game/InstanceSaveMgr.h index 39e12f1e8b3..29972210f3d 100644 --- a/src/game/InstanceSaveMgr.h +++ b/src/game/InstanceSaveMgr.h @@ -18,8 +18,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + #ifndef __InstanceSaveMgr_H #define __InstanceSaveMgr_H + #include "Platform/Define.h" #include "Policies/Singleton.h" #include "ace/Thread_Mutex.h" @@ -27,10 +29,12 @@ #include <map> #include "Utilities/UnorderedMap.h" #include "Database/DatabaseEnv.h" + struct InstanceTemplate; struct MapEntry; class Player; class Group; + /* Holds the information necessary for creating a new map for an existing instance Is referenced in three cases: @@ -47,27 +51,34 @@ class InstanceSave - the first time a player bound to InstanceId logs in - when a group bound to the instance is loaded */ InstanceSave(uint16 MapId, uint32 InstanceId, uint8 difficulty, time_t resetTime, bool canReset); + /* Unloaded when m_playerList and m_groupList become empty or when the instance is reset */ ~InstanceSave(); + uint8 GetPlayerCount() { return m_playerList.size(); } uint8 GetGroupCount() { return m_groupList.size(); } + /* A map corresponding to the InstanceId/MapId does not always exist. InstanceSave objects may be created on player logon but the maps are created and loaded only when a player actually enters the instance. */ uint32 GetInstanceId() { return m_instanceid; } uint32 GetMapId() { return m_mapid; } + /* Saved when the instance is generated for the first time */ void SaveToDB(); /* When the instance is being reset (permanently deleted) */ void DeleteFromDB(); + /* for normal instances this corresponds to max(creature respawn time) + X hours for raid/heroic instances this caches the global respawn time for the map */ time_t GetResetTime() { return m_resetTime; } void SetResetTime(time_t resetTime) { m_resetTime = resetTime; } time_t GetResetTimeForDB(); + InstanceTemplate const* GetTemplate(); MapEntry const* GetMapEntry(); + /* online players bound to the instance (perm/solo) does not include the members of the group unless they have permanent saves */ void AddPlayer(Player *player) { m_playerList.push_back(player); } @@ -75,14 +86,17 @@ class InstanceSave /* all groups bound to the instance */ void AddGroup(Group *group) { m_groupList.push_back(group); } bool RemoveGroup(Group *group) { m_groupList.remove(group); return UnloadIfEmpty(); } + /* instances cannot be reset (except at the global reset time) if there are players permanently bound to it this is cached for the case when those players are offline */ bool CanReset() { return m_canReset; } void SetCanReset(bool canReset) { m_canReset = canReset; } + /* currently it is possible to omit this information from this structure but that would depend on a lot of things that can easily change in future */ uint8 GetDifficulty() { return m_difficulty; } + typedef std::list<Player*> PlayerListType; typedef std::list<Group*> GroupListType; private: @@ -98,15 +112,18 @@ class InstanceSave uint8 m_difficulty; bool m_canReset; }; + class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton<InstanceSaveManager, MaNGOS::ClassLevelLockable<InstanceSaveManager, ACE_Thread_Mutex> > { friend class InstanceSave; public: InstanceSaveManager(); ~InstanceSaveManager(); + typedef std::map<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveMap; typedef UNORDERED_MAP<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveHashMap; typedef std::map<uint32 /*mapId*/, InstanceSaveMap> InstanceSaveMapMap; + /* resetTime is a global propery of each (raid/heroic) map all instances of that map reset at the same time */ struct InstResetEvent @@ -119,20 +136,27 @@ class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton<InstanceSav }; typedef std::multimap<time_t /*resetTime*/, InstResetEvent> ResetTimeQueue; typedef std::vector<time_t /*resetTime*/> ResetTimeVector; + void CleanupInstances(); void PackInstances(); + void LoadResetTimes(); time_t GetResetTimeFor(uint32 mapid) { return m_resetTimeByMapId[mapid]; } void ScheduleReset(bool add, time_t time, InstResetEvent event); + void Update(); + InstanceSave* AddInstanceSave(uint32 mapId, uint32 instanceId, uint8 difficulty, time_t resetTime, bool canReset, bool load = false); void RemoveInstanceSave(uint32 InstanceId); static void DeleteInstanceFromDB(uint32 instanceid); + InstanceSave *GetInstanceSave(uint32 InstanceId); + /* statistics */ uint32 GetNumInstanceSaves() { return m_instanceSaveById.size(); } uint32 GetNumBoundPlayersTotal(); uint32 GetNumBoundGroupsTotal(); + private: void _ResetOrWarnAll(uint32 mapid, bool warn, uint32 timeleft); void _ResetInstance(uint32 mapid, uint32 instanceId); @@ -146,6 +170,7 @@ class MANGOS_DLL_DECL InstanceSaveManager : public MaNGOS::Singleton<InstanceSav ResetTimeVector m_resetTimeByMapId; ResetTimeQueue m_resetTimeQueue; }; + #define sInstanceSaveManager Trinity::Singleton<InstanceSaveManager>::Instance() #endif |