diff --git a/src/tools/map_extractor/System.cpp b/src/tools/map_extractor/System.cpp index cc424c5d3..04ba78759 100644 --- a/src/tools/map_extractor/System.cpp +++ b/src/tools/map_extractor/System.cpp @@ -29,19 +29,19 @@ #include #if defined( __GNUC__ ) - #define _open open - #define _close close - #ifndef O_BINARY - #define O_BINARY 0 - #endif +#define _open open +#define _close close +#ifndef O_BINARY +#define O_BINARY 0 +#endif #else - #include +#include #endif #ifdef O_LARGEFILE - #define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE) +#define OPEN_FLAGS (O_RDONLY | O_BINARY | O_LARGEFILE) #else - #define OPEN_FLAGS (O_RDONLY | O_BINARY) +#define OPEN_FLAGS (O_RDONLY | O_BINARY) #endif extern ArchiveSet gOpenArchives; @@ -51,8 +51,8 @@ typedef struct uint32 id; } map_id; -map_id *map_ids; -uint16 *LiqType; +map_id* map_ids; +uint16* LiqType; #define MAX_PATH_LENGTH 128 char output_path[MAX_PATH_LENGTH] = "."; char input_path[MAX_PATH_LENGTH] = "."; @@ -80,7 +80,8 @@ float CONF_flat_height_delta_limit = 0.005f; // If max - min less this value - s float CONF_flat_liquid_delta_limit = 0.001f; // If max - min less this value - liquid surface is flat // List MPQ for extract from -const char *CONF_mpq_list[]={ +const char* CONF_mpq_list[] = +{ "common.MPQ", "common-2.MPQ", "lichking.MPQ", @@ -108,11 +109,11 @@ void CreateDir( const std::string& Path ) } int ret; - #ifdef _WIN32 +#ifdef _WIN32 ret = _mkdir( Path.c_str()); - #else +#else ret = mkdir( Path.c_str(), 0777 ); - #endif +#endif if (ret != 0) { printf("Fatal Error: Could not create directory %s check your permissions", Path.c_str()); @@ -145,7 +146,7 @@ void Usage(char* prg) exit(1); } -void HandleArgs(int argc, char * arg[]) +void HandleArgs(int argc, char* arg[]) { for(int c = 1; c < argc; ++c) { @@ -173,14 +174,14 @@ void HandleArgs(int argc, char * arg[]) break; case 'f': if(c + 1 < argc) // all ok - CONF_allow_float_to_int=atoi(arg[(c++) + 1])!=0; + CONF_allow_float_to_int = atoi(arg[(c++) + 1]) != 0; else Usage(arg[0]); break; case 'e': if(c + 1 < argc) // all ok { - CONF_extract=atoi(arg[(c++) + 1]); + CONF_extract = atoi(arg[(c++) + 1]); if(!(CONF_extract > 0 && CONF_extract < 4)) Usage(arg[0]); } @@ -194,7 +195,7 @@ void HandleArgs(int argc, char * arg[]) uint32 ReadBuild(int locale) { // include build info file also - std::string filename = std::string("component.wow-")+langs[locale]+".txt"; + std::string filename = std::string("component.wow-") + langs[locale] + ".txt"; //printf("Read %s file... ", filename.c_str()); MPQFile m(filename.c_str()); @@ -209,14 +210,14 @@ uint32 ReadBuild(int locale) size_t pos = text.find("version=\""); size_t pos1 = pos + strlen("version=\""); - size_t pos2 = text.find("\"",pos1); + size_t pos2 = text.find("\"", pos1); if (pos == text.npos || pos2 == text.npos || pos1 >= pos2) { printf("Fatal error: Invalid %s file format!\n", filename.c_str()); exit(1); } - std::string build_str = text.substr(pos1,pos2-pos1); + std::string build_str = text.substr(pos1, pos2 - pos1); int build = atoi(build_str.c_str()); if (build <= 0) @@ -357,16 +358,16 @@ float selectUInt16StepStore(float maxDiff) uint16 area_ids[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; float V8[ADT_GRID_SIZE][ADT_GRID_SIZE]; -float V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]; +float V9[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1]; uint16 uint16_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]; -uint16 uint16_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]; +uint16 uint16_V9[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1]; uint8 uint8_V8[ADT_GRID_SIZE][ADT_GRID_SIZE]; -uint8 uint8_V9[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]; +uint8 uint8_V9[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1]; uint16 liquid_entry[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; uint8 liquid_flags[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID]; bool liquid_show[ADT_GRID_SIZE][ADT_GRID_SIZE]; -float liquid_height[ADT_GRID_SIZE+1][ADT_GRID_SIZE+1]; +float liquid_height[ADT_GRID_SIZE + 1][ADT_GRID_SIZE + 1]; int16 flight_box_max[3][3]; int16 flight_box_min[3][3]; @@ -378,7 +379,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int if (!adt.loadFile(inputPath)) return false; - adt_MCIN *cells = adt.a_grid->getMCIN(); + adt_MCIN* cells = adt.a_grid->getMCIN(); if (!cells) { printf("Can't find cells in '%s'\n", inputPath.c_str()); @@ -437,11 +438,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int // // Get Height map from grid // - for (int i = 0; igetMCNK(i, j); + adt_MCNK* cell = cells->getMCNK(i, j); if (!cell) continue; // Height values for triangles stored in order: @@ -463,44 +464,44 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int // Set map height as grid height for (int y = 0; y <= ADT_CELL_SIZE; y++) { - int cy = i*ADT_CELL_SIZE + y; + int cy = i * ADT_CELL_SIZE + y; for (int x = 0; x <= ADT_CELL_SIZE; x++) { - int cx = j*ADT_CELL_SIZE + x; + int cx = j * ADT_CELL_SIZE + x; V9[cy][cx] = cell->ypos; } } for (int y = 0; y < ADT_CELL_SIZE; y++) { - int cy = i*ADT_CELL_SIZE + y; + int cy = i * ADT_CELL_SIZE + y; for (int x = 0; x < ADT_CELL_SIZE; x++) { - int cx = j*ADT_CELL_SIZE + x; + int cx = j * ADT_CELL_SIZE + x; V8[cy][cx] = cell->ypos; } } // Get custom height - adt_MCVT *v = cell->getMCVT(); + adt_MCVT* v = cell->getMCVT(); if (!v) continue; // get V9 height map for (int y = 0; y <= ADT_CELL_SIZE; y++) { - int cy = i*ADT_CELL_SIZE + y; + int cy = i * ADT_CELL_SIZE + y; for (int x = 0; x <= ADT_CELL_SIZE; x++) { - int cx = j*ADT_CELL_SIZE + x; - V9[cy][cx] += v->height_map[y*(ADT_CELL_SIZE * 2 + 1) + x]; + int cx = j * ADT_CELL_SIZE + x; + V9[cy][cx] += v->height_map[y * (ADT_CELL_SIZE * 2 + 1) + x]; } } // get V8 height map for (int y = 0; y < ADT_CELL_SIZE; y++) { - int cy = i*ADT_CELL_SIZE + y; + int cy = i * ADT_CELL_SIZE + y; for (int x = 0; x < ADT_CELL_SIZE; x++) { - int cx = j*ADT_CELL_SIZE + x; - V8[cy][cx] += v->height_map[y*(ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x]; + int cx = j * ADT_CELL_SIZE + x; + V8[cy][cx] += v->height_map[y * (ADT_CELL_SIZE * 2 + 1) + ADT_CELL_SIZE + 1 + x]; } } } @@ -510,9 +511,9 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int //============================================ float maxHeight = -20000; float minHeight = 20000; - for (int y = 0; ygetMCNK(i, j); + adt_MCNK* cell = cells->getMCNK(i, j); if (!cell) continue; - adt_MCLQ *liquid = cell->getMCLQ(); + adt_MCLQ* liquid = cell->getMCLQ(); int count = 0; if (!liquid || cell->sizeMCLQ <= 8) continue; @@ -684,14 +685,14 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int } // Get liquid map for grid (in WOTLK used MH2O chunk) - adt_MH2O * h2o = adt.a_grid->getMH2O(); + adt_MH2O* h2o = adt.a_grid->getMH2O(); if (h2o) { for (int i = 0; i < ADT_CELLS_PER_GRID; i++) { for(int j = 0; j < ADT_CELLS_PER_GRID; j++) { - adt_liquid_header *h = h2o->getLiquidData(i,j); + adt_liquid_header* h = h2o->getLiquidData(i, j); if (!h) continue; @@ -715,10 +716,18 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int liquid_entry[i][j] = h->liquidType; switch (LiqType[h->liquidType]) { - case LIQUID_TYPE_WATER: liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; break; - case LIQUID_TYPE_OCEAN: liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; break; - case LIQUID_TYPE_MAGMA: liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; break; - case LIQUID_TYPE_SLIME: liquid_flags[i][j] |= MAP_LIQUID_TYPE_SLIME; break; + case LIQUID_TYPE_WATER: + liquid_flags[i][j] |= MAP_LIQUID_TYPE_WATER; + break; + case LIQUID_TYPE_OCEAN: + liquid_flags[i][j] |= MAP_LIQUID_TYPE_OCEAN; + break; + case LIQUID_TYPE_MAGMA: + liquid_flags[i][j] |= MAP_LIQUID_TYPE_MAGMA; + break; + case LIQUID_TYPE_SLIME: + liquid_flags[i][j] |= MAP_LIQUID_TYPE_SLIME; + break; default: printf("\nCan't find Liquid type %u for map %s\nchunk %d,%d\n", h->liquidType, inputPath.c_str(), i, j); break; @@ -726,7 +735,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int // Dark water detect if (LiqType[h->liquidType] == LIQUID_TYPE_OCEAN) { - uint8 *lm = h2o->getLiquidLightMap(h); + uint8* lm = h2o->getLiquidLightMap(h); if (!lm) liquid_flags[i][j] |= MAP_LIQUID_TYPE_DARK_WATER; } @@ -734,14 +743,14 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int if (!count && liquid_flags[i][j]) printf("Wrong liquid detect in MH2O chunk"); - float *height = h2o->getLiquidHeightMap(h); + float* height = h2o->getLiquidHeightMap(h); int pos = 0; - for (int y=0; y<=h->height;y++) + for (int y = 0; y <= h->height; y++) { - int cy = i*ADT_CELL_SIZE + y + h->yOffset; - for (int x=0; x<= h->width; x++) + int cy = i * ADT_CELL_SIZE + y + h->yOffset; + for (int x = 0; x <= h->width; x++) { - int cx = j*ADT_CELL_SIZE + x + h->xOffset; + int cx = j * ADT_CELL_SIZE + x + h->xOffset; if (height) liquid_height[cy][cx] = height[pos]; else @@ -757,11 +766,11 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int //============================================ uint8 type = liquid_flags[0][0]; bool fullType = false; - for (int y=0;ygetMCNK(i,j); + adt_MCNK* cell = cells->getMCNK(i, j); if (!cell) continue; holes[i][j] = cell->holes; @@ -872,7 +881,7 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int fwrite(&map, sizeof(map), 1, output); // Store area data fwrite(&areaHeader, sizeof(areaHeader), 1, output); - if (!(areaHeader.flags&MAP_AREA_NO_AREA)) + if (!(areaHeader.flags & MAP_AREA_NO_AREA)) fwrite(area_ids, sizeof(area_ids), 1, output); // Store height data @@ -906,15 +915,15 @@ bool ConvertADT(std::string const& inputPath, std::string const& outputPath, int if (map.liquidMapOffset) { fwrite(&liquidHeader, sizeof(liquidHeader), 1, output); - if (!(liquidHeader.flags&MAP_LIQUID_NO_TYPE)) + if (!(liquidHeader.flags & MAP_LIQUID_NO_TYPE)) { fwrite(liquid_entry, sizeof(liquid_entry), 1, output); fwrite(liquid_flags, sizeof(liquid_flags), 1, output); } - if (!(liquidHeader.flags&MAP_LIQUID_NO_HEIGHT)) + if (!(liquidHeader.flags & MAP_LIQUID_NO_HEIGHT)) { - for (int y=0; y dbcfiles; // get DBC file list - for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end();++i) + for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) { vector files; (*i)->GetFileListTo(files); for (vector::iterator iter = files.begin(); iter != files.end(); ++iter) if (iter->rfind(".dbc") == iter->length() - strlen(".dbc")) - dbcfiles.insert(*iter); + dbcfiles.insert(*iter); } std::string path = output_path; @@ -1030,7 +1039,7 @@ void ExtractDBCFiles(int locale, bool basicLocale) { string filename = path; filename += (iter->c_str() + strlen("DBFilesClient\\")); - + if(FileExists(filename.c_str())) continue; @@ -1044,7 +1053,7 @@ void LoadLocaleMPQFiles(int const locale) { char filename[512]; - sprintf(filename,"%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]); + sprintf(filename, "%s/Data/%s/locale-%s.MPQ", input_path, langs[locale], langs[locale]); new MPQArchive(filename); for(int i = 1; i < 5; ++i) @@ -1053,7 +1062,7 @@ void LoadLocaleMPQFiles(int const locale) if(i > 1) sprintf(ext, "-%i", i); - sprintf(filename,"%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext); + sprintf(filename, "%s/Data/%s/patch-%s%s.MPQ", input_path, langs[locale], langs[locale], ext); if(FileExists(filename)) new MPQArchive(filename); } @@ -1062,7 +1071,7 @@ void LoadLocaleMPQFiles(int const locale) void LoadCommonMPQFiles() { char filename[512]; - int count = sizeof(CONF_mpq_list)/sizeof(char*); + int count = sizeof(CONF_mpq_list) / sizeof(char*); for(int i = 0; i < count; ++i) { sprintf(filename, "%s/Data/%s", input_path, CONF_mpq_list[i]); @@ -1073,11 +1082,11 @@ void LoadCommonMPQFiles() inline void CloseMPQFiles() { - for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end();++j) (*j)->close(); - gOpenArchives.clear(); + for(ArchiveSet::iterator j = gOpenArchives.begin(); j != gOpenArchives.end(); ++j) (*j)->close(); + gOpenArchives.clear(); } -int main(int argc, char * arg[]) +int main(int argc, char* arg[]) { printf("Map & DBC Extractor\n"); printf("===================\n\n"); diff --git a/src/tools/map_extractor/adt.cpp b/src/tools/map_extractor/adt.cpp index 257d0171a..0b53f0ce0 100644 --- a/src/tools/map_extractor/adt.cpp +++ b/src/tools/map_extractor/adt.cpp @@ -12,13 +12,13 @@ int holetab_h[4] = { 0x1111, 0x2222, 0x4444, 0x8888 }; int holetab_v[4] = { 0x000F, 0x00F0, 0x0F00, 0xF000 }; -u_map_fcc MHDRMagic = { { 'R','D','H','M' } }; -u_map_fcc MCINMagic = { { 'N','I','C','M' } }; -u_map_fcc MH2OMagic = { { 'O','2','H','M' } }; -u_map_fcc MCNKMagic = { { 'K','N','C','M' } }; -u_map_fcc MCVTMagic = { { 'T','V','C','M' } }; -u_map_fcc MCLQMagic = { { 'Q','L','C','M' } }; -u_map_fcc MFBOMagic = { { 'O','B','F','M' } }; +u_map_fcc MHDRMagic = { { 'R', 'D', 'H', 'M' } }; +u_map_fcc MCINMagic = { { 'N', 'I', 'C', 'M' } }; +u_map_fcc MH2OMagic = { { 'O', '2', 'H', 'M' } }; +u_map_fcc MCNKMagic = { { 'K', 'N', 'C', 'M' } }; +u_map_fcc MCVTMagic = { { 'T', 'V', 'C', 'M' } }; +u_map_fcc MCLQMagic = { { 'Q', 'L', 'C', 'M' } }; +u_map_fcc MFBOMagic = { { 'O', 'B', 'F', 'M' } }; bool isHole(int holes, int i, int j) { @@ -58,7 +58,7 @@ bool ADT_file::prepareLoadedData() return false; // Check and prepare MHDR - a_grid = (adt_MHDR *)(GetData()+8+version->size); + a_grid = (adt_MHDR*)(GetData() + 8 + version->size); if (!a_grid->prepareLoadedData()) return false; @@ -93,9 +93,9 @@ bool adt_MCIN::prepareLoadedData() return false; // Check cells data - for (int i=0; iprepareLoadedData()) + for (int i = 0; i < ADT_CELLS_PER_GRID; i++) + for (int j = 0; j < ADT_CELLS_PER_GRID; j++) + if (cells[i][j].offsMCNK && !getMCNK(i, j)->prepareLoadedData()) return false; return true; @@ -107,8 +107,8 @@ bool adt_MH2O::prepareLoadedData() return false; // Check liquid data -// for (int i=0; iformatFlags & ADT_LIQUID_HEADER_NO_HIGHT) return 0; if (h->offsData2b) - return (float *)((uint8*)this + 8 + h->offsData2b); + return (float*)((uint8*)this + 8 + h->offsData2b); return 0; } - uint8 *getLiquidLightMap(adt_liquid_header *h) + uint8* getLiquidLightMap(adt_liquid_header* h) { - if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT) + if (h->formatFlags & ADT_LIQUID_HEADER_FULL_LIGHT) return 0; if (h->offsData2b) { if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT) - return (uint8 *)((uint8*)this + 8 + h->offsData2b); - return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4); + return (uint8*)((uint8*)this + 8 + h->offsData2b); + return (uint8*)((uint8*)this + 8 + h->offsData2b + (h->width + 1) * (h->height + 1) * 4); } return 0; } - uint32 *getLiquidFullLightMap(adt_liquid_header *h) + uint32* getLiquidFullLightMap(adt_liquid_header* h) { - if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)) + if (!(h->formatFlags & ADT_LIQUID_HEADER_FULL_LIGHT)) return 0; if (h->offsData2b) { if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT) - return (uint32 *)((uint8*)this + 8 + h->offsData2b); - return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4); + return (uint32*)((uint8*)this + 8 + h->offsData2b); + return (uint32*)((uint8*)this + 8 + h->offsData2b + (h->width + 1) * (h->height + 1) * 4); } return 0; } - uint64 getLiquidShowMap(adt_liquid_header *h) + uint64 getLiquidShowMap(adt_liquid_header* h) { if (h->offsData2a) - return *((uint64 *)((uint8*)this + 8 + h->offsData2a)); + return *((uint64*)((uint8*)this + 8 + h->offsData2a)); else return 0xFFFFFFFFFFFFFFFFuLL; } @@ -274,7 +283,8 @@ public: // class adt_MHDR { - union{ + union + { uint32 fcc; char fcc_txt[4]; }; @@ -317,14 +327,15 @@ public: } }; -class ADT_file : public FileLoader{ +class ADT_file : public FileLoader +{ public: bool prepareLoadedData(); ADT_file(); ~ADT_file(); void free(); - adt_MHDR *a_grid; + adt_MHDR* a_grid; }; #endif diff --git a/src/tools/map_extractor/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp index b535a18fb..0a9e285f5 100644 --- a/src/tools/map_extractor/dbcfile.cpp +++ b/src/tools/map_extractor/dbcfile.cpp @@ -19,35 +19,35 @@ bool DBCFile::open() { MPQFile f(filename.c_str()); char header[4]; - unsigned int na,nb,es,ss; + unsigned int na, nb, es, ss; - if(f.read(header,4)!=4) // Number of records + if(f.read(header, 4) != 4) // Number of records return false; - if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C') + if(header[0] != 'W' || header[1] != 'D' || header[2] != 'B' || header[3] != 'C') return false; - if(f.read(&na,4)!=4) // Number of records + if(f.read(&na, 4) != 4) // Number of records return false; - if(f.read(&nb,4)!=4) // Number of fields + if(f.read(&nb, 4) != 4) // Number of fields return false; - if(f.read(&es,4)!=4) // Size of a record + if(f.read(&es, 4) != 4) // Size of a record return false; - if(f.read(&ss,4)!=4) // String size + if(f.read(&ss, 4) != 4) // String size return false; recordSize = es; recordCount = na; fieldCount = nb; stringSize = ss; - if(fieldCount*4 != recordSize) + if(fieldCount * 4 != recordSize) return false; - data = new unsigned char[recordSize*recordCount+stringSize]; - stringTable = data + recordSize*recordCount; + data = new unsigned char[recordSize * recordCount + stringSize]; + stringTable = data + recordSize * recordCount; - size_t data_size = recordSize*recordCount+stringSize; - if(f.read(data,data_size)!=data_size) + size_t data_size = recordSize * recordCount + stringSize; + if(f.read(data, data_size) != data_size) return false; f.close(); return true; @@ -60,7 +60,7 @@ DBCFile::~DBCFile() DBCFile::Record DBCFile::getRecord(size_t id) { assert(data); - return Record(*this, data + id*recordSize); + return Record(*this, data + id * recordSize); } size_t DBCFile::getMaxId() diff --git a/src/tools/map_extractor/dbcfile.h b/src/tools/map_extractor/dbcfile.h index 37993f20a..60876afef 100644 --- a/src/tools/map_extractor/dbcfile.h +++ b/src/tools/map_extractor/dbcfile.h @@ -12,7 +12,7 @@ class DBCFile { public: - DBCFile(const std::string &filename); + DBCFile(const std::string& filename); ~DBCFile(); // Open database. It must be openened before it can be used. @@ -22,11 +22,11 @@ public: class Exception { public: - Exception(const std::string &message): message(message) + Exception(const std::string& message): message(message) { } virtual ~Exception() { } - const std::string &getMessage() {return message;} + const std::string& getMessage() {return message;} private: std::string message; }; @@ -44,19 +44,19 @@ public: float getFloat(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+field*4); + return *reinterpret_cast(offset + field * 4); } unsigned int getUInt(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+field*4); + return *reinterpret_cast(offset + field * 4); } int getInt(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+field*4); + return *reinterpret_cast(offset + field * 4); } - const char *getString(size_t field) const + const char* getString(size_t field) const { assert(field < file.fieldCount); size_t stringOffset = getUInt(field); @@ -64,9 +64,9 @@ public: return reinterpret_cast(file.stringTable + stringOffset); } private: - Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {} - DBCFile &file; - unsigned char *offset; + Record(DBCFile& file, unsigned char* offset): file(file), offset(offset) {} + DBCFile& file; + unsigned char* offset; friend class DBCFile; friend class DBCFile::Iterator; @@ -76,24 +76,26 @@ public: class Iterator { public: - Iterator(DBCFile &file, unsigned char *offset): + Iterator(DBCFile& file, unsigned char* offset): record(file, offset) {} /// Advance (prefix only) - Iterator & operator++() { + Iterator& operator++() + { record.offset += record.file.recordSize; return *this; } /// Return address of current instance - Record const & operator*() const { return record; } - const Record* operator->() const { + Record const& operator*() const { return record; } + const Record* operator->() const + { return &record; } /// Comparison - bool operator==(const Iterator &b) const + bool operator==(const Iterator& b) const { return record.offset == b.record.offset; } - bool operator!=(const Iterator &b) const + bool operator!=(const Iterator& b) const { return record.offset != b.record.offset; } @@ -117,8 +119,8 @@ private: size_t recordCount; size_t fieldCount; size_t stringSize; - unsigned char *data; - unsigned char *stringTable; + unsigned char* data; + unsigned char* stringTable; }; #endif diff --git a/src/tools/map_extractor/loadlib.cpp b/src/tools/map_extractor/loadlib.cpp index 5d173cb1f..db33e59cc 100644 --- a/src/tools/map_extractor/loadlib.cpp +++ b/src/tools/map_extractor/loadlib.cpp @@ -12,7 +12,7 @@ class MPQFile; -u_map_fcc MverMagic = { {'R','E','V','M'} }; +u_map_fcc MverMagic = { {'R', 'E', 'V', 'M'} }; FileLoader::FileLoader() { @@ -54,7 +54,7 @@ bool FileLoader::loadFile(std::string const& fileName, bool log) bool FileLoader::prepareLoadedData() { // Check version - version = (file_MVER *) data; + version = (file_MVER*) data; if (version->fcc != MverMagic.fcc) return false; if (version->ver != FILE_FORMAT_VERSION) diff --git a/src/tools/map_extractor/loadlib/loadlib.h b/src/tools/map_extractor/loadlib/loadlib.h index e500f25e6..c8eb82499 100644 --- a/src/tools/map_extractor/loadlib/loadlib.h +++ b/src/tools/map_extractor/loadlib/loadlib.h @@ -48,7 +48,8 @@ union u_map_fcc // struct file_MVER { - union{ + union + { uint32 fcc; char fcc_txt[4]; }; @@ -56,15 +57,16 @@ struct file_MVER uint32 ver; }; -class FileLoader{ - uint8 *data; +class FileLoader +{ + uint8* data; uint32 data_size; public: virtual bool prepareLoadedData(); - uint8 *GetData() {return data;} + uint8* GetData() {return data;} uint32 GetDataSize() {return data_size;} - file_MVER *version; + file_MVER* version; FileLoader(); ~FileLoader(); bool loadFile(std::string const& filename, bool log = true); diff --git a/src/tools/map_extractor/mpq_libmpq.cpp b/src/tools/map_extractor/mpq_libmpq.cpp index 9797b3d01..315b00deb 100644 --- a/src/tools/map_extractor/mpq_libmpq.cpp +++ b/src/tools/map_extractor/mpq_libmpq.cpp @@ -14,8 +14,10 @@ MPQArchive::MPQArchive(const char* filename) { int result = libmpq__archive_open(&mpq_a, filename, -1); printf("Opening %s\n", filename); - if(result) { - switch(result) { + if(result) + { + switch(result) + { case LIBMPQ_ERROR_OPEN : printf("Error opening archive '%s': Does file really exist?\n", filename); break; @@ -52,9 +54,9 @@ MPQFile::MPQFile(const char* filename): pointer(0), size(0) { - for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) + for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) { - mpq_archive *mpq_a = (*i)->mpq_a; + mpq_archive* mpq_a = (*i)->mpq_a; uint32_t filenum; if(libmpq__file_number(mpq_a, filename, &filenum)) continue; @@ -62,8 +64,9 @@ MPQFile::MPQFile(const char* filename): libmpq__file_unpacked_size(mpq_a, filenum, &size); // HACK: in patch.mpq some files don't want to open and give 1 for filesize - if (size<=1) { -// printf("warning: file %s has size %d; cannot read.\n", filename, size); + if (size <= 1) + { + // printf("warning: file %s has size %d; cannot read.\n", filename, size); eof = true; buffer = 0; return; @@ -85,7 +88,8 @@ size_t MPQFile::read(void* dest, size_t bytes) if (eof) return 0; size_t rpos = pointer + bytes; - if (rpos > size_t(size)) { + if (rpos > size_t(size)) + { bytes = size - pointer; eof = true; } diff --git a/src/tools/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h index 12af75d8a..d9f8d8640 100644 --- a/src/tools/map_extractor/mpq_libmpq04.h +++ b/src/tools/map_extractor/mpq_libmpq04.h @@ -21,29 +21,31 @@ class MPQArchive { public: - mpq_archive_s *mpq_a; + mpq_archive_s* mpq_a; MPQArchive(const char* filename); ~MPQArchive() { close(); } void close(); - void GetFileListTo(vector& filelist) { + void GetFileListTo(vector& filelist) + { uint32_t filenum; if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return; libmpq__off_t size, transferred; libmpq__file_unpacked_size(mpq_a, filenum, &size); - char *buffer = new char[size+1]; + char* buffer = new char[size + 1]; buffer[size] = '\0'; libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); char seps[] = "\n"; - char *token; + char* token; token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != nullptr) && (counter < size)) { + while ((token != nullptr) && (counter < size)) + { //cout << token << endl; token[strlen(token) - 1] = 0; string s = token; @@ -61,8 +63,8 @@ class MPQFile { //MPQHANDLE handle; bool eof; - char *buffer; - libmpq__off_t pointer,size; + char* buffer; + libmpq__off_t pointer, size; // disable copying MPQFile(const MPQFile& /*f*/) {} @@ -82,15 +84,15 @@ public: void close(); }; -inline void flipcc(char *fcc) +inline void flipcc(char* fcc) { char t; - t=fcc[0]; - fcc[0]=fcc[3]; - fcc[3]=t; - t=fcc[1]; - fcc[1]=fcc[2]; - fcc[2]=t; + t = fcc[0]; + fcc[0] = fcc[3]; + fcc[3] = t; + t = fcc[1]; + fcc[1] = fcc[2]; + fcc[2] = t; } #endif diff --git a/src/tools/map_extractor/wdt.cpp b/src/tools/map_extractor/wdt.cpp index 82a5e32f2..2e5107299 100644 --- a/src/tools/map_extractor/wdt.cpp +++ b/src/tools/map_extractor/wdt.cpp @@ -59,13 +59,13 @@ bool WDT_file::prepareLoadedData() if (!FileLoader::prepareLoadedData()) return false; - mphd = (wdt_MPHD *)((uint8*)version+version->size+8); + mphd = (wdt_MPHD*)((uint8*)version + version->size + 8); if (!mphd->prepareLoadedData()) return false; - main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8); + main = (wdt_MAIN*)((uint8*)mphd + mphd->size + 8); if (!main->prepareLoadedData()) return false; - wmo = (wdt_MWMO *)((uint8*)main+ main->size+8); + wmo = (wdt_MWMO*)((uint8*)main + main->size + 8); if (!wmo->prepareLoadedData()) return false; return true; diff --git a/src/tools/map_extractor/wdt.h b/src/tools/map_extractor/wdt.h index f65d6d938..6aa9407e0 100644 --- a/src/tools/map_extractor/wdt.h +++ b/src/tools/map_extractor/wdt.h @@ -13,8 +13,10 @@ //************************************************************************************** #define WDT_MAP_SIZE 64 -class wdt_MWMO{ - union{ +class wdt_MWMO +{ + union + { uint32 fcc; char fcc_txt[4]; }; @@ -23,8 +25,10 @@ public: bool prepareLoadedData(); }; -class wdt_MPHD{ - union{ +class wdt_MPHD +{ + union + { uint32 fcc; char fcc_txt[4]; }; @@ -42,15 +46,18 @@ public: bool prepareLoadedData(); }; -class wdt_MAIN{ - union{ +class wdt_MAIN +{ + union + { uint32 fcc; char fcc_txt[4]; }; public: uint32 size; - struct adtData{ + struct adtData + { uint32 exist; uint32 data1; } adt_list[64][64]; @@ -58,7 +65,8 @@ public: bool prepareLoadedData(); }; -class WDT_file : public FileLoader{ +class WDT_file : public FileLoader +{ public: bool prepareLoadedData(); @@ -66,9 +74,9 @@ public: ~WDT_file(); void free(); - wdt_MPHD *mphd; - wdt_MAIN *main; - wdt_MWMO *wmo; + wdt_MPHD* mphd; + wdt_MAIN* main; + wdt_MWMO* wmo; }; #endif \ No newline at end of file diff --git a/src/tools/mesh_extractor/ChunkedData.cpp b/src/tools/mesh_extractor/ChunkedData.cpp index 91d3f9036..0f186013c 100644 --- a/src/tools/mesh_extractor/ChunkedData.cpp +++ b/src/tools/mesh_extractor/ChunkedData.cpp @@ -11,7 +11,7 @@ #include ChunkedData::ChunkedData( FILE* stream, uint32 maxLength, uint32 chunksHint /*= 300*/ ) : -Stream(stream) + Stream(stream) { if (!Stream) return; diff --git a/src/tools/mesh_extractor/ChunkedData.h b/src/tools/mesh_extractor/ChunkedData.h index f979d9c46..f5f08c34b 100644 --- a/src/tools/mesh_extractor/ChunkedData.h +++ b/src/tools/mesh_extractor/ChunkedData.h @@ -14,7 +14,7 @@ class ChunkedData { public: ChunkedData(FILE* stream, uint32 maxLength, uint32 chunksHint = 300); - ChunkedData(const std::string &file, uint32 chunksHint = 300); + ChunkedData(const std::string& file, uint32 chunksHint = 300); ~ChunkedData(); int GetFirstIndex(const std::string& name); diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp index 069f45f17..dda39aef3 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.cpp +++ b/src/tools/mesh_extractor/ContinentBuilder.cpp @@ -23,13 +23,13 @@ private: ContinentBuilder* cBuilder; public: BuilderThread(ContinentBuilder* _cBuilder, dtNavMeshParams& params) : Params(params), cBuilder(_cBuilder), Free(true) {} - - void SetData(int x, int y, int map, const std::string& cont) - { - X = x; - Y = y; - MapId = map; - Continent = cont; + + void SetData(int x, int y, int map, const std::string& cont) + { + X = x; + Y = y; + MapId = map; + Continent = cont; } int svc() @@ -116,13 +116,13 @@ void ContinentBuilder::Build() CalculateTileBounds(); dtNavMeshParams params; - + std::vector Threads; if (TileMap->IsGlobalModel) { printf("Map %s ( %u ) is a WMO. Building with 1 thread.\n", Continent.c_str(), MapId); - + TileBuilder* builder = new TileBuilder(this, Continent, 0, 0, MapId); builder->AddGeometry(TileMap->Model, TileMap->ModelDefinition); uint8* nav = builder->BuildInstance(params); diff --git a/src/tools/mesh_extractor/ContinentBuilder.h b/src/tools/mesh_extractor/ContinentBuilder.h index 9901a8c4f..baf768206 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.h +++ b/src/tools/mesh_extractor/ContinentBuilder.h @@ -16,7 +16,7 @@ public: ContinentBuilder(std::string continent, uint32 mapId, WDT* wdt, uint32 tn) : Continent(continent), TileMap(wdt), MapId(mapId), NumberOfThreads(tn), tileXMin(64), tileYMin(64), tileXMax(0), tileYMax(0) - {} + {} void Build(); void getTileBounds(uint32 tileX, uint32 tileY, float* verts, int vertCount, float* bmin, float* bmax); diff --git a/src/tools/mesh_extractor/DBC.cpp b/src/tools/mesh_extractor/DBC.cpp index 7665b80e5..af6d2e48a 100644 --- a/src/tools/mesh_extractor/DBC.cpp +++ b/src/tools/mesh_extractor/DBC.cpp @@ -58,7 +58,7 @@ std::string DBC::GetStringByOffset( int offset ) break; } } - char* d = new char[len+1]; + char* d = new char[len + 1]; strcpy(d, (const char*)(StringBlock + offset)); d[len] = '\0'; std::string val = std::string(d); diff --git a/src/tools/mesh_extractor/DoodadHandler.cpp b/src/tools/mesh_extractor/DoodadHandler.cpp index 37397e394..f902d7595 100644 --- a/src/tools/mesh_extractor/DoodadHandler.cpp +++ b/src/tools/mesh_extractor/DoodadHandler.cpp @@ -10,7 +10,7 @@ #include "Model.h" #include "G3D/Matrix4.h" -DoodadHandler::DoodadHandler( ADT* adt ) : +DoodadHandler::DoodadHandler( ADT* adt ) : ObjectDataHandler(adt), _definitions(nullptr), _paths(nullptr) { Chunk* mddf = adt->ObjectData->GetChunkByName("MDDF"); @@ -27,7 +27,7 @@ void DoodadHandler::ProcessInternal( MapChunk* mcnk ) { if (!IsSane()) return; - + uint32 refCount = mcnk->Header.DoodadRefs; FILE* stream = mcnk->Source->GetStream(); fseek(stream, mcnk->Source->Offset + mcnk->Header.OffsetMCRF, SEEK_SET); @@ -100,7 +100,7 @@ void DoodadHandler::ReadDoodadPaths( Chunk* id, Chunk* data ) void DoodadHandler::InsertModelGeometry(const DoodadDefinition& def, Model* model) { uint32 vertOffset = Vertices.size(); - + for (std::vector::iterator itr = model->Vertices.begin(); itr != model->Vertices.end(); ++itr) Vertices.push_back(Utils::TransformDoodadVertex(def, *itr)); // Vertices have to be converted based on the information from the DoodadDefinition struct diff --git a/src/tools/mesh_extractor/LiquidHandler.cpp b/src/tools/mesh_extractor/LiquidHandler.cpp index 3af11e337..e3b709017 100644 --- a/src/tools/mesh_extractor/LiquidHandler.cpp +++ b/src/tools/mesh_extractor/LiquidHandler.cpp @@ -100,7 +100,7 @@ void LiquidHandler::HandleNewLiquid() Vertices.push_back(Vector3(location.x, location.y - Constants::UnitSize, location.z)); Vertices.push_back(Vector3(location.x - Constants::UnitSize, location.y - Constants::UnitSize, location.z)); - Triangles.push_back(Triangle(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset+2, vertOffset + 1)); + Triangles.push_back(Triangle(Constants::TRIANGLE_TYPE_WATER, vertOffset, vertOffset + 2, vertOffset + 1)); Triangles.push_back(Triangle(Constants::TRIANGLE_TYPE_WATER, vertOffset + 2, vertOffset + 3, vertOffset + 1)); } } diff --git a/src/tools/mesh_extractor/MPQ.cpp b/src/tools/mesh_extractor/MPQ.cpp index 79803af5b..be7844e13 100644 --- a/src/tools/mesh_extractor/MPQ.cpp +++ b/src/tools/mesh_extractor/MPQ.cpp @@ -46,9 +46,9 @@ void MPQArchive::close() } MPQFile::MPQFile(const char* filename): -eof(false), buffer(0), pointer(0), size(0) + eof(false), buffer(0), pointer(0), size(0) { - for (std::deque::iterator i = MPQHandler->Archives.begin(); i != MPQHandler->Archives.end();++i) + for (std::deque::iterator i = MPQHandler->Archives.begin(); i != MPQHandler->Archives.end(); ++i) { mpq_archive* mpq_a = (*i)->mpq_a; @@ -59,7 +59,8 @@ eof(false), buffer(0), pointer(0), size(0) libmpq__file_unpacked_size(mpq_a, filenum, &size); // HACK: in patch.mpq some files don't want to open and give 1 for filesize - if (size<=1) { + if (size <= 1) + { // printf("warning: file %s has size %d; cannot Read.\n", filename, size); eof = true; buffer = 0; @@ -83,7 +84,8 @@ size_t MPQFile::Read(void* dest, size_t bytes) return 0; size_t rpos = pointer + bytes; - if (rpos > size_t(size)) { + if (rpos > size_t(size)) + { bytes = size - pointer; eof = true; } diff --git a/src/tools/mesh_extractor/MPQ.h b/src/tools/mesh_extractor/MPQ.h index b41896107..a924a8f05 100644 --- a/src/tools/mesh_extractor/MPQ.h +++ b/src/tools/mesh_extractor/MPQ.h @@ -18,52 +18,52 @@ class MPQArchive { - - public: - mpq_archive_s *mpq_a; - - std::vector Files; - - MPQArchive(const char* filename); - void close(); - - void GetFileListTo(std::vector& filelist) + +public: + mpq_archive_s* mpq_a; + + std::vector Files; + + MPQArchive(const char* filename); + void close(); + + void GetFileListTo(std::vector& filelist) + { + uint32_t filenum; + if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return; + libmpq__off_t size, transferred; + libmpq__file_unpacked_size(mpq_a, filenum, &size); + + char* buffer = new char[size + 1]; + buffer[size] = '\0'; + + libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); + + char seps[] = "\n"; + char* token; + + token = strtok( buffer, seps ); + uint32 counter = 0; + while ((token != nullptr) && (counter < size)) { - uint32_t filenum; - if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return; - libmpq__off_t size, transferred; - libmpq__file_unpacked_size(mpq_a, filenum, &size); - - char* buffer = new char[size + 1]; - buffer[size] = '\0'; - - libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); - - char seps[] = "\n"; - char* token; - - token = strtok( buffer, seps ); - uint32 counter = 0; - 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(nullptr, seps); - } - - delete[] buffer; + //cout << token << endl; + token[strlen(token) - 1] = 0; + std::string s = token; + filelist.push_back(s); + counter += strlen(token) + 2; + token = strtok(nullptr, seps); } + + delete[] buffer; + } }; class MPQFile { //MPQHANDLE handle; bool eof; - char *buffer; - libmpq__off_t pointer,size; + char* buffer; + libmpq__off_t pointer, size; // disable copying MPQFile(const MPQFile& /*f*/) {} @@ -84,15 +84,15 @@ public: void close(); }; -inline void flipcc(char *fcc) +inline void flipcc(char* fcc) { char t; - t=fcc[0]; - fcc[0]=fcc[3]; - fcc[3]=t; - t=fcc[1]; - fcc[1]=fcc[2]; - fcc[2]=t; + t = fcc[0]; + fcc[0] = fcc[3]; + fcc[3] = t; + t = fcc[1]; + fcc[1] = fcc[2]; + fcc[2] = t; } #endif diff --git a/src/tools/mesh_extractor/MPQManager.cpp b/src/tools/mesh_extractor/MPQManager.cpp index 5d766a7e4..8fe312c65 100644 --- a/src/tools/mesh_extractor/MPQManager.cpp +++ b/src/tools/mesh_extractor/MPQManager.cpp @@ -9,7 +9,8 @@ #include "DBC.h" #include "Utils.h" -char const* MPQManager::Files[] = { +char const* MPQManager::Files[] = +{ "common.MPQ", "common-2.MPQ", "expansion.MPQ", diff --git a/src/tools/mesh_extractor/MapChunk.cpp b/src/tools/mesh_extractor/MapChunk.cpp index f36c533b5..a34a71321 100644 --- a/src/tools/mesh_extractor/MapChunk.cpp +++ b/src/tools/mesh_extractor/MapChunk.cpp @@ -38,9 +38,9 @@ void MapChunk::GenerateTriangles() { MCNKLiquidData& data = Adt->_LiquidHandler->MCNKData[Index]; float maxHeight = std::max( - std::max( - std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z), - Vertices[bottomRight].z), Vertices[center].z); + std::max( + std::max(std::max(Vertices[topLeft].z, Vertices[topRight].z), Vertices[bottomLeft].z), + Vertices[bottomRight].z), Vertices[center].z); if (data.IsWater(x, y, maxHeight)) triangleType = Constants::TRIANGLE_TYPE_WATER; } diff --git a/src/tools/mesh_extractor/MeshExtractor.cpp b/src/tools/mesh_extractor/MeshExtractor.cpp index d4d033f61..19ac135d1 100644 --- a/src/tools/mesh_extractor/MeshExtractor.cpp +++ b/src/tools/mesh_extractor/MeshExtractor.cpp @@ -137,7 +137,7 @@ void ExtractGameobjectModels() fwrite(&numVerts, sizeof(uint32), 1, output); uint32 numGroups = 1; fwrite(&numGroups, sizeof(uint32), 1, output); - fwrite(Nop, 4 * 3 , 1, output); // rootwmoid, flags, groupid + fwrite(Nop, 4 * 3, 1, output); // rootwmoid, flags, groupid fwrite(Nop, sizeof(float), 3 * 2, output);//bbox, only needed for WMO currently fwrite(Nop, 4, 1, output);// liquidflags fwrite("GRP ", 4, 1, output); @@ -171,7 +171,7 @@ void ExtractGameobjectModels() wsize = sizeof(int) + sizeof(float) * 3 * numVerts; fwrite(&wsize, sizeof(int), 1, output); fwrite(&numVerts, sizeof(int), 1, output); - float* vertices = new float[numVerts*3]; + float* vertices = new float[numVerts * 3]; if (numVerts > 0) { @@ -213,7 +213,7 @@ void ExtractGameobjectModels() fwrite(&model.Header.CountGroups, sizeof(uint32), 1, output); fwrite(&model.Header.WmoId, sizeof(uint32), 1, output); - const char grp[] = { 'G' , 'R' , 'P', ' ' }; + const char grp[] = { 'G', 'R', 'P', ' ' }; for (std::vector::iterator itr2 = model.Groups.begin(); itr2 != model.Groups.end(); ++itr2) { const WMOGroupHeader& header = itr2->Header; @@ -227,7 +227,7 @@ void ExtractGameobjectModels() fwrite(grp, sizeof(char), sizeof(grp), output); uint32 k = 0; uint32 mobaBatch = itr2->MOBALength / 12; - uint32* MobaEx = new uint32[mobaBatch*4]; + uint32* MobaEx = new uint32[mobaBatch * 4]; for(uint32 i = 8; i < itr2->MOBALength; i += 12) MobaEx[k++] = itr2->MOBA[i]; @@ -279,7 +279,7 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set& mapLis mapList.insert(atoi(token)); token = strtok(nullptr, ","); } - + free(copy); printf("Extracting only provided list of maps (%u).\n", uint32(mapList.size())); @@ -437,7 +437,7 @@ int main(int argc, char* argv[]) LoadTile(navMesh, buff); } } - + navMeshQuery->init(navMesh, 2048); float nearestPt[3]; @@ -454,9 +454,9 @@ int main(int argc, char* argv[]) int hops; dtPolyRef* hopBuffer = new dtPolyRef[8192]; dtStatus status = navMeshQuery->findPath(m_startRef, m_endRef, m_spos, m_epos, &m_filter, hopBuffer, &hops, 8192); - + int resultHopCount; - float* straightPath = new float[2048*3]; + float* straightPath = new float[2048 * 3]; unsigned char* pathFlags = new unsigned char[2048]; dtPolyRef* pathRefs = new dtPolyRef[2048]; diff --git a/src/tools/mesh_extractor/Model.cpp b/src/tools/mesh_extractor/Model.cpp index 50be7ef42..2c66e09db 100644 --- a/src/tools/mesh_extractor/Model.cpp +++ b/src/tools/mesh_extractor/Model.cpp @@ -18,7 +18,7 @@ Model::Model( std::string path ) : IsCollidable(false), IsBad(false) } Header.Read(Stream); if (Header.OffsetBoundingNormals > 0 && Header.OffsetBoundingVertices > 0 && - Header.OffsetBoundingTriangles > 0 && Header.BoundingRadius > 0.0f) + Header.OffsetBoundingTriangles > 0 && Header.BoundingRadius > 0.0f) { IsCollidable = true; ReadVertices(); diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp index 308a5d567..358f9f7ab 100644 --- a/src/tools/mesh_extractor/TileBuilder.cpp +++ b/src/tools/mesh_extractor/TileBuilder.cpp @@ -244,7 +244,7 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) } OutputDebugVertices(); - + uint32 numVerts = _Geometry->Vertices.size(); uint32 numTris = _Geometry->Triangles.size(); float* vertices; diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp index 9eee704e2..90f094070 100644 --- a/src/tools/mesh_extractor/Utils.cpp +++ b/src/tools/mesh_extractor/Utils.cpp @@ -12,13 +12,13 @@ #include "G3D/Quat.h" #ifdef _WIN32 - #include "direct.h" +#include "direct.h" #else - #include - #include +#include +#include #endif -const float Constants::TileSize = 533.0f + (1/3.0f); +const float Constants::TileSize = 533.0f + (1 / 3.0f); const float Constants::MaxXY = 32.0f * Constants::TileSize; const float Constants::ChunkSize = Constants::TileSize / 16.0f; const float Constants::UnitSize = Constants::ChunkSize / 8.0f; @@ -45,11 +45,11 @@ void Utils::CreateDir( const std::string& Path ) void Utils::Reverse(char word[]) { int len = strlen(word); - for (int i = 0;i < len / 2; i++) + for (int i = 0; i < len / 2; i++) { - word[i] ^= word[len-i-1]; - word[len-i-1] ^= word[i]; - word[i] ^= word[len-i-1]; + word[i] ^= word[len - i - 1]; + word[len - i - 1] ^= word[i]; + word[i] ^= word[len - i - 1]; } } @@ -159,7 +159,7 @@ Vector3 Utils::GetLiquidVert(const IDefinition& def, Vector3 basePosition, float float Utils::Distance( float x, float y ) { - return sqrt(x*x + y*y); + return sqrt(x * x + y * y); } std::string Utils::Replace( std::string str, const std::string& oldStr, const std::string& newStr ) @@ -194,7 +194,7 @@ void Utils::SaveToDisk( FILE* stream, const std::string& path ) fclose(stream); return; } - + // And write it in the file size_t wrote = fwrite(data, size, 1, disk); if (wrote != 1) @@ -224,7 +224,7 @@ std::string Utils::GetExtension( std::string path ) std::string extension = ""; if(idx != std::string::npos) - extension = path.substr(idx+1); + extension = path.substr(idx + 1); return extension; } @@ -260,7 +260,7 @@ void MapChunkHeader::Read(FILE* stream) count += fread(&OffsetMCCV, sizeof(uint32), 1, stream); if (count != 27) - printf("MapChunkHeader::Read: Failed to read some data expected 27, read %d\n", count); + printf("MapChunkHeader::Read: Failed to read some data expected 27, read %d\n", count); } void MHDR::Read(FILE* stream) @@ -281,7 +281,7 @@ void MHDR::Read(FILE* stream) count += fread(&OffsetMTFX, sizeof(uint32), 1, stream); if (count != 12) - printf("MHDR::Read: Failed to read some data expected 12, read %d\n", count); + printf("MHDR::Read: Failed to read some data expected 12, read %d\n", count); } void ModelHeader::Read(FILE* stream) @@ -343,7 +343,7 @@ void ModelHeader::Read(FILE* stream) count += fread(&OffsetBoundingNormals, sizeof(uint32), 1, stream); if (count != 51) - printf("ModelHeader::Read: Failed to read some data expected 51, read %d\n", count); + printf("ModelHeader::Read: Failed to read some data expected 51, read %d\n", count); } @@ -366,7 +366,7 @@ WorldModelHeader WorldModelHeader::Read(FILE* stream) count += fread(&ret.LiquidTypeRelated, sizeof(uint32), 1, stream); if (count != 10) - printf("WorldModelHeader::Read: Failed to read some data expected 10, read %d\n", count); + printf("WorldModelHeader::Read: Failed to read some data expected 10, read %d\n", count); return ret; } @@ -386,7 +386,7 @@ DoodadInstance DoodadInstance::Read(FILE* stream) count += fread(&ret.LightColor, sizeof(uint32), 1, stream); if (count != 7) - printf("DoodadInstance::Read: Failed to read some data expected 7, read %d\n", count); + printf("DoodadInstance::Read: Failed to read some data expected 7, read %d\n", count); return ret; } @@ -405,7 +405,7 @@ DoodadSet DoodadSet::Read(FILE* stream) count += fread(&ret.UnknownZero, sizeof(uint32), 1, stream); if (count != 23) - printf("DoodadSet::Read: Failed to read some data expected 23, read %d\n", count); + printf("DoodadSet::Read: Failed to read some data expected 23, read %d\n", count); return ret; } @@ -422,7 +422,7 @@ LiquidHeader LiquidHeader::Read(FILE* stream) count += fread(&ret.MaterialId, sizeof(uint16), 1, stream); if (count != 5) - printf("LiquidHeader::Read: Failed to read some data expected 5, read %d\n", count); + printf("LiquidHeader::Read: Failed to read some data expected 5, read %d\n", count); return ret; } @@ -445,7 +445,7 @@ LiquidData LiquidData::Read(FILE* stream, LiquidHeader& header) uint32 discard; float tmp; if (fread(&discard, sizeof(uint32), 1, stream) == 1 && - fread(&tmp, sizeof(float), 1, stream) == 1) + fread(&tmp, sizeof(float), 1, stream) == 1) { ret.HeightMap[x][y] = tmp; } diff --git a/src/tools/mesh_extractor/WorldModelHandler.cpp b/src/tools/mesh_extractor/WorldModelHandler.cpp index 9b998f54c..3cd27bb3e 100644 --- a/src/tools/mesh_extractor/WorldModelHandler.cpp +++ b/src/tools/mesh_extractor/WorldModelHandler.cpp @@ -30,7 +30,7 @@ WorldModelDefinition WorldModelDefinition::Read( FILE* file ) count += fread(&discard, sizeof(uint32), 1, file); if (count != 5) - printf("WorldModelDefinition::Read: Error reading data, expected 5, read %d\n", count); + printf("WorldModelDefinition::Read: Error reading data, expected 5, read %d\n", count); return ret; } @@ -45,7 +45,7 @@ void WorldModelHandler::ProcessInternal( MapChunk* mcnk ) { if (!IsSane()) return; - + uint32 refCount = mcnk->Header.MapObjectRefs; FILE* stream = mcnk->Source->GetStream(); fseek(stream, mcnk->Source->Offset + mcnk->Header.OffsetMCRF, SEEK_SET); @@ -159,13 +159,13 @@ void WorldModelHandler::InsertModelGeometry( std::vector& verts, std::v uint32 vertOffset = verts.size(); Vector3 v1 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation, - liquidDataGeometry.HeightMap[x][y], x, y, translate); + liquidDataGeometry.HeightMap[x][y], x, y, translate); Vector3 v2 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation, - liquidDataGeometry.HeightMap[x + 1][y], x + 1, y, translate); + liquidDataGeometry.HeightMap[x + 1][y], x + 1, y, translate); Vector3 v3 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation, - liquidDataGeometry.HeightMap[x][y + 1], x, y + 1, translate); + liquidDataGeometry.HeightMap[x][y + 1], x, y + 1, translate); Vector3 v4 = Utils::GetLiquidVert(def, liquidHeader.BaseLocation, - liquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1, translate); + liquidDataGeometry.HeightMap[x + 1][y + 1], x + 1, y + 1, translate); verts.push_back(translate ? v1 : Utils::ToRecast(v1)); verts.push_back(translate ? v2 : Utils::ToRecast(v2)); diff --git a/src/tools/mmaps_generator/IntermediateValues.cpp b/src/tools/mmaps_generator/IntermediateValues.cpp index 6dc63e7fa..ecc069c34 100644 --- a/src/tools/mmaps_generator/IntermediateValues.cpp +++ b/src/tools/mmaps_generator/IntermediateValues.cpp @@ -72,7 +72,7 @@ namespace MMAP for (int y = 0; y < mesh->height; ++y) for (int x = 0; x < mesh->width; ++x) { - rcSpan* span = mesh->spans[x+y*mesh->width]; + rcSpan* span = mesh->spans[x + y * mesh->width]; // first, count the number of spans int spanCount = 0; @@ -86,7 +86,7 @@ namespace MMAP fwrite(&spanCount, sizeof(int), 1, file); // write the spans - span = mesh->spans[x+y*mesh->width]; + span = mesh->spans[x + y * mesh->width]; while (span) { fwrite(span, sizeof(rcSpan), 1, file); @@ -125,7 +125,7 @@ namespace MMAP fwrite(&tmp, sizeof(tmp), 1, file); if (chf->cells) - fwrite(chf->cells, sizeof(rcCompactCell), chf->width*chf->height, file); + fwrite(chf->cells, sizeof(rcCompactCell), chf->width * chf->height, file); if (chf->spans) fwrite(chf->spans, sizeof(rcCompactSpan), chf->spanCount, file); if (chf->dist) @@ -149,9 +149,9 @@ namespace MMAP fwrite(&cs->conts[i].area, sizeof(unsigned char), 1, file); fwrite(&cs->conts[i].reg, sizeof(unsigned short), 1, file); fwrite(&cs->conts[i].nverts, sizeof(int), 1, file); - fwrite(cs->conts[i].verts, sizeof(int), cs->conts[i].nverts*4, file); + fwrite(cs->conts[i].verts, sizeof(int), cs->conts[i].nverts * 4, file); fwrite(&cs->conts[i].nrverts, sizeof(int), 1, file); - fwrite(cs->conts[i].rverts, sizeof(int), cs->conts[i].nrverts*4, file); + fwrite(cs->conts[i].rverts, sizeof(int), cs->conts[i].nrverts * 4, file); } } @@ -166,9 +166,9 @@ namespace MMAP fwrite(mesh->bmin, sizeof(float), 3, file); fwrite(mesh->bmax, sizeof(float), 3, file); fwrite(&(mesh->nverts), sizeof(int), 1, file); - fwrite(mesh->verts, sizeof(unsigned short), mesh->nverts*3, file); + fwrite(mesh->verts, sizeof(unsigned short), mesh->nverts * 3, file); fwrite(&(mesh->npolys), sizeof(int), 1, file); - fwrite(mesh->polys, sizeof(unsigned short), mesh->npolys*mesh->nvp*2, file); + fwrite(mesh->polys, sizeof(unsigned short), mesh->npolys * mesh->nvp * 2, file); fwrite(mesh->flags, sizeof(unsigned short), mesh->npolys, file); fwrite(mesh->areas, sizeof(unsigned char), mesh->npolys, file); fwrite(mesh->regs, sizeof(unsigned short), mesh->npolys, file); @@ -180,14 +180,14 @@ namespace MMAP return; fwrite(&(mesh->nverts), sizeof(int), 1, file); - fwrite(mesh->verts, sizeof(float), mesh->nverts*3, file); + fwrite(mesh->verts, sizeof(float), mesh->nverts * 3, file); fwrite(&(mesh->ntris), sizeof(int), 1, file); - fwrite(mesh->tris, sizeof(char), mesh->ntris*4, file); + fwrite(mesh->tris, sizeof(char), mesh->ntris * 4, file); fwrite(&(mesh->nmeshes), sizeof(int), 1, file); - fwrite(mesh->meshes, sizeof(int), mesh->nmeshes*4, file); + fwrite(mesh->meshes, sizeof(int), mesh->nmeshes * 4, file); } - void IntermediateValues::generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData) + 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); @@ -215,10 +215,10 @@ namespace MMAP int triCount = allTris.size() / 3; for (int i = 0; i < allVerts.size() / 3; i++) - fprintf(objFile, "v %f %f %f\n", verts[i*3], verts[i*3 + 1], verts[i*3 + 2]); + fprintf(objFile, "v %f %f %f\n", verts[i * 3], verts[i * 3 + 1], verts[i * 3 + 2]); for (int i = 0; i < allTris.size() / 3; i++) - fprintf(objFile, "f %i %i %i\n", tris[i*3] + 1, tris[i*3 + 1] + 1, tris[i*3 + 2] + 1); + fprintf(objFile, "f %i %i %i\n", tris[i * 3] + 1, tris[i * 3 + 1] + 1, tris[i * 3 + 2] + 1); fclose(objFile); @@ -253,11 +253,11 @@ namespace MMAP } fwrite(&vertCount, sizeof(int), 1, objFile); - fwrite(verts, sizeof(float), vertCount*3, objFile); + fwrite(verts, sizeof(float), vertCount * 3, objFile); fflush(objFile); fwrite(&triCount, sizeof(int), 1, objFile); - fwrite(tris, sizeof(int), triCount*3, objFile); + fwrite(tris, sizeof(int), triCount * 3, objFile); fflush(objFile); fclose(objFile); diff --git a/src/tools/mmaps_generator/IntermediateValues.h b/src/tools/mmaps_generator/IntermediateValues.h index ae365f964..d01372bb0 100644 --- a/src/tools/mmaps_generator/IntermediateValues.h +++ b/src/tools/mmaps_generator/IntermediateValues.h @@ -24,7 +24,7 @@ namespace MMAP rcPolyMeshDetail* polyMeshDetail; IntermediateValues() : heightfield(nullptr), compactHeightfield(nullptr), - contours(nullptr), polyMesh(nullptr), polyMeshDetail(nullptr) {} + contours(nullptr), polyMesh(nullptr), polyMeshDetail(nullptr) {} ~IntermediateValues(); void writeIV(uint32 mapID, uint32 tileX, uint32 tileY); @@ -35,7 +35,7 @@ namespace MMAP void debugWrite(FILE* file, const rcPolyMesh* mesh); void debugWrite(FILE* file, const rcPolyMeshDetail* mesh); - void generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData); + void generateObjFile(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData); }; } #endif diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 3d07b06be..7164441d2 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -39,17 +39,17 @@ struct MmapTileHeader // All padding fields must be handled and initialized to ensure mmaps_generator will produce binary-identical *.mmtile files static_assert(sizeof(MmapTileHeader) == 20, "MmapTileHeader size is not correct, adjust the padding field size"); static_assert(sizeof(MmapTileHeader) == (sizeof(MmapTileHeader::mmapMagic) + - sizeof(MmapTileHeader::dtVersion) + - sizeof(MmapTileHeader::mmapVersion) + - sizeof(MmapTileHeader::size) + - sizeof(MmapTileHeader::usesLiquids) + - sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields"); + sizeof(MmapTileHeader::dtVersion) + + sizeof(MmapTileHeader::mmapVersion) + + sizeof(MmapTileHeader::size) + + sizeof(MmapTileHeader::usesLiquids) + + sizeof(MmapTileHeader::padding)), "MmapTileHeader has uninitialized padding fields"); namespace MMAP { MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid, - bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds, - bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) : + bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds, + bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) : m_terrainBuilder (nullptr), m_debugOutput (debugOutput), m_offMeshFilePath (offMeshFilePath), @@ -96,7 +96,7 @@ namespace MMAP getDirContents(files, "maps"); for (uint32 i = 0; i < files.size(); ++i) { - mapID = uint32(atoi(files[i].substr(0,3).c_str())); + mapID = uint32(atoi(files[i].substr(0, 3).c_str())); if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end()) { m_tiles.emplace_back(MapTiles(mapID, new std::set)); @@ -108,7 +108,7 @@ namespace MMAP getDirContents(files, "vmaps", "*.vmtree"); for (uint32 i = 0; i < files.size(); ++i) { - mapID = uint32(atoi(files[i].substr(0,3).c_str())); + mapID = uint32(atoi(files[i].substr(0, 3).c_str())); if (std::find(m_tiles.begin(), m_tiles.end(), mapID) == m_tiles.end()) { m_tiles.emplace_back(MapTiles(mapID, new std::set)); @@ -129,8 +129,8 @@ namespace MMAP getDirContents(files, "vmaps", filter); for (uint32 i = 0; i < files.size(); ++i) { - tileX = uint32(atoi(files[i].substr(7,2).c_str())); - tileY = uint32(atoi(files[i].substr(4,2).c_str())); + tileX = uint32(atoi(files[i].substr(7, 2).c_str())); + tileY = uint32(atoi(files[i].substr(4, 2).c_str())); tileID = StaticMapTree::packTileID(tileY, tileX); tiles->insert(tileID); @@ -142,8 +142,8 @@ namespace MMAP getDirContents(files, "maps", filter); for (uint32 i = 0; i < files.size(); ++i) { - tileY = uint32(atoi(files[i].substr(3,2).c_str())); - tileX = uint32(atoi(files[i].substr(5,2).c_str())); + tileY = uint32(atoi(files[i].substr(3, 2).c_str())); + tileX = uint32(atoi(files[i].substr(5, 2).c_str())); tileID = StaticMapTree::packTileID(tileX, tileY); if (tiles->insert(tileID).second) @@ -229,7 +229,7 @@ namespace MMAP } /**************************************************************************/ - void MapBuilder::getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) const + void MapBuilder::getGridBounds(uint32 mapID, uint32& minX, uint32& minY, uint32& maxX, uint32& maxY) const { // min and max are initialized to invalid values so the caller iterating the [min, max] range // will never enter the loop unless valid min/max values are found @@ -481,7 +481,7 @@ namespace MMAP } /**************************************************************************/ - void MapBuilder::buildNavMesh(uint32 mapID, dtNavMesh* &navMesh) + void MapBuilder::buildNavMesh(uint32 mapID, dtNavMesh*& navMesh) { std::set* tiles = getTileList(mapID); @@ -557,8 +557,8 @@ namespace MMAP /**************************************************************************/ void MapBuilder::buildMoveMapTile(uint32 mapID, uint32 tileX, uint32 tileY, - MeshData &meshData, float bmin[3], float bmax[3], - dtNavMesh* navMesh) + MeshData& meshData, float bmin[3], float bmax[3], + dtNavMesh* navMesh) { // console output char tileString[20]; @@ -584,9 +584,9 @@ namespace MMAP const static float BASE_UNIT_DIM = m_bigBaseUnit ? 0.5333333f : 0.2666666f; // All are in UNIT metrics! - const static int VERTEX_PER_MAP = int(GRID_SIZE/BASE_UNIT_DIM + 0.5f); + const static int VERTEX_PER_MAP = int(GRID_SIZE / BASE_UNIT_DIM + 0.5f); const static int VERTEX_PER_TILE = m_bigBaseUnit ? 40 : 80; // must divide VERTEX_PER_MAP - const static int TILES_PER_MAP = VERTEX_PER_MAP/VERTEX_PER_TILE; + const static int TILES_PER_MAP = VERTEX_PER_MAP / VERTEX_PER_TILE; rcConfig config; memset(&config, 0, sizeof(rcConfig)); @@ -620,8 +620,8 @@ namespace MMAP // Initialize per tile config. rcConfig tileCfg = config; - tileCfg.width = config.tileSize + config.borderSize*2; - tileCfg.height = config.tileSize + config.borderSize*2; + tileCfg.width = config.tileSize + config.borderSize * 2; + tileCfg.height = config.tileSize + config.borderSize * 2; // merge per tile poly and detail meshes rcPolyMesh** pmmerge = new rcPolyMesh*[TILES_PER_MAP * TILES_PER_MAP]; @@ -635,10 +635,10 @@ namespace MMAP Tile& tile = tiles[x + y * TILES_PER_MAP]; // Calculate the per tile bounding box. - tileCfg.bmin[0] = config.bmin[0] + float(x*config.tileSize - config.borderSize)*config.cs; - tileCfg.bmin[2] = config.bmin[2] + float(y*config.tileSize - config.borderSize)*config.cs; - tileCfg.bmax[0] = config.bmin[0] + float((x+1)*config.tileSize + config.borderSize)*config.cs; - tileCfg.bmax[2] = config.bmin[2] + float((y+1)*config.tileSize + config.borderSize)*config.cs; + tileCfg.bmin[0] = config.bmin[0] + float(x * config.tileSize - config.borderSize) * config.cs; + tileCfg.bmin[2] = config.bmin[2] + float(y * config.tileSize - config.borderSize) * config.cs; + tileCfg.bmax[0] = config.bmin[0] + float((x + 1) * config.tileSize + config.borderSize) * config.cs; + tileCfg.bmax[2] = config.bmin[2] + float((y + 1) * config.tileSize + config.borderSize) * config.cs; // build heightfield tile.solid = rcAllocHeightfield(); @@ -650,7 +650,7 @@ namespace MMAP // mark all walkable tiles, both liquids and solids unsigned char* triFlags = new unsigned char[tTriCount]; - memset(triFlags, NAV_GROUND, tTriCount*sizeof(unsigned char)); + memset(triFlags, NAV_GROUND, tTriCount * sizeof(unsigned char)); rcClearUnwalkableTriangles(m_rcContext, tileCfg.walkableSlopeAngle, tVerts, tVertCount, tTris, tTriCount, triFlags); rcRasterizeTriangles(m_rcContext, tVerts, tVertCount, tTris, triFlags, tTriCount, *tile.solid, config.walkableClimb); delete[] triFlags; @@ -776,15 +776,15 @@ namespace MMAP params.detailTriCount = iv.polyMeshDetail->ntris; params.offMeshConVerts = meshData.offMeshConnections.getCArray(); - params.offMeshConCount = meshData.offMeshConnections.size()/6; + params.offMeshConCount = meshData.offMeshConnections.size() / 6; params.offMeshConRad = meshData.offMeshConnectionRads.getCArray(); params.offMeshConDir = meshData.offMeshConnectionDirs.getCArray(); params.offMeshConAreas = meshData.offMeshConnectionsAreas.getCArray(); params.offMeshConFlags = meshData.offMeshConnectionsFlags.getCArray(); - params.walkableHeight = BASE_UNIT_DIM*config.walkableHeight; // agent height - params.walkableRadius = BASE_UNIT_DIM*config.walkableRadius; // agent radius - params.walkableClimb = BASE_UNIT_DIM*config.walkableClimb; // keep less that walkableHeight (aka agent height)! + params.walkableHeight = BASE_UNIT_DIM * config.walkableHeight; // agent height + params.walkableRadius = BASE_UNIT_DIM * config.walkableRadius; // agent radius + params.walkableClimb = BASE_UNIT_DIM * config.walkableClimb; // keep less that walkableHeight (aka agent height)! params.tileX = (((bmin[0] + bmax[0]) / 2) - navMesh->getParams()->orig[0]) / GRID_SIZE; params.tileY = (((bmin[2] + bmax[2]) / 2) - navMesh->getParams()->orig[2]) / GRID_SIZE; rcVcopy(params.bmin, bmin); @@ -822,7 +822,7 @@ namespace MMAP break; } if (!params.polyCount || !params.polys || - TILES_PER_MAP*TILES_PER_MAP == params.polyCount) + TILES_PER_MAP * TILES_PER_MAP == params.polyCount) { // we have flat tiles with no actual geometry - don't build those, its useless // keep in mind that we do output those into debug info @@ -881,15 +881,14 @@ namespace MMAP // now that tile is written to disk, we can unload it navMesh->removeTile(tileRef, nullptr, nullptr); - } - while (0); + } while (0); if (m_debugOutput) { // restore padding so that the debug visualization is correct for (int i = 0; i < iv.polyMesh->nverts; ++i) { - unsigned short* v = &iv.polyMesh->verts[i*3]; + unsigned short* v = &iv.polyMesh->verts[i * 3]; v[0] += (unsigned short)config.borderSize; v[2] += (unsigned short)config.borderSize; } @@ -1034,7 +1033,7 @@ namespace MMAP return true; } - + /**************************************************************************/ uint32 MapBuilder::percentageDone(uint32 totalTiles, uint32 totalTilesBuilt) { diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index b40a12565..e8a35b0cb 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -63,81 +63,81 @@ namespace MMAP class MapBuilder { - public: - MapBuilder(float maxWalkableAngle = 70.f, - bool skipLiquid = false, - bool skipContinents = false, - bool skipJunkMaps = true, - bool skipBattlegrounds = false, - bool debugOutput = false, - bool bigBaseUnit = false, - const char* offMeshFilePath = nullptr); + public: + MapBuilder(float maxWalkableAngle = 70.f, + bool skipLiquid = false, + bool skipContinents = false, + bool skipJunkMaps = true, + bool skipBattlegrounds = false, + bool debugOutput = false, + bool bigBaseUnit = false, + const char* offMeshFilePath = nullptr); - ~MapBuilder(); + ~MapBuilder(); - // builds all mmap tiles for the specified map id (ignores skip settings) - void buildMap(uint32 mapID); - void buildMeshFromFile(char* name); + // builds all mmap tiles for the specified map id (ignores skip settings) + void buildMap(uint32 mapID); + void buildMeshFromFile(char* name); - // builds an mmap tile for the specified map and its mesh - void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY); + // builds an mmap tile for the specified map and its mesh + void buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY); - // builds list of maps, then builds all of mmap tiles (based on the skip settings) - void buildAllMaps(unsigned int threads); + // builds list of maps, then builds all of mmap tiles (based on the skip settings) + void buildAllMaps(unsigned int threads); - void WorkerThread(); + void WorkerThread(); - private: - // detect maps and tiles - void discoverTiles(); - std::set* getTileList(uint32 mapID); + private: + // detect maps and tiles + void discoverTiles(); + std::set* getTileList(uint32 mapID); - void buildNavMesh(uint32 mapID, dtNavMesh* &navMesh); + void buildNavMesh(uint32 mapID, dtNavMesh*& navMesh); - void buildTile(uint32 mapID, uint32 tileX, uint32 tileY, dtNavMesh* navMesh); + void buildTile(uint32 mapID, uint32 tileX, uint32 tileY, dtNavMesh* navMesh); - // move map building - void buildMoveMapTile(uint32 mapID, - uint32 tileX, - uint32 tileY, - MeshData &meshData, - float bmin[3], - float bmax[3], - dtNavMesh* navMesh); + // move map building + void buildMoveMapTile(uint32 mapID, + uint32 tileX, + uint32 tileY, + MeshData& meshData, + float bmin[3], + float bmax[3], + dtNavMesh* navMesh); - void getTileBounds(uint32 tileX, uint32 tileY, - float* verts, int vertCount, - float* bmin, float* bmax); - void getGridBounds(uint32 mapID, uint32 &minX, uint32 &minY, uint32 &maxX, uint32 &maxY) const; + void getTileBounds(uint32 tileX, uint32 tileY, + float* verts, int vertCount, + float* bmin, float* bmax); + void getGridBounds(uint32 mapID, uint32& minX, uint32& minY, uint32& maxX, uint32& maxY) const; - bool shouldSkipMap(uint32 mapID); - bool isTransportMap(uint32 mapID); - bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY); - // percentageDone - method to calculate percentage - uint32 percentageDone(uint32 totalTiles, uint32 totalTilesDone); + bool shouldSkipMap(uint32 mapID); + bool isTransportMap(uint32 mapID); + bool shouldSkipTile(uint32 mapID, uint32 tileX, uint32 tileY); + // percentageDone - method to calculate percentage + uint32 percentageDone(uint32 totalTiles, uint32 totalTilesDone); - TerrainBuilder* m_terrainBuilder; - TileList m_tiles; + TerrainBuilder* m_terrainBuilder; + TileList m_tiles; - bool m_debugOutput; + bool m_debugOutput; - const char* m_offMeshFilePath; - bool m_skipContinents; - bool m_skipJunkMaps; - bool m_skipBattlegrounds; + const char* m_offMeshFilePath; + bool m_skipContinents; + bool m_skipJunkMaps; + bool m_skipBattlegrounds; - float m_maxWalkableAngle; - bool m_bigBaseUnit; - // percentageDone - variables to calculate percentage - std::atomic m_totalTiles; - std::atomic m_totalTilesBuilt; + float m_maxWalkableAngle; + bool m_bigBaseUnit; + // percentageDone - variables to calculate percentage + std::atomic m_totalTiles; + std::atomic m_totalTilesBuilt; - // build performance - not really used for now - rcContext* m_rcContext; + // build performance - not really used for now + rcContext* m_rcContext; - std::vector _workerThreads; - ProducerConsumerQueue _queue; - std::atomic _cancelationToken; + std::vector _workerThreads; + ProducerConsumerQueue _queue; + std::atomic _cancelationToken; }; } diff --git a/src/tools/mmaps_generator/PathCommon.h b/src/tools/mmaps_generator/PathCommon.h index 19c91ed82..a6215bd96 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -12,12 +12,12 @@ #include #ifndef _WIN32 - #include - #include +#include +#include #endif #ifdef __linux__ - #include +#include #endif #include "Database/DatabaseEnv.h" @@ -33,7 +33,7 @@ enum NavTerrain NAV_UNUSED2 = 0x20, NAV_UNUSED3 = 0x40, NAV_UNUSED4 = 0x80 - // we only have 8 bits + // we only have 8 bits }; namespace MMAP @@ -76,9 +76,9 @@ namespace MMAP LISTFILE_OK = 1 }; - inline ListFilesResult getDirContents(std::vector &fileList, std::string dirpath = ".", std::string filter = "*") + inline ListFilesResult getDirContents(std::vector& fileList, std::string dirpath = ".", std::string filter = "*") { - #ifdef WIN32 +#ifdef WIN32 HANDLE hFind; WIN32_FIND_DATA findFileInfo; std::string directory; @@ -93,15 +93,14 @@ namespace MMAP { if ((findFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) fileList.push_back(std::string(findFileInfo.cFileName)); - } - while (FindNextFile(hFind, &findFileInfo)); + } while (FindNextFile(hFind, &findFileInfo)); FindClose(hFind); - #else - const char *p = dirpath.c_str(); - DIR * dirp = opendir(p); - struct dirent * dp; +#else + const char* p = dirpath.c_str(); + DIR* dirp = opendir(p); + struct dirent* dp; while (dirp) { @@ -119,7 +118,7 @@ namespace MMAP closedir(dirp); else return LISTFILE_DIRECTORY_NOT_FOUND; - #endif +#endif return LISTFILE_OK; } diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 87ad3dcc7..9ae492a1c 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -48,20 +48,20 @@ bool checkDirectories(bool debugOutput) } bool handleArgs(int argc, char** argv, - int &mapnum, - int &tileX, - int &tileY, - float &maxAngle, - bool &skipLiquid, - bool &skipContinents, - bool &skipJunkMaps, - bool &skipBattlegrounds, - bool &debugOutput, - bool &silent, - bool &bigBaseUnit, - char* &offMeshInputPath, - char* &file, - unsigned int& threads) + int& mapnum, + int& tileX, + int& tileY, + float& maxAngle, + bool& skipLiquid, + bool& skipContinents, + bool& skipJunkMaps, + bool& skipBattlegrounds, + bool& debugOutput, + bool& silent, + bool& bigBaseUnit, + char*& offMeshInputPath, + char*& file, + unsigned int& threads) { char* param = nullptr; for (int i = 1; i < argc; ++i) diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index 843e89bc8..ce47d1f7d 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -72,11 +72,11 @@ namespace MMAP char const* MAP_VERSION_MAGIC = "v1.8"; - TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid){ } + TerrainBuilder::TerrainBuilder(bool skipLiquid) : m_skipLiquid (skipLiquid) { } TerrainBuilder::~TerrainBuilder() { } /**************************************************************************/ - void TerrainBuilder::getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc) + void TerrainBuilder::getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc) { switch (portion) { @@ -109,19 +109,19 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData) + void TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData) { if (loadMap(mapID, tileX, tileY, meshData, ENTIRE)) { - loadMap(mapID, tileX+1, tileY, meshData, LEFT); - loadMap(mapID, tileX-1, tileY, meshData, RIGHT); - loadMap(mapID, tileX, tileY+1, meshData, TOP); - loadMap(mapID, tileX, tileY-1, meshData, BOTTOM); + loadMap(mapID, tileX + 1, tileY, meshData, LEFT); + loadMap(mapID, tileX - 1, tileY, meshData, RIGHT); + loadMap(mapID, tileX, tileY + 1, meshData, TOP); + loadMap(mapID, tileX, tileY - 1, meshData, BOTTOM); } } /**************************************************************************/ - bool TerrainBuilder::loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion) + 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); @@ -132,7 +132,7 @@ namespace MMAP map_fileheader fheader; if (fread(&fheader, sizeof(map_fileheader), 1, mapFile) != 1 || - fheader.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC))) + fheader.versionMagic != *((uint32 const*)(MAP_VERSION_MAGIC))) { fclose(mapFile); printf("%s is the wrong version, please extract new .map files\n", mapFileName); @@ -185,10 +185,10 @@ namespace MMAP heightMultiplier = (hheader.gridMaxHeight - hheader.gridHeight) / 255; for (int i = 0; i < V9_SIZE_SQ; ++i) - V9[i] = (float)v9[i]*heightMultiplier + hheader.gridHeight; + V9[i] = (float)v9[i] * heightMultiplier + hheader.gridHeight; for (int i = 0; i < V8_SIZE_SQ; ++i) - V8[i] = (float)v8[i]*heightMultiplier + hheader.gridHeight; + V8[i] = (float)v8[i] * heightMultiplier + hheader.gridHeight; } else if (hheader.flags & MAP_HEIGHT_AS_INT16) { @@ -203,10 +203,10 @@ namespace MMAP heightMultiplier = (hheader.gridMaxHeight - hheader.gridHeight) / 65535; for (int i = 0; i < V9_SIZE_SQ; ++i) - V9[i] = (float)v9[i]*heightMultiplier + hheader.gridHeight; + V9[i] = (float)v9[i] * heightMultiplier + hheader.gridHeight; for (int i = 0; i < V8_SIZE_SQ; ++i) - V8[i] = (float)v8[i]*heightMultiplier + hheader.gridHeight; + V8[i] = (float)v8[i] * heightMultiplier + hheader.gridHeight; } else { @@ -227,8 +227,8 @@ namespace MMAP } int count = meshData.solidVerts.size() / 3; - float xoffset = (float(tileX)-32)*GRID_SIZE; - float yoffset = (float(tileY)-32)*GRID_SIZE; + float xoffset = (float(tileX) - 32) * GRID_SIZE; + float yoffset = (float(tileY) - 32) * GRID_SIZE; float coord[3]; @@ -251,8 +251,8 @@ namespace MMAP int indices[] = { 0, 0, 0 }; int loopStart = 0, loopEnd = 0, loopInc = 0; getLoopVars(portion, loopStart, loopEnd, loopInc); - for (int i = loopStart; i < loopEnd; i+=loopInc) - for (int j = TOP; j <= BOTTOM; j+=1) + for (int i = loopStart; i < loopEnd; i += loopInc) + for (int j = TOP; j <= BOTTOM; j += 1) { getHeightTriangle(i, Spot(j), indices); ttriangles.append(indices[2] + count); @@ -287,8 +287,8 @@ namespace MMAP if (liquid_map) { int count = meshData.liquidVerts.size() / 3; - float xoffset = (float(tileX)-32)*GRID_SIZE; - float yoffset = (float(tileY)-32)*GRID_SIZE; + float xoffset = (float(tileX) - 32) * GRID_SIZE; + float yoffset = (float(tileY) - 32) * GRID_SIZE; float coord[3]; int row, col; @@ -303,10 +303,10 @@ namespace MMAP col = i % V9_SIZE; if (row < lheader.offsetY || row >= lheader.offsetY + lheader.height || - col < lheader.offsetX || col >= lheader.offsetX + lheader.width) + col < lheader.offsetX || col >= lheader.offsetX + lheader.width) { // dummy vert using invalid height - meshData.liquidVerts.append((xoffset+col*GRID_PART_SIZE)*-1, INVALID_MAP_LIQ_HEIGHT, (yoffset+row*GRID_PART_SIZE)*-1); + meshData.liquidVerts.append((xoffset + col * GRID_PART_SIZE) * -1, INVALID_MAP_LIQ_HEIGHT, (yoffset + row * GRID_PART_SIZE) * -1); continue; } @@ -323,19 +323,19 @@ namespace MMAP { row = i / V9_SIZE; col = i % V9_SIZE; - meshData.liquidVerts.append((xoffset+col*GRID_PART_SIZE)*-1, lheader.liquidLevel, (yoffset+row*GRID_PART_SIZE)*-1); + meshData.liquidVerts.append((xoffset + col * GRID_PART_SIZE) * -1, lheader.liquidLevel, (yoffset + row * GRID_PART_SIZE) * -1); } } delete [] liquid_map; int indices[] = { 0, 0, 0 }; - int loopStart = 0, loopEnd = 0, loopInc = 0, triInc = BOTTOM-TOP; + int loopStart = 0, loopEnd = 0, loopInc = 0, triInc = BOTTOM - TOP; getLoopVars(portion, loopStart, loopEnd, loopInc); // generate triangles - for (int i = loopStart; i < loopEnd; i+=loopInc) - for (int j = TOP; j <= BOTTOM; j+= triInc) + for (int i = loopStart; i < loopEnd; i += loopInc) + for (int j = TOP; j <= BOTTOM; j += triInc) { getHeightTriangle(i, Spot(j), indices, true); ltriangles.append(indices[2] + count); @@ -371,7 +371,7 @@ namespace MMAP } getLoopVars(portion, loopStart, loopEnd, loopInc); - for (int i = loopStart; i < loopEnd; i+=loopInc) + for (int i = loopStart; i < loopEnd; i += loopInc) { for (int j = 0; j < 2; ++j) { @@ -423,7 +423,7 @@ namespace MMAP uint32 validCount = 0; for(uint32 idx = 0; idx < 3; idx++) { - float h = lverts_copy[ltris[idx]*3 + 1]; + float h = lverts_copy[ltris[idx] * 3 + 1]; if (h != INVALID_MAP_LIQ_HEIGHT && h < INVALID_MAP_LIQ_HEIGHT_MAX) { quadHeight += h; @@ -437,9 +437,9 @@ namespace MMAP quadHeight /= validCount; for(uint32 idx = 0; idx < 3; idx++) { - float h = lverts[ltris[idx]*3 + 1]; + float h = lverts[ltris[idx] * 3 + 1]; if (h == INVALID_MAP_LIQ_HEIGHT || h > INVALID_MAP_LIQ_HEIGHT_MAX) - lverts[ltris[idx]*3 + 1] = quadHeight; + lverts[ltris[idx] * 3 + 1] = quadHeight; } } @@ -459,7 +459,7 @@ namespace MMAP float maxLLevel = INVALID_MAP_LIQ_HEIGHT; for(uint32 x = 0; x < 3; x++) { - float h = lverts[ltris[x]*3 + 1]; + float h = lverts[ltris[x] * 3 + 1]; if (minLLevel > h) minLLevel = h; @@ -471,7 +471,7 @@ namespace MMAP float minTLevel = INVALID_MAP_LIQ_HEIGHT_MAX; for(uint32 x = 0; x < 6; x++) { - float h = tverts[ttris[x]*3 + 1]; + float h = tverts[ttris[x] * 3 + 1]; if (maxTLevel < h) maxTLevel = h; @@ -497,12 +497,12 @@ namespace MMAP } if (useTerrain) - for (int k = 0; k < 3*tTriCount/2; ++k) + for (int k = 0; k < 3 * tTriCount / 2; ++k) meshData.solidTris.append(ttris[k]); // advance to next set of triangles ltris += 3; - ttris += 3*tTriCount/2; + ttris += 3 * tTriCount / 2; } } @@ -519,63 +519,81 @@ namespace MMAP // coord is mirroed about the horizontal axes switch (grid) { - case GRID_V9: - coord[0] = (xOffset + index%(V9_SIZE)*GRID_PART_SIZE) * -1.f; - coord[1] = (yOffset + (int)(index/(V9_SIZE))*GRID_PART_SIZE) * -1.f; - coord[2] = v[index]; - break; - case GRID_V8: - coord[0] = (xOffset + index%(V8_SIZE)*GRID_PART_SIZE + GRID_PART_SIZE/2.f) * -1.f; - coord[1] = (yOffset + (int)(index/(V8_SIZE))*GRID_PART_SIZE + GRID_PART_SIZE/2.f) * -1.f; - coord[2] = v[index]; - break; + case GRID_V9: + coord[0] = (xOffset + index % (V9_SIZE) * GRID_PART_SIZE) * -1.f; + coord[1] = (yOffset + (int)(index / (V9_SIZE)) * GRID_PART_SIZE) * -1.f; + coord[2] = v[index]; + break; + case GRID_V8: + coord[0] = (xOffset + index % (V8_SIZE) * GRID_PART_SIZE + GRID_PART_SIZE / 2.f) * -1.f; + coord[1] = (yOffset + (int)(index / (V8_SIZE)) * GRID_PART_SIZE + GRID_PART_SIZE / 2.f) * -1.f; + coord[2] = v[index]; + break; } } /**************************************************************************/ void TerrainBuilder::getHeightTriangle(int square, Spot triangle, int* indices, bool liquid/* = false*/) { - int rowOffset = square/V8_SIZE; + int rowOffset = square / V8_SIZE; if (!liquid) switch (triangle) - { - case TOP: - indices[0] = square+rowOffset; // 0-----1 .... 128 - indices[1] = square+1+rowOffset; // |\ T /| - indices[2] = (V9_SIZE_SQ)+square; // | \ / | - break; // |L 0 R| .. 127 - case LEFT: // | / \ | - indices[0] = square+rowOffset; // |/ B \| - indices[1] = (V9_SIZE_SQ)+square; // 129---130 ... 386 - indices[2] = square+V9_SIZE+rowOffset; // |\ /| - break; // | \ / | - case RIGHT: // | 128 | .. 255 - indices[0] = square+1+rowOffset; // | / \ | - indices[1] = square+V9_SIZE+1+rowOffset; // |/ \| - indices[2] = (V9_SIZE_SQ)+square; // 258---259 ... 515 - break; - case BOTTOM: - indices[0] = (V9_SIZE_SQ)+square; - indices[1] = square+V9_SIZE+1+rowOffset; - indices[2] = square+V9_SIZE+rowOffset; - break; - default: break; - } + { + case TOP: + indices[0] = square + rowOffset; // 0-----1 .... 128 + indices[1] = square + 1 + rowOffset; // |\ T /| + indices[2] = (V9_SIZE_SQ) + square; // | \ / | + break; // |L 0 R| .. 127 + case LEFT: // | / \ | + indices[0] = square + rowOffset; // |/ B \| + indices[1] = (V9_SIZE_SQ) + square; // 129---130 ... 386 + indices[2] = square + V9_SIZE + rowOffset; // |\ /| + break; // | \ / | + case RIGHT: // | 128 | .. 255 + indices[0] = square + 1 + rowOffset; // | / \ | + indices[1] = square + V9_SIZE + 1 + rowOffset; // |/ \| + indices[2] = (V9_SIZE_SQ) + square; // 258---259 ... 515 + break; + case BOTTOM: + indices[0] = (V9_SIZE_SQ) + square; + indices[1] = square + V9_SIZE + 1 + rowOffset; + indices[2] = square + V9_SIZE + rowOffset; + break; + default: + break; + } else switch (triangle) - { // 0-----1 .... 128 - case TOP: // |\ | - indices[0] = square+rowOffset; // | \ T | - indices[1] = square+1+rowOffset; // | \ | - indices[2] = square+V9_SIZE+1+rowOffset; // | B \ | - break; // | \| - case BOTTOM: // 129---130 ... 386 - indices[0] = square+rowOffset; // |\ | - indices[1] = square+V9_SIZE+1+rowOffset; // | \ | - indices[2] = square+V9_SIZE+rowOffset; // | \ | - break; // | \ | - default: break; // | \| - } // 258---259 ... 515 + { + case TOP: + indices[0] = square + rowOffset; + indices[1] = square + 1 + rowOffset; + indices[2] = square + V9_SIZE + 1 + rowOffset; + break; + case BOTTOM: + indices[0] = square + rowOffset; + indices[1] = square + V9_SIZE + 1 + rowOffset; + indices[2] = square + V9_SIZE + rowOffset; + break; + default: + break; + } + + /* + 0-----1 .... 128 + |\ | + | \ T | + | \ | + | B \ | + | \| + 129---130 ... 386 + |\ | + | \ | + | \ | + | \ | + | \| + 258---259 ... 515 + */ } @@ -584,8 +602,8 @@ namespace MMAP { // wow coords: x, y, height // coord is mirroed about the horizontal axes - coord[0] = (xOffset + index%(V9_SIZE)*GRID_PART_SIZE) * -1.f; - coord[1] = (yOffset + (int)(index/(V9_SIZE))*GRID_PART_SIZE) * -1.f; + coord[0] = (xOffset + index % (V9_SIZE) * GRID_PART_SIZE) * -1.f; + coord[1] = (yOffset + (int)(index / (V9_SIZE)) * GRID_PART_SIZE) * -1.f; coord[2] = v[index2]; } @@ -619,7 +637,7 @@ namespace MMAP } /**************************************************************************/ - bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData) + bool TerrainBuilder::loadVMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData) { IVMapManager* vmapManager = new VMapManager2(); int result = vmapManager->loadMap("vmaps", mapID, tileX, tileY); @@ -663,10 +681,10 @@ 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::iterator it = groupModels.begin(); it != groupModels.end(); ++it) { @@ -702,16 +720,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... @@ -725,7 +743,7 @@ namespace MMAP { 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]); + vert = G3D::Vector3(corner.x + x * GRID_PART_SIZE, corner.y + y * GRID_PART_SIZE, data[y * vertsX + x]); vert = vert * rotation * scale + position; vert.x *= -1.f; vert.y *= -1.f; @@ -767,14 +785,13 @@ namespace MMAP 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.liquidTris.append(liqTris[j * 3 + 1] + liqOffset, liqTris[j * 3 + 2] + liqOffset, liqTris[j * 3] + liqOffset); meshData.liquidType.append(type); } } } } - } - while (false); + } while (false); vmapManager->unloadMap(mapID, tileX, tileY); delete vmapManager; @@ -783,7 +800,7 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::transform(std::vector &source, std::vector &transformedVertices, float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position) + void TerrainBuilder::transform(std::vector& source, std::vector& transformedVertices, float scale, G3D::Matrix3& rotation, G3D::Vector3& position) { for (std::vector::iterator it = source.begin(); it != source.end(); ++it) { @@ -796,7 +813,7 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::copyVertices(std::vector &source, G3D::Array &dest) + void TerrainBuilder::copyVertices(std::vector& source, G3D::Array& dest) { for (std::vector::iterator it = source.begin(); it != source.end(); ++it) { @@ -807,30 +824,30 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::copyIndices(std::vector &source, G3D::Array &dest, int offset, bool flip) + void TerrainBuilder::copyIndices(std::vector& source, G3D::Array& dest, int offset, bool flip) { if (flip) { for (std::vector::iterator it = source.begin(); it != source.end(); ++it) { - dest.push_back((*it).idx2+offset); - dest.push_back((*it).idx1+offset); - dest.push_back((*it).idx0+offset); + dest.push_back((*it).idx2 + offset); + dest.push_back((*it).idx1 + offset); + dest.push_back((*it).idx0 + offset); } } else { for (std::vector::iterator it = source.begin(); it != source.end(); ++it) { - dest.push_back((*it).idx0+offset); - dest.push_back((*it).idx1+offset); - dest.push_back((*it).idx2+offset); + dest.push_back((*it).idx0 + offset); + dest.push_back((*it).idx1 + offset); + dest.push_back((*it).idx2 + offset); } } } /**************************************************************************/ - void TerrainBuilder::copyIndices(G3D::Array &source, G3D::Array &dest, int offset) + void TerrainBuilder::copyIndices(G3D::Array& source, G3D::Array& dest, int offset) { int* src = source.getCArray(); for (int32 i = 0; i < source.size(); ++i) @@ -838,7 +855,7 @@ namespace MMAP } /**************************************************************************/ - void TerrainBuilder::cleanVertices(G3D::Array &verts, G3D::Array &tris) + void TerrainBuilder::cleanVertices(G3D::Array& verts, G3D::Array& tris) { std::map vertMap; @@ -881,7 +898,7 @@ 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, const char* offMeshFilePath) { // no meshfile input given? if (offMeshFilePath == nullptr) @@ -903,7 +920,7 @@ namespace MMAP uint32 mid, tx, ty; float size; if (sscanf(buf, "%u %u,%u (%f %f %f) (%f %f %f) %f", &mid, &tx, &ty, - &p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10) + &p0[0], &p0[1], &p0[2], &p1[0], &p1[1], &p1[2], &size) != 10) continue; if (mapID == mid && tileX == tx && tileY == ty) diff --git a/src/tools/mmaps_generator/TerrainBuilder.h b/src/tools/mmaps_generator/TerrainBuilder.h index 52773320f..b688d558e 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.h +++ b/src/tools/mmaps_generator/TerrainBuilder.h @@ -32,11 +32,11 @@ namespace MMAP }; static const int V9_SIZE = 129; - static const int V9_SIZE_SQ = V9_SIZE*V9_SIZE; + static const int V9_SIZE_SQ = V9_SIZE * V9_SIZE; static const int V8_SIZE = 128; - static const int V8_SIZE_SQ = V8_SIZE*V8_SIZE; + static const int V8_SIZE_SQ = V8_SIZE * V8_SIZE; static const float GRID_SIZE = 533.3333f; - static const float GRID_PART_SIZE = GRID_SIZE/V8_SIZE; + static const float GRID_PART_SIZE = GRID_SIZE / V8_SIZE; // see contrib/extractor/system.cpp, CONF_use_minHeight static const float INVALID_MAP_LIQ_HEIGHT = -500.f; @@ -65,52 +65,52 @@ namespace MMAP class TerrainBuilder { - public: - TerrainBuilder(bool skipLiquid); - ~TerrainBuilder(); + public: + TerrainBuilder(bool skipLiquid); + ~TerrainBuilder(); - TerrainBuilder(const TerrainBuilder &tb) = delete; + TerrainBuilder(const TerrainBuilder& 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 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); - bool usesLiquids() const { return !m_skipLiquid; } + bool usesLiquids() const { return !m_skipLiquid; } - // vert and triangle methods - static void transform(std::vector &original, std::vector &transformed, - float scale, G3D::Matrix3 &rotation, G3D::Vector3 &position); - static void copyVertices(std::vector &source, G3D::Array &dest); - static void copyIndices(std::vector &source, G3D::Array &dest, int offest, bool flip); - static void copyIndices(G3D::Array &src, G3D::Array &dest, int offset); - static void cleanVertices(G3D::Array &verts, G3D::Array &tris); - private: - /// Loads a portion of a map's terrain - bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, Spot portion); + // vert and triangle methods + static void transform(std::vector& original, std::vector& transformed, + float scale, G3D::Matrix3& rotation, G3D::Vector3& position); + static void copyVertices(std::vector& source, G3D::Array& dest); + static void copyIndices(std::vector& source, G3D::Array& dest, int offest, bool flip); + static void copyIndices(G3D::Array& src, G3D::Array& dest, int offset); + static void cleanVertices(G3D::Array& verts, G3D::Array& tris); + private: + /// Loads a portion of a map's terrain + bool loadMap(uint32 mapID, uint32 tileX, uint32 tileY, MeshData& meshData, Spot portion); - /// Sets loop variables for selecting only certain parts of a map's terrain - void getLoopVars(Spot portion, int &loopStart, int &loopEnd, int &loopInc); + /// Sets loop variables for selecting only certain parts of a map's terrain + void getLoopVars(Spot portion, int& loopStart, int& loopEnd, int& loopInc); - /// Controls whether liquids are loaded - bool m_skipLiquid; + /// Controls whether liquids are loaded + bool m_skipLiquid; - /// Load the map terrain from file - bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array &vertices, G3D::Array &triangles, Spot portion); + /// Load the map terrain from file + bool loadHeightMap(uint32 mapID, uint32 tileX, uint32 tileY, G3D::Array& vertices, G3D::Array& triangles, Spot portion); - /// Get the vector coordinate for a specific position - void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float* coord, float* v); + /// Get the vector coordinate for a specific position + void getHeightCoord(int index, Grid grid, float xOffset, float yOffset, float* coord, float* v); - /// Get the triangle's vector indices for a specific position - void getHeightTriangle(int square, Spot triangle, int* indices, bool liquid = false); + /// Get the triangle's vector indices for a specific position + void getHeightTriangle(int square, Spot triangle, int* indices, bool liquid = false); - /// Determines if the specific position's triangles should be rendered - bool isHole(int square, const uint16 holes[16][16]); + /// Determines if the specific position's triangles should be rendered + bool isHole(int square, const uint16 holes[16][16]); - /// Get the liquid vector coordinate for a specific position - void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v); + /// Get the liquid vector coordinate for a specific position + void getLiquidCoord(int index, int index2, float xOffset, float yOffset, float* coord, float* v); - /// Get the liquid type for a specific position - uint8 getLiquidType(int square, const uint8 liquid_type[16][16]); + /// Get the liquid type for a specific position + uint8 getLiquidType(int square, const uint8 liquid_type[16][16]); }; } diff --git a/src/tools/mmaps_generator/VMapExtensions.cpp b/src/tools/mmaps_generator/VMapExtensions.cpp index 2c6f48dba..9afcb5899 100644 --- a/src/tools/mmaps_generator/VMapExtensions.cpp +++ b/src/tools/mmaps_generator/VMapExtensions.cpp @@ -20,26 +20,26 @@ namespace VMAP // maybe add MapBuilder as friend to all of the below classes would be better? // declared in src/common/vmap/MapTree.h - void StaticMapTree::getModelInstances(ModelInstance* &models, uint32 &count) + void StaticMapTree::getModelInstances(ModelInstance*& models, uint32& count) { models = iTreeValues; count = iNTreeValues; } // declared in src/common/vmap/VMapManager2.h - void VMapManager2::getInstanceMapTree(InstanceTreeMap &instanceMapTree) + void VMapManager2::getInstanceMapTree(InstanceTreeMap& instanceMapTree) { instanceMapTree = iInstanceMapTrees; } // declared in src/common/vmap/WorldModel.h - void WorldModel::getGroupModels(std::vector &groupModels) + void WorldModel::getGroupModels(std::vector& groupModels) { groupModels = this->groupModels; } // declared in src/common/vmap/WorldModel.h - void GroupModel::getMeshData(std::vector &vertices, std::vector &triangles, WmoLiquid* &liquid) + void GroupModel::getMeshData(std::vector& vertices, std::vector& triangles, WmoLiquid*& liquid) { vertices = this->vertices; triangles = this->triangles; @@ -53,7 +53,7 @@ namespace VMAP } // declared in src/common/vmap/WorldModel.h - void WmoLiquid::getPosInfo(uint32 &tilesX, uint32 &tilesY, G3D::Vector3 &corner) const + void WmoLiquid::getPosInfo(uint32& tilesX, uint32& tilesY, G3D::Vector3& corner) const { tilesX = iTilesX; tilesY = iTilesY; diff --git a/src/tools/vmap4_extractor/adtfile.cpp b/src/tools/vmap4_extractor/adtfile.cpp index 11bc828e3..cf6f78394 100644 --- a/src/tools/vmap4_extractor/adtfile.cpp +++ b/src/tools/vmap4_extractor/adtfile.cpp @@ -16,7 +16,7 @@ char const* GetPlainName(char const* FileName) { - const char * szTemp; + const char* szTemp; if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; @@ -25,7 +25,7 @@ char const* GetPlainName(char const* FileName) char* GetPlainName(char* FileName) { - char * szTemp; + char* szTemp; if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; @@ -34,11 +34,11 @@ char* GetPlainName(char* FileName) void fixnamen(char* name, size_t len) { - for (size_t i = 0; i < len-3; i++) + for (size_t i = 0; i < len - 3; i++) { - if (i > 0 && name[i] >= 'A' && name[i] <= 'Z' && isalpha(name[i-1])) + if (i > 0 && name[i] >= 'A' && name[i] <= 'Z' && isalpha(name[i - 1])) name[i] |= 0x20; - else if ((i == 0 || !isalpha(name[i-1])) && name[i]>='a' && name[i]<='z') + else if ((i == 0 || !isalpha(name[i - 1])) && name[i] >= 'a' && name[i] <= 'z') name[i] &= ~0x20; } //extension in lowercase @@ -48,10 +48,10 @@ void fixnamen(char* name, size_t len) void fixname2(char* name, size_t len) { - for (size_t i=0; i= recordSize); + assert(fieldCount * 4 >= recordSize); - data = new unsigned char[recordSize*recordCount+stringSize]; - stringTable = data + recordSize*recordCount; - f.read(data,recordSize*recordCount+stringSize); + data = new unsigned char[recordSize * recordCount + stringSize]; + stringTable = data + recordSize * recordCount; + f.read(data, recordSize * recordCount + stringSize); f.close(); return true; } @@ -68,7 +68,7 @@ DBCFile::~DBCFile() DBCFile::Record DBCFile::getRecord(size_t id) { assert(data); - return Record(*this, data + id*recordSize); + return Record(*this, data + id * recordSize); } DBCFile::Iterator DBCFile::begin() diff --git a/src/tools/vmap4_extractor/dbcfile.h b/src/tools/vmap4_extractor/dbcfile.h index 711d8257b..63052fea1 100644 --- a/src/tools/vmap4_extractor/dbcfile.h +++ b/src/tools/vmap4_extractor/dbcfile.h @@ -13,7 +13,7 @@ class DBCFile { public: - DBCFile(const std::string &filename); + DBCFile(const std::string& filename); ~DBCFile(); // Open database. It must be openened before it can be used. @@ -25,11 +25,11 @@ public: class Exception { public: - Exception(const std::string &message): message(message) + Exception(const std::string& message): message(message) { } virtual ~Exception() { } - const std::string &getMessage() {return message;} + const std::string& getMessage() {return message;} private: std::string message; }; @@ -56,24 +56,24 @@ public: float getFloat(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+field*4); + return *reinterpret_cast(offset + field * 4); } unsigned int getUInt(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+(field*4)); + return *reinterpret_cast(offset + (field * 4)); } int getInt(size_t field) const { assert(field < file.fieldCount); - return *reinterpret_cast(offset+field*4); + return *reinterpret_cast(offset + field * 4); } unsigned char getByte(size_t ofs) const { assert(ofs < file.recordSize); - return *reinterpret_cast(offset+ofs); + return *reinterpret_cast(offset + ofs); } - const char *getString(size_t field) const + const char* getString(size_t field) const { assert(field < file.fieldCount); size_t stringOffset = getUInt(field); @@ -83,9 +83,9 @@ public: return reinterpret_cast(file.stringTable + stringOffset); } private: - Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {} - DBCFile &file; - unsigned char *offset; + Record(DBCFile& file, unsigned char* offset): file(file), offset(offset) {} + DBCFile& file; + unsigned char* offset; friend class DBCFile; friend class Iterator; @@ -95,24 +95,26 @@ public: class Iterator { public: - Iterator(DBCFile &file, unsigned char *offset): + Iterator(DBCFile& file, unsigned char* offset): record(file, offset) {} /// Advance (prefix only) - Iterator & operator++() { + Iterator& operator++() + { record.offset += record.file.recordSize; return *this; } /// Return address of current instance - Record const & operator*() const { return record; } - const Record* operator->() const { + Record const& operator*() const { return record; } + const Record* operator->() const + { return &record; } /// Comparison - bool operator==(const Iterator &b) const + bool operator==(const Iterator& b) const { return record.offset == b.record.offset; } - bool operator!=(const Iterator &b) const + bool operator!=(const Iterator& b) const { return record.offset != b.record.offset; } @@ -136,8 +138,8 @@ private: size_t recordCount; size_t fieldCount; size_t stringSize; - unsigned char *data; - unsigned char *stringTable; + unsigned char* data; + unsigned char* stringTable; }; #endif diff --git a/src/tools/vmap4_extractor/gameobject_extract.cpp b/src/tools/vmap4_extractor/gameobject_extract.cpp index e307aea6f..f6cc07aa9 100644 --- a/src/tools/vmap4_extractor/gameobject_extract.cpp +++ b/src/tools/vmap4_extractor/gameobject_extract.cpp @@ -14,14 +14,14 @@ bool ExtractSingleModel(std::string& fname) { - char * name = GetPlainName((char*)fname.c_str()); - char * ext = GetExtension(name); + char* name = GetPlainName((char*)fname.c_str()); + char* ext = GetExtension(name); // < 3.1.0 ADT MMDX section store filename.mdx filenames for corresponded .m2 file if (!strcmp(ext, ".mdx")) { // replace .mdx -> .m2 - fname.erase(fname.length()-2,2); + fname.erase(fname.length() - 2, 2); fname.append("2"); } // >= 3.1.0 ADT MMDX section store filename.m2 filenames for corresponded .m2 file @@ -71,10 +71,10 @@ void ExtractGameobjectModels() continue; fixnamen((char*)path.c_str(), path.size()); - char * name = GetPlainName((char*)path.c_str()); + char* name = GetPlainName((char*)path.c_str()); fixname2(name, strlen(name)); - char * ch_ext = GetExtension(name); + char* ch_ext = GetExtension(name); if (!ch_ext) continue; diff --git a/src/tools/vmap4_extractor/loadlib/loadlib.h b/src/tools/vmap4_extractor/loadlib/loadlib.h index 989f66593..882530138 100644 --- a/src/tools/vmap4_extractor/loadlib/loadlib.h +++ b/src/tools/vmap4_extractor/loadlib/loadlib.h @@ -42,7 +42,8 @@ typedef uint8_t uint8; // struct file_MVER { - union{ + union + { uint32 fcc; char fcc_txt[4]; }; @@ -50,15 +51,16 @@ struct file_MVER uint32 ver; }; -class FileLoader{ - uint8 *data; +class FileLoader +{ + uint8* data; uint32 data_size; public: virtual bool prepareLoadedData(); - uint8 *GetData() {return data;} + uint8* GetData() {return data;} uint32 GetDataSize() {return data_size;} - file_MVER *version; + file_MVER* version; FileLoader(); ~FileLoader(); bool loadFile(std::string const& filename, bool log = true); diff --git a/src/tools/vmap4_extractor/model.cpp b/src/tools/vmap4_extractor/model.cpp index 07f1f3ec1..f91b11a89 100644 --- a/src/tools/vmap4_extractor/model.cpp +++ b/src/tools/vmap4_extractor/model.cpp @@ -12,7 +12,7 @@ #include #include -Model::Model(std::string &filename) : filename(filename), vertices(0), indices(0) +Model::Model(std::string& filename) : filename(filename), vertices(0), indices(0) { memset(&header, 0, sizeof(header)); } @@ -37,13 +37,13 @@ bool Model::open() f.seek(0); f.seekRelative(header.ofsBoundingVertices); vertices = new Vec3D[header.nBoundingVertices]; - f.read(vertices,header.nBoundingVertices*12); - for (uint32 i=0; i0) + if (nVertices > 0) { for (uint32 vpos = 0; vpos < nVertices; ++vpos) { @@ -110,7 +110,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); @@ -129,7 +129,7 @@ Vec3D fixCoordSystem2(Vec3D v) return Vec3D(v.x, v.z, v.y); } -ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE *pDirfile) +ModelInstance::ModelInstance(MPQFile& f, char const* ModelInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile) { float ff[3]; f.read(&id, 4); @@ -175,7 +175,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/mpq_libmpq.cpp b/src/tools/vmap4_extractor/mpq_libmpq.cpp index 5ed5e083d..b07db02c0 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq.cpp +++ b/src/tools/vmap4_extractor/mpq_libmpq.cpp @@ -14,8 +14,10 @@ MPQArchive::MPQArchive(const char* filename) { int result = libmpq__archive_open(&mpq_a, filename, -1); printf("Opening %s\n", filename); - if(result) { - switch(result) { + if(result) + { + switch(result) + { case LIBMPQ_ERROR_OPEN : printf("Error opening archive '%s': Does file really exist?\n", filename); break; @@ -52,9 +54,9 @@ MPQFile::MPQFile(const char* filename): pointer(0), size(0) { - for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i) + for(ArchiveSet::iterator i = gOpenArchives.begin(); i != gOpenArchives.end(); ++i) { - mpq_archive *mpq_a = (*i)->mpq_a; + mpq_archive* mpq_a = (*i)->mpq_a; uint32 filenum; if(libmpq__file_number(mpq_a, filename, &filenum)) continue; @@ -62,7 +64,8 @@ MPQFile::MPQFile(const char* filename): libmpq__file_unpacked_size(mpq_a, filenum, &size); // HACK: in patch.mpq some files don't want to open and give 1 for filesize - if (size<=1) { + if (size <= 1) + { // printf("info: file %s has size %d; considered dummy file.\n", filename, size); eof = true; buffer = 0; @@ -85,7 +88,8 @@ size_t MPQFile::read(void* dest, size_t bytes) if (eof) return 0; size_t rpos = pointer + bytes; - if (rpos > size_t(size)) { + if (rpos > size_t(size)) + { bytes = size - pointer; eof = true; } diff --git a/src/tools/vmap4_extractor/mpq_libmpq04.h b/src/tools/vmap4_extractor/mpq_libmpq04.h index d0262842a..6f2759544 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq04.h +++ b/src/tools/vmap4_extractor/mpq_libmpq04.h @@ -21,28 +21,30 @@ class MPQArchive { public: - mpq_archive_s *mpq_a; + mpq_archive_s* mpq_a; MPQArchive(const char* filename); void close(); - void GetFileListTo(vector& filelist) { + void GetFileListTo(vector& filelist) + { uint32_t filenum; if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return; libmpq__off_t size, transferred; libmpq__file_unpacked_size(mpq_a, filenum, &size); - char *buffer = new char[size + 1]; + char* buffer = new char[size + 1]; buffer[size] = '\0'; libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred); char seps[] = "\n"; - char *token; + char* token; token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != nullptr) && (counter < size)) { + while ((token != nullptr) && (counter < size)) + { //cout << token << endl; token[strlen(token) - 1] = 0; string s = token; @@ -60,8 +62,8 @@ class MPQFile { //MPQHANDLE handle; bool eof; - char *buffer; - libmpq__off_t pointer,size; + char* buffer; + libmpq__off_t pointer, size; // disable copying MPQFile(const MPQFile& /*f*/) {} @@ -81,15 +83,15 @@ public: void close(); }; -inline void flipcc(char *fcc) +inline void flipcc(char* fcc) { char t; - t=fcc[0]; - fcc[0]=fcc[3]; - fcc[3]=t; - t=fcc[1]; - fcc[1]=fcc[2]; - fcc[2]=t; + t = fcc[0]; + fcc[0] = fcc[3]; + fcc[3] = t; + t = fcc[1]; + fcc[1] = fcc[2]; + fcc[2] = t; } #endif diff --git a/src/tools/vmap4_extractor/vec3d.h b/src/tools/vmap4_extractor/vec3d.h index ead433644..64743e801 100644 --- a/src/tools/vmap4_extractor/vec3d.h +++ b/src/tools/vmap4_extractor/vec3d.h @@ -13,39 +13,40 @@ 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(const Vec3D& v) : x(v.x), y(v.y), z(v.z) {} - Vec3D& operator= (const Vec3D &v) { + Vec3D& operator= (const Vec3D& v) + { x = v.x; y = v.y; z = v.z; return *this; } - Vec3D operator+ (const Vec3D &v) const + Vec3D operator+ (const Vec3D& 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- (const Vec3D& 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* (const Vec3D& 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 r(x*d,y*d,z*d); + Vec3D r(x * d, y * d, z * d); return r; } @@ -54,13 +55,13 @@ public: return v * d; } - Vec3D operator% (const Vec3D &v) const + Vec3D operator% (const Vec3D& 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+= (const Vec3D& v) { x += v.x; y += v.y; @@ -68,7 +69,7 @@ public: return *this; } - Vec3D& operator-= (const Vec3D &v) + Vec3D& operator-= (const Vec3D& v) { x -= v.x; y -= v.y; @@ -86,17 +87,17 @@ public: float lengthSquared() const { - return x*x+y*y+z*z; + return x * x + y * y + z * z; } float length() const { - return sqrt(x*x+y*y+z*z); + return sqrt(x * x + y * y + z * z); } Vec3D& normalize() { - this->operator*= (1.0f/length()); + this->operator*= (1.0f / length()); return *this; } @@ -119,7 +120,7 @@ public: return out; } - operator float*() + operator float* () { return (float*)this; } @@ -129,38 +130,39 @@ public: class Vec2D { public: - float x,y; + float x, y; Vec2D(float x0 = 0.0f, float y0 = 0.0f) : x(x0), y(y0) {} Vec2D(const Vec2D& v) : x(v.x), y(v.y) {} - Vec2D& operator= (const Vec2D &v) { + Vec2D& operator= (const Vec2D& v) + { x = v.x; y = v.y; return *this; } - Vec2D operator+ (const Vec2D &v) const + Vec2D operator+ (const Vec2D& 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- (const Vec2D& 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* (const Vec2D& v) const { - return x*v.x + y*v.y; + return x * v.x + y * v.y; } Vec2D operator* (float d) const { - Vec2D r(x*d,y*d); + Vec2D r(x * d, y * d); return r; } @@ -169,14 +171,14 @@ public: return v * d; } - Vec2D& operator+= (const Vec2D &v) + Vec2D& operator+= (const Vec2D& v) { x += v.x; y += v.y; return *this; } - Vec2D& operator-= (const Vec2D &v) + Vec2D& operator-= (const Vec2D& v) { x -= v.x; y -= v.y; @@ -192,17 +194,17 @@ public: float lengthSquared() const { - return x*x+y*y; + return x * x + y * y; } float length() const { - return sqrt(x*x+y*y); + return sqrt(x * x + y * y); } Vec2D& normalize() { - this->operator*= (1.0f/length()); + this->operator*= (1.0f / length()); return *this; } @@ -220,17 +222,17 @@ public: return in; } - operator float*() + operator float* () { return (float*)this; } }; -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; - *x = xa*cosf(angle) - ya*sinf(angle) + x0; - *y = xa*sinf(angle) + ya*cosf(angle) + y0; + *x = xa * cosf(angle) - ya * sinf(angle) + x0; + *y = xa * sinf(angle) + ya * cosf(angle) + y0; } #endif diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index e0933b2f5..d9c862b1a 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -12,12 +12,12 @@ #include #ifdef WIN32 - #include - #include - #include - #define mkdir _mkdir +#include +#include +#include +#define mkdir _mkdir #else - #include +#include #endif #undef min @@ -50,13 +50,13 @@ typedef struct { char name[64]; unsigned int id; -}map_id; +} map_id; -map_id * map_ids; -uint16 *LiqType = 0; +map_id* map_ids; +uint16* LiqType = 0; uint32 map_count; -char output_path[128]="."; -char input_path[1024]="."; +char output_path[128] = "."; +char input_path[1024] = "."; bool hasInputPathParam = false; bool preciseVectorData = false; @@ -82,7 +82,7 @@ void strToLower(char* str) { while(*str) { - *str=tolower(*str); + *str = tolower(*str); ++str; } } @@ -138,9 +138,9 @@ bool ExtractSingleWmo(std::string& fname) // Copy files from archive char szLocalFile[1024]; - const char * plain_name = GetPlainName(fname.c_str()); + const char* plain_name = GetPlainName(fname.c_str()); sprintf(szLocalFile, "%s/%s", szWorkDirWmo, plain_name); - fixnamen(szLocalFile,strlen(szLocalFile)); + fixnamen(szLocalFile, strlen(szLocalFile)); if (FileExists(szLocalFile)) return true; @@ -171,7 +171,7 @@ bool ExtractSingleWmo(std::string& fname) printf("Couldn't open RootWmo!!!\n"); return true; } - FILE *output = fopen(szLocalFile,"wb"); + FILE* output = fopen(szLocalFile, "wb"); if(!output) { printf("couldn't open %s for writing!\n", szLocalFile); @@ -180,13 +180,13 @@ bool ExtractSingleWmo(std::string& fname) froot.ConvertToVMAPRootWmo(output); int Wmo_nVertices = 0; //printf("root has %d groups\n", froot->nGroups); - if (froot.nGroups !=0) + if (froot.nGroups != 0) { for (uint32 i = 0; i < froot.nGroups; ++i) { char temp[1024]; strncpy(temp, fname.c_str(), 1024); - temp[fname.length()-4] = 0; + temp[fname.length() - 4] = 0; char groupFileName[1024]; int ret = snprintf(groupFileName, 1024, "%s_%03u.wmo", temp, i); if (ret < 0) @@ -210,7 +210,7 @@ bool ExtractSingleWmo(std::string& fname) } fseek(output, 8, SEEK_SET); // store the correct no of vertices - fwrite(&Wmo_nVertices,sizeof(int),1,output); + fwrite(&Wmo_nVertices, sizeof(int), 1, output); fclose(output); // Delete the extracted file in the case of an error @@ -224,19 +224,19 @@ void ParsMapFiles() char fn[512]; //char id_filename[64]; char id[10]; - for (unsigned int i=0; iinit(map_ids[i].id, x, y); @@ -254,9 +254,9 @@ void ParsMapFiles() void getGamePath() { #ifdef _WIN32 - strcpy(input_path,"Data\\"); + strcpy(input_path, "Data\\"); #else - strcpy(input_path,"Data/"); + strcpy(input_path, "Data/"); #endif } @@ -381,7 +381,7 @@ bool fillArchiveNameVector(std::vector& pArchiveNames) return true; } -bool processArgv(int argc, char ** argv, const char *versionString) +bool processArgv(int argc, char** argv, const char* versionString) { bool result = true; hasInputPathParam = false; @@ -389,16 +389,16 @@ bool processArgv(int argc, char ** argv, const char *versionString) for(int i = 1; i < argc; ++i) { - if(strcmp("-s",argv[i]) == 0) + if(strcmp("-s", argv[i]) == 0) { preciseVectorData = false; } - else if(strcmp("-d",argv[i]) == 0) + else if(strcmp("-d", argv[i]) == 0) { - if((i+1)]\n", argv[0]); printf(" -s : (default) small size (data size optimization), ~500MB less vmap data.\n"); printf(" -l : large size, ~500MB more vmap data. (might contain more details)\n"); @@ -444,10 +444,10 @@ bool processArgv(int argc, char ** argv, const char *versionString) // Arg2 - Listfile name // -int main(int argc, char ** argv) +int main(int argc, char** argv) { - bool success=true; - const char *versionString = "V4.00 2012_02"; + bool success = true; + const char* versionString = "V4.00 2012_02"; // Use command line arguments, when some if (!processArgv(argc, argv, versionString)) @@ -468,29 +468,29 @@ 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 #if defined(__linux__) || defined(__APPLE__) - , 0711 + , 0711 #endif - )) - success = (errno == EEXIST); + )) + success = (errno == EEXIST); // prepare archive name list std::vector 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()); + MPQArchive* archive = new MPQArchive(archiveNames[i].c_str()); if (gOpenArchives.empty() || gOpenArchives.front() != archive) delete archive; } 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(); @@ -503,20 +503,20 @@ int main(int argc, char ** argv) //map.dbc if (success) { - DBCFile * dbc = new DBCFile("DBFilesClient\\Map.dbc"); + DBCFile* dbc = new DBCFile("DBFilesClient\\Map.dbc"); if (!dbc->open()) { delete dbc; 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;xgetRecordCount (); + 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); - strcpy(map_ids[x].name,dbc->getRecord(x).getString(1)); - printf("Map - %s\n",map_ids[x].name); + map_ids[x].id = dbc->getRecord (x).getUInt(0); + strcpy(map_ids[x].name, dbc->getRecord(x).getString(1)); + printf("Map - %s\n", map_ids[x].name); } @@ -531,11 +531,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); + printf("Extract %s. Work complete. No errors.\n", versionString); delete [] LiqType; return 0; } diff --git a/src/tools/vmap4_extractor/vmapexport.h b/src/tools/vmap4_extractor/vmapexport.h index 47c16d89c..024e8c224 100644 --- a/src/tools/vmap4_extractor/vmapexport.h +++ b/src/tools/vmap4_extractor/vmapexport.h @@ -12,14 +12,14 @@ enum ModelFlags { MOD_M2 = 1, - MOD_WORLDSPAWN = 1<<1, - MOD_HAS_BOUND = 1<<2 + MOD_WORLDSPAWN = 1 << 1, + MOD_HAS_BOUND = 1 << 2 }; -extern const char * szWorkDirWmo; -extern const char * szRawVMAPMagic; // vmap magic string for extracted raw vmap data +extern const char* szWorkDirWmo; +extern const char* szRawVMAPMagic; // vmap magic string for extracted raw vmap data -bool FileExists(const char * file); +bool FileExists(const char* file); void strToLower(char* str); bool ExtractSingleWmo(std::string& fname); diff --git a/src/tools/vmap4_extractor/wdtfile.cpp b/src/tools/vmap4_extractor/wdtfile.cpp index 72710750c..308099d5e 100644 --- a/src/tools/vmap4_extractor/wdtfile.cpp +++ b/src/tools/vmap4_extractor/wdtfile.cpp @@ -9,9 +9,9 @@ #include "adtfile.h" #include -char * wdtGetPlainName(char * FileName) +char* wdtGetPlainName(char* FileName) { - char * szTemp; + char* szTemp; if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; @@ -20,7 +20,7 @@ char * wdtGetPlainName(char * FileName) WDTFile::WDTFile(char* file_name, char* file_name1) : WDT(file_name), gWmoInstansName(nullptr), gnWMO(0) { - filename.append(file_name1,strlen(file_name1)); + filename.append(file_name1, strlen(file_name1)); } bool WDTFile::init(char* /*map_id*/, unsigned int mapID) @@ -35,7 +35,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID) uint32 size; std::string dirname = std::string(szWorkDirWmo) + "/dir_bin"; - FILE *dirfile; + FILE* dirfile; dirfile = fopen(dirname.c_str(), "ab"); if(!dirfile) { @@ -45,7 +45,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID) while (!WDT.isEof()) { - WDT.read(fourcc,4); + WDT.read(fourcc, 4); WDT.read(&size, 4); flipcc(fourcc); @@ -53,24 +53,24 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID) size_t nextpos = WDT.getPos() + size; - if (!strcmp(fourcc,"MAIN")) + if (!strcmp(fourcc, "MAIN")) { } - if (!strcmp(fourcc,"MWMO")) + if (!strcmp(fourcc, "MWMO")) { // global map objects if (size) { - char *buf = new char[size]; + char* buf = new char[size]; WDT.read(buf, size); - char *p=buf; + char* p = buf; int q = 0; gWmoInstansName = new string[size]; while (p < buf + size) { - char* s=wdtGetPlainName(p); - fixnamen(s,strlen(s)); - p=p+strlen(p)+1; + char* s = wdtGetPlainName(p); + fixnamen(s, strlen(s)); + p = p + strlen(p) + 1; gWmoInstansName[q++] = s; } delete[] buf; @@ -87,7 +87,7 @@ bool WDTFile::init(char* /*map_id*/, unsigned int mapID) { int id; WDT.read(&id, 4); - WMOInstance inst(WDT,gWmoInstansName[id].c_str(), mapID, 65, 65, dirfile); + WMOInstance inst(WDT, gWmoInstansName[id].c_str(), mapID, 65, 65, dirfile); } delete[] gWmoInstansName; @@ -108,11 +108,11 @@ WDTFile::~WDTFile(void) ADTFile* WDTFile::GetMap(int x, int z) { - if(!(x>=0 && z >= 0 && x<64 && z<64)) + if(!(x >= 0 && z >= 0 && x < 64 && z < 64)) return nullptr; char name[512]; - sprintf(name,"World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z); + sprintf(name, "World\\Maps\\%s\\%s_%d_%d.adt", filename.c_str(), filename.c_str(), x, z); return new ADTFile(name); } diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index 3e6f3cb40..9e3c84eb1 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -17,11 +17,11 @@ #include "mpq_libmpq04.h" using namespace std; -extern uint16 *LiqType; +extern uint16* LiqType; -WMORoot::WMORoot(std::string &filename) +WMORoot::WMORoot(std::string& filename) : filename(filename), col(0), nTextures(0), nGroups(0), nP(0), nLights(0), - nModels(0), nDoodads(0), nDoodadSets(0), RootWMOID(0), liquidType(0) + nModels(0), nDoodads(0), nDoodadSets(0), RootWMOID(0), liquidType(0) { memset(bbcorn1, 0, sizeof(bbcorn1)); memset(bbcorn2, 0, sizeof(bbcorn2)); @@ -41,7 +41,7 @@ bool WMORoot::open() while (!f.isEof()) { - f.read(fourcc,4); + f.read(fourcc, 4); f.read(&size, 4); flipcc(fourcc); @@ -49,7 +49,7 @@ bool WMORoot::open() size_t nextpos = f.getPos() + size; - if (!strcmp(fourcc,"MOHD")) // header + if (!strcmp(fourcc, "MOHD")) // header { f.read(&nTextures, 4); f.read(&nGroups, 4); @@ -118,13 +118,13 @@ bool WMORoot::ConvertToVMAPRootWmo(FILE* pOutfile) fwrite(szRawVMAPMagic, 1, 8, pOutfile); unsigned int nVectors = 0; - fwrite(&nVectors,sizeof(nVectors), 1, pOutfile); // will be filled later + fwrite(&nVectors, sizeof(nVectors), 1, pOutfile); // will be filled later fwrite(&nGroups, 4, 1, pOutfile); fwrite(&RootWMOID, 4, 1, pOutfile); return true; } -WMOGroup::WMOGroup(const std::string &filename) : +WMOGroup::WMOGroup(const std::string& filename) : filename(filename), MOPY(0), MOVI(0), MoviEx(0), MOVT(0), MOBA(0), MobaEx(0), hlq(0), LiquEx(0), LiquBytes(0), groupName(0), descGroupName(0), mogpFlags(0), moprIdx(0), moprNItems(0), nBatchA(0), nBatchB(0), nBatchC(0), fogIdx(0), @@ -147,10 +147,10 @@ bool WMOGroup::open() char fourcc[5]; while (!f.isEof()) { - f.read(fourcc,4); + f.read(fourcc, 4); f.read(&size, 4); flipcc(fourcc); - if (!strcmp(fourcc,"MOGP"))//Fix sizeoff = Data size. + if (!strcmp(fourcc, "MOGP")) //Fix sizeoff = Data size. { size = 68; } @@ -159,7 +159,7 @@ bool WMOGroup::open() LiquEx_size = 0; liquflags = 0; - if (!strcmp(fourcc,"MOGP"))//header + if (!strcmp(fourcc, "MOGP")) //header { f.read(&groupName, 4); f.read(&descGroupName, 4); @@ -173,40 +173,40 @@ bool WMOGroup::open() f.read(&nBatchC, 4); f.read(&fogIdx, 4); f.read(&liquidType, 4); - f.read(&groupWMOID,4); + f.read(&groupWMOID, 4); } - else if (!strcmp(fourcc,"MOPY")) + else if (!strcmp(fourcc, "MOPY")) { MOPY = new char[size]; mopy_size = size; nTriangles = (int)size / 2; f.read(MOPY, size); } - else if (!strcmp(fourcc,"MOVI")) + else if (!strcmp(fourcc, "MOVI")) { - MOVI = new uint16[size/2]; + MOVI = new uint16[size / 2]; f.read(MOVI, size); } - else if (!strcmp(fourcc,"MOVT")) + else if (!strcmp(fourcc, "MOVT")) { - MOVT = new float[size/4]; + MOVT = new float[size / 4]; f.read(MOVT, size); nVertices = (int)size / 12; } - else if (!strcmp(fourcc,"MONR")) + else if (!strcmp(fourcc, "MONR")) { } - else if (!strcmp(fourcc,"MOTV")) + else if (!strcmp(fourcc, "MOTV")) { } - else if (!strcmp(fourcc,"MOBA")) + else if (!strcmp(fourcc, "MOBA")) { - MOBA = new uint16[size/2]; - moba_size = size/2; + MOBA = new uint16[size / 2]; + moba_size = size / 2; f.read(MOBA, size); } - else if (!strcmp(fourcc,"MLIQ")) + else if (!strcmp(fourcc, "MLIQ")) { liquflags |= 1; hlq = new WMOLiquidHeader(); @@ -231,36 +231,36 @@ bool WMOGroup::open() return true; } -int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool preciseVectorData) +int WMOGroup::ConvertToVMAPGroupWmo(FILE* output, WMORoot* rootWMO, bool preciseVectorData) { - fwrite(&mogpFlags,sizeof(uint32),1,output); - fwrite(&groupWMOID,sizeof(uint32),1,output); + fwrite(&mogpFlags, sizeof(uint32), 1, output); + fwrite(&groupWMOID, sizeof(uint32), 1, output); // group bound fwrite(bbcorn1, sizeof(float), 3, output); fwrite(bbcorn2, sizeof(float), 3, output); - fwrite(&liquflags,sizeof(uint32),1,output); + fwrite(&liquflags, sizeof(uint32), 1, output); int nColTriangles = 0; if (preciseVectorData) { char GRP[] = "GRP "; - fwrite(GRP,1,4,output); + fwrite(GRP, 1, 4, output); int k = 0; - int moba_batch = moba_size/12; - MobaEx = new int[moba_batch*4]; - for(int i=8; i0) + if(nIdexes > 0) { if(fwrite(MOVI, sizeof(unsigned short), nIdexes, output) != nIdexes) { @@ -285,7 +285,7 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise } } - if(fwrite("VERT",4, 1, output) != 1) + if(fwrite("VERT", 4, 1, output) != 1) { printf("Error while writing file nbraches ID"); exit(0); @@ -301,9 +301,9 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise printf("Error while writing file nVertices"); exit(0); } - if(nVertices >0) + if(nVertices > 0) { - if(fwrite(MOVT, sizeof(float)*3, nVertices, output) != nVertices) + if(fwrite(MOVT, sizeof(float) * 3, nVertices, output) != nVertices) { printf("Error while writing file vectors"); exit(0); @@ -315,27 +315,27 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise else { char GRP[] = "GRP "; - fwrite(GRP,1,4,output); + fwrite(GRP, 1, 4, output); int k = 0; - int moba_batch = moba_size/12; - MobaEx = new int[moba_batch*4]; - for(int i=8; i(sizeof(float))+4, nColVertices};// "VERT" - int check = 3*nColVertices; - fwrite(VERT,4,3,output); - for (uint32 i=0; i(sizeof(float)) + 4, nColVertices}; // "VERT" + int check = 3 * nColVertices; + fwrite(VERT, 4, 3, output); + for (uint32 i = 0; i < nVertices; ++i) if(IndexRenum[i] >= 0) - check -= fwrite(MOVT+3*i, sizeof(float), 3, output); + check -= fwrite(MOVT + 3 * i, sizeof(float), 3, output); - assert(check==0); + assert(check == 0); delete [] MoviEx; delete [] IndexRenum; @@ -391,7 +391,7 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise //------LIQU------------------------ if (LiquEx_size != 0) { - int LIQU_h[] = {0x5551494C, static_cast(sizeof(WMOLiquidHeader) + LiquEx_size) + hlq->xtiles*hlq->ytiles};// "LIQU" + int LIQU_h[] = {0x5551494C, static_cast(sizeof(WMOLiquidHeader) + LiquEx_size) + hlq->xtiles* hlq->ytiles}; // "LIQU" fwrite(LIQU_h, 4, 2, output); // according to WoW.Dev Wiki: @@ -452,10 +452,10 @@ int WMOGroup::ConvertToVMAPGroupWmo(FILE *output, WMORoot *rootWMO, bool precise fwrite(hlq, sizeof(WMOLiquidHeader), 1, output); // only need height values, the other values are unknown anyway - for (uint32 i = 0; ixtiles*hlq->ytiles, output); + fwrite(LiquBytes, 1, hlq->xtiles * hlq->ytiles, output); } return nColTriangles; @@ -477,25 +477,25 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint { 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]); - f.read(ff,12); - pos3 = Vec3D(ff[0],ff[1],ff[2]); - f.read(&d2,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]); + f.read(ff, 12); + pos3 = Vec3D(ff[0], ff[1], ff[2]); + f.read(&d2, 4); - uint16 trash,adtId; - f.read(&adtId,2); - f.read(&trash,2); + uint16 trash, adtId; + f.read(&adtId, 2); + f.read(&trash, 2); //-----------add_in _dir_file---------------- char tempname[512]; sprintf(tempname, "%s/%s", szWorkDirWmo, WmoInstName); - FILE *input; + FILE* input; input = fopen(tempname, "r+b"); if(!input) @@ -512,13 +512,13 @@ WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint 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); @@ -539,7 +539,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 ce70acc64..a9df008f0 100644 --- a/src/tools/vmap4_extractor/wmo.h +++ b/src/tools/vmap4_extractor/wmo.h @@ -32,7 +32,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(const Vec3D& v) { return Vec3D(v.z, v.x, v.y); } class WMORoot { @@ -118,7 +118,7 @@ public: Vec3D pos2, pos3, rot; uint32 indx, id, d2, d3; - WMOInstance(MPQFile&f , char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile); + WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile); static void reset(); };