Created
April 3, 2010 22:07
-
-
Save SkirnirMaNGOS/354890 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/> | |
* | |
* This program is free software; you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation; either version 2 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program; if not, write to the Free Software | |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
*/ | |
#ifndef MANGOS_MAPMANAGER_H | |
#define MANGOS_MAPMANAGER_H | |
#include "Platform/Define.h" | |
#include "Policies/Singleton.h" | |
#include "ace/Thread_Mutex.h" | |
#include "Common.h" | |
#include "Map.h" | |
#include "GridStates.h" | |
class Transport; | |
class BattleGround; | |
class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::ClassLevelLockable<MapManager, ACE_Recursive_Thread_Mutex> > | |
friend class MaNGOS::OperatorNew<MapManager>; | |
public: // Public type definitions. | |
typedef UNORDERED_MAP<uint32, Map*> MapMapType; | |
typedef std::set<Transport*> TransportSet; | |
typedef std::map<uint32, TransportSet> TransportMap; | |
private: // Private type definitions. | |
typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair; | |
typedef MaNGOS::ClassLevelLockable<MapManager, ACE_Thread_Mutex>::Lock Guard; | |
public: // Primary map management. | |
Map* CreateMap(uint32, const WorldObject* obj); | |
Map* CreateContinentMap(uint32 mapid); | |
InstanceMap* CreateInstanceMap(uint32 mapId, Player* pl); | |
BattleGroundMap* CreateBattleGroundMap(uint32 mapid, BattleGround* bg); | |
Map* FindMap(uint32 mapid, uint32 instanceId = 0); | |
Map* FindContinentMap(uint32 mapid); | |
InstanceMap* FindInstanceMap(uint32 instanceId, uint32 mapid = 0); | |
MapMapType const& GetAllContinents() const { return i_maps; } | |
MapMapType const& GetAllInstances() const { return i_instancedMaps; } | |
public: // Initialization and updating. | |
void Initialize(); | |
void Update(uint32 diff); | |
public: // Transport handling. | |
void LoadTransports(); | |
TransportSet& GetTransports() { return m_Transports; } | |
TransportMap& GetTransportsByMap() { return m_TransportsByMap; } | |
public: // Map/grid configuration. | |
void SetGridCleanUpDelay(uint32 t); | |
void SetMapUpdateInterval(uint32 t); | |
void InitializeVisibilityDistanceInfo(); | |
public: // Miscellaneous functionality. | |
static bool CanEnterMap(uint32 mapid); | |
bool CanPlayerEnter(uint32 mapid, Player* player); | |
public: // Unloading and removal. | |
void UnloadAll(); | |
void RemoveAllObjectsInRemoveList(); | |
public: // Map/coordinate validity checks. | |
static bool IsValidMapCoordinate(uint32 mapid, float x, float y); | |
static bool IsValidMapCoordinate(uint32 mapid, float x, float y, float z); | |
static bool IsValidMapCoordinate(uint32 mapid, float x, float y, float z, float o); | |
static bool IsValidMapCoordinate(WorldLocation const& loc); | |
public: // Instance ID management. | |
uint32 GenerateInstanceId() { return ++i_MaxInstanceId; } | |
void InitMaxInstanceId(); | |
public: // Statistics and information. | |
uint32 GetNumContinents(); | |
uint32 GetNumPlayersInContinents(); | |
uint32 GetNumInstances(); | |
uint32 GetNumPlayersInInstances(); | |
private: // Internal grid state maintenance. | |
void _checkAndCorrectGridStatesArray(); | |
void _createStateMachine(); | |
void _deleteStateMachine(); | |
GridState* i_GridStates[MAX_GRID_STATE]; | |
int i_GridStateErrorCount; | |
private: // Internal map operations. | |
InstanceMap* _createInstanceMap(uint32 mapid, uint32 instanceId, InstanceSave* save, Difficulty difficulty); | |
void _deleteInstance(MapMapType::iterator& iter); | |
private: // Private fields. | |
uint32 i_gridCleanUpDelay; | |
MapMapType i_maps; // <mapid, map object> | |
MapMapType i_instancedMaps; // <instanceid, map object> | |
TransportSet m_Transports; | |
TransportMap m_TransportsByMap; | |
IntervalTimer i_timer; | |
uint32 i_MaxInstanceId; | |
private: // Construction/destruction and assignment. | |
MapManager(); | |
~MapManager(); | |
MapManager(const MapManager &); | |
MapManager& operator=(const MapManager &); | |
}; | |
#define sMapMgr MapManager::Instance() | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment