Cache the footprint LINQ for performance.
This commit is contained in:
committed by
atlimit8
parent
99957e57b9
commit
551ab2fc59
@@ -63,8 +63,15 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
class ChronoshiftPower : SupportPower
|
||||
{
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
|
||||
public ChronoshiftPower(Actor self, ChronoshiftPowerInfo info)
|
||||
: base(self, info) { }
|
||||
: base(self, info)
|
||||
{
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
}
|
||||
|
||||
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
|
||||
{
|
||||
@@ -96,8 +103,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
|
||||
public IEnumerable<Actor> UnitsInRange(CPos xy)
|
||||
{
|
||||
var footprint = ((ChronoshiftPowerInfo)Info).Footprint;
|
||||
var dimensions = ((ChronoshiftPowerInfo)Info).Dimensions;
|
||||
var tiles = CellsMatching(xy, footprint, dimensions);
|
||||
var units = new HashSet<Actor>();
|
||||
foreach (var t in tiles)
|
||||
@@ -111,8 +116,6 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
if (!Self.Owner.Shroud.IsExplored(xy))
|
||||
return false;
|
||||
|
||||
var footprint = ((ChronoshiftPowerInfo)Info).Footprint;
|
||||
var dimensions = ((ChronoshiftPowerInfo)Info).Dimensions;
|
||||
var sourceTiles = CellsMatching(xy, footprint, dimensions);
|
||||
var destTiles = CellsMatching(sourceLocation, footprint, dimensions);
|
||||
|
||||
@@ -139,7 +142,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
class SelectChronoshiftTarget : OrderGenerator
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly string footprint;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite tile;
|
||||
readonly SupportPowerManager manager;
|
||||
@@ -156,7 +159,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
this.power = power;
|
||||
|
||||
var info = (ChronoshiftPowerInfo)power.Info;
|
||||
footprint = info.Footprint;
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
tile = world.Map.Rules.Sequences.GetSequence(info.FootprintImage, info.SourceFootprintSequence).GetSprite(0);
|
||||
}
|
||||
@@ -214,7 +217,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
{
|
||||
readonly ChronoshiftPower power;
|
||||
readonly CPos sourceLocation;
|
||||
readonly string footprint;
|
||||
readonly char[] footprint;
|
||||
readonly CVec dimensions;
|
||||
readonly Sprite validTile, invalidTile, sourceTile;
|
||||
readonly SupportPowerManager manager;
|
||||
@@ -228,7 +231,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
||||
this.sourceLocation = sourceLocation;
|
||||
|
||||
var info = (ChronoshiftPowerInfo)power.Info;
|
||||
footprint = info.Footprint;
|
||||
footprint = info.Footprint.Where(c => !char.IsWhiteSpace(c)).ToArray();
|
||||
dimensions = info.Dimensions;
|
||||
|
||||
var sequences = world.Map.Rules.Sequences;
|
||||
|
||||
@@ -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