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