From 8a9c25c72ca46c4ea8f491cbf8c6d2a5fe8aa289 Mon Sep 17 00:00:00 2001 From: bash Date: Tue, 29 Oct 2024 10:57:26 +0000 Subject: [PATCH] [performance] initialize server and bots fase --- conf/playerbots.conf.dist | 2 +- src/PlayerbotAI.cpp | 3 +- src/PlayerbotAIConfig.cpp | 2 +- src/RandomPlayerbotMgr.cpp | 59 +++++++++++++++++++++----------------- src/RandomPlayerbotMgr.h | 6 ++-- 5 files changed, 38 insertions(+), 34 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 8d7bf12e..a8273767 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -728,7 +728,7 @@ AiPlayerbot.FastReactInBG = 1 # # All In seconds -AiPlayerbot.RandomBotUpdateInterval = 1 +AiPlayerbot.RandomBotUpdateInterval = 5 AiPlayerbot.RandomBotCountChangeMinInterval = 1800 AiPlayerbot.RandomBotCountChangeMaxInterval = 7200 AiPlayerbot.MinRandomBotInWorldTime = 3600 diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index af993980..6a36ed24 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -4219,8 +4219,7 @@ bool PlayerbotAI::AllowActive(ActivityType activityType) { // no activity allowed during bot initialization during first // few minutes after starting the server based on maxRandomBots. - if (!sRandomPlayerbotMgr->isBotInitCompleted() && - GameTime::GetUptime().count() < sPlayerbotAIConfig->maxRandomBots * 0.15) + if (sRandomPlayerbotMgr->isBotInitializing()) return false; // General exceptions diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 7bf16079..9d9bdd44 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -156,7 +156,7 @@ bool PlayerbotAIConfig::Initialize() randomBotAutologin = sConfigMgr->GetOption("AiPlayerbot.RandomBotAutologin", true); minRandomBots = sConfigMgr->GetOption("AiPlayerbot.MinRandomBots", 50); maxRandomBots = sConfigMgr->GetOption("AiPlayerbot.MaxRandomBots", 200); - randomBotUpdateInterval = sConfigMgr->GetOption("AiPlayerbot.RandomBotUpdateInterval", 1); + randomBotUpdateInterval = sConfigMgr->GetOption("AiPlayerbot.RandomBotUpdateInterval", 5); randomBotCountChangeMinInterval = sConfigMgr->GetOption("AiPlayerbot.RandomBotCountChangeMinInterval", 30 * MINUTE); randomBotCountChangeMaxInterval = diff --git a/src/RandomPlayerbotMgr.cpp b/src/RandomPlayerbotMgr.cpp index 9020f8ce..669d9cea 100644 --- a/src/RandomPlayerbotMgr.cpp +++ b/src/RandomPlayerbotMgr.cpp @@ -40,6 +40,7 @@ #include "Unit.h" #include "UpdateTime.h" #include "World.h" +#include "GameTime.h" void PrintStatsThread() { sRandomPlayerbotMgr->PrintStats(); } @@ -309,12 +310,17 @@ void RandomPlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/) uint32 onlineBotFocus = 75; if (onlineBotCount < (uint32)(sPlayerbotAIConfig->minRandomBots * 90 / 100)) + { onlineBotFocus = 25; + } + + setBotInitializing( + onlineBotCount < maxAllowedBotCount && + GameTime::GetUptime().count() < sPlayerbotAIConfig->maxRandomBots * 0.15); // when server is balancing bots then boost (decrease value of) the nextCheckDelay till // onlineBotCount reached the AllowedBotCount. - setIsBotInitCompleted(onlineBotCount < maxAllowedBotCount); - uint32 updateIntervalTurboBoost = onlineBotCount < maxAllowedBotCount ? 1 : sPlayerbotAIConfig->randomBotUpdateInterval; + uint32 updateIntervalTurboBoost = isBotInitializing() ? 1 : sPlayerbotAIConfig->randomBotUpdateInterval; SetNextCheckDelay(updateIntervalTurboBoost * (onlineBotFocus + 25) * 10); PerformanceMonitorOperation* pmo = sPerformanceMonitor->start( @@ -987,35 +993,34 @@ bool RandomPlayerbotMgr::ProcessBot(uint32 bot) if (isLogginIn) return false; + uint32 randomTime; - if (!player) - { - AddPlayerBot(botGUID, 0); - randomTime = urand(1, 2); - SetEventValue(bot, "login", 1, randomTime); + if (!player) + { + AddPlayerBot(botGUID, 0); + randomTime = urand(1, 2); + SetEventValue(bot, "login", 1, randomTime); - randomTime = urand( - std::max(5, static_cast(sPlayerbotAIConfig->randomBotUpdateInterval * 0.5)), - std::max(12, static_cast(sPlayerbotAIConfig->randomBotUpdateInterval * 2))); - SetEventValue(bot, "update", 1, randomTime); + uint32 updateIntervalTurboBoost = isBotInitializing() ? 1 : sPlayerbotAIConfig->randomBotUpdateInterval; + randomTime = urand(std::max(5, static_cast(updateIntervalTurboBoost * 0.5)), + std::max(10, static_cast(updateIntervalTurboBoost * 2))); + SetEventValue(bot, "update", 1, randomTime); - // do not randomize or teleport immediately after server start (prevent lagging) - if (!GetEventValue(bot, "randomize")) - { - randomTime = urand( - 3,std::max(4, static_cast(sPlayerbotAIConfig->randomBotUpdateInterval * 0.4))); - ScheduleRandomize(bot, randomTime); - } - if (!GetEventValue(bot, "teleport")) - { - randomTime = urand( - std::max(7, static_cast(sPlayerbotAIConfig->randomBotUpdateInterval * 0.7)), - std::max(14, static_cast(sPlayerbotAIConfig->randomBotUpdateInterval * 1.4))); - ScheduleTeleport(bot, randomTime); - } + // do not randomize or teleport immediately after server start (prevent lagging) + if (!GetEventValue(bot, "randomize")) + { + randomTime = urand(3, std::max(4, static_cast(updateIntervalTurboBoost * 0.4))); + ScheduleRandomize(bot, randomTime); + } + if (!GetEventValue(bot, "teleport")) + { + randomTime = urand(std::max(7, static_cast(updateIntervalTurboBoost * 0.7)), + std::max(14, static_cast(updateIntervalTurboBoost * 1.4))); + ScheduleTeleport(bot, randomTime); + } - return true; - } + return true; + } SetEventValue(bot, "login", 0, 0); diff --git a/src/RandomPlayerbotMgr.h b/src/RandomPlayerbotMgr.h index b5208656..10405413 100644 --- a/src/RandomPlayerbotMgr.h +++ b/src/RandomPlayerbotMgr.h @@ -165,8 +165,8 @@ public: static uint8 GetTeamClassIdx(bool isAlliance, uint8 claz) { return isAlliance * 20 + claz; } - bool isBotInitCompleted() const { return _isBotInitCompleted; } - void setIsBotInitCompleted(bool completed) { _isBotInitCompleted = completed; } + bool isBotInitializing() const { return _isBotInitializing; } + void setBotInitializing(bool completed) { _isBotInitializing = completed; } void PrepareAddclassCache(); std::map> addclassCache; @@ -176,7 +176,7 @@ protected: private: // pid values are set in constructor botPID pid = botPID(1, 50, -50, 0, 0, 0); - bool _isBotInitCompleted = false; + bool _isBotInitializing = true; uint32 GetEventValue(uint32 bot, std::string const event); std::string const GetEventData(uint32 bot, std::string const event); uint32 SetEventValue(uint32 bot, std::string const event, uint32 value, uint32 validIn,