[11455] Use ObjectGuid in HashMapHolder

This commit is contained in:
VladimirMangos 2011-05-09 19:57:10 +04:00
parent b647835469
commit 51031c2d24
8 changed files with 42 additions and 40 deletions

View file

@ -146,42 +146,44 @@ void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers(); HashMapHolder<Player>::MapType& m = sObjectAccessor.GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{ {
Player* pl = itr->second;
if (security == SEC_PLAYER) if (security == SEC_PLAYER)
{ {
// player can see member of other team only if CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST // player can see member of other team only if CONFIG_BOOL_ALLOW_TWO_SIDE_WHO_LIST
if (itr->second->GetTeam() != team && !allowTwoSideWhoList ) if (pl->GetTeam() != team && !allowTwoSideWhoList )
continue; continue;
// player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
if (itr->second->GetSession()->GetSecurity() > gmLevelInWhoList) if (pl->GetSession()->GetSecurity() > gmLevelInWhoList)
continue; continue;
} }
// do not process players which are not in world // do not process players which are not in world
if(!(itr->second->IsInWorld())) if (!pl->IsInWorld())
continue; continue;
// check if target is globally visible for player // check if target is globally visible for player
if (!(itr->second->IsVisibleGloballyFor(_player))) if (!pl->IsVisibleGloballyFor(_player))
continue; continue;
// check if target's level is in level range // check if target's level is in level range
uint32 lvl = itr->second->getLevel(); uint32 lvl = pl->getLevel();
if (lvl < level_min || lvl > level_max) if (lvl < level_min || lvl > level_max)
continue; continue;
// check if class matches classmask // check if class matches classmask
uint32 class_ = itr->second->getClass(); uint32 class_ = pl->getClass();
if (!(classmask & (1 << class_))) if (!(classmask & (1 << class_)))
continue; continue;
// check if race matches racemask // check if race matches racemask
uint32 race = itr->second->getRace(); uint32 race = pl->getRace();
if (!(racemask & (1 << race))) if (!(racemask & (1 << race)))
continue; continue;
uint32 pzoneid = itr->second->GetZoneId(); uint32 pzoneid = pl->GetZoneId();
uint8 gender = itr->second->getGender(); uint8 gender = pl->getGender();
bool z_show = true; bool z_show = true;
for (uint32 i = 0; i < zones_count; ++i) for (uint32 i = 0; i < zones_count; ++i)
@ -197,7 +199,7 @@ void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
if (!z_show) if (!z_show)
continue; continue;
std::string pname = itr->second->GetName(); std::string pname = pl->GetName();
std::wstring wpname; std::wstring wpname;
if(!Utf8toWStr(pname,wpname)) if(!Utf8toWStr(pname,wpname))
continue; continue;
@ -206,7 +208,7 @@ void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos)) if (!(wplayer_name.empty() || wpname.find(wplayer_name) != std::wstring::npos))
continue; continue;
std::string gname = sGuildMgr.GetGuildNameById(itr->second->GetGuildId()); std::string gname = sGuildMgr.GetGuildNameById(pl->GetGuildId());
std::wstring wgname; std::wstring wgname;
if (!Utf8toWStr(gname,wgname)) if (!Utf8toWStr(gname,wgname))
continue; continue;
@ -216,7 +218,7 @@ void WorldSession::HandleWhoOpcode( WorldPacket & recv_data )
continue; continue;
std::string aname; std::string aname;
if(AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(itr->second->GetZoneId())) if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid))
aname = areaEntry->area_name[GetSessionDbcLocale()]; aname = areaEntry->area_name[GetSessionDbcLocale()];
bool s_show = true; bool s_show = true;

View file

@ -270,7 +270,7 @@ void ObjectAccessor::RemoveOldCorpses()
/// Define the static member of HashMapHolder /// Define the static member of HashMapHolder
template <class T> UNORDERED_MAP< uint64, T* > HashMapHolder<T>::m_objectMap; template <class T> typename HashMapHolder<T>::MapType HashMapHolder<T>::m_objectMap;
template <class T> ACE_RW_Thread_Mutex HashMapHolder<T>::i_lock; template <class T> ACE_RW_Thread_Mutex HashMapHolder<T>::i_lock;
/// Global definitions for the hashmap storage /// Global definitions for the hashmap storage

View file

@ -46,7 +46,7 @@ class HashMapHolder
{ {
public: public:
typedef UNORDERED_MAP< uint64, T* > MapType; typedef UNORDERED_MAP<ObjectGuid, T*> MapType;
typedef ACE_RW_Thread_Mutex LockType; typedef ACE_RW_Thread_Mutex LockType;
typedef ACE_Read_Guard<LockType> ReadGuard; typedef ACE_Read_Guard<LockType> ReadGuard;
typedef ACE_Write_Guard<LockType> WriteGuard; typedef ACE_Write_Guard<LockType> WriteGuard;
@ -54,19 +54,19 @@ class HashMapHolder
static void Insert(T* o) static void Insert(T* o)
{ {
WriteGuard guard(i_lock); WriteGuard guard(i_lock);
m_objectMap[o->GetGUID()] = o; m_objectMap[o->GetObjectGuid()] = o;
} }
static void Remove(T* o) static void Remove(T* o)
{ {
WriteGuard guard(i_lock); WriteGuard guard(i_lock);
m_objectMap.erase(o->GetGUID()); m_objectMap.erase(o->GetObjectGuid());
} }
static T* Find(ObjectGuid guid) static T* Find(ObjectGuid guid)
{ {
ReadGuard guard(i_lock); ReadGuard guard(i_lock);
typename MapType::iterator itr = m_objectMap.find(guid.GetRawValue()); typename MapType::iterator itr = m_objectMap.find(guid);
return (itr != m_objectMap.end()) ? itr->second : NULL; return (itr != m_objectMap.end()) ? itr->second : NULL;
} }

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "11454" #define REVISION_NR "11455"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__