diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 0e0e54bcdc..04a26d767a 100644 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -10,7 +10,7 @@ namespace OpenRa.Game { abstract class Actor { - public float2 renderLocation; + public abstract float2 RenderLocation { get; } public int palette; public abstract Sprite[] CurrentImages { get; } public virtual void Tick(World world, double t) { } diff --git a/OpenRa.Game/Building.cs b/OpenRa.Game/Building.cs index 8c824359d8..adc81adefd 100644 --- a/OpenRa.Game/Building.cs +++ b/OpenRa.Game/Building.cs @@ -7,10 +7,11 @@ namespace OpenRa.Game class Building : Actor { protected Animation animation; + protected int2 location; public Building( string name, int2 location, int palette ) { - this.renderLocation = 24.0f * location.ToFloat2(); + this.location = location; this.palette = palette; animation = new Animation( name ); @@ -26,5 +27,10 @@ namespace OpenRa.Game { get { return animation.Images; } } + + public override float2 RenderLocation + { + get { return 24.0f * location.ToFloat2(); } + } } } diff --git a/OpenRa.Game/Tree.cs b/OpenRa.Game/Tree.cs index 1938d0efd5..6a4fef113c 100644 --- a/OpenRa.Game/Tree.cs +++ b/OpenRa.Game/Tree.cs @@ -8,14 +8,17 @@ namespace OpenRa.Game { class Tree : Actor { + int2 location; + public Tree(TreeReference r, TreeCache renderer, Map map) { - renderLocation = 24 * (new float2(r.Location) - new float2(map.XOffset, map.YOffset)); + location = new int2( r.Location ) - new int2( map.XOffset, map.YOffset ); currentImages = new Sprite[] { renderer.GetImage(r.Image) }; } Sprite[] currentImages; - public override Sprite[] CurrentImages { get { return currentImages; } } + + public override float2 RenderLocation { get { return 24 * location.ToFloat2(); } } } } diff --git a/OpenRa.Game/Unit.cs b/OpenRa.Game/Unit.cs index ec26993094..db051ca093 100644 --- a/OpenRa.Game/Unit.cs +++ b/OpenRa.Game/Unit.cs @@ -20,8 +20,6 @@ namespace OpenRa.Game { fromCell = toCell = cell; this.renderOffset = renderOffset; - // HACK: display the mcv centered in it's cell; - renderLocation = ( cell * 24 ).ToFloat2() - renderOffset; this.palette = palette; } @@ -101,17 +99,6 @@ namespace OpenRa.Game } } } - - float2 location; - if( moveFraction > 0 ) - location = 24 * float2.Lerp( fromCell.ToFloat2(), toCell.ToFloat2(), - (float)moveFraction / moveFractionTotal ); - else - location = 24 * fromCell.ToFloat2(); - - renderLocation = location - renderOffset; - - renderLocation = renderLocation.Round(); }; } @@ -130,5 +117,16 @@ namespace OpenRa.Game { get { return toCell; } } + + public override float2 RenderLocation + { + get + { + float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f; + + float2 location = 24 * float2.Lerp( fromCell.ToFloat2(), toCell.ToFloat2(), fraction ); + return ( location - renderOffset ).Round(); ; + } + } } } diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 3031f9ad8a..32873da0fc 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -13,13 +13,11 @@ namespace OpenRa.Game List actors = new List(); List> frameEndActions = new List>(); SpriteRenderer spriteRenderer; - Renderer renderer; Viewport viewport; public ISelectable myUnit; public World(Renderer renderer, Viewport viewport) { - this.renderer = renderer; this.viewport = viewport; viewport.AddRegion(Region.Create(viewport, DockStyle.Left, viewport.Width - 128, Draw)); spriteRenderer = new SpriteRenderer(renderer, true); @@ -44,15 +42,16 @@ namespace OpenRa.Game a.Tick( this, dt ); Sprite[] images = a.CurrentImages; + float2 loc = a.RenderLocation; - if( a.renderLocation.X > range.End.X || a.renderLocation.X < range.Start.X - images[ 0 ].bounds.Width ) + if( loc.X > range.End.X || loc.X < range.Start.X - images[ 0 ].bounds.Width ) continue; - if (a.renderLocation.Y > range.End.Y || a.renderLocation.Y < range.Start.Y - images[0].bounds.Height) + if( loc.Y > range.End.Y || loc.Y < range.Start.Y - images[ 0 ].bounds.Height ) continue; foreach( Sprite image in images ) - spriteRenderer.DrawSprite(image, a.renderLocation, a.palette); + spriteRenderer.DrawSprite(image, loc, a.palette); } foreach( Action a in frameEndActions )