From 23ef8a6dd6d286c4ad165729ad7efd221f1e744e Mon Sep 17 00:00:00 2001 From: megamage Date: Thu, 26 Feb 2009 17:01:02 -0600 Subject: [PATCH] *Fix a crash. --HG-- branch : trunk --- src/game/Map.cpp | 34 ++++++++++++++++++++++++++++++---- src/game/Map.h | 2 ++ src/game/Object.cpp | 10 +--------- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 6bbefa8b0a0..c6b0739b6bd 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -330,14 +330,14 @@ void Map::RemoveFromGrid(DynamicObject* obj, NGridType *grid, Cell const& cell) } template -void Map::SwitchGridContainers(T* obj, bool apply) +void Map::SwitchGridContainers(T* obj, bool on) { CellPair pair = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()); Cell cell(pair); NGridType *ngrid = getNGrid(cell.GridX(), cell.GridY()); GridType &grid = (*ngrid)(cell.CellX(), cell.CellY()); - if(apply) + if(on) { if(!grid.RemoveGridObject(obj, obj->GetGUID()) || !grid.AddWorldObject(obj, obj->GetGUID())) @@ -1589,10 +1589,36 @@ void Map::AddObjectToRemoveList(WorldObject *obj) //sLog.outDebug("Object (GUID: %u TypeId: %u ) added to removing list.",obj->GetGUIDLow(),obj->GetTypeId()); } +void Map::AddObjectToSwitchList(WorldObject *obj, bool on) +{ + assert(obj->GetMapId()==GetId() && obj->GetInstanceId()==GetInstanceId()); + + std::map::iterator itr = i_objectsToSwitch.find(obj); + if(itr == i_objectsToSwitch.end()) + i_objectsToSwitch.insert(itr, std::make_pair(obj, on)); + else if(itr->second != on) + i_objectsToSwitch.erase(itr); + else + assert(false); +} + void Map::RemoveAllObjectsInRemoveList() { - if(i_objectsToRemove.empty()) - return; + while(!i_objectsToSwitch.empty()) + { + std::map::iterator itr = i_objectsToSwitch.begin(); + WorldObject *obj = itr->first; + bool on = itr->second; + i_objectsToSwitch.erase(itr); + + switch(obj->GetTypeId()) + { + case TYPEID_UNIT: + if(!((Creature*)obj)->isPet()) + SwitchGridContainers((Creature*)obj, on); + break; + } + } //sLog.outDebug("Object remover 1 check."); while(!i_objectsToRemove.empty()) diff --git a/src/game/Map.h b/src/game/Map.h index 5f052c8806c..42e66996d3b 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -236,6 +236,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O bool IsBattleGroundOrArena() const { return i_mapEntry && i_mapEntry->IsBattleGroundOrArena(); } void AddObjectToRemoveList(WorldObject *obj); + void AddObjectToSwitchList(WorldObject *obj, bool on); void DoDelayedMovesAndRemoves(); virtual bool RemoveBones(uint64 guid, float x, float y); @@ -343,6 +344,7 @@ class TRINITY_DLL_SPEC Map : public GridRefManager, public Trinity::O bool i_lock; std::vector i_unitsToNotify; std::set i_objectsToRemove; + std::map i_objectsToSwitch; // Type specific code for add/remove to/from grid template diff --git a/src/game/Object.cpp b/src/game/Object.cpp index 1e0834ecf1f..62ad688e52e 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1075,15 +1075,7 @@ void WorldObject::SetWorldObject(bool on) if(!IsInWorld()) return; - if(GetTypeId() == TYPEID_UNIT) - { - if(!((Creature*)this)->isPet()) - GetMap()->SwitchGridContainers((Creature*)this, on); - } - /*else if(GetTypeId() == TYPEID_DYNAMICOBJECT) - { - GetMap()->SwitchGridContainers((DynamicObject*)this, on); - }*/ + GetMap()->AddObjectToSwitchList(this, on); } void WorldObject::setActive( bool on )