diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 383f6df1d7..83970ec606 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -139,10 +139,9 @@ namespace OpenRA.Graphics get { // Visible rectangle in world coordinates (expanded to the corners of the cells) - // Expand the cordon by an additional cell to account for staggered rows on diamond cell grids. var map = worldRenderer.world.Map; - var ctl = map.CenterOfCell(VisibleCells.TopLeft) - new WVec(1536, 1536, 0); - var cbr = map.CenterOfCell(VisibleCells.BottomRight) + new WVec(1535, 1535, 0); + var ctl = map.CenterOfCell(VisibleCells.TopLeft) - new WVec(512, 512, 0); + var cbr = map.CenterOfCell(VisibleCells.BottomRight) + new WVec(512, 512, 0); // Convert to screen coordinates var tl = WorldToViewPx(worldRenderer.ScreenPxPosition(ctl)).Clamp(ScreenClip); diff --git a/OpenRA.Game/Map/CellRegion.cs b/OpenRA.Game/Map/CellRegion.cs index 282030b07f..ce7316ecd1 100644 --- a/OpenRA.Game/Map/CellRegion.cs +++ b/OpenRA.Game/Map/CellRegion.cs @@ -40,6 +40,16 @@ namespace OpenRA mapBottomRight = Map.CellToMap(shape, BottomRight); } + /// Expand the specified region with an additional cordon. This may expand the region outside the map borders. + public static CellRegion Expand(CellRegion region, int cordon) + { + var offset = new CVec(cordon, cordon); + var tl = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.TopLeft) - offset); + var br = Map.MapToCell(region.shape, Map.CellToMap(region.shape, region.BottomRight) + offset); + + return new CellRegion(region.shape, tl, br); + } + public bool Contains(CPos cell) { var uv = Map.CellToMap(shape, cell); diff --git a/OpenRA.Mods.RA/ShroudRenderer.cs b/OpenRA.Mods.RA/ShroudRenderer.cs index 0d5b45ff12..10a44b1fc5 100644 --- a/OpenRA.Mods.RA/ShroudRenderer.cs +++ b/OpenRA.Mods.RA/ShroudRenderer.cs @@ -197,11 +197,19 @@ namespace OpenRA.Mods.RA public void WorldLoaded(World w, WorldRenderer wr) { // Initialize tile cache - foreach (var cell in map.Cells) + // Adds a 1-cell border around the border to cover any sprites peeking outside the map + foreach (var cell in CellRegion.Expand(w.Map.Cells, 1)) { var screen = wr.ScreenPosition(w.Map.CenterOfCell(cell)); var variant = Game.CosmeticRandom.Next(info.ShroudVariants.Length); tiles[cell] = new ShroudTile(cell, screen, variant); + + // Set the cells outside the border so they don't need to be touched again + if (!map.Contains(cell)) + { + var index = info.UseExtendedIndex ? 240 : 15; + tiles[cell].Shroud = shroudSprites[variant * variantStride + spriteMap[index]]; + } } fogPalette = wr.Palette(info.FogPalette); @@ -253,7 +261,7 @@ namespace OpenRA.Mods.RA { Update(shroud); - foreach (var cell in wr.Viewport.VisibleCells) + foreach (var cell in CellRegion.Expand(wr.Viewport.VisibleCells, 1)) { var t = tiles[cell];