From 10f5e68f7fd6322dabacd655a25dd3df8d554eb2 Mon Sep 17 00:00:00 2001 From: Bob Date: Mon, 25 Oct 2010 08:54:53 +1300 Subject: [PATCH] fix #166 (shroud artifacting at bounds) --- OpenRA.Game/Game.cs | 2 +- OpenRA.Game/Graphics/Viewport.cs | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 8c56104bb6..da9bdb215d 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -166,7 +166,7 @@ namespace OpenRA BeforeGameStart(); var map = modData.PrepareMap(mapUID); - viewport = new Viewport(new float2(Renderer.Resolution), map.TopLeft, map.BottomRight, Renderer); + viewport = new Viewport(new int2(Renderer.Resolution), map.TopLeft, map.BottomRight, Renderer); orderManager.world = new World(modData.Manifest, map, orderManager); worldRenderer = new WorldRenderer(orderManager.world); diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 8720e55e6a..addc87f36b 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -18,16 +18,16 @@ namespace OpenRA.Graphics { public class Viewport { - readonly float2 screenSize; - float2 scrollPosition; + readonly int2 screenSize; + int2 scrollPosition; readonly Renderer renderer; readonly int2 mapStart; readonly int2 mapEnd; public float2 Location { get { return scrollPosition; } } - public int Width { get { return (int)screenSize.X; } } - public int Height { get { return (int)screenSize.Y; } } + public int Width { get { return screenSize.X; } } + public int Height { get { return screenSize.Y; } } float cursorFrame = 0f; @@ -41,7 +41,8 @@ namespace OpenRA.Graphics public void Scroll(float2 delta, bool ignoreBorders) { - float2 newScrollPosition = scrollPosition + delta; + var d = delta.ToInt2(); + var newScrollPosition = scrollPosition + d; if(!ignoreBorders) newScrollPosition = this.NormalizeScrollPosition(newScrollPosition); @@ -49,10 +50,10 @@ namespace OpenRA.Graphics scrollPosition = newScrollPosition; } - private float2 NormalizeScrollPosition(float2 newScrollPosition) + private int2 NormalizeScrollPosition(int2 newScrollPosition) { - float2 topLeftBorder = (Game.CellSize* mapStart).ToFloat2(); - float2 bottomRightBorder = (Game.CellSize* mapEnd).ToFloat2(); + var topLeftBorder = Game.CellSize* mapStart; + var bottomRightBorder = Game.CellSize* mapEnd; if(newScrollPosition.Y < topLeftBorder.Y - screenSize.Y/2) newScrollPosition.Y = topLeftBorder.Y - screenSize.Y/2; @@ -85,7 +86,7 @@ namespace OpenRA.Graphics return blockedDirections; } - public Viewport(float2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer) + public Viewport(int2 screenSize, int2 mapStart, int2 mapEnd, Renderer renderer) { this.screenSize = screenSize; this.renderer = renderer; @@ -125,7 +126,7 @@ namespace OpenRA.Graphics public void Center(float2 loc) { - scrollPosition = this.NormalizeScrollPosition(Game.CellSize*loc - .5f * new float2(Width, Height)); + scrollPosition = this.NormalizeScrollPosition(Game.CellSize*loc - screenSize / 2); } public void Center(IEnumerable actors) @@ -136,7 +137,7 @@ namespace OpenRA.Graphics .Select(a => a.CenterLocation) .Aggregate((a, b) => a + b); - scrollPosition = this.NormalizeScrollPosition((avgPos - .5f * new float2(Width, Height))); + scrollPosition = this.NormalizeScrollPosition((avgPos.ToInt2() - screenSize / 2)); } public Rectangle ShroudBounds( World world )