Ensure Clear(T) also have a safety check to ensure no listener is attached.
Move related methods next to each other. Change Clear(T) to use Array.Fill.
This commit is contained in:
@@ -25,24 +25,33 @@ namespace OpenRA
|
|||||||
public CellLayer(MapGridType gridType, Size size)
|
public CellLayer(MapGridType gridType, Size size)
|
||||||
: base(gridType, 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<T> anotherLayer)
|
public override void CopyValuesFrom(CellLayerBase<T> anotherLayer)
|
||||||
{
|
{
|
||||||
if (CellEntryChanged != null)
|
if (CellEntryChanged != null)
|
||||||
throw new InvalidOperationException(
|
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);
|
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
|
// Resolve an array index from cell coordinates
|
||||||
int Index(CPos cell)
|
int Index(CPos cell)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,11 +35,6 @@ namespace OpenRA
|
|||||||
entries = new T[size.Width * size.Height];
|
entries = new T[size.Width * size.Height];
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Clear()
|
|
||||||
{
|
|
||||||
Array.Clear(entries, 0, entries.Length);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void CopyValuesFrom(CellLayerBase<T> anotherLayer)
|
public virtual void CopyValuesFrom(CellLayerBase<T> anotherLayer)
|
||||||
{
|
{
|
||||||
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)
|
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)
|
||||||
@@ -48,11 +43,16 @@ namespace OpenRA
|
|||||||
Array.Copy(anotherLayer.entries, entries, entries.Length);
|
Array.Copy(anotherLayer.entries, entries, entries.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Clears the layer contents with a known value</summary>
|
/// <summary>Clears the layer contents with their default value</summary>
|
||||||
public void Clear(T clearValue)
|
public virtual void Clear()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < entries.Length; i++)
|
Array.Clear(entries, 0, entries.Length);
|
||||||
entries[i] = clearValue;
|
}
|
||||||
|
|
||||||
|
/// <summary>Clears the layer contents with a known value</summary>
|
||||||
|
public virtual void Clear(T clearValue)
|
||||||
|
{
|
||||||
|
Array.Fill(entries, clearValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
public IEnumerator<T> GetEnumerator()
|
||||||
|
|||||||
@@ -309,6 +309,7 @@ namespace OpenRA
|
|||||||
Resources = new CellLayer<ResourceTile>(Grid.Type, size);
|
Resources = new CellLayer<ResourceTile>(Grid.Type, size);
|
||||||
Height = new CellLayer<byte>(Grid.Type, size);
|
Height = new CellLayer<byte>(Grid.Type, size);
|
||||||
Ramp = new CellLayer<byte>(Grid.Type, size);
|
Ramp = new CellLayer<byte>(Grid.Type, size);
|
||||||
|
Tiles.Clear(terrainInfo.DefaultTerrainTile);
|
||||||
if (Grid.MaximumTerrainHeight > 0)
|
if (Grid.MaximumTerrainHeight > 0)
|
||||||
{
|
{
|
||||||
Height.CellEntryChanged += UpdateProjection;
|
Height.CellEntryChanged += UpdateProjection;
|
||||||
@@ -316,8 +317,6 @@ namespace OpenRA
|
|||||||
Tiles.CellEntryChanged += UpdateRamp;
|
Tiles.CellEntryChanged += UpdateRamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
Tiles.Clear(terrainInfo.DefaultTerrainTile);
|
|
||||||
|
|
||||||
PostInit();
|
PostInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user