diff --git a/OpenRA.Game/Map/CellLayer.cs b/OpenRA.Game/Map/CellLayer.cs index b1e975a3b3..79d73c2bf0 100644 --- a/OpenRA.Game/Map/CellLayer.cs +++ b/OpenRA.Game/Map/CellLayer.cs @@ -25,24 +25,33 @@ namespace OpenRA public CellLayer(MapGridType gridType, Size size) : base(gridType, size) { } - public override void Clear() - { - if (CellEntryChanged != null) - throw new InvalidOperationException( - "Cannot clear values when there are listeners attached to the CellEntryChanged event."); - - base.Clear(); - } - public override void CopyValuesFrom(CellLayerBase anotherLayer) { if (CellEntryChanged != null) throw new InvalidOperationException( - "Cannot copy values when there are listeners attached to the CellEntryChanged event."); + $"Cannot copy values when there are listeners attached to the {nameof(CellEntryChanged)} event."); base.CopyValuesFrom(anotherLayer); } + public override void Clear() + { + if (CellEntryChanged != null) + throw new InvalidOperationException( + $"Cannot clear values when there are listeners attached to the {nameof(CellEntryChanged)} event."); + + base.Clear(); + } + + public override void Clear(T clearValue) + { + if (CellEntryChanged != null) + throw new InvalidOperationException( + $"Cannot clear values when there are listeners attached to the {nameof(CellEntryChanged)} event."); + + base.Clear(clearValue); + } + // Resolve an array index from cell coordinates int Index(CPos cell) { diff --git a/OpenRA.Game/Map/CellLayerBase.cs b/OpenRA.Game/Map/CellLayerBase.cs index 9d09322f80..9cbc8e5974 100644 --- a/OpenRA.Game/Map/CellLayerBase.cs +++ b/OpenRA.Game/Map/CellLayerBase.cs @@ -35,11 +35,6 @@ namespace OpenRA entries = new T[size.Width * size.Height]; } - public virtual void Clear() - { - Array.Clear(entries, 0, entries.Length); - } - public virtual void CopyValuesFrom(CellLayerBase anotherLayer) { if (Size != anotherLayer.Size || GridType != anotherLayer.GridType) @@ -48,11 +43,16 @@ namespace OpenRA Array.Copy(anotherLayer.entries, entries, entries.Length); } - /// Clears the layer contents with a known value - public void Clear(T clearValue) + /// Clears the layer contents with their default value + public virtual void Clear() { - for (var i = 0; i < entries.Length; i++) - entries[i] = clearValue; + Array.Clear(entries, 0, entries.Length); + } + + /// Clears the layer contents with a known value + public virtual void Clear(T clearValue) + { + Array.Fill(entries, clearValue); } public IEnumerator GetEnumerator() diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index cd2356900f..4120eb2894 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -309,6 +309,7 @@ namespace OpenRA Resources = new CellLayer(Grid.Type, size); Height = new CellLayer(Grid.Type, size); Ramp = new CellLayer(Grid.Type, size); + Tiles.Clear(terrainInfo.DefaultTerrainTile); if (Grid.MaximumTerrainHeight > 0) { Height.CellEntryChanged += UpdateProjection; @@ -316,8 +317,6 @@ namespace OpenRA Tiles.CellEntryChanged += UpdateRamp; } - Tiles.Clear(terrainInfo.DefaultTerrainTile); - PostInit(); }