Significantly improve actor placement and removal speeds

This commit is contained in:
Gustas
2025-09-11 12:58:09 +03:00
committed by Paul Chote
parent 7d4a590240
commit b5b44c048d
5 changed files with 228 additions and 50 deletions

View File

@@ -9,6 +9,7 @@
*/
#endregion
using System;
using System.Collections;
using System.Collections.Generic;
@@ -89,6 +90,31 @@ namespace OpenRA
return GetEnumerator();
}
/// <summary>Returns the minimal region that covers at least the specified cells.</summary>
public static CellCoordsRegion BoundingRegion(IReadOnlyCollection<CPos> cells)
{
if (cells == null || cells.Count == 0)
throw new ArgumentException("cells must not be null or empty.", nameof(cells));
var minX = int.MaxValue;
var minY = int.MaxValue;
var maxX = int.MinValue;
var maxY = int.MinValue;
foreach (var cell in cells)
{
if (minX > cell.X)
minX = cell.X;
if (maxX < cell.X)
maxX = cell.X;
if (minY > cell.Y)
minY = cell.Y;
if (maxY < cell.Y)
maxY = cell.Y;
}
return new CellCoordsRegion(new CPos(minX, minY), new CPos(maxX, maxY));
}
public CPos TopLeft { get; }
public CPos BottomRight { get; }
}