diff options
author | DDuarte <dnpd.dd@gmail.com> | 2014-01-10 18:32:05 +0000 |
---|---|---|
committer | DDuarte <dnpd.dd@gmail.com> | 2014-01-10 18:32:05 +0000 |
commit | 33c2bd5ce1f4f8d20981e9f7aea90e37de0abbda (patch) | |
tree | 823ad5570f27e923c77203660ee7cc12e26182ec /src/server/collision/Management/MMapManager.cpp | |
parent | 352a2682b1d531c83bd2b80704233677448e99de (diff) | |
parent | a63780fd90701ed81a0a5f2030e82ab1f6927ab4 (diff) |
Merge branch 'master' into 4.3.4
Conflicts:
src/server/game/Entities/Creature/Creature.cpp
src/server/game/Entities/Creature/Creature.h
src/server/game/Entities/Creature/GossipDef.cpp
src/server/game/Entities/Player/Player.cpp
src/server/game/Entities/Transport/Transport.cpp
src/server/game/Entities/Unit/Unit.cpp
src/server/game/Globals/ObjectMgr.cpp
src/server/game/Globals/ObjectMgr.h
src/server/game/Handlers/QuestHandler.cpp
src/server/game/Handlers/SpellHandler.cpp
src/server/game/Handlers/TradeHandler.cpp
src/server/game/Quests/QuestDef.h
src/server/game/Spells/Auras/SpellAuraEffects.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_akilzon.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_halazzi.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_hexlord.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_janalai.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_nalorakk.cpp
src/server/scripts/EasternKingdoms/ZulAman/boss_zuljin.cpp
src/server/scripts/EasternKingdoms/ZulAman/zulaman.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_arlokk.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_hakkar.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_jeklik.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_jindo.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_mandokir.cpp
src/server/scripts/EasternKingdoms/ZulGurub/boss_thekal.cpp
src/server/scripts/EasternKingdoms/zone_arathi_highlands.cpp
src/server/scripts/EasternKingdoms/zone_burning_steppes.cpp
src/server/scripts/EasternKingdoms/zone_ghostlands.cpp
src/server/scripts/EasternKingdoms/zone_hinterlands.cpp
src/server/scripts/EasternKingdoms/zone_redridge_mountains.cpp
src/server/scripts/EasternKingdoms/zone_swamp_of_sorrows.cpp
src/server/scripts/Kalimdor/zone_azshara.cpp
src/server/scripts/Kalimdor/zone_darkshore.cpp
src/server/scripts/Kalimdor/zone_desolace.cpp
src/server/scripts/Northrend/zone_dalaran.cpp
src/tools/CMakeLists.txt
Diffstat (limited to 'src/server/collision/Management/MMapManager.cpp')
-rw-r--r-- | src/server/collision/Management/MMapManager.cpp | 175 |
1 files changed, 82 insertions, 93 deletions
diff --git a/src/server/collision/Management/MMapManager.cpp b/src/server/collision/Management/MMapManager.cpp index 4e6b3bb6d10..c29d6fa4b56 100644 --- a/src/server/collision/Management/MMapManager.cpp +++ b/src/server/collision/Management/MMapManager.cpp @@ -22,32 +22,29 @@ namespace MMAP { - // ######################## MMapManager ######################## MMapManager::~MMapManager() { - for (MMapDataSet::iterator i = loadedMMaps.begin(); i != loadedMMaps.end(); ++i) + for (MMapDataSet::iterator i = _loadedMaps.begin(); i != _loadedMaps.end(); ++i) delete i->second; - - // by now we should not have maps loaded - // if we had, tiles in MMapData->mmapLoadedTiles, their actual data is lost! } - bool MMapManager::loadMapData(uint32 mapId) + bool MMapManager::LoadMap(uint32 mapId) { - // we already have this map loaded? - if (loadedMMaps.find(mapId) != loadedMMaps.end()) + // Do not load a map twice. + if (_loadedMaps.find(mapId) != _loadedMaps.end()) return true; // load and init dtNavMesh - read parameters from file - uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i.mmap")+1; - char *fileName = new char[pathLen]; - snprintf(fileName, pathLen, (sWorld->GetDataPath()+"mmaps/%03i.mmap").c_str(), mapId); + std::string basePath = sWorld->GetDataPath(); + uint32 pathLen = basePath.length() + strlen("mmaps/%03i.mmap") + 1; + char* fileName = new char[pathLen]; + snprintf(fileName, pathLen, (basePath + "mmaps/%03i.mmap").c_str(), mapId); FILE* file = fopen(fileName, "rb"); if (!file) { - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not open mmap file '%s'", fileName); - delete [] fileName; + TC_LOG_DEBUG("maps", "MMAP::LoadMap: Error: Could not open mmap file '%s'", fileName); + delete[] fileName; return false; } @@ -56,80 +53,75 @@ namespace MMAP fclose(file); if (count != 1) { - TC_LOG_DEBUG("maps", "MMAP:loadMapData: Error: Could not read params from file '%s'", fileName); - delete [] fileName; + TC_LOG_DEBUG("maps", "MMAP::LoadMap: Error: Could not read params from file '%s'", fileName); + delete[] fileName; return false; } dtNavMesh* mesh = dtAllocNavMesh(); - ASSERT(mesh); if (dtStatusFailed(mesh->init(¶ms))) { dtFreeNavMesh(mesh); - TC_LOG_ERROR("maps", "MMAP:loadMapData: Failed to initialize dtNavMesh for mmap %03u from file %s", mapId, fileName); - delete [] fileName; + TC_LOG_ERROR("maps", "MMAP::LoadMap: Failed to initialize dtNavMesh for mmap %03u from file %s", mapId, fileName); + delete[] fileName; return false; } - delete [] fileName; + delete[] fileName; - TC_LOG_INFO("maps", "MMAP:loadMapData: Loaded %03i.mmap", mapId); + TC_LOG_INFO("maps", "MMAP::LoadMap: Loaded %03i.mmap", mapId); // store inside our map list - MMapData* mmap_data = new MMapData(mesh); - mmap_data->mmapLoadedTiles.clear(); + MMapData* mmapData = new MMapData(mesh); + mmapData->_loadedTiles.clear(); - loadedMMaps.insert(std::pair<uint32, MMapData*>(mapId, mmap_data)); + _loadedMaps.insert(std::pair<uint32, MMapData*>(mapId, mmapData)); return true; } - uint32 MMapManager::packTileID(int32 x, int32 y) - { - return uint32(x << 16 | y); - } - - bool MMapManager::loadMap(const std::string& /*basePath*/, uint32 mapId, int32 x, int32 y) + bool MMapManager::LoadMapTile(uint32 mapId, int32 x, int32 y) { // make sure the mmap is loaded and ready to load tiles - if (!loadMapData(mapId)) + if (!LoadMap(mapId)) return false; // get this mmap data - MMapData* mmap = loadedMMaps[mapId]; + MMapData* mmap = _loadedMaps[mapId]; ASSERT(mmap->navMesh); - // check if we already have this tile loaded - uint32 packedGridPos = packTileID(x, y); - if (mmap->mmapLoadedTiles.find(packedGridPos) != mmap->mmapLoadedTiles.end()) + // Check if we already have this tile loaded + uint32 pos = PackTileId(x, y); + if (mmap->_loadedTiles.find(pos) != mmap->_loadedTiles.end()) return false; - // load this tile :: mmaps/MMMXXYY.mmtile - uint32 pathLen = sWorld->GetDataPath().length() + strlen("mmaps/%03i%02i%02i.mmtile")+1; - char *fileName = new char[pathLen]; + std::string basePath = sWorld->GetDataPath(); + uint32 pathLen = basePath.length() + strlen("mmaps/%03i%02i%02i.mmtile") + 1; + char* fileName = new char[pathLen]; - snprintf(fileName, pathLen, (sWorld->GetDataPath()+"mmaps/%03i%02i%02i.mmtile").c_str(), mapId, x, y); + snprintf(fileName, pathLen, (basePath + "mmaps/%03i%02i%02i.mmtile").c_str(), mapId, x, y); FILE* file = fopen(fileName, "rb"); if (!file) { - TC_LOG_DEBUG("maps", "MMAP:loadMap: Could not open mmtile file '%s'", fileName); - delete [] fileName; + TC_LOG_DEBUG("maps", "MMAP::LoadMapTile: Could not open mmtile file '%s'", fileName); + delete[] fileName; return false; } - delete [] fileName; + + delete[] fileName; // read header MmapTileHeader fileHeader; if (fread(&fileHeader, sizeof(MmapTileHeader), 1, file) != 1 || fileHeader.mmapMagic != MMAP_MAGIC) { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header in mmap %03u%02i%02i.mmtile", mapId, x, y); + TC_LOG_ERROR("maps", "MMAP::LoadMapTile: Bad header in mmap %03u%02i%02i.mmtile", mapId, x, y); fclose(file); return false; } if (fileHeader.mmapVersion != MMAP_VERSION) { - TC_LOG_ERROR("maps", "MMAP:loadMap: %03u%02i%02i.mmtile was built with generator v%i, expected v%i", + TC_LOG_ERROR("maps", "MMAP::LoadMapTile: %03u%02i%02i.mmtile was built with generator v%i, expected v%i", mapId, x, y, fileHeader.mmapVersion, MMAP_VERSION); fclose(file); return false; @@ -139,9 +131,9 @@ namespace MMAP ASSERT(data); size_t result = fread(data, fileHeader.size, 1, file); - if (!result) + if (result != 1) { - TC_LOG_ERROR("maps", "MMAP:loadMap: Bad header or data in mmap %03u%02i%02i.mmtile", mapId, x, y); + TC_LOG_ERROR("maps", "MMAP::LoadMapTile: Bad header or data in mmap %03u%02i%02i.mmtile", mapId, x, y); fclose(file); return false; } @@ -154,14 +146,14 @@ namespace MMAP // memory allocated for data is now managed by detour, and will be deallocated when the tile is removed if (dtStatusSucceed(mmap->navMesh->addTile(data, fileHeader.size, DT_TILE_FREE_DATA, 0, &tileRef))) { - mmap->mmapLoadedTiles.insert(std::pair<uint32, dtTileRef>(packedGridPos, tileRef)); - ++loadedTiles; - TC_LOG_INFO("maps", "MMAP:loadMap: Loaded mmtile %03i[%02i, %02i] into %03i[%02i, %02i]", mapId, x, y, mapId, header->x, header->y); + mmap->_loadedTiles.insert(std::pair<uint32, dtTileRef>(pos, tileRef)); + ++_loadedTiles; + TC_LOG_INFO("maps", "MMAP::LoadMapTile: Loaded mmtile %03i[%02i, %02i] into %03i[%02i, %02i]", mapId, x, y, mapId, header->x, header->y); return true; } else { - TC_LOG_ERROR("maps", "MMAP:loadMap: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y); + TC_LOG_ERROR("maps", "MMAP::LoadMapTile: Could not load %03u%02i%02i.mmtile into navmesh", mapId, x, y); dtFree(data); return false; } @@ -169,28 +161,26 @@ namespace MMAP return false; } - bool MMapManager::unloadMap(uint32 mapId, int32 x, int32 y) + bool MMapManager::UnloadMapTile(uint32 mapId, int32 x, int32 y) { - // check if we have this map loaded - if (loadedMMaps.find(mapId) == loadedMMaps.end()) + // Do not attempt to remove tiles from a not-loaded map + if (_loadedMaps.find(mapId) == _loadedMaps.end()) { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map. %03u%02i%02i.mmtile", mapId, x, y); + TC_LOG_DEBUG("maps", "MMAP::UnloadMapTile: Asked to unload not loaded navmesh map. %03u%02i%02i.mmtile", mapId, x, y); return false; } - MMapData* mmap = loadedMMaps[mapId]; + MMapData* mmap = _loadedMaps[mapId]; // check if we have this tile loaded - uint32 packedGridPos = packTileID(x, y); - if (mmap->mmapLoadedTiles.find(packedGridPos) == mmap->mmapLoadedTiles.end()) + uint32 pos = PackTileId(x, y); + if (mmap->_loadedTiles.find(pos) == mmap->_loadedTiles.end()) { - // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh tile. %03u%02i%02i.mmtile", mapId, x, y); + TC_LOG_DEBUG("maps", "MMAP::UnloadMapTile: Asked to unload not loaded navmesh tile. %03u%02i%02i.mmtile", mapId, x, y); return false; } - dtTileRef tileRef = mmap->mmapLoadedTiles[packedGridPos]; + dtTileRef tileRef = mmap->_loadedTiles[pos]; // unload, and mark as non loaded if (dtStatusFailed(mmap->navMesh->removeTile(tileRef, NULL, NULL))) @@ -198,107 +188,106 @@ namespace MMAP // this is technically a memory leak // if the grid is later reloaded, dtNavMesh::addTile will return error but no extra memory is used // we cannot recover from this error - assert out - TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y); + TC_LOG_ERROR("maps", "MMAP::UnloadMapTile: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y); ASSERT(false); } else { - mmap->mmapLoadedTiles.erase(packedGridPos); - --loadedTiles; - TC_LOG_INFO("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i, %02i] from %03i", mapId, x, y, mapId); + mmap->_loadedTiles.erase(pos); + --_loadedTiles; + TC_LOG_INFO("maps", "MMAP::UnloadMapTile: Unloaded mmtile [%02i, %02i] from %03i", x, y, mapId); return true; } return false; } - bool MMapManager::unloadMap(uint32 mapId) + bool MMapManager::UnloadMap(uint32 mapId) { - if (loadedMMaps.find(mapId) == loadedMMaps.end()) + if (_loadedMaps.find(mapId) == _loadedMaps.end()) { // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMap: Asked to unload not loaded navmesh map %03u", mapId); + TC_LOG_DEBUG("maps", "MMAP::UnloadMap: Asked to unload not loaded navmesh map %03u", mapId); return false; } // unload all tiles from given map - MMapData* mmap = loadedMMaps[mapId]; - for (MMapTileSet::iterator i = mmap->mmapLoadedTiles.begin(); i != mmap->mmapLoadedTiles.end(); ++i) + MMapData* mmap = _loadedMaps[mapId]; + for (MMapTileSet::iterator i = mmap->_loadedTiles.begin(); i != mmap->_loadedTiles.end(); ++i) { uint32 x = (i->first >> 16); uint32 y = (i->first & 0x0000FFFF); if (dtStatusFailed(mmap->navMesh->removeTile(i->second, NULL, NULL))) - TC_LOG_ERROR("maps", "MMAP:unloadMap: Could not unload %03u%02i%02i.mmtile from navmesh", mapId, x, y); + TC_LOG_ERROR("maps", "MMAP::UnloadMap: Could not unload %03u%02u%02u.mmtile from navmesh", mapId, x, y); else { - --loadedTiles; - TC_LOG_INFO("maps", "MMAP:unloadMap: Unloaded mmtile %03i[%02i, %02i] from %03i", mapId, x, y, mapId); + --_loadedTiles; + TC_LOG_INFO("maps", "MMAP::UnloadMap: Unloaded mmtile [%02u, %02u] from %03u", x, y, mapId); } } delete mmap; - loadedMMaps.erase(mapId); - TC_LOG_INFO("maps", "MMAP:unloadMap: Unloaded %03i.mmap", mapId); + _loadedMaps.erase(mapId); + TC_LOG_INFO("maps", "MMAP::UnloadMap: Unloaded %03u.mmap", mapId); return true; } - bool MMapManager::unloadMapInstance(uint32 mapId, uint32 instanceId) + bool MMapManager::UnloadMapInstance(uint32 mapId, uint32 instanceId) { // check if we have this map loaded - if (loadedMMaps.find(mapId) == loadedMMaps.end()) + if (_loadedMaps.find(mapId) == _loadedMaps.end()) { // file may not exist, therefore not loaded - TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded navmesh map %03u", mapId); + TC_LOG_DEBUG("maps", "MMAP::UnloadMapInstance: Asked to unload not loaded navmesh map %03u", mapId); return false; } - MMapData* mmap = loadedMMaps[mapId]; - if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end()) + MMapData* mmap = _loadedMaps[mapId]; + if (mmap->_navMeshQueries.find(instanceId) == mmap->_navMeshQueries.end()) { - TC_LOG_DEBUG("maps", "MMAP:unloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId %03u instanceId %u", mapId, instanceId); + TC_LOG_DEBUG("maps", "MMAP::UnloadMapInstance: Asked to unload not loaded dtNavMeshQuery mapId %03u instanceId %u", mapId, instanceId); return false; } - dtNavMeshQuery* query = mmap->navMeshQueries[instanceId]; + dtNavMeshQuery* query = mmap->_navMeshQueries[instanceId]; dtFreeNavMeshQuery(query); - mmap->navMeshQueries.erase(instanceId); - TC_LOG_INFO("maps", "MMAP:unloadMapInstance: Unloaded mapId %03u instanceId %u", mapId, instanceId); + mmap->_navMeshQueries.erase(instanceId); + TC_LOG_INFO("maps", "MMAP::UnloadMapInstance: Unloaded mapId %03u instanceId %u", mapId, instanceId); return true; } dtNavMesh const* MMapManager::GetNavMesh(uint32 mapId) { - if (loadedMMaps.find(mapId) == loadedMMaps.end()) + if (_loadedMaps.find(mapId) == _loadedMaps.end()) return NULL; - return loadedMMaps[mapId]->navMesh; + return _loadedMaps[mapId]->navMesh; } dtNavMeshQuery const* MMapManager::GetNavMeshQuery(uint32 mapId, uint32 instanceId) { - if (loadedMMaps.find(mapId) == loadedMMaps.end()) + if (_loadedMaps.find(mapId) == _loadedMaps.end()) return NULL; - MMapData* mmap = loadedMMaps[mapId]; - if (mmap->navMeshQueries.find(instanceId) == mmap->navMeshQueries.end()) + MMapData* mmap = _loadedMaps[mapId]; + if (mmap->_navMeshQueries.find(instanceId) == mmap->_navMeshQueries.end()) { // allocate mesh query dtNavMeshQuery* query = dtAllocNavMeshQuery(); - ASSERT(query); - if (dtStatusFailed(query->init(mmap->navMesh, 1024))) + if (dtStatusFailed(query->init(mmap->navMesh, 2048))) { dtFreeNavMeshQuery(query); - TC_LOG_ERROR("maps", "MMAP:GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId); + TC_LOG_ERROR("maps", "MMAP::GetNavMeshQuery: Failed to initialize dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId); return NULL; } TC_LOG_INFO("maps", "MMAP:GetNavMeshQuery: created dtNavMeshQuery for mapId %03u instanceId %u", mapId, instanceId); - mmap->navMeshQueries.insert(std::pair<uint32, dtNavMeshQuery*>(instanceId, query)); + mmap->_navMeshQueries.insert(std::pair<uint32, dtNavMeshQuery*>(instanceId, query)); } - return mmap->navMeshQueries[instanceId]; + return mmap->_navMeshQueries[instanceId]; } } |