CellLayer.Index inline CPos.ToMPos.

This commit is contained in:
Vapre
2021-07-15 23:20:35 +02:00
committed by abcdefg30
parent 7bfe83cce7
commit 627fd4e68b

View File

@@ -52,7 +52,15 @@ namespace OpenRA
// Resolve an array index from cell coordinates
int Index(CPos cell)
{
return Index(cell.ToMPos(GridType));
// PERF: Inline CPos.ToMPos to avoid MPos allocation
var x = cell.X;
var y = cell.Y;
if (GridType == MapGridType.Rectangular)
return y * Size.Width + x;
var u = (x - y) / 2;
var v = x + y;
return v * Size.Width + u;
}
// Resolve an array index from map coordinates