TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapBuilder.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _MAP_BUILDER_H
20 #define _MAP_BUILDER_H
21 
22 #include <vector>
23 #include <set>
24 #include <map>
25 #include <list>
26 #include <atomic>
27 #include <thread>
28 
29 #include "TerrainBuilder.h"
30 #include "IntermediateValues.h"
31 
32 #include "Recast.h"
33 #include "DetourNavMesh.h"
34 #include "ProducerConsumerQueue.h"
35 
36 using namespace VMAP;
37 
38 namespace MMAP
39 {
40  struct MapTiles
41  {
42  MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {}
43 
44  MapTiles(uint32 id, std::set<uint32>* tiles) : m_mapId(id), m_tiles(tiles) {}
45  ~MapTiles() {}
46 
48  std::set<uint32>* m_tiles;
49 
50  bool operator==(uint32 id)
51  {
52  return m_mapId == id;
53  }
54  };
55 
56  typedef std::list<MapTiles> TileList;
57 
58  struct Tile
59  {
60  Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {}
62  {
64  rcFreeContourSet(cset);
65  rcFreeHeightField(solid);
66  rcFreePolyMesh(pmesh);
67  rcFreePolyMeshDetail(dmesh);
68  }
74  };
75 
76  class MapBuilder
77  {
78  public:
79  MapBuilder(float maxWalkableAngle = 70.f,
80  bool skipLiquid = false,
81  bool skipContinents = false,
82  bool skipJunkMaps = true,
83  bool skipBattlegrounds = false,
84  bool debugOutput = false,
85  bool bigBaseUnit = false,
86  const char* offMeshFilePath = NULL);
87 
88  ~MapBuilder();
89 
90  // builds all mmap tiles for the specified map id (ignores skip settings)
91  void buildMap(uint32 mapID);
92  void buildMeshFromFile(char* name);
93 
94  // builds an mmap tile for the specified map and its mesh
95  void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY);
96 
97  // builds list of maps, then builds all of mmap tiles (based on the skip settings)
98  void buildAllMaps(int threads);
99 
100  void WorkerThread();
101 
102  private:
103  // detect maps and tiles
104  void discoverTiles();
105  std::set<uint32>* getTileList(uint32 mapID);
106 
107  void buildNavMesh(uint32 mapID, dtNavMesh* &navMesh);
108 
109  void buildTile(uint32 mapID, uint32 tileX, uint32 tileY, dtNavMesh* navMesh);
110 
111  // move map building
112  void buildMoveMapTile(uint32 mapID,
113  uint32 tileX,
114  uint32 tileY,
115  MeshData &meshData,
116  float bmin[3],
117  float bmax[3],
118  dtNavMesh* navMesh);
119 
120  void getTileBounds(uint32 tileX, uint32 tileY,
121  float* verts, int vertCount,
122  float* bmin, float* bmax);
123  void getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY);
124 
125  bool shouldSkipMap(uint32 mapID);
126  bool isTransportMap(uint32 mapID);
127  bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY);
128 
130  TileList m_tiles;
131 
133 
134  const char* m_offMeshFilePath;
138 
141 
142  // build performance - not really used for now
144 
145  std::vector<std::thread> _workerThreads;
147  std::atomic<bool> _cancelationToken;
148  };
149 }
150 
151 #endif
Definition: Recast.h:274
void rcFreeCompactHeightfield(rcCompactHeightfield *chf)
Definition: Recast.cpp:102
Definition: TerrainBuilder.h:78
TileList m_tiles
Definition: MapBuilder.h:130
Definition: Recast.h:101
MapTiles()
Definition: MapBuilder.h:42
uint32 m_mapId
Definition: MapBuilder.h:47
bool m_skipBattlegrounds
Definition: MapBuilder.h:137
arena_t NULL
Definition: jemalloc_internal.h:624
bool operator==(uint32 id)
Definition: MapBuilder.h:50
Definition: MMapFactory.cpp:22
void rcFreeHeightField(rcHeightfield *hf)
Definition: Recast.cpp:80
~Tile()
Definition: MapBuilder.h:61
std::list< MapTiles > TileList
Definition: MapBuilder.h:56
Definition: IVMapManager.h:31
~MapTiles()
Definition: MapBuilder.h:45
rcHeightfield * solid
Definition: MapBuilder.h:70
rcPolyMeshDetail * dmesh
Definition: MapBuilder.h:73
Definition: DetourNavMesh.h:323
rcContourSet * cset
Definition: MapBuilder.h:71
Definition: Recast.h:305
Definition: Recast.h:368
bool m_skipContinents
Definition: MapBuilder.h:135
Definition: Recast.h:383
bool m_skipJunkMaps
Definition: MapBuilder.h:136
std::atomic< bool > _cancelationToken
Definition: MapBuilder.h:147
MapTiles(uint32 id, std::set< uint32 > *tiles)
Definition: MapBuilder.h:44
uint32_t uint32
Definition: Define.h:150
Tile()
Definition: MapBuilder.h:60
bool m_bigBaseUnit
Definition: MapBuilder.h:140
Definition: MapBuilder.h:40
bool m_debugOutput
Definition: MapBuilder.h:132
float m_maxWalkableAngle
Definition: MapBuilder.h:139
Definition: MapBuilder.h:58
TerrainBuilder * m_terrainBuilder
Definition: MapBuilder.h:129
std::vector< std::thread > _workerThreads
Definition: MapBuilder.h:145
void rcFreePolyMeshDetail(rcPolyMeshDetail *dmesh)
Definition: Recast.cpp:178
Definition: TerrainBuilder.h:61
rcContext * m_rcContext
Definition: MapBuilder.h:143
ProducerConsumerQueue< uint32 > _queue
Definition: MapBuilder.h:146
rcPolyMesh * pmesh
Definition: MapBuilder.h:72
const char * m_offMeshFilePath
Definition: MapBuilder.h:134
void rcFreePolyMesh(rcPolyMesh *pmesh)
Definition: Recast.cpp:160
rcCompactHeightfield * chf
Definition: MapBuilder.h:69
Definition: MapBuilder.h:76
Definition: Recast.h:404
void rcFreeContourSet(rcContourSet *cset)
Definition: Recast.cpp:141
std::set< uint32 > * m_tiles
Definition: MapBuilder.h:48