mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 22:37:03 +00:00
[8102] Simplify code base at new root method WorldObject::CleanupsBeforeDelete
* Call it from Map::AddObjectToRemoveList and remove now not needed explcit calls * Create Gameobject version to make GO with owner more safe for remove
This commit is contained in:
parent
dc10620148
commit
9f41772828
15 changed files with 19 additions and 32 deletions
|
|
@ -1529,7 +1529,6 @@ bool BattleGround::DelCreature(uint32 type)
|
|||
sLog.outError("Can't find creature guid: %u",GUID_LOPART(m_BgCreatures[type]));
|
||||
return false;
|
||||
}
|
||||
cr->CleanupsBeforeDelete();
|
||||
cr->AddObjectToRemoveList();
|
||||
m_BgCreatures[type] = 0;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -599,12 +599,9 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
|
|||
objmgr.RemoveCreatureFromGrid(*itr, data);
|
||||
|
||||
if( Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT), (Creature*)NULL) )
|
||||
{
|
||||
pCreature->CleanupsBeforeDelete();
|
||||
pCreature->AddObjectToRemoveList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(internal_event_id < 0 || internal_event_id >= mGameEventGameobjectGuids.size())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -59,15 +59,18 @@ GameObject::GameObject() : WorldObject()
|
|||
}
|
||||
|
||||
GameObject::~GameObject()
|
||||
{
|
||||
CleanupsBeforeDelete();
|
||||
}
|
||||
|
||||
void GameObject::CleanupsBeforeDelete()
|
||||
{
|
||||
if(m_uint32Values) // field array can be not exist if GameOBject not loaded
|
||||
{
|
||||
// Possible crash at access to deleted GO in Unit::m_gameobj
|
||||
uint64 owner_guid = GetOwnerGUID();
|
||||
if(owner_guid)
|
||||
if(uint64 owner_guid = GetOwnerGUID())
|
||||
{
|
||||
Unit* owner = ObjectAccessor::GetUnit(*this,owner_guid);
|
||||
if(owner)
|
||||
if(Unit* owner = ObjectAccessor::GetUnit(*this,owner_guid))
|
||||
owner->RemoveGameObject(this,false);
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -467,6 +467,7 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject
|
|||
|
||||
void AddToWorld();
|
||||
void RemoveFromWorld();
|
||||
void CleanupsBeforeDelete();
|
||||
|
||||
bool Create(uint32 guidlow, uint32 name_id, Map *map, uint32 phaseMask, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 animprogress, GOState go_state);
|
||||
void Update(uint32 p_time);
|
||||
|
|
|
|||
|
|
@ -1337,7 +1337,6 @@ bool ChatHandler::HandleNpcDeleteCommand(const char* args)
|
|||
// Delete the creature
|
||||
unit->CombatStop();
|
||||
unit->DeleteFromDB();
|
||||
unit->CleanupsBeforeDelete();
|
||||
unit->AddObjectToRemoveList();
|
||||
|
||||
SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
|
||||
|
|
@ -2783,7 +2782,6 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
|||
{
|
||||
wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
||||
wpCreature->DeleteFromDB();
|
||||
wpCreature->CleanupsBeforeDelete();
|
||||
wpCreature->AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
|
@ -2847,7 +2845,6 @@ bool ChatHandler::HandleWpModifyCommand(const char* args)
|
|||
{
|
||||
wpCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(wpGuid, VISUAL_WAYPOINT, HIGHGUID_UNIT));
|
||||
wpCreature->DeleteFromDB();
|
||||
wpCreature->CleanupsBeforeDelete();
|
||||
wpCreature->AddObjectToRemoveList();
|
||||
// re-create
|
||||
Creature* wpCreature2 = new Creature;
|
||||
|
|
@ -3127,7 +3124,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
|
|||
else
|
||||
{
|
||||
pCreature->DeleteFromDB();
|
||||
pCreature->CleanupsBeforeDelete();
|
||||
pCreature->AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
|
@ -3325,7 +3321,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
|
|||
else
|
||||
{
|
||||
pCreature->DeleteFromDB();
|
||||
pCreature->CleanupsBeforeDelete();
|
||||
pCreature->AddObjectToRemoveList();
|
||||
}
|
||||
}while(result->NextRow());
|
||||
|
|
|
|||
|
|
@ -880,7 +880,6 @@ void Map::MoveAllCreaturesInMoveList()
|
|||
if((sLog.getLogFilter() & LOG_FILTER_CREATURE_MOVES)==0)
|
||||
sLog.outDebug("Creature (GUID: %u Entry: %u ) can't be move to unloaded respawn grid.",c->GetGUIDLow(),c->GetEntry());
|
||||
#endif
|
||||
c->CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList(c);
|
||||
}
|
||||
}
|
||||
|
|
@ -2048,6 +2047,8 @@ void Map::AddObjectToRemoveList(WorldObject *obj)
|
|||
{
|
||||
assert(obj->GetMapId()==GetId() && obj->GetInstanceId()==GetInstanceId());
|
||||
|
||||
obj->CleanupsBeforeDelete(); // remove or simplify at least cross referenced links
|
||||
|
||||
i_objectsToRemove.insert(obj);
|
||||
//sLog.outDebug("Object (GUID: %u TypeId: %u ) added to removing list.",obj->GetGUIDLow(),obj->GetTypeId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1053,6 +1053,10 @@ WorldObject::WorldObject()
|
|||
{
|
||||
}
|
||||
|
||||
void WorldObject::CleanupsBeforeDelete()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldObject::_Create( uint32 guidlow, HighGuid guidhigh, uint32 mapid, uint32 phaseMask )
|
||||
{
|
||||
Object::_Create(guidlow, 0, guidhigh);
|
||||
|
|
@ -1546,14 +1550,7 @@ Map const* WorldObject::GetBaseMap() const
|
|||
|
||||
void WorldObject::AddObjectToRemoveList()
|
||||
{
|
||||
Map* map = GetMap();
|
||||
if(!map)
|
||||
{
|
||||
sLog.outError("Object (TypeId: %u Entry: %u GUID: %u) at attempt add to move list not have valid map (Id: %u).",GetTypeId(),GetEntry(),GetGUIDLow(),GetMapId());
|
||||
return;
|
||||
}
|
||||
|
||||
map->AddObjectToRemoveList(this);
|
||||
GetMap()->AddObjectToRemoveList(this);
|
||||
}
|
||||
|
||||
Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang,TempSummonType spwtype,uint32 despwtime)
|
||||
|
|
|
|||
|
|
@ -447,6 +447,8 @@ class MANGOS_DLL_SPEC WorldObject : public Object
|
|||
float GetAngle( const float x, const float y ) const;
|
||||
bool HasInArc( const float arcangle, const WorldObject* obj ) const;
|
||||
|
||||
virtual void CleanupsBeforeDelete(); // used in destructor or explicitly before mass creature delete to remove cross-references to already deleted units
|
||||
|
||||
virtual void SendMessageToSet(WorldPacket *data, bool self);
|
||||
virtual void SendMessageToSetInRange(WorldPacket *data, float dist, bool self);
|
||||
|
||||
|
|
|
|||
|
|
@ -680,7 +680,6 @@ void Pet::Remove(PetSaveMode mode, bool returnreagent)
|
|||
owner->SetPet(0);
|
||||
}
|
||||
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
m_removed = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16247,7 +16247,6 @@ void Player::RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent)
|
|||
|
||||
pet->SavePetToDB(mode);
|
||||
|
||||
pet->CleanupsBeforeDelete();
|
||||
pet->AddObjectToRemoveList();
|
||||
pet->m_removed = true;
|
||||
|
||||
|
|
|
|||
|
|
@ -127,11 +127,8 @@ void PoolGroup<Creature>::Despawn1Object(uint32 guid)
|
|||
objmgr.RemoveCreatureFromGrid(guid, data);
|
||||
|
||||
if (Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(guid, data->id, HIGHGUID_UNIT), (Creature*)NULL))
|
||||
{
|
||||
pCreature->CleanupsBeforeDelete();
|
||||
pCreature->AddObjectToRemoveList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Same on one gameobject
|
||||
|
|
|
|||
|
|
@ -165,7 +165,6 @@ void TemporarySummon::UnSummon()
|
|||
{
|
||||
CombatStop();
|
||||
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
|
||||
Unit* sum = m_summoner ? ObjectAccessor::GetUnit(*this, m_summoner) : NULL;
|
||||
|
|
|
|||
|
|
@ -122,7 +122,6 @@ void Totem::UnSummon()
|
|||
}
|
||||
}
|
||||
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,5 @@ void Vehicle::Dismiss()
|
|||
{
|
||||
SendObjectDeSpawnAnim(GetGUID());
|
||||
CombatStop();
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "8101"
|
||||
#define REVISION_NR "8102"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue