Cache the footprint LINQ for performance.
This commit is contained in:
committed by
atlimit8
parent
99957e57b9
commit
551ab2fc59
@@ -57,11 +57,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
class GrantExternalConditionPower : SupportPower
|
||||
{
|
||||
readonly GrantExternalConditionPowerInfo info;
|
||||
readonly char[] footprint;
|
||||
|
||||
public GrantExternalConditionPower(Actor self, GrantExternalConditionPowerInfo info)
|
||||
: base(self, info)
|
||||
{
|
||||
this.info = info;
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
@@ -93,7 +95,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var tiles = CellsMatching(xy, info.Footprint, info.Dimensions);
|
||||
var tiles = CellsMatching(xy, footprint, info.Dimensions);
|
||||
var units = new List<Actor>();
|
||||
foreach (var t in tiles)
|
||||
units.AddRange(Self.World.ActorMap.GetActorsAt(t));
|
||||
@@ -111,7 +113,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
class SelectConditionTarget : OrderGenerator
|
||||
{
|
||||
readonly GrantExternalConditionPower power;
|
||||
readonly string footprint;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite tile;
|
||||
readonly SupportPowerManager manager;
|
||||
@@ -126,7 +128,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
this.manager = manager;
|
||||
this.order = order;
|
||||
this.power = power;
|
||||
footprint = power.info.Footprint;
|
||||
footprint = power.info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = power.info.Dimensions;
|
||||
tile = world.Map.Rules.Sequences.GetSequence("overlay", "target-select").GetSprite(0);
|
||||
}
|
||||
|
||||
@@ -194,15 +194,14 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Game.Sound.PlayNotification(Self.World.Map.Rules, toPlayer, "Speech", speech, toPlayer.Faction.InternalName);
|
||||
}
|
||||
|
||||
public IEnumerable<CPos> CellsMatching(CPos location, string footprint, CVec dimensions)
|
||||
public IEnumerable<CPos> CellsMatching(CPos location, char[] footprint, CVec dimensions)
|
||||
{
|
||||
var index = 0;
|
||||
var fp = footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
var x = location.X - (dimensions.X - 1) / 2;
|
||||
var y = location.Y - (dimensions.Y - 1) / 2;
|
||||
for (var j = 0; j < dimensions.Y; j++)
|
||||
for (var i = 0; i < dimensions.X; i++)
|
||||
if (fp[index++] == 'x')
|
||||
if (footprint[index++] == 'x')
|
||||
yield return new CPos(x + i, y + j);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user