From 1b2eefd7214c558a8ff58e9a41666754037bdc94 Mon Sep 17 00:00:00 2001 From: balrok Date: Tue, 16 Mar 2010 23:30:12 +0100 Subject: [PATCH] [9598] update battlegrounds per map + cleanup at delete this will be useful, if we have multithreaded mapupdates one day since i couldn't reproduce any errors regarding to self deletions of battlegrounds i removed the m_deleteThis variable --- src/game/BattleGround.cpp | 5 +++-- src/game/BattleGround.h | 3 --- src/game/BattleGroundMgr.cpp | 35 +---------------------------------- src/game/BattleGroundMgr.h | 5 +++++ src/game/Map.cpp | 8 ++++++++ src/game/Map.h | 1 + src/shared/revision_nr.h | 2 +- 7 files changed, 19 insertions(+), 40 deletions(-) diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp index 42443db28..368bab43b 100644 --- a/src/game/BattleGround.cpp +++ b/src/game/BattleGround.cpp @@ -225,7 +225,6 @@ BattleGround::BattleGround() m_LevelMin = 0; m_LevelMax = 0; m_InBGFreeSlotQueue = false; - m_SetDeleteThis = false; m_MaxPlayersPerTeam = 0; m_MaxPlayers = 0; @@ -296,6 +295,7 @@ BattleGround::~BattleGround() } sBattleGroundMgr.RemoveBattleGround(GetInstanceID(), GetTypeID()); + sBattleGroundMgr.DeleteClientVisibleInstanceId(GetTypeID(), GetBracketId(), GetClientInstanceID()); // unload map // map can be null at bg destruction @@ -324,7 +324,8 @@ void BattleGround::Update(uint32 diff) // ]] // BattleGround Template instance cannot be updated, because it would be deleted if (!GetInvitedCount(HORDE) && !GetInvitedCount(ALLIANCE)) - m_SetDeleteThis = true; + delete this; + return; } diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h index dae112979..bdf7c1304 100644 --- a/src/game/BattleGround.h +++ b/src/game/BattleGround.h @@ -516,8 +516,6 @@ class BattleGround uint32 GetOtherTeam(uint32 teamId){ return (teamId) ? ((teamId == ALLIANCE) ? HORDE : ALLIANCE) : 0; } bool IsPlayerInBattleGround(uint64 guid); - void SetDeleteThis() {m_SetDeleteThis = true;} - /* virtual score-array - get's used in bg-subclasses */ int32 m_TeamScores[BG_TEAMS_COUNT]; @@ -572,7 +570,6 @@ class BattleGround BattleGroundBracketId m_BracketId; uint8 m_ArenaType; // 2=2v2, 3=3v3, 5=5v5 bool m_InBGFreeSlotQueue; // used to make sure that BG is only once inserted into the BattleGroundMgr.BGFreeSlotQueue[bgTypeId] deque - bool m_SetDeleteThis; // used for safe deletion of the bg after end / all players leave bool m_IsArena; uint8 m_Winner; // 0=alliance, 1=horde, 2=none int32 m_StartDelayTime; diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp index c6adeb92a..c0a842d92 100644 --- a/src/game/BattleGroundMgr.cpp +++ b/src/game/BattleGroundMgr.cpp @@ -1139,16 +1139,8 @@ BattleGroundMgr::~BattleGroundMgr() void BattleGroundMgr::DeleteAllBattleGrounds() { for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++) - { for(BattleGroundSet::iterator itr = m_BattleGrounds[i].begin(); itr != m_BattleGrounds[i].end();) - { - BattleGround * bg = itr->second; - m_BattleGrounds[i].erase(itr++); - if (!m_ClientBattleGroundIds[i][bg->GetBracketId()].empty()) - m_ClientBattleGroundIds[i][bg->GetBracketId()].erase(bg->GetClientInstanceID()); - delete bg; - } - } + delete itr->second; // destroy template battlegrounds that listed only in queues (other already terminated) for(uint32 bgTypeId = 0; bgTypeId < MAX_BATTLEGROUND_TYPE_ID; ++bgTypeId) @@ -1162,31 +1154,6 @@ void BattleGroundMgr::DeleteAllBattleGrounds() // used to update running battlegrounds, and delete finished ones void BattleGroundMgr::Update(uint32 diff) { - BattleGroundSet::iterator itr, next; - for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++) - { - itr = m_BattleGrounds[i].begin(); - // skip updating battleground template - if (itr != m_BattleGrounds[i].end()) - ++itr; - for(; itr != m_BattleGrounds[i].end(); itr = next) - { - next = itr; - ++next; - itr->second->Update(diff); - // use the SetDeleteThis variable - // direct deletion caused crashes - if (itr->second->m_SetDeleteThis) - { - BattleGround * bg = itr->second; - m_BattleGrounds[i].erase(itr); - if (!m_ClientBattleGroundIds[i][bg->GetBracketId()].empty()) - m_ClientBattleGroundIds[i][bg->GetBracketId()].erase(bg->GetClientInstanceID()); - delete bg; - } - } - } - // update scheduled queues if (!m_QueueUpdateScheduler.empty()) { diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h index 73352f669..b16e80115 100644 --- a/src/game/BattleGroundMgr.h +++ b/src/game/BattleGroundMgr.h @@ -211,6 +211,11 @@ class BattleGroundMgr void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; }; void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); } uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BattleGroundBracketId bracket_id); + void DeleteClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BattleGroundBracketId bracket_id, uint32 clientInstanceID) + { + if (!m_ClientBattleGroundIds[bgTypeId][bracket_id].empty()) + m_ClientBattleGroundIds[bgTypeId][bracket_id].erase(clientInstanceID); + } void CreateInitialBattleGrounds(); void DeleteAllBattleGrounds(); diff --git a/src/game/Map.cpp b/src/game/Map.cpp index b11881131..5c2b74c27 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -39,6 +39,7 @@ #include "MapInstanced.h" #include "InstanceSaveMgr.h" #include "VMapFactory.h" +#include "BattleGroundMgr.h" GridState* si_GridStates[MAX_GRID_STATE]; @@ -2527,6 +2528,13 @@ void InstanceMap::Update(const uint32& t_diff) i_data->Update(t_diff); } +void BattleGroundMap::Update(const uint32& diff) +{ + Map::Update(diff); + + GetBG()->Update(diff); +} + void InstanceMap::Remove(Player *player, bool remove) { sLog.outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName()); diff --git a/src/game/Map.h b/src/game/Map.h index bd6c0c952..b22cad16f 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -576,6 +576,7 @@ class MANGOS_DLL_SPEC BattleGroundMap : public Map BattleGroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode); ~BattleGroundMap(); + void Update(const uint32&); bool Add(Player *); void Remove(Player *, bool); bool CanEnter(Player* player); diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 912805887..df403074c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "9597" + #define REVISION_NR "9598" #endif // __REVISION_NR_H__