diff --git a/playerbot/PerformanceMonitor.cpp b/playerbot/PerformanceMonitor.cpp index 9a9fa9ad..9890b3e9 100644 --- a/playerbot/PerformanceMonitor.cpp +++ b/playerbot/PerformanceMonitor.cpp @@ -7,21 +7,21 @@ PerformanceMonitor::PerformanceMonitor() { - } PerformanceMonitor::~PerformanceMonitor() { - } -PerformanceMonitorOperation* PerformanceMonitor::start(PerformanceMetric metric, std::string name, PerformanceStack* stack) +std::unique_ptr PerformanceMonitor::start(PerformanceMetric metric, std::string name, PerformanceStack* stack) { - if (!sPlayerbotAIConfig.perfMonEnabled) return NULL; + if (!sPlayerbotAIConfig.perfMonEnabled) + { + return { }; + } std::string stackName = name; - if (stack) { if (!stack->empty()) @@ -45,15 +45,15 @@ PerformanceMonitorOperation* PerformanceMonitor::start(PerformanceMetric metric, data[metric][stackName] = pd; } - return new PerformanceMonitorOperation(pd, name, stack); + return std::make_unique(pd, name, stack); #endif } -PerformanceMonitorOperation* PerformanceMonitor::start(PerformanceMetric metric, std::string name, PlayerbotAI* ai) +std::unique_ptr PerformanceMonitor::start(PerformanceMetric metric, std::string name, PlayerbotAI * ai) { if (!sPlayerbotAIConfig.perfMonEnabled) return NULL; - if(ai->GetAiObjectContext()) + if (ai->GetAiObjectContext()) return start(metric, name, &ai->GetAiObjectContext()->performanceStack); else return start(metric, name); @@ -61,10 +61,9 @@ PerformanceMonitorOperation* PerformanceMonitor::start(PerformanceMetric metric, void PerformanceMonitor::PrintStats(bool perTick, bool fullStack) { - if(data.empty()) + if (data.empty()) return; - uint32 total = 0; if (!perTick) @@ -272,18 +271,18 @@ void PerformanceMonitor::PrintStats(bool perTick, bool fullStack) void PerformanceMonitor::Reset() { - for (std::map >::iterator i = data.begin(); i != data.end(); ++i) - { - std::map pdMap = i->second; - for (std::map::iterator j = pdMap.begin(); j != pdMap.end(); ++j) - { + for (std::map >::iterator i = data.begin(); i != data.end(); ++i) + { + std::map pdMap = i->second; + for (std::map::iterator j = pdMap.begin(); j != pdMap.end(); ++j) + { #ifdef CMANGOS - PerformanceData* pd = j->second; - std::lock_guard guard(pd->lock); - pd->minTime = pd->maxTime = pd->totalTime = pd->count = 0; + PerformanceData* pd = j->second; + std::lock_guard guard(pd->lock); + pd->minTime = pd->maxTime = pd->totalTime = pd->count = 0; #endif - } - } + } + } } PerformanceMonitorOperation::PerformanceMonitorOperation(PerformanceData* data, std::string name, PerformanceStack* stack) : data(data), name(name), stack(stack) @@ -293,6 +292,11 @@ PerformanceMonitorOperation::PerformanceMonitorOperation(PerformanceData* data, #endif } +PerformanceMonitorOperation::~PerformanceMonitorOperation() +{ + finish(); +} + void PerformanceMonitorOperation::finish() { #ifdef CMANGOS @@ -313,7 +317,6 @@ void PerformanceMonitorOperation::finish() { stack->erase(std::remove(stack->begin(), stack->end(), name), stack->end()); } - delete this; } bool ChatHandler::HandlePerfMonCommand(char* args) diff --git a/playerbot/PerformanceMonitor.h b/playerbot/PerformanceMonitor.h index 903ebadd..d01e1d72 100644 --- a/playerbot/PerformanceMonitor.h +++ b/playerbot/PerformanceMonitor.h @@ -32,9 +32,11 @@ class PerformanceMonitorOperation { public: PerformanceMonitorOperation(PerformanceData* data, std::string name, PerformanceStack* stack); - void finish(); + ~PerformanceMonitorOperation(); private: + void finish(); + PerformanceData* data; std::string name; PerformanceStack* stack; @@ -54,15 +56,17 @@ class PerformanceMonitor return instance; } - public: - PerformanceMonitorOperation* start(PerformanceMetric metric, std::string name, PerformanceStack* stack = nullptr); - PerformanceMonitorOperation* start(PerformanceMetric metric, std::string name, PlayerbotAI* ai); + public: + std::unique_ptr start(PerformanceMetric metric, std::string name, PerformanceStack* stack = nullptr); + std::unique_ptr start(PerformanceMetric metric, std::string name, PlayerbotAI* ai); void PrintStats(bool perTick = false, bool fullStack = false); void Reset(); - private: + + private: std::map > data; + #ifdef CMANGOS - std::mutex lock; + std::mutex lock; #endif }; diff --git a/playerbot/PlayerbotAI.cpp b/playerbot/PlayerbotAI.cpp index 81c28713..207c3a52 100644 --- a/playerbot/PlayerbotAI.cpp +++ b/playerbot/PlayerbotAI.cpp @@ -244,7 +244,8 @@ PlayerbotAI::~PlayerbotAI() void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) { std::string mapString = WorldPosition(bot).isOverworld() ? std::to_string(bot->GetMapId()) : "I"; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAI " + mapString); + auto pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAI " + mapString); + if(aiInternalUpdateDelay > elapsed) { aiInternalUpdateDelay -= elapsed; @@ -513,7 +514,6 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) // Cancel the update if the new delay increased if (!CanUpdateAIInternal()) { - if (pmo) pmo->finish(); return; } } @@ -530,16 +530,16 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal) YieldAIInternalThread(min); } - if (pmo) pmo->finish(); } bool PlayerbotAI::UpdateAIReaction(uint32 elapsed, bool minimal, bool isStunned) { bool reactionFound; std::string mapString = WorldPosition(bot).isOverworld() ? std::to_string(bot->GetMapId()) : "I"; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIReaction " + mapString); + + auto pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIReaction " + mapString); const bool reactionInProgress = reactionEngine->Update(elapsed, minimal, isStunned, reactionFound); - if (pmo) pmo->finish(); + pmo.reset(); if(reactionFound) { @@ -1038,7 +1038,7 @@ void PlayerbotAI::UpdateAIInternal(uint32 elapsed, bool minimal) return; std::string mapString = WorldPosition(bot).isOverworld() ? std::to_string(bot->GetMapId()) : "I"; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIInternal " + mapString); + auto pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAI::UpdateAIInternal " + mapString); ExternalEventHelper helper(aiObjectContext); @@ -1105,7 +1105,6 @@ void PlayerbotAI::UpdateAIInternal(uint32 elapsed, bool minimal) masterOutgoingPacketHandlers.Handle(helper); DoNextAction(minimal); - if (pmo) pmo->finish(); } void PlayerbotAI::HandleTeleportAck() diff --git a/playerbot/PlayerbotAIBase.cpp b/playerbot/PlayerbotAIBase.cpp index fdce1ed4..2a23abbb 100644 --- a/playerbot/PlayerbotAIBase.cpp +++ b/playerbot/PlayerbotAIBase.cpp @@ -14,9 +14,7 @@ void PlayerbotAIBase::UpdateAIInternal(uint32 elapsed, bool minimal) void PlayerbotAIBase::UpdateAI(uint32 elapsed) { - if (totalPmo) - totalPmo->finish(); - + totalPmo.reset(); totalPmo = sPerformanceMonitor.start(PERF_MON_TOTAL, "PlayerbotAIBase::FullTick"); if (aiInternalUpdateDelay > elapsed) diff --git a/playerbot/PlayerbotAIBase.h b/playerbot/PlayerbotAIBase.h index acdc2659..f8d69977 100644 --- a/playerbot/PlayerbotAIBase.h +++ b/playerbot/PlayerbotAIBase.h @@ -5,10 +5,12 @@ class PlayerbotMgr; class ChatHandler; class PerformanceMonitorOperation; +#include + class PlayerbotAIBase { public: - PlayerbotAIBase(); + PlayerbotAIBase(); public: bool IsActive() const; @@ -26,5 +28,6 @@ class PlayerbotAIBase protected: uint32 aiInternalUpdateDelay; - PerformanceMonitorOperation* totalPmo = nullptr; + + std::unique_ptr totalPmo; }; diff --git a/playerbot/PlayerbotFactory.cpp b/playerbot/PlayerbotFactory.cpp index f1ae4746..703f1c06 100644 --- a/playerbot/PlayerbotFactory.cpp +++ b/playerbot/PlayerbotFactory.cpp @@ -175,7 +175,7 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) bool isRandomBot = sRandomPlayerbotMgr.IsRandomBot(bot) && bot->GetPlayerbotAI() && !bot->GetPlayerbotAI()->HasRealPlayerMaster() && !bot->GetPlayerbotAI()->IsInRealGuild(); sLog.outDetail("Resetting player..."); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reset"); //ClearSkills(); ClearSpells(); @@ -209,23 +209,16 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) bot->SetUInt32Value(PLAYER_NEXT_LEVEL_XP, sObjectMgr.GetXPForLevel(level)); } } - if (pmo) pmo->finish(); + pmo.reset(); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags"); sLog.outDetail("Initializing bags..."); InitBags(); - if (pmo) pmo->finish(); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1"); sLog.outDetail("Initializing spells (step 1)..."); InitAvailableSpells(); - if (pmo) pmo->finish(); sLog.outDetail("Initializing skills (step 1)..."); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1"); - InitSkills(); - InitTradeSkills(); - if (pmo) pmo->finish(); + InitAllSkills(); pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Talents"); sLog.outDetail("Initializing talents..."); @@ -237,33 +230,28 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) sPlayerbotDbStore.Reset(ai); ai->ResetStrategies(incremental); // fix wrong stored strategy - if (pmo) pmo->finish(); + pmo.reset(); pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells2"); sLog.outDetail("Initializing spells (step 2)..."); InitAvailableSpells(); InitSpecialSpells(); - if (pmo) pmo->finish(); + pmo.reset(); if (isRealRandomBot) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts"); sLog.outDetail("Initializing mounts..."); InitMounts(); - if (pmo) pmo->finish(); } - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills2"); sLog.outDetail("Initializing skills (step 2)..."); UpdateTradeSkills(); - if (pmo) pmo->finish(); if (isRealRandomBot) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reputations"); sLog.outDetail("Initializing reputations..."); InitReputations(); - if (pmo) pmo->finish(); + } pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Equip"); @@ -276,37 +264,27 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) InitEquipment(incremental, syncWithMaster); InitGems(); - if (pmo) pmo->finish(); + pmo.reset(); if (isRandomBot) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo"); sLog.outDetail("Initializing ammo..."); InitAmmo(); - if (pmo) pmo->finish(); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Food"); sLog.outDetail("Initializing food..."); InitFood(); - if (pmo) pmo->finish(); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions"); sLog.outDetail("Initializing potions..."); InitPotions(); - if (pmo) pmo->finish(); - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents"); sLog.outDetail("Initializing reagents..."); InitReagents(); - if (pmo) pmo->finish(); } if (!incremental) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumables"); sLog.outDetail("Initializing consumables..."); AddConsumables(); - if (pmo) pmo->finish(); } if (!incremental && isRandomBot) @@ -316,31 +294,28 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) InitSecondEquipmentSet(); if (pmo) pmo->finish();*/ - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory"); sLog.outDetail("Initializing inventory..."); InitInventory(); - if (pmo) pmo->finish(); } if (isRandomBot) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Guilds & ArenaTeams"); + auto pmo_guild_teams = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Guilds & ArenaTeams"); sLog.outDetail("Initializing guilds & ArenaTeams"); InitGuild(); #ifndef MANGOSBOT_ZERO if (bot->GetLevel() >= 70) InitArenaTeam(); #endif - if (pmo) pmo->finish(); } - if (bot->GetLevel() >= 10) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet"); - sLog.outDetail("Initializing pet..."); - InitPet(); + if (bot->GetLevel() >= 10) + { + auto pmo_pet = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Pet"); + sLog.outDetail("Initializing pet..."); + InitPet(); InitPetSpells(); - if (pmo) pmo->finish(); - } + } if (isRandomBot) { @@ -357,10 +332,8 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) if (isRandomBot) { - pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_TaxiNodes"); sLog.outDetail("Initializing taxi..."); InitTaxiNodes(); - if (pmo) pmo->finish(); } pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Save"); @@ -368,7 +341,7 @@ void PlayerbotFactory::Randomize(bool incremental, bool syncWithMaster) if (sRandomPlayerbotMgr.GetDatabaseDelay("CharacterDatabase") < 10 * IN_MILLISECONDS) bot->SaveToDB(); sLog.outDetail("Done."); - if (pmo) pmo->finish(); + pmo.reset(); } void PlayerbotFactory::Refresh() @@ -388,6 +361,7 @@ void PlayerbotFactory::Refresh() void PlayerbotFactory::AddConsumables() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Consumables"); switch (bot->getClass()) { case CLASS_PRIEST: @@ -956,6 +930,7 @@ void PlayerbotFactory::ResetQuests() void PlayerbotFactory::InitReputations() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reputations"); // list of factions std::list factions; @@ -2269,6 +2244,7 @@ void PlayerbotFactory::InitSecondEquipmentSet() void PlayerbotFactory::InitBags() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Bags"); for (uint8 slot = INVENTORY_SLOT_BAG_START; slot < INVENTORY_SLOT_BAG_END; ++slot) { Bag* pBag = (Bag*)bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); @@ -2414,6 +2390,13 @@ void PlayerbotFactory::AddGems(Item* item) #endif } +void PlayerbotFactory::InitAllSkills() +{ + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills1"); + InitSkills(); + InitTradeSkills(); +} + void PlayerbotFactory::InitTradeSkills() { uint16 firstSkill = sRandomPlayerbotMgr.GetValue(bot, "firstSkill"); @@ -2604,6 +2587,7 @@ void PlayerbotFactory::InitTradeSkills() void PlayerbotFactory::UpdateTradeSkills() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Skills2"); for (int i = 0; i < sizeof(tradeSkills) / sizeof(uint32); ++i) { if (bot->GetSkillValue(tradeSkills[i]) == 1) @@ -2785,6 +2769,7 @@ void PlayerbotFactory::SetRandomSkill(uint16 id) void PlayerbotFactory::InitAvailableSpells() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Spells1"); bot->learnDefaultSpells(); bot->learnClassLevelSpells(true); @@ -3039,6 +3024,7 @@ void PlayerbotFactory::ClearAllItems() void PlayerbotFactory::InitAmmo() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Ammo"); if (bot->getClass() != CLASS_HUNTER && bot->getClass() != CLASS_ROGUE && bot->getClass() != CLASS_WARRIOR) return; @@ -3097,6 +3083,7 @@ void PlayerbotFactory::InitAmmo() void PlayerbotFactory::InitMounts() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Mounts"); uint32 firstmount = #ifdef MANGOSBOT_ZERO 40 @@ -3235,6 +3222,7 @@ void PlayerbotFactory::InitMounts() void PlayerbotFactory::InitPotions() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Potions"); uint32 effects[] = { SPELL_EFFECT_HEAL, SPELL_EFFECT_ENERGIZE }; for (int i = 0; i < 2; ++i) { @@ -3264,6 +3252,7 @@ void PlayerbotFactory::InitPotions() void PlayerbotFactory::InitFood() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Food"); uint32 categories[] = { 11, 59 }; for (int i = 0; i < 2; ++i) { @@ -3292,6 +3281,7 @@ void PlayerbotFactory::InitFood() void PlayerbotFactory::InitReagents() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Reagents"); std::list items; uint32 regCount = 1; switch (bot->getClass()) @@ -3452,6 +3442,7 @@ void PlayerbotFactory::CancelAuras() void PlayerbotFactory::InitInventory() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_Inventory"); //InitInventoryTrade(); //InitInventoryEquip(); InitInventorySkill(); @@ -4120,6 +4111,7 @@ void PlayerbotFactory::InitGems() //WIP void PlayerbotFactory::InitTaxiNodes() { + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "PlayerbotFactory_TaxiNodes"); uint32 startMap = bot->GetMapId(); if (startMap == 530) //BE=EK, DREA=KAL diff --git a/playerbot/PlayerbotFactory.h b/playerbot/PlayerbotFactory.h index 147dcd9d..66a51824 100644 --- a/playerbot/PlayerbotFactory.h +++ b/playerbot/PlayerbotFactory.h @@ -74,6 +74,7 @@ class PlayerbotFactory void InitEquipment(bool incremental, bool syncWithMaster, bool progressive = sPlayerbotAIConfig.randomGearProgression, bool partialUpgrade = false); void InitEquipmentNew(bool incremental); bool CanEquipItem(ItemPrototype const* proto, uint32 desiredQuality); + void InitAllSkills(); void InitTradeSkills(); void UpdateTradeSkills(); void SetRandomSkill(uint16 id); diff --git a/playerbot/RandomPlayerbotMgr.cpp b/playerbot/RandomPlayerbotMgr.cpp index fee81679..221f879b 100644 --- a/playerbot/RandomPlayerbotMgr.cpp +++ b/playerbot/RandomPlayerbotMgr.cpp @@ -561,7 +561,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool minimal) SetAIInternalUpdateDelay(sPlayerbotAIConfig.randomBotUpdateInterval * 1000); - PerformanceMonitorOperation *pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, + auto pmo = sPerformanceMonitor.start(PERF_MON_TOTAL, onlineBotCount < maxAllowedBotCount ? "RandomPlayerbotMgr::Login" : "RandomPlayerbotMgr::UpdateAIInternal"); if (time(nullptr) > (EventTimeSyncTimer + 30)) @@ -648,7 +648,7 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool minimal) } } - if (pmo) pmo->finish(); + pmo.reset(); LoginFreeBots(); @@ -2242,7 +2242,7 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector return; } - PerformanceMonitorOperation *pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomTeleportByLocations"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomTeleportByLocations"); int index = 0; @@ -2326,12 +2326,10 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot, std::vector } } - if (pmo) pmo->finish(); return; } } - if (pmo) pmo->finish(); sLog.outError("Cannot teleport bot %s - no locations available", bot->GetName()); } @@ -2606,7 +2604,7 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot) if (bot->InBattleGround()) return; - PerformanceMonitorOperation *pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomTeleport"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomTeleport"); std::vector locs; std::list targets; @@ -2635,7 +2633,7 @@ void RandomPlayerbotMgr::RandomTeleport(Player* bot) RandomTeleportForLevel(bot, true); } - if (pmo) pmo->finish(); + pmo.reset(); Refresh(bot); } @@ -2691,7 +2689,7 @@ void RandomPlayerbotMgr::Randomize(Player* bot) void RandomPlayerbotMgr::UpdateGearSpells(Player* bot) { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "UpgradeGear"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "UpgradeGear"); uint32 maxLevel = sPlayerbotAIConfig.randomBotMaxLevel; if (maxLevel > sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) @@ -2708,21 +2706,19 @@ void RandomPlayerbotMgr::UpdateGearSpells(Player* bot) // schedule randomise uint32 randomTime = urand(sPlayerbotAIConfig.minRandomBotRandomizeTime, sPlayerbotAIConfig.maxRandomBotRandomizeTime); SetEventValue(bot->GetGUIDLow(), "randomize", 1, randomTime); - - if (pmo) pmo->finish(); } void RandomPlayerbotMgr::RandomizeFirst(Player* bot) { - uint32 maxLevel = sPlayerbotAIConfig.randomBotMaxLevel; - if (maxLevel > sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) - maxLevel = sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL); + uint32 maxLevel = sPlayerbotAIConfig.randomBotMaxLevel; + if (maxLevel > sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL)) + maxLevel = sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL); // if lvl sync is enabled, max level is limited by online players lvl if (sPlayerbotAIConfig.syncLevelWithPlayers) maxLevel = std::max(sPlayerbotAIConfig.randomBotMinLevel, std::min(playersLevel+ sPlayerbotAIConfig.syncLevelMaxAbove, sWorld.getConfig(CONFIG_UINT32_MAX_PLAYER_LEVEL))); - PerformanceMonitorOperation *pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomizeFirst"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "RandomizeFirst"); uint32 level = urand(std::max(uint32(sWorld.getConfig(CONFIG_UINT32_START_PLAYER_LEVEL)), sPlayerbotAIConfig.randomBotMinLevel), maxLevel); #ifdef MANGOSBOT_TWO @@ -2764,8 +2760,6 @@ void RandomPlayerbotMgr::RandomizeFirst(Player* bot) if (bot->GetGroup() && !hasPlayer) bot->RemoveFromGroup(); - - if (pmo) pmo->finish(); } uint32 RandomPlayerbotMgr::GetZoneLevel(uint16 mapId, float teleX, float teleY, float teleZ) @@ -2814,7 +2808,7 @@ void RandomPlayerbotMgr::Refresh(Player* bot) return; sLog.outDetail("Refreshing bot #%d <%s>", bot->GetGUIDLow(), bot->GetName()); - PerformanceMonitorOperation *pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "Refresh"); + auto pmo = sPerformanceMonitor.start(PERF_MON_RNDBOT, "Refresh"); bot->GetPlayerbotAI()->Reset(); @@ -2837,8 +2831,6 @@ void RandomPlayerbotMgr::Refresh(Player* bot) uint32 money = bot->GetMoney(); bot->SetMoney(money + 500 * sqrt(urand(1, bot->GetLevel() * 5))); - - if (pmo) pmo->finish(); } bool RandomPlayerbotMgr::IsRandomBot(Player* bot) diff --git a/playerbot/strategy/Engine.cpp b/playerbot/strategy/Engine.cpp index e8ce9bb3..6a284c90 100644 --- a/playerbot/strategy/Engine.cpp +++ b/playerbot/strategy/Engine.cpp @@ -154,7 +154,7 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) if (!event.getSource().empty()) actionName += " <" + event.getSource() + ">"; - PerformanceMonitorOperation* pmo1 = sPerformanceMonitor.start(PERF_MON_ACTION, actionName, &aiObjectContext->performanceStack); + auto pmo1 = sPerformanceMonitor.start(PERF_MON_ACTION, actionName, &aiObjectContext->performanceStack); if(action) action->setRelevance(relevance); @@ -180,9 +180,9 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) } else { - PerformanceMonitorOperation* pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "isUseful", &aiObjectContext->performanceStack); + auto pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "isUseful", &aiObjectContext->performanceStack); bool isUseful = action->isUseful(); - if (pmo2) pmo2->finish(); + pmo2.reset(); if (isUseful && (!isStunned || action->isUsefulWhenStunned())) { @@ -203,7 +203,6 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) if (relevance < oldRelevance && peekAction && peekAction->getRelevance() > relevance) //Relevance changed. Try again. { PushAgain(actionNode, relevance, event); - if (pmo1) pmo1->finish(); continue; } @@ -213,21 +212,19 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) if (MultiplyAndPush(actionNode->getPrerequisites(), relevance + 0.02, false, event, "prereq")) { PushAgain(actionNode, relevance + 0.01, event); - - if (pmo1) pmo1->finish(); continue; } } - PerformanceMonitorOperation* pmo3 = sPerformanceMonitor.start(PERF_MON_ACTION, "isPossible", &aiObjectContext->performanceStack); + auto pmo3 = sPerformanceMonitor.start(PERF_MON_ACTION, "isPossible", &aiObjectContext->performanceStack); bool isPossible = action->isPossible(); - if (pmo3) pmo3->finish(); + pmo3.reset(); if (isPossible && relevance) { - PerformanceMonitorOperation* pmo4 = sPerformanceMonitor.start(PERF_MON_ACTION, "Execute", &aiObjectContext->performanceStack); + auto pmo4 = sPerformanceMonitor.start(PERF_MON_ACTION, "Execute", &aiObjectContext->performanceStack); actionExecuted = ListenAndExecute(action, event); - if (pmo4) pmo4->finish(); + pmo4.reset(); #ifdef PLAYERBOT_ELUNA // used by eluna @@ -241,7 +238,6 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) MultiplyAndPush(actionNode->getContinuers(), 0, false, event, "cont"); lastRelevance = relevance; delete actionNode; - if (pmo1) pmo1->finish(); break; } else @@ -293,8 +289,6 @@ bool Engine::DoNextAction(Unit* unit, int depth, bool minimal, bool isStunned) } } delete actionNode; - - if (pmo1) pmo1->finish(); } } while (basket && ++iterations <= iterationsPerTick); @@ -412,25 +406,27 @@ ActionResult Engine::ExecuteAction(const std::string& name, Event& event) ActionNode* actionNode = CreateActionNode(name); if (actionNode) { - PerformanceMonitorOperation* pmo1 = sPerformanceMonitor.start(PERF_MON_ACTION, name, &aiObjectContext->performanceStack); + auto pmo1 = sPerformanceMonitor.start(PERF_MON_ACTION, name, &aiObjectContext->performanceStack); Action* action = InitializeAction(actionNode); if (action) { - PerformanceMonitorOperation* pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "isUseful", &aiObjectContext->performanceStack); + auto pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "isUseful", &aiObjectContext->performanceStack); bool isUseful = action->isUseful(); - if (pmo2) pmo2->finish(); + pmo2.reset(); + if (isUseful) { - PerformanceMonitorOperation* pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "isPossible", &aiObjectContext->performanceStack); + auto pmo3 = sPerformanceMonitor.start(PERF_MON_ACTION, "isPossible", &aiObjectContext->performanceStack); bool isPossible = action->isPossible(); - if (pmo2) pmo2->finish(); + pmo3.reset(); if (isPossible) { action->MakeVerbose(true); - PerformanceMonitorOperation* pmo2 = sPerformanceMonitor.start(PERF_MON_ACTION, "Execute", &aiObjectContext->performanceStack); + auto pmo4 = sPerformanceMonitor.start(PERF_MON_ACTION, "Execute", &aiObjectContext->performanceStack); bool executionResult = ListenAndExecute(action, event); - if (pmo2) pmo2->finish(); + pmo4.reset(); + MultiplyAndPush(action->getContinuers(), 0.0f, false, event, "default"); actionResult = executionResult ? ACTION_RESULT_OK : ACTION_RESULT_FAILED; } @@ -444,8 +440,6 @@ ActionResult Engine::ExecuteAction(const std::string& name, Event& event) actionResult = ACTION_RESULT_USELESS; } } - if (pmo1) pmo1->finish(); - delete actionNode; } @@ -590,7 +584,7 @@ void Engine::ProcessTriggers(bool minimal) { if (minimal && node->getFirstRelevance() < 100) continue; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_TRIGGER, trigger->getName(), &aiObjectContext->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_TRIGGER, trigger->getName(), &aiObjectContext->performanceStack); event = trigger->Check(); #ifdef PLAYERBOT_ELUNA @@ -599,7 +593,6 @@ void Engine::ProcessTriggers(bool minimal) e->OnTriggerCheck(ai, trigger->getName(), !event ? false : true); #endif - if (pmo) pmo->finish(); if (!event) continue; diff --git a/playerbot/strategy/Value.h b/playerbot/strategy/Value.h index 23def694..a53da988 100644 --- a/playerbot/strategy/Value.h +++ b/playerbot/strategy/Value.h @@ -61,9 +61,8 @@ namespace ai { lastCheckTime = now; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, AiNamedObject::getName(), this->ai); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, AiNamedObject::getName(), this->ai); value = Calculate(); - if (pmo) pmo->finish(); } return value; } @@ -99,9 +98,8 @@ namespace ai { this->lastCheckTime = now; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, AiNamedObject::getName(), this->ai); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, AiNamedObject::getName(), this->ai); this->value = this->Calculate(); - if (pmo) pmo->finish(); } return this->value; } diff --git a/playerbot/strategy/actions/AhAction.cpp b/playerbot/strategy/actions/AhAction.cpp index 496be1d1..c396231e 100644 --- a/playerbot/strategy/actions/AhAction.cpp +++ b/playerbot/strategy/actions/AhAction.cpp @@ -64,9 +64,9 @@ bool AhAction::ExecuteCommand(Player* requester, std::string text, Unit* auction if(AI_VALUE2(ItemUsage, "item usage", ItemQualifier(item).GetQualifier()) != ItemUsage::ITEM_USAGE_AH) continue; - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsMoreProfitableToSellToAHThanToVendor", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsMoreProfitableToSellToAHThanToVendor", &context->performanceStack); bool isMoreProfitableToSellToAHThanToVendor = ItemUsageValue::IsMoreProfitableToSellToAHThanToVendor(item->GetProto(), bot); - if (pmo) pmo->finish(); + pmo.reset(); if (!isMoreProfitableToSellToAHThanToVendor) continue; @@ -312,9 +312,9 @@ bool AhBidAction::ExecuteCommand(Player* requester, std::string text, Unit* auct break; case ItemUsage::ITEM_USAGE_AH: { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsWorthBuyingFromAhToResellAtAH", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsWorthBuyingFromAhToResellAtAH", &context->performanceStack); bool isWorthBuyingFromAhToResellAtAH = ItemUsageValue::IsWorthBuyingFromAhToResellAtAH(sObjectMgr.GetItemPrototype(auction->itemTemplate), totalCost, auction->itemCount); - if (pmo) pmo->finish(); + pmo.reset(); if (!isWorthBuyingFromAhToResellAtAH) continue; diff --git a/playerbot/strategy/actions/BuyAction.cpp b/playerbot/strategy/actions/BuyAction.cpp index 96fc3151..b5557fd3 100644 --- a/playerbot/strategy/actions/BuyAction.cpp +++ b/playerbot/strategy/actions/BuyAction.cpp @@ -87,9 +87,9 @@ bool BuyAction::Execute(Event& event) //if item is worth selling to AH? - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsWorthBuyingFromVendorToResellAtAH", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "IsWorthBuyingFromVendorToResellAtAH", &context->performanceStack); bool isWorthBuyingFromVendorToResellAtAH = ItemUsageValue::IsWorthBuyingFromVendorToResellAtAH(proto, tItem->maxcount > 0); - if (pmo) pmo->finish(); + pmo.reset(); if (isWorthBuyingFromVendorToResellAtAH) freeMoney[ItemUsage::ITEM_USAGE_AH] = (uint32)NeedMoneyFor::anything; diff --git a/playerbot/strategy/actions/ChooseTravelTargetAction.cpp b/playerbot/strategy/actions/ChooseTravelTargetAction.cpp index 61c24787..5fea4af0 100644 --- a/playerbot/strategy/actions/ChooseTravelTargetAction.cpp +++ b/playerbot/strategy/actions/ChooseTravelTargetAction.cpp @@ -82,9 +82,8 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (shouldRpg) { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetRpgTarget1", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetRpgTarget1", &context->performanceStack); foundTarget = SetRpgTarget(requester, newTarget); //Go to town to sell items or repair - if (pmo) pmo->finish(); } } @@ -94,9 +93,8 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (!foundTarget && urand(1, 100) > 90 && bot->GetLevel() > 5 && botPos.isOverworld()) //10% chance if not currenlty in dungeon. { ai->TellDebug(requester, "Random rpg in city", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetNpcFlagTarget2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetNpcFlagTarget2", &context->performanceStack); foundTarget = SetNpcFlagTarget(requester, newTarget, { UNIT_NPC_FLAG_BANKER,UNIT_NPC_FLAG_BATTLEMASTER,UNIT_NPC_FLAG_AUCTIONEER }); - if(pmo) pmo->finish(); } // PvP activities @@ -132,9 +130,8 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (AI_VALUE(bool, "can get mail")) { ai->TellDebug(requester, "Get mail for money", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGoTarget1", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGoTarget1", &context->performanceStack); foundTarget = SetGOTypeTarget(requester, newTarget, GAMEOBJECT_TYPE_MAILBOX,"",false); //Find a mailbox - if (pmo) pmo->finish(); } if (!foundTarget) @@ -143,26 +140,23 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new { { ai->TellDebug(requester, "Turn in quests for money", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget1", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget1", &context->performanceStack); foundTarget = SetQuestTarget(requester, newTarget, false, true, true); //Turn in quests for money. - if (pmo) pmo->finish(); } if (!foundTarget) { ai->TellDebug(requester, "Start quests for money", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget2", &context->performanceStack); foundTarget = SetQuestTarget(requester, newTarget, true, false, false); //Find new (low) level quests - if (pmo) pmo->finish(); } } if (!foundTarget) { ai->TellDebug(requester, "Grind mobs for money", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGrindTarget1", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGrindTarget1", &context->performanceStack); foundTarget = SetGrindTarget(requester, newTarget); //Go grind mobs for money - if (pmo) pmo->finish(); } } } @@ -172,9 +166,8 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (!foundTarget && (!botPos.isOverworld() || urand(1, 100) > 10)) //90% chance or currently in dungeon. { ai->TellDebug(requester, "Continue previous target", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetCurrentTarget", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetCurrentTarget", &context->performanceStack); foundTarget = SetCurrentTarget(requester, newTarget, oldTarget); //Extend current target. - if(pmo) pmo->finish(); } //Get mail @@ -183,9 +176,8 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (AI_VALUE(bool, "can get mail")) { ai->TellDebug(requester, "Get mail", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGoTarget2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGoTarget2", &context->performanceStack); foundTarget = SetGOTypeTarget(requester, newTarget, GAMEOBJECT_TYPE_MAILBOX, "", false); //Find a mailbox - if (pmo) pmo->finish(); } } @@ -194,27 +186,24 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new if (AI_VALUE(bool, "can fight boss")) { ai->TellDebug(requester, "Fight boss for loot", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetBossTarget", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetBossTarget", &context->performanceStack); foundTarget = SetBossTarget(requester, newTarget); //Go fight a (dungeon boss) - if(pmo) pmo->finish(); } //Do quests (start, do, end) if (!foundTarget && urand(1, 100) > 5) //95% chance { ai->TellDebug(requester, "Do questing", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetQuestTarget", &context->performanceStack); foundTarget = SetQuestTarget(requester, newTarget, true, true, true); //Do any nearby - if(pmo) pmo->finish(); } //Explore a nearby unexplored area. if (!foundTarget && ai->HasStrategy("explore", BotState::BOT_STATE_NON_COMBAT) && urand(1, 100) > 90) //10% chance Explore a unexplored sub-zone. { ai->TellDebug(requester, "Explore unexplored areas", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetExploreTarget", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetExploreTarget", &context->performanceStack); foundTarget = SetExploreTarget(requester, newTarget); - if(pmo) pmo->finish(); } //Just hang with an npc @@ -222,20 +211,18 @@ void ChooseTravelTargetAction::getNewTarget(Player* requester, TravelTarget* new { { ai->TellDebug(requester, "Rpg with random npcs", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetRpgTarget2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetRpgTarget2", &context->performanceStack); foundTarget = SetRpgTarget(requester, newTarget); if (foundTarget) newTarget->setForced(true); - if(pmo) pmo->finish(); } } if (!foundTarget) { ai->TellDebug(requester, "Grind random mobs", "debug travel"); - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGrindTarget2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "SetGrindTarget2", &context->performanceStack); foundTarget = SetGrindTarget(requester, newTarget); - if(pmo) pmo->finish(); } if (!foundTarget) @@ -572,7 +559,7 @@ void ChooseTravelTargetAction::ReportTravelTarget(Player* requester, TravelTarge //Select only those points that are in sight distance or failing that a multiplication of the sight distance. std::vector ChooseTravelTargetAction::getLogicalPoints(Player* requester, std::vector& travelPoints) { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getLogicalPoints", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getLogicalPoints", &context->performanceStack); std::vector retvec; static std::vector distanceLimits = { sPlayerbotAIConfig.sightDistance, 4 * sPlayerbotAIConfig.sightDistance, 10 * sPlayerbotAIConfig.sightDistance, 20 * sPlayerbotAIConfig.sightDistance, 50 * sPlayerbotAIConfig.sightDistance, 100 * sPlayerbotAIConfig.sightDistance, 10000 * sPlayerbotAIConfig.sightDistance }; @@ -605,21 +592,22 @@ std::vector ChooseTravelTargetAction::getLogicalPoints(Player* r else centerLocation = WorldPosition(bot); - PerformanceMonitorOperation* pmo1 = sPerformanceMonitor.start(PERF_MON_VALUE, "Shuffle", &context->performanceStack); - if(travelPoints.size() > 50) - std::shuffle(travelPoints.begin(), travelPoints.end(), *GetRandomGenerator()); - if(pmo1) pmo1->finish(); + { + auto pmo1 = sPerformanceMonitor.start(PERF_MON_VALUE, "Shuffle", &context->performanceStack); + if (travelPoints.size() > 50) + std::shuffle(travelPoints.begin(), travelPoints.end(), *GetRandomGenerator()); + } uint8 checked = 0; //Loop over all points for (auto pos : travelPoints) - { + { if (pos->getMapId() == bot->GetMapId()) { - PerformanceMonitorOperation* pmo1 = sPerformanceMonitor.start(PERF_MON_VALUE, "AreaLevel", &context->performanceStack); + auto pmo1 = sPerformanceMonitor.start(PERF_MON_VALUE, "AreaLevel", &context->performanceStack); + int32 areaLevel = pos->getAreaLevel(); - if (pmo1) pmo1->finish(); if (!pos->isOverworld() && !canFightElite) areaLevel += 10; @@ -630,23 +618,22 @@ std::vector ChooseTravelTargetAction::getLogicalPoints(Player* r GuidPosition* guidP = dynamic_cast(pos); - PerformanceMonitorOperation* pmo2 = sPerformanceMonitor.start(PERF_MON_VALUE, "IsEventUnspawned", &context->performanceStack); + auto pmo2 = sPerformanceMonitor.start(PERF_MON_VALUE, "IsEventUnspawned", &context->performanceStack); if (guidP && guidP->IsEventUnspawned()) //Skip points that are not spawned due to events. { - if(pmo2) pmo2->finish(); continue; } - if (pmo2) pmo2->finish(); + pmo2.reset(); - PerformanceMonitorOperation* pmo3 = sPerformanceMonitor.start(PERF_MON_VALUE, "distancePartition", &context->performanceStack); + auto pmo3 = sPerformanceMonitor.start(PERF_MON_VALUE, "distancePartition", &context->performanceStack); centerLocation.distancePartition(distanceLimits, pos, partitions); //Partition point in correct distance bracket. - if (pmo3) pmo3->finish(); + pmo3.reset(); if (checked++ > 50) break; } - if(pmo) pmo->finish(); + pmo.reset(); for (uint8 l = 0; l < distanceLimits.size(); l++) { @@ -825,9 +812,8 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t if (newQuests) { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations1", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations1", &context->performanceStack); TravelDestinations = sTravelMgr.getQuestTravelDestinations(bot, -1, true, false, 400 + bot->GetLevel() * 10); //Prefer new quests near the player at lower levels. - if(pmo) pmo->finish(); } if (ai->HasStrategy("debug travel", BotState::BOT_STATE_NON_COMBAT)) @@ -855,9 +841,9 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t continue; //Find quest takers or objectives - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations2", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations2", &context->performanceStack); std::vector questDestinations = sTravelMgr.getQuestTravelDestinations(bot, questId, true, false,0); - if(pmo) pmo->finish(); + pmo.reset(); if (onlyClassQuest && TravelDestinations.size() && questDestinations.size()) //Only do class quests if we have any. { @@ -874,9 +860,8 @@ bool ChooseTravelTargetAction::SetQuestTarget(Player* requester, TravelTarget* t if (newQuests && TravelDestinations.empty()) { - PerformanceMonitorOperation* pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations3", &context->performanceStack); + auto pmo = sPerformanceMonitor.start(PERF_MON_VALUE, "getQuestTravelDestinations3", &context->performanceStack); TravelDestinations = sTravelMgr.getQuestTravelDestinations(bot, -1, true, false); //If we really don't find any new quests look futher away. - if (pmo) pmo->finish(); } if (ai->HasStrategy("debug travel", BotState::BOT_STATE_NON_COMBAT))