TrinityCore
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:
55 ModelInstance* iTreeValues; // the tree entries
57 std::unordered_map<uint32, uint32> iSpawnIndices;
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 std::vector<std::pair<int32, int32>> iLoadedPrimaryTiles;
64 // stores <tree_index, reference_count> to invalidate tree values, unload map, and to be able to report errors
66 std::string iBasePath;
67
69 {
70 std::string Name;
71 FILE* File;
73 };
74
75 private:
76 static TileFileOpenResult OpenMapTileFile(std::string const& basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm);
77 bool getIntersectionTime(const G3D::Ray& pRay, float &pMaxDist, bool pStopAtFirstHit, ModelIgnoreFlags ignoreFlags) const;
78 //bool containsLoadedMapTile(unsigned int pTileIdent) const { return(iLoadedMapTiles.containsKey(pTileIdent)); }
79 public:
80 static std::string getTileFileName(uint32 mapID, uint32 tileX, uint32 tileY);
81 static uint32 packTileID(uint32 tileX, uint32 tileY) { return tileX<<16 | tileY; }
82 static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY) { tileX = ID >> 16; tileY = ID & 0xFF; }
83 static LoadResult CanLoadMap(const std::string &basePath, uint32 mapID, uint32 tileX, uint32 tileY, VMapManager2* vm);
84
85 StaticMapTree(uint32 mapID, const std::string &basePath);
87
88 bool isInLineOfSight(const G3D::Vector3& pos1, const G3D::Vector3& pos2, ModelIgnoreFlags ignoreFlags) const;
89 bool getObjectHitPos(const G3D::Vector3& pos1, const G3D::Vector3& pos2, G3D::Vector3& pResultHitPos, float pModifyDist) const;
90 float getHeight(const G3D::Vector3& pPos, float maxSearchDist) const;
91 bool GetLocationInfo(const G3D::Vector3 &pos, LocationInfo &info) const;
92
93 LoadResult InitMap(std::string const& fname);
94 void UnloadMap(VMapManager2* vm);
95 LoadResult LoadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
96 void UnloadMapTile(uint32 tileX, uint32 tileY, VMapManager2* vm);
97 uint32 numLoadedTiles() const { return uint32(iLoadedTiles.size()); }
98 void getModelInstances(ModelInstance* &models, uint32 &count);
99
100 private:
101 StaticMapTree(StaticMapTree const& right) = delete;
102 StaticMapTree& operator=(StaticMapTree const& right) = delete;
103 };
104
106 {
107 AreaInfo(): result(false), ground_Z(-G3D::finf()), flags(0), adtId(0),
108 rootId(0), groupId(0) { }
109 bool result;
110 float ground_Z;
115 };
116} // VMAP
117
118#endif // _MAPTREE_H
uint8_t uint8
Definition: Define.h:144
#define TC_COMMON_API
Definition: Define.h:99
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
uint16 flags
Definition: DisableMgr.cpp:49
uint32 iNTreeValues
Definition: MapTree.h:56
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:81
std::unordered_map< uint32, bool > loadedTileMap
Definition: MapTree.h:50
std::string iBasePath
Definition: MapTree.h:66
ModelInstance * iTreeValues
Definition: MapTree.h:55
std::unordered_map< uint32, uint32 > iSpawnIndices
Definition: MapTree.h:57
loadedTileMap iLoadedTiles
Definition: MapTree.h:62
loadedSpawnMap iLoadedSpawns
Definition: MapTree.h:65
static void unpackTileID(uint32 ID, uint32 &tileX, uint32 &tileY)
Definition: MapTree.h:82
StaticMapTree(StaticMapTree const &right)=delete
uint32 numLoadedTiles() const
Definition: MapTree.h:97
std::vector< std::pair< int32, int32 > > iLoadedPrimaryTiles
Definition: MapTree.h:63
LoadResult
Definition: IVMapManager.h:35
int32 rootId
Definition: MapTree.h:113
int32 groupId
Definition: MapTree.h:114
uint32 flags
Definition: MapTree.h:111
int32 adtId
Definition: MapTree.h:112
float ground_Z
Definition: MapTree.h:110
const GroupModel * hitModel
Definition: MapTree.h:35
GroupModel const * hitModel
Definition: MapTree.h:44
ModelInstance const * hitInstance
Definition: MapTree.h:43