Improve performance of AIUtils.FindQueues

The AI would often invoke this method inside of loops, searching for a different category of queue each time. This would result in multiple searches against the trait dictionary to locate matching queues. Now we alter the method to create a lookup of all the queues keyed by category. This allows a single trait search to be performed.

UnitBuilderBotModule and BaseBuilderBotModule are updated to fetch this lookup once when required, and pass the results along to avoid calling the method more times than necessary. This improves their performance.
This commit is contained in:
RoosterDragon
2024-07-05 19:42:22 +01:00
committed by Gustas
parent 62d1f002dd
commit c45e78cf1d
4 changed files with 22 additions and 14 deletions

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
waterState = WaterCheck.DontCheck;
}
public void Tick(IBot bot)
public void Tick(IBot bot, ILookup<string, ProductionQueue> queuesByCategory)
{
// If failed to place something N consecutive times, wait M ticks until resuming building production
if (failCount >= baseBuilder.Info.MaximumFailedPlacementAttempts && --failRetryTicks <= 0)
@@ -106,7 +106,7 @@ namespace OpenRA.Mods.Common.Traits
// PERF: Queue only one actor at a time per category
itemQueuedThisTick = false;
var active = false;
foreach (var queue in AIUtils.FindQueues(player, Category))
foreach (var queue in queuesByCategory[Category])
{
if (TickQueue(bot, queue))
active = true;