mirror of
https://github.com/EQEmu/Server.git
synced 2026-04-04 14:22:24 +00:00
[Performance] Reworked how client to NPC aggro checks are made
- Before when reverse aggro checks were done (client to NPC), checks would happen every 750 millseconds where a client would check an entire entity list with distance calcs and other checks for aggro, with many clients in a zone and many NPC's this would add a lot of unecessary overhead. A temporary adjustment on 3/25 was made and upped the check to 6 seconds. - Now, there is a new methodology to scanning. The client will build a cache list of NPC's within close range as defined in new rule: RULE_INT(Range, ClientNPCScan, 300) and will also get any NPC that has an aggro range beyond that defined range to use in the frequent checks for aggro, the result is far less overhead - Client scanning changes when moving versus not moving, the client will scan aggro every 500 milliseconds while moving, and 3000 millseconds aggro check when not moving, with a 6000ms re-fetch for close NPC's - A demo of these changes can be found here: https://youtu.be/aGroiwLSTVU
This commit is contained in:
parent
940f3b03e8
commit
4b6ce1c19e
@ -1,8 +1,21 @@
|
||||
EQEMu Changelog (Started on Sept 24, 2003 15:50)
|
||||
-------------------------------------------------------
|
||||
== 03/27/2017 ==
|
||||
Akkadius: [Performance] Reworked how client to NPC aggro checks are made
|
||||
- Before when reverse aggro checks were done (client to NPC), checks would happen every 750 millseconds where a client would
|
||||
check an entire entity list with distance calcs and other checks for aggro, with many clients in a zone and many NPC's this would
|
||||
add a lot of unecessary overhead. A temporary adjustment on 3/25 was made and upped the check to 6 seconds.
|
||||
- Now, there is a new methodology to scanning. The client will build a cache list of NPC's within close range as defined in new rule:
|
||||
RULE_INT(Range, ClientNPCScan, 300) and will also get any NPC that has an aggro range beyond that defined range to use in
|
||||
the frequent checks for aggro, the result is far less overhead
|
||||
- Client scanning changes when moving versus not moving, the client will scan aggro every 500 milliseconds while moving, and
|
||||
3000 millseconds aggro check when not moving, with a 6000ms re-fetch for close NPC's
|
||||
- A demo of these changes can be found here:
|
||||
https://youtu.be/aGroiwLSTVU
|
||||
|
||||
== 03/25/2017 ==
|
||||
Akkadius: Reduced CPU footprint in non-combat zones doing constant checks for combat related activities
|
||||
Akkadius: Reduced CPU footprint in cases where a client is checking for aggro excessively every 750 millseconds. This has
|
||||
Akkadius: [Performance] Reduced CPU footprint in non-combat zones doing constant checks for combat related activities
|
||||
Akkadius: [Performance] Reduced CPU footprint in cases where a client is checking for aggro excessively every 750 millseconds. This has
|
||||
been adjusted to 6 seconds per new rule RULE_INT(Aggro, ClientAggroCheckInterval)
|
||||
- When zones have many players, with many NPC's, this adds up quickly
|
||||
|
||||
|
||||
@ -559,6 +559,7 @@ RULE_INT(Range, SpellMessages, 75)
|
||||
RULE_INT(Range, SongMessages, 75)
|
||||
RULE_INT(Range, MobPositionUpdates, 600)
|
||||
RULE_INT(Range, CriticalDamage, 80)
|
||||
RULE_INT(Range, ClientNPCScan, 300)
|
||||
RULE_CATEGORY_END()
|
||||
|
||||
|
||||
|
||||
@ -135,7 +135,7 @@ Client::Client(EQStreamInterface* ieqs)
|
||||
forget_timer(0),
|
||||
autosave_timer(RuleI(Character, AutosaveIntervalS) * 1000),
|
||||
#ifdef REVERSE_AGGRO
|
||||
scanarea_timer(RuleI(Aggro, ClientAggroCheckInterval) * 1000),
|
||||
client_scan_npc_aggro_timer(RuleI(Aggro, ClientAggroCheckInterval) * 1000),
|
||||
#endif
|
||||
tribute_timer(Tribute_duration),
|
||||
proximity_timer(ClientProximity_interval),
|
||||
@ -160,7 +160,8 @@ Client::Client(EQStreamInterface* ieqs)
|
||||
m_AutoAttackPosition(0.0f, 0.0f, 0.0f, 0.0f),
|
||||
m_AutoAttackTargetLocation(0.0f, 0.0f, 0.0f),
|
||||
last_region_type(RegionTypeUnsupported),
|
||||
m_dirtyautohaters(false)
|
||||
m_dirtyautohaters(false),
|
||||
npc_close_scan_timer(6000)
|
||||
{
|
||||
for(int cf=0; cf < _FilterCount; cf++)
|
||||
ClientFilters[cf] = FilterShow;
|
||||
@ -358,6 +359,8 @@ Client::~Client() {
|
||||
m_tradeskill_object = nullptr;
|
||||
}
|
||||
|
||||
close_npcs.clear();
|
||||
|
||||
if(IsDueling() && GetDuelTarget() != 0) {
|
||||
Entity* entity = entity_list.GetID(GetDuelTarget());
|
||||
if(entity != nullptr && entity->IsClient()) {
|
||||
|
||||
@ -221,6 +221,9 @@ public:
|
||||
Client(EQStreamInterface * ieqs);
|
||||
~Client();
|
||||
|
||||
std::unordered_map<NPC *, float> close_npcs;
|
||||
bool is_client_moving;
|
||||
|
||||
//abstract virtual function implementations required by base abstract class
|
||||
virtual bool Death(Mob* killerMob, int32 damage, uint16 spell_id, EQEmu::skills::SkillType attack_skill);
|
||||
virtual void Damage(Mob* from, int32 damage, uint16 spell_id, EQEmu::skills::SkillType attack_skill, bool avoidable = true, int8 buffslot = -1, bool iBuffTic = false, eSpecialAttacks special = eSpecialAttacks::None);
|
||||
@ -1458,7 +1461,7 @@ private:
|
||||
Timer forget_timer; // our 2 min everybody forgets you timer
|
||||
Timer autosave_timer;
|
||||
#ifdef REVERSE_AGGRO
|
||||
Timer scanarea_timer;
|
||||
Timer client_scan_npc_aggro_timer;
|
||||
#endif
|
||||
Timer tribute_timer;
|
||||
|
||||
@ -1477,6 +1480,7 @@ private:
|
||||
Timer helm_toggle_timer;
|
||||
Timer light_update_timer;
|
||||
Timer aggro_meter_timer;
|
||||
Timer npc_close_scan_timer;
|
||||
|
||||
glm::vec3 m_Proximity;
|
||||
|
||||
|
||||
@ -4580,6 +4580,34 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app)
|
||||
rewind_timer.Start(30000, true);
|
||||
}
|
||||
|
||||
|
||||
/* Handle client aggro scanning timers NPCs */
|
||||
is_client_moving = (ppu->y_pos == m_Position.y && ppu->x_pos == m_Position.x) ? false : true;
|
||||
|
||||
if (is_client_moving) {
|
||||
Log.Out(Logs::Detail, Logs::Normal, "ClientUpdate: Client is moving - scan timer is: %u", client_scan_npc_aggro_timer.GetDuration());
|
||||
if (client_scan_npc_aggro_timer.GetDuration() > 1000) {
|
||||
|
||||
npc_close_scan_timer.Disable();
|
||||
npc_close_scan_timer.Start(500);
|
||||
|
||||
client_scan_npc_aggro_timer.Disable();
|
||||
client_scan_npc_aggro_timer.Start(500);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
Log.Out(Logs::Detail, Logs::Normal, "ClientUpdate: Client is NOT moving - scan timer is: %u", client_scan_npc_aggro_timer.GetDuration());
|
||||
if (client_scan_npc_aggro_timer.GetDuration() < 1000) {
|
||||
|
||||
npc_close_scan_timer.Disable();
|
||||
npc_close_scan_timer.Start(6000);
|
||||
|
||||
client_scan_npc_aggro_timer.Disable();
|
||||
client_scan_npc_aggro_timer.Start(3000);
|
||||
}
|
||||
}
|
||||
|
||||
// Outgoing client packet
|
||||
float tmpheading = EQ19toFloat(ppu->heading);
|
||||
/* The clients send an update at best every 1.3 seconds
|
||||
|
||||
@ -161,34 +161,29 @@ bool Client::Process() {
|
||||
return(false);
|
||||
}
|
||||
|
||||
if(charm_update_timer.Check())
|
||||
{
|
||||
if (charm_update_timer.Check()) {
|
||||
CalcItemScale();
|
||||
}
|
||||
|
||||
if (TaskPeriodic_Timer.Check() && taskstate)
|
||||
taskstate->TaskPeriodicChecks(this);
|
||||
|
||||
if(linkdead_timer.Check())
|
||||
{
|
||||
if (linkdead_timer.Check()) {
|
||||
LeaveGroup();
|
||||
Save();
|
||||
if (GetMerc())
|
||||
{
|
||||
if (GetMerc()) {
|
||||
GetMerc()->Save();
|
||||
GetMerc()->Depop();
|
||||
}
|
||||
|
||||
Raid *myraid = entity_list.GetRaidByClient(this);
|
||||
if (myraid)
|
||||
{
|
||||
if (myraid) {
|
||||
myraid->MemberZoned(this);
|
||||
}
|
||||
return false; //delete client
|
||||
}
|
||||
|
||||
if (camp_timer.Check())
|
||||
{
|
||||
if (camp_timer.Check()) {
|
||||
LeaveGroup();
|
||||
Save();
|
||||
if (GetMerc())
|
||||
@ -202,8 +197,7 @@ bool Client::Process() {
|
||||
if (IsStunned() && stunned_timer.Check())
|
||||
Mob::UnStun();
|
||||
|
||||
if(!m_CheatDetectMoved)
|
||||
{
|
||||
if (!m_CheatDetectMoved) {
|
||||
m_TimeSinceLastPositionCheck = Timer::GetCurrentTime();
|
||||
}
|
||||
|
||||
@ -213,26 +207,26 @@ bool Client::Process() {
|
||||
Mob *song_target = nullptr;
|
||||
if (bardsong_target_id == GetID()) {
|
||||
song_target = this;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
song_target = entity_list.GetMob(bardsong_target_id);
|
||||
}
|
||||
|
||||
if (song_target == nullptr) {
|
||||
InterruptSpell(SONG_ENDS_ABRUPTLY, 0x121, bardsong);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
if (!ApplyNextBardPulse(bardsong, song_target, bardsong_slot))
|
||||
InterruptSpell(SONG_ENDS_ABRUPTLY, 0x121, bardsong);
|
||||
//SpellFinished(bardsong, bardsong_target, bardsong_slot, spells[bardsong].mana);
|
||||
}
|
||||
}
|
||||
|
||||
if(GetMerc())
|
||||
{
|
||||
if (GetMerc()) {
|
||||
UpdateMercTimer();
|
||||
}
|
||||
|
||||
if(GetMercInfo().MercTemplateID != 0 && GetMercInfo().IsSuspended)
|
||||
{
|
||||
if (GetMercInfo().MercTemplateID != 0 && GetMercInfo().IsSuspended) {
|
||||
CheckMercSuspendTimer();
|
||||
}
|
||||
|
||||
@ -244,19 +238,15 @@ bool Client::Process() {
|
||||
BindWound(bindwound_target, false);
|
||||
}
|
||||
|
||||
if(KarmaUpdateTimer)
|
||||
{
|
||||
if(KarmaUpdateTimer->Check(false))
|
||||
{
|
||||
if (KarmaUpdateTimer) {
|
||||
if (KarmaUpdateTimer->Check(false)) {
|
||||
KarmaUpdateTimer->Start(RuleI(Chat, KarmaUpdateIntervalMS));
|
||||
database.UpdateKarma(AccountID(), ++TotalKarma);
|
||||
}
|
||||
}
|
||||
|
||||
if(qGlobals)
|
||||
{
|
||||
if(qglobal_purge_timer.Check())
|
||||
{
|
||||
if (qGlobals) {
|
||||
if (qglobal_purge_timer.Check()) {
|
||||
qGlobals->PurgeExpiredGlobals();
|
||||
}
|
||||
}
|
||||
@ -269,6 +259,28 @@ bool Client::Process() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Build a close range list of NPC's */
|
||||
if (npc_close_scan_timer.Check()) {
|
||||
|
||||
close_npcs.clear();
|
||||
|
||||
std::list<NPC*> npc_list;
|
||||
entity_list.GetNPCList(npc_list);
|
||||
|
||||
float scan_range = RuleI(Range, ClientNPCScan);
|
||||
for (auto itr = npc_list.begin(); itr != npc_list.end(); ++itr) {
|
||||
NPC* npc = *itr;
|
||||
float distance = DistanceNoZ(m_Position, npc->GetPosition());
|
||||
if(distance <= scan_range) {
|
||||
close_npcs.insert(std::pair<NPC *, float>(npc, distance));
|
||||
}
|
||||
else if (npc->GetAggroRange() > scan_range) {
|
||||
close_npcs.insert(std::pair<NPC *, float>(npc, distance));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool may_use_attacks = false;
|
||||
/*
|
||||
Things which prevent us from attacking:
|
||||
@ -616,8 +628,17 @@ bool Client::Process() {
|
||||
//At this point, we are still connected, everything important has taken
|
||||
//place, now check to see if anybody wants to aggro us.
|
||||
// only if client is not feigned
|
||||
if(zone->CanDoCombat() && ret && !GetFeigned() && scanarea_timer.Check()) {
|
||||
entity_list.CheckClientAggro(this);
|
||||
if (zone->CanDoCombat() && ret && !GetFeigned() && client_scan_npc_aggro_timer.Check()) {
|
||||
int npc_scan_count = 0;
|
||||
for (auto it = close_npcs.begin(); it != close_npcs.end(); ++it) {
|
||||
NPC *npc = it->first;
|
||||
|
||||
if (npc->CheckWillAggro(this) && !npc->CheckAggro(this)) {
|
||||
npc->AddToHateList(this, 25);
|
||||
}
|
||||
npc_scan_count++;
|
||||
}
|
||||
Log.Out(Logs::General, Logs::Aggro, "Checking Reverse Aggro (client->npc) scanned_npcs (%i)", npc_scan_count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -2288,10 +2288,15 @@ bool EntityList::RemoveNPC(uint16 delete_id)
|
||||
{
|
||||
auto it = npc_list.find(delete_id);
|
||||
if (it != npc_list.end()) {
|
||||
NPC *npc = it->second;
|
||||
// make sure its proximity is removed
|
||||
RemoveProximity(delete_id);
|
||||
// remove from client close lists
|
||||
RemoveNPCFromClientCloseLists(npc);
|
||||
// remove from the list
|
||||
npc_list.erase(it);
|
||||
|
||||
|
||||
// remove from limit list if needed
|
||||
if (npc_limit_list.count(delete_id))
|
||||
npc_limit_list.erase(delete_id);
|
||||
@ -2300,6 +2305,16 @@ bool EntityList::RemoveNPC(uint16 delete_id)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntityList::RemoveNPCFromClientCloseLists(NPC *npc)
|
||||
{
|
||||
auto it = client_list.begin();
|
||||
while (it != client_list.end()) {
|
||||
it->second->close_npcs.erase(npc);
|
||||
++it;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool EntityList::RemoveMerc(uint16 delete_id)
|
||||
{
|
||||
auto it = merc_list.find(delete_id);
|
||||
|
||||
@ -279,6 +279,7 @@ public:
|
||||
bool RemoveTrap(uint16 delete_id);
|
||||
bool RemoveObject(uint16 delete_id);
|
||||
bool RemoveProximity(uint16 delete_npc_id);
|
||||
bool RemoveNPCFromClientCloseLists(NPC *npc);
|
||||
void RemoveAllMobs();
|
||||
void RemoveAllClients();
|
||||
void RemoveAllNPCs();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user