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()
This commit is contained in:
1 parent
46863b3afa
commit
49ececf038
6 files changed
+12
-10
No files matched your search
@@ -23,6 +23,7 @@
|
|||||||
#include "ByteBuffer.h"
|
#include "ByteBuffer.h"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
enum TypeID
|
enum TypeID
|
||||||
{
|
{
|
||||||
@@ -202,6 +203,7 @@ typedef std::set<ObjectGuid> GuidSet;
|
|||||||
typedef std::list<ObjectGuid> GuidList;
|
typedef std::list<ObjectGuid> GuidList;
|
||||||
typedef std::deque<ObjectGuid> GuidDeque;
|
typedef std::deque<ObjectGuid> GuidDeque;
|
||||||
typedef std::vector<ObjectGuid> GuidVector;
|
typedef std::vector<ObjectGuid> GuidVector;
|
||||||
|
typedef std::unordered_set<ObjectGuid> GuidUnorderedSet;
|
||||||
|
|
||||||
// minimum buffer size for packed guid is 9 bytes
|
// minimum buffer size for packed guid is 9 bytes
|
||||||
#define PACKED_GUID_MIN_BUFFER_SIZE 9
|
#define PACKED_GUID_MIN_BUFFER_SIZE 9
|
||||||
|
|||||||
@@ -22560,13 +22560,13 @@ bool Player::IsVisibleGloballyFor(Player const* u) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
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());
|
s64.insert(target->GetGUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
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
|
// @HACK: This is to prevent objects like deeprun tram from disappearing when player moves far from its spawn point while riding it
|
||||||
if ((target->GetGOInfo()->type != GAMEOBJECT_TYPE_TRANSPORT))
|
if ((target->GetGOInfo()->type != GAMEOBJECT_TYPE_TRANSPORT))
|
||||||
@@ -22574,14 +22574,14 @@ inline void UpdateVisibilityOf_helper(GuidSet& s64, GameObject* target, std::set
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
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());
|
s64.insert(target->GetGUID());
|
||||||
v.insert(target);
|
v.insert(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
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());
|
s64.insert(target->GetGUID());
|
||||||
v.insert(target);
|
v.insert(target);
|
||||||
@@ -22643,7 +22643,7 @@ void Player::UpdateTriggerVisibility()
|
|||||||
|
|
||||||
UpdateData udata;
|
UpdateData udata;
|
||||||
WorldPacket packet;
|
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())
|
if (itr->IsCreature())
|
||||||
{
|
{
|
||||||
@@ -23702,7 +23702,7 @@ void Player::UpdateForQuestWorldObjects()
|
|||||||
|
|
||||||
UpdateData udata;
|
UpdateData udata;
|
||||||
WorldPacket packet;
|
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())
|
if (itr->IsGameObject())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2170,7 +2170,7 @@ class Player : public Unit, public GridObject<Player>
|
|||||||
WorldLocation GetStartPosition() const;
|
WorldLocation GetStartPosition() const;
|
||||||
|
|
||||||
// currently visible objects at player client
|
// currently visible objects at player client
|
||||||
GuidSet m_clientGUIDs;
|
GuidUnorderedSet m_clientGUIDs;
|
||||||
|
|
||||||
bool HaveAtClient(WorldObject const* u) const;
|
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_player.m_clientGUIDs.erase(*it);
|
||||||
i_data.AddOutOfRangeGUID(*it);
|
i_data.AddOutOfRangeGUID(*it);
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ namespace Trinity
|
|||||||
Player &i_player;
|
Player &i_player;
|
||||||
UpdateData i_data;
|
UpdateData i_data;
|
||||||
std::set<Unit*> i_visibleNow;
|
std::set<Unit*> i_visibleNow;
|
||||||
GuidSet vis_guids;
|
GuidUnorderedSet vis_guids;
|
||||||
|
|
||||||
VisibleNotifier(Player &player) : i_player(player), vis_guids(player.m_clientGUIDs) { }
|
VisibleNotifier(Player &player) : i_player(player), vis_guids(player.m_clientGUIDs) { }
|
||||||
template<class T> void Visit(GridRefManager<T> &m);
|
template<class T> void Visit(GridRefManager<T> &m);
|
||||||
|
|||||||
@@ -627,7 +627,7 @@ void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPacket& /*recvPacket
|
|||||||
WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
|
WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
|
||||||
data << uint32(count); // placeholder
|
data << uint32(count); // placeholder
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
uint32 questStatus = DIALOG_STATUS_NONE;
|
uint32 questStatus = DIALOG_STATUS_NONE;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user