aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2009-08-24 19:34:56 -0500
committermegamage <none@none>2009-08-24 19:34:56 -0500
commit19bfa37ec6e63252df1dea09a2560a18eaef17f3 (patch)
tree72d90fdde40ababb4545596667123d8d5f551849 /src
parent785577e170a9791a324cac85a1fe682872249d1b (diff)
[8405] Fixed possible crash in BGQueueRemoveEvent::Execute() when two paralell BattleGroundQueue Updates are called, optimalized code.
Signed-off-by: Triply <triply@getmangos.com> --HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/BattleGroundMgr.cpp36
-rw-r--r--src/game/BattleGroundMgr.h2
2 files changed, 37 insertions, 1 deletions
diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
index eb832fe6d41..49424249eb3 100644
--- a/src/game/BattleGroundMgr.cpp
+++ b/src/game/BattleGroundMgr.cpp
@@ -1095,7 +1095,7 @@ bool BGQueueRemoveEvent::Execute(uint64 /*e_time*/, uint32 /*p_time*/)
sBattleGroundMgr.m_BattleGroundQueues[m_BgQueueTypeId].RemovePlayer(m_PlayerGuid, true);
//update queues if battleground isn't ended
if (bg)
- sBattleGroundMgr.m_BattleGroundQueues[m_BgQueueTypeId].Update(m_BgTypeId, bg->GetQueueId());
+ sBattleGroundMgr.ScheduleQueueUpdate(m_BgQueueTypeId, m_BgTypeId, bg->GetQueueId());
WorldPacket data;
sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, queueSlot, STATUS_NONE, 0, 0, 0);
@@ -1179,6 +1179,22 @@ void BattleGroundMgr::Update(uint32 diff)
}
}
}
+
+ // update scheduled queues
+ if (!m_QueueUpdateScheduler.empty())
+ {
+ //copy vector and clear the other
+ std::vector<uint32> scheduled(m_QueueUpdateScheduler);
+ m_QueueUpdateScheduler.clear();
+ for (uint8 i = 0; i < scheduled.size(); i++)
+ {
+ BattleGroundQueueTypeId bgQueueTypeId = BattleGroundQueueTypeId(scheduled[i] / 65536);
+ BattleGroundTypeId bgTypeId = BattleGroundTypeId((scheduled[i] % 65536) / 256);
+ BGQueueIdBasedOnLevel queue_id = BGQueueIdBasedOnLevel(scheduled[i] % 256);
+ m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, queue_id);
+ }
+ }
+
// if rating difference counts, maybe force-update queues
if (sWorld.getConfig(CONFIG_ARENA_MAX_RATING_DIFFERENCE) && sWorld.getConfig(CONFIG_ARENA_RATING_DISCARD_TIMER))
{
@@ -2018,6 +2034,24 @@ void BattleGroundMgr::SetHolidayWeekends(uint32 mask)
}
}
+void BattleGroundMgr::ScheduleQueueUpdate(BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id)
+{
+ //This method must be atomic!
+ //we will use only 1 number created of bgTypeId and queue_id
+ uint32 schedule_id = (bgQueueTypeId * 65536) + (bgTypeId * 256) + queue_id;
+ bool found = false;
+ for (uint8 i = 0; i < m_QueueUpdateScheduler.size(); i++)
+ {
+ if (m_QueueUpdateScheduler[i] == schedule_id)
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ m_QueueUpdateScheduler.push_back(schedule_id);
+}
+
uint32 BattleGroundMgr::GetMaxRatingDifference() const
{
// this is for stupid people who can't use brain and set max rating difference to 0
diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h
index 9c38fea1ad4..dbf68dc1d31 100644
--- a/src/game/BattleGroundMgr.h
+++ b/src/game/BattleGroundMgr.h
@@ -220,6 +220,7 @@ class BattleGroundMgr
BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID];
+ void ScheduleQueueUpdate(BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id);
uint32 GetMaxRatingDifference() const;
uint32 GetRatingDiscardTimer() const;
uint32 GetPrematureFinishTime() const;
@@ -252,6 +253,7 @@ class BattleGroundMgr
/* Battlegrounds */
BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID];
+ std::vector<uint32>m_QueueUpdateScheduler;
std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_QUEUES]; //the instanceids just visible for the client
uint32 m_NextRatingDiscardUpdate;
time_t m_NextAutoDistributionTime;