Skip to content

Commit

Permalink
Merge pull request liyunfan1223#180 from liyunfan1223/perf
Browse files Browse the repository at this point in the history
Performance optimization
  • Loading branch information
liyunfan1223 authored Apr 12, 2024
2 parents 839257c + c8c33f0 commit 69ecee0
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 82 deletions.
4 changes: 4 additions & 0 deletions conf/playerbots.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ AiPlayerbot.GlobalCooldown = 500
# Max wait time when moving
AiPlayerbot.MaxWaitForMove = 5000

# Max search time for movement (higher for better movement on slopes)
# default: 3
AiPlayerbot.MaxMovementSearchTime = 3

# Action expiration time
AiPlayerbot.ExpireActionTime = 5000

Expand Down
2 changes: 1 addition & 1 deletion src/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1993,7 +1993,7 @@ bool PlayerbotAI::HasAura(std::string const name, Unit* unit, bool maxStack, boo
{
SpellInfo const* spellInfo = aurEff->GetSpellInfo();

std::string const auraName = spellInfo->SpellName[0];
std::string_view const auraName = spellInfo->SpellName[0];
if (auraName.empty() || auraName.length() != wnamepart.length() || !Utf8FitTo(auraName, wnamepart))
continue;

Expand Down
1 change: 1 addition & 0 deletions src/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool PlayerbotAIConfig::Initialize()

globalCoolDown = sConfigMgr->GetOption<int32>("AiPlayerbot.GlobalCooldown", 1500);
maxWaitForMove = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxWaitForMove", 5000);
maxMovementSearchTime = sConfigMgr->GetOption<int32>("AiPlayerbot.MaxMovementSearchTime", 3);
expireActionTime = sConfigMgr->GetOption<int32>("AiPlayerbot.ExpireActionTime", 5000);
dispelAuraDuration = sConfigMgr->GetOption<int32>("AiPlayerbot.DispelAuraDuration", 7000);
reactDelay = sConfigMgr->GetOption<int32>("AiPlayerbot.ReactDelay", 500);
Expand Down
3 changes: 2 additions & 1 deletion src/PlayerbotAIConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class PlayerbotAIConfig

bool enabled;
bool allowGuildBots, allowPlayerBots;
uint32 globalCoolDown, reactDelay, maxWaitForMove, expireActionTime, dispelAuraDuration, passiveDelay, repeatDelay,
uint32 globalCoolDown, reactDelay, maxWaitForMove, maxMovementSearchTime, expireActionTime,
dispelAuraDuration, passiveDelay, repeatDelay,
errorDelay, rpgDelay, sitDelay, returnDelay, lootDelay;
float sightDistance, spellDistance, reactDistance, grindDistance, lootDistance, shootDistance,
fleeDistance, tooCloseDistance, meleeDistance, followDistance, whisperDistance, contactDistance,
Expand Down
16 changes: 8 additions & 8 deletions src/PlayerbotFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ void PlayerbotFactory::InitPetTalents()
return;
}
pet->resetTalents();
std::map<uint32, std::vector<TalentEntry const*> > spells;
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
Expand All @@ -625,7 +625,7 @@ void PlayerbotFactory::InitPetTalents()
uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel());
int row = 0;
// LOG_INFO("playerbots", "{} learning, max talent points: {}, cur: {}", bot->GetName().c_str(), maxTalentPoints, curTalentPoints);
for (std::map<uint32, std::vector<TalentEntry const*> >::iterator i = spells.begin(); i != spells.end(); ++i, ++row)
for (auto i = spells.begin(); i != spells.end(); ++i, ++row)
{
std::vector<TalentEntry const*> &spells_row = i->second;
if (spells_row.empty())
Expand Down Expand Up @@ -893,7 +893,7 @@ void PlayerbotFactory::InitTalentsBySpecNo(Player* bot, int specNo, bool reset)
uint32 cls = bot->getClass();
int startLevel = bot->GetLevel();
uint32 classMask = bot->getClassMask();
std::map<uint32, std::vector<TalentEntry const*> > spells_row;
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells_row;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
Expand Down Expand Up @@ -954,7 +954,7 @@ void PlayerbotFactory::InitTalentsByParsedSpecLink(Player* bot, std::vector<std:
bot->resetTalents(true);
}
uint32 classMask = bot->getClassMask();
std::map<uint32, std::vector<TalentEntry const*> > spells_row;
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells_row;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
Expand Down Expand Up @@ -2248,7 +2248,7 @@ void PlayerbotFactory::InitSpecialSpells()
void PlayerbotFactory::InitTalents(uint32 specNo)
{
uint32 classMask = bot->getClassMask();
std::map<uint32, std::vector<TalentEntry const*> > spells;
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
Expand All @@ -2266,7 +2266,7 @@ void PlayerbotFactory::InitTalents(uint32 specNo)
}

uint32 freePoints = bot->GetFreeTalentPoints();
for (std::map<uint32, std::vector<TalentEntry const*> >::iterator i = spells.begin(); i != spells.end(); ++i)
for (auto i = spells.begin(); i != spells.end(); ++i)
{
std::vector<TalentEntry const*> &spells_row = i->second;
if (spells_row.empty())
Expand Down Expand Up @@ -2308,7 +2308,7 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab)
int startLevel = bot->GetLevel();
uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab];
uint32 classMask = bot->getClassMask();
std::map<uint32, std::vector<TalentEntry const*> > spells_row;
std::unordered_map<uint32, std::vector<TalentEntry const*> > spells_row;
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
Expand Down Expand Up @@ -2648,7 +2648,7 @@ void PlayerbotFactory::InitFood()
if (sPlayerbotAIConfig->freeFood) {
return;
}
std::map<uint32, std::vector<uint32> > items;
std::unordered_map<uint32, std::vector<uint32> > items;
ItemTemplateContainer const* itemTemplateContainer = sObjectMgr->GetItemTemplateStore();
for (ItemTemplateContainer::const_iterator i = itemTemplateContainer->begin(); i != itemTemplateContainer->end(); ++i)
{
Expand Down
4 changes: 2 additions & 2 deletions src/PlayerbotMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg

std::string const cmdStr = cmd;

std::set<std::string> bots;
std::unordered_set<std::string> bots;
if (charnameStr == "*" && master)
{
Group* group = master->GetGroup();
Expand Down Expand Up @@ -958,7 +958,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
}
}

