diff options
author | Shauren <shauren.trinity@gmail.com> | 2015-10-28 21:43:44 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2015-10-28 21:56:40 +0100 |
commit | 20b4e6f03adc29e486e20866222a42e8935704b4 (patch) | |
tree | 1c55c9209fa8493058779bdde75f7396d5fa38ab /src/server/game/Maps/Map.cpp | |
parent | 8e7012f0769ccca3cd61684b8978d6637f81065f (diff) |
Core/Corpses: Fixed leaking corpses
Closes #15765
(cherry picked from commit bd16520ecc91d827abae7f0447cc292fe9e843e9)
Diffstat (limited to 'src/server/game/Maps/Map.cpp')
-rw-r--r-- | src/server/game/Maps/Map.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 7ab83d51c7c..a9ef590f84e 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -1601,6 +1601,13 @@ void Map::UnloadAll() RemoveFromMap<Transport>(transport, true); } + + for (auto& cellCorpsePair : _corpsesByCell) + for (Corpse* corpse : cellCorpsePair.second) + delete corpse; + + _corpsesByCell.clear(); + _corpsesByPlayer.clear(); } // ***************************** @@ -3575,14 +3582,16 @@ void Map::AddCorpse(Corpse* corpse) { corpse->SetMap(this); - CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY()); - _corpsesByCell[cellCoord.GetId()].insert(corpse); - _corpsesByPlayer[corpse->GetOwnerGUID()] = corpse; + _corpsesByCell[corpse->GetCellCoord().GetId()].insert(corpse); + if (corpse->GetType() != CORPSE_BONES) + _corpsesByPlayer[corpse->GetOwnerGUID()] = corpse; + else + _corpseBones.insert(corpse); } void Map::RemoveCorpse(Corpse* corpse) { - ASSERT(corpse && corpse->GetType() != CORPSE_BONES); + ASSERT(corpse); corpse->DestroyForNearbyPlayers(); if (corpse->IsInGrid()) @@ -3593,9 +3602,11 @@ void Map::RemoveCorpse(Corpse* corpse) corpse->ResetMap(); } - CellCoord cellCoord = Trinity::ComputeCellCoord(corpse->GetPositionX(), corpse->GetPositionY()); - _corpsesByCell[cellCoord.GetId()].erase(corpse); - _corpsesByPlayer.erase(corpse->GetOwnerGUID()); + _corpsesByCell[corpse->GetCellCoord().GetId()].erase(corpse); + if (corpse->GetType() != CORPSE_BONES) + _corpsesByPlayer.erase(corpse->GetOwnerGUID()); + else + _corpseBones.erase(corpse); } Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*= false*/) @@ -3626,7 +3637,7 @@ Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*= for (uint8 i = OBJECT_FIELD_TYPE + 1; i < CORPSE_END; ++i) // don't overwrite guid and object type bones->SetUInt32Value(i, corpse->GetUInt32Value(i)); - bones->SetGridCoord(corpse->GetGridCoord()); + bones->SetCellCoord(corpse->GetCellCoord()); bones->Relocate(corpse->GetPositionX(), corpse->GetPositionY(), corpse->GetPositionZ(), corpse->GetOrientation()); bones->SetPhaseMask(corpse->GetPhaseMask(), false); @@ -3637,6 +3648,8 @@ Corpse* Map::ConvertCorpseToBones(ObjectGuid const& ownerGuid, bool insignia /*= if (corpse->GetUInt32Value(CORPSE_FIELD_ITEM + i)) bones->SetUInt32Value(CORPSE_FIELD_ITEM + i, 0); + AddCorpse(bones); + // add bones in grid store if grid loaded where corpse placed AddToMap(bones); } @@ -3660,6 +3673,17 @@ void Map::RemoveOldCorpses() for (ObjectGuid const& ownerGuid : corpses) ConvertCorpseToBones(ownerGuid); + + std::vector<Corpse*> expiredBones; + for (Corpse* bones : _corpseBones) + if (bones->IsExpired(now)) + expiredBones.push_back(bones); + + for (Corpse* bones : expiredBones) + { + RemoveCorpse(bones); + delete bones; + } } void Map::SendZoneDynamicInfo(Player* player) |