Cache the footprint LINQ for performance.

This commit is contained in:
Matthias Mailänder
2020-03-10 19:20:27 +01:00
committed by atlimit8
parent 99957e57b9
commit 551ab2fc59
3 changed files with 19 additions and 15 deletions

View File

@@ -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);
}
}