diff options
-rw-r--r-- | src/server/game/Battlegrounds/BattlegroundMgr.cpp | 42 | ||||
-rw-r--r-- | src/server/game/Battlegrounds/BattlegroundMgr.h | 6 |
2 files changed, 30 insertions, 18 deletions
diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index b64821997e3..f7405c0337e 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -50,7 +50,7 @@ BattlegroundMgr::BattlegroundMgr() : m_NextRatedArenaUpdate(sWorld->getIntConfig(CONFIG_ARENA_RATED_UPDATE_TIMER)), - m_ArenaTesting(false), m_Testing(false) + m_UpdateTimer(0), m_ArenaTesting(false), m_Testing(false) { } BattlegroundMgr::~BattlegroundMgr() @@ -84,28 +84,34 @@ BattlegroundMgr* BattlegroundMgr::instance() // used to update running battlegrounds, and delete finished ones void BattlegroundMgr::Update(uint32 diff) { - for (BattlegroundDataContainer::iterator itr1 = bgDataStore.begin(); itr1 != bgDataStore.end(); ++itr1) + m_UpdateTimer += diff; + if (m_UpdateTimer > BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL) { - BattlegroundContainer& bgs = itr1->second.m_Battlegrounds; - BattlegroundContainer::iterator itrDelete = bgs.begin(); - // first one is template and should not be deleted - for (BattlegroundContainer::iterator itr = ++itrDelete; itr != bgs.end();) + for (BattlegroundDataContainer::iterator itr1 = bgDataStore.begin(); itr1 != bgDataStore.end(); ++itr1) { - itrDelete = itr++; - Battleground* bg = itrDelete->second; - - bg->Update(diff); - if (bg->ToBeDeleted()) + BattlegroundContainer& bgs = itr1->second.m_Battlegrounds; + BattlegroundContainer::iterator itrDelete = bgs.begin(); + // first one is template and should not be deleted + for (BattlegroundContainer::iterator itr = ++itrDelete; itr != bgs.end();) { - itrDelete->second = NULL; - bgs.erase(itrDelete); - BattlegroundClientIdsContainer& clients = itr1->second.m_ClientBattlegroundIds[bg->GetBracketId()]; - if (!clients.empty()) - clients.erase(bg->GetClientInstanceID()); - - delete bg; + itrDelete = itr++; + Battleground* bg = itrDelete->second; + + 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; + } } } + + m_UpdateTimer = 0; } // update events timer diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.h b/src/server/game/Battlegrounds/BattlegroundMgr.h index 75ec14f1b0b..1914a880be7 100644 --- a/src/server/game/Battlegrounds/BattlegroundMgr.h +++ b/src/server/game/Battlegrounds/BattlegroundMgr.h @@ -29,6 +29,11 @@ typedef std::set<uint32> BattlegroundClientIdsContainer; typedef std::unordered_map<uint32, BattlegroundTypeId> BattleMastersMap; +enum BattlegroundMisc +{ + BATTLEGROUND_OBJECTIVE_UPDATE_INTERVAL = 1000 +}; + struct BattlegroundData { BattlegroundContainer m_Battlegrounds; @@ -148,6 +153,7 @@ class TC_GAME_API BattlegroundMgr std::vector<uint64> m_QueueUpdateScheduler; uint32 m_NextRatedArenaUpdate; + uint32 m_UpdateTimer; bool m_ArenaTesting; bool m_Testing; BattleMastersMap mBattleMastersMap; |