TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
VMapManager2.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2010 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _VMAPMANAGER2_H
20 #define _VMAPMANAGER2_H
21 
22 #include <mutex>
23 #include <unordered_map>
24 #include <vector>
25 #include "Define.h"
26 #include "IVMapManager.h"
27 
28 //===========================================================
29 
30 #define MAP_FILENAME_EXTENSION2 ".vmtree"
31 
32 #define FILENAMEBUFFER_SIZE 500
33 
42 //===========================================================
43 
44 namespace G3D
45 {
46  class Vector3;
47 }
48 
49 namespace VMAP
50 {
51  class StaticMapTree;
52  class WorldModel;
53 
55  {
56  public:
57  ManagedModel() : iModel(nullptr), iRefCount(0) { }
58  void setModel(WorldModel* model) { iModel = model; }
59  WorldModel* getModel() { return iModel; }
60  void incRefCount() { ++iRefCount; }
61  int decRefCount() { return --iRefCount; }
62  protected:
64  int iRefCount;
65  };
66 
67  typedef std::unordered_map<uint32, StaticMapTree*> InstanceTreeMap;
68  typedef std::unordered_map<std::string, ManagedModel> ModelFileMap;
69 
71  {
76  };
77 
79  {
80  protected:
81  // Tree to check collision
82  ModelFileMap iLoadedModelFiles;
83  InstanceTreeMap iInstanceMapTrees;
85  // Mutex for iLoadedModelFiles
87 
88  bool _loadMap(uint32 mapId, const std::string& basePath, uint32 tileX, uint32 tileY);
89  /* void _unloadMap(uint32 pMapId, uint32 x, uint32 y); */
90 
91  static uint32 GetLiquidFlagsDummy(uint32) { return 0; }
92  static bool IsVMAPDisabledForDummy(uint32 /*entry*/, uint8 /*flags*/) { return false; }
93 
94  InstanceTreeMap::const_iterator GetMapTree(uint32 mapId) const;
95 
96  public:
97  // public for debug
98  G3D::Vector3 convertPositionToInternalRep(float x, float y, float z) const;
99  static std::string getMapFileName(unsigned int mapId);
100 
101  VMapManager2();
102  ~VMapManager2(void);
103 
104  void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
105  int loadMap(const char* pBasePath, unsigned int mapId, int x, int y) override;
106 
107  void unloadMap(unsigned int mapId, int x, int y) override;
108  void unloadMap(unsigned int mapId) override;
109 
110  bool isInLineOfSight(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2) override ;
114  bool getObjectHitPos(unsigned int mapId, float x1, float y1, float z1, float x2, float y2, float z2, float& rx, float& ry, float& rz, float modifyDist) override;
115  float getHeight(unsigned int mapId, float x, float y, float z, float maxSearchDist) override;
116 
117  bool processCommand(char* /*command*/) override { return false; } // for debug and extensions
118 
119  bool getAreaInfo(unsigned int pMapId, float x, float y, float& z, uint32& flags, int32& adtId, int32& rootId, int32& groupId) const override;
120  bool GetLiquidLevel(uint32 pMapId, float x, float y, float z, uint8 reqLiquidType, float& level, float& floor, uint32& type) const override;
121 
122  WorldModel* acquireModelInstance(const std::string& basepath, const std::string& filename);
123  void releaseModelInstance(const std::string& filename);
124 
125  // what's the use of this? o.O
126  virtual std::string getDirFileName(unsigned int mapId, int /*x*/, int /*y*/) const override
127  {
128  return getMapFileName(mapId);
129  }
130  virtual bool existsMap(const char* basePath, unsigned int mapId, int x, int y) override;
131 
132  void getInstanceMapTree(InstanceTreeMap &instanceMapTree);
133 
134  typedef uint32(*GetLiquidFlagsFn)(uint32 liquidType);
135  GetLiquidFlagsFn GetLiquidFlagsPtr;
136 
137  typedef bool(*IsVMAPDisabledForFn)(uint32 entry, uint8 flags);
138  IsVMAPDisabledForFn IsVMAPDisabledForPtr;
139  };
140 }
141 
142 #endif
Definition: VMapManager2.h:73
Definition: VMapManager2.h:78
virtual std::string getDirFileName(unsigned int mapId, int, int) const override
Definition: VMapManager2.h:126
static Vector3int16 floor(const Vector3 &v)
Definition: VMapManager2.h:75
std::unordered_map< uint32, StaticMapTree * > InstanceTreeMap
Definition: VMapManager2.h:67
Definition: AABox.h:25
Definition: VMapManager2.h:54
WorldModel * iModel
Definition: VMapManager2.h:63
Definition: IVMapManager.h:31
std::mutex LoadedModelFilesLock
Definition: VMapManager2.h:86
bool thread_safe_environment
Definition: VMapManager2.h:84
Definition: Vector3.h:58
#define bool
Definition: CascPort.h:16
ModelFileMap iLoadedModelFiles
Definition: VMapManager2.h:82
static uint32 GetLiquidFlagsDummy(uint32)
Definition: VMapManager2.h:91
std::unordered_map< std::string, ManagedModel > ModelFileMap
Definition: VMapManager2.h:68
void incRefCount()
Definition: VMapManager2.h:60
Definition: WorldModel.h:106
GetLiquidFlagsFn GetLiquidFlagsPtr
Definition: VMapManager2.h:135
G3D::int16 z
Definition: Vector3int16.h:46
int iRefCount
Definition: VMapManager2.h:64
int32_t int32
Definition: Define.h:146
uint32_t uint32
Definition: Define.h:150
ManagedModel()
Definition: VMapManager2.h:57
G3D::int16 y
Definition: Vector2int16.h:38
Definition: IVMapManager.h:45
int decRefCount()
Definition: VMapManager2.h:61
DisableTypes
Definition: VMapManager2.h:70
#define TC_COMMON_API
Definition: Define.h:116
WorldModel * getModel()
Definition: VMapManager2.h:59
bool processCommand(char *) override
Definition: VMapManager2.h:117
static bool IsVMAPDisabledForDummy(uint32, uint8)
Definition: VMapManager2.h:92
uint8_t uint8
Definition: Define.h:152
Definition: VMapManager2.h:74
uint32_t uint32
Definition: g3dmath.h:168
uint8 flags
Definition: DisableMgr.cpp:44
G3D::int16 x
Definition: Vector2int16.h:37
void setModel(WorldModel *model)
Definition: VMapManager2.h:58
static unsigned short getHeight(const float fx, const float fy, const float fz, const float, const float ics, const float ch, const rcHeightPatch &hp)
Definition: RecastMeshDetail.cpp:203
IsVMAPDisabledForFn IsVMAPDisabledForPtr
Definition: VMapManager2.h:138
Definition: VMapManager2.h:72
InstanceTreeMap iInstanceMapTrees
Definition: VMapManager2.h:83