TrinityCore
Loading...
Searching...
No Matches
MapTree.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 _MAPTREE_H
19#define _MAPTREE_H
20
21#include "Define.h"
23#include <unordered_map>
24
25namespace VMAP
26{
27 class ModelInstance;
28 class GroupModel;
29 class VMapManager2;
30 enum class LoadResult : uint8;
31 enum class ModelIgnoreFlags : uint32;
32
34 {
35 const GroupModel* hitModel = nullptr;
37 };
38
40 {
41 LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
45 float ground_Z;
46 };
47
49 {
50 typedef std::unordered_map<uint32, bool> loadedTileMap;
51 typedef std::unordered_map<uint32, uint32> loadedSpawnMap;
52 private:
56 ModelInstance* iTreeValues; // the tree entries
58
59 // Store all the map tile idents that are loaded for that map
60 // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
61 // empty tiles have no tile file, hence map with bool instead of just a set (consistency check)
63 // stores <tree_index, reference_count> to invalidate tree values, unload map, and to be able to report errors
65 std::string iBasePath;
66
67 private:
68 bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
69 //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
70 public:
71 static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY);
72 static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; }
73 static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID>>16; tileY = ID&0xFF; }
74 static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY);
75
76 StaticMapTree(uint32 mapID, const std::string &basePath);
78
79 bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2, ModelIgnoreFlags ignoreFlags) const;
80 bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
81 float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
82 bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
83
84 bool InitMap(const std::string &fname, VMapManager2* vm);
85 void UnloadMap(VMapManager2* vm);
86 bool LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
87 void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
88 bool isTiled() const { return iIsTiled; }
89 uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
90 void getModelInstances(ModelInstance* &models, uint32 &count);
91
92 private:
93 StaticMapTree(StaticMapTree const& right) = delete;
94 StaticMapTree& operator=(StaticMapTree const& right) = delete;
95 };
96
98 {
99 AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
100 rootId(0), groupId(0) { }
101 bool result;
102 float ground_Z;
107 };
108} // VMAP
109
110#endif // _MAPTREE_H
uint8_t uint8
Definition Define.h:135
#define TC_COMMON_API
Definition Define.h:96
int32_t int32
Definition Define.h:129
uint32_t uint32
Definition Define.h:133
uint16 flags
uint32 iNTreeValues
Definition MapTree.h:57
std::unordered_map< uint32, uint32 > loadedSpawnMap
Definition MapTree.h:51
StaticMapTree & operator=(StaticMapTree const &right)=delete
static uint32 packTileID(uint32 tileX, uint32 tileY)
Definition MapTree.h:72
std::unordered_map< uint32, bool > loadedTileMap
Definition MapTree.h:50
std::string iBasePath
Definition MapTree.h:65
ModelInstance * iTreeValues
Definition MapTree.h:56
loadedTileMap iLoadedTiles
Definition MapTree.h:62
loadedSpawnMap iLoadedSpawns
Definition MapTree.h:64
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition MapTree.h:73
StaticMapTree(StaticMapTree const &right)=delete
bool isTiled() const
Definition MapTree.h:88
uint32 numLoadedTiles() const
Definition MapTree.h:89
int32 groupId
Definition MapTree.h:106
uint32 flags
Definition MapTree.h:103
float ground_Z
Definition MapTree.h:102
const GroupModel * hitModel
Definition MapTree.h:35
GroupModel const * hitModel
Definition MapTree.h:44
ModelInstance const * hitInstance
Definition MapTree.h:43