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 <span>
24#include <unordered_map>
25
26namespace VMAP
27{
28 class ModelInstance;
29 class GroupModel;
30 class VMapManager;
31 enum class LoadResult : uint8;
32 enum class ModelIgnoreFlags : uint32;
33
35 {
36 GroupModel const* hitModel = nullptr;
38 float ground_Z = -G3D::finf();
39 };
40
45
47 {
48 typedef std::unordered_map<uint32, std::vector<uint32>> loadedTileMap;
49 private:
52 std::vector<ModelInstance> iTreeValues; // the tree entries
53
54 // Store all the map tile idents that are loaded for that map
55 // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
56 // empty tiles have no tile file, hence map with bool instead of just a set (consistency check)
58 std::string iBasePath;
59
60 private:
61 bool getIntersectionTime(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
62 //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
63 public:
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 LoadResult CanLoadMap(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager* vm);
67
68 StaticMapTree(uint32 mapID, std::string const& basePath);
70
71 bool isInLineOfSight(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, ModelIgnoreFlags ignoreFlags) const;
72 bool getObjectHitPos(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
73 float getHeight(G3D::Vector3 const& pPos, float maxSearchDist) const;
74 bool GetLocationInfo(G3D::Vector3 const& pos, StaticMapTreeLocationInfo& info) const;
75
76 LoadResult InitMap(std::string const& fname);
77 void UnloadMap();
78 LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager* vm);
79 void UnloadMapTile(uint32 tileX, uint32 tileY);
80 uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
81 std::span<ModelInstance const> getModelInstances() const;
82
83 private:
84 StaticMapTree(StaticMapTree const& right) = delete;
85 StaticMapTree& operator=(StaticMapTree const& right) = delete;
86 };
87
89 {
90 AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
91 rootId(0), groupId(0) { }
92 bool result;
93 float ground_Z;
98 };
99} // VMAP
100
101#endif // _MAPTREE_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::vector< ModelInstance > iTreeValues
Definition MapTree.h:52
~StaticMapTree()
Make sure to call unloadMap() to unregister acquired model references before destroying.
StaticMapTree & operator=(StaticMapTree const &right)=delete
std::unordered_map< uint32, std::vector< uint32 > > loadedTileMap
Definition MapTree.h:48
static uint32 packTileID(uint32 tileX, uint32 tileY)
Definition MapTree.h:64
std::string iBasePath
Definition MapTree.h:58
loadedTileMap iLoadedTiles
Definition MapTree.h:57
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition MapTree.h:65
StaticMapTree(StaticMapTree const &right)=delete
uint32 numLoadedTiles() const
Definition MapTree.h:80
int32 rootId
Definition MapTree.h:96
int32 groupId
Definition MapTree.h:97
uint32 flags
Definition MapTree.h:94
int32 adtId
Definition MapTree.h:95
float ground_Z
Definition MapTree.h:93
GroupModel const * hitModel
Definition MapTree.h:36
ModelInstance const * hitInstance
Definition MapTree.h:43