TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PathGenerator.cpp File Reference
#include "PathCommon.h"
#include "MapBuilder.h"
#include "Timer.h"
+ Include dependency graph for PathGenerator.cpp:

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, int &threads)
 
int finish (const char *message, int returnValue)
 
int main (int argc, char **argv)
 

Function Documentation

bool checkDirectories ( bool  debugOutput)
26 {
27  std::vector<std::string> dirFiles;
28 
29  if (getDirContents(dirFiles, "maps") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
30  {
31  printf("'maps' directory is empty or does not exist\n");
32  return false;
33  }
34 
35  dirFiles.clear();
36  if (getDirContents(dirFiles, "vmaps", "*.vmtree") == LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
37  {
38  printf("'vmaps' directory is empty or does not exist\n");
39  return false;
40  }
41 
42  dirFiles.clear();
43  if (getDirContents(dirFiles, "mmaps") == LISTFILE_DIRECTORY_NOT_FOUND)
44  {
45  printf("'mmaps' directory does not exist\n");
46  return false;
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 }
Definition: PathCommon.h:86
ListFilesResult getDirContents(std::vector< std::string > &fileList, std::string dirpath=".", std::string filter="*")
Definition: PathCommon.h:90
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int finish ( const char *  message,
int  returnValue 
)
237 {
238  printf("%s", message);
239  getchar(); // Wait for user input
240  return returnValue;
241 }
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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,
int &  threads 
)
77 {
78  char* param = NULL;
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 = atoi(param);
99  printf("Using %i threads to extract mmaps\n", threads);
100  }
101  else if (strcmp(argv[i], "--file") == 0)
102  {
103  param = argv[++i];
104  if (!param)
105  return false;
106  file = param;
107  }
108  else if (strcmp(argv[i], "--tile") == 0)
109  {
110  param = argv[++i];
111  if (!param)
112  return false;
113 
114  char* stileX = strtok(param, ",");
115  char* stileY = strtok(NULL, ",");
116  int tilex = atoi(stileX);
117  int tiley = atoi(stileY);
118 
119  if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX, "0") == 0))
120  tileX = tilex;
121  if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY, "0") == 0))
122  tileY = tiley;
123 
124  if (tileX < 0 || tileY < 0)
125  {
126  printf("invalid tile coords.\n");
127  return false;
128  }
129  }
130  else if (strcmp(argv[i], "--skipLiquid") == 0)
131  {
132  param = argv[++i];
133  if (!param)
134  return false;
135 
136  if (strcmp(param, "true") == 0)
137  skipLiquid = true;
138  else if (strcmp(param, "false") == 0)
139  skipLiquid = false;
140  else
141  printf("invalid option for '--skipLiquid', using default\n");
142  }
143  else if (strcmp(argv[i], "--skipContinents") == 0)
144  {
145  param = argv[++i];
146  if (!param)
147  return false;
148 
149  if (strcmp(param, "true") == 0)
150  skipContinents = true;
151  else if (strcmp(param, "false") == 0)
152  skipContinents = false;
153  else
154  printf("invalid option for '--skipContinents', using default\n");
155  }
156  else if (strcmp(argv[i], "--skipJunkMaps") == 0)
157  {
158  param = argv[++i];
159  if (!param)
160  return false;
161 
162  if (strcmp(param, "true") == 0)
163  skipJunkMaps = true;
164  else if (strcmp(param, "false") == 0)
165  skipJunkMaps = false;
166  else
167  printf("invalid option for '--skipJunkMaps', using default\n");
168  }
169  else if (strcmp(argv[i], "--skipBattlegrounds") == 0)
170  {
171  param = argv[++i];
172  if (!param)
173  return false;
174 
175  if (strcmp(param, "true") == 0)
176  skipBattlegrounds = true;
177  else if (strcmp(param, "false") == 0)
178  skipBattlegrounds = false;
179  else
180  printf("invalid option for '--skipBattlegrounds', using default\n");
181  }
182  else if (strcmp(argv[i], "--debugOutput") == 0)
183  {
184  param = argv[++i];
185  if (!param)
186  return false;
187 
188  if (strcmp(param, "true") == 0)
189  debugOutput = true;
190  else if (strcmp(param, "false") == 0)
191  debugOutput = false;
192  else
193  printf("invalid option for '--debugOutput', using default true\n");
194  }
195  else if (strcmp(argv[i], "--silent") == 0)
196  {
197  silent = true;
198  }
199  else if (strcmp(argv[i], "--bigBaseUnit") == 0)
200  {
201  param = argv[++i];
202  if (!param)
203  return false;
204 
205  if (strcmp(param, "true") == 0)
206  bigBaseUnit = true;
207  else if (strcmp(param, "false") == 0)
208  bigBaseUnit = false;
209  else
210  printf("invalid option for '--bigBaseUnit', using default false\n");
211  }
212  else if (strcmp(argv[i], "--offMeshInput") == 0)
213  {
214  param = argv[++i];
215  if (!param)
216  return false;
217 
218  offMeshInputPath = param;
219  }
220  else
221  {
222  int map = atoi(argv[i]);
223  if (map > 0 || (map == 0 && (strcmp(argv[i], "0") == 0)))
224  mapnum = map;
225  else
226  {
227  printf("invalid map id\n");
228  return false;
229  }
230  }
231  }
232 
233  return true;
234 }
arena_t NULL
Definition: jemalloc_internal.h:624
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)
244 {
245  int threads = 3, mapnum = -1;
246  float maxAngle = 70.0f;
247  int tileX = -1, tileY = -1;
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 = NULL;
256  char* file = NULL;
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, offMeshInputPath);
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.buildMap(uint32(mapnum));
291  else
292  builder.buildAllMaps(threads);
293 
294  if (!silent)
295  printf("Finished. MMAPS were built in %u ms!\n", GetMSTimeDiffToNow(start));
296  return 0;
297 }
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, int &threads)
Definition: PathGenerator.cpp:62
uint32 getMSTime()
Definition: Timer.h:24
arena_t NULL
Definition: jemalloc_internal.h:624
bool checkDirectories(bool debugOutput)
Definition: PathGenerator.cpp:25
int finish(const char *message, int returnValue)
Definition: PathGenerator.cpp:236
uint32_t uint32
Definition: Define.h:150
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:42
uint32_t uint32
Definition: g3dmath.h:168
Definition: MapBuilder.h:76
void printf(BasicWriter< Char > &w, BasicCStringRef< Char > format, ArgList args)
Definition: format.h:3083

+ Here is the call graph for this function: