Merge pull request #439 from liyunfan1223/performance

Improve performance
This commit is contained in:
Yunfan Li
2024-08-05 23:39:19 +08:00
committed by GitHub
12 changed files with 71 additions and 39 deletions

View File

@@ -1,9 +1,9 @@
name: macos-build name: macos-build
on: on:
push: push:
branches: [ "master" ] branches: [never-match-this-branch]
pull_request: pull_request:
branches: [ "master" ] branches: [never-match-this-branch]
# concurrency: # concurrency:
# group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }}) # group: ${{ github.head_ref }} || concat(${{ github.ref }}, ${{ github.workflow }})

View File

@@ -1379,7 +1379,7 @@ bool PlayerbotAI::ContainsStrategy(StrategyType type)
{ {
for (uint8 i = 0; i < BOT_STATE_MAX; i++) for (uint8 i = 0; i < BOT_STATE_MAX; i++)
{ {
if (engines[i]->ContainsStrategy(type)) if (engines[i]->HasStrategyType(type))
return true; return true;
} }
@@ -3285,12 +3285,18 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
return false; return false;
} }
bool isFriend = bot->IsFriendlyTo(target); bool isFriend = bot->IsFriendlyTo(target);
for (uint32 type = SPELL_AURA_NONE; type < TOTAL_AURAS; ++type) Unit::VisibleAuraMap const* visibleAuras = target->GetVisibleAuras();
for (Unit::VisibleAuraMap::const_iterator itr = visibleAuras->begin(); itr != visibleAuras->end(); ++itr)
{ {
Unit::AuraEffectList const& auras = target->GetAuraEffectsByType((AuraType)type); Aura* aura = itr->second->GetBase();
for (AuraEffect const* aurEff : auras)
{ if (aura->IsPassive())
Aura const* aura = aurEff->GetBase(); continue;
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() &&
aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
continue;
SpellInfo const* spellInfo = aura->GetSpellInfo(); SpellInfo const* spellInfo = aura->GetSpellInfo();
bool isPositiveSpell = spellInfo->IsPositive(); bool isPositiveSpell = spellInfo->IsPositive();
@@ -3300,14 +3306,9 @@ bool PlayerbotAI::HasAuraToDispel(Unit* target, uint32 dispelType)
if (!isPositiveSpell && !isFriend) if (!isPositiveSpell && !isFriend)
continue; continue;
if (sPlayerbotAIConfig->dispelAuraDuration && aura->GetDuration() &&
aura->GetDuration() < (int32)sPlayerbotAIConfig->dispelAuraDuration)
continue;
if (canDispel(spellInfo, dispelType)) if (canDispel(spellInfo, dispelType))
return true; return true;
} }
}
return false; return false;
} }

View File

@@ -86,6 +86,7 @@ Engine::~Engine(void)
void Engine::Reset() void Engine::Reset()
{ {
strategyTypeMask = 0;
ActionNode* action = nullptr; ActionNode* action = nullptr;
do do
{ {
@@ -120,6 +121,7 @@ void Engine::Init()
for (std::map<std::string, Strategy*>::iterator i = strategies.begin(); i != strategies.end(); i++) for (std::map<std::string, Strategy*>::iterator i = strategies.begin(); i != strategies.end(); i++)
{ {
Strategy* strategy = i->second; Strategy* strategy = i->second;
strategyTypeMask |= strategy->GetType();
strategy->InitMultipliers(multipliers); strategy->InitMultipliers(multipliers);
strategy->InitTriggers(triggers); strategy->InitTriggers(triggers);

View File

@@ -83,7 +83,7 @@ public:
void AddActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Add(listener); } void AddActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Add(listener); }
void removeActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Remove(listener); } void removeActionExecutionListener(ActionExecutionListener* listener) { actionExecutionListeners.Remove(listener); }
bool HasStrategyType(StrategyType type) { return strategyTypeMask & type; }
virtual ~Engine(void); virtual ~Engine(void);
bool testMode; bool testMode;
@@ -112,6 +112,7 @@ protected:
std::map<std::string, Strategy*> strategies; std::map<std::string, Strategy*> strategies;
float lastRelevance; float lastRelevance;
std::string lastAction; std::string lastAction;
uint32 strategyTypeMask;
}; };
#endif #endif

View File

@@ -98,7 +98,9 @@ void GenericHunterStrategy::InitTriggers(std::vector<TriggerNode*>& triggers)
new TriggerNode("misdirection on main tank", new TriggerNode("misdirection on main tank",
NextAction::array(0, new NextAction("misdirection on main tank", ACTION_HIGH + 7), NULL))); NextAction::array(0, new NextAction("misdirection on main tank", ACTION_HIGH + 7), NULL)));
triggers.push_back( triggers.push_back(
new TriggerNode("tranquilizing shot", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL))); new TriggerNode("tranquilizing shot enrage", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL)));
triggers.push_back(
new TriggerNode("tranquilizing shot magic", NextAction::array(0, new NextAction("tranquilizing shot", 61.0f), NULL)));
} }
NextAction** HunterBoostStrategy::getDefaultActions() NextAction** HunterBoostStrategy::getDefaultActions()

