Cache the initial path layer for faster path search startups.

Reinitializing the initial cell info layer for the path search took a fair bit of time. We cache this initial setup so it only has to be done each time the map size changes. A CopyValuesFrom method in CellLayer is provided which copies values between layers by just copying the internal arrays for super speed.

This speeds up InitCellInfo 10x.
This commit is contained in:
RoosterDragon
2014-12-09 23:00:48 +00:00
parent 8e001663dc
commit f01f8d92b3
2 changed files with 31 additions and 5 deletions

View File

@@ -34,6 +34,17 @@ namespace OpenRA
entries = new T[size.Width * size.Height];
}
public void CopyValuesFrom(CellLayer<T> anotherLayer)
{
if (Size != anotherLayer.Size || Shape != anotherLayer.Shape)
throw new ArgumentException(
"layers must have a matching size and shape.", "anotherLayer");
if (CellEntryChanged != null)
throw new InvalidOperationException(
"Cannot copy values when there are listeners attached to the CellEntryChanged event.");
Array.Copy(anotherLayer.entries, entries, entries.Length);
}
// Resolve an array index from cell coordinates
int Index(CPos cell)
{