Skip to content

Commit

Permalink
[9575] Use ObjectGuid in Map object stores/world access/search.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed Mar 12, 2010
1 parent f44feb9 commit 0caa5b5
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/game/BattleGround.cpp
Expand Up @@ -201,7 +201,7 @@ template<class Do>
void BattleGround::BroadcastWorker(Do& _do)
{
for(BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
if (Player *plr = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER)))
if (Player *plr = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
_do(plr);
}

Expand Down
7 changes: 3 additions & 4 deletions src/game/GameEventMgr.cpp
Expand Up @@ -594,7 +594,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
{
sObjectMgr.RemoveCreatureFromGrid(*itr, data);

if( Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT)) )
if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(ObjectGuid(HIGHGUID_UNIT, data->id, *itr)))
pCreature->AddObjectToRemoveList();
}
}
Expand All @@ -612,7 +612,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
{
sObjectMgr.RemoveGameobjectFromGrid(*itr, data);

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

// Update if spawned
Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(itr->first, data->id,HIGHGUID_UNIT));
if (pCreature)
if (Creature* pCreature = ObjectAccessor::GetCreatureInWorld(ObjectGuid(HIGHGUID_UNIT, data->id, itr->first)))
{
if (activate)
{
Expand Down
16 changes: 8 additions & 8 deletions src/game/Guild.cpp
Expand Up @@ -551,7 +551,7 @@ void Guild::BroadcastToGuild(WorldSession *session, const std::string& msg, uint

for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player *pl = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));

if (pl && pl->GetSession() && HasRankRight(pl->GetRank(),GR_RIGHT_GCHATLISTEN) && !pl->GetSocial()->HasIgnore(session->GetPlayer()->GetGUIDLow()) )
pl->GetSession()->SendPacket(&data);
Expand All @@ -568,7 +568,7 @@ void Guild::BroadcastToOfficers(WorldSession *session, const std::string& msg, u
WorldPacket data;
ChatHandler::FillMessageData(&data, session, CHAT_MSG_OFFICER, language, NULL, 0, msg.c_str(), NULL);

Player *pl = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));

if (pl && pl->GetSession() && HasRankRight(pl->GetRank(),GR_RIGHT_OFFCHATLISTEN) && !pl->GetSocial()->HasIgnore(session->GetPlayer()->GetGUIDLow()))
pl->GetSession()->SendPacket(&data);
Expand All @@ -580,7 +580,7 @@ void Guild::BroadcastPacket(WorldPacket *packet)
{
for(MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player *player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (player)
player->GetSession()->SendPacket(packet);
}
Expand All @@ -592,7 +592,7 @@ void Guild::BroadcastPacketToRank(WorldPacket *packet, uint32 rankId)
{
if (itr->second.RankId == rankId)
{
Player *player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (player)
player->GetSession()->SendPacket(packet);
}
Expand Down Expand Up @@ -731,7 +731,7 @@ void Guild::Roster(WorldSession *session /*= NULL*/)
}
for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
if (Player *pl = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER)))
if (Player *pl = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
{
data << uint64(pl->GetGUID());
data << uint8(1);
Expand All @@ -746,7 +746,7 @@ void Guild::Roster(WorldSession *session /*= NULL*/)
}
else
{
data << uint64(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
data << uint64(ObjectGuid(HIGHGUID_PLAYER, itr->first).GetRawValue());
data << uint8(0);
data << itr->second.Name;
data << uint32(itr->second.RankId);
Expand Down Expand Up @@ -976,7 +976,7 @@ void Guild::DisplayGuildBankContentUpdate(uint8 TabId, int32 slot1, int32 slot2)

for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player *player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (!player)
continue;

Expand Down Expand Up @@ -1011,7 +1011,7 @@ void Guild::DisplayGuildBankContentUpdate(uint8 TabId, GuildItemPosCountVec cons

for (MemberList::const_iterator itr = members.begin(); itr != members.end(); ++itr)
{
Player *player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER));
Player *player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first));
if (!player)
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/game/Guild.h
Expand Up @@ -343,7 +343,7 @@ class Guild
void BroadcastWorker(Do& _do, Player* except = NULL)
{
for(MemberList::iterator itr = members.begin(); itr != members.end(); ++itr)
if(Player *player = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER)))
if(Player *player = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, itr->first)))
if(player != except)
_do(player);
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/Level1.cpp
Expand Up @@ -261,7 +261,7 @@ bool ChatHandler::HandleGPSCommand(const char* args)
{
uint64 guid = extractGuidFromLink((char*)args);
if(guid)
obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
obj = (WorldObject*)m_session->GetPlayer()->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);

