diff --git a/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs b/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs index 742516efd8..b5b17f1d59 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/FootprintPlaceBuildingPreview.cs @@ -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); diff --git a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs index 3dd6c3eae5..7b68f8aa91 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs @@ -74,11 +74,11 @@ namespace OpenRA.Mods.Common.Traits if ((c.Value & filter) == 0) continue; - var tile = c.Value.HasFlag(PlaceBuildingCellType.Invalid) ? buildBlocked : + var tile = HasFlag(c.Value, PlaceBuildingCellType.Invalid) ? buildBlocked : candidateSafeTiles.Contains(c.Key) && info.UnsafeTerrainTypes.Contains(wr.World.Map.GetTerrainInfo(c.Key).Type) ? buildUnsafe : buildOk; - var pal = c.Value.HasFlag(PlaceBuildingCellType.LineBuild) ? linePalette : cellPalette; + 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);