1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
/*
* This file is part of the AzerothCore Project. See AUTHORS file for Copyright information
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef ACORE_MAPMANAGER_H
#define ACORE_MAPMANAGER_H
#include "Common.h"
#include "Define.h"
#include "Map.h"
#include "MapInstanced.h"
#include "MapUpdater.h"
#include "Object.h"
#include "Timer.h"
class Transport;
class StaticTransport;
class MotionTransport;
struct TransportCreatureProto;
class MapMgr
{
public:
static MapMgr* instance();
Map* CreateBaseMap(uint32 mapId);
Map* FindBaseNonInstanceMap(uint32 mapId) const;
Map* CreateMap(uint32 mapId, Player* player);
Map* FindMap(uint32 mapId, uint32 instanceId) const;
Map* FindBaseMap(uint32 mapId) const // pussywizard: need this public for movemaps (mmaps)
{
MapMapType::const_iterator iter = i_maps.find(mapId);
return (iter == i_maps.end() ? nullptr : iter->second);
}
[[nodiscard]] uint32 GetAreaId(uint32 phaseMask, uint32 mapid, float x, float y, float z) const
{
Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
return m->GetAreaId(phaseMask, x, y, z);
}
[[nodiscard]] uint32 GetAreaId(uint32 phaseMask, uint32 mapid, Position const& pos) const { return GetAreaId(phaseMask, mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); }
[[nodiscard]] uint32 GetAreaId(uint32 phaseMask, WorldLocation const& loc) const { return GetAreaId(phaseMask, loc.GetMapId(), loc); }
[[nodiscard]] uint32 GetZoneId(uint32 phaseMask, uint32 mapid, float x, float y, float z) const
{
Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
return m->GetZoneId(phaseMask, x, y, z);
}
[[nodiscard]] uint32 GetZoneId(uint32 phaseMask, uint32 mapid, Position const& pos) const { return GetZoneId(phaseMask, mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ()); }
[[nodiscard]] uint32 GetZoneId(uint32 phaseMask, WorldLocation const& loc) const { return GetZoneId(phaseMask, loc.GetMapId(), loc); }
void GetZoneAndAreaId(uint32 phaseMask, uint32& zoneid, uint32& areaid, uint32 mapid, float x, float y, float z)
{
Map const* m = const_cast<MapMgr*>(this)->CreateBaseMap(mapid);
m->GetZoneAndAreaId(phaseMask, zoneid, areaid, x, y, z);
}
void Initialize(void);
void Update(uint32);
void SetMapUpdateInterval(uint32 t)
{
if (t < MIN_MAP_UPDATE_DELAY)
t = MIN_MAP_UPDATE_DELAY;
i_timer[3].SetInterval(t);
i_timer[3].Reset();
}
//void LoadGrid(int mapid, int instId, float x, float y, WorldObject const* obj, bool no_unload = false);
void UnloadAll();
static bool ExistMapAndVMap(uint32 mapid, float x, float y);
static bool IsValidMAP(uint32 mapid, bool startUp);
static bool IsValidMapCoord(uint32 mapid, Position const& pos)
{
return IsValidMapCoord(mapid, pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation());
}
static bool IsValidMapCoord(uint32 mapid, float x, float y)
{
return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y);
}
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z)
{
return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y, z);
}
static bool IsValidMapCoord(uint32 mapid, float x, float y, float z, float o)
{
return IsValidMAP(mapid, false) && Acore::IsValidMapCoord(x, y, z, o);
}
static bool IsValidMapCoord(WorldLocation const& loc)
{
return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation());
}
// modulos a radian orientation to the range of 0..2PI
static float NormalizeOrientation(float o)
{
// fmod only supports positive numbers. Thus we have
// to emulate negative numbers
if (o < 0)
{
float mod = o * -1;
mod = std::fmod(mod, 2.0f * static_cast<float>(M_PI));
mod = -mod + 2.0f * static_cast<float>(M_PI);
return mod;
}
return std::fmod(o, 2.0f * static_cast<float>(M_PI));
}
/**
* @name GetInstanceIDs
* @return vector of instance IDs
*/
std::vector<bool> GetInstanceIDs()
{
return _instanceIds;
}
void DoDelayedMovesAndRemoves();
Map::EnterState PlayerCannotEnter(uint32 mapid, Player* player, bool loginCheck = false);
void InitializeVisibilityDistanceInfo();
/* statistics */
void GetNumInstances(uint32& dungeons, uint32& battlegrounds, uint32& arenas);
void GetNumPlayersInInstances(uint32& dungeons, uint32& battlegrounds, uint32& arenas, uint32& spectators);
// Instance ID management
void InitInstanceIds();
void RegisterInstanceId(uint32 instanceId);
uint32 GenerateInstanceId();
MapUpdater* GetMapUpdater() { return &m_updater; }
template<typename Worker>
void DoForAllMaps(Worker&& worker);
template<typename Worker>
void DoForAllMapsWithMapId(uint32 mapId, Worker&& worker);
private:
typedef std::unordered_map<uint32, Map*> MapMapType;
typedef std::vector<bool> InstanceIds;
MapMgr();
~MapMgr();
MapMgr(const MapMgr&);
MapMgr& operator=(const MapMgr&);
std::mutex Lock;
MapMapType i_maps;
IntervalTimer i_timer[4]; // continents, bgs/arenas, instances, total from the beginning
uint8 mapUpdateStep;
InstanceIds _instanceIds;
uint32 _nextInstanceId;
MapUpdater m_updater;
};
template<typename Worker>
void MapMgr::DoForAllMaps(Worker&& worker)
{
std::lock_guard<std::mutex> guard(Lock);
for (auto& mapPair : i_maps)
{
Map* map = mapPair.second;
if (MapInstanced* mapInstanced = map->ToMapInstanced())
{
MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
for (auto& instancePair : instances)
worker(instancePair.second);
}
else
worker(map);
}
}
template<typename Worker>
inline void MapMgr::DoForAllMapsWithMapId(uint32 mapId, Worker&& worker)
{
std::lock_guard<std::mutex> guard(Lock);
auto itr = i_maps.find(mapId);
if (itr != i_maps.end())
{
Map* map = itr->second;
if (MapInstanced* mapInstanced = map->ToMapInstanced())
{
MapInstanced::InstancedMaps& instances = mapInstanced->GetInstancedMaps();
for (auto& p : instances)
worker(p.second);
}
else
worker(map);
}
}
#define sMapMgr MapMgr::instance()
#endif
|