mirror of
https://github.com/kadeshar/mod-player-bot-level-brackets.git
synced 2026-01-13 09:17:19 +00:00
Merge pull request #13 from DustinHendrickson/Dustin/SafetyChanges
Pulling the queue processing into its own thread
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "PlayerbotFactory.h"
|
#include "PlayerbotFactory.h"
|
||||||
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
void RemoveAllEquippedItems(Player* bot);
|
void RemoveAllEquippedItems(Player* bot);
|
||||||
void RemoveAllTradeSkills(Player* bot);
|
void RemoveAllTradeSkills(Player* bot);
|
||||||
@@ -23,6 +26,9 @@ void RemoveAllActiveAuras(Player* bot);
|
|||||||
static bool IsAlliancePlayerBot(Player* bot);
|
static bool IsAlliancePlayerBot(Player* bot);
|
||||||
static bool IsHordePlayerBot(Player* bot);
|
static bool IsHordePlayerBot(Player* bot);
|
||||||
|
|
||||||
|
static std::mutex g_ResetMutex;
|
||||||
|
static bool g_RunningResetThread = true;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// LEVEL RANGE CONFIGURATION
|
// LEVEL RANGE CONFIGURATION
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -315,8 +321,13 @@ struct PendingResetEntry
|
|||||||
};
|
};
|
||||||
static std::vector<PendingResetEntry> g_PendingLevelResets;
|
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(); )
|
for (auto it = g_PendingLevelResets.begin(); it != g_PendingLevelResets.end(); )
|
||||||
{
|
{
|
||||||
Player* bot = it->bot;
|
Player* bot = it->bot;
|
||||||
@@ -330,6 +341,7 @@ static void ProcessPendingLevelResets()
|
|||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// WORLD SCRIPT: Bot Level Distribution with Faction Separation
|
// 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);
|
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
|
void OnUpdate(uint32 diff) override
|
||||||
@@ -362,8 +382,6 @@ public:
|
|||||||
return;
|
return;
|
||||||
m_timer = 0;
|
m_timer = 0;
|
||||||
|
|
||||||
ProcessPendingLevelResets();
|
|
||||||
|
|
||||||
// Containers for Alliance bots.
|
// Containers for Alliance bots.
|
||||||
uint32 totalAllianceBots = 0;
|
uint32 totalAllianceBots = 0;
|
||||||
int allianceActualCounts[NUM_RANGES] = {0};
|
int allianceActualCounts[NUM_RANGES] = {0};
|
||||||
|
|||||||
Reference in New Issue
Block a user