Remove LINQ in some performance critical AutoTarget paths.
This commit is contained in:
@@ -132,10 +132,11 @@ namespace OpenRA.GameRules
|
|||||||
if (!IsValidTarget(targetTypes))
|
if (!IsValidTarget(targetTypes))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!Warheads.Any(w => w.IsValidAgainst(victim, firedBy)))
|
foreach (var warhead in Warheads)
|
||||||
return false;
|
if (warhead.IsValidAgainst(victim, firedBy))
|
||||||
|
return true;
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Checks if the weapon is valid against (can target) the frozen actor.</summary>
|
/// <summary>Checks if the weapon is valid against (can target) the frozen actor.</summary>
|
||||||
|
|||||||
@@ -159,13 +159,25 @@ namespace OpenRA
|
|||||||
|
|
||||||
public bool CanTargetActor(Actor a)
|
public bool CanTargetActor(Actor a)
|
||||||
{
|
{
|
||||||
if (HasFogVisibility && fogVisibilities.Any(f => f.IsVisible(a)))
|
if (HasFogVisibility)
|
||||||
return true;
|
foreach (var fogVisibility in fogVisibilities)
|
||||||
|
if (fogVisibility.IsVisible(a))
|
||||||
|
return true;
|
||||||
|
|
||||||
return CanViewActor(a);
|
return CanViewActor(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HasFogVisibility { get { return fogVisibilities.Any(f => f.HasFogVisibility()); } }
|
public bool HasFogVisibility
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
foreach (var fogVisibility in fogVisibilities)
|
||||||
|
if (fogVisibility.HasFogVisibility())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#region Scripting interface
|
#region Scripting interface
|
||||||
|
|
||||||
|
|||||||
@@ -189,7 +189,11 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (Info.AttackRequiresEnteringCell && !positionable.Value.CanEnterCell(t.Actor.Location, null, false))
|
if (Info.AttackRequiresEnteringCell && !positionable.Value.CanEnterCell(t.Actor.Location, null, false))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return Armaments.Any(a => a.Weapon.IsValidAgainst(t, self.World, self));
|
foreach (var armament in Armaments)
|
||||||
|
if (armament.Weapon.IsValidAgainst(t, self.World, self))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WDist GetMinimumRange()
|
public WDist GetMinimumRange()
|
||||||
@@ -197,9 +201,16 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return WDist.Zero;
|
return WDist.Zero;
|
||||||
|
|
||||||
var min = Armaments.Where(a => !a.IsTraitDisabled)
|
var min = WDist.MaxValue;
|
||||||
.Select(a => a.Weapon.MinRange)
|
foreach (var armament in Armaments)
|
||||||
.Append(WDist.MaxValue).Min();
|
{
|
||||||
|
if (armament.IsTraitDisabled)
|
||||||
|
continue;
|
||||||
|
var range = armament.Weapon.MinRange;
|
||||||
|
if (min > range)
|
||||||
|
min = range;
|
||||||
|
}
|
||||||
|
|
||||||
return min != WDist.MaxValue ? min : WDist.Zero;
|
return min != WDist.MaxValue ? min : WDist.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,9 +219,17 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (IsTraitDisabled)
|
if (IsTraitDisabled)
|
||||||
return WDist.Zero;
|
return WDist.Zero;
|
||||||
|
|
||||||
return Armaments.Where(a => !a.IsTraitDisabled)
|
var max = WDist.Zero;
|
||||||
.Select(a => a.MaxRange())
|
foreach (var armament in Armaments)
|
||||||
.Append(WDist.Zero).Max();
|
{
|
||||||
|
if (armament.IsTraitDisabled)
|
||||||
|
continue;
|
||||||
|
var range = armament.MaxRange();
|
||||||
|
if (max < range)
|
||||||
|
max = range;
|
||||||
|
}
|
||||||
|
|
||||||
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enumerates all armaments, that this actor possesses, that can be used against Target t
|
// Enumerates all armaments, that this actor possesses, that can be used against Target t
|
||||||
|
|||||||
Reference in New Issue
Block a user