TrinityCore
MMapManager.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 _MMAP_MANAGER_H
19#define _MMAP_MANAGER_H
20
21#include "Define.h"
22#include "DetourNavMesh.h"
23#include "DetourNavMeshQuery.h"
24#include "Hash.h"
25#include <string>
26#include <unordered_map>
27#include <vector>
28
29// move map related classes
30namespace MMAP
31{
32 typedef std::unordered_map<uint32, dtTileRef> MMapTileSet;
33 typedef std::unordered_map<std::pair<uint32, uint32>, dtNavMeshQuery*> NavMeshQuerySet;
34
35 // dummy struct to hold map's mmap data
37 {
38 MMapData(dtNavMesh* mesh) : navMesh(mesh) { }
40 {
41 for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
42 dtFreeNavMeshQuery(i->second);
43
44 if (navMesh)
45 dtFreeNavMesh(navMesh);
46 }
47
48 // we have to use single dtNavMeshQuery for every instance, since those are not thread safe
49 NavMeshQuerySet navMeshQueries; // instanceId to query
50
51 dtNavMesh* navMesh;
52 MMapTileSet loadedTileRefs; // maps [map grid coords] to [dtTile]
53 };
54
55 typedef std::unordered_map<uint32, MMapData*> MMapDataSet;
56
57 // singleton class
58 // holds all all access to mmap loading unloading and meshes
60 {
61 public:
62 MMapManager() : loadedTiles(0), thread_safe_environment(true) {}
64
65 void InitializeThreadUnsafe(std::unordered_map<uint32, std::vector<uint32>> const& mapData);
66 bool loadMap(std::string const& basePath, uint32 mapId, int32 x, int32 y);
67 bool loadMapInstance(std::string const& basePath, uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
68 bool unloadMap(uint32 mapId, int32 x, int32 y);
69 bool unloadMap(uint32 mapId);
70 bool unloadMapInstance(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
71
72 // the returned [dtNavMeshQuery const*] is NOT threadsafe
73 dtNavMeshQuery const* GetNavMeshQuery(uint32 meshMapId, uint32 instanceMapId, uint32 instanceId);
74 dtNavMesh const* GetNavMesh(uint32 mapId);
75
76 uint32 getLoadedTilesCount() const { return loadedTiles; }
77 uint32 getLoadedMapsCount() const { return uint32(loadedMMaps.size()); }
78 private:
79 bool loadMapData(std::string const& basePath, uint32 mapId);
80 uint32 packTileID(int32 x, int32 y);
81
82 MMapDataSet::const_iterator GetMMapData(uint32 mapId) const;
86
87 std::unordered_map<uint32, uint32> parentMapData;
88 };
89}
90
91#endif
#define TC_COMMON_API
Definition: Define.h:99
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
uint32 getLoadedMapsCount() const
Definition: MMapManager.h:77
std::unordered_map< uint32, uint32 > parentMapData
Definition: MMapManager.h:87
bool thread_safe_environment
Definition: MMapManager.h:85
MMapDataSet loadedMMaps
Definition: MMapManager.h:83
uint32 getLoadedTilesCount() const
Definition: MMapManager.h:76
std::unordered_map< uint32, dtTileRef > MMapTileSet
Definition: MMapManager.h:32
std::unordered_map< std::pair< uint32, uint32 >, dtNavMeshQuery * > NavMeshQuerySet
Definition: MMapManager.h:33
std::unordered_map< uint32, MMapData * > MMapDataSet
Definition: MMapManager.h:55
dtNavMesh * navMesh
Definition: MMapManager.h:51
MMapData(dtNavMesh *mesh)
Definition: MMapManager.h:38
NavMeshQuerySet navMeshQueries
Definition: MMapManager.h:49
MMapTileSet loadedTileRefs
Definition: MMapManager.h:52