OregonCore  revision fb2a440-git
Your Favourite TBC server
MoveMap.h
Go to the documentation of this file.
1 /*
2  * This file is part of the OregonCore 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 _MOVE_MAP_H
19 #define _MOVE_MAP_H
20 
21 #include <vector>
22 #include "Utilities/UnorderedMap.h"
23 
24 #include "DetourAlloc.h"
25 #include "DetourNavMesh.h"
26 #include "DetourNavMeshQuery.h"
27 
28 // memory management
29 inline void* dtCustomAlloc(size_t size, dtAllocHint /*hint*/)
30 {
31  return (void*)new unsigned char[size];
32 }
33 
34 inline void dtCustomFree(void* ptr)
35 {
36  delete [] (unsigned char*)ptr;
37 }
38 
39 // move map related classes
40 namespace MMAP
41 {
42 typedef UNORDERED_MAP<uint32, dtTileRef> MMapTileSet;
43 typedef UNORDERED_MAP<uint32, dtNavMeshQuery*> NavMeshQuerySet;
44 
45 // dummy struct to hold map's mmap data
46 struct MMapData
47 {
48  MMapData(dtNavMesh* mesh) : navMesh(mesh) {}
50  {
51  for (NavMeshQuerySet::iterator i = navMeshQueries.begin(); i != navMeshQueries.end(); ++i)
52  dtFreeNavMeshQuery(i->second);
53 
54  if (navMesh)
55  dtFreeNavMesh(navMesh);
56  }
57 
58  dtNavMesh* navMesh;
59 
60  // we have to use single dtNavMeshQuery for every instance, since those are not thread safe
61  NavMeshQuerySet navMeshQueries; // instanceId to query
62  MMapTileSet mmapLoadedTiles; // maps [map grid coords] to [dtTile]
63 };
64 
65 
66 typedef UNORDERED_MAP<uint32, MMapData*> MMapDataSet;
67 
68 // singelton class
69 // holds all all access to mmap loading unloading and meshes
71 {
72  public:
73  MMapManager() : loadedTiles(0), thread_safe_environment(true) {}
74  ~MMapManager();
75 
76  void InitializeThreadUnsafe(const std::vector<uint32>& mapIds);
77  bool loadMap(uint32 mapId, int32 x, int32 y);
78  bool unloadMap(uint32 mapId, int32 x, int32 y);
79  bool unloadMap(uint32 mapId);
80  bool unloadMapInstance(uint32 mapId, uint32 instanceId);
81 
82  // the returned [dtNavMeshQuery const*] is NOT threadsafe
83  dtNavMeshQuery const* GetNavMeshQuery(uint32 mapId, uint32 instanceId);
84  dtNavMesh const* GetNavMesh(uint32 mapId);
85 
87  {
88  return loadedTiles;
89  }
91  {
92  return loadedMMaps.size();
93  }
94  private:
95  bool loadMapData(uint32 mapId);
96  uint32 packTileID(int32 x, int32 y);
97 
98  MMapDataSet::const_iterator GetMMapData(uint32 mapId) const;
99  MMapDataSet loadedMMaps;
102 };
103 
104 // static class
105 // holds all mmap global data
106 // access point to MMapManager singelton
108 {
109  public:
110  static MMapManager* createOrGetMMapManager();
111  static void clear();
112  static void preventPathfindingOnMaps(const char* ignoreMapIds);
113  static bool IsPathfindingEnabled(uint32 mapId);
114 };
115 }
116 
117 #endif // _MOVE_MAP_H
NavMeshQuerySet navMeshQueries
Definition: MoveMap.h:61
MMapTileSet mmapLoadedTiles
Definition: MoveMap.h:62
ACE_INT32 int32
Definition: Define.h:67
Definition: MoveMap.cpp:25
uint32 getLoadedMapsCount() const
Definition: MoveMap.h:90
bool thread_safe_environment
Definition: MoveMap.h:101
uint32 loadedTiles
Definition: MoveMap.h:100
void dtCustomFree(void *ptr)
Definition: MoveMap.h:34
MMapDataSet loadedMMaps
Definition: MoveMap.h:99
void * dtCustomAlloc(size_t size, dtAllocHint)
Definition: MoveMap.h:29
UNORDERED_MAP< uint32, dtNavMeshQuery * > NavMeshQuerySet
Definition: MoveMap.h:43
uint32 getLoadedTilesCount() const
Definition: MoveMap.h:86
dtNavMesh * navMesh
Definition: MoveMap.h:58
UNORDERED_MAP< uint32, MMapData * > MMapDataSet
Definition: MoveMap.h:66
MMapData(dtNavMesh *mesh)
Definition: MoveMap.h:48
UNORDERED_MAP< uint32, dtTileRef > MMapTileSet
Definition: MoveMap.h:42
ACE_UINT32 uint32
Definition: Define.h:71
true
Definition: Log.cpp:534