diff options
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/mmaps_generator/IntermediateValues.cpp | 81 | ||||
| -rw-r--r-- | src/tools/mmaps_generator/MapBuilder.cpp | 23 | ||||
| -rw-r--r-- | src/tools/mmaps_generator/TerrainBuilder.cpp | 8 | ||||
| -rw-r--r-- | src/tools/vmap4_extractor/model.cpp | 33 | ||||
| -rw-r--r-- | src/tools/vmap4_extractor/vmapexport.cpp | 11 | ||||
| -rw-r--r-- | src/tools/vmap4_extractor/wmo.cpp | 16 |
6 files changed, 67 insertions, 105 deletions
diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp index 633e4de80e0..9e82c793320 100644 --- a/src/tools/mmaps_generator/IntermediateValues.cpp +++ b/src/tools/mmaps_generator/IntermediateValues.cpp @@ -16,6 +16,7 @@ */ #include "IntermediateValues.h" +#include "StringFormat.h" namespace MMAP { @@ -30,42 +31,32 @@ namespace MMAP void IntermediateValues::writeIV(uint32 mapID, uint32 tileX, uint32 tileY) { - char fileName[255]; - char tileString[25]; - sprintf(tileString, "[%02u,%02u]: ", tileX, tileY); - - printf("%sWriting debug output... \r", tileString); - - std::string name("meshes/%03u%02i%02i."); - -#define DEBUG_WRITE(fileExtension,data) \ - do { \ - sprintf(fileName, (name + fileExtension).c_str(), mapID, tileY, tileX); \ - FILE* file = fopen(fileName, "wb"); \ - if (!file) \ - { \ - char message[1024]; \ - sprintf(message, "%sFailed to open %s for writing!\n", tileString, fileName); \ - perror(message); \ - } \ - else \ - debugWrite(file, data); \ - if (file) fclose(file); \ - printf("%sWriting debug output... \r", tileString); \ - } while (false) + std::string tileString = Trinity::StringFormat("[{:02},{:02}]: ", tileX, tileY); + + printf("%sWriting debug output... \r", tileString.c_str()); + + auto debugWrite = [&](char const* extension, auto const* data) + { + std::string fileName = Trinity::StringFormat("meshes/{:03}{:02}{:02}.{}", mapID, tileY, tileX, extension); + if (FILE* file = fopen(fileName.c_str(), "wb")) + { + this->debugWrite(file, data); + fclose(file); + } + else + perror(Trinity::StringFormat("{}Failed to open {} for writing!\n", tileString, fileName).c_str()); + }; if (heightfield) - DEBUG_WRITE("hf", heightfield); + debugWrite("hf", heightfield); if (compactHeightfield) - DEBUG_WRITE("chf", compactHeightfield); + debugWrite("chf", compactHeightfield); if (contours) - DEBUG_WRITE("cs", contours); + debugWrite("cs", contours); if (polyMesh) - DEBUG_WRITE("pmesh", polyMesh); + debugWrite("pmesh", polyMesh); if (polyMeshDetail) - DEBUG_WRITE("dmesh", polyMeshDetail); - -#undef DEBUG_WRITE + debugWrite("dmesh", polyMeshDetail); } void IntermediateValues::debugWrite(FILE* file, rcHeightfield const* mesh) @@ -200,15 +191,13 @@ namespace MMAP void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData) { - char objFileName[255]; - sprintf(objFileName, "meshes/map%03u%02u%02u.obj", mapID, tileY, tileX); + std::string objFileName; + objFileName = Trinity::StringFormat("meshes/map{:03}{:02}{:02}.obj", mapID, tileY, tileX); - FILE* objFile = fopen(objFileName, "wb"); + FILE* objFile = fopen(objFileName.c_str(), "wb"); if (!objFile) { - char message[1024]; - sprintf(message, "Failed to open %s for writing!\n", objFileName); - perror(message); + perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str()); return; } @@ -233,18 +222,14 @@ namespace MMAP fclose(objFile); - char tileString[25]; - sprintf(tileString, "[%02u,%02u]: ", tileY, tileX); - printf("%sWriting debug output... \r", tileString); + printf("[%02u,%02u]: Writing debug output... \r", tileY, tileX); - sprintf(objFileName, "meshes/%03u.map", mapID); + objFileName = Trinity::StringFormat("meshes/map{:03}.map", mapID); - objFile = fopen(objFileName, "wb"); + objFile = fopen(objFileName.c_str(), "wb"); if (!objFile) { - char message[1024]; - sprintf(message, "Failed to open %s for writing!\n", objFileName); - perror(message); + perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str()); return; } @@ -252,13 +237,11 @@ namespace MMAP fwrite(&b, sizeof(char), 1, objFile); fclose(objFile); - sprintf(objFileName, "meshes/%03u%02u%02u.mesh", mapID, tileY, tileX); - objFile = fopen(objFileName, "wb"); + objFileName = Trinity::StringFormat("meshes/map{:03}{:02}{:02}.mesh", mapID, tileY, tileX); + objFile = fopen(objFileName.c_str(), "wb"); if (!objFile) { - char message[1024]; - sprintf(message, "Failed to open %s for writing!\n", objFileName); - perror(message); + perror(Trinity::StringFormat("Failed to open {} for writing!\n", objFileName).c_str()); return; } diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 274ea10bca6..beb708df9ac 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -576,16 +576,13 @@ namespace MMAP return; } - char fileName[25]; - sprintf(fileName, "mmaps/%03u.mmap", mapID); + std::string fileName = Trinity::StringFormat("mmaps/{:03}.mmap", mapID); - FILE* file = fopen(fileName, "wb"); + FILE* file = fopen(fileName.c_str(), "wb"); if (!file) { dtFreeNavMesh(navMesh); - char message[1024]; - sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName); - perror(message); + perror(Trinity::StringFormat("[Map {:03}] Failed to open {} for writing!\n", mapID, fileName).c_str()); return; } @@ -890,14 +887,11 @@ namespace MMAP } // file output - char fileName[255]; - sprintf(fileName, "mmaps/%03u%02i%02i.mmtile", mapID, tileY, tileX); - FILE* file = fopen(fileName, "wb"); + std::string fileName = Trinity::StringFormat("mmaps/{:03}{:02}{:02}.mmtile", mapID, tileY, tileX); + FILE* file = fopen(fileName.c_str(), "wb"); if (!file) { - char message[1024]; - sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName); - perror(message); + perror(Trinity::StringFormat("[Map {:03}] Failed to open {} for writing!\n", mapID, fileName).c_str()); navMesh->removeTile(tileRef, nullptr, nullptr); break; } @@ -1063,9 +1057,8 @@ namespace MMAP /**************************************************************************/ bool TileBuilder::shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY) const { - char fileName[255]; - sprintf(fileName, "mmaps/%03u%02i%02i.mmtile", mapID, tileY, tileX); - FILE* file = fopen(fileName, "rb"); + std::string fileName = Trinity::StringFormat("mmaps/{:03}{:02}{:02}.mmtile", mapID, tileY, tileX); + FILE* file = fopen(fileName.c_str(), "rb"); if (!file) return false; diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index c9743d229ac..9da006f813c 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -21,6 +21,7 @@ #include "MapDefines.h" #include "MapTree.h" #include "ModelInstance.h" +#include "StringFormat.h" #include "VMapFactory.h" #include "VMapManager2.h" #include <map> @@ -135,10 +136,9 @@ namespace MMAP /**************************************************************************/ bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion) { - char mapFileName[255]; - sprintf(mapFileName, "maps/%03u%02u%02u.map", mapID, tileY, tileX); + std::string mapFileName = Trinity::StringFormat("maps/{:03}{:02}{:02}.map", mapID, tileY, tileX); - FILE* mapFile = fopen(mapFileName, "rb"); + FILE* mapFile = fopen(mapFileName.c_str(), "rb"); if (!mapFile) return false; @@ -147,7 +147,7 @@ namespace MMAP fheader.versionMagic != MAP_VERSION_MAGIC) { fclose(mapFile); - printf("%s is the wrong version, please extract new .map files\n", mapFileName); + printf("%s is the wrong version, please extract new .map files\n", mapFileName.c_str()); return false; } diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp index c1271b1c76d..49e812916b3 100644 --- a/src/tools/vmap4_extractor/model.cpp +++ b/src/tools/vmap4_extractor/model.cpp @@ -18,6 +18,7 @@ #include "vmapexport.h" #include "Errors.h" #include "model.h" +#include "StringFormat.h" #include "wmo.h" #include "adtfile.h" #include "mpq_libmpq.h" @@ -140,9 +141,8 @@ Vec3D fixCoordSystem(Vec3D const& v) void Doodad::Extract(ADT::MDDF const& doodadDef, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile) { - char tempname[1036]; - sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName); - FILE* input = fopen(tempname, "r+b"); + std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, ModelInstName); + FILE* input = fopen(tempname.c_str(), "r+b"); if (!input) return; @@ -199,24 +199,15 @@ void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, u WMO::MODD const& doodad = doodadData.Spawns[doodadIndex]; - char ModelInstName[1024]; - sprintf(ModelInstName, "%s", GetPlainName(&doodadData.Paths[doodad.NameIndex])); - uint32 nlen = strlen(ModelInstName); - fixnamen(ModelInstName, nlen); - fixname2(ModelInstName, nlen); - if (nlen > 3) - { - char const* extension = &ModelInstName[nlen - 4]; - if (!strcmp(extension, ".mdx") || !strcmp(extension, ".mdl")) - { - ModelInstName[nlen - 2] = '2'; - ModelInstName[nlen - 1] = '\0'; - } - } + std::string ModelInstName = GetPlainName(&doodadData.Paths[doodad.NameIndex]); + uint32 nlen = ModelInstName.length(); + fixnamen(ModelInstName.data(), nlen); + fixname2(ModelInstName.data(), nlen); + if (ModelInstName.ends_with(".mdx") || ModelInstName.ends_with(".mdl")) + ModelInstName.replace(ModelInstName.length() - 2, 2, "2"); - char tempname[1036]; - sprintf(tempname, "%s/%s", szWorkDirWmo, ModelInstName); - FILE* input = fopen(tempname, "r+b"); + std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, ModelInstName); + FILE* input = fopen(tempname.c_str(), "r+b"); if (!input) continue; @@ -259,6 +250,6 @@ void Doodad::ExtractSet(WMODoodadData const& doodadData, ADT::MODF const& wmo, u fwrite(&rotation, sizeof(Vec3D), 1, pDirfile); fwrite(&doodad.Scale, sizeof(float), 1, pDirfile); fwrite(&nlen, sizeof(uint32), 1, pDirfile); - fwrite(ModelInstName, sizeof(char), nlen, pDirfile); + fwrite(ModelInstName.c_str(), sizeof(char), nlen, pDirfile); } } diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index e5a3c04b839..5926f2e525c 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -87,13 +87,12 @@ bool ExtractSingleWmo(std::string& fname) // Copy files from archive std::string originalName = fname; - char szLocalFile[1024]; char* plain_name = GetPlainName(&fname[0]); fixnamen(plain_name, strlen(plain_name)); fixname2(plain_name, strlen(plain_name)); - sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name); + std::string szLocalFile = Trinity::StringFormat("{}/{}", szWorkDirWmo, plain_name); - if (FileExists(szLocalFile)) + if (FileExists(szLocalFile.c_str())) return true; int p = 0; @@ -122,10 +121,10 @@ bool ExtractSingleWmo(std::string& fname) printf("Couldn't open RootWmo!!!\n"); return true; } - FILE *output = fopen(szLocalFile,"wb"); + FILE *output = fopen(szLocalFile.c_str(),"wb"); if(!output) { - printf("couldn't open %s for writing!\n", szLocalFile); + printf("couldn't open %s for writing!\n", szLocalFile.c_str()); return false; } froot.ConvertToVMAPRootWmo(output); @@ -177,7 +176,7 @@ bool ExtractSingleWmo(std::string& fname) // Delete the extracted file in the case of an error if (!file_ok) - remove(szLocalFile); + remove(szLocalFile.c_str()); return true; } diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index ffb3116014b..4e7e0eb2e2d 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -17,18 +17,16 @@ #include "vmapexport.h" #include "adtfile.h" -#include "vec3d.h" +#include "Errors.h" #include "mpq_libmpq.h" - +#include "StringFormat.h" +#include "vec3d.h" #include "VMapDefinitions.h" #include "wmo.h" #include <fstream> #include <map> #include <cstdio> #include <cstdlib> -#include "Errors.h" -#undef min -#undef max WMORoot::WMORoot(std::string const& filename) : filename(filename), color(0), nTextures(0), nGroups(0), nPortals(0), nLights(0), @@ -533,14 +531,12 @@ void MapObject::Extract(ADT::MODF const& mapObjDef, char const* WmoInstName, uin //-----------add_in _dir_file---------------- - char tempname[512]; - sprintf(tempname, "%s/%s", szWorkDirWmo, WmoInstName); - FILE *input; - input = fopen(tempname, "r+b"); + std::string tempname = Trinity::StringFormat("{}/{}", szWorkDirWmo, WmoInstName); + FILE* input = fopen(tempname.c_str(), "r+b"); if (!input) { - printf("WMOInstance::WMOInstance: couldn't open %s\n", tempname); + printf("WMOInstance::WMOInstance: couldn't open %s\n", tempname.c_str()); return; } |
