feat(performance): reduce lag impact by attackers and yieldthread

This commit is contained in:
Yunfan Li
2023-06-11 22:30:47 +08:00
parent df43d7dff7
commit 81149246c4
2 changed files with 13 additions and 12 deletions

View File

@@ -54,7 +54,7 @@ bool PlayerbotAIBase::CanUpdateAI()
void PlayerbotAIBase::YieldThread(bool delay) void PlayerbotAIBase::YieldThread(bool delay)
{ {
if (nextAICheckDelay < sPlayerbotAIConfig->reactDelay) if (nextAICheckDelay < sPlayerbotAIConfig->reactDelay)
nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay; nextAICheckDelay = delay ? sPlayerbotAIConfig->reactDelay * 10 : sPlayerbotAIConfig->reactDelay * 5;
} }
bool PlayerbotAIBase::IsActive() bool PlayerbotAIBase::IsActive()

View File

@@ -63,20 +63,21 @@ void AttackersValue::AddAttackersOf(Player* player, std::set<Unit*>& targets)
if (!player || !player->IsInWorld() || player->IsBeingTeleported()) if (!player || !player->IsInWorld() || player->IsBeingTeleported())
return; return;
std::list<Unit*> units; HostileRefMgr& refManager = player->getHostileRefMgr();
Acore::AnyUnfriendlyUnitInObjectRangeCheck u_check(player, player, sPlayerbotAIConfig->sightDistance); HostileReference *ref = refManager.getFirst();
Acore::UnitListSearcher<Acore::AnyUnfriendlyUnitInObjectRangeCheck> searcher(player, units, u_check); if (!ref)
Cell::VisitAllObjects(player, searcher, sPlayerbotAIConfig->sightDistance); return;
for (Unit* unit : units) while( ref )
{ {
if (!player->GetGroup()) ThreatMgr *threatMgr = ref->GetSource();
{ Unit *attacker = threatMgr->GetOwner();
if (!unit->GetThreatMgr().GetThreat(player) && (!unit->GetThreatMgr().getCurrentVictim() || unit->GetThreatMgr().getCurrentVictim()->getTarget() != player)) Unit *victim = attacker->GetVictim();
continue;
}
targets.insert(unit); if (player->IsValidAttackTarget(attacker) && player->GetDistance2d(attacker) < sPlayerbotAIConfig->sightDistance) {
targets.insert(attacker);
}
ref = ref->next();
} }
} }