aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-07-06 14:06:20 +0200
committerOvahlord <dreadkiller@gmx.de>2024-07-06 15:36:47 +0200
commit134b602b959864b4c04b9762152d55dab02efa0b (patch)
tree724553d03234388a1bac8a1e62fa8ee58144a5ee /src/tools
parentf40c4e32182d7696b234d0eda5e1de6cd6f273ae (diff)
Tools/vmap_assembler: Use boost::filesystem::path for creating filenames
(cherry picked from commit 51d1ff11bcd29ca5b58ce24b622b1634d1366873)
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/vmap4_assembler/TileAssembler.cpp64
-rw-r--r--src/tools/vmap4_assembler/TileAssembler.h18
-rw-r--r--src/tools/vmap4_assembler/VMapAssembler.cpp2
3 files changed, 41 insertions, 43 deletions
diff --git a/src/tools/vmap4_assembler/TileAssembler.cpp b/src/tools/vmap4_assembler/TileAssembler.cpp
index 6be3e1b70b6..ab2ec472d61 100644
--- a/src/tools/vmap4_assembler/TileAssembler.cpp
+++ b/src/tools/vmap4_assembler/TileAssembler.cpp
@@ -36,6 +36,11 @@ template<> struct BoundsTrait<VMAP::ModelSpawn*>
namespace VMAP
{
+ static auto OpenFile(boost::filesystem::path const& p, char const* mode)
+ {
+ return Trinity::make_unique_ptr_with_deleter(fopen(p.string().c_str(), mode), &::fclose);
+ }
+
G3D::Vector3 ModelPosition::transform(G3D::Vector3 const& pIn) const
{
G3D::Vector3 out = pIn * iScale;
@@ -45,18 +50,18 @@ namespace VMAP
//=================================================================
- TileAssembler::TileAssembler(std::string srcDirName, std::string destDirName, uint32 threads)
- : iSrcDir(std::move(srcDirName)), iDestDir(std::move(destDirName)), iThreads(threads)
+ TileAssembler::TileAssembler(std::string const& srcDirName, std::string const& destDirName, uint32 threads)
+ : iSrcDir(srcDirName), iDestDir(destDirName), iThreads(threads)
{
}
bool TileAssembler::convertWorld2()
{
boost::system::error_code ec;
- Trinity::IteratorPair dirBin(boost::filesystem::directory_iterator(iSrcDir + "/dir_bin", ec), {});
+ Trinity::IteratorPair dirBin(boost::filesystem::directory_iterator(iSrcDir / "dir_bin", ec), {});
if (ec)
{
- printf("Failed to open input %s/dir_bin: %s\n", iSrcDir.c_str(), ec.message().c_str());
+ printf("Failed to open input %s/dir_bin: %s\n", iSrcDir.string().c_str(), ec.message().c_str());
return false;
}
@@ -65,7 +70,7 @@ namespace VMAP
boost::system::error_code existsErr;
if (!boost::filesystem::exists(iDestDir, existsErr))
{
- printf("Failed to create output directory %s: %s\n", iDestDir.c_str(), ec.message().c_str());
+ printf("Failed to create output directory %s: %s\n", iDestDir.string().c_str(), ec.message().c_str());
return false;
}
// else already exists - this is fine, continue
@@ -97,7 +102,7 @@ namespace VMAP
thread_local std::size_t workerIndex = workerIndexGen++;
--mapsToProcess;
- auto dirf = Trinity::make_unique_ptr_with_deleter(fopen(file.string().c_str(), "rb"), &::fclose);
+ auto dirf = OpenFile(file, "rb");
if (!dirf)
{
printf("Could not read dir_bin file!\n");
@@ -203,12 +208,14 @@ namespace VMAP
for (uint32 i = 0; i < mapSpawns.size(); ++i)
modelNodeIdx.try_emplace(mapSpawns[i]->ID, i);
+ boost::filesystem::path mapDestDir = iDestDir;
+
// write map tree file
- std::string mapfilename = Trinity::StringFormat("{}/{:04}.vmtree", iDestDir, data.MapId);
- auto mapfile = Trinity::make_unique_ptr_with_deleter(fopen(mapfilename.c_str(), "wb"), &::fclose);
+ boost::filesystem::path mapfilename = mapDestDir / Trinity::StringFormat("{:04}.vmtree", data.MapId);
+ auto mapfile = OpenFile(mapfilename, "wb");
if (!mapfile)
{
- printf("Cannot open %s\n", mapfilename.c_str());
+ printf("Cannot open %s\n", mapfilename.string().c_str());
return false;
}
@@ -230,10 +237,8 @@ namespace VMAP
{
uint32 x, y;
StaticMapTree::unpackTileID(tileId, x, y);
- std::string tileFileName = Trinity::StringFormat("{}/{:04}_{:02}_{:02}.vmtile", iDestDir, data.MapId, y, x);
- auto tileFile = Trinity::make_unique_ptr_with_deleter(fopen(tileFileName.c_str(), "wb"), &::fclose);
- std::string tileSpawnIndicesFileName = Trinity::StringFormat("{}/{:04}_{:02}_{:02}.vmtileidx", iDestDir, data.MapId, y, x);
- auto tileSpawnIndicesFile = Trinity::make_unique_ptr_with_deleter(fopen(tileSpawnIndicesFileName.c_str(), "wb"), &::fclose);
+ auto tileFile = OpenFile(mapDestDir / Trinity::StringFormat("{:04}_{:02}_{:02}.vmtile", data.MapId, y, x), "wb");
+ auto tileSpawnIndicesFile = OpenFile(mapDestDir / Trinity::StringFormat("{:04}_{:02}_{:02}.vmtileidx", data.MapId, y, x), "wb");
if (tileFile && tileSpawnIndicesFile)
{
std::set<uint32> const& parentTileEntries = data.ParentTileEntries[tileId];
@@ -278,8 +283,7 @@ namespace VMAP
uint32 x, y;
StaticMapTree::unpackTileID(tileId, x, y);
- std::string tileSpawnIndicesFileName = Trinity::StringFormat("{}/{:04}_{:02}_{:02}.vmtileidx", iDestDir, data.MapId, y, x);
- auto tileSpawnIndicesFile = Trinity::make_unique_ptr_with_deleter(fopen(tileSpawnIndicesFileName.c_str(), "wb"), &::fclose);
+ auto tileSpawnIndicesFile = OpenFile(mapDestDir / Trinity::StringFormat("{:04}_{:02}_{:02}.vmtileidx", data.MapId, y, x), "wb");
if (tileSpawnIndicesFile)
{
uint32 nSpawns = spawns.size();
@@ -325,9 +329,7 @@ namespace VMAP
bool TileAssembler::calculateTransformedBound(ModelSpawn &spawn) const
{
- std::string modelFilename(iSrcDir);
- modelFilename.push_back('/');
- modelFilename.append(spawn.name);
+ boost::filesystem::path modelFilename = iSrcDir / spawn.name;
ModelPosition modelPosition;
modelPosition.iDir = spawn.iRot;
@@ -335,12 +337,12 @@ namespace VMAP
modelPosition.init();
WorldModel_Raw raw_model;
- if (!raw_model.Read(modelFilename.c_str()))
+ if (!raw_model.Read(modelFilename))
return false;
uint32 groups = raw_model.groupsArray.size();
if (groups != 1)
- printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.c_str());
+ printf("Warning: '%s' does not seem to be a M2 model!\n", modelFilename.string().c_str());
G3D::AABox rotated_bounds;
for (int i = 0; i < 8; ++i)
@@ -362,16 +364,12 @@ namespace VMAP
};
#pragma pack(pop)
//=================================================================
- bool TileAssembler::convertRawFile(const std::string& pModelFilename)
+ bool TileAssembler::convertRawFile(const std::string& pModelFilename) const
{
bool success = true;
- std::string filename = iSrcDir;
- if (filename.length() >0)
- filename.push_back('/');
- filename.append(pModelFilename);
WorldModel_Raw raw_model;
- if (!raw_model.Read(filename.c_str()))
+ if (!raw_model.Read(iSrcDir / pModelFilename))
return false;
// write WorldModel
@@ -394,14 +392,14 @@ namespace VMAP
model.setGroupModels(groupsArray);
}
- success = model.writeFile(iDestDir + "/" + pModelFilename + ".vmo");
+ success = model.writeFile((iDestDir / (pModelFilename + ".vmo")).string());
//std::cout << "readRawFile2: '" << pModelFilename << "' tris: " << nElements << " nodes: " << nNodes << std::endl;
return success;
}
void TileAssembler::exportGameobjectModels()
{
- auto model_list = Trinity::make_unique_ptr_with_deleter(fopen((iSrcDir + "/" + "temp_gameobject_models").c_str(), "rb"), &::fclose);
+ auto model_list = OpenFile(iSrcDir / "temp_gameobject_models", "rb");
if (!model_list)
return;
@@ -409,7 +407,7 @@ namespace VMAP
if (fread(ident, 1, 8, model_list.get()) != 8 || memcmp(ident, VMAP::RAW_VMAP_MAGIC, 8) != 0)
return;
- auto model_list_copy = Trinity::make_unique_ptr_with_deleter(fopen((iDestDir + "/" + GAMEOBJECT_MODELS).c_str(), "wb"), &::fclose);
+ auto model_list_copy = OpenFile(iDestDir / GAMEOBJECT_MODELS, "wb");
if (!model_list_copy)
return;
@@ -434,7 +432,7 @@ namespace VMAP
std::string model_name(buff, name_length);
WorldModel_Raw raw_model;
- if (!raw_model.Read((iSrcDir + "/" + model_name).c_str()) )
+ if (!raw_model.Read(iSrcDir / model_name))
continue;
spawnedModelFiles.insert(model_name);
@@ -557,12 +555,12 @@ namespace VMAP
return true;
}
- bool WorldModel_Raw::Read(const char * path)
+ bool WorldModel_Raw::Read(boost::filesystem::path const& path)
{
- auto file = Trinity::make_unique_ptr_with_deleter(fopen(path, "rb"), &::fclose);
+ auto file = OpenFile(path, "rb");
if (!file)
{
- printf("ERROR: Can't open raw model file: %s\n", path);
+ printf("ERROR: Can't open raw model file: %s\n", path.string().c_str());
return false;
}
diff --git a/src/tools/vmap4_assembler/TileAssembler.h b/src/tools/vmap4_assembler/TileAssembler.h
index 3586a9daec6..51325742888 100644
--- a/src/tools/vmap4_assembler/TileAssembler.h
+++ b/src/tools/vmap4_assembler/TileAssembler.h
@@ -18,15 +18,15 @@
#ifndef _TILEASSEMBLER_H_
#define _TILEASSEMBLER_H_
-#include <G3D/Vector3.h>
+#include "ModelInstance.h"
+#include "WorldModel.h"
#include <G3D/Matrix3.h>
+#include <G3D/Vector3.h>
+#include <boost/filesystem/path.hpp>
#include <deque>
#include <map>
#include <set>
-#include "ModelInstance.h"
-#include "WorldModel.h"
-
namespace VMAP
{
/**
@@ -87,19 +87,19 @@ namespace VMAP
uint32 RootWMOID;
std::vector<GroupModel_Raw> groupsArray;
- bool Read(const char * path);
+ bool Read(boost::filesystem::path const& path);
};
class TileAssembler
{
private:
- std::string iSrcDir;
- std::string iDestDir;
+ boost::filesystem::path iSrcDir;
+ boost::filesystem::path iDestDir;
uint32 iThreads;
std::set<std::string> spawnedModelFiles;
public:
- TileAssembler(std::string srcDirName, std::string destDirName, uint32 threads);
+ TileAssembler(std::string const& srcDirName, std::string const& destDirName, uint32 threads);
bool convertWorld2();
bool convertMap(MapSpawns& data) const;
@@ -107,7 +107,7 @@ namespace VMAP
bool calculateTransformedBound(ModelSpawn &spawn) const;
void exportGameobjectModels();
- bool convertRawFile(const std::string& pModelFilename);
+ bool convertRawFile(const std::string& pModelFilename) const;
};
} // VMAP
diff --git a/src/tools/vmap4_assembler/VMapAssembler.cpp b/src/tools/vmap4_assembler/VMapAssembler.cpp
index 9a4886b2919..a61d7341d22 100644
--- a/src/tools/vmap4_assembler/VMapAssembler.cpp
+++ b/src/tools/vmap4_assembler/VMapAssembler.cpp
@@ -55,7 +55,7 @@ int main(int argc, char* argv[])
std::cout << "using " << src << " as source directory and writing output to " << dest << std::endl;
- VMAP::TileAssembler ta(std::move(src), std::move(dest), threads);
+ VMAP::TileAssembler ta(src, dest, threads);
if (!ta.convertWorld2())
{