From a576f304998823248541b37ef413555b5a276315 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Sun, 21 Jul 2019 15:39:46 +0200 Subject: [PATCH] Reduce Map.Contains(CPos) cost in legacy mods 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. --- OpenRA.Game/Map/Map.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index cf9cdd120024..af4c29c17803 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -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)); }