From a514f3a3888152a7f7afe202aac890e8725a0bf7 Mon Sep 17 00:00:00 2001 From: Gustas <37534529+PunkPun@users.noreply.github.com> Date: Tue, 14 Oct 2025 11:03:18 +0300 Subject: [PATCH] Make map grid immutable --- OpenRA.Game/Map/MapGrid.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/OpenRA.Game/Map/MapGrid.cs b/OpenRA.Game/Map/MapGrid.cs index a8179863ea..50827697b2 100644 --- a/OpenRA.Game/Map/MapGrid.cs +++ b/OpenRA.Game/Map/MapGrid.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Collections.Immutable; using System.IO; using System.Linq; using OpenRA.Traits; @@ -24,8 +25,8 @@ namespace OpenRA public readonly struct CellRamp { public readonly int CenterHeightOffset; - public readonly WVec[] Corners; - public readonly WVec[][] Polygons; + public readonly ImmutableArray Corners; + public readonly ImmutableArray> Polygons; public readonly WRot Orientation; public CellRamp(MapGridType type, WRot orientation, @@ -83,10 +84,11 @@ namespace OpenRA { // Enumerate over the polygons, assuming that they are triangles // If the ramp is not split we will take the first three vertices of the corners as a valid triangle - WVec[] p = null; - var u = 0; - var v = 0; - for (var i = 0; i < Polygons.Length; i++) + int u; + int v; + ImmutableArray p; + var i = 0; + do { p = Polygons[i]; u = ((p[1].Y - p[2].Y) * (dX - p[2].X) - (p[1].X - p[2].X) * (dY - p[2].Y)) / 1024; @@ -95,7 +97,10 @@ namespace OpenRA // Point is within the triangle if 0 <= u,v <= 1024 if (u >= 0 && u <= 1024 && v >= 0 && v <= 1024) break; + + i++; } + while (i < Polygons.Length); // Calculate w from u,v and interpolate height return (u * p[0].Z + v * p[1].Z + (1024 - u - v) * p[2].Z) / 1024;