diff options
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r-- | src/server/game/Maps/Map.cpp | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index a206b6529d0..cf358105825 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -48,11 +48,11 @@ #include "Weather.h" #include "WeatherMgr.h" #include "World.h" +#include <boost/heap/fibonacci_heap.hpp> #include <unordered_set> #include <vector> #include "Hacks/boost_1_74_fibonacci_heap.h" -BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(RespawnListContainer::value_type) u_map_magic MapMagic = { {'M','A','P','S'} }; uint32 MapVersionMagic = 10; @@ -72,6 +72,20 @@ GridState* si_GridStates[MAX_GRID_STATE]; ZoneDynamicInfo::ZoneDynamicInfo() : MusicId(0), DefaultWeather(nullptr), WeatherId(WEATHER_STATE_FINE), Intensity(0.0f) { } +struct RespawnInfoWithHandle; +struct RespawnListContainer : boost::heap::fibonacci_heap<RespawnInfoWithHandle*, boost::heap::compare<CompareRespawnInfo>> +{ +}; + +BOOST_1_74_FIBONACCI_HEAP_MSVC_COMPILE_FIX(RespawnListContainer::value_type) + +struct RespawnInfoWithHandle : RespawnInfo +{ + explicit RespawnInfoWithHandle(RespawnInfo const& other) : RespawnInfo(other) { } + + RespawnListContainer::handle_type handle; +}; + Map::~Map() { // UnloadAll must be called before deleting the map @@ -274,7 +288,7 @@ m_unloadTimer(0), m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE), m_VisibilityNotifyPeriod(DEFAULT_VISIBILITY_NOTIFY_PERIOD), m_activeNonPlayersIter(m_activeNonPlayers.end()), _transportsUpdateIter(_transports.end()), i_gridExpiry(expiry), -i_scriptLock(false), _respawnCheckTimer(0) +i_scriptLock(false), _respawnTimes(std::make_unique<RespawnListContainer>()), _respawnCheckTimer(0) { m_parentMap = (_parent ? _parent : this); for (unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx) @@ -3109,7 +3123,7 @@ void Map::Respawn(RespawnInfo* info, CharacterDatabaseTransaction dbTrans) if (info->respawnTime <= GameTime::GetGameTime()) return; info->respawnTime = GameTime::GetGameTime(); - _respawnTimes.increase(info->handle); + _respawnTimes->increase(static_cast<RespawnInfoWithHandle*>(info)->handle); SaveRespawnInfoDB(*info, dbTrans); } @@ -3163,8 +3177,8 @@ bool Map::AddRespawnInfo(RespawnInfo const& info) else ABORT_MSG("Invalid respawn info for spawn id (%u,%u) being inserted", uint32(info.type), info.spawnId); - RespawnInfo * ri = new RespawnInfo(info); - ri->handle = _respawnTimes.push(ri); + RespawnInfoWithHandle* ri = new RespawnInfoWithHandle(info); + ri->handle = _respawnTimes->push(ri); bySpawnIdMap.emplace(ri->spawnId, ri); return true; } @@ -3195,9 +3209,9 @@ RespawnInfo* Map::GetRespawnInfo(SpawnObjectType type, ObjectGuid::LowType spawn void Map::UnloadAllRespawnInfos() // delete everything from memory { - for (RespawnInfo* info : _respawnTimes) + for (RespawnInfo* info : *_respawnTimes) delete info; - _respawnTimes.clear(); + _respawnTimes->clear(); _creatureRespawnTimesBySpawnId.clear(); _gameObjectRespawnTimesBySpawnId.clear(); } @@ -3215,7 +3229,7 @@ void Map::DeleteRespawnInfo(RespawnInfo* info, CharacterDatabaseTransaction dbTr spawnMap.erase(it); // respawn heap - _respawnTimes.erase(info->handle); + _respawnTimes->erase(static_cast<RespawnInfoWithHandle*>(info)->handle); // database DeleteRespawnInfoFromDB(info->type, info->spawnId, dbTrans); @@ -3263,16 +3277,16 @@ void Map::DoRespawn(SpawnObjectType type, ObjectGuid::LowType spawnId, uint32 gr void Map::ProcessRespawns() { time_t now = GameTime::GetGameTime(); - while (!_respawnTimes.empty()) + while (!_respawnTimes->empty()) { - RespawnInfo* next = _respawnTimes.top(); + RespawnInfoWithHandle* next = _respawnTimes->top(); if (now < next->respawnTime) // done for this tick break; if (uint32 poolId = sPoolMgr->IsPartOfAPool(next->type, next->spawnId)) // is this part of a pool? { // if yes, respawn will be handled by (external) pooling logic, just delete the respawn time // step 1: remove entry from maps to avoid it being reachable by outside logic - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); // step 2: tell pooling logic to do its thing @@ -3285,7 +3299,7 @@ void Map::ProcessRespawns() else if (CheckRespawn(next)) // see if we're allowed to respawn { // ok, respawn // step 1: remove entry from maps to avoid it being reachable by outside logic - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); // step 2: do the respawn, which involves external logic @@ -3297,7 +3311,7 @@ void Map::ProcessRespawns() } else if (!next->respawnTime) { // just remove this respawn entry without rescheduling - _respawnTimes.pop(); + _respawnTimes->pop(); GetRespawnMapForType(next->type).erase(next->spawnId); RemoveRespawnTime(next->type, next->spawnId, nullptr, true); delete next; @@ -3305,7 +3319,7 @@ void Map::ProcessRespawns() else { // new respawn time, update heap position ASSERT(now < next->respawnTime); // infinite loop guard - _respawnTimes.decrease(next->handle); + _respawnTimes->decrease(next->handle); SaveRespawnInfoDB(*next); } } |