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:
@@ -34,11 +34,12 @@ namespace OpenRA.Mods.Common
|
||||
.Any(availableCells => availableCells > 0);
|
||||
}
|
||||
|
||||
public static IEnumerable<ProductionQueue> FindQueues(Player player, string category)
|
||||
public static ILookup<string, ProductionQueue> FindQueuesByCategory(Player player)
|
||||
{
|
||||
return player.World.ActorsWithTrait<ProductionQueue>()
|
||||
.Where(a => a.Actor.Owner == player && a.Trait.Info.Type == category && a.Trait.Enabled)
|
||||
.Select(a => a.Trait);
|
||||
.Where(a => a.Actor.Owner == player && a.Trait.Enabled)
|
||||
.Select(a => a.Trait)
|
||||
.ToLookup(pq => pq.Info.Type);
|
||||
}
|
||||
|
||||
public static int CountActorsWithNameAndTrait<T>(string actorName, Player owner)
|
||||
|
||||
Reference in New Issue
Block a user