Remove Enum.HasFlag from building preview generation.

This commit is contained in:
Paul Chote
2019-05-21 22:39:19 +01:00
committed by reaperrr
parent 697935f931
commit 6723306bb4
2 changed files with 10 additions and 4 deletions

View File

@@ -52,6 +52,12 @@ namespace OpenRA.Mods.Common.Traits
readonly Sprite buildOk;
readonly Sprite buildBlocked;
protected static bool HasFlag(PlaceBuildingCellType value, PlaceBuildingCellType flag)
{
// PERF: Enum.HasFlag is slower and requires allocations.
return (value & flag) == value;
}
public FootprintPlaceBuildingPreviewPreview(WorldRenderer wr, ActorInfo ai, FootprintPlaceBuildingPreviewInfo info, TypeDictionary init)
{
actorInfo = ai;
@@ -83,8 +89,8 @@ namespace OpenRA.Mods.Common.Traits
if ((c.Value & filter) == 0)
continue;
var tile = !c.Value.HasFlag(PlaceBuildingCellType.Invalid) ? buildOk : buildBlocked;
var pal = c.Value.HasFlag(PlaceBuildingCellType.LineBuild) ? linePalette : cellPalette;
var tile = HasFlag(c.Value, PlaceBuildingCellType.Invalid) ? buildBlocked : buildOk;
var pal = HasFlag(c.Value, PlaceBuildingCellType.LineBuild) ? linePalette : cellPalette;
var pos = wr.World.Map.CenterOfCell(c.Key);
var offset = new WVec(0, 0, topLeftPos.Z - pos.Z);
yield return new SpriteRenderable(tile, pos, offset, -511, pal, 1f, true);