AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
PathGenerator.cpp File Reference
#include "MapBuilder.h"
#include "PathCommon.h"
#include "Timer.h"
#include "Util.h"
#include <boost/filesystem.hpp>

Go to the source code of this file.

Functions

bool checkDirectories (bool debugOutput)
 
bool handleArgs (int argc, char **argv, int &mapnum, int &tileX, int &tileY, float &maxAngle, bool &skipLiquid, bool &skipContinents, bool &skipJunkMaps, bool &skipBattlegrounds, bool &debugOutput, bool &silent, bool &bigBaseUnit, char *&offMeshInputPath, char *&file, unsigned int &threads)
 
int finish (const char *message, int returnValue)
 
int main (int argc, char **argv)
 

Function Documentation

◆ checkDirectories()

bool checkDirectories ( bool  debugOutput)
27{
28 std::vector<std::string> dirFiles;
29
30 if (getDirContents(dirFiles, "maps") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
31 {
32 printf("'maps' directory is empty or does not exist\n");
33 return false;
34 }
35
36 dirFiles.clear();
37 if (getDirContents(dirFiles, "vmaps", "*.vmtree") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
38 {
39 printf("'vmaps' directory is empty or does not exist\n");
40 return false;
41 }
42
43 dirFiles.clear();
44 if (getDirContents(dirFiles, "mmaps") == LISTFILE_DIRECTORY_NOT_FOUND)
45 {
46 return boost::filesystem::create_directory("mmaps");
47 }
48
49 dirFiles.clear();
50 if (debugOutput)
51 {
52 if (getDirContents(dirFiles, "meshes") == LISTFILE_DIRECTORY_NOT_FOUND)
53 {
54 printf("'meshes' directory does not exist (no place to put debugOutput files)\n");
55 return false;
56 }
57 }
58
59 return true;
60}
@ LISTFILE_DIRECTORY_NOT_FOUND
Definition: PathCommon.h:73
ListFilesResult getDirContents(std::vector< std::string > &fileList, std::string dirpath=".", std::string filter="*")
Definition: PathCommon.h:77

References MMAP::getDirContents(), and MMAP::LISTFILE_DIRECTORY_NOT_FOUND.

Referenced by main().

◆ finish()

int finish ( const char *  message,
int  returnValue 
)
236{
237 printf("%s", message);
238 getchar(); // Wait for user input
239 return returnValue;
240}

Referenced by main().

◆ handleArgs()

bool handleArgs ( int  argc,
char **  argv,
int &  mapnum,
int &  tileX,
int &  tileY,
float &  maxAngle,
bool &  skipLiquid,
bool &  skipContinents,
bool &  skipJunkMaps,
bool &  skipBattlegrounds,
bool &  debugOutput,
bool &  silent,
bool &  bigBaseUnit,
char *&  offMeshInputPath,
char *&  file,
unsigned int &  threads 
)
77{
78 char* param = nullptr;
79 for (int i = 1; i < argc; ++i)
80 {
81 if (strcmp(argv[i], "--maxAngle") == 0)
82 {
83 param = argv[++i];
84 if (!param)
85 return false;
86
87 float maxangle = atof(param);
88 if (maxangle <= 90.f && maxangle >= 45.f)
89 maxAngle = maxangle;
90 else
91 printf("invalid option for '--maxAngle', using default\n");
92 }
93 else if (strcmp(argv[i], "--threads") == 0)
94 {
95 param = argv[++i];
96 if (!param)
97 return false;
98 threads = static_cast<unsigned int>(std::max(0, atoi(param)));
99 }
100 else if (strcmp(argv[i], "--file") == 0)
101 {
102 param = argv[++i];
103 if (!param)
104 return false;
105 file = param;
106 }
107 else if (strcmp(argv[i], "--tile") == 0)
108 {
109 param = argv[++i];
110 if (!param)
111 return false;
112
113 char* stileX = strtok(param, ",");
114 char* stileY = strtok(nullptr, ",");
115 int tilex = atoi(stileX);
116 int tiley = atoi(stileY);
117
118 if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX, "0") == 0))
119 tileX = tilex;
120 if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY, "0") == 0))
121 tileY = tiley;
122
123 if (tileX < 0 || tileY < 0)
124 {
125 printf("invalid tile coords.\n");
126 return false;
127 }
128 }
129 else if (strcmp(argv[i], "--skipLiquid") == 0)
130 {
131 param = argv[++i];
132 if (!param)
133 return false;
134
135 if (strcmp(param, "true") == 0)
136 skipLiquid = true;
137 else if (strcmp(param, "false") == 0)
138 skipLiquid = false;
139 else
140 printf("invalid option for '--skipLiquid', using default\n");
141 }
142 else if (strcmp(argv[i], "--skipContinents") == 0)
143 {
144 param = argv[++i];
145 if (!param)
146 return false;
147
148 if (strcmp(param, "true") == 0)
149 skipContinents = true;
150 else if (strcmp(param, "false") == 0)
151 skipContinents = false;
152 else
153 printf("invalid option for '--skipContinents', using default\n");
154 }
155 else if (strcmp(argv[i], "--skipJunkMaps") == 0)
156 {
157 param = argv[++i];
158 if (!param)
159 return false;
160
161 if (strcmp(param, "true") == 0)
162 skipJunkMaps = true;
163 else if (strcmp(param, "false") == 0)
164 skipJunkMaps = false;
165 else
166 printf("invalid option for '--skipJunkMaps', using default\n");
167 }
168 else if (strcmp(argv[i], "--skipBattlegrounds") == 0)
169 {
170 param = argv[++i];
171 if (!param)
172 return false;
173
174 if (strcmp(param, "true") == 0)
175 skipBattlegrounds = true;
176 else if (strcmp(param, "false") == 0)
177 skipBattlegrounds = false;
178 else
179 printf("invalid option for '--skipBattlegrounds', using default\n");
180 }
181 else if (strcmp(argv[i], "--debugOutput") == 0)
182 {
183 param = argv[++i];
184 if (!param)
185 return false;
186
187 if (strcmp(param, "true") == 0)
188 debugOutput = true;
189 else if (strcmp(param, "false") == 0)
190 debugOutput = false;
191 else
192 printf("invalid option for '--debugOutput', using default true\n");
193 }
194 else if (strcmp(argv[i], "--silent") == 0)
195 {
196 silent = true;
197 }
198 else if (strcmp(argv[i], "--bigBaseUnit") == 0)
199 {
200 param = argv[++i];
201 if (!param)
202 return false;
203
204 if (strcmp(param, "true") == 0)
205 bigBaseUnit = true;
206 else if (strcmp(param, "false") == 0)
207 bigBaseUnit = false;
208 else
209 printf("invalid option for '--bigBaseUnit', using default false\n");
210 }
211 else if (strcmp(argv[i], "--offMeshInput") == 0)
212 {
213 param = argv[++i];
214 if (!param)
215 return false;
216
217 offMeshInputPath = param;
218 }
219 else
220 {
221 int map = atoi(argv[i]);
222 if (map > 0 || (map == 0 && (strcmp(argv[i], "0") == 0)))
223 mapnum = map;
224 else
225 {
226 printf("invalid map id\n");
227 return false;
228 }
229 }
230 }
231
232 return true;
233}

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)
243{
244 unsigned int threads = std::thread::hardware_concurrency();
245 int mapnum = -1;
246 int tileX = -1, tileY = -1;
247 float maxAngle = 60.0f;
248 bool skipLiquid = false,
249 skipContinents = false,
250 skipJunkMaps = true,
251 skipBattlegrounds = false,
252 debugOutput = false,
253 silent = false,
254 bigBaseUnit = false;
255 char* offMeshInputPath = nullptr;
256 char* file = nullptr;
257
258 bool validParam = handleArgs(argc, argv, mapnum,
259 tileX, tileY, maxAngle,
260 skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
261 debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
262
263 if (!validParam)
264 return silent ? -1 : finish("You have specified invalid parameters", -1);
265
266 if (mapnum == -1 && debugOutput)
267 {
268 if (silent)
269 return -2;
270
271 printf("You have specifed debug output, but didn't specify a map to generate.\n");
272 printf("This will generate debug output for ALL maps.\n");
273 printf("Are you sure you want to continue? (y/n) ");
274 if (getchar() != 'y')
275 return 0;
276 }
277
278 if (!checkDirectories(debugOutput))
279 return silent ? -3 : finish("Press ENTER to close...", -3);
280
281 MapBuilder builder(maxAngle, skipLiquid, skipContinents, skipJunkMaps,
282 skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
283
284 uint32 start = getMSTime();
285 if (file)
286 builder.buildMeshFromFile(file);
287 else if (tileX > -1 && tileY > -1 && mapnum >= 0)
288 builder.buildSingleTile(mapnum, tileX, tileY);
289 else if (mapnum >= 0)
290 builder.buildMaps(uint32(mapnum));
291 else
292 builder.buildMaps({});
293
294 if (!silent)
295 printf("Finished. MMAPS were built in %s\n", secsToTimeString(GetMSTimeDiffToNow(start) / 1000).c_str());
296 return 0;
297}
std::uint32_t uint32
Definition: Define.h:108
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
std::string secsToTimeString(uint64 timeInSecs, bool shortText)
Definition: Util.cpp:73
Definition: MapBuilder.h:147
int finish(const char *message, int returnValue)
Definition: PathGenerator.cpp:235
bool handleArgs(int argc, char **argv, int &mapnum, int &tileX, int &tileY, float &maxAngle, bool &skipLiquid, bool &skipContinents, bool &skipJunkMaps, bool &skipBattlegrounds, bool &debugOutput, bool &silent, bool &bigBaseUnit, char *&offMeshInputPath, char *&file, unsigned int &threads)
Definition: PathGenerator.cpp:62
bool checkDirectories(bool debugOutput)
Definition: PathGenerator.cpp:26

References MMAP::MapBuilder::buildMaps(), MMAP::MapBuilder::buildMeshFromFile(), MMAP::MapBuilder::buildSingleTile(), checkDirectories(), finish(), getMSTime(), GetMSTimeDiffToNow(), handleArgs(), and secsToTimeString().