if(!obj)
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/Level3.cpp
Expand Up @@ -3407,7 +3407,7 @@ bool ChatHandler::HandleGetDistanceCommand(const char* args)
{
uint64 guid = extractGuidFromLink((char*)args);
if(guid)
obj = (WorldObject*)ObjectAccessor::GetObjectByTypeMask(*m_session->GetPlayer(),guid,TYPEMASK_UNIT|TYPEMASK_GAMEOBJECT);
obj = (WorldObject*)m_session->GetPlayer()->GetObjectByTypeMask(guid, TYPEMASK_CREATURE_OR_GAMEOBJECT);

if(!obj)
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/LootHandler.cpp
Expand Up @@ -453,7 +453,7 @@ void WorldSession::HandleLootMasterGiveOpcode( WorldPacket & recv_data )
return;
}

Player *target = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(target_playerguid, 0, HIGHGUID_PLAYER));
Player *target = ObjectAccessor::FindPlayer(ObjectGuid(HIGHGUID_PLAYER, target_playerguid));
if(!target)
return;

Expand Down
45 changes: 22 additions & 23 deletions src/game/Map.cpp
Expand Up @@ -3497,22 +3497,22 @@ void Map::ScriptsProcess()
return;
}

Creature* Map::GetCreature(uint64 guid)
Creature* Map::GetCreature(ObjectGuid guid)
{
return m_objectsStore.find<Creature>(guid, (Creature*)NULL);
return m_objectsStore.find<Creature>(guid.GetRawValue(), (Creature*)NULL);
}

Vehicle* Map::GetVehicle(uint64 guid)
Vehicle* Map::GetVehicle(ObjectGuid guid)
{
return m_objectsStore.find<Vehicle>(guid, (Vehicle*)NULL);
return m_objectsStore.find<Vehicle>(guid.GetRawValue(), (Vehicle*)NULL);
}

Pet* Map::GetPet(uint64 guid)
Pet* Map::GetPet(ObjectGuid guid)
{
return m_objectsStore.find<Pet>(guid, (Pet*)NULL);
return m_objectsStore.find<Pet>(guid.GetRawValue(), (Pet*)NULL);
}

Corpse* Map::GetCorpse(uint64 guid)
Corpse* Map::GetCorpse(ObjectGuid guid)
{
Corpse * ret = ObjectAccessor::GetCorpseInMap(guid,GetId());
if (!ret)
Expand All @@ -3522,33 +3522,32 @@ Corpse* Map::GetCorpse(uint64 guid)
return ret;
}

Creature* Map::GetCreatureOrPetOrVehicle(uint64 guid)
Creature* Map::GetCreatureOrPetOrVehicle(ObjectGuid guid)
{
if (IS_PLAYER_GUID(guid))
return NULL;

if (IS_PET_GUID(guid))
return GetPet(guid);

if (IS_VEHICLE_GUID(guid))
return GetVehicle(guid);
switch(guid.GetHigh())
{
case HIGHGUID_UNIT: return GetCreature(guid);
case HIGHGUID_PET: return GetPet(guid);
case HIGHGUID_VEHICLE: return GetVehicle(guid);
default: break;
}

return GetCreature(guid);
return NULL;
}

GameObject* Map::GetGameObject(uint64 guid)
GameObject* Map::GetGameObject(ObjectGuid guid)
{
return m_objectsStore.find<GameObject>(guid, (GameObject*)NULL);
return m_objectsStore.find<GameObject>(guid.GetRawValue(), (GameObject*)NULL);
}

DynamicObject* Map::GetDynamicObject(uint64 guid)
DynamicObject* Map::GetDynamicObject(ObjectGuid guid)
{
return m_objectsStore.find<DynamicObject>(guid, (DynamicObject*)NULL);
return m_objectsStore.find<DynamicObject>(guid.GetRawValue(), (DynamicObject*)NULL);
}

