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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user