[8102] Simplify code base at new root method WorldObject::CleanupsBeforeDelete Author: VladimirMangos
* Call it from Map::AddObjectToRemoveList and remove now not needed explcit calls
* Create Gameobject version to make GO with owner more safe for remove
--HG--
branch : trunk
This commit is contained in:
@@ -1609,8 +1609,6 @@ bool BattleGround::DelCreature(uint32 type)
|
||||
sLog.outError("Can't find creature guid: %u",GUID_LOPART(m_BgCreatures[type]));
|
||||
return false;
|
||||
}
|
||||
//TODO: only delete creature after not in combat
|
||||
cr->CleanupsBeforeDelete();
|
||||
cr->AddObjectToRemoveList();
|
||||
m_BgCreatures[type] = 0;
|
||||
return true;
|
||||
|
||||
@@ -1313,10 +1313,7 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-7
@@ -65,14 +65,18 @@ GameObject::GameObject() : WorldObject(), m_goValue(new GameObjectValue)
|
||||
|
||||
GameObject::~GameObject()
|
||||
{
|
||||
/*if(m_uint32Values) // field array can be not exist if GameOBject not loaded
|
||||
//if(m_uint32Values) // field array can be not exist if GameOBject not loaded
|
||||
// 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
|
||||
{
|
||||
@@ -83,10 +87,10 @@ GameObject::~GameObject()
|
||||
ownerType = "pet";
|
||||
|
||||
sLog.outError("Delete GameObject (GUID: %u Entry: %u SpellId %u LinkedGO %u) that lost references to owner (GUID %u Type '%s') GO list. Crash possible later.",
|
||||
GetGUIDLow(), GetGOInfo()->id, m_spellId, GetLinkedGameObjectEntry(), GUID_LOPART(owner_guid), ownerType);
|
||||
GetGUIDLow(), GetGOInfo()->id, m_spellId, GetLinkedGameObjectEntry(), GUID_LOPART(owner_guid), ownerType);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::AddToWorld()
|
||||
|
||||
@@ -488,6 +488,7 @@ class TRINITY_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, uint32 ArtKit = 0);
|
||||
void Update(uint32 p_time);
|
||||
|
||||
@@ -1377,7 +1377,6 @@ bool ChatHandler::HandleNpcDeleteCommand(const char* args)
|
||||
// Delete the creature
|
||||
unit->CombatStop();
|
||||
unit->DeleteFromDB();
|
||||
unit->CleanupsBeforeDelete();
|
||||
unit->AddObjectToRemoveList();
|
||||
|
||||
SendSysMessage(LANG_COMMAND_DELCREATMESSAGE);
|
||||
@@ -3449,7 +3448,6 @@ bool ChatHandler::HandleWpShowCommand(const char* args)
|
||||
Field *fields = result->Fetch();
|
||||
uint32 guid = fields[0].GetUInt32();
|
||||
Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(MAKE_NEW_GUID(guid,VISUAL_WAYPOINT,HIGHGUID_UNIT));
|
||||
|
||||
if(!pCreature)
|
||||
{
|
||||
PSendSysMessage(LANG_WAYPOINT_NOTREMOVED, guid);
|
||||
|
||||
+2
-1
@@ -1010,7 +1010,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);
|
||||
}
|
||||
}
|
||||
@@ -2151,6 +2150,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());
|
||||
}
|
||||
|
||||
@@ -1096,6 +1096,10 @@ void WorldObject::setActive( bool on )
|
||||
}
|
||||
}
|
||||
|
||||
void WorldObject::CleanupsBeforeDelete()
|
||||
{
|
||||
}
|
||||
|
||||
void WorldObject::_Create( uint32 guidlow, HighGuid guidhigh, uint32 mapid, uint32 phaseMask )
|
||||
{
|
||||
Object::_Create(guidlow, 0, guidhigh);
|
||||
|
||||
@@ -498,6 +498,8 @@ class TRINITY_DLL_SPEC WorldObject : public Object
|
||||
bool HasInArc( const float arcangle, const WorldObject* obj ) const;
|
||||
bool IsInBetween(const WorldObject *obj1, const WorldObject *obj2, float size = 0) 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);
|
||||
|
||||
|
||||
@@ -116,7 +116,6 @@ bool OPvPCapturePoint::DelCreature(uint32 type)
|
||||
// Don't save respawn time
|
||||
cr->SetRespawnTime(0);
|
||||
cr->RemoveCorpse();
|
||||
cr->CleanupsBeforeDelete();
|
||||
// explicit removal from map
|
||||
// beats me why this is needed, but with the recent removal "cleanup" some creatures stay in the map if "properly" deleted
|
||||
// so this is a big fat workaround, if AddObjectToRemoveList and DoDelayedMovesAndRemoves worked correctly, this wouldn't be needed
|
||||
|
||||
@@ -16814,7 +16814,6 @@ void Player::RemovePet(Pet* pet, PetSaveMode mode, bool returnreagent)
|
||||
|
||||
SetMinion(pet, false);
|
||||
|
||||
pet->CleanupsBeforeDelete();
|
||||
pet->AddObjectToRemoveList();
|
||||
pet->m_removed = true;
|
||||
|
||||
|
||||
@@ -127,10 +127,7 @@ 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,6 @@ void TempSummon::UnSummon()
|
||||
if(owner && owner->GetTypeId() == TYPEID_UNIT && ((Creature*)owner)->IsAIEnabled)
|
||||
((Creature*)owner)->AI()->SummonedCreatureDespawn(this);
|
||||
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
||||
@@ -129,7 +129,6 @@ void Totem::UnSummon()
|
||||
}
|
||||
}
|
||||
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
||||
@@ -389,7 +389,6 @@ void Vehicle::Dismiss()
|
||||
RemoveAllPassengers();
|
||||
SendObjectDeSpawnAnim(GetGUID());
|
||||
CombatStop();
|
||||
CleanupsBeforeDelete();
|
||||
AddObjectToRemoveList();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user