diff options
| author | ariel- <ariel-@users.noreply.github.com> | 2017-06-19 23:20:06 -0300 |
|---|---|---|
| committer | ariel- <ariel-@users.noreply.github.com> | 2017-06-19 23:20:06 -0300 |
| commit | 85a7d5ce9ac68b30da2277cc91d4b70358f1880d (patch) | |
| tree | df3d2084ee2e35008903c03178039b9c986e2d08 /src/tools | |
| parent | 052fc24315ace866ea1cf610e85df119b68100c9 (diff) | |
Core: ported headers cleanup from master branch
Diffstat (limited to 'src/tools')
32 files changed, 306 insertions, 309 deletions
diff --git a/src/tools/map_extractor/CMakeLists.txt b/src/tools/map_extractor/CMakeLists.txt index 52da3adf127..87ad3ff5089 100644 --- a/src/tools/map_extractor/CMakeLists.txt +++ b/src/tools/map_extractor/CMakeLists.txt @@ -13,6 +13,10 @@ CollectSourceFiles( ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES) +if (WIN32) + list(APPEND PRIVATE_SOURCES ${sources_windows}) +endif() + add_executable(mapextractor ${PRIVATE_SOURCES} ) diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index c681e669ebe..1fbf831e20f 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -16,8 +16,6 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _CRT_SECURE_NO_DEPRECATE - #include <stdio.h> #include <deque> #include <set> @@ -25,6 +23,7 @@ #include <fstream> #include "dbcfile.h" +#include "Banner.h" #include "mpq_libmpq04.h" #include "StringFormat.h" @@ -84,7 +83,7 @@ const char *CONF_mpq_list[]={ "patch-5.MPQ", }; -static const char* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; +static char const* const langs[] = {"enGB", "enUS", "deDE", "esES", "frFR", "koKR", "zhCN", "zhTW", "enCN", "enTW", "esMX", "ruRU" }; #define LANG_COUNT 12 void CreateDir(boost::filesystem::path const& path) @@ -122,7 +121,7 @@ void HandleArgs(int argc, char * arg[]) if(arg[c][0] != '-') Usage(arg[0]); - switch(arg[c][1]) + switch (arg[c][1]) { case 'i': if (c + 1 < argc && strlen(arg[c + 1]) < MAX_PATH_LENGTH) // all ok @@ -143,16 +142,16 @@ void HandleArgs(int argc, char * arg[]) Usage(arg[0]); break; case 'f': - if(c + 1 < argc) // all ok - CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0; + if (c + 1 < argc) // all ok + CONF_allow_float_to_int = atoi(arg[(c++) + 1]) != 0; else Usage(arg[0]); break; case 'e': - if(c + 1 < argc) // all ok + if (c + 1 < argc) // all ok { - CONF_extract=atoi(arg[(c++) + 1]); - if(!(CONF_extract > 0 && CONF_extract < 8)) + CONF_extract = atoi(arg[(c++) + 1]); + if (!(CONF_extract > 0 && CONF_extract < 8)) Usage(arg[0]); } else @@ -216,7 +215,7 @@ uint32 ReadMapDBC() { map_ids[x].id = dbc.getRecord(x).getUInt(0); - const char* map_name = dbc.getRecord(x).getString(1); + char const* map_name = dbc.getRecord(x).getString(1); size_t max_map_name_length = sizeof(map_ids[x].name); if (strlen(map_name) >= max_map_name_length) { @@ -567,12 +566,12 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int float diff = maxHeight - minHeight; if (diff < CONF_float_to_int8_limit) // As uint8 (max accuracy = CONF_float_to_int8_limit/256) { - heightHeader.flags|=MAP_HEIGHT_AS_INT8; + heightHeader.flags |= MAP_HEIGHT_AS_INT8; step = selectUInt8StepStore(diff); } - else if (diff<CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536) + else if (diff < CONF_float_to_int16_limit) // As uint16 (max accuracy = CONF_float_to_int16_limit/65536) { - heightHeader.flags|=MAP_HEIGHT_AS_INT16; + heightHeader.flags |= MAP_HEIGHT_AS_INT16; step = selectUInt16StepStore(diff); } } @@ -852,30 +851,30 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int return false; } - outFile.write(reinterpret_cast<const char*>(&map), sizeof(map)); + outFile.write(reinterpret_cast<char const*>(&map), sizeof(map)); // Store area data - outFile.write(reinterpret_cast<const char*>(&areaHeader), sizeof(areaHeader)); + outFile.write(reinterpret_cast<char const*>(&areaHeader), sizeof(areaHeader)); if (!(areaHeader.flags & MAP_AREA_NO_AREA)) - outFile.write(reinterpret_cast<const char*>(area_ids), sizeof(area_ids)); + outFile.write(reinterpret_cast<char const*>(area_ids), sizeof(area_ids)); // Store height data - outFile.write(reinterpret_cast<const char*>(&heightHeader), sizeof(heightHeader)); + outFile.write(reinterpret_cast<char const*>(&heightHeader), sizeof(heightHeader)); if (!(heightHeader.flags & MAP_HEIGHT_NO_HEIGHT)) { if (heightHeader.flags & MAP_HEIGHT_AS_INT16) { - outFile.write(reinterpret_cast<const char*>(uint16_V9), sizeof(uint16_V9)); - outFile.write(reinterpret_cast<const char*>(uint16_V8), sizeof(uint16_V8)); + outFile.write(reinterpret_cast<char const*>(uint16_V9), sizeof(uint16_V9)); + outFile.write(reinterpret_cast<char const*>(uint16_V8), sizeof(uint16_V8)); } else if (heightHeader.flags & MAP_HEIGHT_AS_INT8) { - outFile.write(reinterpret_cast<const char*>(uint8_V9), sizeof(uint8_V9)); - outFile.write(reinterpret_cast<const char*>(uint8_V8), sizeof(uint8_V8)); + outFile.write(reinterpret_cast<char const*>(uint8_V9), sizeof(uint8_V9)); + outFile.write(reinterpret_cast<char const*>(uint8_V8), sizeof(uint8_V8)); } else { - outFile.write(reinterpret_cast<const char*>(V9), sizeof(V9)); - outFile.write(reinterpret_cast<const char*>(V8), sizeof(V8)); + outFile.write(reinterpret_cast<char const*>(V9), sizeof(V9)); + outFile.write(reinterpret_cast<char const*>(V8), sizeof(V8)); } } @@ -888,24 +887,24 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int // Store liquid data if need if (map.liquidMapOffset) { - outFile.write(reinterpret_cast<const char*>(&liquidHeader), sizeof(liquidHeader)); + outFile.write(reinterpret_cast<char const*>(&liquidHeader), sizeof(liquidHeader)); if (!(liquidHeader.flags&MAP_LIQUID_NO_TYPE)) { - outFile.write(reinterpret_cast<const char*>(liquid_entry), sizeof(liquid_entry)); - outFile.write(reinterpret_cast<const char*>(liquid_flags), sizeof(liquid_flags)); + outFile.write(reinterpret_cast<char const*>(liquid_entry), sizeof(liquid_entry)); + outFile.write(reinterpret_cast<char const*>(liquid_flags), sizeof(liquid_flags)); } if (!(liquidHeader.flags&MAP_LIQUID_NO_HEIGHT)) { for (int y = 0; y < liquidHeader.height; y++) - outFile.write(reinterpret_cast<const char*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width); + outFile.write(reinterpret_cast<char const*>(&liquid_height[y + liquidHeader.offsetY][liquidHeader.offsetX]), sizeof(float) * liquidHeader.width); } } // store hole data if (hasHoles) - outFile.write(reinterpret_cast<const char*>(holes), map.holesSize); + outFile.write(reinterpret_cast<char const*>(holes), map.holesSize); outFile.close(); return true; @@ -1114,8 +1113,7 @@ inline void CloseMPQFiles() int main(int argc, char * arg[]) { - printf("Map & DBC Extractor\n"); - printf("===================\n\n"); + Trinity::Banner::Show("Map & DBC Extractor", [](char const* text) { printf("%s\n", text); }, nullptr); HandleArgs(argc, arg); diff --git a/src/tools/map_extractor/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp index b8a504877a3..25ded3e6c60 100644 --- a/src/tools/map_extractor/dbcfile.cpp +++ b/src/tools/map_extractor/dbcfile.cpp @@ -22,7 +22,7 @@ #include "mpq_libmpq04.h" DBCFile::DBCFile(const std::string& filename): - filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(NULL), stringTable(NULL) + filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr) { } diff --git a/src/tools/map_extractor/dbcfile.h b/src/tools/map_extractor/dbcfile.h index f490544d9d6..5130469b5f3 100644 --- a/src/tools/map_extractor/dbcfile.h +++ b/src/tools/map_extractor/dbcfile.h @@ -99,15 +99,15 @@ public: } /// Return address of current instance Record const & operator*() const { return record; } - const Record* operator->() const { + Record const* operator->() const { return &record; } /// Comparison - bool operator==(const Iterator &b) const + bool operator==(Iterator const& b) const { return record.offset == b.record.offset; } - bool operator!=(const Iterator &b) const + bool operator!=(Iterator const& b) const { return record.offset != b.record.offset; } diff --git a/src/tools/map_extractor/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp index 5891a1be49b..120fa9731b7 100644 --- a/src/tools/map_extractor/mpq_libmpq.cpp +++ b/src/tools/map_extractor/mpq_libmpq.cpp @@ -22,7 +22,7 @@ ArchiveSet gOpenArchives; -MPQArchive::MPQArchive(const char* filename) +MPQArchive::MPQArchive(char const* filename) { int result = libmpq__archive_open(&mpq_a, filename, -1); printf("Opening %s\n", filename); @@ -58,7 +58,7 @@ void MPQArchive::close() libmpq__archive_close(mpq_a); } -MPQFile::MPQFile(const char* filename): +MPQFile::MPQFile(char const* filename): eof(false), buffer(0), pointer(0), diff --git a/src/tools/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h index b03ae7b7639..589ce0b31d1 100644 --- a/src/tools/map_extractor/mpq_libmpq04.h +++ b/src/tools/map_extractor/mpq_libmpq04.h @@ -33,7 +33,7 @@ class MPQArchive public: mpq_archive_s *mpq_a; - MPQArchive(const char* filename); + MPQArchive(char const* filename); ~MPQArchive() { close(); } void close(); @@ -53,13 +53,13 @@ public: token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != NULL) && (counter < size)) { + while ((token != nullptr) && (counter < size)) { //cout << token << endl; token[strlen(token) - 1] = 0; std::string s = token; filelist.push_back(s); counter += strlen(token) + 2; - token = strtok(NULL, seps); + token = strtok(nullptr, seps); } delete[] buffer; @@ -75,11 +75,11 @@ class MPQFile libmpq__off_t pointer,size; // disable copying - MPQFile(const MPQFile& /*f*/) {} - void operator=(const MPQFile& /*f*/) {} + MPQFile(MPQFile const& /*f*/) = delete; + void operator=(MPQFile const& /*f*/) = delete; public: - MPQFile(const char* filename); // filenames are not case sensitive + MPQFile(char const* filename); // filenames are not case sensitive ~MPQFile() { close(); } size_t read(void* dest, size_t bytes); size_t getSize() { return size; } diff --git a/src/tools/mmaps_generator/CMakeLists.txt b/src/tools/mmaps_generator/CMakeLists.txt index d55920690ad..593a6737210 100644 --- a/src/tools/mmaps_generator/CMakeLists.txt +++ b/src/tools/mmaps_generator/CMakeLists.txt @@ -12,6 +12,10 @@ CollectSourceFiles( ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES) +if (WIN32) + list(APPEND PRIVATE_SOURCES ${sources_windows}) +endif() + add_executable(mmaps_generator ${PRIVATE_SOURCES}) target_link_libraries(mmaps_generator diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp index 6a802ff1059..7be5cdaf3f3 100644 --- a/src/tools/mmaps_generator/IntermediateValues.cpp +++ b/src/tools/mmaps_generator/IntermediateValues.cpp @@ -69,7 +69,7 @@ namespace MMAP #undef DEBUG_WRITE } - void IntermediateValues::debugWrite(FILE* file, const rcHeightfield* mesh) + void IntermediateValues::debugWrite(FILE* file, rcHeightfield const* mesh) { if (!file || !mesh) return; @@ -107,7 +107,7 @@ namespace MMAP } } - void IntermediateValues::debugWrite(FILE* file, const rcCompactHeightfield* chf) + void IntermediateValues::debugWrite(FILE* file, rcCompactHeightfield const* chf) { if (!file | !chf) return; @@ -146,7 +146,7 @@ namespace MMAP fwrite(chf->areas, sizeof(unsigned char), chf->spanCount, file); } - void IntermediateValues::debugWrite(FILE* file, const rcContourSet* cs) + void IntermediateValues::debugWrite(FILE* file, rcContourSet const* cs) { if (!file || !cs) return; @@ -167,7 +167,7 @@ namespace MMAP } } - void IntermediateValues::debugWrite(FILE* file, const rcPolyMesh* mesh) + void IntermediateValues::debugWrite(FILE* file, rcPolyMesh const* mesh) { if (!file || !mesh) return; @@ -186,7 +186,7 @@ namespace MMAP fwrite(mesh->regs, sizeof(unsigned short), mesh->npolys, file); } - void IntermediateValues::debugWrite(FILE* file, const rcPolyMeshDetail* mesh) + void IntermediateValues::debugWrite(FILE* file, rcPolyMeshDetail const* mesh) { if (!file || !mesh) return; diff --git a/src/tools/mmaps_generator/IntermediateValues.h b/src/tools/mmaps_generator/IntermediateValues.h index edcf372e376..d93e7eabb11 100644 --- a/src/tools/mmaps_generator/IntermediateValues.h +++ b/src/tools/mmaps_generator/IntermediateValues.h @@ -34,17 +34,17 @@ namespace MMAP rcPolyMesh* polyMesh; rcPolyMeshDetail* polyMeshDetail; - IntermediateValues() : heightfield(NULL), compactHeightfield(NULL), - contours(NULL), polyMesh(NULL), polyMeshDetail(NULL) {} + IntermediateValues() : heightfield(nullptr), compactHeightfield(nullptr), + contours(nullptr), polyMesh(nullptr), polyMeshDetail(nullptr) {} ~IntermediateValues(); void writeIV(uint32 mapID, uint32 tileX, uint32 tileY); - void debugWrite(FILE* file, const rcHeightfield* mesh); - void debugWrite(FILE* file, const rcCompactHeightfield* chf); - void debugWrite(FILE* file, const rcContourSet* cs); - void debugWrite(FILE* file, const rcPolyMesh* mesh); - void debugWrite(FILE* file, const rcPolyMeshDetail* mesh); + 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); void generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); }; diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 097d3d3932c..91b139a29ea 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -54,8 +54,8 @@ namespace MMAP { MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid, bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds, - bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) : - m_terrainBuilder (NULL), + bool debugOutput, bool bigBaseUnit, char const* offMeshFilePath) : + m_terrainBuilder (nullptr), m_debugOutput (debugOutput), m_offMeshFilePath (offMeshFilePath), m_skipContinents (skipContinents), @@ -65,7 +65,7 @@ namespace MMAP m_bigBaseUnit (bigBaseUnit), m_totalTiles (0u), m_totalTilesProcessed(0u), - m_rcContext (NULL), + m_rcContext (nullptr), _cancelationToken (false) { m_terrainBuilder = new TerrainBuilder(skipLiquid); @@ -295,7 +295,7 @@ namespace MMAP return; } - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapId, navMesh); if (!navMesh) { @@ -359,7 +359,7 @@ namespace MMAP /**************************************************************************/ void MapBuilder::buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY) { - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapID, navMesh); if (!navMesh) { @@ -397,7 +397,7 @@ namespace MMAP if (!tiles->empty()) { // build navMesh - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapID, navMesh); if (!navMesh) { @@ -503,7 +503,7 @@ namespace MMAP // use Max because '32 - tileX' is negative for values over 32 float bmin[3], bmax[3]; - getTileBounds(tileXMax, tileYMax, NULL, 0, bmin, bmax); + getTileBounds(tileXMax, tileYMax, nullptr, 0, bmin, bmax); /*** now create the navmesh ***/ @@ -701,11 +701,11 @@ namespace MMAP // we may want to keep them in the future for debug // but right now, we don't have the code to merge them rcFreeHeightField(tile.solid); - tile.solid = NULL; + tile.solid = nullptr; rcFreeCompactHeightfield(tile.chf); - tile.chf = NULL; + tile.chf = nullptr; rcFreeContourSet(tile.cset); - tile.cset = NULL; + tile.cset = nullptr; pmmerge[nmerge] = tile.pmesh; dmmerge[nmerge] = tile.dmesh; @@ -782,7 +782,7 @@ namespace MMAP params.buildBvTree = true; // will hold final navmesh - unsigned char* navData = NULL; + unsigned char* navData = nullptr; int navDataSize = 0; do @@ -850,7 +850,7 @@ namespace MMAP char message[1024]; sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName); perror(message); - navMesh->removeTile(tileRef, NULL, NULL); + navMesh->removeTile(tileRef, nullptr, nullptr); break; } @@ -867,7 +867,7 @@ namespace MMAP fclose(file); // now that tile is written to disk, we can unload it - navMesh->removeTile(tileRef, NULL, NULL); + navMesh->removeTile(tileRef, nullptr, nullptr); } while (0); diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index 2f47fdd0ff6..5d79951f856 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -37,7 +37,7 @@ namespace MMAP { struct MapTiles { - MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {} + MapTiles() : m_mapId(uint32(-1)), m_tiles(nullptr) {} MapTiles(uint32 id, std::set<uint32>* tiles) : m_mapId(id), m_tiles(tiles) {} ~MapTiles() {} @@ -55,7 +55,7 @@ namespace MMAP struct Tile { - Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {} + Tile() : chf(nullptr), solid(nullptr), cset(nullptr), pmesh(nullptr), dmesh(nullptr) {} ~Tile() { rcFreeCompactHeightfield(chf); @@ -81,7 +81,7 @@ namespace MMAP bool skipBattlegrounds = false, bool debugOutput = false, bool bigBaseUnit = false, - const char* offMeshFilePath = NULL); + char const* offMeshFilePath = nullptr); ~MapBuilder(); @@ -131,7 +131,7 @@ namespace MMAP bool m_debugOutput; - const char* m_offMeshFilePath; + char const* m_offMeshFilePath; bool m_skipContinents; bool m_skipJunkMaps; bool m_skipBattlegrounds; diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index 1ddb5a8009c..f09ec0f0e29 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -20,16 +20,18 @@ #define _MMAP_COMMON_H #include "Common.h" - +#include <string> #include <vector> #ifndef _WIN32 - #include <stddef.h> + #include <cstddef> #include <dirent.h> +#else + #include <Windows.h> #endif -#ifdef __linux__ - #include <errno.h> +#ifndef _WIN32 + #include <cerrno> #endif enum NavTerrain @@ -48,7 +50,7 @@ enum NavTerrain namespace MMAP { - inline bool matchWildcardFilter(const char* filter, const char* str) + inline bool matchWildcardFilter(char const* filter, char const* str) { if (!filter || !str) return false; @@ -116,7 +118,7 @@ namespace MMAP while (dirp) { errno = 0; - if ((dp = readdir(dirp)) != NULL) + if ((dp = readdir(dirp)) != nullptr) { if (matchWildcardFilter(filter.c_str(), dp->d_name)) fileList.push_back(std::string(dp->d_name)); diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 1e907909737..0a97fe59f34 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -19,6 +19,7 @@ #include "PathCommon.h" #include "MapBuilder.h" #include "Timer.h" +#include "Banner.h" using namespace MMAP; @@ -75,7 +76,7 @@ bool handleArgs(int argc, char** argv, char* &file, int& threads) { - char* param = NULL; + char* param = nullptr; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--maxAngle") == 0) @@ -112,7 +113,7 @@ bool handleArgs(int argc, char** argv, return false; char* stileX = strtok(param, ","); - char* stileY = strtok(NULL, ","); + char* stileY = strtok(nullptr, ","); int tilex = atoi(stileX); int tiley = atoi(stileY); @@ -233,7 +234,7 @@ bool handleArgs(int argc, char** argv, return true; } -int finish(const char* message, int returnValue) +int finish(char const* message, int returnValue) { printf("%s", message); getchar(); // Wait for user input @@ -242,6 +243,8 @@ int finish(const char* message, int returnValue) int main(int argc, char** argv) { + Trinity::Banner::Show("MMAP generator", [](char const* text) { printf("%s\n", text); }, nullptr); + int threads = 3, mapnum = -1; float maxAngle = 70.0f; int tileX = -1, tileY = -1; @@ -252,8 +255,8 @@ int main(int argc, char** argv) debugOutput = false, silent = false, bigBaseUnit = false; - char* offMeshInputPath = NULL; - char* file = NULL; + char* offMeshInputPath = nullptr; + char* file = nullptr; bool validParam = handleArgs(argc, argv, mapnum, tileX, tileY, maxAngle, diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index 09ad5eec819..b367a282bfe 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -23,6 +23,7 @@ #include "VMapManager2.h" #include "MapTree.h" #include "ModelInstance.h" +#include <map> // ****************************************** // Map file format defines @@ -280,7 +281,7 @@ namespace MMAP printf("TerrainBuilder::loadMap: Failed to read some data expected 1, read 0\n"); - float* liquid_map = NULL; + float* liquid_map = nullptr; if (!(lheader.flags & MAP_LIQUID_NO_TYPE)) if (fread(liquid_type, sizeof(liquid_type), 1, mapFile) != 1) @@ -373,7 +374,7 @@ namespace MMAP // make a copy of liquid vertices // used to pad right-bottom frame due to lost vertex data at extraction - float* lverts_copy = NULL; + float* lverts_copy = nullptr; if (meshData.liquidVerts.size()) { lverts_copy = new float[meshData.liquidVerts.size()]; @@ -646,7 +647,7 @@ namespace MMAP if (!instanceTrees[mapID]) break; - ModelInstance* models = NULL; + ModelInstance* models = nullptr; uint32 count = 0; instanceTrees[mapID]->getModelInstances(models, count); @@ -673,17 +674,17 @@ namespace MMAP // transform data float scale = instance.iScale; - G3D::Matrix3 rotation = G3D::Matrix3::fromEulerAnglesXYZ(G3D::pi()*instance.iRot.z/-180.f, G3D::pi()*instance.iRot.x/-180.f, G3D::pi()*instance.iRot.y/-180.f); + G3D::Matrix3 rotation = G3D::Matrix3::fromEulerAnglesXYZ(G3D::pi()*instance.iRot.z / -180.f, G3D::pi() * instance.iRot.x / -180.f, G3D::pi() * instance.iRot.y / -180.f); G3D::Vector3 position = instance.iPos; - position.x -= 32*GRID_SIZE; - position.y -= 32*GRID_SIZE; + position.x -= 32 * GRID_SIZE; + position.y -= 32 * GRID_SIZE; for (std::vector<GroupModel>::iterator it = groupModels.begin(); it != groupModels.end(); ++it) { std::vector<G3D::Vector3> tempVertices; std::vector<G3D::Vector3> transformedVertices; std::vector<MeshTriangle> tempTriangles; - WmoLiquid* liquid = NULL; + WmoLiquid* liquid = nullptr; it->getMeshData(tempVertices, tempTriangles, liquid); @@ -712,16 +713,16 @@ namespace MMAP // convert liquid type to NavTerrain switch (liquid->GetType() & 3) { - case 0: - case 1: - type = NAV_WATER; - break; - case 2: - type = NAV_MAGMA; - break; - case 3: - type = NAV_SLIME; - break; + case 0: + case 1: + type = NAV_WATER; + break; + case 2: + type = NAV_MAGMA; + break; + case 3: + type = NAV_SLIME; + break; } // indexing is weird... @@ -732,6 +733,7 @@ namespace MMAP G3D::Vector3 vert; for (uint32 x = 0; x < vertsX; ++x) + { for (uint32 y = 0; y < vertsY; ++y) { vert = G3D::Vector3(corner.x + x * GRID_PART_SIZE, corner.y + y * GRID_PART_SIZE, data[y*vertsX + x]); @@ -740,38 +742,43 @@ namespace MMAP vert.y *= -1.f; liqVerts.push_back(vert); } + } - int idx1, idx2, idx3, idx4; - uint32 square; - for (uint32 x = 0; x < tilesX; ++x) - for (uint32 y = 0; y < tilesY; ++y) - if ((flags[x+y*tilesX] & 0x0f) != 0x0f) - { - square = x * tilesY + y; - idx1 = square+x; - idx2 = square+1+x; - idx3 = square+tilesY+1+1+x; - idx4 = square+tilesY+1+x; - - // top triangle - liqTris.push_back(idx3); - liqTris.push_back(idx2); - liqTris.push_back(idx1); - // bottom triangle - liqTris.push_back(idx4); - liqTris.push_back(idx3); - liqTris.push_back(idx1); - } - - uint32 liqOffset = meshData.liquidVerts.size() / 3; - for (uint32 j = 0; j < liqVerts.size(); ++j) - meshData.liquidVerts.append(liqVerts[j].y, liqVerts[j].z, liqVerts[j].x); - - for (uint32 j = 0; j < liqTris.size() / 3; ++j) - { - meshData.liquidTris.append(liqTris[j*3+1] + liqOffset, liqTris[j*3+2] + liqOffset, liqTris[j*3] + liqOffset); - meshData.liquidType.append(type); - } + int idx1, idx2, idx3, idx4; + uint32 square; + for (uint32 x = 0; x < tilesX; ++x) + { + for (uint32 y = 0; y < tilesY; ++y) + { + if ((flags[x + y*tilesX] & 0x0f) != 0x0f) + { + square = x * tilesY + y; + idx1 = square + x; + idx2 = square + 1 + x; + idx3 = square + tilesY + 1 + 1 + x; + idx4 = square + tilesY + 1 + x; + + // top triangle + liqTris.push_back(idx3); + liqTris.push_back(idx2); + liqTris.push_back(idx1); + // bottom triangle + liqTris.push_back(idx4); + liqTris.push_back(idx3); + liqTris.push_back(idx1); + } + } + } + + uint32 liqOffset = meshData.liquidVerts.size() / 3; + for (uint32 j = 0; j < liqVerts.size(); ++j) + meshData.liquidVerts.append(liqVerts[j].y, liqVerts[j].z, liqVerts[j].x); + + for (uint32 j = 0; j < liqTris.size() / 3; ++j) + { + meshData.liquidTris.append(liqTris[j * 3 + 1] + liqOffset, liqTris[j * 3 + 2] + liqOffset, liqTris[j * 3] + liqOffset); + meshData.liquidType.append(type); + } } } } @@ -883,10 +890,10 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath) + void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, char const* offMeshFilePath) { // no meshfile input given? - if (offMeshFilePath == NULL) + if (offMeshFilePath == nullptr) return; FILE* fp = fopen(offMeshFilePath, "rb"); diff --git a/src/tools/mmaps_generator/TerrainBuilder.h b/src/tools/mmaps_generator/TerrainBuilder.h index c85dd850fec..4dcca5f15fe 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.h +++ b/src/tools/mmaps_generator/TerrainBuilder.h @@ -22,9 +22,9 @@ #include "PathCommon.h" #include "WorldModel.h" -#include "G3D/Array.h" -#include "G3D/Vector3.h" -#include "G3D/Matrix3.h" +#include <G3D/Array.h> +#include <G3D/Vector3.h> +#include <G3D/Matrix3.h> namespace MMAP { @@ -81,11 +81,11 @@ namespace MMAP TerrainBuilder(bool skipLiquid); ~TerrainBuilder(); - TerrainBuilder(const TerrainBuilder &tb) = delete; + TerrainBuilder(TerrainBuilder const& tb) = delete; void loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); bool loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); - void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath); + void loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, char const* offMeshFilePath); bool usesLiquids() const { return !m_skipLiquid; } diff --git a/src/tools/vmap4_assembler/CMakeLists.txt b/src/tools/vmap4_assembler/CMakeLists.txt index 57c351f2ebc..520c07793fb 100644 --- a/src/tools/vmap4_assembler/CMakeLists.txt +++ b/src/tools/vmap4_assembler/CMakeLists.txt @@ -9,7 +9,13 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -add_executable(vmap4assembler VMapAssembler.cpp) +set(PRIVATE_SOURCES VMapAssembler.cpp) + +if (WIN32) + list(APPEND PRIVATE_SOURCES ${sources_windows}) +endif() + +add_executable(vmap4assembler ${PRIVATE_SOURCES}) if(CMAKE_SYSTEM_NAME MATCHES "Darwin") set_target_properties(vmap4assembler PROPERTIES LINK_FLAGS "-framework Carbon") diff --git a/src/tools/vmap4_assembler/VMapAssembler.cpp b/src/tools/vmap4_assembler/VMapAssembler.cpp index d5a6f95ea53..170ce80fcb2 100644 --- a/src/tools/vmap4_assembler/VMapAssembler.cpp +++ b/src/tools/vmap4_assembler/VMapAssembler.cpp @@ -20,9 +20,12 @@ #include <iostream> #include "TileAssembler.h" +#include "Banner.h" int main(int argc, char* argv[]) { + Trinity::Banner::Show("VMAP assembler", [](char const* text) { std::cout << text << std::endl; }, nullptr); + if (argc != 3) { std::cout << "usage: " << argv[0] << " <raw data dir> <vmap dest dir>" << std::endl; diff --git a/src/tools/vmap4_extractor/CMakeLists.txt b/src/tools/vmap4_extractor/CMakeLists.txt index 848b9d089d0..42bff330d0b 100644 --- a/src/tools/vmap4_extractor/CMakeLists.txt +++ b/src/tools/vmap4_extractor/CMakeLists.txt @@ -13,21 +13,15 @@ CollectSourceFiles( ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE_SOURCES) +if (WIN32) + list(APPEND PRIVATE_SOURCES ${sources_windows}) +endif() + add_executable(vmap4extractor ${PRIVATE_SOURCES}) target_link_libraries(vmap4extractor - PUBLIC - mpq) - -CollectIncludeDirectories( - ${CMAKE_CURRENT_SOURCE_DIR} - PUBLIC_INCLUDES) - -target_include_directories(vmap4extractor - PUBLIC - ${PUBLIC_INCLUDES} - PRIVATE - ${CMAKE_CURRENT_BINARY_DIR}) + common + mpq) set_target_properties(vmap4extractor PROPERTIES diff --git a/src/tools/vmap4_extractor/adtfile.cpp b/src/tools/vmap4_extractor/adtfile.cpp index bb9f69f4be7..ee9a93fd3ff 100644 --- a/src/tools/vmap4_extractor/adtfile.cpp +++ b/src/tools/vmap4_extractor/adtfile.cpp @@ -30,7 +30,7 @@ char const* GetPlainName(char const* FileName) { const char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } @@ -39,7 +39,7 @@ char* GetPlainName(char* FileName) { char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } @@ -71,10 +71,10 @@ char* GetExtension(char* FileName) { if (char* szTemp = strrchr(FileName, '.')) return szTemp; - return NULL; + return nullptr; } -ADTFile::ADTFile(char* filename): ADT(filename), nWMO(0), nMDX(0), WmoInstansName(NULL), ModelInstansName(NULL) +ADTFile::ADTFile(char* filename): ADT(filename), nWMO(0), nMDX(0), WmoInstansName(nullptr), ModelInstansName(nullptr) { Adtfilename.append(filename); } @@ -184,7 +184,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) ModelInstance inst(ADT,ModelInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] ModelInstansName; - ModelInstansName = NULL; + ModelInstansName = nullptr; } } else if (!strcmp(fourcc,"MODF")) @@ -199,7 +199,7 @@ bool ADTFile::init(uint32 map_num, uint32 tileX, uint32 tileY) WMOInstance inst(ADT,WmoInstansName[id].c_str(), map_num, tileX, tileY, dirfile); } delete[] WmoInstansName; - WmoInstansName = NULL; + WmoInstansName = nullptr; } } //====================== diff --git a/src/tools/vmap4_extractor/adtfile.h b/src/tools/vmap4_extractor/adtfile.h index 72ee528640a..2b03b9d7b1e 100644 --- a/src/tools/vmap4_extractor/adtfile.h +++ b/src/tools/vmap4_extractor/adtfile.h @@ -126,7 +126,7 @@ public: //uint32 wmo_count; /* - const mcell& Getmcell() const + mcell const& Getmcell() const { return Mcell; } diff --git a/src/tools/vmap4_extractor/dbcfile.cpp b/src/tools/vmap4_extractor/dbcfile.cpp index d12e279e2fc..25612818e44 100644 --- a/src/tools/vmap4_extractor/dbcfile.cpp +++ b/src/tools/vmap4_extractor/dbcfile.cpp @@ -24,7 +24,7 @@ #include <cstdio> DBCFile::DBCFile(const std::string& filename): - filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(NULL), stringTable(NULL) + filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr) { } @@ -46,7 +46,7 @@ bool DBCFile::open() if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C') { f.close(); - data = NULL; + data = nullptr; printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str()); return false; } diff --git a/src/tools/vmap4_extractor/dbcfile.h b/src/tools/vmap4_extractor/dbcfile.h index 6246f5b7708..cdee4b8ee9e 100644 --- a/src/tools/vmap4_extractor/dbcfile.h +++ b/src/tools/vmap4_extractor/dbcfile.h @@ -59,7 +59,7 @@ public: class Record { public: - Record& operator= (const Record& r) + Record& operator= (Record const& r) { file = r.file; offset = r.offset; @@ -116,15 +116,15 @@ public: } /// Return address of current instance Record const & operator*() const { return record; } - const Record* operator->() const { + Record const* operator->() const { return &record; } /// Comparison - bool operator==(const Iterator &b) const + bool operator==(Iterator const& b) const { return record.offset == b.record.offset; } - bool operator!=(const Iterator &b) const + bool operator!=(Iterator const& b) const { return record.offset != b.record.offset; } diff --git a/src/tools/vmap4_extractor/loadlib/loadlib.h b/src/tools/vmap4_extractor/loadlib/loadlib.h index 2e66892da1c..6d2d07b06de 100644 --- a/src/tools/vmap4_extractor/loadlib/loadlib.h +++ b/src/tools/vmap4_extractor/loadlib/loadlib.h @@ -19,31 +19,7 @@ #ifndef LOAD_LIB_H #define LOAD_LIB_H -#ifdef WIN32 -typedef __int64 int64; -typedef __int32 int32; -typedef __int16 int16; -typedef __int8 int8; -typedef unsigned __int64 uint64; -typedef unsigned __int32 uint32; -typedef unsigned __int16 uint16; -typedef unsigned __int8 uint8; -#else -#include <stdint.h> -#ifndef uint64_t -#ifdef __linux__ -#include <linux/types.h> -#endif -#endif -typedef int64_t int64; -typedef int32_t int32; -typedef int16_t int16; -typedef int8_t int8; -typedef uint64_t uint64; -typedef uint32_t uint32; -typedef uint16_t uint16; -typedef uint8_t uint8; -#endif +#include "Define.h" #define FILE_FORMAT_VERSION 18 diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp index 3b2f8368cab..4a4ff052433 100644 --- a/src/tools/vmap4_extractor/model.cpp +++ b/src/tools/vmap4_extractor/model.cpp @@ -69,30 +69,30 @@ bool Model::open() bool Model::ConvertToVMAPModel(const char * outfilename) { - int N[12] = {0,0,0,0,0,0,0,0,0,0,0,0}; - FILE* output=fopen(outfilename, "wb"); + int N[12] = { }; + FILE* output = fopen(outfilename, "wb"); if (!output) { - printf("Can't create the output file '%s'\n",outfilename); + printf("Can't create the output file '%s'\n", outfilename); return false; } fwrite(szRawVMAPMagic, 8, 1, output); uint32 nVertices = header.nBoundingVertices; fwrite(&nVertices, sizeof(int), 1, output); uint32 nofgroups = 1; - fwrite(&nofgroups,sizeof(uint32), 1, output); - fwrite(N,4*3,1,output);// rootwmoid, flags, groupid - fwrite(N,sizeof(float),3*2,output);//bbox, only needed for WMO currently - fwrite(N,4,1,output);// liquidflags - fwrite("GRP ",4,1,output); + fwrite(&nofgroups, sizeof(uint32), 1, output); + fwrite(N, 4 * 3, 1, output);// rootwmoid, flags, groupid + fwrite(N, sizeof(float), 3 * 2, output);//bbox, only needed for WMO currently + fwrite(N, 4, 1, output);// liquidflags + fwrite("GRP ", 4, 1, output); uint32 branches = 1; int wsize; wsize = sizeof(branches) + sizeof(uint32) * branches; fwrite(&wsize, sizeof(int), 1, output); - fwrite(&branches,sizeof(branches), 1, output); + fwrite(&branches, sizeof(branches), 1, output); uint32 nIndexes = header.nBoundingTriangles; - fwrite(&nIndexes,sizeof(uint32), 1, output); - fwrite("INDX",4, 1, output); + fwrite(&nIndexes, sizeof(uint32), 1, output); + fwrite("INDX", 4, 1, output); wsize = sizeof(uint32) + sizeof(unsigned short) * nIndexes; fwrite(&wsize, sizeof(int), 1, output); fwrite(&nIndexes, sizeof(uint32), 1, output); @@ -114,7 +114,7 @@ bool Model::ConvertToVMAPModel(const char * outfilename) wsize = sizeof(int) + sizeof(float) * 3 * nVertices; fwrite(&wsize, sizeof(int), 1, output); fwrite(&nVertices, sizeof(int), 1, output); - if (nVertices >0) + if (nVertices > 0) { for (uint32 vpos = 0; vpos < nVertices; ++vpos) { @@ -123,7 +123,7 @@ bool Model::ConvertToVMAPModel(const char * outfilename) vertices[vpos].z = tmp; } - fwrite(vertices, sizeof(float)*3, nVertices, output); + fwrite(vertices, sizeof(float) * 3, nVertices, output); } fclose(output); @@ -168,7 +168,7 @@ ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID fseek(input, 8, SEEK_SET); // get the correct no of vertices int nVertices; - int count = fread(&nVertices, sizeof (int), 1, input); + int count = fread(&nVertices, sizeof(int), 1, input); fclose(input); if (count != 1 || nVertices == 0) @@ -189,7 +189,7 @@ ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID fwrite(&pos, sizeof(float), 3, pDirfile); fwrite(&rot, sizeof(float), 3, pDirfile); fwrite(&sc, sizeof(float), 1, pDirfile); - uint32 nlen=strlen(ModelInstName); + uint32 nlen = strlen(ModelInstName); fwrite(&nlen, sizeof(uint32), 1, pDirfile); fwrite(ModelInstName, sizeof(char), nlen, pDirfile); diff --git a/src/tools/vmap4_extractor/model.h b/src/tools/vmap4_extractor/model.h index c86f13be337..39322e63288 100644 --- a/src/tools/vmap4_extractor/model.h +++ b/src/tools/vmap4_extractor/model.h @@ -35,8 +35,8 @@ private: { delete[] vertices; delete[] indices; - vertices = NULL; - indices = NULL; + vertices = nullptr; + indices = nullptr; } std::string filename; public: diff --git a/src/tools/vmap4_extractor/mpq_libmpq.cpp b/src/tools/vmap4_extractor/mpq_libmpq.cpp index 09f05d28ce1..7253b718c09 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq.cpp +++ b/src/tools/vmap4_extractor/mpq_libmpq.cpp @@ -23,7 +23,7 @@ ArchiveSet gOpenArchives; -MPQArchive::MPQArchive(const char* filename) +MPQArchive::MPQArchive(char const* filename) { int result = libmpq__archive_open(&mpq_a, filename, -1); printf("Opening %s\n", filename); @@ -64,7 +64,7 @@ void MPQArchive::close() libmpq__archive_close(mpq_a); } -MPQFile::MPQFile(const char* filename): +MPQFile::MPQFile(char const* filename): eof(false), buffer(0), pointer(0), diff --git a/src/tools/vmap4_extractor/mpq_libmpq04.h b/src/tools/vmap4_extractor/mpq_libmpq04.h index dea79961602..c4c473acd9f 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq04.h +++ b/src/tools/vmap4_extractor/mpq_libmpq04.h @@ -33,7 +33,7 @@ class MPQArchive public: mpq_archive_s *mpq_a; - MPQArchive(const char* filename); + MPQArchive(char const* filename); ~MPQArchive() { if (isOpened()) close(); } void GetFileListTo(std::vector<std::string>& filelist) { @@ -52,13 +52,13 @@ public: token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != NULL) && (counter < size)) { + while ((token != nullptr) && (counter < size)) { //cout << token << endl; token[strlen(token) - 1] = 0; std::string s = token; filelist.push_back(s); counter += strlen(token) + 2; - token = strtok(NULL, seps); + token = strtok(nullptr, seps); } delete[] buffer; @@ -77,11 +77,11 @@ class MPQFile char *buffer; libmpq__off_t pointer,size; - MPQFile(const MPQFile& /*f*/) = delete; - void operator=(const MPQFile& /*f*/) = delete; + MPQFile(MPQFile const& /*f*/) = delete; + void operator=(MPQFile const& /*f*/) = delete; public: - MPQFile(const char* filename); // filenames are not case sensitive + MPQFile(char const* filename); // filenames are not case sensitive ~MPQFile() { close(); } size_t read(void* dest, size_t bytes); size_t getSize() { return size; } diff --git a/src/tools/vmap4_extractor/vec3d.h b/src/tools/vmap4_extractor/vec3d.h index dd89bc1afb7..0b25d2f60b5 100644 --- a/src/tools/vmap4_extractor/vec3d.h +++ b/src/tools/vmap4_extractor/vec3d.h @@ -25,54 +25,55 @@ class Vec3D { public: - float x,y,z; + float x, y, z; - Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) {} + Vec3D(float x0 = 0.0f, float y0 = 0.0f, float z0 = 0.0f) : x(x0), y(y0), z(z0) { } - Vec3D(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {} + Vec3D(Vec3D const& v) : x(v.x), y(v.y), z(v.z) { } - Vec3D& operator= (const Vec3D &v) { + Vec3D& operator=(Vec3D const& v) + { x = v.x; y = v.y; z = v.z; return *this; } - Vec3D operator+ (const Vec3D &v) const + Vec3D operator+(Vec3D const& v) const { - Vec3D r(x+v.x,y+v.y,z+v.z); + Vec3D r(x + v.x, y + v.y, z + v.z); return r; } - Vec3D operator- (const Vec3D &v) const + Vec3D operator-(Vec3D const& v) const { - Vec3D r(x-v.x,y-v.y,z-v.z); + Vec3D r(x - v.x, y - v.y, z - v.z); return r; } - float operator* (const Vec3D &v) const + float operator*(Vec3D const& v) const { - return x*v.x + y*v.y + z*v.z; + return x * v.x + y * v.y + z * v.z; } - Vec3D operator* (float d) const + Vec3D operator*(float d) const { - Vec3D r(x*d,y*d,z*d); + Vec3D r(x * d, y * d, z * d); return r; } - friend Vec3D operator* (float d, const Vec3D& v) + friend Vec3D operator*(float d, Vec3D const& v) { return v * d; } - Vec3D operator% (const Vec3D &v) const + Vec3D operator%(Vec3D const& v) const { - Vec3D r(y*v.z-z*v.y, z*v.x-x*v.z, x*v.y-y*v.x); + Vec3D r(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x); return r; } - Vec3D& operator+= (const Vec3D &v) + Vec3D& operator+=(Vec3D const& v) { x += v.x; y += v.y; @@ -80,7 +81,7 @@ public: return *this; } - Vec3D& operator-= (const Vec3D &v) + Vec3D& operator-=(Vec3D const& v) { x -= v.x; y -= v.y; @@ -88,7 +89,7 @@ public: return *this; } - Vec3D& operator*= (float d) + Vec3D& operator*=(float d) { x *= d; y *= d; @@ -98,21 +99,21 @@ public: float lengthSquared() const { - return x*x+y*y+z*z; + return x * x + y * y + z * z; } float length() const { - return std::sqrt(x*x+y*y+z*z); + return std::sqrt(lengthSquared()); } Vec3D& normalize() { - this->operator*= (1.0f/length()); + *this *= (1.0f / length()); return *this; } - Vec3D operator~ () const + Vec3D operator~() const { Vec3D r(*this); r.normalize(); @@ -125,7 +126,7 @@ public: return in; } - friend std::ostream& operator<<(std::ostream& out, const Vec3D& v) + friend std::ostream& operator<<(std::ostream& out, Vec3D const& v) { out << v.x << " " << v.y << " " << v.z; return out; @@ -137,65 +138,65 @@ public: } }; - class Vec2D { public: - float x,y; + float x, y; - Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {} + Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) { } - Vec2D(const Vec2D& v) : x(v.x), y(v.y) {} + Vec2D(Vec2D const& v) : x(v.x), y(v.y) { } - Vec2D& operator= (const Vec2D &v) { + Vec2D& operator=(Vec2D const& v) + { x = v.x; y = v.y; return *this; } - Vec2D operator+ (const Vec2D &v) const + Vec2D operator+(Vec2D const& v) const { - Vec2D r(x+v.x,y+v.y); + Vec2D r(x + v.x, y + v.y); return r; } - Vec2D operator- (const Vec2D &v) const + Vec2D operator-(Vec2D const& v) const { - Vec2D r(x-v.x,y-v.y); + Vec2D r(x - v.x, y - v.y); return r; } - float operator* (const Vec2D &v) const + float operator*(Vec2D const& v) const { - return x*v.x + y*v.y; + return x * v.x + y * v.y; } - Vec2D operator* (float d) const + Vec2D operator*(float d) const { - Vec2D r(x*d,y*d); + Vec2D r(x * d, y * d); return r; } - friend Vec2D operator* (float d, const Vec2D& v) + friend Vec2D operator*(float d, Vec2D const& v) { return v * d; } - Vec2D& operator+= (const Vec2D &v) + Vec2D& operator+=(Vec2D const& v) { x += v.x; y += v.y; return *this; } - Vec2D& operator-= (const Vec2D &v) + Vec2D& operator-=(Vec2D const& v) { x -= v.x; y -= v.y; return *this; } - Vec2D& operator*= (float d) + Vec2D& operator*=(float d) { x *= d; y *= d; @@ -204,28 +205,27 @@ public: float lengthSquared() const { - return x*x+y*y; + return x * x + y * y; } float length() const { - return std::sqrt(x*x+y*y); + return std::sqrt(lengthSquared()); } Vec2D& normalize() { - this->operator*= (1.0f/length()); + *this *= (1.0f / length()); return *this; } - Vec2D operator~ () const + Vec2D operator~() const { Vec2D r(*this); r.normalize(); return r; } - friend std::istream& operator>>(std::istream& in, Vec2D& v) { in >> v.x >> v.y; @@ -238,9 +238,10 @@ public: } }; -inline void rotate(float x0, float y0, float *x, float *y, float angle) +inline void rotate(float x0, float y0, float* x, float* y, float angle) { - float xa = *x - x0, ya = *y - y0; + float xa = *x - x0; + float ya = *y - y0; *x = xa*cosf(angle) - ya*sinf(angle) + x0; *y = xa*sinf(angle) + ya*cosf(angle) + y0; } diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index a93e0f88308..aeac69b6751 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -16,21 +16,18 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#define _CRT_SECURE_NO_DEPRECATE - #include "adtfile.h" #include "wdtfile.h" #include "dbcfile.h" #include "wmo.h" #include "mpq_libmpq04.h" #include "vmapexport.h" +#include "Banner.h" +#include <sys/stat.h> #ifdef WIN32 - #include <sys/stat.h> #include <direct.h> #define mkdir _mkdir -#else - #include <sys/stat.h> #endif #include <cstdio> @@ -67,12 +64,12 @@ bool preciseVectorData = false; // Constants //static const char * szWorkDirMaps = ".\\Maps"; -const char* szWorkDirWmo = "./Buildings"; -const char* szRawVMAPMagic = "VMAP043"; +char const* szWorkDirWmo = "./Buildings"; +char const* szRawVMAPMagic = "VMAP043"; // Local testing functions -bool FileExists(const char* file) +bool FileExists(char const* file) { if (FILE* n = fopen(file, "rb")) { @@ -84,9 +81,9 @@ bool FileExists(const char* file) void strToLower(char* str) { - while(*str) + while (*str) { - *str=tolower(*str); + *str = tolower(*str); ++str; } } @@ -117,7 +114,7 @@ bool ExtractWmo() { bool success = true; - //const char* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"}; + //char const* ParsArchiveNames[] = {"patch-2.MPQ", "patch.MPQ", "common.MPQ", "expansion.MPQ"}; for (ArchiveSet::const_iterator ar_itr = gOpenArchives.begin(); ar_itr != gOpenArchives.end() && success; ++ar_itr) { @@ -152,7 +149,7 @@ bool ExtractSingleWmo(std::string& fname) int p = 0; // Select root wmo files char const* rchr = strrchr(plain_name, '_'); - if (rchr != NULL) + if (rchr != nullptr) { char cpy[4]; memcpy(cpy, rchr, 4); @@ -437,7 +434,9 @@ bool processArgv(int argc, char ** argv, const char *versionString) int main(int argc, char ** argv) { - bool success=true; + Trinity::Banner::Show("VMAP data extractor", [](char const* text) { printf("%s\n", text); }, nullptr); + + bool success = true; const char *versionString = "V4.00 2012_02"; // Use command line arguments, when some @@ -459,7 +458,7 @@ int main(int argc, char ** argv) } } - printf("Extract %s. Beginning work ....\n",versionString); + printf("Extract %s. Beginning work ....\n", versionString); //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // Create the working directory if (mkdir(szWorkDirWmo @@ -472,7 +471,7 @@ int main(int argc, char ** argv) // prepare archive name list std::vector<std::string> archiveNames; fillArchiveNameVector(archiveNames); - for (size_t i=0; i < archiveNames.size(); ++i) + for (size_t i = 0; i < archiveNames.size(); ++i) { MPQArchive *archive = new MPQArchive(archiveNames[i].c_str()); if (gOpenArchives.empty() || gOpenArchives.front() != archive) @@ -481,7 +480,7 @@ int main(int argc, char ** argv) if (gOpenArchives.empty()) { - printf("FATAL ERROR: None MPQ archive found by path '%s'. Use -d option with proper path.\n",input_path); + printf("FATAL ERROR: None MPQ archive found by path '%s'. Use -d option with proper path.\n", input_path); return 1; } ReadLiquidTypeTableDBC(); @@ -501,13 +500,13 @@ int main(int argc, char ** argv) printf("FATAL ERROR: Map.dbc not found in data file.\n"); return 1; } - map_count=dbc->getRecordCount (); - map_ids=new map_id[map_count]; - for (unsigned int x=0;x<map_count;++x) + map_count = dbc->getRecordCount(); + map_ids = new map_id[map_count]; + for (unsigned int x = 0; x < map_count; ++x) { map_ids[x].id = dbc->getRecord(x).getUInt(0); - const char* map_name = dbc->getRecord(x).getString(1); + char const* map_name = dbc->getRecord(x).getString(1); size_t max_map_name_length = sizeof(map_ids[x].name); if (strlen(map_name) >= max_map_name_length) { @@ -524,7 +523,7 @@ int main(int argc, char ** argv) delete dbc; ParsMapFiles(); - delete [] map_ids; + delete[] map_ids; //nError = ERROR_SUCCESS; // Extract models, listed in DameObjectDisplayInfo.dbc ExtractGameobjectModels(); @@ -533,11 +532,11 @@ int main(int argc, char ** argv) printf("\n"); if (!success) { - printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n",versionString, preciseVectorData); + printf("ERROR: Extract %s. Work NOT complete.\n Precise vector data=%d.\nPress any key.\n", versionString, preciseVectorData); getchar(); } - printf("Extract %s. Work complete. No errors.\n",versionString); - delete [] LiqType; + printf("Extract %s. Work complete. No errors.\n", versionString); + delete[] LiqType; return 0; } diff --git a/src/tools/vmap4_extractor/wdtfile.cpp b/src/tools/vmap4_extractor/wdtfile.cpp index d4265311fe3..fe045d36600 100644 --- a/src/tools/vmap4_extractor/wdtfile.cpp +++ b/src/tools/vmap4_extractor/wdtfile.cpp @@ -26,12 +26,12 @@ char * wdtGetPlainName(char * FileName) { char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } -WDTFile::WDTFile(char* file_name, char* file_name1) : gWmoInstansName(NULL), gnWMO(0), WDT(file_name) +WDTFile::WDTFile(char* file_name, char* file_name1) : gWmoInstansName(nullptr), gnWMO(0), WDT(file_name) { filename.append(file_name1,strlen(file_name1)); } @@ -104,7 +104,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID) } delete[] gWmoInstansName; - gWmoInstansName = NULL; + gWmoInstansName = nullptr; } } WDT.seek((int)nextpos); @@ -123,7 +123,7 @@ WDTFile::~WDTFile(void) ADTFile* WDTFile::GetMap(int x, int z) { if(!(x>=0 && z >= 0 && x<64 && z<64)) - return NULL; + return nullptr; char name[512]; diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index a46e786bef5..441fe281c04 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -486,18 +486,18 @@ WMOGroup::~WMOGroup() } WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile) - : currx(0), curry(0), wmo(NULL), doodadset(0), pos(), indx(0), id(0) + : currx(0), curry(0), wmo(nullptr), doodadset(0), pos(), indx(0), id(0) { float ff[3]; f.read(&id, 4); - f.read(ff,12); - pos = Vec3D(ff[0],ff[1],ff[2]); - f.read(ff,12); - rot = Vec3D(ff[0],ff[1],ff[2]); - f.read(ff,12); - pos2 = Vec3D(ff[0],ff[1],ff[2]); // bounding box corners - f.read(ff,12); - pos3 = Vec3D(ff[0],ff[1],ff[2]); // bounding box corners + f.read(ff, 12); + pos = Vec3D(ff[0], ff[1], ff[2]); + f.read(ff, 12); + rot = Vec3D(ff[0], ff[1], ff[2]); + f.read(ff, 12); + pos2 = Vec3D(ff[0], ff[1], ff[2]); // bounding box corners + f.read(ff, 12); + pos3 = Vec3D(ff[0], ff[1], ff[2]); // bounding box corners uint16 fflags; f.read(&fflags, 2); @@ -505,9 +505,9 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint uint16 doodadSet; f.read(&doodadSet, 2); - uint16 trash,adtId; - f.read(&adtId,2); - f.read(&trash,2); + uint16 trash, adtId; + f.read(&adtId, 2); + f.read(&trash, 2); // destructible wmo, do not dump. we can handle the vmap for these // in dynamic tree (gameobject vmaps) @@ -521,7 +521,7 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint FILE *input; input = fopen(tempname, "r+b"); - if(!input) + if (!input) { printf("WMOInstance::WMOInstance: couldn't open %s\n", tempname); return; @@ -529,19 +529,19 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint fseek(input, 8, SEEK_SET); // get the correct no of vertices int nVertices; - int count = fread(&nVertices, sizeof (int), 1, input); + int count = fread(&nVertices, sizeof(int), 1, input); fclose(input); if (count != 1 || nVertices == 0) return; - float x,z; + float x, z; x = pos.x; z = pos.z; - if(x==0 && z == 0) + if (x == 0 && z == 0) { - pos.x = 533.33333f*32; - pos.z = 533.33333f*32; + pos.x = 533.33333f * 32; + pos.z = 533.33333f * 32; } pos = fixCoords(pos); pos2 = fixCoords(pos2); @@ -549,7 +549,7 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint float scale = 1.0f; uint32 flags = MOD_HAS_BOUND; - if(tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN; + if (tileX == 65 && tileY == 65) flags |= MOD_WORLDSPAWN; //write mapID, tileX, tileY, Flags, ID, Pos, Rot, Scale, Bound_lo, Bound_hi, name fwrite(&mapID, sizeof(uint32), 1, pDirfile); fwrite(&tileX, sizeof(uint32), 1, pDirfile); @@ -562,7 +562,7 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint fwrite(&scale, sizeof(float), 1, pDirfile); fwrite(&pos2, sizeof(float), 3, pDirfile); fwrite(&pos3, sizeof(float), 3, pDirfile); - uint32 nlen=strlen(WmoInstName); + uint32 nlen = strlen(WmoInstName); fwrite(&nlen, sizeof(uint32), 1, pDirfile); fwrite(WmoInstName, sizeof(char), nlen, pDirfile); diff --git a/src/tools/vmap4_extractor/wmo.h b/src/tools/vmap4_extractor/wmo.h index 813ff50d756..74be0b05fa8 100644 --- a/src/tools/vmap4_extractor/wmo.h +++ b/src/tools/vmap4_extractor/wmo.h @@ -44,7 +44,7 @@ class WMOManager; class MPQFile; /* for whatever reason a certain company just can't stick to one coordinate system... */ -static inline Vec3D fixCoords(const Vec3D &v){ return Vec3D(v.z, v.x, v.y); } +static inline Vec3D fixCoords(Vec3D const& v){ return Vec3D(v.z, v.x, v.y); } class WMORoot { |
