Core/Player: Optimize Player::HaveAtClient() performance
Change m_clientGUIDs from std::set to std::unordered_set to reduce by 2.7x times the cpu usage in Player::HaveAtClient() (cherry picked from commit 49ececf03830ca1d3df45bec1cd7f657d309450b)
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <boost/functional/hash.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_set>
|
||||
|
||||
enum TypeID
|
||||
{
|
||||
@@ -266,6 +267,7 @@ typedef std::set<ObjectGuid> GuidSet;
|
||||
typedef std::list<ObjectGuid> GuidList;
|
||||
typedef std::deque<ObjectGuid> GuidDeque;
|
||||
typedef std::vector<ObjectGuid> GuidVector;
|
||||
typedef std::unordered_set<ObjectGuid> GuidUnorderedSet;
|
||||
|
||||
// maximum buffer size for packed guid is 18 bytes
|
||||
#define PACKED_GUID_MIN_BUFFER_SIZE 18
|
||||
|
||||
@@ -22042,13 +22042,13 @@ bool Player::IsVisibleGloballyFor(Player const* u) const
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline void UpdateVisibilityOf_helper(GuidSet& s64, T* target, std::set<Unit*>& /*v*/)
|
||||
inline void UpdateVisibilityOf_helper(GuidUnorderedSet& s64, T* target, std::set<Unit*>& /*v*/)
|
||||
{
|
||||
s64.insert(target->GetGUID());
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void UpdateVisibilityOf_helper(GuidSet& s64, GameObject* target, std::set<Unit*>& /*v*/)
|
||||
inline void UpdateVisibilityOf_helper(GuidUnorderedSet& s64, GameObject* target, std::set<Unit*>& /*v*/)
|
||||
{
|
||||
// @HACK: This is to prevent objects like deeprun tram from disappearing when player moves far from its spawn point while riding it
|
||||
// But exclude stoppable elevators from this hack - they would be teleporting from one end to another
|
||||
@@ -22059,14 +22059,14 @@ inline void UpdateVisibilityOf_helper(GuidSet& s64, GameObject* target, std::set
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void UpdateVisibilityOf_helper(GuidSet& s64, Creature* target, std::set<Unit*>& v)
|
||||
inline void UpdateVisibilityOf_helper(GuidUnorderedSet& s64, Creature* target, std::set<Unit*>& v)
|
||||
{
|
||||
s64.insert(target->GetGUID());
|
||||
v.insert(target);
|
||||
}
|
||||
|
||||
template<>
|
||||
inline void UpdateVisibilityOf_helper(GuidSet& s64, Player* target, std::set<Unit*>& v)
|
||||
inline void UpdateVisibilityOf_helper(GuidUnorderedSet& s64, Player* target, std::set<Unit*>& v)
|
||||
{
|
||||
s64.insert(target->GetGUID());
|
||||
v.insert(target);
|
||||
@@ -22128,7 +22128,7 @@ void Player::UpdateTriggerVisibility()
|
||||
|
||||
UpdateData udata(GetMapId());
|
||||
WorldPacket packet;
|
||||
for (GuidSet::iterator itr = m_clientGUIDs.begin(); itr != m_clientGUIDs.end(); ++itr)
|
||||
for (auto itr = m_clientGUIDs.begin(); itr != m_clientGUIDs.end(); ++itr)
|
||||
{
|
||||
if (itr->IsCreature())
|
||||
{
|
||||
@@ -23235,7 +23235,7 @@ void Player::UpdateForQuestWorldObjects()
|
||||
|
||||
UpdateData udata(GetMapId());
|
||||
WorldPacket packet;
|
||||
for (GuidSet::iterator itr = m_clientGUIDs.begin(); itr != m_clientGUIDs.end(); ++itr)
|
||||
for (auto itr = m_clientGUIDs.begin(); itr != m_clientGUIDs.end(); ++itr)
|
||||
{
|
||||
if (itr->IsGameObject())
|
||||
{
|
||||
|
||||
@@ -2435,7 +2435,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
WorldLocation GetStartPosition() const;
|
||||
|
||||
// currently visible objects at player client
|
||||
GuidSet m_clientGUIDs;
|
||||
GuidUnorderedSet m_clientGUIDs;
|
||||
|
||||
bool HaveAtClient(WorldObject const* u) const;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ void VisibleNotifier::SendToSelf()
|
||||
}
|
||||
}
|
||||
|
||||
for (GuidSet::const_iterator it = vis_guids.begin(); it != vis_guids.end(); ++it)
|
||||
for (auto it = vis_guids.begin(); it != vis_guids.end(); ++it)
|
||||
{
|
||||
i_player.m_clientGUIDs.erase(*it);
|
||||
i_data.AddOutOfRangeGUID(*it);
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace Trinity
|
||||
Player &i_player;
|
||||
UpdateData i_data;
|
||||
std::set<Unit*> i_visibleNow;
|
||||
GuidSet vis_guids;
|
||||
GuidUnorderedSet vis_guids;
|
||||
|
||||
VisibleNotifier(Player &player) : i_player(player), i_data(player.GetMapId()), vis_guids(player.m_clientGUIDs) { }
|
||||
template<class T> void Visit(GridRefManager<T> &m);
|
||||
|
||||
@@ -619,7 +619,7 @@ void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPackets::Quest::Ques
|
||||
|
||||
WorldPackets::Quest::QuestGiverStatusMultiple response;
|
||||
|
||||
for (GuidSet::const_iterator itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
|
||||
for (auto itr = _player->m_clientGUIDs.begin(); itr != _player->m_clientGUIDs.end(); ++itr)
|
||||
{
|
||||
if (itr->IsAnyTypeCreature())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user