Merge pull request #13 from DustinHendrickson/Dustin/SafetyChanges

Pulling the queue processing into its own thread
This commit is contained in:
Dustin Hendrickson
2025-02-18 16:58:38 -08:00
committed by GitHub

View File

@@ -13,6 +13,9 @@
#include <cmath>
#include <utility>
#include "PlayerbotFactory.h"
#include <thread>
#include <mutex>
#include <chrono>
void RemoveAllEquippedItems(Player* bot);
void RemoveAllTradeSkills(Player* bot);
@@ -23,6 +26,9 @@ void RemoveAllActiveAuras(Player* bot);
static bool IsAlliancePlayerBot(Player* bot);
static bool IsHordePlayerBot(Player* bot);
static std::mutex g_ResetMutex;
static bool g_RunningResetThread = true;
// -----------------------------------------------------------------------------
// LEVEL RANGE CONFIGURATION
// -----------------------------------------------------------------------------
@@ -315,8 +321,13 @@ struct PendingResetEntry
};
static std::vector<PendingResetEntry> g_PendingLevelResets;
static void ProcessPendingLevelResets()
static void ProcessPendingLevelResetsAsync()
{
while (g_RunningResetThread)
{
std::this_thread::sleep_for(std::chrono::seconds(30)); // Run every 30 seconds
std::lock_guard<std::mutex> lock(g_ResetMutex);
for (auto it = g_PendingLevelResets.begin(); it != g_PendingLevelResets.end(); )
{
Player* bot = it->bot;
@@ -330,6 +341,7 @@ static void ProcessPendingLevelResets()
++it;
}
}
}
// -----------------------------------------------------------------------------
// WORLD SCRIPT: Bot Level Distribution with Faction Separation
@@ -353,6 +365,14 @@ public:
i + 1, g_HordeLevelRanges[i].lower, g_HordeLevelRanges[i].upper, g_HordeLevelRanges[i].desiredPercent);
}
}
// Start background thread for pending level resets
std::thread(ProcessPendingLevelResetsAsync).detach();
}
void OnShutdown() override
{
g_RunningResetThread = false;
}
void OnUpdate(uint32 diff) override
@@ -362,8 +382,6 @@ public:
return;
m_timer = 0;
ProcessPendingLevelResets();
// Containers for Alliance bots.
uint32 totalAllianceBots = 0;
int allianceActualCounts[NUM_RANGES] = {0};