28#include <boost/filesystem/operations.hpp>
29#include <unordered_map>
34#include "Info/readme.txt"
39 std::unordered_map<uint32, uint8> _liquidTypes;
40 std::unordered_map<uint32, std::vector<uint32>> _mapDataForVmapInitialization;
51 std::unique_ptr<VMAP::VMapManager2> vmgr = std::make_unique<VMAP::VMapManager2>();
52 vmgr->InitializeThreadUnsafe(_mapDataForVmapInitialization);
55 auto itr = _liquidTypes.find(liquidId);
56 return itr != _liquidTypes.end() ? (1 << itr->second) : 0;
69 printf(
"'dbc' directory is empty or does not exist\n");
73 std::vector<std::string> dirFiles;
77 printf(
"'maps' directory is empty or does not exist\n");
84 printf(
"'vmaps' directory is empty or does not exist\n");
91 if (!boost::filesystem::create_directory(
"mmaps"))
93 printf(
"'mmaps' directory does not exist and failed to create it\n");
103 if (!boost::filesystem::create_directory(
"meshes"))
105 printf(
"'meshes' directory does not exist and failed to create it (no place to put debugOutput files)\n");
114int finish(
char const* message,
int returnValue)
116 printf(
"%s", message);
128 bool &skipContinents,
130 bool &skipBattlegrounds,
134 char* &offMeshInputPath,
136 unsigned int& threads)
138 char* param =
nullptr;
139 [[maybe_unused]]
bool allowDebug =
false;
140 for (
int i = 1; i < argc; ++i)
142 if (strcmp(argv[i],
"--maxAngle") == 0)
148 float maxangle = atof(param);
149 if (maxangle <= 90.f && maxangle >= 0.f)
152 printf(
"invalid option for '--maxAngle', using default\n");
154 else if (strcmp(argv[i],
"--maxAngleNotSteep") == 0)
160 float maxangle = atof(param);
161 if (maxangle <= 90.f && maxangle >= 0.f)
162 maxAngleNotSteep = maxangle;
164 printf(
"invalid option for '--maxAngleNotSteep', using default\n");
166 else if (strcmp(argv[i],
"--threads") == 0)
171 threads =
static_cast<unsigned int>(std::max(0, atoi(param)));
173 else if (strcmp(argv[i],
"--file") == 0)
180 else if (strcmp(argv[i],
"--tile") == 0)
186 char* stileX = strtok(param,
",");
187 char* stileY = strtok(
nullptr,
",");
188 int tilex = atoi(stileX);
189 int tiley = atoi(stileY);
191 if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX,
"0") == 0))
193 if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY,
"0") == 0))
196 if (tileX < 0 || tileY < 0)
198 printf(
"invalid tile coords.\n");
202 else if (strcmp(argv[i],
"--skipLiquid") == 0)
208 if (strcmp(param,
"true") == 0)
210 else if (strcmp(param,
"false") == 0)
213 printf(
"invalid option for '--skipLiquid', using default\n");
215 else if (strcmp(argv[i],
"--skipContinents") == 0)
221 if (strcmp(param,
"true") == 0)
222 skipContinents =
true;
223 else if (strcmp(param,
"false") == 0)
224 skipContinents =
false;
226 printf(
"invalid option for '--skipContinents', using default\n");
228 else if (strcmp(argv[i],
"--skipJunkMaps") == 0)
234 if (strcmp(param,
"true") == 0)
236 else if (strcmp(param,
"false") == 0)
237 skipJunkMaps =
false;
239 printf(
"invalid option for '--skipJunkMaps', using default\n");
241 else if (strcmp(argv[i],
"--skipBattlegrounds") == 0)
247 if (strcmp(param,
"true") == 0)
248 skipBattlegrounds =
true;
249 else if (strcmp(param,
"false") == 0)
250 skipBattlegrounds =
false;
252 printf(
"invalid option for '--skipBattlegrounds', using default\n");
254 else if (strcmp(argv[i],
"--debugOutput") == 0)
260 if (strcmp(param,
"true") == 0)
262 else if (strcmp(param,
"false") == 0)
265 printf(
"invalid option for '--debugOutput', using default true\n");
267 else if (strcmp(argv[i],
"--silent") == 0)
271 else if (strcmp(argv[i],
"--bigBaseUnit") == 0)
277 if (strcmp(param,
"true") == 0)
279 else if (strcmp(param,
"false") == 0)
282 printf(
"invalid option for '--bigBaseUnit', using default false\n");
284 else if (strcmp(argv[i],
"--offMeshInput") == 0)
290 offMeshInputPath = param;
292 else if (strcmp(argv[i],
"--allowDebug") == 0)
296 else if (!strcmp(argv[i],
"--help") || !strcmp(argv[i],
"-?"))
304 int map = atoi(argv[i]);
305 if (map > 0 || (map == 0 && (strcmp(argv[i],
"0") == 0)))
309 printf(
"invalid map id\n");
318 finish(
"Build mmaps_generator in RelWithDebInfo or Release mode or it will take hours to complete!!!\nUse '--allowDebug' argument if you really want to run this tool in Debug.\n", -2);
327std::unordered_map<uint32, uint8>
LoadLiquid(std::string
const& locale,
bool silent,
int32 errorExitCode)
330 std::unordered_map<uint32, uint8> liquidData;
331 DB2FileSystemSource liquidTypeSource((boost::filesystem::path(
"dbc") / locale /
"LiquidType.db2").
string());
344 catch (std::exception
const& e)
349 exit(
finish(e.what(), errorExitCode));
355std::unordered_map<uint32, std::vector<uint32>>
LoadMap(std::string
const& locale,
bool silent,
int32 errorExitCode)
358 std::unordered_map<uint32, std::vector<uint32>> mapData;
359 DB2FileSystemSource mapSource((boost::filesystem::path(
"dbc") / locale /
"Map.db2").
string());
369 mapData.emplace(std::piecewise_construct, std::forward_as_tuple(record.
GetId()), std::forward_as_tuple());
373 if (parentMapId != -1)
374 mapData[parentMapId].push_back(record.
GetId());
383 catch (std::exception
const& e)
388 exit(
finish(e.what(), errorExitCode));
402 unsigned int threads = std::thread::hardware_concurrency();
404 int tileX = -1, tileY = -1;
406 bool skipLiquid =
false,
407 skipContinents =
false,
409 skipBattlegrounds =
false,
413 char* offMeshInputPath =
nullptr;
414 char* file =
nullptr;
416 bool validParam =
handleArgs(argc, argv, mapnum,
417 tileX, tileY, maxAngle, maxAngleNotSteep,
418 skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
419 debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
422 return silent ? -1 :
finish(
"You have specified invalid parameters", -1);
424 if (mapnum == -1 && debugOutput)
429 printf(
"You have specifed debug output, but didn't specify a map to generate.\n");
430 printf(
"This will generate debug output for ALL maps.\n");
431 printf(
"Are you sure you want to continue? (y/n) ");
432 if (getchar() !=
'y')
436 std::vector<std::string> dbcLocales;
438 return silent ? -3 :
finish(
"Press ENTER to close...", -3);
440 _liquidTypes =
LoadLiquid(dbcLocales[0], silent, -5);
442 _mapDataForVmapInitialization =
LoadMap(dbcLocales[0], silent, -4);
444 MapBuilder builder(maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
445 skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
450 else if (tileX > -1 && tileY > -1 && mapnum >= 0)
452 else if (mapnum >= 0)
DB2Storage< MapEntry > sMapStore("Map.db2", &MapLoadInfo::Instance)
std::optional< T > Optional
Optional helper class to wrap optional values within.
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
std::string secsToTimeString(uint64 timeInSecs, TimeFormat timeFormat, bool hoursOnly)
void Load(DB2FileSource *source, DB2FileLoadInfo const *loadInfo)
DB2Record GetRecord(uint32 recordNumber) const
uint32 GetRecordCount() const
int32 GetInt32(uint32 field, uint32 arrayIndex) const
uint16 GetUInt16(uint32 field, uint32 arrayIndex) const
uint8 GetUInt8(uint32 field, uint32 arrayIndex) const
void buildMaps(Optional< uint32 > mapID)
void buildMeshFromFile(char *name)
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY)
std::unique_ptr< VMAP::VMapManager2 > CreateVMapManager()
@ LISTFILE_DIRECTORY_NOT_FOUND
ListFilesResult getDirContents(std::vector< std::string > &fileList, std::string dirpath=".", std::string filter="*")
std::unordered_map< uint32, MapEntry > sMapStore
TC_COMMON_API void Show(char const *applicationName, void(*log)(char const *text), void(*logExtraInfo)())
TC_COMMON_API void Init()
TC_COMMON_API void VerifyOsVersion()
static constexpr DB2LoadInfo Instance
static constexpr DB2LoadInfo Instance