diff --git a/src/common/Threading/PCQueue.h b/src/common/Threading/PCQueue.h new file mode 100644 index 000000000..12cad73b4 --- /dev/null +++ b/src/common/Threading/PCQueue.h @@ -0,0 +1,101 @@ +/* +* Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 +* Copyright (C) 2008-2016 TrinityCore +* Copyright (C) 2005-2009 MaNGOS +*/ + +#ifndef _PCQ_H +#define _PCQ_H + +#include +#include +#include +#include +#include + +template +class ProducerConsumerQueue +{ +private: + std::mutex _queueLock; + std::queue _queue; + std::condition_variable _condition; + std::atomic _shutdown; + +public: + + ProducerConsumerQueue() : _shutdown(false) { } + + void Push(const T& value) + { + std::lock_guard lock(_queueLock); + _queue.push(std::move(value)); + + _condition.notify_one(); + } + + bool Empty() + { + std::lock_guard lock(_queueLock); + + return _queue.empty(); + } + + bool Pop(T& value) + { + std::lock_guard lock(_queueLock); + + if (_queue.empty() || _shutdown) + return false; + + value = _queue.front(); + + _queue.pop(); + + return true; + } + + void WaitAndPop(T& value) + { + std::unique_lock lock(_queueLock); + + // we could be using .wait(lock, predicate) overload here but it is broken + // https://connect.microsoft.com/VisualStudio/feedback/details/1098841 + while (_queue.empty() && !_shutdown) + _condition.wait(lock); + + if (_queue.empty() || _shutdown) + return; + + value = _queue.front(); + + _queue.pop(); + } + + void Cancel() + { + std::unique_lock lock(_queueLock); + + while (!_queue.empty()) + { + T& value = _queue.front(); + + DeleteQueuedObject(value); + + _queue.pop(); + } + + _shutdown = true; + + _condition.notify_all(); + } + +private: + template + typename std::enable_if::value>::type DeleteQueuedObject(E& obj) { delete obj; } + + template + typename std::enable_if::value>::type DeleteQueuedObject(E const& /*packet*/) { } +}; + +#endif diff --git a/src/common/Threading/PolicyLock.h b/src/common/Threading/PolicyLock.h new file mode 100644 index 000000000..d147fbe00 --- /dev/null +++ b/src/common/Threading/PolicyLock.h @@ -0,0 +1,16 @@ +/* +* Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 +* Copyright (C) 2008-2016 TrinityCore +* Copyright (C) 2005-2009 MaNGOS +*/ + +#ifndef POLICYLOCK_H +#define POLICYLOCK_H + +#include + +#define RETURN_GUARD(mutex, retval) if (!mutex.try_lock()) \ + return retval; \ + std::lock_guard guard(mutex, std::adopt_lock) + +#endif diff --git a/src/common/Threading/ThreadingModel.h b/src/common/Threading/ThreadingModel.h new file mode 100644 index 000000000..793580a87 --- /dev/null +++ b/src/common/Threading/ThreadingModel.h @@ -0,0 +1,144 @@ +/* +* Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2 +* Copyright (C) 2008-2016 TrinityCore +* Copyright (C) 2005-2009 MaNGOS +*/ + +#ifndef ACORE_THREADINGMODEL_H +#define ACORE_THREADINGMODEL_H + +/** + * @class ThreadingModel + * + */ + +#include "Define.h" + +namespace acore +{ + template + class GeneralLock + { + public: + + GeneralLock(MUTEX& m) + : i_mutex(m) + { + i_mutex.lock(); + } + + ~GeneralLock() + { + i_mutex.unlock(); + } + + private: + + GeneralLock(const GeneralLock&); + GeneralLock& operator=(const GeneralLock&); + MUTEX& i_mutex; + }; + + template + class SingleThreaded + { + public: + + struct Lock // empty object + { + Lock() + { + } + Lock(const T&) + { + } + + Lock(const SingleThreaded&) // for single threaded we ignore this + { + } + }; + }; + + template + class ObjectLevelLockable + { + public: + + ObjectLevelLockable() + : i_mtx() + { + } + + friend class Lock; + + class Lock + { + public: + + Lock(ObjectLevelLockable& host) + : i_lock(host.i_mtx) + { + } + + private: + + GeneralLock i_lock; + }; + + private: + + // prevent the compiler creating a copy construct + ObjectLevelLockable(const ObjectLevelLockable&); + ObjectLevelLockable& operator=(const ObjectLevelLockable&); + + MUTEX i_mtx; + }; + + template + class ClassLevelLockable + { + public: + + ClassLevelLockable() + { + } + + friend class Lock; + + class Lock + { + public: + + Lock(const T& /*host*/) + { + ClassLevelLockable::si_mtx.lock(); + } + + Lock(const ClassLevelLockable&) + { + ClassLevelLockable::si_mtx.lock(); + } + + Lock() + { + ClassLevelLockable::si_mtx.lock(); + } + + ~Lock() + { + ClassLevelLockable::si_mtx.unlock(); + } + }; + + private: + + static MUTEX si_mtx; + }; +} + +template MUTEX acore::ClassLevelLockable::si_mtx; + +#define INSTANTIATE_CLASS_MUTEX(CTYPE, MUTEX) \ + template class acore::ClassLevelLockable + +#endif diff --git a/src/tools/map_extractor/dbcfile.cpp b/src/tools/map_extractor/dbcfile.cpp index 59217aaed..b535a18fb 100644 --- a/src/tools/map_extractor/dbcfile.cpp +++ b/src/tools/map_extractor/dbcfile.cpp @@ -10,7 +10,7 @@ #include "mpq_libmpq04.h" DBCFile::DBCFile(const std::string& filename): - filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(NULL), stringTable(NULL) + filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr) { } diff --git a/src/tools/map_extractor/mpq_libmpq04.h b/src/tools/map_extractor/mpq_libmpq04.h index cd6771090..12af75d8a 100644 --- a/src/tools/map_extractor/mpq_libmpq04.h +++ b/src/tools/map_extractor/mpq_libmpq04.h @@ -43,13 +43,13 @@ public: token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != NULL) && (counter < size)) { + while ((token != nullptr) && (counter < size)) { //cout << token << endl; token[strlen(token) - 1] = 0; string s = token; filelist.push_back(s); counter += strlen(token) + 2; - token = strtok(NULL, seps); + token = strtok(nullptr, seps); } delete[] buffer; diff --git a/src/tools/mesh_extractor/ADT.cpp b/src/tools/mesh_extractor/ADT.cpp index 1e122ac7e..e0c62f656 100644 --- a/src/tools/mesh_extractor/ADT.cpp +++ b/src/tools/mesh_extractor/ADT.cpp @@ -9,15 +9,15 @@ #include "LiquidHandler.h" #include "WorldModelHandler.h" -ADT::ADT( std::string file, int x, int y ) : ObjectData(NULL), Data(NULL), HasObjectData(false), - _DoodadHandler(NULL), _WorldModelHandler(NULL), _LiquidHandler(NULL), X(x), Y(y) +ADT::ADT( std::string file, int x, int y ) : ObjectData(nullptr), Data(nullptr), HasObjectData(false), + _DoodadHandler(nullptr), _WorldModelHandler(nullptr), _LiquidHandler(nullptr), X(x), Y(y) { Data = new ChunkedData(file); ObjectData = new ChunkedData(file); if (ObjectData->Stream) HasObjectData = true; else - ObjectData = NULL; + ObjectData = nullptr; } ADT::~ADT() diff --git a/src/tools/mesh_extractor/Cache.h b/src/tools/mesh_extractor/Cache.h index 94b166442..ccd1222a8 100644 --- a/src/tools/mesh_extractor/Cache.h +++ b/src/tools/mesh_extractor/Cache.h @@ -9,8 +9,8 @@ #include #include #include "Define.h" -#include -#include +#include "PolicyLock.h" +#include #include "WorldModelRoot.h" #include "Model.h" @@ -24,7 +24,7 @@ public: void Insert(K key, T* val) { - ACE_GUARD(ACE_Thread_Mutex, g, mutex); + std::lock_guard guard(_mutex); if (_items.size() > FlushLimit) Clear(); @@ -33,11 +33,11 @@ public: T* Get(K key) { - ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL); + RETURN_GUAD(mutex, false); typename std::map::iterator itr = _items.find(key); if (itr != _items.end()) return itr->second; - return NULL; + return nullptr; } void Clear() @@ -48,7 +48,7 @@ public: } private: std::map _items; - ACE_Thread_Mutex mutex; + std::mutex mutex; }; class CacheClass diff --git a/src/tools/mesh_extractor/ChunkedData.cpp b/src/tools/mesh_extractor/ChunkedData.cpp index 75ea98d04..91d3f9036 100644 --- a/src/tools/mesh_extractor/ChunkedData.cpp +++ b/src/tools/mesh_extractor/ChunkedData.cpp @@ -66,7 +66,7 @@ Chunk* ChunkedData::GetChunkByName( const std::string& name ) for (uint32 i = 0; i < Chunks.size(); ++i) if (Chunks[i]->Name == name) return Chunks[i]; - return NULL; + return nullptr; } ChunkedData::~ChunkedData() diff --git a/src/tools/mesh_extractor/ContinentBuilder.cpp b/src/tools/mesh_extractor/ContinentBuilder.cpp index d65f1ae37..069f45f17 100644 --- a/src/tools/mesh_extractor/ContinentBuilder.cpp +++ b/src/tools/mesh_extractor/ContinentBuilder.cpp @@ -10,11 +10,11 @@ #include "Utils.h" #include "DetourNavMesh.h" #include "Cache.h" -#include "ace/Task.h" +#include #include "Recast.h" #include "DetourCommon.h" -class BuilderThread : public ACE_Task_Base +class BuilderThread { private: int X, Y, MapId; @@ -99,7 +99,7 @@ void ContinentBuilder::CalculateTileBounds() tileYMax = std::max(itr->Y, tileYMax); tileYMin = std::min(itr->Y, tileYMin); } - getTileBounds(tileXMax, tileYMax, NULL, 0, bmin, bmax); + getTileBounds(tileXMax, tileYMax, nullptr, 0, bmin, bmax); } void ContinentBuilder::Build() @@ -186,7 +186,7 @@ void ContinentBuilder::Build() } } // Wait for 20 seconds - ACE_OS::sleep(ACE_Time_Value (0, 20000)); + std::this_thread::sleep_for(std::chrono::seconds(20)); } } } diff --git a/src/tools/mesh_extractor/DBC.cpp b/src/tools/mesh_extractor/DBC.cpp index 32672bf64..7665b80e5 100644 --- a/src/tools/mesh_extractor/DBC.cpp +++ b/src/tools/mesh_extractor/DBC.cpp @@ -8,7 +8,7 @@ #include "DBC.h" #include "Define.h" -DBC::DBC( FILE* stream ) : StringBlock(NULL), StringBlockSize(0), IsFaulty(true) +DBC::DBC( FILE* stream ) : StringBlock(nullptr), StringBlockSize(0), IsFaulty(true) { char magic[5]; uint32 count = 0; @@ -72,5 +72,5 @@ Record* DBC::GetRecordById( int id ) for (std::vector::iterator itr = Records.begin(); itr != Records.end(); ++itr) if ((*itr)->Values[0] == id) return *itr; - return NULL; + return nullptr; } diff --git a/src/tools/mesh_extractor/DoodadHandler.cpp b/src/tools/mesh_extractor/DoodadHandler.cpp index e3e07f5b8..37397e394 100644 --- a/src/tools/mesh_extractor/DoodadHandler.cpp +++ b/src/tools/mesh_extractor/DoodadHandler.cpp @@ -11,7 +11,7 @@ #include "G3D/Matrix4.h" DoodadHandler::DoodadHandler( ADT* adt ) : - ObjectDataHandler(adt), _definitions(NULL), _paths(NULL) + ObjectDataHandler(adt), _definitions(nullptr), _paths(nullptr) { Chunk* mddf = adt->ObjectData->GetChunkByName("MDDF"); if (mddf) diff --git a/src/tools/mesh_extractor/LiquidHandler.cpp b/src/tools/mesh_extractor/LiquidHandler.cpp index 96034b2d8..3af11e337 100644 --- a/src/tools/mesh_extractor/LiquidHandler.cpp +++ b/src/tools/mesh_extractor/LiquidHandler.cpp @@ -33,7 +33,7 @@ void LiquidHandler::HandleNewLiquid() if (h.LayerCount == 0) { // Need to fill in missing data with dummies. - MCNKData.push_back(MCNKLiquidData(NULL, H2ORenderMask())); + MCNKData.push_back(MCNKLiquidData(nullptr, H2ORenderMask())); continue; } fseek(stream, chunk->Offset + h.OffsetInformation, SEEK_SET); diff --git a/src/tools/mesh_extractor/MPQ.h b/src/tools/mesh_extractor/MPQ.h index 59e4dfd5e..b41896107 100644 --- a/src/tools/mesh_extractor/MPQ.h +++ b/src/tools/mesh_extractor/MPQ.h @@ -9,6 +9,7 @@ #include "libmpq/mpq.h" #include "Define.h" +#include "Errors.h" #include #include #include @@ -17,42 +18,44 @@ class MPQArchive { - -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 != NULL) && (counter < size)) { - //cout << token << endl; - token[strlen(token) - 1] = 0; - std::string s = token; - filelist.push_back(s); - counter += strlen(token) + 2; - token = strtok(NULL, seps); + + 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)) + { + //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; } - - delete[] buffer; - } }; class MPQFile diff --git a/src/tools/mesh_extractor/MPQManager.cpp b/src/tools/mesh_extractor/MPQManager.cpp index d67bd5e3b..5d766a7e4 100644 --- a/src/tools/mesh_extractor/MPQManager.cpp +++ b/src/tools/mesh_extractor/MPQManager.cpp @@ -8,7 +8,6 @@ #include "MPQ.h" #include "DBC.h" #include "Utils.h" -#include char const* MPQManager::Files[] = { "common.MPQ", @@ -39,7 +38,7 @@ void MPQManager::InitializeDBC() BaseLocale = -1; std::string fileName; uint32 size = sizeof(Languages) / sizeof(char*); - MPQArchive* _baseLocale = NULL; + MPQArchive* _baseLocale = nullptr; for (uint32 i = 0; i < size; ++i) { std::string _fileName = "Data/" + std::string(Languages[i]) + "/locale-" + std::string(Languages[i]) + ".MPQ"; @@ -72,10 +71,10 @@ void MPQManager::InitializeDBC() FILE* MPQManager::GetFile(const std::string& path ) { - ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL); + RETURN_GUAD(mutex, false); MPQFile file(path.c_str()); if (file.isEof()) - return NULL; + return nullptr; return file.GetFileStream(); } @@ -87,12 +86,12 @@ DBC* MPQManager::GetDBC(const std::string& name ) FILE* MPQManager::GetFileFrom(const std::string& path, MPQArchive* file ) { - ACE_GUARD_RETURN(ACE_Thread_Mutex, g, mutex, NULL); + RETURN_GUAD(mutex, false); mpq_archive* mpq_a = file->mpq_a; uint32_t filenum; if(libmpq__file_number(mpq_a, path.c_str(), &filenum)) - return NULL; + return nullptr; libmpq__off_t transferred; libmpq__off_t size = 0; @@ -100,7 +99,7 @@ FILE* MPQManager::GetFileFrom(const std::string& path, MPQArchive* file ) // HACK: in patch.mpq some files don't want to open and give 1 for filesize if (size <= 1) - return NULL; + return nullptr; uint8* buffer = new uint8[size]; diff --git a/src/tools/mesh_extractor/MPQManager.h b/src/tools/mesh_extractor/MPQManager.h index 8f86a5d39..2d5353b1f 100644 --- a/src/tools/mesh_extractor/MPQManager.h +++ b/src/tools/mesh_extractor/MPQManager.h @@ -8,7 +8,8 @@ #define MPQ_MANAGER_H #include "MPQ.h" -#include +#include "PolicyLock.h" +#include #include #include @@ -35,7 +36,7 @@ public: protected: void InitializeDBC(); private: - ACE_Thread_Mutex mutex; + std::mutex mutex; }; extern MPQManager* MPQHandler; diff --git a/src/tools/mesh_extractor/MeshExtractor.cpp b/src/tools/mesh_extractor/MeshExtractor.cpp index c8cbf71fd..d4d033f61 100644 --- a/src/tools/mesh_extractor/MeshExtractor.cpp +++ b/src/tools/mesh_extractor/MeshExtractor.cpp @@ -252,7 +252,7 @@ void ExtractGameobjectModels() bool HandleArgs(int argc, char** argv, uint32& threads, std::set& mapList, bool& debugOutput, uint32& extractFlags) { - char* param = NULL; + char* param = nullptr; extractFlags = 0; for (int i = 1; i < argc; ++i) @@ -277,7 +277,7 @@ bool HandleArgs(int argc, char** argv, uint32& threads, std::set& mapLis while (token) { mapList.insert(atoi(token)); - token = strtok(NULL, ","); + token = strtok(nullptr, ","); } free(copy); @@ -345,7 +345,7 @@ void LoadTile(dtNavMesh*& navMesh, const char* tile) if (fread(nav, header.size, 1, f) != 1) return; - navMesh->addTile(nav, header.size, DT_TILE_FREE_DATA, 0, NULL); + navMesh->addTile(nav, header.size, DT_TILE_FREE_DATA, 0, nullptr); fclose(f); } diff --git a/src/tools/mesh_extractor/TileBuilder.cpp b/src/tools/mesh_extractor/TileBuilder.cpp index a2c6a0594..308a5d567 100644 --- a/src/tools/mesh_extractor/TileBuilder.cpp +++ b/src/tools/mesh_extractor/TileBuilder.cpp @@ -17,10 +17,8 @@ #include "RecastAlloc.h" #include "DetourNavMeshBuilder.h" -#include - TileBuilder::TileBuilder(ContinentBuilder* _cBuilder, std::string world, int x, int y, uint32 mapId) : - World(world), X(x), Y(y), MapId(mapId), _Geometry(NULL), DataSize(0), cBuilder(_cBuilder) + World(world), X(x), Y(y), MapId(mapId), _Geometry(nullptr), DataSize(0), cBuilder(_cBuilder) { // Config for normal maps memset(&Config, 0, sizeof(rcConfig)); @@ -82,7 +80,7 @@ void TileBuilder::AddGeometry(WorldModelRoot* root, const WorldModelDefinition& uint8* TileBuilder::BuildInstance( dtNavMeshParams& navMeshParams ) { - float* bmin = NULL, *bmax = NULL; + float* bmin = nullptr, *bmax = nullptr; _Geometry->CalculateBoundingBox(bmin, bmax); @@ -186,7 +184,7 @@ uint8* TileBuilder::BuildInstance( dtNavMeshParams& navMeshParams ) printf("No polygons to build on tile, skipping.\n"); rcFreePolyMesh(pmesh); rcFreePolyMeshDetail(dmesh); - return NULL; + return nullptr; } int navDataSize; @@ -204,7 +202,7 @@ uint8* TileBuilder::BuildInstance( dtNavMeshParams& navMeshParams ) return navData; } - return NULL; + return nullptr; } uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) @@ -217,9 +215,9 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) delete adt; if (_Geometry->Vertices.empty() && _Geometry->Triangles.empty()) - return NULL; + return nullptr; - float* bmin = NULL, *bmax = NULL; + float* bmin = nullptr, *bmax = nullptr; CalculateTileBounds(bmin, bmax, navMeshParams); _Geometry->CalculateMinMaxHeight(bmin[1], bmax[1]); @@ -326,7 +324,7 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) params.buildBvTree = true; // Recalculate the bounds with the added geometry - float* bmin2 = NULL, *bmax2 = NULL; + float* bmin2 = nullptr, *bmax2 = nullptr; CalculateTileBounds(bmin2, bmax2, navMeshParams); bmin2[1] = bmin[1]; bmax2[1] = bmax[1]; @@ -354,7 +352,7 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) printf("[%02i, %02i] No polygons to build on tile, skipping.\n", X, Y); rcFreePolyMesh(pmesh); rcFreePolyMeshDetail(dmesh); - return NULL; + return nullptr; } int navDataSize; @@ -372,7 +370,7 @@ uint8* TileBuilder::BuildTiled(dtNavMeshParams& navMeshParams) return navData; } - return NULL; + return nullptr; } void TileBuilder::OutputDebugVertices() diff --git a/src/tools/mesh_extractor/Utils.cpp b/src/tools/mesh_extractor/Utils.cpp index 42c87501d..9eee704e2 100644 --- a/src/tools/mesh_extractor/Utils.cpp +++ b/src/tools/mesh_extractor/Utils.cpp @@ -525,7 +525,7 @@ char* Utils::GetPlainName(const char* FileName) { char* temp; - if((temp = (char*)strrchr(FileName, '\\')) != NULL) + if((temp = (char*)strrchr(FileName, '\\')) != nullptr) FileName = temp + 1; return (char*)FileName; } diff --git a/src/tools/mesh_extractor/Utils.h b/src/tools/mesh_extractor/Utils.h index 904ccdfaf..872a37f6d 100644 --- a/src/tools/mesh_extractor/Utils.h +++ b/src/tools/mesh_extractor/Utils.h @@ -16,13 +16,11 @@ #include "Define.h" #include "Constants.h" -#include - struct WorldModelDefinition; class DoodadDefinition; class DoodadInstance; -#define ASSERT(assertion) { if (!(assertion)) { ACE_Stack_Trace st; fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n%s\n", __FILE__, __LINE__, __FUNCTION__, #assertion, st.c_str()); *((volatile int*)NULL) = 0; } } +#define ASSERT(assertion) { if (!(assertion)) {fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n%s\n", __FILE__, __LINE__, __FUNCTION__, #assertion, st.c_str()); *((volatile int*)nullptr) = 0; } } struct Vector3 { diff --git a/src/tools/mesh_extractor/WDT.cpp b/src/tools/mesh_extractor/WDT.cpp index 1e31526c2..c77d0e726 100644 --- a/src/tools/mesh_extractor/WDT.cpp +++ b/src/tools/mesh_extractor/WDT.cpp @@ -10,7 +10,7 @@ #include "Utils.h" #include "WorldModelHandler.h" -WDT::WDT(std::string file) : IsGlobalModel(false), IsValid(false), Model(NULL) +WDT::WDT(std::string file) : IsGlobalModel(false), IsValid(false), Model(nullptr) { Data = new ChunkedData(file, 2); ReadTileTable(); diff --git a/src/tools/mesh_extractor/WorldModelGroup.cpp b/src/tools/mesh_extractor/WorldModelGroup.cpp index cb0289ce4..30806ab6f 100644 --- a/src/tools/mesh_extractor/WorldModelGroup.cpp +++ b/src/tools/mesh_extractor/WorldModelGroup.cpp @@ -9,7 +9,7 @@ #include "Chunk.h" #include "Utils.h" -WorldModelGroup::WorldModelGroup( std::string path, int groupIndex ) : GroupIndex(groupIndex), MOBA(NULL), IsBad(false), HasLiquidData(false) +WorldModelGroup::WorldModelGroup( std::string path, int groupIndex ) : GroupIndex(groupIndex), MOBA(nullptr), IsBad(false), HasLiquidData(false) { Data = new ChunkedData(path); if (!Data->Stream) diff --git a/src/tools/mesh_extractor/WorldModelHandler.cpp b/src/tools/mesh_extractor/WorldModelHandler.cpp index febd14822..9b998f54c 100644 --- a/src/tools/mesh_extractor/WorldModelHandler.cpp +++ b/src/tools/mesh_extractor/WorldModelHandler.cpp @@ -35,7 +35,7 @@ WorldModelDefinition WorldModelDefinition::Read( FILE* file ) } -WorldModelHandler::WorldModelHandler( ADT* adt ) : ObjectDataHandler(adt), _definitions(NULL), _paths(NULL) +WorldModelHandler::WorldModelHandler( ADT* adt ) : ObjectDataHandler(adt), _definitions(nullptr), _paths(nullptr) { ReadModelPaths(); ReadDefinitions(); diff --git a/src/tools/mmaps_generator/IntermediateValues.h b/src/tools/mmaps_generator/IntermediateValues.h index 37832f853..ae365f964 100644 --- a/src/tools/mmaps_generator/IntermediateValues.h +++ b/src/tools/mmaps_generator/IntermediateValues.h @@ -23,8 +23,8 @@ namespace MMAP rcPolyMesh* polyMesh; rcPolyMeshDetail* polyMeshDetail; - IntermediateValues() : heightfield(NULL), compactHeightfield(NULL), - contours(NULL), polyMesh(NULL), polyMeshDetail(NULL) {} + IntermediateValues() : heightfield(nullptr), compactHeightfield(nullptr), + contours(nullptr), polyMesh(nullptr), polyMeshDetail(nullptr) {} ~IntermediateValues(); void writeIV(uint32 mapID, uint32 tileX, uint32 tileY); diff --git a/src/tools/mmaps_generator/MapBuilder.cpp b/src/tools/mmaps_generator/MapBuilder.cpp index 7fa3363ce..3d07b06be 100644 --- a/src/tools/mmaps_generator/MapBuilder.cpp +++ b/src/tools/mmaps_generator/MapBuilder.cpp @@ -50,7 +50,7 @@ namespace MMAP MapBuilder::MapBuilder(float maxWalkableAngle, bool skipLiquid, bool skipContinents, bool skipJunkMaps, bool skipBattlegrounds, bool debugOutput, bool bigBaseUnit, const char* offMeshFilePath) : - m_terrainBuilder (NULL), + m_terrainBuilder (nullptr), m_debugOutput (debugOutput), m_offMeshFilePath (offMeshFilePath), m_skipContinents (skipContinents), @@ -58,7 +58,8 @@ namespace MMAP m_skipBattlegrounds (skipBattlegrounds), m_maxWalkableAngle (maxWalkableAngle), m_bigBaseUnit (bigBaseUnit), - m_rcContext (NULL) + m_rcContext (nullptr), + _cancelationToken (false) { m_terrainBuilder = new TerrainBuilder(skipLiquid); @@ -88,14 +89,14 @@ namespace MMAP void MapBuilder::discoverTiles() { std::vector files; - uint32 mapID, tileX, tileY, tileID, count = 0, fsize = 0; + uint32 mapID, tileX, tileY, tileID, count = 0; char filter[12]; printf("Discovering maps... "); getDirContents(files, "maps"); for (uint32 i = 0; i < files.size(); ++i) { - mapID = uint32(atoi(files[i].substr(0, files[i].size() - 8).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)); @@ -107,7 +108,7 @@ namespace MMAP getDirContents(files, "vmaps", "*.vmtree"); for (uint32 i = 0; i < files.size(); ++i) { - mapID = uint32(atoi(files[i].substr(0, files[i].size() - 7).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)); @@ -128,10 +129,8 @@ namespace MMAP getDirContents(files, "vmaps", filter); for (uint32 i = 0; i < files.size(); ++i) { - fsize = files[i].size(); - - tileY = uint32(atoi(files[i].substr(fsize - 12, 2).c_str())); - tileX = uint32(atoi(files[i].substr(fsize - 9, 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); @@ -143,20 +142,36 @@ namespace MMAP getDirContents(files, "maps", filter); for (uint32 i = 0; i < files.size(); ++i) { - fsize = files[i].size(); - - tileY = uint32(atoi(files[i].substr(fsize - 8, 2).c_str())); - tileX = uint32(atoi(files[i].substr(fsize - 6, 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) count++; } + + // make sure we process maps which don't have tiles + if (tiles->empty()) + { + // convert coord bounds to grid bounds + uint32 minX, minY, maxX, maxY; + getGridBounds(mapID, minX, minY, maxX, maxY); + + // add all tiles within bounds to tile list. + for (uint32 i = minX; i <= maxX; ++i) + for (uint32 j = minY; j <= maxY; ++j) + if (tiles->insert(StaticMapTree::packTileID(i, j)).second) + count++; + } } printf("found %u.\n\n", count); - // percentageDone - total tiles to process - m_totalTiles = count; + // Calculate tiles to process in total + for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) + { + if (!shouldSkipMap(it->m_mapId)) + m_totalTiles += it->m_tiles->size(); + } } /**************************************************************************/ @@ -172,11 +187,14 @@ namespace MMAP } /**************************************************************************/ - void MapBuilder::buildAllMaps(int threads) + void MapBuilder::buildAllMaps(unsigned int threads) { - std::vector _threads; + printf("Using %u threads to extract mmaps\n", threads); - BuilderThreadPool* pool = threads > 0 ? new BuilderThreadPool() : NULL; + for (unsigned int i = 0; i < threads; ++i) + { + _workerThreads.push_back(std::thread(&MapBuilder::WorkerThread, this)); + } m_tiles.sort([](MapTiles a, MapTiles b) { @@ -185,27 +203,29 @@ namespace MMAP for (TileList::iterator it = m_tiles.begin(); it != m_tiles.end(); ++it) { - uint32 mapID = it->m_mapId; - if (!shouldSkipMap(mapID)) + uint32 mapId = it->m_mapId; + if (!shouldSkipMap(mapId)) { if (threads > 0) - pool->Enqueue(new MapBuildRequest(mapID)); + _queue.Push(mapId); else - buildMap(mapID); + buildMap(mapId); } } - for (int i = 0; i < threads; ++i) - _threads.push_back(new BuilderThread(this, pool->Queue())); - - // Free memory - for (std::vector::iterator _th = _threads.begin(); _th != _threads.end(); ++_th) + while (!_queue.Empty()) { - (*_th)->wait(); - delete *_th; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } - delete pool; + _cancelationToken = true; + + _queue.Cancel(); + + for (auto& thread : _workerThreads) + { + thread.join(); + } } /**************************************************************************/ @@ -277,7 +297,7 @@ namespace MMAP return; } - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapId, navMesh); if (!navMesh) { @@ -341,7 +361,7 @@ namespace MMAP /**************************************************************************/ void MapBuilder::buildSingleTile(uint32 mapID, uint32 tileX, uint32 tileY) { - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapID, navMesh); if (!navMesh) { @@ -353,13 +373,24 @@ namespace MMAP dtFreeNavMesh(navMesh); } + void MapBuilder::WorkerThread() + { + while (1) + { + uint32 mapId = 0; + + _queue.WaitAndPop(mapId); + + if (_cancelationToken) + return; + + buildMap(mapId); + } + } + /**************************************************************************/ void MapBuilder::buildMap(uint32 mapID) { -#ifndef __APPLE__ - //printf("[Thread %u] Building map %03u:\n", uint32(ACE_Thread::self()), mapID); -#endif - std::set* tiles = getTileList(mapID); // make sure we process maps which don't have tiles @@ -378,7 +409,7 @@ namespace MMAP if (!tiles->empty()) { // build navMesh - dtNavMesh* navMesh = NULL; + dtNavMesh* navMesh = nullptr; buildNavMesh(mapID, navMesh); if (!navMesh) { @@ -485,7 +516,7 @@ namespace MMAP // use Max because '32 - tileX' is negative for values over 32 float bmin[3], bmax[3]; - getTileBounds(tileXMax, tileYMax, NULL, 0, bmin, bmax); + getTileBounds(tileXMax, tileYMax, nullptr, 0, bmin, bmax); /*** now create the navmesh ***/ @@ -683,11 +714,11 @@ namespace MMAP // we may want to keep them in the future for debug // but right now, we don't have the code to merge them rcFreeHeightField(tile.solid); - tile.solid = NULL; + tile.solid = nullptr; rcFreeCompactHeightfield(tile.chf); - tile.chf = NULL; + tile.chf = nullptr; rcFreeContourSet(tile.cset); - tile.cset = NULL; + tile.cset = nullptr; pmmerge[nmerge] = tile.pmesh; dmmerge[nmerge] = tile.dmesh; @@ -764,7 +795,7 @@ namespace MMAP params.buildBvTree = true; // will hold final navmesh - unsigned char* navData = NULL; + unsigned char* navData = nullptr; int navDataSize = 0; do @@ -832,7 +863,7 @@ namespace MMAP char message[1024]; sprintf(message, "[Map %03i] Failed to open %s for writing!\n", mapID, fileName); perror(message); - navMesh->removeTile(tileRef, NULL, NULL); + navMesh->removeTile(tileRef, nullptr, nullptr); break; } @@ -849,7 +880,7 @@ namespace MMAP fclose(file); // now that tile is written to disk, we can unload it - navMesh->removeTile(tileRef, NULL, NULL); + navMesh->removeTile(tileRef, nullptr, nullptr); } while (0); diff --git a/src/tools/mmaps_generator/MapBuilder.h b/src/tools/mmaps_generator/MapBuilder.h index 877102af7..b40a12565 100644 --- a/src/tools/mmaps_generator/MapBuilder.h +++ b/src/tools/mmaps_generator/MapBuilder.h @@ -7,31 +7,27 @@ #ifndef _MAP_BUILDER_H #define _MAP_BUILDER_H +#include #include #include #include #include -#include +#include #include "TerrainBuilder.h" #include "IntermediateValues.h" #include "Recast.h" #include "DetourNavMesh.h" - -#include -#include -#include +#include "PCQueue.h" using namespace VMAP; -// G3D namespace typedefs conflicts with ACE typedefs - namespace MMAP { struct MapTiles { - MapTiles() : m_mapId(uint32(-1)), m_tiles(NULL) {} + MapTiles() : m_mapId(uint32(-1)), m_tiles(nullptr) {} MapTiles(uint32 id, std::set* tiles) : m_mapId(id), m_tiles(tiles) {} ~MapTiles() {} @@ -49,7 +45,7 @@ namespace MMAP struct Tile { - Tile() : chf(NULL), solid(NULL), cset(NULL), pmesh(NULL), dmesh(NULL) {} + Tile() : chf(nullptr), solid(nullptr), cset(nullptr), pmesh(nullptr), dmesh(nullptr) {} ~Tile() { rcFreeCompactHeightfield(chf); @@ -75,7 +71,7 @@ namespace MMAP bool skipBattlegrounds = false, bool debugOutput = false, bool bigBaseUnit = false, - const char* offMeshFilePath = NULL); + const char* offMeshFilePath = nullptr); ~MapBuilder(); @@ -87,7 +83,9 @@ namespace MMAP 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(int threads); + void buildAllMaps(unsigned int threads); + + void WorkerThread(); private: // detect maps and tiles @@ -131,68 +129,15 @@ namespace MMAP float m_maxWalkableAngle; bool m_bigBaseUnit; // percentageDone - variables to calculate percentage - uint32 m_totalTiles; + std::atomic m_totalTiles; std::atomic m_totalTilesBuilt; // build performance - not really used for now rcContext* m_rcContext; - }; - class MapBuildRequest : public ACE_Method_Request - { - public: - MapBuildRequest(uint32 mapId) : _mapId(mapId) {} - - virtual int call() - { - /// @ Actually a creative way of unabstracting the class and returning a member variable - return (int)_mapId; - } - - private: - uint32 _mapId; - }; - - class BuilderThread : public ACE_Task_Base - { - private: - MapBuilder* _builder; - ACE_Activation_Queue* _queue; - - public: - BuilderThread(MapBuilder* builder, ACE_Activation_Queue* queue) : _builder(builder), _queue(queue) { activate(); } - - int svc() - { - /// @ Set a timeout for dequeue attempts (only used when the queue is empty) as it will never get populated after thread starts - ACE_Time_Value timeout(5); - ACE_Method_Request* request = NULL; - while ((request = _queue->dequeue(&timeout)) != NULL) - { - _builder->buildMap(request->call()); - delete request; - request = NULL; - } - - return 0; - } - }; - - class BuilderThreadPool - { - public: - BuilderThreadPool() : _queue(new ACE_Activation_Queue()) {} - ~BuilderThreadPool() { _queue->queue()->close(); delete _queue; } - - void Enqueue(MapBuildRequest* request) - { - _queue->enqueue(request); - } - - ACE_Activation_Queue* Queue() { return _queue; } - - private: - ACE_Activation_Queue* _queue; + 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 e3f23b1a7..19c91ed82 100644 --- a/src/tools/mmaps_generator/PathCommon.h +++ b/src/tools/mmaps_generator/PathCommon.h @@ -106,7 +106,7 @@ namespace MMAP while (dirp) { errno = 0; - if ((dp = readdir(dirp)) != NULL) + if ((dp = readdir(dirp)) != nullptr) { if (matchWildcardFilter(filter.c_str(), dp->d_name)) fileList.push_back(std::string(dp->d_name)); diff --git a/src/tools/mmaps_generator/PathGenerator.cpp b/src/tools/mmaps_generator/PathGenerator.cpp index 1ce6137fc..87ad3dcc7 100644 --- a/src/tools/mmaps_generator/PathGenerator.cpp +++ b/src/tools/mmaps_generator/PathGenerator.cpp @@ -61,9 +61,9 @@ bool handleArgs(int argc, char** argv, bool &bigBaseUnit, char* &offMeshInputPath, char* &file, - int& threads) + unsigned int& threads) { - char* param = NULL; + char* param = nullptr; for (int i = 1; i < argc; ++i) { if (strcmp(argv[i], "--maxAngle") == 0) @@ -83,8 +83,7 @@ bool handleArgs(int argc, char** argv, param = argv[++i]; if (!param) return false; - threads = atoi(param); - printf("Using %i threads to extract mmaps\n", threads); + threads = static_cast(std::max(0, atoi(param))); } else if (strcmp(argv[i], "--file") == 0) { @@ -100,7 +99,7 @@ bool handleArgs(int argc, char** argv, return false; char* stileX = strtok(param, ","); - char* stileY = strtok(NULL, ","); + char* stileY = strtok(nullptr, ","); int tilex = atoi(stileX); int tiley = atoi(stileY); @@ -230,7 +229,8 @@ int finish(const char* message, int returnValue) int main(int argc, char** argv) { - int threads = 3, mapnum = -1; + unsigned int threads = std::thread::hardware_concurrency(); + int mapnum = -1; float maxAngle = 70.0f; int tileX = -1, tileY = -1; bool skipLiquid = false, @@ -240,8 +240,8 @@ int main(int argc, char** argv) debugOutput = false, silent = false, bigBaseUnit = false; - char* offMeshInputPath = NULL; - char* file = NULL; + char* offMeshInputPath = nullptr; + char* file = nullptr; bool validParam = handleArgs(argc, argv, mapnum, tileX, tileY, maxAngle, diff --git a/src/tools/mmaps_generator/TerrainBuilder.cpp b/src/tools/mmaps_generator/TerrainBuilder.cpp index 017eefc61..843e89bc8 100644 --- a/src/tools/mmaps_generator/TerrainBuilder.cpp +++ b/src/tools/mmaps_generator/TerrainBuilder.cpp @@ -270,7 +270,7 @@ namespace MMAP printf("TerrainBuilder::loadMap: Failed to read some data expected 1, read 0\n"); - float* liquid_map = NULL; + float* liquid_map = nullptr; if (!(lheader.flags & MAP_LIQUID_NO_TYPE)) if (fread(liquid_type, sizeof(liquid_type), 1, mapFile) != 1) @@ -363,7 +363,7 @@ namespace MMAP // make a copy of liquid vertices // used to pad right-bottom frame due to lost vertex data at extraction - float* lverts_copy = NULL; + float* lverts_copy = nullptr; if (meshData.liquidVerts.size()) { lverts_copy = new float[meshData.liquidVerts.size()]; @@ -636,7 +636,7 @@ namespace MMAP if (!instanceTrees[mapID]) break; - ModelInstance* models = NULL; + ModelInstance* models = nullptr; uint32 count = 0; instanceTrees[mapID]->getModelInstances(models, count); @@ -673,7 +673,7 @@ namespace MMAP std::vector tempVertices; std::vector transformedVertices; std::vector tempTriangles; - WmoLiquid* liquid = NULL; + WmoLiquid* liquid = nullptr; it->getMeshData(tempVertices, tempTriangles, liquid); @@ -884,7 +884,7 @@ namespace MMAP void TerrainBuilder::loadOffMeshConnections(uint32 mapID, uint32 tileX, uint32 tileY, MeshData &meshData, const char* offMeshFilePath) { // no meshfile input given? - if (offMeshFilePath == NULL) + if (offMeshFilePath == nullptr) return; FILE* fp = fopen(offMeshFilePath, "rb"); diff --git a/src/tools/vmap4_extractor/adtfile.cpp b/src/tools/vmap4_extractor/adtfile.cpp index 748b1c374..11bc828e3 100644 --- a/src/tools/vmap4_extractor/adtfile.cpp +++ b/src/tools/vmap4_extractor/adtfile.cpp @@ -18,7 +18,7 @@ char const* GetPlainName(char const* FileName) { const char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } @@ -27,7 +27,7 @@ char* GetPlainName(char* FileName) { char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } @@ -59,10 +59,10 @@ char* GetExtension(char* FileName) { if (char* szTemp = strrchr(FileName, '.')) return szTemp; - return NULL; + return nullptr; } -ADTFile::ADTFile(char* filename): ADT(filename), nWMO(0), nMDX(0), WmoInstansName(NULL), ModelInstansName(NULL) +ADTFile::ADTFile(char* filename): ADT(filename), nWMO(0), nMDX(0), WmoInstansName(nullptr), ModelInstansName(nullptr) { Adtfilename.append(filename); } diff --git a/src/tools/vmap4_extractor/dbcfile.cpp b/src/tools/vmap4_extractor/dbcfile.cpp index 2ee2b3de5..b79bd5f7a 100644 --- a/src/tools/vmap4_extractor/dbcfile.cpp +++ b/src/tools/vmap4_extractor/dbcfile.cpp @@ -12,7 +12,7 @@ #include DBCFile::DBCFile(const std::string& filename): - filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(NULL), stringTable(NULL) + filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(nullptr), stringTable(nullptr) { } @@ -34,7 +34,7 @@ bool DBCFile::open() if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3] != 'C') { f.close(); - data = NULL; + data = nullptr; printf("Critical Error: An error occured while trying to read the DBCFile %s.", filename.c_str()); return false; } diff --git a/src/tools/vmap4_extractor/model.h b/src/tools/vmap4_extractor/model.h index b403129c6..a43320133 100644 --- a/src/tools/vmap4_extractor/model.h +++ b/src/tools/vmap4_extractor/model.h @@ -23,8 +23,8 @@ private: { delete[] vertices; delete[] indices; - vertices = NULL; - indices = NULL; + vertices = nullptr; + indices = nullptr; } std::string filename; public: diff --git a/src/tools/vmap4_extractor/mpq_libmpq04.h b/src/tools/vmap4_extractor/mpq_libmpq04.h index 80041b16d..d0262842a 100644 --- a/src/tools/vmap4_extractor/mpq_libmpq04.h +++ b/src/tools/vmap4_extractor/mpq_libmpq04.h @@ -42,13 +42,13 @@ public: token = strtok( buffer, seps ); uint32 counter = 0; - while ((token != NULL) && (counter < size)) { + while ((token != nullptr) && (counter < size)) { //cout << token << endl; token[strlen(token) - 1] = 0; string s = token; filelist.push_back(s); counter += strlen(token) + 2; - token = strtok(NULL, seps); + token = strtok(nullptr, seps); } delete[] buffer; diff --git a/src/tools/vmap4_extractor/vmapexport.cpp b/src/tools/vmap4_extractor/vmapexport.cpp index be189bd9c..e0933b2f5 100644 --- a/src/tools/vmap4_extractor/vmapexport.cpp +++ b/src/tools/vmap4_extractor/vmapexport.cpp @@ -148,7 +148,7 @@ bool ExtractSingleWmo(std::string& fname) int p = 0; // Select root wmo files char const* rchr = strrchr(plain_name, '_'); - if (rchr != NULL) + if (rchr != nullptr) { char cpy[4]; memcpy(cpy, rchr, 4); diff --git a/src/tools/vmap4_extractor/wdtfile.cpp b/src/tools/vmap4_extractor/wdtfile.cpp index a79bec03c..72710750c 100644 --- a/src/tools/vmap4_extractor/wdtfile.cpp +++ b/src/tools/vmap4_extractor/wdtfile.cpp @@ -13,12 +13,12 @@ char * wdtGetPlainName(char * FileName) { char * szTemp; - if((szTemp = strrchr(FileName, '\\')) != NULL) + if((szTemp = strrchr(FileName, '\\')) != nullptr) FileName = szTemp + 1; return FileName; } -WDTFile::WDTFile(char* file_name, char* file_name1) : WDT(file_name), gWmoInstansName(NULL), gnWMO(0) +WDTFile::WDTFile(char* file_name, char* file_name1) : WDT(file_name), gWmoInstansName(nullptr), gnWMO(0) { filename.append(file_name1,strlen(file_name1)); } @@ -109,7 +109,7 @@ WDTFile::~WDTFile(void) ADTFile* WDTFile::GetMap(int x, int z) { if(!(x>=0 && z >= 0 && x<64 && z<64)) - return NULL; + return nullptr; char name[512]; diff --git a/src/tools/vmap4_extractor/wmo.cpp b/src/tools/vmap4_extractor/wmo.cpp index 90fd9e4d4..3e6f3cb40 100644 --- a/src/tools/vmap4_extractor/wmo.cpp +++ b/src/tools/vmap4_extractor/wmo.cpp @@ -473,7 +473,7 @@ WMOGroup::~WMOGroup() } WMOInstance::WMOInstance(MPQFile& f, char const* WmoInstName, uint32 mapID, uint32 tileX, uint32 tileY, FILE* pDirfile) - : currx(0), curry(0), wmo(NULL), doodadset(0), pos(), indx(0), id(0), d2(0), d3(0) + : currx(0), curry(0), wmo(nullptr), doodadset(0), pos(), indx(0), id(0), d2(0), d3(0) { float ff[3]; f.read(&id, 4);