mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
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:
@@ -23,6 +23,7 @@
|
||||
#include "ByteBuffer.h"
|
||||
|
||||
#include <functional>
|
||||
#include <unordered_set>
|
||||
|
||||
enum TypeID
|
||||
{
|
||||
@@ -202,6 +203,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;
|
||||
|
||||
// minimum buffer size for packed guid is 9 bytes
|
||||
#define PACKED_GUID_MIN_BUFFER_SIZE 9
|
||||
|
||||
@@ -22560,13 +22560,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
|
||||
if ((target->GetGOInfo()->type != GAMEOBJECT_TYPE_TRANSPORT))
|
||||
@@ -22574,14 +22574,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);
|
||||
@@ -22643,7 +22643,7 @@ void Player::UpdateTriggerVisibility()
|
||||
|
||||
UpdateData udata;
|
||||
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())
|
||||
{
|
||||
@@ -23702,7 +23702,7 @@ void Player::UpdateForQuestWorldObjects()
|
||||
|
||||
UpdateData udata;
|
||||
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())
|
||||
{
|
||||
|
||||
@@ -2170,7 +2170,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);
|
||||
|
||||
@@ -43,7 +43,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), vis_guids(player.m_clientGUIDs) { }
|
||||
template<class T> void Visit(GridRefManager<T> &m);
|
||||
|
||||
@@ -627,7 +627,7 @@ void WorldSession::HandleQuestgiverStatusMultipleQuery(WorldPacket& /*recvPacket
|
||||
WorldPacket data(SMSG_QUESTGIVER_STATUS_MULTIPLE, 4);
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user