mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Memory: Get rid of some memory leaks, converted FormationMgr back to singleton
This commit is contained in:
@@ -199,7 +199,7 @@ void Creature::RemoveFromWorld()
|
||||
if (m_zoneScript)
|
||||
m_zoneScript->OnCreatureRemove(this);
|
||||
if (m_formation)
|
||||
FormationMgr::RemoveCreatureFromGroup(m_formation, this);
|
||||
sFormationMgr->RemoveCreatureFromGroup(m_formation, this);
|
||||
Unit::RemoveFromWorld();
|
||||
sObjectAccessor->RemoveObject(this);
|
||||
}
|
||||
@@ -224,9 +224,9 @@ void Creature::SearchFormation()
|
||||
if (!lowguid)
|
||||
return;
|
||||
|
||||
CreatureGroupInfoType::iterator frmdata = CreatureGroupMap.find(lowguid);
|
||||
if (frmdata != CreatureGroupMap.end())
|
||||
FormationMgr::AddCreatureToGroup(frmdata->second->leaderGUID, this);
|
||||
CreatureGroupInfoType::iterator frmdata = sFormationMgr->CreatureGroupMap.find(lowguid);
|
||||
if (frmdata != sFormationMgr->CreatureGroupMap.end())
|
||||
sFormationMgr->AddCreatureToGroup(frmdata->second->leaderGUID, this);
|
||||
}
|
||||
|
||||
void Creature::RemoveCorpse(bool setSpawnTime)
|
||||
|
||||
@@ -24,12 +24,13 @@
|
||||
|
||||
#define MAX_DESYNC 5.0f
|
||||
|
||||
CreatureGroupInfoType CreatureGroupMap;
|
||||
|
||||
namespace FormationMgr
|
||||
FormationMgr::~FormationMgr()
|
||||
{
|
||||
for (CreatureGroupInfoType::iterator itr = CreatureGroupMap.begin(); itr != CreatureGroupMap.end(); ++itr)
|
||||
delete itr->second;
|
||||
}
|
||||
|
||||
void AddCreatureToGroup(uint32 groupId, Creature* member)
|
||||
void FormationMgr::AddCreatureToGroup(uint32 groupId, Creature* member)
|
||||
{
|
||||
Map* map = member->FindMap();
|
||||
if (!map)
|
||||
@@ -53,7 +54,7 @@ void AddCreatureToGroup(uint32 groupId, Creature* member)
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveCreatureFromGroup(CreatureGroup* group, Creature* member)
|
||||
void FormationMgr::RemoveCreatureFromGroup(CreatureGroup* group, Creature* member)
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "Deleting member pointer to GUID: %u from group %u", group->GetId(), member->GetDBTableGUIDLow());
|
||||
group->RemoveMember(member);
|
||||
@@ -70,7 +71,7 @@ void RemoveCreatureFromGroup(CreatureGroup* group, Creature* member)
|
||||
}
|
||||
}
|
||||
|
||||
void LoadCreatureFormations()
|
||||
void FormationMgr::LoadCreatureFormations()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
@@ -97,7 +98,7 @@ void LoadCreatureFormations()
|
||||
fields = result->Fetch();
|
||||
|
||||
//Load group member data
|
||||
group_member = new FormationInfo;
|
||||
group_member = new FormationInfo();
|
||||
group_member->leaderGUID = fields[0].GetUInt32();
|
||||
uint32 memberGUID = fields[1].GetUInt32();
|
||||
group_member->groupAI = fields[4].GetUInt8();
|
||||
@@ -139,8 +140,6 @@ void LoadCreatureFormations()
|
||||
sLog->outString();
|
||||
}
|
||||
|
||||
} // Namespace
|
||||
|
||||
void CreatureGroup::AddMember(Creature* member)
|
||||
{
|
||||
sLog->outDebug(LOG_FILTER_UNITS, "CreatureGroup::AddMember: Adding unit GUID: %u.", member->GetGUIDLow());
|
||||
@@ -152,7 +151,7 @@ void CreatureGroup::AddMember(Creature* member)
|
||||
m_leader = member;
|
||||
}
|
||||
|
||||
m_members[member] = CreatureGroupMap.find(member->GetDBTableGUIDLow())->second;
|
||||
m_members[member] = sFormationMgr->CreatureGroupMap.find(member->GetDBTableGUIDLow())->second;
|
||||
member->SetFormation(this);
|
||||
}
|
||||
|
||||
@@ -167,7 +166,7 @@ void CreatureGroup::RemoveMember(Creature* member)
|
||||
|
||||
void CreatureGroup::MemberAttackStart(Creature* member, Unit* target)
|
||||
{
|
||||
uint8 groupAI = CreatureGroupMap[member->GetDBTableGUIDLow()]->groupAI;
|
||||
uint8 groupAI = sFormationMgr->CreatureGroupMap[member->GetDBTableGUIDLow()]->groupAI;
|
||||
if (!groupAI)
|
||||
return;
|
||||
|
||||
|
||||
@@ -34,16 +34,19 @@ struct FormationInfo
|
||||
uint8 groupAI;
|
||||
};
|
||||
|
||||
namespace FormationMgr
|
||||
{
|
||||
void AddCreatureToGroup(uint32 group_id, Creature* creature);
|
||||
void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
|
||||
void LoadCreatureFormations();
|
||||
};
|
||||
|
||||
typedef UNORDERED_MAP<uint32/*memberDBGUID*/, FormationInfo*> CreatureGroupInfoType;
|
||||
|
||||
extern CreatureGroupInfoType CreatureGroupMap;
|
||||
class FormationMgr
|
||||
{
|
||||
friend class ACE_Singleton<FormationMgr, ACE_Null_Mutex>;
|
||||
public:
|
||||
FormationMgr() { }
|
||||
~FormationMgr();
|
||||
void AddCreatureToGroup(uint32 group_id, Creature* creature);
|
||||
void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
|
||||
void LoadCreatureFormations();
|
||||
CreatureGroupInfoType CreatureGroupMap;
|
||||
};
|
||||
|
||||
class CreatureGroup
|
||||
{
|
||||
@@ -73,4 +76,6 @@ class CreatureGroup
|
||||
void MemberAttackStart(Creature* member, Unit* target);
|
||||
};
|
||||
|
||||
#define sFormationMgr ACE_Singleton<FormationMgr, ACE_Null_Mutex>::instance()
|
||||
|
||||
#endif
|
||||
|
||||
@@ -198,6 +198,12 @@ void GmTicket::TeleportTo(Player* player) const
|
||||
// Ticket manager
|
||||
TicketMgr::TicketMgr() : _status(true), _lastTicketId(0), _lastSurveyId(0), _openTicketCount(0), _lastChange(time(NULL)) { }
|
||||
|
||||
TicketMgr::~TicketMgr()
|
||||
{
|
||||
for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
|
||||
delete itr->second;
|
||||
}
|
||||
|
||||
void TicketMgr::Initialize() { SetStatus(sWorld->getBoolConfig(CONFIG_ALLOW_TICKETS)); }
|
||||
|
||||
void TicketMgr::ResetTickets()
|
||||
@@ -217,10 +223,8 @@ void TicketMgr::LoadTickets()
|
||||
{
|
||||
uint32 oldMSTime = getMSTime();
|
||||
|
||||
if (!_ticketList.empty())
|
||||
for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
|
||||
if (itr->second)
|
||||
delete itr->second;
|
||||
for (GmTicketList::const_iterator itr = _ticketList.begin(); itr != _ticketList.end(); ++itr)
|
||||
delete itr->second;
|
||||
_ticketList.clear();
|
||||
|
||||
_lastTicketId = 0;
|
||||
|
||||
@@ -166,6 +166,7 @@ class TicketMgr
|
||||
|
||||
private:
|
||||
TicketMgr();
|
||||
~TicketMgr();
|
||||
|
||||
public:
|
||||
void LoadTickets();
|
||||
|
||||
@@ -1589,7 +1589,7 @@ void World::SetInitialWorldSettings()
|
||||
sSmartWaypointMgr->LoadFromDB();
|
||||
|
||||
sLog->outString("Loading Creature Formations...");
|
||||
FormationMgr::LoadCreatureFormations();
|
||||
sFormationMgr->LoadCreatureFormations();
|
||||
|
||||
sLog->outString("Loading World States..."); // must be loaded before battleground, outdoor PvP and conditions
|
||||
LoadWorldStates();
|
||||
|
||||
@@ -1249,7 +1249,7 @@ public:
|
||||
group_member->leaderGUID = leaderGUID;
|
||||
group_member->groupAI = 0;
|
||||
|
||||
CreatureGroupMap[lowguid] = group_member;
|
||||
sFormationMgr->CreatureGroupMap[lowguid] = group_member;
|
||||
creature->SearchFormation();
|
||||
|
||||
PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_CREATURE_FORMATION);
|
||||
|
||||
Reference in New Issue
Block a user