View File

@@ -85,7 +85,8 @@ public:
creators["switch to melee"] = &HunterTriggerFactoryInternal::switch_to_melee; creators["switch to melee"] = &HunterTriggerFactoryInternal::switch_to_melee;
creators["switch to ranged"] = &HunterTriggerFactoryInternal::switch_to_ranged; creators["switch to ranged"] = &HunterTriggerFactoryInternal::switch_to_ranged;
creators["misdirection on main tank"] = &HunterTriggerFactoryInternal::misdirection_on_main_tank; creators["misdirection on main tank"] = &HunterTriggerFactoryInternal::misdirection_on_main_tank;
creators["tranquilizing shot"] = &HunterTriggerFactoryInternal::remove_enrage; creators["tranquilizing shot enrage"] = &HunterTriggerFactoryInternal::remove_enrage;
creators["tranquilizing shot magic"] = &HunterTriggerFactoryInternal::remove_magic;
} }
private: private:
@@ -118,6 +119,7 @@ private:
static Trigger* switch_to_ranged(PlayerbotAI* botAI) { return new SwitchToRangedTrigger(botAI); } static Trigger* switch_to_ranged(PlayerbotAI* botAI) { return new SwitchToRangedTrigger(botAI); }
static Trigger* misdirection_on_main_tank(PlayerbotAI* ai) { return new MisdirectionOnMainTankTrigger(ai); } static Trigger* misdirection_on_main_tank(PlayerbotAI* ai) { return new MisdirectionOnMainTankTrigger(ai); }
static Trigger* remove_enrage(PlayerbotAI* ai) { return new TargetRemoveEnrageTrigger(ai); } static Trigger* remove_enrage(PlayerbotAI* ai) { return new TargetRemoveEnrageTrigger(ai); }
static Trigger* remove_magic(PlayerbotAI* ai) { return new TargetRemoveMagicTrigger(ai); }
}; };
class HunterAiObjectContextInternal : public NamedObjectContext<Action> class HunterAiObjectContextInternal : public NamedObjectContext<Action>

View File

@@ -88,9 +88,3 @@ bool SwitchToMeleeTrigger::IsActive()
(target->GetVictim() == bot && (target->GetVictim() == bot &&
sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f)); sServerFacade->IsDistanceLessOrEqualThan(AI_VALUE2(float, "distance", "current target"), 8.0f));
} }
bool TargetRemoveEnrageTrigger::IsActive()
{
Unit* target = GetTarget();
return target && (botAI->HasAuraToDispel(target, DISPEL_ENRAGE) || botAI->HasAuraToDispel(target, DISPEL_MAGIC));
}

View File

@@ -170,6 +170,11 @@ class TargetRemoveEnrageTrigger : public TargetAuraDispelTrigger
{ {
public: public:
TargetRemoveEnrageTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_ENRAGE) {} TargetRemoveEnrageTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_ENRAGE) {}
bool IsActive() override; };
class TargetRemoveMagicTrigger : public TargetAuraDispelTrigger
{
public:
TargetRemoveMagicTrigger(PlayerbotAI* ai) : TargetAuraDispelTrigger(ai, "tranquilizing shot", DISPEL_MAGIC) {}
}; };
#endif #endif

