Allow the default value of a CellInfo to be an Unvisited location.

In CellInfoLayerPool, instead of having to store a layer with the default values, we know we can just clear the pooled layer in order to reset it. This saves on memory, and also makes resetting marginally faster.

In PathSearch, we need to amend a check to ensure a cell info is not Unvisited before we check on its cost.
This commit is contained in:
RoosterDragon
2021-09-25 13:08:26 +01:00
committed by abcdefg30
parent 6edd5d7bfa
commit 19760b04bd
5 changed files with 51 additions and 33 deletions

View File

@@ -25,6 +25,15 @@ 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<T> anotherLayer)
{
if (CellEntryChanged != null)
@@ -34,21 +43,6 @@ namespace OpenRA
base.CopyValuesFrom(anotherLayer);
}
public static CellLayer<T> CreateInstance(Func<MPos, T> initialCellValueFactory, Size size, MapGridType mapGridType)
{
var cellLayer = new CellLayer<T>(mapGridType, size);
for (var v = 0; v < size.Height; v++)
{
for (var u = 0; u < size.Width; u++)
{
var mpos = new MPos(u, v);
cellLayer[mpos] = initialCellValueFactory(mpos);
}
}
return cellLayer;
}
// Resolve an array index from cell coordinates
int Index(CPos cell)
{

View File

@@ -35,6 +35,11 @@ namespace OpenRA
entries = new T[size.Width * size.Height];
}
public virtual void Clear()
{
Array.Clear(entries, 0, entries.Length);
}
public virtual void CopyValuesFrom(CellLayerBase<T> anotherLayer)
{
if (Size != anotherLayer.Size || GridType != anotherLayer.GridType)