Revert expireActionTime (#991)

* Revert expireActionTime

* Revert expireActionTime

* Revert RemoveExpired

* Revert RemoveExpired

* Revert RemoveExpired

* Revert Action expiration
This commit is contained in:
SaW
2025-02-21 04:32:00 +01:00
committed by GitHub
parent 61333a02bf
commit 419e96e5aa
6 changed files with 60 additions and 8 deletions

View File

@@ -239,13 +239,9 @@ bool Engine::DoNextAction(Unit* unit, uint32 depth, bool minimal)
}
if (!actionExecuted)
LogAction("No actions executed");
ActionNode* action = nullptr;
while ((action = queue.Pop()) != nullptr)
{
delete action;
}
LogAction("no actions executed");
queue.RemoveExpired();
return actionExecuted;
}

View File

@@ -48,6 +48,18 @@ uint32 Queue::Size()
return actions.size();
}
void Queue::RemoveExpired()
{
if (!sPlayerbotAIConfig->expireActionTime)
{
return;
}
std::list<ActionBasket*> expiredBaskets;
collectExpiredBaskets(expiredBaskets);
removeAndDeleteBaskets(expiredBaskets);
}
// Private helper methods
void Queue::updateExistingBasket(ActionBasket* existing, ActionBasket* newBasket)
{
@@ -93,3 +105,30 @@ ActionNode* Queue::extractAndDeleteBasket(ActionBasket* basket)
delete basket;
return action;
}
void Queue::collectExpiredBaskets(std::list<ActionBasket*>& expiredBaskets)
{
uint32 expiryTime = sPlayerbotAIConfig->expireActionTime;
for (ActionBasket* basket : actions)
{
if (basket->isExpired(expiryTime))
{
expiredBaskets.push_back(basket);
}
}
}
void Queue::removeAndDeleteBaskets(std::list<ActionBasket*>& basketsToRemove)
{
for (ActionBasket* basket : basketsToRemove)
{
actions.remove(basket);
if (ActionNode* action = basket->getAction())
{
delete action;
}
delete basket;
}
}

View File

@@ -53,6 +53,14 @@ public:
*/
uint32 Size();
/**
* @brief Removes and deletes expired actions from the queue
*
* Uses sPlayerbotAIConfig->expireActionTime to determine if actions have expired.
* Both the ActionNode and ActionBasket are deleted for expired actions.
*/
void RemoveExpired();
private:
/**
* @brief Updates existing basket with new relevance and cleans up new basket
@@ -70,6 +78,11 @@ private:
*/
ActionNode* extractAndDeleteBasket(ActionBasket* basket);
/**
* @brief Collects all expired baskets into the provided list
*/
void collectExpiredBaskets(std::list<ActionBasket*>& expiredBaskets);
/**
* @brief Removes and deletes all baskets in the provided list
*/