View File

@@ -19,4 +19,10 @@ Value<Unit*>* PartyMemberNeedCureTrigger::GetTargetValue()
return context->GetValue<Unit*>("party member to dispel", dispelType); return context->GetValue<Unit*>("party member to dispel", dispelType);
} }
bool PartyMemberNeedCureTrigger::IsActive()
{
Unit* target = GetTarget();
return target && target->IsInWorld();
}
bool NeedWorldBuffTrigger::IsActive() { return !WorldBuffAction::NeedWorldBuffs(bot).empty(); } bool NeedWorldBuffTrigger::IsActive() { return !WorldBuffAction::NeedWorldBuffs(bot).empty(); }

View File

@@ -46,6 +46,7 @@ public:
} }
Value<Unit*>* GetTargetValue() override; Value<Unit*>* GetTargetValue() override;
bool IsActive() override;
}; };
class NeedWorldBuffTrigger : public Trigger class NeedWorldBuffTrigger : public Trigger

View File

@@ -41,36 +41,54 @@ Unit* PartyMemberToHeal::Calculate()
for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next()) for (GroupReference* gref = group->GetFirstMember(); gref; gref = gref->next())
{ {
Player* player = gref->GetSource(); Player* player = gref->GetSource();
if (player && Check(player) && player->IsAlive()) if (player && player->IsAlive())
{ {
uint8 health = player->GetHealthPct(); uint8 health = player->GetHealthPct();
if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate)) if (isRaid || health < sPlayerbotAIConfig->mediumHealth || !IsTargetOfSpellCast(player, predicate))
{ {
uint32 probeValue = 100;
if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance) if (player->GetDistance2d(bot) > sPlayerbotAIConfig->healDistance)
{ {
calc.probe(health + 30, player); probeValue = health + 30;
} }
else else
{ {
calc.probe(health + player->GetDistance2d(bot) / 10, player); probeValue = health + player->GetDistance2d(bot) / 10;
}
// delay Check player to here for better performance
if (probeValue < calc.minValue && Check(player))
{
calc.probe(probeValue, player);
} }
} }
} }
Pet* pet = player->GetPet(); Pet* pet = player->GetPet();
if (pet && Check(pet) && pet->IsAlive()) if (pet && pet->IsAlive())
{ {
uint8 health = ((Unit*)pet)->GetHealthPct(); uint8 health = ((Unit*)pet)->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth) if (isRaid || health < sPlayerbotAIConfig->mediumHealth)
calc.probe(health + 30, pet); probeValue = health + 30;
// delay Check pet to here for better performance
if (probeValue < calc.minValue && Check(pet))
{
calc.probe(probeValue, pet);
}
} }
Unit* charm = player->GetCharm(); Unit* charm = player->GetCharm();
if (charm && Check(charm) && charm->IsAlive()) if (charm && charm->IsAlive())
{ {
uint8 health = charm->GetHealthPct(); uint8 health = charm->GetHealthPct();
uint32 probeValue = 100;
if (isRaid || health < sPlayerbotAIConfig->mediumHealth) if (isRaid || health < sPlayerbotAIConfig->mediumHealth)
calc.probe(health, charm); probeValue = health + 30;
// delay Check charm to here for better performance
if (probeValue < calc.minValue && Check(charm))
{
calc.probe(probeValue, charm);
}
} }
} }
return (Unit*)calc.param; return (Unit*)calc.param;

View File

@@ -12,11 +12,11 @@ Unit* PartyMemberValue::FindPartyMember(std::vector<Player*>* party, FindPlayerP
{ {
for (Player* player : *party) for (Player* player : *party)
{ {
if (Check(player) && predicate.Check(player)) if (predicate.Check(player) && Check(player))
return player; return player;
if (Pet* pet = player->GetPet()) if (Pet* pet = player->GetPet())
if (Check(pet) && predicate.Check(pet)) if (predicate.Check(pet) && Check(pet))
return pet; return pet;
} }