TrinityCore
Loading...
Searching...
No Matches
VMapManager.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore 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 TRINITYCORE_VMAP_MANAGER2_H
19#define TRINITYCORE_VMAP_MANAGER2_H
20
21#include "Define.h"
22#include "ModelIgnoreFlags.h"
23#include "Optional.h"
24#include <memory>
25#include <mutex>
26#include <span>
27#include <string>
28#include <unordered_map>
29#include <vector>
30
31//===========================================================
32
41//===========================================================
42
43namespace VMAP
44{
45 class ManagedModel;
46 class ModelInstance;
47 class StaticMapTree;
48 class WorldModel;
49
50 typedef std::unordered_map<uint32, std::unique_ptr<StaticMapTree>> InstanceTreeMap;
51 typedef std::unordered_map<std::string, std::weak_ptr<ManagedModel>> ModelFileMap;
52
60
69
70 #define VMAP_INVALID_HEIGHT -100000.0f // for check
71 #define VMAP_INVALID_HEIGHT_VALUE -200000.0f // real assigned value in unknown height case
72
74 {
75 struct AreaInfo
76 {
77 AreaInfo() = default;
78 AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
79 : groupId(_groupId), adtId(_adtId), rootId(_rootId), mogpFlags(_mogpFlags), uniqueId(_uniqueId) { }
85 };
87 {
88 LiquidInfo() = default;
89 LiquidInfo(uint32 _type, float _level) : type(_type), level(_level) { }
91 float level = 0.0f;
92 };
93
97 };
98
100 {
101 protected:
105 // Tree to check collision
108 std::unordered_map<uint32, uint32> iParentMapData;
109 // Mutex for iLoadedModelFiles
111
112 InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
113
114 public:
115 // public for debug
116 static std::string getMapFileName(uint32 mapId);
117 static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY, std::string_view extension);
118
119 VMapManager();
120
121 VMapManager(VMapManager const&) = delete;
123
126
128
129 void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
130 void InitializeThreadUnsafe(uint32 mapId, int32 parentMapId);
135 void setEnableLineOfSightCalc(bool enableLineOfSightCalc) { iEnableLineOfSightCalc = enableLineOfSightCalc; }
136
141 void setEnableHeightCalc(bool enableHeightCalc) { iEnableHeightCalc = enableHeightCalc; }
142
143 bool isLineOfSightCalcEnabled() const { return iEnableLineOfSightCalc; }
144 bool isHeightCalcEnabled() const { return iEnableHeightCalc; }
145 bool isMapLoadingEnabled() const { return iEnableLineOfSightCalc || iEnableHeightCalc; }
146
147 LoadResult loadMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
148
149 void unloadMap(uint32 mapId, uint32 x, uint32 y);
150
151 void unloadMap(uint32 mapId);
152
153 bool isInLineOfSight(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, ModelIgnoreFlags ignoreFlags);
158 bool getObjectHitPos(uint32 mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist);
159 float getHeight(uint32 mapId, float x, float y, float z, float maxSearchDist);
160
164 bool getAreaAndLiquidData(uint32 mapId, float x, float y, float z, Optional<uint8> reqLiquidType, AreaAndLiquidData& data) const;
165
166 std::shared_ptr<WorldModel> acquireModelInstance(std::string const& basepath, std::string const& filename);
167 void releaseModelInstance(std::string const& filename);
168
169 // what's the use of this? o.O
170 static std::string getDirFileName(uint32 mapId, uint32 x, uint32 y)
171 {
172 return getTileFileName(mapId, x, y, "vmtile");
173 }
174 LoadResult existsMap(std::string const& basePath, uint32 mapId, uint32 x, uint32 y);
175
176 std::span<ModelInstance const> getModelsOnMap(uint32 mapId) const;
177
178 int32 getParentMapId(uint32 mapId) const;
179
180 typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
181 GetLiquidFlagsFn GetLiquidFlagsPtr;
182
183 typedef bool(*IsVMAPDisabledForFn)(uint32 entry, uint8 flags);
184 IsVMAPDisabledForFn IsVMAPDisabledForPtr;
185
187 };
188}
189
190#endif // TRINITYCORE_VMAP_MANAGER2_H
uint8_t uint8
Definition Define.h:156
#define TC_COMMON_API
Definition Define.h:99
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
uint16 flags
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
#define VMAP_INVALID_HEIGHT
Definition VMapManager.h:70
static std::string getDirFileName(uint32 mapId, uint32 x, uint32 y)
bool isLineOfSightCalcEnabled() const
VMapManager(VMapManager &&)=delete
bool isHeightCalcEnabled() const
VMapManager & operator=(VMapManager &&)=delete
bool isMapLoadingEnabled() const
ModelFileMap iLoadedModelFiles
void setEnableLineOfSightCalc(bool enableLineOfSightCalc)
void setEnableHeightCalc(bool enableHeightCalc)
VMapManager(VMapManager const &)=delete
std::unordered_map< uint32, uint32 > iParentMapData
std::mutex LoadedModelFilesLock
VMapManager & operator=(VMapManager const &)=delete
GetLiquidFlagsFn GetLiquidFlagsPtr
InstanceTreeMap iInstanceMapTrees
IsVMAPDisabledForFn IsVMAPDisabledForPtr
std::unordered_map< uint32, std::unique_ptr< StaticMapTree > > InstanceTreeMap
Definition VMapManager.h:50
std::unordered_map< std::string, std::weak_ptr< ManagedModel > > ModelFileMap
Definition VMapManager.h:51
DisableTypes
Definition VMapManager.h:54
@ VMAP_DISABLE_LIQUIDSTATUS
Definition VMapManager.h:58
@ VMAP_DISABLE_LOS
Definition VMapManager.h:57
@ VMAP_DISABLE_HEIGHT
Definition VMapManager.h:56
@ VMAP_DISABLE_AREAFLAG
Definition VMapManager.h:55
AreaInfo(int32 _groupId, int32 _adtId, int32 _rootId, uint32 _mogpFlags, uint32 _uniqueId)
Definition VMapManager.h:78
LiquidInfo(uint32 _type, float _level)
Definition VMapManager.h:89
Optional< AreaInfo > areaInfo
Definition VMapManager.h:95
Optional< LiquidInfo > liquidInfo
Definition VMapManager.h:96