TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapTree.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 _MAPTREE_H
20 #define _MAPTREE_H
21 
22 #include "Define.h"
24 #include <unordered_map>
25 
26 namespace VMAP
27 {
28  class ModelInstance;
29  class GroupModel;
30  class VMapManager2;
31 
33  {
34  LocationInfo(): hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
37  float ground_Z;
38  };
39 
41  {
42  typedef std::unordered_map<uint32, bool> loadedTileMap;
43  typedef std::unordered_map<uint32, uint32> loadedSpawnMap;
44  private:
46  bool iIsTiled;
48  ModelInstance* iTreeValues; // the tree entries
50 
51  // Store all the map tile idents that are loaded for that map
52  // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
53  // empty tiles have no tile file, hence map with bool instead of just a set (consistency check)
54  loadedTileMap iLoadedTiles;
55  // stores <tree_index, reference_count> to invalidate tree values, unload map, and to be able to report errors
56  loadedSpawnMap iLoadedSpawns;
57  std::string iBasePath;
58 
59  private:
60  bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit) const;
61  //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
62  public:
63  static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY);
64  static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; }
65  static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID>>16; tileY = ID&0xFF; }
66  static bool CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY);
67 
68  StaticMapTree(uint32 mapID, const std::string &basePath);
69  ~StaticMapTree();
70 
71  bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2) const;
72  bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
73  float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
74  bool getAreaInfo(G3D::Vector3 &pos, uint32 &flags, int32 &adtId, int32 &rootId, int32 &groupId) const;
75  bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
76 
77  bool InitMap(const std::string &fname, VMapManager2* vm);
78  void UnloadMap(VMapManager2* vm);
79  bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
80  void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
81  bool isTiled() const { return iIsTiled; }
82  uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
83  void getModelInstances(ModelInstance* &models, uint32 &count);
84 
85  private:
86  StaticMapTree(StaticMapTree const& right) = delete;
87  StaticMapTree& operator=(StaticMapTree const& right) = delete;
88  };
89 
91  {
92  AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
93  rootId(0), groupId(0) { }
94  bool result;
95  float ground_Z;
100  };
101 } // VMAP
102 
103 #endif // _MAPTREE_H
float finf()
Definition: g3dmath.cpp:71
float ground_Z
Definition: MapTree.h:95
LocationInfo()
Definition: MapTree.h:34
static uint32 packTileID(uint32 tileX, uint32 tileY)
Definition: MapTree.h:64
Definition: VMapManager2.h:78
Definition: MapTree.h:32
uint32 numLoadedTiles() const
Definition: MapTree.h:82
Definition: model.h:53
Definition: WorldModel.h:73
Definition: AABox.h:25
float ground_Z
Definition: MapTree.h:37
bool result
Definition: MapTree.h:94
int32 groupId
Definition: MapTree.h:99
const ModelInstance * hitInstance
Definition: MapTree.h:35
#define false
Definition: CascPort.h:18
uint32 iMapID
Definition: MapTree.h:45
Definition: IVMapManager.h:31
Definition: Vector3.h:58
loadedSpawnMap iLoadedSpawns
Definition: MapTree.h:56
std::unordered_map< uint32, uint32 > loadedSpawnMap
Definition: MapTree.h:43
ModelInstance * iTreeValues
Definition: MapTree.h:48
bool isTiled() const
Definition: MapTree.h:81
Definition: MapTree.h:90
Definition: MapTree.h:40
uint32 flags
Definition: MapTree.h:96
uint32 iNTreeValues
Definition: MapTree.h:49
std::unordered_map< uint32, bool > loadedTileMap
Definition: MapTree.h:42
const GroupModel * hitModel
Definition: MapTree.h:36
Vector2int16 & operator=(const Any &a)
int32_t int32
Definition: Define.h:146
int32 adtId
Definition: MapTree.h:97
uint32_t uint32
Definition: Define.h:150
Definition: Ray.h:24
#define TC_COMMON_API
Definition: Define.h:116
BIH iTree
Definition: MapTree.h:47
bool iIsTiled
Definition: MapTree.h:46
loadedTileMap iLoadedTiles
Definition: MapTree.h:54
uint32_t uint32
Definition: g3dmath.h:168
uint8 flags
Definition: DisableMgr.cpp:44
AreaInfo()
Definition: MapTree.h:92
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
Definition: BoundingIntervalHierarchy.h:70
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition: MapTree.h:65
std::string iBasePath
Definition: MapTree.h:57
int32 rootId
Definition: MapTree.h:98
Definition: ModelInstance.h:63