aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Battlegrounds/BattlegroundMgr.cpp
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2016-08-16 00:44:31 -0300
committerjoschiwald <joschiwald.trinity@gmail.com>2017-02-12 15:34:34 +0100
commit5681dc3a646c8391a6ca1b130db42f972cf6b6f5 (patch)
tree8d85e74ff70cb55b602e5ed6911b470bfe0c6b39 /src/server/game/Battlegrounds/BattlegroundMgr.cpp
parent07e8fe115fbd7d19695cd10db506ca6b68bb2a89 (diff)
Core/BattlegroundMgr: Update Battlegrounds each second instead of every tick (just like Battlefield).
There are some battleground scripts (like SOTA) performing object access every update, this should help throttle the cpu usage. (cherry picked from commit 9cdbf903e28fca303c580b096016e26c402a6a7f) # Conflicts: # src/server/game/Battlegrounds/BattlegroundMgr.cpp # src/server/game/Battlegrounds/BattlegroundMgr.h
Diffstat (limited to 'src/server/game/Battlegrounds/BattlegroundMgr.cpp')
-rw-r--r--src/server/game/Battlegrounds/BattlegroundMgr.cpp42
1 files changed, 24 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