diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game/Map.cpp | 77 | ||||
-rw-r--r-- | src/game/Map.h | 3 | ||||
-rw-r--r-- | src/game/Unit.cpp | 21 | ||||
-rw-r--r-- | src/game/Unit.h | 3 |
4 files changed, 64 insertions, 40 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp index 3af876f6fde..e798a022671 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -370,16 +370,16 @@ void Map::AddNotifier(T*) template<> void Map::AddNotifier(Player* obj) { - obj->m_Notified = false; - obj->m_IsInNotifyList = false; + //obj->m_Notified = false; + //obj->m_IsInNotifyList = false; AddUnitToNotify(obj); } template<> void Map::AddNotifier(Creature* obj) { - obj->m_Notified = false; - obj->m_IsInNotifyList = false; + //obj->m_Notified = false; + //obj->m_IsInNotifyList = false; AddUnitToNotify(obj); } @@ -561,25 +561,21 @@ bool Map::loaded(const GridPair &p) const void Map::RelocationNotify() { - //Move backlog to notify list - for(std::vector<uint64>::iterator iter = i_unitsToNotifyBacklog.begin(); iter != i_unitsToNotifyBacklog.end(); ++iter) - { - if(Unit *unit = ObjectAccessor::GetObjectInWorld(*iter, (Unit*)NULL)) - { - i_unitsToNotify.push_back(unit); - } - } - i_unitsToNotifyBacklog.clear(); + i_lock = true; //Notify for(std::vector<Unit*>::iterator iter = i_unitsToNotify.begin(); iter != i_unitsToNotify.end(); ++iter) { Unit *unit = *iter; - if(unit->m_Notified || !unit->IsInWorld() || unit->GetMapId() != GetId()) + if(!unit) + continue; + + unit->m_NotifyListPos = -1; + + if(unit->m_Notified) continue; unit->m_Notified = true; - unit->m_IsInNotifyList = false; float dist = abs(unit->GetPositionX() - unit->oldX) + abs(unit->GetPositionY() - unit->oldY); if(dist > 10.0f) @@ -592,10 +588,10 @@ void Map::RelocationNotify() if(unit->GetTypeId() == TYPEID_PLAYER) { Trinity::PlayerRelocationNotifier notifier(*((Player*)unit)); - if(((Player*)unit)->m_seer != unit) + //if(((Player*)unit)->m_seer != unit) VisitAll(((Player*)unit)->m_seer->GetPositionX(), ((Player*)unit)->m_seer->GetPositionY(), World::GetMaxVisibleDistance() + dist, notifier); - else - VisitAll(((Player*)unit)->GetPositionX(), ((Player*)unit)->GetPositionY(), World::GetMaxVisibleDistance() + dist, notifier); + //else + //VisitAll(((Player*)unit)->GetPositionX(), ((Player*)unit)->GetPositionY(), World::GetMaxVisibleDistance() + dist, notifier); notifier.Notify(); } else @@ -609,27 +605,52 @@ void Map::RelocationNotify() (*iter)->m_Notified = false; } i_unitsToNotify.clear(); + + i_lock = false; + + if(!i_unitsToNotifyBacklog.empty()) + { + i_unitsToNotify.insert(i_unitsToNotify.end(), i_unitsToNotifyBacklog.begin(), i_unitsToNotifyBacklog.end()); + i_unitsToNotifyBacklog.clear(); + } } void Map::AddUnitToNotify(Unit* u) { - if(u->m_IsInNotifyList) - return; + if(u->m_NotifyListPos < 0) + { + u->oldX = u->GetPositionX(); + u->oldY = u->GetPositionY(); - u->m_IsInNotifyList = true; - u->oldX = u->GetPositionX(); - u->oldY = u->GetPositionY(); + if(i_lock) + { + u->m_NotifyListPos = i_unitsToNotifyBacklog.size(); + i_unitsToNotifyBacklog.push_back(u); + } + else + { + u->m_NotifyListPos = i_unitsToNotify.size(); + i_unitsToNotify.push_back(u); + } + } +} +void Map::RemoveUnitFromNotify(int32 slot) +{ if(i_lock) - i_unitsToNotifyBacklog.push_back(u->GetGUID()); + { + assert(slot < i_unitsToNotifyBacklog.size()); + i_unitsToNotifyBacklog[slot] = NULL; + } else - i_unitsToNotify.push_back(u); + { + assert(slot < i_unitsToNotify.size()); + i_unitsToNotify[slot] = NULL; + } } void Map::Update(const uint32 &t_diff) { - i_lock = false; - resetMarkedCells(); Trinity::ObjectUpdater updater(t_diff); @@ -734,8 +755,6 @@ void Map::Update(const uint32 &t_diff) } } - i_lock = true; - MoveAllCreaturesInMoveList(); RelocationNotify(); RemoveAllObjectsInRemoveList(); diff --git a/src/game/Map.h b/src/game/Map.h index 9e9f7a9d402..e40c6118ea6 100644 --- a/src/game/Map.h +++ b/src/game/Map.h @@ -388,6 +388,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj bool ActiveObjectsNearGrid(uint32 x, uint32 y) const; void AddUnitToNotify(Unit* unit); + void RemoveUnitFromNotify(int32 slot); void RelocationNotify(); void SendToPlayers(WorldPacket const* data) const; @@ -496,7 +497,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj time_t i_gridExpiry; bool i_lock; - std::vector<uint64> i_unitsToNotifyBacklog; + std::vector<Unit*> i_unitsToNotifyBacklog; std::vector<Unit*> i_unitsToNotify; std::set<WorldObject *> i_objectsToRemove; std::map<WorldObject*, bool> i_objectsToSwitch; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 79e31ce6dce..e845dff66cf 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -80,7 +80,7 @@ static bool procPrepared = InitTriggerAuraData(); Unit::Unit() : WorldObject(), i_motionMaster(this), m_ThreatManager(this), m_HostilRefManager(this) -, m_IsInNotifyList(false), m_Notified(false), IsAIEnabled(false), NeedChangeAI(false) +, m_NotifyListPos(-1), m_Notified(false), IsAIEnabled(false), NeedChangeAI(false) , i_AI(NULL), i_disabledAI(NULL), m_removedAurasCount(0), m_Vehicle(NULL), m_transport(NULL) , m_ControlledByPlayer(false), m_procDeep(0) { @@ -10448,8 +10448,7 @@ void Unit::SetVisibility(UnitVisibility x) { m_Visibility = x; - if(IsInWorld()) - SetToNotify(); + SetToNotify(); if(x == VISIBILITY_GROUP_STEALTH) DestroyForNearbyPlayers(); @@ -11683,7 +11682,7 @@ void Unit::AddToWorld() { WorldObject::AddToWorld(); m_Notified = false; - m_IsInNotifyList = false; + assert(m_NotifyListPos < 0); SetToNotify(); } } @@ -11702,6 +11701,12 @@ void Unit::RemoveFromWorld() RemoveNotOwnSingleTargetAuras(); ExitVehicle(); + if(m_NotifyListPos >= 0) + { + GetMap()->RemoveUnitFromNotify(m_NotifyListPos); + m_NotifyListPos = -1; + } + if(GetCharmerGUID()) { sLog.outCrash("Unit %u has charmer guid when removed from world", GetEntry()); @@ -13227,11 +13232,9 @@ bool Unit::HandleAuraRaidProcFromCharge( AuraEffect* triggeredByAura ) void Unit::SetToNotify() { - if(m_IsInNotifyList) - return; - - if(Map *map = GetMap()) - map->AddUnitToNotify(this); + // it is called somewhere when obj is not in world (crash when log in instance) + if(m_NotifyListPos < 0 && IsInWorld()) + GetMap()->AddUnitToNotify(this); } void Unit::Kill(Unit *pVictim, bool durabilityLoss) diff --git a/src/game/Unit.h b/src/game/Unit.h index 65621ca02b7..5dea3b3304b 100644 --- a/src/game/Unit.h +++ b/src/game/Unit.h @@ -1722,7 +1722,8 @@ class TRINITY_DLL_SPEC Unit : public WorldObject // relocation notification void SetToNotify(); - bool m_Notified, m_IsInNotifyList; + bool m_Notified; + int32 m_NotifyListPos; float oldX, oldY; void SetReducedThreatPercent(uint32 pct, uint64 guid) |