for (std::set<std::string>::iterator i = bots.begin(); i != bots.end(); ++i)
for (auto i = bots.begin(); i != bots.end(); ++i)
{
std::string const bot = *i;

Expand Down
19 changes: 10 additions & 9 deletions src/strategy/NamedObjectContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

#include "Common.h"

#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <list>
#include <vector>

Expand Down Expand Up @@ -46,7 +47,7 @@ class NamedObjectFactory
{
protected:
typedef T*(*ActionCreator)(PlayerbotAI* botAI);
std::map<std::string, ActionCreator> creators;
std::unordered_map<std::string, ActionCreator> creators;

public:
T* create(std::string name, PlayerbotAI* botAI)
Expand Down Expand Up @@ -77,7 +78,7 @@ class NamedObjectFactory
std::set<std::string> supports()
{
std::set<std::string> keys;
for (typename std::map<std::string, ActionCreator>::iterator it = creators.begin(); it != creators.end(); it++)
for (typename std::unordered_map<std::string, ActionCreator>::iterator it = creators.begin(); it != creators.end(); it++)
keys.insert(it->first);

return keys;
Expand Down Expand Up @@ -106,7 +107,7 @@ class NamedObjectContext : public NamedObjectFactory<T>

void Clear()
{
for (typename std::map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
for (typename std::unordered_map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
{
if (i->second)
delete i->second;
Expand All @@ -117,7 +118,7 @@ class NamedObjectContext : public NamedObjectFactory<T>

void Update()
{
for (typename std::map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
for (typename std::unordered_map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
{
if (i->second)
i->second->Update();
Expand All @@ -126,7 +127,7 @@ class NamedObjectContext : public NamedObjectFactory<T>

void Reset()
{
for (typename std::map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
for (typename std::unordered_map<std::string, T*>::iterator i = created.begin(); i != created.end(); i++)
{
if (i->second)
i->second->Reset();
Expand All @@ -139,14 +140,14 @@ class NamedObjectContext : public NamedObjectFactory<T>
std::set<std::string> GetCreated()
{
std::set<std::string> keys;
for (typename std::map<std::string, T*>::iterator it = created.begin(); it != created.end(); it++)
for (typename std::unordered_map<std::string, T*>::iterator it = created.begin(); it != created.end(); it++)
keys.insert(it->first);

return keys;
}

protected:
std::map<std::string, T*> created;
std::unordered_map<std::string, T*> created;
bool shared;
bool supportsSiblings;
};
Expand Down Expand Up @@ -264,7 +265,7 @@ class NamedObjectFactoryList
factories.push_front(context);
}

T* GetContextObject(std::string const name, PlayerbotAI* botAI)
T* GetContextObject(std::string const &name, PlayerbotAI* botAI)
{
for (typename std::list<NamedObjectFactory<T>*>::iterator i = factories.begin(); i != factories.end(); i++)
{
Expand Down
Loading

0 comments on commit 69ecee0

Please sign in to comment.