OregonCore  revision fb2a440-git
Your Favourite TBC server
MapManager.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore Project. See AUTHORS file for Copyright information
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation; either version 2 of the License, or (at your
7  * option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef OREGON_MAPMANAGER_H
19 #define OREGON_MAPMANAGER_H
20 
21 #include "Platform/Define.h"
22 #include "Policies/Singleton.h"
23 #include "ace/Thread_Mutex.h"
24 #include "Common.h"
25 #include "Map.h"
26 #include "GridStates.h"
27 #include "MapUpdater.h"
28 
29 class Transport;
30 
31 class MapManager : public Oregon::Singleton<MapManager, Oregon::ClassLevelLockable<MapManager, ACE_Thread_Mutex> >
32 {
33 
35  typedef UNORDERED_MAP<uint32, Map*> MapMapType;
36  typedef std::pair<UNORDERED_MAP<uint32, Map*>::iterator, bool> MapMapPair;
37 
38  public:
39 
40  Map* CreateMap(uint32 mapId, const WorldObject* obj, uint32 loginInstanceId = 0);
41  Map const* CreateBaseMap(uint32 id) const
42  {
43  return const_cast<MapManager*>(this)->_createBaseMap(id);
44  }
45  Map* FindMap(uint32 mapid, uint32 instanceId = 0) const;
46 
47  uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
48  {
49  Map const* m = CreateBaseMap(mapid);
50  return m->GetAreaFlag(x, y, z);
51  }
52  uint32 GetAreaId(uint32 mapid, float x, float y, float z)
53  {
54  return Map::GetAreaId(GetAreaFlag(mapid, x, y, z), mapid);
55  }
56  uint32 GetZoneId(uint32 mapid, float x, float y, float z)
57  {
58  return Map::GetZoneId(GetAreaFlag(mapid, x, y, z), mapid);
59  }
60 
61  void Initialize(void);
62  void Update(time_t);
63 
65  {
66  if (t < MIN_GRID_DELAY)
68  else
70  }
71 
73  {
74  if (t > MIN_MAP_UPDATE_DELAY)
76 
78  i_timer.Reset();
79  }
80 
81  //void LoadGrid(int mapid, float x, float y, const WorldObject* obj, bool no_unload = false);
82  void UnloadAll();
83 
84  static bool ExistMapAndVMap(uint32 mapid, float x, float y);
85  static bool IsValidMAP(uint32 mapid);
86 
87  static bool IsValidMapCoord(uint32 mapid, float x, float y)
88  {
89  return IsValidMAP(mapid) && Oregon::IsValidMapCoord(x, y);
90  }
91 
92  static bool IsValidMapCoord(uint32 mapid, float x, float y, float z)
93  {
94  return IsValidMAP(mapid) && Oregon::IsValidMapCoord(x, y, z);
95  }
96 
97  static bool IsValidMapCoord(uint32 mapid, float x, float y, float z, float o)
98  {
99  return IsValidMAP(mapid) && Oregon::IsValidMapCoord(x, y, z, o);
100  }
101 
102  static bool IsValidMapCoord(WorldLocation const& loc)
103  {
104  return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
105  }
106 
107  // modulos a radian orientation to the range of 0..2PI
108  static float NormalizeOrientation(float o)
109  {
110  // fmod only supports positive numbers. Thus we have
111  // to emulate negative numbers
112  if (o < 0)
113  {
114  float mod = o * -1;
115  mod = fmod(mod, 2.0f * static_cast<float>(M_PI));
116  mod = -mod + 2.0f * M_PI;
117  return mod;
118  }
119  return fmod(o, 2.0f * static_cast<float>(M_PI));
120  }
121 
123 
124  void LoadTransports();
125 
126  typedef std::set<Transport*> TransportSet;
127  TransportSet m_Transports;
128 
129  typedef std::map<uint32, TransportSet> TransportMap;
130  TransportMap m_TransportsByMap;
131 
132  Map::EnterState PlayerCannotEnter(uint32 mapid, Player* player, bool loginCheck = false);
134  {
135  return ++i_MaxInstanceId;
136  }
137  void InitMaxInstanceId();
139 
140  /* statistics */
143 
145 
146  private:
147  // debugging code, should be deleted some day
148  void checkAndCorrectGridStatesArray(); // just for debugging to find some memory overwrites
149  GridState* i_GridStates[MAX_GRID_STATE]; // shadow entries to the global array in Map.cpp
151  private:
152  MapManager();
153  ~MapManager();
154 
155  MapManager(const MapManager&);
157 
159  Map* _findMap(uint32 id) const
160  {
161  MapMapType::const_iterator iter = i_maps.find(id);
162  return (iter == i_maps.end() ? NULL : iter->second);
163  }
164 
167  MapMapType i_maps;
169 
172 };
173 #endif
174 
#define MIN_GRID_DELAY
Definition: GridDefines.h:40
static float NormalizeOrientation(float o)
Definition: MapManager.h:108
uint32 GetZoneId(uint32 mapid, float x, float y, float z)
Definition: MapManager.h:56
Map::EnterState PlayerCannotEnter(uint32 mapid, Player *player, bool loginCheck=false)
Definition: MapManager.cpp:153
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z, float o)
Definition: MapManager.h:97
uint32 i_MaxInstanceId
Definition: MapManager.h:170
GridState * i_GridStates[MAX_GRID_STATE]
Definition: MapManager.h:149
Map * _findMap(uint32 id) const
Definition: MapManager.h:159
bool IsValidMapCoord(float c)
Definition: GridDefines.h:192
uint32 GetNumPlayersInInstances()
Definition: MapManager.cpp:313
static bool ExistMapAndVMap(uint32 mapid, float x, float y)
Definition: MapManager.cpp:256
uint16 GetAreaFlag(uint32 mapid, float x, float y, float z) const
Definition: MapManager.h:47
uint32 i_gridCleanUpDelay
Definition: MapManager.h:166
static uint32 GetAreaId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1822
std::pair< UNORDERED_MAP< uint32, Map * >::iterator, bool > MapMapPair
Definition: MapManager.h:36
void SetInterval(time_t interval)
Definition: Timer.h:122
Map const * CreateBaseMap(uint32 id) const
Definition: MapManager.h:41
MapMapType i_maps
Definition: MapManager.h:167
void InitializeVisibilityDistanceInfo()
Definition: MapManager.cpp:72
static bool IsValidMapCoord(WorldLocation const &loc)
Definition: MapManager.h:102
MapUpdater m_updater
Definition: MapManager.h:171
float GetOrientation() const
Definition: Position.h:100
std::set< Transport * > TransportSet
Definition: MapManager.h:126
void Update(time_t)
Definition: MapManager.cpp:225
float GetPositionY() const
Definition: Position.h:98
uint32 GenerateInstanceId()
Definition: MapManager.h:133
float GetPositionZ() const
Definition: Position.h:99
static uint32 GetZoneId(uint16 areaflag, uint32 map_id)
Definition: Map.cpp:1832
#define MIN_MAP_UPDATE_DELAY
Definition: GridDefines.h:41
std::map< uint32, TransportSet > TransportMap
Definition: MapManager.h:129
TransportMap m_TransportsByMap
Definition: MapManager.h:130
uint32 GetMapId() const
Definition: Object.h:591
void UnloadAll()
Definition: MapManager.cpp:272
Definition: Map.h:266
Map * FindMap(uint32 mapid, uint32 instanceId=0) const
Definition: MapManager.cpp:137
void checkAndCorrectGridStatesArray()
Definition: MapManager.cpp:79
void LoadTransports()
Definition: Transports.cpp:26
void Reset()
Definition: Timer.h:113
Map * CreateMap(uint32 mapId, const WorldObject *obj, uint32 loginInstanceId=0)
Definition: MapManager.cpp:125
int i_GridStateErrorCount
Definition: MapManager.h:150
static bool IsValidMapCoord(uint32 mapid, float x, float y)
Definition: MapManager.h:87
Oregon::ClassLevelLockable< MapManager, ACE_Thread_Mutex >::Lock Guard
Definition: MapManager.h:165
void DoDelayedMovesAndRemoves()
Definition: MapManager.cpp:252
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z)
Definition: MapManager.h:92
uint32 GetNumInstances()
Definition: MapManager.cpp:296
void SetMapUpdateInterval(uint32 t)
Definition: MapManager.h:72
void Initialize(void)
Definition: MapManager.cpp:53
TransportSet m_Transports
Definition: MapManager.h:127
EnterState
Definition: Map.h:399
void SetGridCleanUpDelay(uint32 t)
Definition: MapManager.h:64
MapUpdater * GetMapUpdater()
Definition: MapManager.h:144
ACE_UINT16 uint16
Definition: Define.h:72
ACE_UINT32 uint32
Definition: Define.h:71
UNORDERED_MAP< uint32, Map * > MapMapType
Definition: MapManager.h:35
float GetPositionX() const
Definition: Position.h:97
Map * _createBaseMap(uint32 id)
Definition: MapManager.cpp:105
MapManager & operator=(const MapManager &)
uint32 GetAreaId(uint32 mapid, float x, float y, float z)
Definition: MapManager.h:52
Definition: Player.h:922
static bool IsValidMAP(uint32 mapid)
Definition: MapManager.cpp:266
void InitMaxInstanceId()
Definition: MapManager.cpp:287
IntervalTimer i_timer
Definition: MapManager.h:168
uint16 GetAreaFlag(float x, float y, float z, bool *isOutdoors=0) const
Definition: Map.cpp:1682