Don't allocate priorities
This commit is contained in:
committed by
Matthias Mailänder
parent
c56d2c1bbe
commit
bb0a39ba6c
@@ -363,6 +363,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
.Concat(self.Owner.FrozenActorLayer.FrozenActorsInCircle(self.World, self.CenterPosition, scanRange)
|
||||
.Select(Target.FromFrozenActor));
|
||||
|
||||
// PERF: Avoid allocating a new list for each target.
|
||||
List<AutoTargetPriorityInfo> validPriorities = [];
|
||||
|
||||
foreach (var target in targetsInRange)
|
||||
{
|
||||
BitSet<TargetableType> targetTypes;
|
||||
@@ -401,22 +404,22 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else
|
||||
continue;
|
||||
|
||||
var validPriorities = activePriorities.Where(ati =>
|
||||
foreach (var ati in activePriorities)
|
||||
{
|
||||
// Already have a higher priority target
|
||||
if (ati.Priority < chosenTargetPriority)
|
||||
return false;
|
||||
continue;
|
||||
|
||||
// Incompatible relationship
|
||||
if (!ati.ValidRelationships.HasRelationship(self.Owner.RelationshipWith(owner)))
|
||||
return false;
|
||||
continue;
|
||||
|
||||
// Incompatible target types
|
||||
if (!ati.ValidTargets.Overlaps(targetTypes) || ati.InvalidTargets.Overlaps(targetTypes))
|
||||
return false;
|
||||
continue;
|
||||
|
||||
return true;
|
||||
}).ToList();
|
||||
validPriorities.Add(ati);
|
||||
}
|
||||
|
||||
if (validPriorities.Count == 0)
|
||||
continue;
|
||||
@@ -446,6 +449,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
chosenTargetRange = targetRange;
|
||||
}
|
||||
}
|
||||
|
||||
validPriorities.Clear();
|
||||
}
|
||||
|
||||
return chosenTarget;
|
||||
|
||||
Reference in New Issue
Block a user