aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Battlegrounds/BattlegroundMgr.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game/Battlegrounds/BattlegroundMgr.cpp')
-rw-r--r--src/server/game/Battlegrounds/BattlegroundMgr.cpp38
1 files changed, 13 insertions, 25 deletions
diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
index b59831ff05d..1b3d2f0c851 100644
--- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp
+++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
@@ -69,18 +69,6 @@ BattlegroundMgr::~BattlegroundMgr()
void BattlegroundMgr::DeleteAllBattlegrounds()
{
- for (BattlegroundDataContainer::iterator itr1 = bgDataStore.begin(); itr1 != bgDataStore.end(); ++itr1)
- {
- BattlegroundData& data = itr1->second;
-
- while (!data.m_Battlegrounds.empty())
- delete data.m_Battlegrounds.begin()->second;
- data.m_Battlegrounds.clear();
-
- while (!data.BGFreeSlotQueue.empty())
- delete data.BGFreeSlotQueue.front();
- }
-
bgDataStore.clear();
}
@@ -104,18 +92,19 @@ void BattlegroundMgr::Update(uint32 diff)
for (BattlegroundContainer::iterator itr = ++itrDelete; itr != bgs.end();)
{
itrDelete = itr++;
- Battleground* bg = itrDelete->second;
+ Battleground* bg = itrDelete->second.get();
bg->Update(m_UpdateTimer);
if (bg->ToBeDeleted())
{
- itrDelete->second = nullptr;
- bgs.erase(itrDelete);
BattlegroundClientIdsContainer& clients = itr1->second.m_ClientBattlegroundIds[bg->GetBracketId()];
if (!clients.empty())
clients.erase(bg->GetClientInstanceID());
- delete bg;
+ // move out unique_ptr to delete after erasing
+ Trinity::unique_trackable_ptr<Battleground> bgPtr = std::move(itrDelete->second);
+
+ bgs.erase(itrDelete);
}
}
}
@@ -274,7 +263,7 @@ Battleground* BattlegroundMgr::GetBattlegroundThroughClientInstance(uint32 insta
for (BattlegroundContainer::const_iterator itr = it->second.m_Battlegrounds.begin(); itr != it->second.m_Battlegrounds.end(); ++itr)
{
if (itr->second->GetClientInstanceID() == instanceId)
- return itr->second;
+ return itr->second.get();
}
return nullptr;
@@ -305,7 +294,7 @@ Battleground* BattlegroundMgr::GetBattleground(uint32 instanceId, BattlegroundTy
BattlegroundContainer const& bgs = it->second.m_Battlegrounds;
BattlegroundContainer::const_iterator itr = bgs.find(instanceId);
if (itr != bgs.end())
- return itr->second;
+ return itr->second.get();
}
return nullptr;
@@ -319,7 +308,7 @@ Battleground* BattlegroundMgr::GetBattlegroundTemplate(BattlegroundTypeId bgType
BattlegroundContainer const& bgs = itr->second.m_Battlegrounds;
//map is sorted and we can be sure that lowest instance id has only BG template
- return bgs.empty() ? nullptr : bgs.begin()->second;
+ return bgs.empty() ? nullptr : bgs.begin()->second.get();
}
uint32 BattlegroundMgr::CreateClientVisibleInstanceId(BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
@@ -1015,10 +1004,9 @@ void BattlegroundMgr::RemoveFromBGFreeSlotQueue(BattlegroundTypeId bgTypeId, uin
void BattlegroundMgr::AddBattleground(Battleground* bg)
{
if (bg)
- bgDataStore[bg->GetTypeID()].m_Battlegrounds[bg->GetInstanceID()] = bg;
-}
-
-void BattlegroundMgr::RemoveBattleground(BattlegroundTypeId bgTypeId, uint32 instanceId)
-{
- bgDataStore[bgTypeId].m_Battlegrounds.erase(instanceId);
+ {
+ Trinity::unique_trackable_ptr<Battleground>& ptr = bgDataStore[bg->GetTypeID()].m_Battlegrounds[bg->GetInstanceID()];
+ ptr.reset(bg);
+ bg->SetWeakPtr(ptr);
+ }
}