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