31#include <boost/filesystem/operations.hpp>
32#include <unordered_map>
37#include "Info/readme.txt"
42 std::unordered_map<uint32, uint8> _liquidTypes;
53 std::unique_ptr<VMAP::VMapManager> vmgr = std::make_unique<VMAP::VMapManager>();
59 vmgr->InitializeThreadUnsafe(mapId, parentMapId);
68 auto itr = _liquidTypes.find(liquidId);
69 return itr != _liquidTypes.end() ? (1 << itr->second) : 0;
71 vmgr->LoadPathOnlyModels =
true;
90bool checkDirectories(boost::filesystem::path
const& inputDirectory, boost::filesystem::path
const& outputDirectory,
91 bool debugOutput, std::vector<std::string>& dbcLocales)
95 TC_LOG_ERROR(
"tool.mmapgen",
"'dbc' directory is empty or does not exist");
99 std::vector<std::string> dirFiles;
103 TC_LOG_ERROR(
"tool.mmapgen",
"'maps' directory is empty or does not exist");
110 TC_LOG_ERROR(
"tool.mmapgen",
"'vmaps' directory is empty or does not exist");
114 boost::system::error_code ec;
115 if (!boost::filesystem::create_directories(outputDirectory /
"mmaps", ec) && ec)
117 TC_LOG_ERROR(
"tool.mmapgen",
"'mmaps' directory does not exist and failed to create it");
123 if (!boost::filesystem::create_directories(outputDirectory /
"meshes", ec) && ec)
125 TC_LOG_ERROR(
"tool.mmapgen",
"'meshes' directory does not exist and failed to create it (no place to put debugOutput files)");
133int finish(
char const* message,
int returnValue)
135 TC_LOG_FATAL(
"tool.mmapgen.commandline",
"{}", message);
147 bool& skipContinents,
149 bool& skipBattlegrounds,
153 char const*& offMeshInputPath,
155 unsigned int& threads,
156 boost::filesystem::path& inputDirectory,
157 boost::filesystem::path& outputDirectory)
159 char* param =
nullptr;
160 [[maybe_unused]]
bool allowDebug =
false;
161 for (
int i = 1; i < argc; ++i)
163 if (strcmp(argv[i],
"--maxAngle") == 0)
169 float maxangle = atof(param);
170 if (maxangle <= 90.f && maxangle >= 0.f)
173 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--maxAngle', using default");
175 else if (strcmp(argv[i],
"--maxAngleNotSteep") == 0)
181 float maxangle = atof(param);
182 if (maxangle <= 90.f && maxangle >= 0.f)
183 maxAngleNotSteep = maxangle;
185 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--maxAngleNotSteep', using default");
187 else if (strcmp(argv[i],
"--threads") == 0)
192 threads =
static_cast<unsigned int>(std::max(0, atoi(param)));
194 else if (strcmp(argv[i],
"--file") == 0)
201 else if (strcmp(argv[i],
"--tile") == 0)
207 char* stileX = strtok(param,
",");
208 char* stileY = strtok(
nullptr,
",");
209 int tilex = atoi(stileX);
210 int tiley = atoi(stileY);
212 if ((tilex > 0 && tilex < 64) || (tilex == 0 && strcmp(stileX,
"0") == 0))
214 if ((tiley > 0 && tiley < 64) || (tiley == 0 && strcmp(stileY,
"0") == 0))
217 if (tileX < 0 || tileY < 0)
219 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid tile coords.");
223 else if (strcmp(argv[i],
"--skipLiquid") == 0)
229 if (strcmp(param,
"true") == 0)
231 else if (strcmp(param,
"false") == 0)
234 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--skipLiquid', using default");
236 else if (strcmp(argv[i],
"--skipContinents") == 0)
242 if (strcmp(param,
"true") == 0)
243 skipContinents =
true;
244 else if (strcmp(param,
"false") == 0)
245 skipContinents =
false;
247 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--skipContinents', using default");
249 else if (strcmp(argv[i],
"--skipJunkMaps") == 0)
255 if (strcmp(param,
"true") == 0)
257 else if (strcmp(param,
"false") == 0)
258 skipJunkMaps =
false;
260 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--skipJunkMaps', using default");
262 else if (strcmp(argv[i],
"--skipBattlegrounds") == 0)
268 if (strcmp(param,
"true") == 0)
269 skipBattlegrounds =
true;
270 else if (strcmp(param,
"false") == 0)
271 skipBattlegrounds =
false;
273 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--skipBattlegrounds', using default");
275 else if (strcmp(argv[i],
"--debugOutput") == 0)
281 if (strcmp(param,
"true") == 0)
283 else if (strcmp(param,
"false") == 0)
286 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--debugOutput', using default true");
288 else if (strcmp(argv[i],
"--silent") == 0)
292 else if (strcmp(argv[i],
"--bigBaseUnit") == 0)
298 if (strcmp(param,
"true") == 0)
300 else if (strcmp(param,
"false") == 0)
303 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid option for '--bigBaseUnit', using default false");
305 else if (strcmp(argv[i],
"--offMeshInput") == 0)
311 offMeshInputPath = param;
313 else if (strcmp(argv[i],
"--input") == 0)
319 inputDirectory = param;
321 else if (strcmp(argv[i],
"--output") == 0)
327 outputDirectory = param;
329 else if (strcmp(argv[i],
"--allowDebug") == 0)
333 else if (!strcmp(argv[i],
"--help") || !strcmp(argv[i],
"-?"))
341 int map = atoi(argv[i]);
342 if (map > 0 || (map == 0 && (strcmp(argv[i],
"0") == 0)))
346 TC_LOG_ERROR(
"tool.mmapgen.commandline",
"invalid map id {}", map);
355 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.", -2);
364std::unordered_map<uint32, uint8>
LoadLiquid(boost::filesystem::path
const& inputDirectory, std::string
const& locale,
bool silent,
int32 errorExitCode)
367 std::unordered_map<uint32, uint8> liquidData;
368 DB2FileSystemSource liquidTypeSource((inputDirectory /
"dbc" / locale /
"LiquidType.db2").
string());
381 catch (std::exception
const& e)
386 exit(
finish(e.what(), errorExitCode));
392void LoadMap(boost::filesystem::path
const& inputDirectory, std::string
const& locale,
bool silent,
int32 errorExitCode)
416 catch (std::exception
const& e)
421 exit(
finish(e.what(), errorExitCode));
435 std::thread loggingThread;
437 auto workGuard = std::pair(
446 unsigned int threads = std::thread::hardware_concurrency();
448 int tileX = -1, tileY = -1;
450 bool skipLiquid =
false,
451 skipContinents =
false,
453 skipBattlegrounds =
false,
457 char const* offMeshInputPath =
nullptr;
458 char const* file =
nullptr;
459 boost::filesystem::path inputDirectory = boost::filesystem::current_path();
460 boost::filesystem::path outputDirectory = boost::filesystem::current_path();
462 bool validParam =
handleArgs(argc, argv, mapnum,
463 tileX, tileY, maxAngle, maxAngleNotSteep,
464 skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
465 debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads,
466 inputDirectory, outputDirectory);
469 return silent ? -1 :
finish(
"You have specified invalid parameters", -1);
471 if (mapnum == -1 && debugOutput)
476 TC_LOG_INFO(
"tool.mmapgen",
"You have specifed debug output, but didn't specify a map to generate.");
477 TC_LOG_INFO(
"tool.mmapgen",
"This will generate debug output for ALL maps.");
478 TC_LOG_INFO(
"tool.mmapgen",
"Are you sure you want to continue? (y/n)");
479 if (getchar() !=
'y')
483 std::vector<std::string> dbcLocales;
484 if (!
checkDirectories(inputDirectory, outputDirectory, debugOutput, dbcLocales))
485 return silent ? -3 :
finish(
"Press ENTER to close...", -3);
487 _liquidTypes =
LoadLiquid(inputDirectory, dbcLocales[0], silent, -5);
489 LoadMap(inputDirectory, dbcLocales[0], silent, -4);
493 MMAP::MapBuilder builder(inputDirectory, outputDirectory, maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
494 skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
499 else if (tileX > -1 && tileY > -1 && mapnum >= 0)
501 else if (mapnum >= 0)
512#if TRINITY_PLATFORM == TRINITY_PLATFORM_WINDOWS
#define TC_LOG_ERROR(filterType__, message__,...)
#define TC_LOG_FATAL(filterType__, message__,...)
#define TC_LOG_INFO(filterType__, message__,...)
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 CreateAppenderFromConfigLine(std::string const &name, std::string const &options)
void CreateLoggerFromConfigLine(std::string const &name, std::string const &options)
void SetAsynchronous(Trinity::Asio::IoContext *ioContext)
void buildMeshFromFile(char const *name)
void buildMaps(Optional< uint32 > mapID)
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY)
Executor get_executor() noexcept
std::unique_ptr< VMAP::VMapManager > CreateVMapManager(uint32 mapId)
@ LISTFILE_DIRECTORY_NOT_FOUND
std::unique_ptr< VMAP::VMapManager >(* CreateVMapManager)(uint32 mapId)
ListFilesResult getDirContents(std::vector< std::string > &fileList, boost::filesystem::path const &dirpath, boost::filesystem::file_type type=boost::filesystem::regular_file, std::string_view filter="*"sv)
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()
std::unique_ptr< T, Impl::stateful_unique_ptr_deleter< Ptr, Del > > make_unique_ptr_with_deleter(Ptr ptr, Del deleter)
static constexpr DB2LoadInfo Instance
static constexpr DB2LoadInfo Instance