Performance optim

This commit is contained in:
Yunfan Li
2024-04-11 11:02:42 +08:00
parent 839257cd1e
commit b474dc44bb
3 changed files with 19 additions and 18 deletions

View File

@@ -605,7 +605,7 @@ void PlayerbotFactory::InitPetTalents()
return; return;
} }
pet->resetTalents(); 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) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
@@ -625,7 +625,7 @@ void PlayerbotFactory::InitPetTalents()
uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel()); uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel());
int row = 0; int row = 0;
// LOG_INFO("playerbots", "{} learning, max talent points: {}, cur: {}", bot->GetName().c_str(), maxTalentPoints, curTalentPoints); // 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; std::vector<TalentEntry const*> &spells_row = i->second;
if (spells_row.empty()) if (spells_row.empty())
@@ -893,7 +893,7 @@ void PlayerbotFactory::InitTalentsBySpecNo(Player* bot, int specNo, bool reset)
uint32 cls = bot->getClass(); uint32 cls = bot->getClass();
int startLevel = bot->GetLevel(); int startLevel = bot->GetLevel();
uint32 classMask = bot->getClassMask(); 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) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
@@ -954,7 +954,7 @@ void PlayerbotFactory::InitTalentsByParsedSpecLink(Player* bot, std::vector<std:
bot->resetTalents(true); bot->resetTalents(true);
} }
uint32 classMask = bot->getClassMask(); 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) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
@@ -2248,7 +2248,7 @@ void PlayerbotFactory::InitSpecialSpells()
void PlayerbotFactory::InitTalents(uint32 specNo) void PlayerbotFactory::InitTalents(uint32 specNo)
{ {
uint32 classMask = bot->getClassMask(); 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) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
@@ -2266,7 +2266,7 @@ void PlayerbotFactory::InitTalents(uint32 specNo)
} }
uint32 freePoints = bot->GetFreeTalentPoints(); 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; std::vector<TalentEntry const*> &spells_row = i->second;
if (spells_row.empty()) if (spells_row.empty())
@@ -2308,7 +2308,7 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab)
int startLevel = bot->GetLevel(); int startLevel = bot->GetLevel();
uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab]; uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab];
uint32 classMask = bot->getClassMask(); 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) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
@@ -2648,7 +2648,7 @@ void PlayerbotFactory::InitFood()
if (sPlayerbotAIConfig->freeFood) { if (sPlayerbotAIConfig->freeFood) {
return; return;
} }
std::map<uint32, std::vector<uint32> > items; std::unordered_map<uint32, std::vector<uint32> > items;
ItemTemplateContainer const* itemTemplateContainer = sObjectMgr->GetItemTemplateStore(); ItemTemplateContainer const* itemTemplateContainer = sObjectMgr->GetItemTemplateStore();
for (ItemTemplateContainer::const_iterator i = itemTemplateContainer->begin(); i != itemTemplateContainer->end(); ++i) for (ItemTemplateContainer::const_iterator i = itemTemplateContainer->begin(); i != itemTemplateContainer->end(); ++i)
{ {

View File

@@ -900,7 +900,7 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
std::string const cmdStr = cmd; std::string const cmdStr = cmd;
std::set<std::string> bots; std::unordered_set<std::string> bots;
if (charnameStr == "*" && master) if (charnameStr == "*" && master)
{ {
Group* group = master->GetGroup(); Group* group = master->GetGroup();
@@ -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; std::string const bot = *i;

View File

@@ -7,8 +7,9 @@
#include "Common.h" #include "Common.h"
#include <map> #include <unordered_map>
#include <set> #include <set>
#include <unordered_set>
#include <list> #include <list>
#include <vector> #include <vector>
@@ -46,7 +47,7 @@ class NamedObjectFactory
{ {
protected: protected:
typedef T*(*ActionCreator)(PlayerbotAI* botAI); typedef T*(*ActionCreator)(PlayerbotAI* botAI);
std::map<std::string, ActionCreator> creators; std::unordered_map<std::string, ActionCreator> creators;
public: public:
T* create(std::string name, PlayerbotAI* botAI) T* create(std::string name, PlayerbotAI* botAI)
@@ -77,7 +78,7 @@ class NamedObjectFactory
std::set<std::string> supports() std::set<std::string> supports()
{ {
std::set<std::string> keys; 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); keys.insert(it->first);
return keys; return keys;
@@ -106,7 +107,7 @@ class NamedObjectContext : public NamedObjectFactory<T>
void Clear() 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) if (i->second)
delete i->second; delete i->second;
@@ -117,7 +118,7 @@ class NamedObjectContext : public NamedObjectFactory<T>
void Update() 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) if (i->second)
i->second->Update(); i->second->Update();
@@ -126,7 +127,7 @@ class NamedObjectContext : public NamedObjectFactory<T>
void Reset() 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) if (i->second)
i->second->Reset(); i->second->Reset();
@@ -139,14 +140,14 @@ class NamedObjectContext : public NamedObjectFactory<T>
std::set<std::string> GetCreated() std::set<std::string> GetCreated()
{ {
std::set<std::string> keys; 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); keys.insert(it->first);
return keys; return keys;
} }
protected: protected:
std::map<std::string, T*> created; std::unordered_map<std::string, T*> created;
bool shared; bool shared;
bool supportsSiblings; bool supportsSiblings;
}; };