aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/mmaps_generator/Info/readme.txt6
-rw-r--r--src/tools/mmaps_generator/IntermediateValues.cpp16
-rw-r--r--src/tools/mmaps_generator/IntermediateValues.h14
-rw-r--r--src/tools/mmaps_generator/MapBuilder.cpp17
-rw-r--r--src/tools/mmaps_generator/MapBuilder.h9
-rw-r--r--src/tools/mmaps_generator/PathCommon.h110
-rw-r--r--src/tools/mmaps_generator/PathGenerator.cpp99
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.cpp12
-rw-r--r--src/tools/mmaps_generator/TerrainBuilder.h5
-rw-r--r--src/tools/mmaps_generator/TileBuilder.cpp14
-rw-r--r--src/tools/mmaps_generator/TileBuilder.h7
11 files changed, 155 insertions, 154 deletions
diff --git a/src/tools/mmaps_generator/Info/readme.txt b/src/tools/mmaps_generator/Info/readme.txt
index 5178138c65f..dcd3e635913 100644
--- a/src/tools/mmaps_generator/Info/readme.txt
+++ b/src/tools/mmaps_generator/Info/readme.txt
@@ -1,5 +1,11 @@
R"(Generator command line args
+--input [path] Directory to use for reading maps and vmaps
+ Default: current_directory
+
+--output [path] Directory to write generated data to
+ Default: current_directory
+
--threads [#] Max number of threads used by the generator
Default: Same as CPU cores
diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp
index bb88f1f9c72..39af491f273 100644
--- a/src/tools/mmaps_generator/IntermediateValues.cpp
+++ b/src/tools/mmaps_generator/IntermediateValues.cpp
@@ -31,16 +31,16 @@ namespace MMAP
rcFreePolyMeshDetail(polyMeshDetail);
}
- void IntermediateValues::writeIV(uint32 mapID, uint32 tileX, uint32 tileY)
+ void IntermediateValues::writeIV(boost::filesystem::path const& outputDirectory, uint32 mapID, uint32 tileX, uint32 tileY)
{
TC_LOG_INFO("maps.mmapgen.debug", "[Map {:04}] [{:02},{:02}]: Writing debug output intermediate values...", mapID, tileX, tileY);
- auto debugWrite = [&](char const* extension, auto const* data)
+ auto debugWrite = [=, outputDirectory = outputDirectory.generic_string()](char const* extension, auto const* data)
{
- std::string fileName = Trinity::StringFormat("meshes/{:04}{:02}{:02}.{}", mapID, tileX, tileY, extension);
+ std::string fileName = Trinity::StringFormat("{}/meshes/{:04}{:02}{:02}.{}", outputDirectory, mapID, tileX, tileY, extension);
if (auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "wb")))
{
- this->debugWrite(file.get(), data);
+ IntermediateValues::debugWrite(file.get(), data);
}
else
TC_LOG_ERROR("maps.mmapgen.debug", "{}: [{:04}-{:02},{:02}] Failed to open {} for writing!", strerror(errno), mapID, tileX, tileY, fileName);
@@ -188,10 +188,10 @@ namespace MMAP
fwrite(mesh->meshes, sizeof(int), mesh->nmeshes*4, file);
}
- void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData const& meshData)
+ void IntermediateValues::generateObjFile(boost::filesystem::path const& outputDirectory, uint32 mapID, uint32 tileX, uint32 tileY, MeshData const& meshData)
{
std::string objFileName;
- objFileName = Trinity::StringFormat("meshes/map{:04}{:02}{:02}.obj", mapID, tileX, tileY);
+ objFileName = Trinity::StringFormat("{}/meshes/map{:04}{:02}{:02}.obj", outputDirectory.generic_string(), mapID, tileX, tileY);
auto objFile = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(objFileName.c_str(), "wb"));
if (!objFile)
@@ -221,7 +221,7 @@ namespace MMAP
TC_LOG_INFO("maps.mmapgen.debug", "[Map {:04}] [{:02},{:02}]: Writing debug output object file...", mapID, tileX, tileY);
- objFileName = Trinity::StringFormat("meshes/map{:04}.map", mapID);
+ objFileName = Trinity::StringFormat("{}/meshes/map{:04}.map", outputDirectory.generic_string(), mapID);
objFile.reset(fopen(objFileName.c_str(), "wb"));
if (!objFile)
@@ -233,7 +233,7 @@ namespace MMAP
char b = '\0';
fwrite(&b, sizeof(char), 1, objFile.get());
- objFileName = Trinity::StringFormat("meshes/map{:04}{:02}{:02}.mesh", mapID, tileX, tileY);
+ objFileName = Trinity::StringFormat("{}/meshes/map{:04}{:02}{:02}.mesh", outputDirectory.generic_string(), mapID, tileX, tileY);
objFile.reset(fopen(objFileName.c_str(), "wb"));
if (!objFile)
{
diff --git a/src/tools/mmaps_generator/IntermediateValues.h b/src/tools/mmaps_generator/IntermediateValues.h
index 75ade2259e3..4ef8805f921 100644
--- a/src/tools/mmaps_generator/IntermediateValues.h
+++ b/src/tools/mmaps_generator/IntermediateValues.h
@@ -64,15 +64,15 @@ namespace MMAP
return *this;
}
- void writeIV(uint32 mapID, uint32 tileX, uint32 tileY);
+ void writeIV(boost::filesystem::path const& outputDirectory, uint32 mapID, uint32 tileX, uint32 tileY);
- void debugWrite(FILE* file, rcHeightfield const* mesh);
- void debugWrite(FILE* file, rcCompactHeightfield const* chf);
- void debugWrite(FILE* file, rcContourSet const* cs);
- void debugWrite(FILE* file, rcPolyMesh const* mesh);
- void debugWrite(FILE* file, rcPolyMeshDetail const* mesh);
+ static void debugWrite(FILE* file, rcHeightfield const* mesh);
+ static void debugWrite(FILE* file, rcCompactHeightfield const* chf);
+ static void debugWrite(FILE* file, rcContourSet const* cs);
+ static void debugWrite(FILE* file, rcPolyMesh const* mesh);
+ static void debugWrite(FILE* file, rcPolyMeshDetail const* mesh);
- void generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData const& meshData);
+ void generateObjFile(boost::filesystem::path const& outputDirectory, uint32 mapID, uint32 tileX, uint32 tileY, MeshData const& meshData);
};
}
#endif
diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp
index f6bc2ed47cb..893f4d8e208 100644
--- a/src/tools/mmaps_generator/MapBuilder.cpp
+++ b/src/tools/mmaps_generator/MapBuilder.cpp
@@ -37,7 +37,7 @@ namespace MMAP
{
MapTileBuilder::MapTileBuilder(MapBuilder* mapBuilder, Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep,
bool skipLiquid, bool bigBaseUnit, bool debugOutput, std::vector<OffMeshData> const* offMeshConnections) :
- TileBuilder(maxWalkableAngle, maxWalkableAngleNotSteep, skipLiquid, bigBaseUnit, debugOutput, offMeshConnections),
+ TileBuilder(mapBuilder->m_inputDirectory, mapBuilder->m_outputDirectory, maxWalkableAngle, maxWalkableAngleNotSteep, skipLiquid, bigBaseUnit, debugOutput, offMeshConnections),
m_mapBuilder(mapBuilder),
m_workerThread(&MapTileBuilder::WorkerThread, this)
{
@@ -59,9 +59,12 @@ namespace MMAP
++m_mapBuilder->m_totalTilesProcessed;
}
- MapBuilder::MapBuilder(Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep, bool skipLiquid,
+ MapBuilder::MapBuilder(boost::filesystem::path const& inputDirectory, boost::filesystem::path const& outputDirectory,
+ Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep, bool skipLiquid,
bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds,
bool debugOutput, bool bigBaseUnit, int mapid, char const* offMeshFilePath, unsigned int threads) :
+ m_inputDirectory (inputDirectory),
+ m_outputDirectory (outputDirectory),
m_debugOutput (debugOutput),
m_threads (threads),
m_skipContinents (skipContinents),
@@ -100,7 +103,7 @@ namespace MMAP
void MapBuilder::discoverTiles()
{
boost::filesystem::directory_iterator end;
- for (auto itr = boost::filesystem::directory_iterator("maps"); itr != end; ++itr)
+ for (auto itr = boost::filesystem::directory_iterator(m_inputDirectory / "maps"); itr != end; ++itr)
{
if (!boost::filesystem::is_regular_file(*itr))
continue;
@@ -138,7 +141,7 @@ namespace MMAP
}
}
- for (auto itr = boost::filesystem::directory_iterator("vmaps"); itr != end; ++itr)
+ for (auto itr = boost::filesystem::directory_iterator(m_inputDirectory / "vmaps"); itr != end; ++itr)
{
if (!boost::filesystem::is_directory(*itr))
continue;
@@ -278,7 +281,7 @@ namespace MMAP
}
/**************************************************************************/
- void MapBuilder::buildMeshFromFile(char* name)
+ void MapBuilder::buildMeshFromFile(char const* name)
{
auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(name, "rb"));
if (!file)
@@ -460,7 +463,7 @@ namespace MMAP
return;
}
- std::string fileName = Trinity::StringFormat("mmaps/{:04}.mmap", mapID);
+ std::string fileName = Trinity::StringFormat("{}/mmaps/{:04}.mmap", m_outputDirectory.generic_string(), mapID);
auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "wb"));
if (!file)
@@ -563,7 +566,7 @@ namespace MMAP
/**************************************************************************/
bool MapTileBuilder::shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY) const
{
- std::string fileName = Trinity::StringFormat("mmaps/{:04}{:02}{:02}.mmtile", mapID, tileX, tileY);
+ std::string fileName = Trinity::StringFormat("{}/mmaps/{:04}{:02}{:02}.mmtile", m_outputDirectory.generic_string(), mapID, tileX, tileY);
auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "rb"));
if (!file)
return false;
diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h
index 68ba4c77eff..d475280b577 100644
--- a/src/tools/mmaps_generator/MapBuilder.h
+++ b/src/tools/mmaps_generator/MapBuilder.h
@@ -23,6 +23,7 @@
#include "ProducerConsumerQueue.h"
#include "TerrainBuilder.h"
#include "TileBuilder.h"
+#include <boost/filesystem/path.hpp>
#include <DetourNavMesh.h>
#include <atomic>
#include <span>
@@ -78,7 +79,9 @@ namespace MMAP
friend class MapTileBuilder;
public:
- MapBuilder(Optional<float> maxWalkableAngle,
+ MapBuilder(boost::filesystem::path const& inputDirectory,
+ boost::filesystem::path const& outputDirectory,
+ Optional<float> maxWalkableAngle,
Optional<float> maxWalkableAngleNotSteep,
bool skipLiquid,
bool skipContinents,
@@ -92,7 +95,7 @@ namespace MMAP
~MapBuilder();
- void buildMeshFromFile(char* name);
+ void buildMeshFromFile(char const* name);
// builds an mmap tile for the specified map and its mesh
void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY);
@@ -122,6 +125,8 @@ namespace MMAP
TileList m_tiles;
+ boost::filesystem::path m_inputDirectory;
+ boost::filesystem::path m_outputDirectory;
bool m_debugOutput;
std::vector<OffMeshData> m_offMeshConnections;
diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h
index b0761cc2d9a..3ab2c43afda 100644
--- a/src/tools/mmaps_generator/PathCommon.h
+++ b/src/tools/mmaps_generator/PathCommon.h
@@ -15,64 +15,49 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef _MMAP_COMMON_H
-#define _MMAP_COMMON_H
+#ifndef TRINITYCORE_MMAP_COMMON_H
+#define TRINITYCORE_MMAP_COMMON_H
-#include "Define.h"
-#include <memory>
-#include <string>
+#include "Common.h"
+#include <boost/filesystem/directory.hpp>
+#include <string_view>
#include <unordered_map>
-#include <vector>
-
-#ifndef _WIN32
- #include <cstddef>
- #include <cstring>
- #include <dirent.h>
-#else
- #include <Windows.h>
-#endif
-
-#ifndef _WIN32
- #include <cerrno>
-#endif
-
-namespace VMAP
-{
- class VMapManager;
-}
namespace MMAP
{
- inline bool matchWildcardFilter(char const* filter, char const* str)
+ inline bool matchWildcardFilter(std::string_view filter, std::string_view str)
{
- if (!filter || !str)
+ if (filter.empty() || str.empty())
return false;
+ auto filterItr = filter.begin();
+ auto filterEnd = filter.end();
+ auto strItr = str.begin();
+ auto strEnd = str.end();
+
// end on null character
- while (*filter && *str)
+ while (filterItr != filterEnd && strItr != strEnd)
{
- if (*filter == '*')
+ if (*filterItr == '*')
{
- if (*++filter == '\0') // wildcard at end of filter means all remaing chars match
+ if (++filterItr == filterEnd) // wildcard at end of filter means all remaing chars match
return true;
- for (;;)
+ while (*filterItr != *strItr)
{
- if (*filter == *str)
- break;
- if (*str == '\0')
+ if (strItr == strEnd)
return false; // reached end of string without matching next filter character
- str++;
+ ++strItr;
}
}
- else if (*filter != *str)
+ else if (*filterItr != *strItr)
return false; // mismatch
- filter++;
- str++;
+ ++filterItr;
+ ++strItr;
}
- return ((*filter == '\0' || (*filter == '*' && *++filter == '\0')) && *str == '\0');
+ return (filterItr == filterEnd || (*filterItr == '*' && filterItr + 1 == filterEnd)) && strItr == strEnd;
}
enum ListFilesResult
@@ -81,51 +66,26 @@ namespace MMAP
LISTFILE_OK = 1
};
- inline ListFilesResult getDirContents(std::vector<std::string> &fileList, std::string dirpath = ".", std::string filter = "*")
+ inline 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)
{
- #ifdef WIN32
- HANDLE hFind;
- WIN32_FIND_DATAA findFileInfo;
- std::string directory;
-
- directory = dirpath + "/" + filter;
-
- hFind = FindFirstFileA(directory.c_str(), &findFileInfo);
-
- if (hFind == INVALID_HANDLE_VALUE)
+ boost::system::error_code ec;
+ boost::filesystem::directory_iterator dirItr(dirpath, ec);
+ if (ec)
return LISTFILE_DIRECTORY_NOT_FOUND;
- do
- {
- if (strcmp(findFileInfo.cFileName, ".") != 0 && strcmp(findFileInfo.cFileName, "..") != 0)
- fileList.push_back(std::string(findFileInfo.cFileName));
- }
- while (FindNextFileA(hFind, &findFileInfo));
- FindClose(hFind);
+ for (boost::filesystem::directory_entry const& dirEntry : dirItr)
+ {
+ if (dirEntry.status(ec).type() != type || ec)
+ continue;
- #else
- const char *p = dirpath.c_str();
- DIR * dirp = opendir(p);
- struct dirent * dp;
+ std::string fileName = dirEntry.path().filename().string();
+ if (!matchWildcardFilter(filter, fileName))
+ continue;
- while (dirp)
- {
- errno = 0;
- if ((dp = readdir(dirp)) != nullptr)
- {
- if (strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0 && matchWildcardFilter(filter.c_str(), dp->d_name))
- fileList.push_back(std::string(dp->d_name));
- }
- else
- break;
+ fileList.push_back(std::move(fileName));
}
- if (dirp)
- closedir(dirp);
- else
- return LISTFILE_DIRECTORY_NOT_FOUND;
- #endif
-
return LISTFILE_OK;
}
diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp
index af4eb816626..452c63855fc 100644
--- a/src/tools/mmaps_generator/PathGenerator.cpp
+++ b/src/tools/mmaps_generator/PathGenerator.cpp
@@ -87,9 +87,10 @@ void SetupLogging(Trinity::Asio::IoContext* ioContext)
log->CreateLoggerFromConfigLine("Logger.maps.mmapgen", "2,Console"); // LOG_LEVEL_DEBUG | Console appender
}
-bool checkDirectories(bool debugOutput, std::vector<std::string>& dbcLocales)
+bool checkDirectories(boost::filesystem::path const& inputDirectory, boost::filesystem::path const& outputDirectory,
+ bool debugOutput, std::vector<std::string>& dbcLocales)
{
- if (MMAP::getDirContents(dbcLocales, "dbc") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dbcLocales.empty())
+ if (MMAP::getDirContents(dbcLocales, inputDirectory / "dbc", boost::filesystem::directory_file) == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dbcLocales.empty())
{
TC_LOG_ERROR("tool.mmapgen", "'dbc' directory is empty or does not exist");
return false;
@@ -97,39 +98,32 @@ bool checkDirectories(bool debugOutput, std::vector<std::string>& dbcLocales)
std::vector<std::string> dirFiles;
- if (MMAP::getDirContents(dirFiles, "maps") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
+ if (MMAP::getDirContents(dirFiles, inputDirectory / "maps") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
{
TC_LOG_ERROR("tool.mmapgen", "'maps' directory is empty or does not exist");
return false;
}
dirFiles.clear();
- if (MMAP::getDirContents(dirFiles, "vmaps/0000", "*.vmtree") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
+ if (MMAP::getDirContents(dirFiles, inputDirectory / "vmaps" / "0000", boost::filesystem::regular_file, "*.vmtree") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND || dirFiles.empty())
{
TC_LOG_ERROR("tool.mmapgen", "'vmaps' directory is empty or does not exist");
return false;
}
- dirFiles.clear();
- if (MMAP::getDirContents(dirFiles, "mmaps") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND)
+ boost::system::error_code ec;
+ if (!boost::filesystem::create_directories(outputDirectory / "mmaps", ec) && ec)
{
- if (!boost::filesystem::create_directory("mmaps"))
- {
- TC_LOG_ERROR("tool.mmapgen", "'mmaps' directory does not exist and failed to create it");
- return false;
- }
+ TC_LOG_ERROR("tool.mmapgen", "'mmaps' directory does not exist and failed to create it");
+ return false;
}
- dirFiles.clear();
if (debugOutput)
{
- if (MMAP::getDirContents(dirFiles, "meshes") == MMAP::LISTFILE_DIRECTORY_NOT_FOUND)
+ if (!boost::filesystem::create_directories(outputDirectory / "meshes", ec) && ec)
{
- if (!boost::filesystem::create_directory("meshes"))
- {
- TC_LOG_ERROR("tool.mmapgen", "'meshes' directory does not exist and failed to create it (no place to put debugOutput files)");
- return false;
- }
+ TC_LOG_ERROR("tool.mmapgen", "'meshes' directory does not exist and failed to create it (no place to put debugOutput files)");
+ return false;
}
}
@@ -144,21 +138,23 @@ int finish(char const* message, int returnValue)
}
bool handleArgs(int argc, char** argv,
- int &mapnum,
- int &tileX,
- int &tileY,
+ int& mapnum,
+ int& tileX,
+ int& tileY,
Optional<float>& maxAngle,
Optional<float>& maxAngleNotSteep,
- bool &skipLiquid,
- bool &skipContinents,
- bool &skipJunkMaps,
- bool &skipBattlegrounds,
- bool &debugOutput,
- bool &silent,
- bool &bigBaseUnit,
- char* &offMeshInputPath,
- char* &file,
- unsigned int& threads)
+ bool& skipLiquid,
+ bool& skipContinents,
+ bool& skipJunkMaps,
+ bool& skipBattlegrounds,
+ bool& debugOutput,
+ bool& silent,
+ bool& bigBaseUnit,
+ char const*& offMeshInputPath,
+ char const*& file,
+ unsigned int& threads,
+ boost::filesystem::path& inputDirectory,
+ boost::filesystem::path& outputDirectory)
{
char* param = nullptr;
[[maybe_unused]] bool allowDebug = false;
@@ -314,6 +310,22 @@ bool handleArgs(int argc, char** argv,
offMeshInputPath = param;
}
+ else if (strcmp(argv[i], "--input") == 0)
+ {
+ param = argv[++i];
+ if (!param)
+ return false;
+
+ inputDirectory = param;
+ }
+ else if (strcmp(argv[i], "--output") == 0)
+ {
+ param = argv[++i];
+ if (!param)
+ return false;
+
+ outputDirectory = param;
+ }
else if (strcmp(argv[i], "--allowDebug") == 0)
{
allowDebug = true;
@@ -349,11 +361,11 @@ bool handleArgs(int argc, char** argv,
return true;
}
-std::unordered_map<uint32, uint8> LoadLiquid(std::string const& locale, bool silent, int32 errorExitCode)
+std::unordered_map<uint32, uint8> LoadLiquid(boost::filesystem::path const& inputDirectory, std::string const& locale, bool silent, int32 errorExitCode)
{
DB2FileLoader liquidDb2;
std::unordered_map<uint32, uint8> liquidData;
- DB2FileSystemSource liquidTypeSource((boost::filesystem::path("dbc") / locale / "LiquidType.db2").string());
+ DB2FileSystemSource liquidTypeSource((inputDirectory / "dbc" / locale / "LiquidType.db2").string());
try
{
liquidDb2.Load(&liquidTypeSource, &LiquidTypeLoadInfo::Instance);
@@ -377,10 +389,10 @@ std::unordered_map<uint32, uint8> LoadLiquid(std::string const& locale, bool sil
return liquidData;
}
-void LoadMap(std::string const& locale, bool silent, int32 errorExitCode)
+void LoadMap(boost::filesystem::path const& inputDirectory, std::string const& locale, bool silent, int32 errorExitCode)
{
DB2FileLoader mapDb2;
- DB2FileSystemSource mapSource((boost::filesystem::path("dbc") / locale / "Map.db2").string());
+ DB2FileSystemSource mapSource((inputDirectory / "dbc" / locale / "Map.db2").string());
try
{
mapDb2.Load(&mapSource, &MapLoadInfo::Instance);
@@ -442,13 +454,16 @@ int main(int argc, char** argv)
debugOutput = false,
silent = false,
bigBaseUnit = false;
- char* offMeshInputPath = nullptr;
- char* file = nullptr;
+ char const* offMeshInputPath = nullptr;
+ char const* file = nullptr;
+ boost::filesystem::path inputDirectory = boost::filesystem::current_path();
+ boost::filesystem::path outputDirectory = boost::filesystem::current_path();
bool validParam = handleArgs(argc, argv, mapnum,
tileX, tileY, maxAngle, maxAngleNotSteep,
skipLiquid, skipContinents, skipJunkMaps, skipBattlegrounds,
- debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads);
+ debugOutput, silent, bigBaseUnit, offMeshInputPath, file, threads,
+ inputDirectory, outputDirectory);
if (!validParam)
return silent ? -1 : finish("You have specified invalid parameters", -1);
@@ -466,14 +481,14 @@ int main(int argc, char** argv)
}
std::vector<std::string> dbcLocales;
- if (!checkDirectories(debugOutput, dbcLocales))
+ if (!checkDirectories(inputDirectory, outputDirectory, debugOutput, dbcLocales))
return silent ? -3 : finish("Press ENTER to close...", -3);
- _liquidTypes = LoadLiquid(dbcLocales[0], silent, -5);
+ _liquidTypes = LoadLiquid(inputDirectory, dbcLocales[0], silent, -5);
- LoadMap(dbcLocales[0], silent, -4);
+ LoadMap(inputDirectory, dbcLocales[0], silent, -4);
- MMAP::MapBuilder builder(maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
+ MMAP::MapBuilder builder(inputDirectory, outputDirectory, maxAngle, maxAngleNotSteep, skipLiquid, skipContinents, skipJunkMaps,
skipBattlegrounds, debugOutput, bigBaseUnit, mapnum, offMeshInputPath, threads);
uint32 start = getMSTime();
diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp
index 241a724a46f..9f452634a09 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.cpp
+++ b/src/tools/mmaps_generator/TerrainBuilder.cpp
@@ -29,7 +29,11 @@
namespace MMAP
{
- TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid){ }
+ TerrainBuilder::TerrainBuilder(boost::filesystem::path const& inputDirectory, bool skipLiquid) :
+ m_inputDirectory(inputDirectory),
+ m_skipLiquid (skipLiquid)
+ {
+ }
/**************************************************************************/
void TerrainBuilder::getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc)
@@ -79,7 +83,7 @@ namespace MMAP
/**************************************************************************/
bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager, Spot portion)
{
- std::string mapFileName = Trinity::StringFormat("maps/{:04}_{:02}_{:02}.map", mapID, tileX, tileY);
+ std::string mapFileName = Trinity::StringFormat("{}/maps/{:04}_{:02}_{:02}.map", m_inputDirectory.generic_string(), mapID, tileX, tileY);
auto mapFile = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(mapFileName.c_str(), "rb"));
if (!mapFile)
@@ -87,7 +91,7 @@ namespace MMAP
int32 parentMapId = vmapManager->getParentMapId(mapID);
while (!mapFile && parentMapId != -1)
{
- mapFileName = Trinity::StringFormat("maps/{:04}_{:02}_{:02}.map", parentMapId, tileX, tileY);
+ mapFileName = Trinity::StringFormat("{}/maps/{:04}_{:02}_{:02}.map", m_inputDirectory.generic_string(), parentMapId, tileX, tileY);
mapFile.reset(fopen(mapFileName.c_str(), "rb"));
parentMapId = vmapManager->getParentMapId(parentMapId);
}
@@ -563,7 +567,7 @@ namespace MMAP
/**************************************************************************/
bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager)
{
- VMAP::LoadResult result = vmapManager->loadMap("vmaps", mapID, tileX, tileY);
+ VMAP::LoadResult result = vmapManager->loadMap((m_inputDirectory / "vmaps").string(), mapID, tileX, tileY);
if (result != VMAP::LoadResult::Success)
return false;
diff --git a/src/tools/mmaps_generator/TerrainBuilder.h b/src/tools/mmaps_generator/TerrainBuilder.h
index c1c01e2d0db..1865696ed7e 100644
--- a/src/tools/mmaps_generator/TerrainBuilder.h
+++ b/src/tools/mmaps_generator/TerrainBuilder.h
@@ -20,6 +20,7 @@
#include "WorldModel.h"
#include <G3D/Vector3.h>
+#include <boost/filesystem/path.hpp>
namespace VMAP
{
@@ -93,7 +94,7 @@ namespace MMAP
class TerrainBuilder
{
public:
- explicit TerrainBuilder(bool skipLiquid);
+ explicit TerrainBuilder(boost::filesystem::path const& inputDirectory, bool skipLiquid);
void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager);
bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, VMAP::VMapManager* vmapManager);
@@ -114,6 +115,8 @@ namespace MMAP
/// Sets loop variables for selecting only certain parts of a map's terrain
static void getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc);
+ boost::filesystem::path m_inputDirectory;
+
/// Controls whether liquids are loaded
bool m_skipLiquid;
diff --git a/src/tools/mmaps_generator/TileBuilder.cpp b/src/tools/mmaps_generator/TileBuilder.cpp
index eff2f7bcf59..2403d130584 100644
--- a/src/tools/mmaps_generator/TileBuilder.cpp
+++ b/src/tools/mmaps_generator/TileBuilder.cpp
@@ -69,13 +69,15 @@ namespace MMAP
int TILES_PER_MAP;
};
- TileBuilder::TileBuilder(Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep,
+ TileBuilder::TileBuilder(boost::filesystem::path const& inputDirectory, boost::filesystem::path const& outputDirectory,
+ Optional<float> maxWalkableAngle, Optional<float> maxWalkableAngleNotSteep,
bool skipLiquid, bool bigBaseUnit, bool debugOutput, std::vector<OffMeshData> const* offMeshConnections) :
+ m_outputDirectory(outputDirectory),
m_maxWalkableAngle(maxWalkableAngle),
m_maxWalkableAngleNotSteep(maxWalkableAngleNotSteep),
m_bigBaseUnit(bigBaseUnit),
m_debugOutput(debugOutput),
- m_terrainBuilder(skipLiquid),
+ m_terrainBuilder(inputDirectory, skipLiquid),
m_rcContext(false),
m_offMeshConnections(offMeshConnections)
{
@@ -375,7 +377,7 @@ namespace MMAP
// will hold final navmesh
unsigned char* navData = nullptr;
- auto debugOutputWriter = Trinity::make_unique_ptr_with_deleter(m_debugOutput ? &iv : nullptr, [=, borderSize = static_cast<unsigned short>(config.borderSize), &meshData](IntermediateValues* intermediate)
+ auto debugOutputWriter = Trinity::make_unique_ptr_with_deleter(m_debugOutput ? &iv : nullptr, [borderSize = static_cast<unsigned short>(config.borderSize), outputDir = &m_outputDirectory, mapID, tileX, tileY, &meshData](IntermediateValues* intermediate)
{
// restore padding so that the debug visualization is correct
for (std::ptrdiff_t i = 0; i < intermediate->polyMesh->nverts; ++i)
@@ -385,8 +387,8 @@ namespace MMAP
v[2] += borderSize;
}
- intermediate->generateObjFile(mapID, tileX, tileY, meshData);
- intermediate->writeIV(mapID, tileX, tileY);
+ intermediate->generateObjFile(*outputDir, mapID, tileX, tileY, meshData);
+ intermediate->writeIV(*outputDir, mapID, tileX, tileY);
});
// these values are checked within dtCreateNavMeshData - handle them here
@@ -462,7 +464,7 @@ namespace MMAP
}
// file output
- std::string fileName = Trinity::StringFormat("mmaps/{:04}{:02}{:02}.mmtile", mapID, tileX, tileY);
+ std::string fileName = Trinity::StringFormat("{}/mmaps/{:04}{:02}{:02}.mmtile", m_outputDirectory.generic_string(), mapID, tileX, tileY);
auto file = Trinity::make_unique_ptr_with_deleter<&::fclose>(fopen(fileName.c_str(), "wb"));
if (!file)
{
diff --git a/src/tools/mmaps_generator/TileBuilder.h b/src/tools/mmaps_generator/TileBuilder.h
index f533a3d1afa..9c6d015b6cc 100644
--- a/src/tools/mmaps_generator/TileBuilder.h
+++ b/src/tools/mmaps_generator/TileBuilder.h
@@ -34,7 +34,9 @@ using detour_unique_ptr = std::unique_ptr<unsigned char, decltype(Trinity::uniqu
class TileBuilder
{
public:
- TileBuilder(Optional<float> maxWalkableAngle,
+ TileBuilder(boost::filesystem::path const& inputDirectory,
+ boost::filesystem::path const& outputDirectory,
+ Optional<float> maxWalkableAngle,
Optional<float> maxWalkableAngleNotSteep,
bool skipLiquid,
bool bigBaseUnit,
@@ -79,7 +81,8 @@ public:
virtual void OnTileDone() { }
-private:
+protected:
+ boost::filesystem::path m_outputDirectory;
Optional<float> m_maxWalkableAngle;
Optional<float> m_maxWalkableAngleNotSteep;
bool m_bigBaseUnit;