[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
This commit is contained in:
balrok 2010-03-16 23:30:12 +01:00
parent 24d45c6a08
commit 1b2eefd721
7 changed files with 19 additions and 40 deletions

View file

@ -225,7 +225,6 @@ BattleGround::BattleGround()
m_LevelMin = 0; m_LevelMin = 0;
m_LevelMax = 0; m_LevelMax = 0;
m_InBGFreeSlotQueue = false; m_InBGFreeSlotQueue = false;
m_SetDeleteThis = false;
m_MaxPlayersPerTeam = 0; m_MaxPlayersPerTeam = 0;
m_MaxPlayers = 0; m_MaxPlayers = 0;
@ -296,6 +295,7 @@ BattleGround::~BattleGround()
} }
sBattleGroundMgr.RemoveBattleGround(GetInstanceID(), GetTypeID()); sBattleGroundMgr.RemoveBattleGround(GetInstanceID(), GetTypeID());
sBattleGroundMgr.DeleteClientVisibleInstanceId(GetTypeID(), GetBracketId(), GetClientInstanceID());
// unload map // unload map
// map can be null at bg destruction // 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 // BattleGround Template instance cannot be updated, because it would be deleted
if (!GetInvitedCount(HORDE) && !GetInvitedCount(ALLIANCE)) if (!GetInvitedCount(HORDE) && !GetInvitedCount(ALLIANCE))
m_SetDeleteThis = true; delete this;
return; return;
} }

View file

@ -516,8 +516,6 @@ class BattleGround
uint32 GetOtherTeam(uint32 teamId){ return (teamId) ? ((teamId == ALLIANCE) ? HORDE : ALLIANCE) : 0; } uint32 GetOtherTeam(uint32 teamId){ return (teamId) ? ((teamId == ALLIANCE) ? HORDE : ALLIANCE) : 0; }
bool IsPlayerInBattleGround(uint64 guid); bool IsPlayerInBattleGround(uint64 guid);
void SetDeleteThis() {m_SetDeleteThis = true;}
/* virtual score-array - get's used in bg-subclasses */ /* virtual score-array - get's used in bg-subclasses */
int32 m_TeamScores[BG_TEAMS_COUNT]; int32 m_TeamScores[BG_TEAMS_COUNT];
@ -572,7 +570,6 @@ class BattleGround
BattleGroundBracketId m_BracketId; BattleGroundBracketId m_BracketId;
uint8 m_ArenaType; // 2=2v2, 3=3v3, 5=5v5 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_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; bool m_IsArena;
uint8 m_Winner; // 0=alliance, 1=horde, 2=none uint8 m_Winner; // 0=alliance, 1=horde, 2=none
int32 m_StartDelayTime; int32 m_StartDelayTime;

View file

@ -1139,16 +1139,8 @@ BattleGroundMgr::~BattleGroundMgr()
void BattleGroundMgr::DeleteAllBattleGrounds() void BattleGroundMgr::DeleteAllBattleGrounds()
{ {
for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++) 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();) for(BattleGroundSet::iterator itr = m_BattleGrounds[i].begin(); itr != m_BattleGrounds[i].end();)
{ delete itr->second;
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;
}
}
// destroy template battlegrounds that listed only in queues (other already terminated) // destroy template battlegrounds that listed only in queues (other already terminated)
for(uint32 bgTypeId = 0; bgTypeId < MAX_BATTLEGROUND_TYPE_ID; ++bgTypeId) 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 // used to update running battlegrounds, and delete finished ones
void BattleGroundMgr::Update(uint32 diff) 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 // update scheduled queues
if (!m_QueueUpdateScheduler.empty()) if (!m_QueueUpdateScheduler.empty())
{ {

View file

@ -211,6 +211,11 @@ class BattleGroundMgr
void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; }; void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; };
void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); } void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); }
uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BattleGroundBracketId bracket_id); 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 CreateInitialBattleGrounds();
void DeleteAllBattleGrounds(); void DeleteAllBattleGrounds();

View file

@ -39,6 +39,7 @@
#include "MapInstanced.h" #include "MapInstanced.h"
#include "InstanceSaveMgr.h" #include "InstanceSaveMgr.h"
#include "VMapFactory.h" #include "VMapFactory.h"
#include "BattleGroundMgr.h"
GridState* si_GridStates[MAX_GRID_STATE]; GridState* si_GridStates[MAX_GRID_STATE];
@ -2527,6 +2528,13 @@ void InstanceMap::Update(const uint32& t_diff)
i_data->Update(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) 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()); sLog.outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName());

View file

@ -576,6 +576,7 @@ class MANGOS_DLL_SPEC BattleGroundMap : public Map
BattleGroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode); BattleGroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode);
~BattleGroundMap(); ~BattleGroundMap();
void Update(const uint32&);
bool Add(Player *); bool Add(Player *);
void Remove(Player *, bool); void Remove(Player *, bool);
bool CanEnter(Player* player); bool CanEnter(Player* player);

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "9597" #define REVISION_NR "9598"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__