Skip to content

Commit

Permalink
[8718] Remove most GetObjectInWorld functions and move some map local…
Browse files Browse the repository at this point in the history
… to Map

Also mape pet guid counter per-map (in different expecte to be global pet number)
  • Loading branch information
VladimirMangos committed Oct 23, 2009
1 parent fcef298 commit d4682be
Show file tree
Hide file tree
Showing 20 changed files with 135 additions and 132 deletions.
8 changes: 1 addition & 7 deletions src/game/AccountMgr.cpp
Expand Up @@ -71,13 +71,7 @@ AccountOpResult AccountMgr::DeleteAccount(uint32 accid)
uint64 guid = MAKE_NEW_GUID(guidlo, 0, HIGHGUID_PLAYER);

// kick if player currently
if(Player* p = ObjectAccessor::GetObjectInWorld(guid, (Player*)NULL))
{
WorldSession* s = p->GetSession();
s->KickPlayer(); // mark session to remove at next session list update
s->LogoutPlayer(false); // logout player without waiting next session list update
}

ObjectAccessor::KickPlayer(guid);
Player::DeleteFromDB(guid, accid, false); // no need to update realm characters
} while (result->NextRow());

Expand Down
2 changes: 1 addition & 1 deletion src/game/Corpse.cpp
Expand Up @@ -126,7 +126,7 @@ void Corpse::SaveToDB()
void Corpse::DeleteBonesFromWorld()
{
assert(GetType() == CORPSE_BONES);
Corpse* corpse = ObjectAccessor::GetCorpse(*this, GetGUID());
Corpse* corpse = GetMap()->GetCorpse(GetGUID());

if (!corpse)
{
Expand Down
6 changes: 3 additions & 3 deletions src/game/GameEventMgr.cpp
Expand Up @@ -603,7 +603,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) )
if( Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT)) )
pCreature->AddObjectToRemoveList();
}
}
Expand All @@ -621,7 +621,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
{
objmgr.RemoveGameobjectFromGrid(*itr, data);

if( GameObject* pGameobject = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_GAMEOBJECT), (GameObject*)NULL) )
if( GameObject* pGameobject = ObjectAccessor::Instance().GetGameObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_GAMEOBJECT)) )
pGameobject->AddObjectToRemoveList();
}
}
Expand All @@ -647,7 +647,7 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
continue;