WorldObject* Map::GetWorldObject(uint64 guid)
WorldObject* Map::GetWorldObject(ObjectGuid guid)
{
switch(GUID_HIPART(guid))
switch(guid.GetHigh())
{
case HIGHGUID_PLAYER: return ObjectAccessor::FindPlayer(guid);
case HIGHGUID_GAMEOBJECT: return GetGameObject(guid);
Expand Down
16 changes: 8 additions & 8 deletions src/game/Map.h
Expand Up @@ -396,14 +396,14 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj

void RemoveFromActive(Creature* obj);

Creature* GetCreature(uint64 guid);
Vehicle* GetVehicle(uint64 guid);
Pet* GetPet(uint64 guid);
Creature* GetCreatureOrPetOrVehicle(uint64 guid);
GameObject* GetGameObject(uint64 guid);
DynamicObject* GetDynamicObject(uint64 guid);
Corpse* GetCorpse(uint64 guid);
WorldObject* GetWorldObject(uint64 guid);
Creature* GetCreature(ObjectGuid guid);
Vehicle* GetVehicle(ObjectGuid guid);
Pet* GetPet(ObjectGuid guid);
Creature* GetCreatureOrPetOrVehicle(ObjectGuid guid);
GameObject* GetGameObject(ObjectGuid guid);
DynamicObject* GetDynamicObject(ObjectGuid guid);
Corpse* GetCorpse(ObjectGuid guid);
WorldObject* GetWorldObject(ObjectGuid guid);

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

Expand Down
57 changes: 8 additions & 49 deletions src/game/ObjectAccessor.cpp
Expand Up @@ -54,12 +54,12 @@ ObjectAccessor::~ObjectAccessor()
}

Unit*
ObjectAccessor::GetUnit(WorldObject const &u, uint64 guid)
ObjectAccessor::GetUnit(WorldObject const &u, ObjectGuid guid)
{
if(!guid)
if(guid.IsEmpty())
return NULL;

if(IS_PLAYER_GUID(guid))
if(guid.IsPlayer())
return FindPlayer(guid);

if (!u.IsInWorld())
Expand All @@ -68,7 +68,7 @@ ObjectAccessor::GetUnit(WorldObject const &u, uint64 guid)
return u.GetMap()->GetCreatureOrPetOrVehicle(guid);
}

Corpse* ObjectAccessor::GetCorpseInMap( uint64 guid, uint32 mapid )
Corpse* ObjectAccessor::GetCorpseInMap(ObjectGuid guid, uint32 mapid)
{
Corpse * ret = HashMapHolder<Corpse>::Find(guid);
if(!ret)
Expand All @@ -79,49 +79,8 @@ Corpse* ObjectAccessor::GetCorpseInMap( uint64 guid, uint32 mapid )
return ret;
}

Object* ObjectAccessor::GetObjectByTypeMask(WorldObject const &p, uint64 guid, uint32 typemask)
{
switch(GUID_HIPART(guid))
{
case HIGHGUID_ITEM:
if(typemask & TYPEMASK_ITEM && p.GetTypeId() == TYPEID_PLAYER)
return ((Player const &)p).GetItemByGuid( guid );
break;
case HIGHGUID_PLAYER:
if(typemask & TYPEMASK_PLAYER)
return FindPlayer(guid);
break;
case HIGHGUID_GAMEOBJECT:
if(typemask & TYPEMASK_GAMEOBJECT)
return p.GetMap()->GetGameObject(guid);
break;
case HIGHGUID_UNIT:
if(typemask & TYPEMASK_UNIT)
return p.GetMap()->GetCreature(guid);
break;
case HIGHGUID_PET:
if(typemask & TYPEMASK_UNIT)
return p.GetMap()->GetPet(guid);
break;
case HIGHGUID_VEHICLE:
if(typemask & TYPEMASK_UNIT)
return p.GetMap()->GetVehicle(guid);
break;
case HIGHGUID_DYNAMICOBJECT:
if(typemask & TYPEMASK_DYNAMICOBJECT)
return p.GetMap()->GetDynamicObject(guid);
break;
case HIGHGUID_TRANSPORT:
case HIGHGUID_CORPSE:
case HIGHGUID_MO_TRANSPORT:
break;
}

return NULL;
}

Player*
ObjectAccessor::FindPlayer(uint64 guid)
ObjectAccessor::FindPlayer(ObjectGuid guid)
{
Player * plr = HashMapHolder<Player>::Find(guid);;
if(!plr || !plr->IsInWorld())
Expand Down Expand Up @@ -163,11 +122,11 @@ void ObjectAccessor::KickPlayer(uint64 guid)
}

Corpse*
ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid)
{
Guard guard(i_corpseGuard);

Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid.GetRawValue());
if( iter == i_player2corpse.end() ) return NULL;

assert(iter->second->GetType() != CORPSE_BONES);
Expand Down Expand Up @@ -234,7 +193,7 @@ ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair,GridType& grid,Map* ma
}

Corpse*
ObjectAccessor::ConvertCorpseForPlayer(uint64 player_guid, bool insignia)
ObjectAccessor::ConvertCorpseForPlayer(ObjectGuid player_guid, bool insignia)
{
Corpse *corpse = GetCorpseForPlayerGUID(player_guid);
if(!corpse)
Expand Down

1 comment on commit 0caa5b5

@VladimirMangos
Copy link

Choose a reason for hiding this comment

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

Read code? More wide use ObjectGuid instead raw uint64. This more work in this direction. In fact nothing intresting fro users.

Please sign in to comment.