diff --git a/src/game/ChatCommands/Level0.cpp b/src/game/ChatCommands/Level0.cpp index 804a2aa6..ae628ace 100644 --- a/src/game/ChatCommands/Level0.cpp +++ b/src/game/ChatCommands/Level0.cpp @@ -171,7 +171,7 @@ bool ChatHandler::HandleGMListIngameCommand(char* /*args*/) std::list< std::pair > names; { - HashMapHolder::ReadGuard g(HashMapHolder::GetLock()); + ACE_READ_GUARD_RETURN(HashMapHolder::LockType, g, HashMapHolder::GetLock(), true) HashMapHolder::MapType& m = sObjectAccessor.GetPlayers(); for (HashMapHolder::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr) { diff --git a/src/game/Object/ObjectAccessor.cpp b/src/game/Object/ObjectAccessor.cpp index 6ddbb07e..0c4993f6 100644 --- a/src/game/Object/ObjectAccessor.cpp +++ b/src/game/Object/ObjectAccessor.cpp @@ -93,14 +93,11 @@ Player* ObjectAccessor::FindPlayer(ObjectGuid guid, bool inWorld /*= true*/) Player* ObjectAccessor::FindPlayerByName(const char* name) { - HashMapHolder::ReadGuard g(HashMapHolder::GetLock(), true); - if (g.locked()) - { - HashMapHolder::MapType& m = sObjectAccessor.GetPlayers(); - for (HashMapHolder::MapType::iterator iter = m.begin(); iter != m.end(); ++iter) - if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0)) - { return iter->second; } - } + ACE_READ_GUARD_RETURN(HashMapHolder::LockType, guard, HashMapHolder::GetLock(), NULL) + HashMapHolder::MapType& m = sObjectAccessor.GetPlayers(); + for (HashMapHolder::MapType::iterator iter = m.begin(); iter != m.end(); ++iter) + if (iter->second->IsInWorld() && (::strcmp(name, iter->second->GetName()) == 0)) + { return iter->second; } return NULL; } @@ -131,16 +128,15 @@ void ObjectAccessor::KickPlayer(ObjectGuid guid) Corpse* ObjectAccessor::GetCorpseForPlayerGUID(ObjectGuid guid) { - ACE_Guard guard(i_corpseGuard, true); - if (guard.locked()) - { - Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid); - if (iter == i_player2corpse.end()) - { return NULL; } - MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES); - return iter->second; - } - return NULL; + ACE_GUARD_RETURN(LockType, guard, i_corpseGuard, NULL) + + Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid); + + if (iter == i_player2corpse.end()) + { return NULL; } + + MANGOS_ASSERT(iter->second->GetType() != CORPSE_BONES); + return iter->second; } void @@ -148,22 +144,20 @@ ObjectAccessor::RemoveCorpse(Corpse* corpse) { MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES); - ACE_Guard guard(i_corpseGuard, true); - if (guard.locked()) - { - Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid()); - if (iter == i_player2corpse.end()) - { return; } + ACE_GUARD(LockType, guard, i_corpseGuard) - // build mapid*cellid -> guid_set map - CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); - uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGuid()); + if (iter == i_player2corpse.end()) + { return; } - sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter()); - corpse->RemoveFromWorld(); + // build mapid*cellid -> guid_set map + CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); + uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; - i_player2corpse.erase(iter); - } + sObjectMgr.DeleteCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter()); + corpse->RemoveFromWorld(); + + i_player2corpse.erase(iter); } void @@ -171,43 +165,39 @@ ObjectAccessor::AddCorpse(Corpse* corpse) { MANGOS_ASSERT(corpse && corpse->GetType() != CORPSE_BONES); - ACE_Guard guard(i_corpseGuard, true); - if (guard.locked()) - { - MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end()); - i_player2corpse[corpse->GetOwnerGuid()] = corpse; + ACE_GUARD(LockType, guard, i_corpseGuard) - // build mapid*cellid -> guid_set map - CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); - uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + MANGOS_ASSERT(i_player2corpse.find(corpse->GetOwnerGuid()) == i_player2corpse.end()); + i_player2corpse[corpse->GetOwnerGuid()] = corpse; - sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId()); - } + // build mapid*cellid -> guid_set map + CellPair cell_pair = MaNGOS::ComputeCellPair(corpse->GetPositionX(), corpse->GetPositionY()); + uint32 cell_id = (cell_pair.y_coord * TOTAL_NUMBER_OF_CELLS_PER_MAP) + cell_pair.x_coord; + + sObjectMgr.AddCorpseCellData(corpse->GetMapId(), cell_id, corpse->GetOwnerGuid().GetCounter(), corpse->GetInstanceId()); } void ObjectAccessor::AddCorpsesToGrid(GridPair const& gridpair, GridType& grid, Map* map) { - ACE_Guard guard(i_corpseGuard, true); - if (guard.locked()) - { - for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter) - if (iter->second->GetGrid() == gridpair) + ACE_GUARD(LockType, guard, i_corpseGuard) + + for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter) + if (iter->second->GetGrid() == gridpair) + { + // verify, if the corpse in our instance (add only corpses which are) + if (map->Instanceable()) { - // verify, if the corpse in our instance (add only corpses which are) - if (map->Instanceable()) - { - if (iter->second->GetInstanceId() == map->GetInstanceId()) - { - grid.AddWorldObject(iter->second); - } - } - else + if (iter->second->GetInstanceId() == map->GetInstanceId()) { grid.AddWorldObject(iter->second); } } - } + else + { + grid.AddWorldObject(iter->second); + } + } } Corpse* diff --git a/src/game/Object/ObjectAccessor.h b/src/game/Object/ObjectAccessor.h index 56a529af..18d3b6f9 100644 --- a/src/game/Object/ObjectAccessor.h +++ b/src/game/Object/ObjectAccessor.h @@ -54,33 +54,24 @@ class HashMapHolder typedef UNORDERED_MAP MapType; typedef ACE_RW_Thread_Mutex LockType; - typedef ACE_Read_Guard ReadGuard; - typedef ACE_Write_Guard WriteGuard; static void Insert(T* o) { - WriteGuard guard(i_lock, true); - if (guard.locked()) - m_objectMap[o->GetObjectGuid()] = o; + ACE_WRITE_GUARD(LockType, guard, i_lock) + m_objectMap[o->GetObjectGuid()] = o; } static void Remove(T* o) { - WriteGuard guard(i_lock, true); - if (guard.locked()) - m_objectMap.erase(o->GetObjectGuid()); + ACE_WRITE_GUARD(LockType, guard, i_lock) + m_objectMap.erase(o->GetObjectGuid()); } static T* Find(ObjectGuid guid) { - ReadGuard guard(i_lock, true); - if (guard.locked()) - { - typename MapType::iterator itr = m_objectMap.find(guid); - return (itr != m_objectMap.end()) ? itr->second : NULL; - } - else - return NULL; + ACE_READ_GUARD_RETURN (LockType, guard, i_lock, NULL) + typename MapType::iterator itr = m_objectMap.find(guid); + return (itr != m_objectMap.end()) ? itr->second : NULL; } static MapType& GetContainer() { return m_objectMap; } diff --git a/src/game/Object/Player.cpp b/src/game/Object/Player.cpp index 5ef069a8..017d53f5 100644 --- a/src/game/Object/Player.cpp +++ b/src/game/Object/Player.cpp @@ -18960,6 +18960,9 @@ void Player::_LoadSkills(QueryResult* result) case SKILL_RANGE_MONO: // 1..1, grey monolite bar value = max = 1; break; + case SKILL_RANGE_LEVEL: + max = GetMaxSkillValueForLevel(); // max value can be wrong for the actual level + break; default: break; }