Speed up AutoTarget.ChooseTarget among groups of allied units.

Most auto target scans will be conducted among groups of allied units unable to target each other because they are allied and their weapons only target enemies. Since they cannot target each other, the scan will be repeated constantly. Realising this, we can significantly reduce the performance impact of auto target scanning by bailing early in this scenario to avoid carrying out expensive targeting checks on friendly units which we know will fail anyway.
This commit is contained in:
RoosterDragon
2016-01-03 00:12:37 +00:00
parent 7acd71cd7d
commit adc7e902e3
2 changed files with 27 additions and 3 deletions

View File

@@ -287,6 +287,17 @@ namespace OpenRA.Mods.Common.Traits
&& (target.IsInRange(self.CenterPosition, GetMaximumRange()) || (allowMove && self.Info.HasTraitInfo<IMoveInfo>()));
}
public Stance UnforcedAttackTargetStances()
{
// PERF: Avoid LINQ.
var stances = Stance.None;
foreach (var armament in Armaments)
if (!armament.IsTraitDisabled)
stances |= armament.Info.TargetStances;
return stances;
}
class AttackOrderTargeter : IOrderTargeter
{
readonly AttackBase ab;