// Update if spawned
Creature* pCreature = ObjectAccessor::Instance().GetObjectInWorld(MAKE_NEW_GUID(itr->first, data->id,HIGHGUID_UNIT), (Creature*)NULL);
Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(itr->first, data->id,HIGHGUID_UNIT));
if (pCreature)
{
if (activate)
Expand Down
2 changes: 1 addition & 1 deletion src/game/GridNotifiers.cpp
Expand Up @@ -129,7 +129,7 @@ VisibleNotifier::Notify()
if(!IS_PLAYER_GUID(*iter))
continue;

if (Player* plr = ObjectAccessor::GetPlayer(i_player,*iter))
if (Player* plr = ObjectAccessor::FindPlayer(*iter))
plr->UpdateVisibilityOf(plr->GetViewPoint(),&i_player);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/game/LootHandler.cpp
Expand Up @@ -67,7 +67,7 @@ void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data )
}
else if (IS_CORPSE_GUID(lguid))
{
Corpse *bones = ObjectAccessor::GetCorpse(*player, lguid);
Corpse *bones = player->GetMap()->GetCorpse(lguid);
if (!bones)
{
player->SendLootRelease(lguid);
Expand Down Expand Up @@ -180,7 +180,7 @@ void WorldSession::HandleLootMoneyOpcode( WorldPacket & /*recv_data*/ )
}
case HIGHGUID_CORPSE: // remove insignia ONLY in BG
{
Corpse *bones = ObjectAccessor::GetCorpse(*GetPlayer(), guid);
Corpse *bones = _player->GetMap()->GetCorpse(guid);

if (bones && bones->IsWithinDistInMap(_player,INTERACTION_DISTANCE) )
pLoot = &bones->loot;
Expand Down Expand Up @@ -367,7 +367,7 @@ void WorldSession::DoLootRelease( uint64 lguid )
}
else if (IS_CORPSE_GUID(lguid)) // ONLY remove insignia at BG
{
Corpse *corpse = ObjectAccessor::GetCorpse(*player, lguid);
Corpse *corpse = _player->GetMap()->GetCorpse(lguid);
if (!corpse || !corpse->IsWithinDistInMap(_player,INTERACTION_DISTANCE) )
return;

Expand Down
75 changes: 56 additions & 19 deletions src/game/Map.cpp
Expand Up @@ -203,7 +203,7 @@ Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _par
m_activeNonPlayersIter(m_activeNonPlayers.end()),
i_gridExpiry(expiry), m_parentMap(_parent ? _parent : this),
m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE),
m_hiDynObjectGuid(1), m_hiVehicleGuid(1)
m_hiDynObjectGuid(1), m_hiPetGuid(1), m_hiVehicleGuid(1)
{
for(unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx)
{
Expand Down Expand Up @@ -776,8 +776,8 @@ bool Map::RemoveBones(uint64 guid, float x, float y)
{
if (IsRemovalGrid(x, y))
{
Corpse* corpse = ObjectAccessor::GetObjectInWorld(guid, (Corpse*)NULL);
if(!corpse || corpse->GetMapId() != GetId())
Corpse* corpse = ObjectAccessor::GetCorpseInMap(guid,GetId());
if (!corpse)
return false;

CellPair p = MaNGOS::ComputeCellPair(x,y);
Expand Down Expand Up @@ -2146,28 +2146,29 @@ void Map::RemoveAllObjectsInRemoveList()
{
case TYPEID_CORPSE:
{
Corpse* corpse = ObjectAccessor::Instance().GetCorpse(*obj, obj->GetGUID());
// ??? WTF
Corpse* corpse = GetCorpse(obj->GetGUID());
if (!corpse)
sLog.outError("Try delete corpse/bones %u that not in map", obj->GetGUIDLow());
else
Remove(corpse,true);
break;
}
case TYPEID_DYNAMICOBJECT:
Remove((DynamicObject*)obj,true);
break;
case TYPEID_GAMEOBJECT:
Remove((GameObject*)obj,true);
break;
case TYPEID_UNIT:
// in case triggered sequence some spell can continue casting after prev CleanupsBeforeDelete call
// make sure that like sources auras/etc removed before destructor start
((Creature*)obj)->CleanupsBeforeDelete ();
Remove((Creature*)obj,true);
break;
default:
sLog.outError("Non-grid object (TypeId: %u) in grid object removing list, ignored.",obj->GetTypeId());
break;
case TYPEID_DYNAMICOBJECT:
Remove((DynamicObject*)obj,true);
break;
case TYPEID_GAMEOBJECT:
Remove((GameObject*)obj,true);
break;
case TYPEID_UNIT:
// in case triggered sequence some spell can continue casting after prev CleanupsBeforeDelete call
// make sure that like sources auras/etc removed before destructor start
((Creature*)obj)->CleanupsBeforeDelete ();
Remove((Creature*)obj,true);
break;
default:
sLog.outError("Non-grid object (TypeId: %u) in grid object removing list, ignored.",obj->GetTypeId());
break;
}
}
//sLog.outDebug("Object remover 2 check.");
Expand Down Expand Up @@ -3425,6 +3426,16 @@ Pet* Map::GetPet(uint64 guid)
return m_objectsStore.find<Pet>(guid, (Pet*)NULL);
}

Corpse* Map::GetCorpse(uint64 guid)
{
Corpse * ret = ObjectAccessor::GetCorpseInMap(guid,GetId());
if (!ret)
return NULL;
if (ret->GetInstanceId() != GetInstanceId())
return NULL;
return ret;
}

Creature* Map::GetCreatureOrPetOrVehicle(uint64 guid)
{
if (IS_PLAYER_GUID(guid))
Expand All @@ -3449,6 +3460,25 @@ DynamicObject* Map::GetDynamicObject(uint64 guid)
return m_objectsStore.find<DynamicObject>(guid, (DynamicObject*)NULL);
}

WorldObject* Map::GetWorldObject(uint64 guid)
{
switch(GUID_HIPART(guid))
{
case HIGHGUID_PLAYER: return ObjectAccessor::FindPlayer(guid);
case HIGHGUID_GAMEOBJECT: return GetGameObject(guid);
case HIGHGUID_UNIT: return GetCreature(guid);
case HIGHGUID_PET: return GetPet(guid);
case HIGHGUID_VEHICLE: return GetVehicle(guid);
case HIGHGUID_DYNAMICOBJECT:return GetDynamicObject(guid);
case HIGHGUID_CORPSE: return GetCorpse(guid);
case HIGHGUID_MO_TRANSPORT:
case HIGHGUID_TRANSPORT:
default: break;
}

return NULL;
}

void Map::SendObjectUpdates()
{
UpdateDataMapType update_players;
Expand Down Expand Up @@ -3483,6 +3513,13 @@ uint32 Map::GenerateLocalLowGuid(HighGuid guidhigh)
World::StopNow(ERROR_EXIT_CODE);
}
return m_hiDynObjectGuid++;
case HIGHGUID_PET:
if(m_hiPetGuid>=0x00FFFFFE)
{
sLog.outError("Pet guid overflow!! Can't continue, shutting down server. ");
World::StopNow(ERROR_EXIT_CODE);
}
return m_hiPetGuid++;
case HIGHGUID_VEHICLE:
if(m_hiVehicleGuid>=0x00FFFFFF)
{
Expand Down
3 changes: 3 additions & 0 deletions src/game/Map.h
Expand Up @@ -433,6 +433,8 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
Creature* GetCreatureOrPetOrVehicle(uint64 guid);
GameObject* GetGameObject(uint64 guid);
DynamicObject* GetDynamicObject(uint64 guid);
Corpse* GetCorpse(uint64 guid);
WorldObject* GetWorldObject(uint64 guid);

TypeUnorderedMapContainer<AllMapStoredObjectTypes>& GetObjectsStore() { return m_objectsStore; }

Expand Down Expand Up @@ -532,6 +534,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj

// Map local low guid counters
uint32 m_hiDynObjectGuid;
uint32 m_hiPetGuid;
uint32 m_hiVehicleGuid;

// Type specific code for add/remove to/from grid
Expand Down
41 changes: 15 additions & 26 deletions src/game/ObjectAccessor.cpp
Expand Up @@ -65,36 +65,15 @@ ObjectAccessor::GetUnit(WorldObject const &u, uint64 guid)
return u.GetMap()->GetCreatureOrPetOrVehicle(guid);
}

Corpse*
ObjectAccessor::GetCorpse(WorldObject const &u, uint64 guid)
Corpse* ObjectAccessor::GetCorpseInMap( uint64 guid, uint32 mapid )
{
Corpse * ret = GetObjectInWorld(guid, (Corpse*)NULL);
Corpse * ret = HashMapHolder<Corpse>::Find(guid);
if(!ret)
return NULL;
if(ret->GetMapId() != u.GetMapId())
return NULL;
if(ret->GetInstanceId() != u.GetInstanceId())
if(ret->GetMapId() != mapid)
return NULL;
return ret;
}

WorldObject* ObjectAccessor::GetWorldObject(WorldObject const &p, uint64 guid)
{
switch(GUID_HIPART(guid))
{
case HIGHGUID_PLAYER: return FindPlayer(guid);
case HIGHGUID_GAMEOBJECT: return p.GetMap()->GetGameObject(guid);
case HIGHGUID_UNIT: return p.GetMap()->GetCreature(guid);
case HIGHGUID_PET: return p.GetMap()->GetPet(guid);
case HIGHGUID_VEHICLE: return p.GetMap()->GetVehicle(guid);
case HIGHGUID_DYNAMICOBJECT:return p.GetMap()->GetDynamicObject(guid);
case HIGHGUID_TRANSPORT: return NULL;
case HIGHGUID_CORPSE: return GetCorpse(p,guid);
case HIGHGUID_MO_TRANSPORT: return NULL;
default: break;
}

return NULL;
return ret;
}

Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const &p, uint64 guid, uint32 typemask)
Expand Down Expand Up @@ -141,7 +120,7 @@ Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const &p, uint64 guid, u
Player*
ObjectAccessor::FindPlayer(uint64 guid)
{
Player * plr = GetObjectInWorld(guid, (Player*)NULL);
Player * plr = HashMapHolder<Player>::Find(guid);;
if(!plr || !plr->IsInWorld())
return NULL;

Expand Down Expand Up @@ -170,6 +149,16 @@ ObjectAccessor::SaveAllPlayers()
itr->second->SaveToDB();
}

void ObjectAccessor::KickPlayer(uint64 guid)
{
if (Player* p = HashMapHolder<Player>::Find(guid))
{
WorldSession* s = p->GetSession();
s->KickPlayer(); // mark session to remove at next session list update
s->LogoutPlayer(false); // logout player without waiting next session list update
}
}

Corpse*
ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
{
Expand Down
59 changes: 25 additions & 34 deletions src/game/ObjectAccessor.h
Expand Up @@ -88,46 +88,43 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
public:
typedef UNORDERED_MAP<uint64, Corpse* > Player2CorpsesMapType;

// global
static Player* GetObjectInWorld(uint64 guid, Player* /*fake*/) { return HashMapHolder<Player>::Find(guid); }
static Corpse* GetObjectInWorld(uint64 guid, Corpse* /*fake*/) { return HashMapHolder<Corpse>::Find(guid); }
static Unit* GetObjectInWorld(uint64 guid, Unit* /*fake*/);

// map local object with global search
static Creature* GetObjectInWorld(uint64 guid, Creature* /*fake*/) { return FindHelper<Creature>(guid); }
static GameObject* GetObjectInWorld(uint64 guid, GameObject* /*fake*/) { return FindHelper<GameObject>(guid); }
static Pet* GetObjectInWorld(uint64 guid, Pet* /*fake*/) { return FindHelper<Pet>(guid); }
static Vehicle* GetObjectInWorld(uint64 guid, Vehicle* /*fake*/); // no implementation, link error trap until creature move to Map

static WorldObject* GetWorldObject(WorldObject const &, uint64);
static Object* GetObjectByTypeMask(WorldObject const &, uint64, uint32 typemask);
// global (obj used for map only location local guid objects (pets currently)
static Unit* GetUnitInWorld(WorldObject const& obj, uint64 guid);

// FIXME: map local object with global search
static Creature* GetCreatureInWorld(uint64 guid) { return FindHelper<Creature>(guid); }
static GameObject* GetGameObjectInWorld(uint64 guid) { return FindHelper<GameObject>(guid); }

// possible local search for specific object map
static Object* GetObjectByTypeMask(WorldObject const &, uint64, uint32 typemask);
static Unit* GetUnit(WorldObject const &, uint64);
static Player* GetPlayer(Unit const &, uint64 guid) { return FindPlayer(guid); }
static Corpse* GetCorpse(WorldObject const &u, uint64 guid);
static Pet* GetPet(uint64 guid) { return GetObjectInWorld(guid, (Pet*)NULL); }
static Player* FindPlayer(uint64);

Player* FindPlayerByName(const char *name) ;
// Player access
static Player* FindPlayer(uint64 guid);
static Player* FindPlayerByName(const char *name);
static void KickPlayer(uint64 guid);

HashMapHolder<Player>::MapType& GetPlayers()
{
return HashMapHolder<Player>::GetContainer();
}

// For call from Player/Corpse AddToWorld/RemoveFromWorld only
void AddObject(Corpse *object) { HashMapHolder<Corpse>::Insert(object); }
void AddObject(Player *object) { HashMapHolder<Player>::Insert(object); }
void RemoveObject(Corpse *object) { HashMapHolder<Corpse>::Remove(object); }
void RemoveObject(Player *object) { HashMapHolder<Player>::Remove(object); }

void SaveAllPlayers();

// Corpse access
Corpse* GetCorpseForPlayerGUID(uint64 guid);
static Corpse* GetCorpseInMap(uint64 guid, uint32 mapid);
void RemoveCorpse(Corpse *corpse);
void AddCorpse(Corpse* corpse);
void AddCorpsesToGrid(GridPair const& gridpair,GridType& grid,Map* map);
Corpse* ConvertCorpseForPlayer(uint64 player_guid, bool insignia = false);

// For call from Player/Corpse AddToWorld/RemoveFromWorld only
void AddObject(Corpse *object) { HashMapHolder<Corpse>::Insert(object); }
void AddObject(Player *object) { HashMapHolder<Player>::Insert(object); }
void RemoveObject(Corpse *object) { HashMapHolder<Corpse>::Remove(object); }
void RemoveObject(Player *object) { HashMapHolder<Player>::Remove(object); }

// TODO: This methods will need lock in MT environment
static void LinkMap(Map* map) { i_mapList.push_back(map); }
static void DelinkMap(Map* map) { i_mapList.remove(map); }
Expand Down Expand Up @@ -159,24 +156,18 @@ class MANGOS_DLL_DECL ObjectAccessor : public MaNGOS::Singleton<ObjectAccessor,
LockType i_corpseGuard;
};

inline Unit* ObjectAccessor::GetObjectInWorld(uint64 guid, Unit* /*fake*/)
inline Unit* ObjectAccessor::GetUnitInWorld(WorldObject const& obj, uint64 guid)
{
if(!guid)
return NULL;

if (IS_PLAYER_GUID(guid))
{
Unit * u = (Unit*)HashMapHolder<Player>::Find(guid);
if(!u || !u->IsInWorld())
return NULL;

return u;
}
return FindPlayer(guid);

if (IS_PET_GUID(guid))
return GetObjectInWorld(guid, (Pet*)NULL);
return obj.IsInWorld() ? obj.GetMap()->GetPet(guid) : NULL;

return GetObjectInWorld(guid, (Creature*)NULL);
return GetCreatureInWorld(guid);
}

#endif

1 comment on commit d4682be

@NetSky
Copy link

@NetSky NetSky commented on d4682be Oct 24, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx a lot problems seem to be gone now :D

Please sign in to comment.