Skip to content

Commit

Permalink
Reduce Map.Contains(CPos) cost in legacy mods
Browse files Browse the repository at this point in the history
If a mod uses rectangular maps and no height levels,
checking if the CPos is within Bounds
should be enough and cheaper than the whole ToMPos
conversion and checks.
  • Loading branch information
reaperrr committed Jul 26, 2019
1 parent 9ac3d75 commit a576f30
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions OpenRA.Game/Map/Map.cs
Expand Up @@ -752,6 +752,16 @@ public bool Contains(CPos cell)
if (Grid.Type == MapGridType.RectangularIsometric && cell.X < cell.Y)
return false;

// If the mod uses flat & rectangular maps, ToMPos and Contains(MPos) create unnecessary cost.
// Just check if CPos is within map bounds.
if (Grid.MaximumTerrainHeight == 0 && Grid.Type == MapGridType.Rectangular)
{
if (!Bounds.Contains(cell.X, cell.Y))
return false;

return true;
}

return Contains(cell.ToMPos(this));
}

Expand Down

0 comments on commit a576f30

Please sign in to comment.