diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index e464dbc1ba..b0642a4d91 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -180,9 +180,9 @@ namespace OpenRA.Graphics { var colors = (int*)bitmapData.Scan0; var stride = bitmapData.Stride / 4; - var shroudObscured = world.ShroudObscuresTest(map.Cells); - var fogObscured = world.FogObscuresTest(map.Cells); - foreach (var uv in map.Cells.MapCoords) + var shroudObscured = world.ShroudObscuresTest(map.CellsInsideBounds); + var fogObscured = world.FogObscuresTest(map.CellsInsideBounds); + foreach (var uv in map.CellsInsideBounds.MapCoords) { var bitmapXy = new int2(uv.U - b.Left, uv.V - b.Top); if (shroudObscured(uv)) diff --git a/OpenRA.Game/Graphics/TerrainRenderer.cs b/OpenRA.Game/Graphics/TerrainRenderer.cs index 40da938959..07bf276e91 100644 --- a/OpenRA.Game/Graphics/TerrainRenderer.cs +++ b/OpenRA.Game/Graphics/TerrainRenderer.cs @@ -25,7 +25,7 @@ namespace OpenRA.Graphics mapTiles = world.Map.MapTiles.Value; terrain = new TerrainSpriteLayer(world, wr, theater.Sheet, BlendMode.Alpha, wr.Palette("terrain")); - foreach (var cell in world.Map.Cells) + foreach (var cell in world.Map.AllCells) UpdateCell(cell); world.Map.MapTiles.Value.CellEntryChanged += UpdateCell; diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index eae3e9e1b5..142d169a37 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -239,7 +239,8 @@ namespace OpenRA public SequenceProvider SequenceProvider { get { return Rules.Sequences[Tileset]; } } public WVec[][] CellCorners { get; private set; } - [FieldLoader.Ignore] public CellRegion Cells; + [FieldLoader.Ignore] public CellRegion CellsInsideBounds; + [FieldLoader.Ignore] public CellRegion AllCells; public static Map FromTileset(TileSet tileset) { @@ -392,12 +393,16 @@ namespace OpenRA cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]); - var tl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this); - var br = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this); - Cells = new CellRegion(TileShape, tl, br); + var tl = new MPos(0, 0).ToCPos(this); + var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); + AllCells = new CellRegion(TileShape, tl, br); + + var btl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this); + var bbr = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this); + CellsInsideBounds = new CellRegion(TileShape, btl, bbr); CustomTerrain = new CellLayer(this); - foreach (var uv in Cells.MapCoords) + foreach (var uv in AllCells.MapCoords) CustomTerrain[uv] = byte.MaxValue; var leftDelta = TileShape == TileShape.Diamond ? new WVec(-512, 0, 0) : new WVec(-512, -512, 0); @@ -689,6 +694,10 @@ namespace OpenRA MapResources = Exts.Lazy(() => CellLayer.Resize(oldMapResources, newSize, oldMapResources[MPos.Zero])); MapHeight = Exts.Lazy(() => CellLayer.Resize(oldMapHeight, newSize, oldMapHeight[MPos.Zero])); MapSize = new int2(newSize); + + var tl = new MPos(0, 0).ToCPos(this); + var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); + AllCells = new CellRegion(TileShape, tl, br); } public void ResizeCordon(int left, int top, int right, int bottom) @@ -697,7 +706,7 @@ namespace OpenRA var tl = new MPos(Bounds.Left, Bounds.Top).ToCPos(this); var br = new MPos(Bounds.Right - 1, Bounds.Bottom - 1).ToCPos(this); - Cells = new CellRegion(TileShape, tl, br); + CellsInsideBounds = new CellRegion(TileShape, tl, br); } string ComputeHash() @@ -797,8 +806,8 @@ namespace OpenRA public WRange DistanceToEdge(WPos pos, WVec dir) { - var tl = CenterOfCell(Cells.TopLeft) - new WVec(512, 512, 0); - var br = CenterOfCell(Cells.BottomRight) + new WVec(511, 511, 0); + var tl = CenterOfCell(CellsInsideBounds.TopLeft) - new WVec(512, 512, 0); + var br = CenterOfCell(CellsInsideBounds.BottomRight) + new WVec(511, 511, 0); var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X; var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y; return new WRange(Math.Min(x, y) * dir.Length); diff --git a/OpenRA.Game/Traits/World/Shroud.cs b/OpenRA.Game/Traits/World/Shroud.cs index 93587afc35..b2469772c4 100644 --- a/OpenRA.Game/Traits/World/Shroud.cs +++ b/OpenRA.Game/Traits/World/Shroud.cs @@ -249,7 +249,7 @@ namespace OpenRA.Traits throw new ArgumentException("The map bounds of these shrouds do not match.", "s"); var changed = new List(); - foreach (var uv in map.Cells.MapCoords) + foreach (var uv in map.CellsInsideBounds.MapCoords) { if (!explored[uv] && s.explored[uv]) { @@ -264,7 +264,7 @@ namespace OpenRA.Traits public void ExploreAll(World world) { var changed = new List(); - foreach (var uv in map.Cells.MapCoords) + foreach (var uv in map.CellsInsideBounds.MapCoords) { if (!explored[uv]) { @@ -279,7 +279,7 @@ namespace OpenRA.Traits public void ResetExploration() { var changed = new List(); - foreach (var uv in map.Cells.MapCoords) + foreach (var uv in map.CellsInsideBounds.MapCoords) { var visible = visibleCount[uv] > 0; if (explored[uv] != visible) @@ -318,7 +318,7 @@ namespace OpenRA.Traits public Func IsExploredTest(CellRegion region) { // If the region to test extends outside the map we must use the slow test that checks the map boundary every time. - if (!map.Cells.Contains(region)) + if (!map.CellsInsideBounds.Contains(region)) return slowExploredTest; // If shroud isn't enabled, then we can see everything inside the map. @@ -361,7 +361,7 @@ namespace OpenRA.Traits public Func IsVisibleTest(CellRegion region) { // If the region to test extends outside the map we must use the slow test that checks the map boundary every time. - if (!map.Cells.Contains(region)) + if (!map.CellsInsideBounds.Contains(region)) return slowVisibleTest; // If fog isn't enabled, then we can see everything. diff --git a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs index c7608ed245..1c6ba077f5 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorResourceLayer.cs @@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits if (w.Type != WorldType.Editor) return; - foreach (var cell in Map.Cells) + foreach (var cell in Map.AllCells) UpdateCell(cell); } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index cff197e5b2..84a16d522a 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -70,7 +70,7 @@ namespace OpenRA.Mods.Common.Traits var resources = w.WorldActor.TraitsImplementing() .ToDictionary(r => r.Info.ResourceType, r => r); - foreach (var cell in w.Map.Cells) + foreach (var cell in w.Map.AllCells) { ResourceType t; if (!resources.TryGetValue(w.Map.MapResources.Value[cell].Type, out t)) @@ -83,7 +83,7 @@ namespace OpenRA.Mods.Common.Traits } // Set initial density based on the number of neighboring resources - foreach (var cell in w.Map.Cells) + foreach (var cell in w.Map.AllCells) { var type = content[cell].Type; if (type != null) diff --git a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs index 6bc75c9e82..6330f814dc 100644 --- a/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs +++ b/OpenRA.Mods.Common/Traits/World/ShroudRenderer.cs @@ -162,8 +162,8 @@ namespace OpenRA.Mods.Common.Traits public void WorldLoaded(World w, WorldRenderer wr) { // Initialize tile cache - // Adds a 1-cell border around the border to cover any sprites peeking outside the map - foreach (var uv in CellRegion.Expand(w.Map.Cells, 1).MapCoords) + // This includes the region outside the visible area to cover any sprites peeking outside the map + foreach (var uv in w.Map.AllCells.MapCoords) { var screen = wr.ScreenPosition(w.Map.CenterOfCell(uv.ToCPos(map))); var variant = (byte)Game.CosmeticRandom.Next(info.ShroudVariants.Length); @@ -176,7 +176,7 @@ namespace OpenRA.Mods.Common.Traits wr.PaletteInvalidated += () => { mapBorderShroudIsCached = false; - MarkCellsDirty(CellRegion.Expand(map.Cells, 1)); + MarkCellsDirty(map.AllCells); }; } @@ -278,7 +278,7 @@ namespace OpenRA.Mods.Common.Traits { // Cache the whole of the map border shroud ahead of time, since it never changes. Func mapContains = map.Contains; - foreach (var uv in CellRegion.Expand(map.Cells, 1).MapCoords) + foreach (var uv in map.AllCells.MapCoords) { var offset = VertexArrayOffset(uv); var edges = GetEdges(uv, mapContains); @@ -304,7 +304,7 @@ namespace OpenRA.Mods.Common.Traits { // The map border shroud only affects the map border. If none of the visible cells are on the border, then // we don't need to render anything and can bail early for performance. - if (CellRegion.Expand(map.Cells, -1).Contains(visibleRegion)) + if (CellRegion.Expand(map.CellsInsideBounds, -1).Contains(visibleRegion)) return; // Render the shroud that just encroaches at the map border. This shroud is always fully cached, so we can diff --git a/OpenRA.Mods.Common/Widgets/RadarWidget.cs b/OpenRA.Mods.Common/Widgets/RadarWidget.cs index 81c5f0aab7..1b0d2cd500 100644 --- a/OpenRA.Mods.Common/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.Common/Widgets/RadarWidget.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Widgets actorSprite = new Sprite(radarSheet, new Rectangle(0, height, width, height), TextureChannel.Alpha); // Set initial terrain data - foreach (var cell in world.Map.Cells) + foreach (var cell in world.Map.CellsInsideBounds) UpdateTerrainCell(cell); world.Map.MapTiles.Value.CellEntryChanged += UpdateTerrainCell; @@ -91,6 +91,9 @@ namespace OpenRA.Mods.Common.Widgets void UpdateTerrainCell(CPos cell) { + if (!world.Map.Contains(cell)) + return; + var stride = radarSheet.Size.Width; var uv = cell.ToMPos(world.Map);