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 const GroupModel* hitModel = nullptr;
38 };
39
41 {
42 LocationInfo(): rootId(-1), hitInstance(nullptr), hitModel(nullptr), ground_Z(-G3D::finf()) { }
46 float ground_Z;
47 };
48
50 {
51 typedef std::unordered_map<uint32, std::vector<uint32>> loadedTileMap;
52 private:
55 std::vector<ModelInstance> iTreeValues; // the tree entries
56
57 // Store all the map tile idents that are loaded for that map
58 // some maps are not splitted into tiles and we have to make sure, not removing the map before all tiles are removed
59 // empty tiles have no tile file, hence map with bool instead of just a set (consistency check)
61 std::string iBasePath;
62
63 private:
64 bool getIntersectionTime(G3D::Ray const& pRay, float& pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
65 //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
66 public:
67 static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX << 16 | tileY; }
68 static void unpackTileID(uint32 ID, uint32& tileX, uint32& tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
69 static LoadResult CanLoadMap(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager* vm);
70
71 StaticMapTree(uint32 mapID, std::string const& basePath);
73
74 bool isInLineOfSight(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, ModelIgnoreFlags ignoreFlags) const;
75 bool getObjectHitPos(G3D::Vector3 const& pos1, G3D::Vector3 const& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
76 float getHeight(G3D::Vector3 const& pPos, float maxSearchDist) const;
77 bool GetLocationInfo(G3D::Vector3 const& pos, LocationInfo& info) const;
78
79 LoadResult InitMap(std::string const& fname);
80 void UnloadMap();
81 LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager* vm);
82 void UnloadMapTile(uint32 tileX, uint32 tileY);
83 uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
84 std::span<ModelInstance const> getModelInstances() const;
85
86 private:
87 StaticMapTree(StaticMapTree const& right) = delete;
88 StaticMapTree& operator=(StaticMapTree const& right) = delete;
89 };
90
92 {
93 AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
94 rootId(0), groupId(0) { }
95 bool result;
96 float ground_Z;
101 };
102} // VMAP
103
104#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:55
~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:51
static uint32 packTileID(uint32 tileX, uint32 tileY)
Definition MapTree.h:67
std::string iBasePath
Definition MapTree.h:61
loadedTileMap iLoadedTiles
Definition MapTree.h:60
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition MapTree.h:68
StaticMapTree(StaticMapTree const &right)=delete
uint32 numLoadedTiles() const
Definition MapTree.h:83
int32 rootId
Definition MapTree.h:99
int32 groupId
Definition MapTree.h:100
uint32 flags
Definition MapTree.h:97
int32 adtId
Definition MapTree.h:98
float ground_Z
Definition MapTree.h:96
const GroupModel * hitModel
Definition MapTree.h:36
GroupModel const * hitModel
Definition MapTree.h:45
ModelInstance const * hitInstance
Definition MapTree.h:44