From 23da8a24bdaf0adfe5618201a57a450ffe4d19f3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 19 Sep 2010 18:33:47 +1200 Subject: [PATCH] Only render shroud/ore that is in the current viewport --- OpenRA.Game/Graphics/Viewport.cs | 9 +++++++++ OpenRA.Game/ShroudRenderer.cs | 2 +- OpenRA.Game/Traits/World/ResourceLayer.cs | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 642cd78c6e..7f59bf0c2d 100644 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -158,5 +158,14 @@ namespace OpenRA.Graphics if (localPlayer.Shroud.Disabled) return null; return localPlayer.Shroud.Bounds; } + + public Rectangle ViewBounds() + { + int2 boundary = new int2(3,3); // Add a curtain of cells around the viewport to account for rounding errors + var origin = new int2((int)(scrollPosition.X/Game.CellSize), (int)(scrollPosition.Y/Game.CellSize)); + var tl = ViewToWorld(origin).ToInt2() - boundary; + var br = ViewToWorld(origin + new int2(Width, Height)).ToInt2() + boundary; + return Rectangle.FromLTRB(tl.X, tl.Y, br.X, br.Y); + } } } \ No newline at end of file diff --git a/OpenRA.Game/ShroudRenderer.cs b/OpenRA.Game/ShroudRenderer.cs index 08a2faccc7..be7bcfa912 100644 --- a/OpenRA.Game/ShroudRenderer.cs +++ b/OpenRA.Game/ShroudRenderer.cs @@ -145,7 +145,7 @@ namespace OpenRA } var clipRect = Bounds.HasValue ? Rectangle.Intersect(Bounds.Value, map.Bounds) : map.Bounds; - + clipRect = Rectangle.Intersect(Game.viewport.ViewBounds(), clipRect); var miny = clipRect.Top; var maxy = clipRect.Bottom; var minx = clipRect.Left; diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 96ebef7f8a..01e7bb5de5 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -29,6 +29,8 @@ namespace OpenRA.Traits var cliprect = Game.viewport.ShroudBounds().HasValue ? Rectangle.Intersect(Game.viewport.ShroudBounds().Value, world.Map.Bounds) : world.Map.Bounds; + cliprect = Rectangle.Intersect(Game.viewport.ViewBounds(), cliprect); + var minx = cliprect.Left; var maxx = cliprect.Right;