From b335d67ce337a6896814c4d871ac1ad567f7b4c4 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 20 Sep 2013 21:56:40 +1200 Subject: [PATCH 01/19] Remove PPos hacks from RadarWidget. --- OpenRA.Game/Graphics/Viewport.cs | 1 + OpenRA.Mods.RA/Widgets/RadarWidget.cs | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index e7623d5697..e1dd2f3948 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -151,6 +151,7 @@ namespace OpenRA.Graphics public PPos ViewToWorldPx(int2 loc) { return (PPos)(1f/Zoom*loc.ToFloat2() + Location).ToInt2(); } public PPos ViewToWorldPx(MouseInput mi) { return ViewToWorldPx(mi.Location); } + public int2 WorldToViewPx(PPos loc) { return (Zoom * (loc.ToFloat2() - Location)).ToInt2(); } public void Center(float2 loc) { diff --git a/OpenRA.Mods.RA/Widgets/RadarWidget.cs b/OpenRA.Mods.RA/Widgets/RadarWidget.cs index 36539fdefe..6f6ff16e8d 100755 --- a/OpenRA.Mods.RA/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarWidget.cs @@ -42,11 +42,13 @@ namespace OpenRA.Mods.RA.Widgets Sprite shroudSprite; readonly World world; + readonly WorldRenderer worldRenderer; [ObjectCreator.UseCtor] - public RadarWidget(World world) + public RadarWidget(World world, WorldRenderer worldRenderer) { this.world = world; + this.worldRenderer = worldRenderer; } public override void Initialize(WidgetArgs args) @@ -104,19 +106,21 @@ namespace OpenRA.Mods.RA.Widgets if (!hasRadar) return true; - var loc = MinimapPixelToCell(mi.Location); + var cell = MinimapPixelToCell(mi.Location); + var pos = cell.CenterPosition; if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left) - Game.viewport.Center(loc.ToFloat2()); + Game.viewport.Center(cell.ToFloat2()); if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right) { // fake a mousedown/mouseup here + var location = Game.viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(pos)); var fakemi = new MouseInput { Event = MouseInputEvent.Down, Button = MouseButton.Right, Modifiers = mi.Modifiers, - Location = (loc.ToPPos().ToFloat2() - Game.viewport.Location).ToInt2() + Location = location }; if (WorldInteractionController != null) From 0dc50c65f538bb27a256d5261d141840e6ff0f6e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 24 Sep 2013 18:18:44 +1200 Subject: [PATCH 02/19] Remove unnecessary int2 -> PPos -> int2 conversions. --- OpenRA.Game/Graphics/Viewport.cs | 5 ++--- OpenRA.Game/Graphics/WorldRenderer.cs | 4 ++-- OpenRA.Game/Traits/World/ScreenMap.cs | 3 --- .../Widgets/WorldInteractionControllerWidget.cs | 14 +++++++------- OpenRA.Game/WorldUtils.cs | 2 +- 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index e1dd2f3948..93aa963343 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -149,9 +149,8 @@ namespace OpenRA.Graphics return (CPos)( (1f / Game.CellSize) * (1f/Zoom*loc.ToFloat2() + Location) ).ToInt2(); } - public PPos ViewToWorldPx(int2 loc) { return (PPos)(1f/Zoom*loc.ToFloat2() + Location).ToInt2(); } - public PPos ViewToWorldPx(MouseInput mi) { return ViewToWorldPx(mi.Location); } - public int2 WorldToViewPx(PPos loc) { return (Zoom * (loc.ToFloat2() - Location)).ToInt2(); } + public int2 ViewToWorldPx(int2 loc) { return (1f/Zoom*loc.ToFloat2() + Location).ToInt2(); } + public int2 WorldToViewPx(int2 loc) { return (Zoom * (loc.ToFloat2() - Location)).ToInt2(); } public void Center(float2 loc) { diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 56c2f10c9b..de977cff7d 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -75,8 +75,8 @@ namespace OpenRA.Graphics { var comparer = new RenderableComparer(this); var vb = Game.viewport.ViewBounds(world); - var tl = Game.viewport.ViewToWorldPx(new int2(vb.Left, vb.Top)).ToInt2(); - var br = Game.viewport.ViewToWorldPx(new int2(vb.Right, vb.Bottom)).ToInt2(); + var tl = Game.viewport.ViewToWorldPx(new int2(vb.Left, vb.Top)); + var br = Game.viewport.ViewToWorldPx(new int2(vb.Right, vb.Bottom)); var actors = world.ScreenMap.ActorsInBox(tl, br) .Append(world.WorldActor) .ToList(); diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 684a60c365..283440b8e9 100755 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -127,9 +127,6 @@ namespace OpenRA.Traits .Select(kv => kv.Key); } - // Legacy fallback - public IEnumerable ActorsAt(PPos pxPos) { return ActorsAt(pxPos.ToInt2()); } - public IEnumerable ActorsInBox(int2 a, int2 b) { return ActorsInBox(Rectangle.FromLTRB(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Max(a.X, b.X), Math.Max(a.Y, b.Y))); diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index d58e682a35..4d122e5ebc 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -23,6 +23,7 @@ namespace OpenRA.Widgets { protected readonly World world; readonly WorldRenderer worldRenderer; + int2 dragStart, dragEnd; [ObjectCreator.UseCtor] public WorldInteractionControllerWidget(World world, WorldRenderer worldRenderer) @@ -47,11 +48,10 @@ namespace OpenRA.Widgets worldRenderer.DrawRollover(u); } - PPos dragStart, dragEnd; public override bool HandleMouseInput(MouseInput mi) { - var xy = Game.viewport.ViewToWorldPx(mi); + var xy = Game.viewport.ViewToWorldPx(mi.Location); var UseClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle; @@ -127,7 +127,7 @@ namespace OpenRA.Widgets } - public Pair? SelectionBox + public Pair? SelectionBox { get { @@ -136,11 +136,11 @@ namespace OpenRA.Widgets } } - public void ApplyOrders(World world, PPos xy, MouseInput mi) + public void ApplyOrders(World world, int2 xy, MouseInput mi) { if (world.OrderGenerator == null) return; - var orders = world.OrderGenerator.Order(world, xy.ToCPos(), mi).ToArray(); + var orders = world.OrderGenerator.Order(world, ((PPos)xy).ToCPos(), mi).ToArray(); orders.Do(o => world.IssueOrder(o)); world.PlayVoiceForOrders(orders); @@ -183,9 +183,9 @@ namespace OpenRA.Widgets } static readonly Actor[] NoActors = {}; - IEnumerable SelectActorsInBox(World world, PPos a, PPos b, Func cond) + IEnumerable SelectActorsInBox(World world, int2 a, int2 b, Func cond) { - return world.ScreenMap.ActorsInBox(a.ToInt2(), b.ToInt2()) + return world.ScreenMap.ActorsInBox(a, b) .Where(x => x.HasTrait() && x.Trait().Info.Selectable && !world.FogObscures(x) && cond(x)) .GroupBy(x => x.GetSelectionPriority()) .OrderByDescending(g => g.Key) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index df54b6d96b..19450fe65f 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -27,7 +27,7 @@ namespace OpenRA if (world.RenderPlayer == null) return NoFrozenActors; - return world.ScreenMap.FrozenActorsAt(world.RenderPlayer, Game.viewport.ViewToWorldPx(mouseLocation).ToInt2()); + return world.ScreenMap.FrozenActorsAt(world.RenderPlayer, Game.viewport.ViewToWorldPx(mouseLocation)); } public static IEnumerable FindActorsInBox(this World world, CPos tl, CPos br) From aed7f2ace6d4bbb670867fe33d0c438489ffce76 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:07:13 +1200 Subject: [PATCH 03/19] Remove PPos and tidy DebugOverlay. --- OpenRA.Mods.RA/World/DebugOverlay.cs | 32 ++++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.RA/World/DebugOverlay.cs b/OpenRA.Mods.RA/World/DebugOverlay.cs index 729a953f6a..7f568ae102 100644 --- a/OpenRA.Mods.RA/World/DebugOverlay.cs +++ b/OpenRA.Mods.RA/World/DebugOverlay.cs @@ -46,37 +46,37 @@ namespace OpenRA.Mods.RA public void Render(WorldRenderer wr) { - if (!Visible) return; + if (!Visible) + return; var qr = Game.Renderer.WorldQuadRenderer; - bool doDim = refreshTick - world.FrameNumber <= 0; + var doDim = refreshTick - world.FrameNumber <= 0; if (doDim) refreshTick = world.FrameNumber + 20; var viewBounds = Game.viewport.WorldBounds(world); - var mapBounds = world.Map.Bounds; foreach (var pair in layers) { - Color c = (pair.Key != null) ? pair.Key.Color.RGB : Color.PaleTurquoise; + var c = (pair.Key != null) ? pair.Key.Color.RGB : Color.PaleTurquoise; var layer = pair.Value; - for (int j = mapBounds.Top; j <= mapBounds.Bottom; ++j) - for (int i = mapBounds.Left; i <= mapBounds.Right; ++i) + // Only render quads in viewing range: + for (var j = viewBounds.Top; j <= viewBounds.Bottom; ++j) + { + for (var i = viewBounds.Left; i <= viewBounds.Right; ++i) { - if (layer[i, j] <= 0) continue; + if (layer [i, j] <= 0) + continue; - var w = Math.Max(0, Math.Min(layer[i, j], 128)); + var w = Math.Max(0, Math.Min(layer [i, j], 128)); if (doDim) - { - layer[i, j] = layer[i, j] * 5 / 6; - } + layer [i, j] = layer [i, j] * 5 / 6; - if (!viewBounds.Contains(i, j)) continue; - - // Only render quads in viewing range: - var ploc = new CPos(i, j).ToPPos(); - qr.FillRect(new RectangleF(ploc.X, ploc.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, c)); + // TODO: This doesn't make sense for isometric terrain + var tl = wr.ScreenPxPosition(new CPos(i, j).CenterPosition) - new int2(Game.CellSize, Game.CellSize); + qr.FillRect(new RectangleF(tl.X, tl.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, c)); } + } } } } From 4df9fc1accf124ad6229fc1835d51a96e00541ed Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:33:19 +1200 Subject: [PATCH 04/19] Render minefield targeting using PBOG-style overlay. --- OpenRA.Game/Graphics/WorldRenderer.cs | 18 ------- OpenRA.Mods.RA/Minelayer.cs | 69 ++++++++++++++++++--------- 2 files changed, 46 insertions(+), 41 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index de977cff7d..8e4bc582ac 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -179,24 +179,6 @@ namespace OpenRA.Graphics selectable.DrawRollover(this, unit); } - public void DrawLocus(Color c, CPos[] cells) - { - var dict = cells.ToDictionary(a => a, a => 0); - var wlr = Game.Renderer.WorldLineRenderer; - - foreach (var t in dict.Keys) - { - if (!dict.ContainsKey(t + new CVec(-1, 0))) - wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(0, 1)).ToPPos().ToFloat2(), c, c); - if (!dict.ContainsKey(t + new CVec(1, 0))) - wlr.DrawLine((t + new CVec(1, 0)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c); - if (!dict.ContainsKey(t + new CVec(0, -1))) - wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(1, 0)).ToPPos().ToFloat2(), c, c); - if (!dict.ContainsKey(t + new CVec(0, 1))) - wlr.DrawLine((t + new CVec(0, 1)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c); - } - } - public void DrawRangeCircle(Color c, float2 location, float range) { for (var i = 0; i < 32; i++) diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index d52144080c..b3626a59ee 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -34,28 +34,34 @@ namespace OpenRA.Mods.RA public CPos[] minefield = null; [Sync] CPos minefieldStart; Actor self; + Sprite tile; - public Minelayer(Actor self) { this.self = self; } + public Minelayer(Actor self) + { + this.self = self; + + var tileset = self.World.TileSet.Id.ToLower(); + tile = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0); + } public IEnumerable Orders { get { yield return new BeginMinefieldOrderTargeter(); } } - public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) + public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) { - if( order is BeginMinefieldOrderTargeter ) - { - var start = target.CenterPosition.ToCPos(); - self.World.OrderGenerator = new MinefieldOrderGenerator( self, start ); - return new Order("BeginMinefield", self, false) { TargetLocation = start }; - } - return null; + if (!(order is BeginMinefieldOrderTargeter)) + return null; + + var start = target.CenterPosition.ToCPos(); + self.World.OrderGenerator = new MinefieldOrderGenerator(self, start); + return new Order("BeginMinefield", self, false) { TargetLocation = start }; } public void ResolveOrder(Actor self, Order order) { - if( order.OrderString == "BeginMinefield" ) + if (order.OrderString == "BeginMinefield") minefieldStart = order.TargetLocation; if (order.OrderString == "PlaceMinefield") @@ -91,12 +97,33 @@ namespace OpenRA.Mods.RA yield return new CPos(i, j); } + public void RenderAfterWorld(WorldRenderer wr) + { + if (self.Owner != self.World.LocalPlayer || minefield == null) + return; + + var pal = wr.Palette("terrain"); + foreach (var c in minefield) + new SpriteRenderable(tile, c.CenterPosition, + WVec.Zero, -511, pal, 1f, true).Render(wr); + } + class MinefieldOrderGenerator : IOrderGenerator { readonly Actor minelayer; readonly CPos minefieldStart; + readonly Sprite tileOk; + readonly Sprite tileBlocked; - public MinefieldOrderGenerator(Actor self, CPos xy ) { minelayer = self; minefieldStart = xy; } + public MinefieldOrderGenerator(Actor self, CPos xy) + { + minelayer = self; + minefieldStart = xy; + + var tileset = self.World.TileSet.Id.ToLower(); + tileOk = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0); + tileBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0); + } public IEnumerable Order(World world, CPos xy, MouseInput mi) { @@ -134,24 +161,20 @@ namespace OpenRA.Mods.RA var movement = minelayer.Trait(); var minefield = GetMinefieldCells(minefieldStart, lastMousePos, - minelayer.Info.Traits.Get().MinefieldDepth) - .Where(p => movement.CanEnterCell(p)).ToArray(); + minelayer.Info.Traits.Get().MinefieldDepth); - wr.DrawLocus(Color.Cyan, minefield); + var pal = wr.Palette("terrain"); + foreach (var c in minefield) + { + var tile = movement.CanEnterCell(c) ? tileOk : tileBlocked; + new SpriteRenderable(tile, c.CenterPosition, + WVec.Zero, -511, pal, 1f, true).Render(wr); + } } public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* TODO */ } - public void RenderAfterWorld(WorldRenderer wr) - { - if (self.Owner != self.World.LocalPlayer) - return; - - if (minefield != null) - wr.DrawLocus(Color.Cyan, minefield); - } - class BeginMinefieldOrderTargeter : IOrderTargeter { public string OrderID { get { return "BeginMinefield"; } } From 27e4bbf1cbe30a40e604d6b5e3f0607eab14cdf1 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:46:57 +1200 Subject: [PATCH 05/19] Replace CenterLocationInit -> CenterPositionInit. --- OpenRA.Game/ActorInitializer.cs | 10 +++++----- OpenRA.Mods.RA/Husk.cs | 2 +- OpenRA.Mods.RA/LeavesHusk.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/ActorInitializer.cs b/OpenRA.Game/ActorInitializer.cs index f342c21d24..909c716b8e 100755 --- a/OpenRA.Game/ActorInitializer.cs +++ b/OpenRA.Game/ActorInitializer.cs @@ -80,12 +80,12 @@ namespace OpenRA public SubCell Value(World world) { return (SubCell)value; } } - public class CenterLocationInit : IActorInit + public class CenterPositionInit : IActorInit { - [FieldFromYamlKey] public readonly int2 value = int2.Zero; - public CenterLocationInit() { } - public CenterLocationInit(PPos init) { value = init.ToInt2(); } - public PPos Value(World world) { return (PPos)value; } + [FieldFromYamlKey] public readonly WPos value = WPos.Zero; + public CenterPositionInit() { } + public CenterPositionInit(WPos init) { value = init; } + public WPos Value(World world) { return value; } } public class OwnerInit : IActorInit diff --git a/OpenRA.Mods.RA/Husk.cs b/OpenRA.Mods.RA/Husk.cs index 2e9c0b0383..7efd9e19e4 100644 --- a/OpenRA.Mods.RA/Husk.cs +++ b/OpenRA.Mods.RA/Husk.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA this.self = init.self; TopLeft = init.Get(); - CenterPosition = init.Contains() ? init.Get().ToWPos(0) : TopLeft.CenterPosition; + CenterPosition = init.Contains() ? init.Get() : TopLeft.CenterPosition; Facing = init.Contains() ? init.Get() : 128; var speed = init.Contains() ? init.Get() : 0; diff --git a/OpenRA.Mods.RA/LeavesHusk.cs b/OpenRA.Mods.RA/LeavesHusk.cs index c543da970c..f27171be06 100644 --- a/OpenRA.Mods.RA/LeavesHusk.cs +++ b/OpenRA.Mods.RA/LeavesHusk.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA { new ParentActorInit(self), new LocationInit(self.Location), - new CenterLocationInit(self.CenterLocation), + new CenterPositionInit(self.CenterPosition), new OwnerInit(self.Owner), new SkipMakeAnimsInit() }; From 2e0e4b0bc5e6bc232d8ddb039fe244892d167ce0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 24 Sep 2013 18:33:48 +1200 Subject: [PATCH 06/19] Add WorldRenderer.Position for screen -> world conversion. --- OpenRA.Game/Graphics/WorldRenderer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 8e4bc582ac..64710fa49a 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -235,5 +235,10 @@ namespace OpenRA.Graphics } public float ScreenZPosition(WPos pos, int zOffset) { return (pos.Y + pos.Z + zOffset)*Game.CellSize/1024f; } + + public WPos Position(int2 screenPx) + { + return new WPos(1024 * screenPx.X / Game.CellSize, 1024 * screenPx.Y / Game.CellSize, 0); + } } } From b100b4131c5f1729f120b356741220a138a0a156 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 24 Sep 2013 18:34:26 +1200 Subject: [PATCH 07/19] Remove PPos hacks from WorldInteractionController. --- .../WorldInteractionControllerWidget.cs | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 4d122e5ebc..407fff9394 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -136,33 +136,38 @@ namespace OpenRA.Widgets } } - public void ApplyOrders(World world, int2 xy, MouseInput mi) + void ApplyOrders(World world, int2 xy, MouseInput mi) { if (world.OrderGenerator == null) return; - var orders = world.OrderGenerator.Order(world, ((PPos)xy).ToCPos(), mi).ToArray(); + var pos = worldRenderer.Position(xy); + var orders = world.OrderGenerator.Order(world, pos.ToCPos(), mi).ToArray(); orders.Do(o => world.IssueOrder(o)); world.PlayVoiceForOrders(orders); } - public override string GetCursor(int2 pos) + public override string GetCursor(int2 screenPos) { return Sync.CheckSyncUnchanged(world, () => { + // Always show an arrow while selecting if (SelectionBox != null) - return null; /* always show an arrow while selecting */ + return null; + + var xy = Game.viewport.ViewToWorldPx(screenPos); + var pos = worldRenderer.Position(xy); + var cell = pos.ToCPos(); var mi = new MouseInput { - Location = pos, + Location = screenPos, Button = Game.mouseButtonPreference.Action, Modifiers = Game.GetModifierKeys() }; - // TODO: fix this up. - return world.OrderGenerator.GetCursor(world, Game.viewport.ViewToWorld(mi), mi); - } ); + return world.OrderGenerator.GetCursor(world, cell, mi); + }); } public override bool HandleKeyPress(KeyInput e) From 7320493a21b0eadb5e4af8da78ffb37be28a35a0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 24 Sep 2013 18:36:08 +1200 Subject: [PATCH 08/19] Fix radar cursor fake mouse event location. --- OpenRA.Mods.RA/Widgets/RadarWidget.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/OpenRA.Mods.RA/Widgets/RadarWidget.cs b/OpenRA.Mods.RA/Widgets/RadarWidget.cs index 6f6ff16e8d..6e8f31b928 100755 --- a/OpenRA.Mods.RA/Widgets/RadarWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarWidget.cs @@ -82,16 +82,17 @@ namespace OpenRA.Mods.RA.Widgets if (world == null || !hasRadar) return null; - var loc = MinimapPixelToCell(pos); + var cell = MinimapPixelToCell(pos); + var location = Game.viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(cell.CenterPosition)); var mi = new MouseInput { - Location = loc.ToInt2(), + Location = location, Button = MouseButton.Right, Modifiers = Game.GetModifierKeys() }; - var cursor = world.OrderGenerator.GetCursor(world, loc, mi); + var cursor = world.OrderGenerator.GetCursor(world, cell, mi); if (cursor == null) return "default"; From 1a1d5ede192080bc8db073750125438ea71de4d7 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:10:22 +1200 Subject: [PATCH 09/19] Remove PPos from TeslaZapRenderable. --- OpenRA.Mods.RA/TeslaZapRenderable.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.RA/TeslaZapRenderable.cs b/OpenRA.Mods.RA/TeslaZapRenderable.cs index 0389fd0a81..2293dcf29a 100755 --- a/OpenRA.Mods.RA/TeslaZapRenderable.cs +++ b/OpenRA.Mods.RA/TeslaZapRenderable.cs @@ -128,14 +128,15 @@ namespace OpenRA.Mods.RA var c = -float2.Dot(from, q); var rs = new List(); var z = from; + var pal = wr.Palette("effect"); while ((to - z).X > 5 || (to - z).X < -5 || (to - z).Y > 5 || (to - z).Y < -5) { var step = steps.Where(t => (to - (z + new float2(t[0], t[1]))).LengthSquared < (to - z).LengthSquared) .OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First(); - var pos = new PPos((int)(z.X + step[2]), (int)(z.Y + step[3])).ToWPos(0); - rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, wr.Palette("effect"), 1f, true)); + var pos = wr.Position((z + new float2(step[2], step[3])).ToInt2()); + rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, pal, 1f, true)); z += new float2(step[0], step[1]); if (rs.Count >= 1000) From 8c0da26ae1ba9b637ac361dd63357557346bb173 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:17:46 +1200 Subject: [PATCH 10/19] Remove PPos from GainsExperience. --- OpenRA.Mods.RA/GainsExperience.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index 5c9edd51e0..0dc11ce260 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA var bounds = self.Bounds.Value; bounds.Offset(pos.X, pos.Y); - var effectPos = new PPos(bounds.Right, bounds.Bottom - 2).ToWPos(0); + var effectPos = wr.Position(new int2(bounds.Right, bounds.Bottom - 2)); yield return new SpriteRenderable(RankAnim.Image, effectPos, WVec.Zero, 0, wr.Palette("effect"), 1f, true); } } From 3002c4b77d67172151d4ea3842b011c2fc821fd0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 10:26:03 +1200 Subject: [PATCH 11/19] Use SpriteRenderables for tile overlays. --- OpenRA.Game/Traits/World/ResourceLayer.cs | 7 ++----- OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs | 3 ++- OpenRA.Mods.RA/World/SmudgeLayer.cs | 4 +++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenRA.Game/Traits/World/ResourceLayer.cs b/OpenRA.Game/Traits/World/ResourceLayer.cs index 7f44e87ab5..74219e47ff 100644 --- a/OpenRA.Game/Traits/World/ResourceLayer.cs +++ b/OpenRA.Game/Traits/World/ResourceLayer.cs @@ -48,11 +48,8 @@ namespace OpenRA.Traits var c = render[x, y]; if (c.Image != null) - { - var tile = c.Image[c.Density]; - var px = wr.ScreenPxPosition(pos.CenterPosition) - 0.5f * tile.size; - tile.DrawAt(px, c.Type.info.PaletteRef); - } + new SpriteRenderable(c.Image[c.Density], pos.CenterPosition, + WVec.Zero, -511, c.Type.info.PaletteRef, 1f, true).Render(wr); } } } diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 2677892789..1285491f6e 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -112,7 +112,8 @@ namespace OpenRA.Mods.RA.Orders foreach (var c in cells) { var tile = c.Value ? buildOk : buildBlocked; - tile.DrawAt(wr.ScreenPxPosition(c.Key.CenterPosition) - 0.5f * tile.size, pal); + new SpriteRenderable(tile, c.Key.CenterPosition, + WVec.Zero, -511, pal, 1f, true).Render(wr); } } diff --git a/OpenRA.Mods.RA/World/SmudgeLayer.cs b/OpenRA.Mods.RA/World/SmudgeLayer.cs index f70e3313eb..cdc8942d27 100644 --- a/OpenRA.Mods.RA/World/SmudgeLayer.cs +++ b/OpenRA.Mods.RA/World/SmudgeLayer.cs @@ -106,7 +106,9 @@ namespace OpenRA.Mods.RA if (world.ShroudObscures(kv.Key)) continue; - smudgeSprites[kv.Value.Type - 1][kv.Value.Index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal); + var tile = smudgeSprites[kv.Value.Type - 1][kv.Value.Index]; + new SpriteRenderable(tile, kv.Key.CenterPosition, + WVec.Zero, -511, pal, 1f, true).Render(wr); } } } From f94c7034bfc19edcb106c23c602b2606c95a79d6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 10:26:15 +1200 Subject: [PATCH 12/19] Use SpriteRenderables for selection decorations. --- OpenRA.Game/Traits/SelectionDecorations.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Traits/SelectionDecorations.cs b/OpenRA.Game/Traits/SelectionDecorations.cs index be999bd9b9..83b043e43d 100644 --- a/OpenRA.Game/Traits/SelectionDecorations.cs +++ b/OpenRA.Game/Traits/SelectionDecorations.cs @@ -54,7 +54,9 @@ namespace OpenRA.Traits var pipImages = new Animation("pips"); pipImages.PlayFetchIndex("groups", () => (int)group); pipImages.Tick(); - pipImages.Image.DrawAt(basePosition + new float2(-8, 1), wr.Palette("chrome")); + + var pos = (basePosition + new float2(-8, 1) + 0.5f * pipImages.Image.size).ToInt2(); + pipImages.Render(wr.Position(pos), wr.Palette("chrome")).Do(r => r.Render(wr)); } void DrawPips(WorldRenderer wr, Actor self, float2 basePosition) @@ -90,8 +92,10 @@ namespace OpenRA.Traits pipxyOffset.Y -= pipSize.Y; } pipImages.PlayRepeating(pipStrings[(int)pip]); - pipImages.Image.DrawAt(pipxyBase + pipxyOffset, pal); pipxyOffset += new float2(pipSize.X, 0); + + var pos = (pipxyBase + pipxyOffset + 0.5f * pipSize).ToInt2(); + pipImages.Render(wr.Position(pos), pal).Do(r => r.Render(wr)); } // Increment row @@ -106,8 +110,7 @@ namespace OpenRA.Traits return; // If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows - var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file - var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows + var tagxyOffset = new float2(-16, 2); // Correct in the shp file and multiple rows var pal = wr.Palette("chrome"); foreach (var tags in self.TraitsImplementing()) { @@ -118,7 +121,8 @@ namespace OpenRA.Traits var tagImages = new Animation("pips"); tagImages.PlayRepeating(tagStrings[(int)tag]); - tagImages.Image.DrawAt(tagxyBase + tagxyOffset, pal); + var pos = (basePosition + tagxyOffset + 0.5f * tagImages.Image.size).ToInt2(); + tagImages.Render(wr.Position(pos), pal).Do(r => r.Render(wr)); // Increment row tagxyOffset.Y += 8; From 2303d8064ae18300c72b2d56ae03bca939fa2840 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 11:00:43 +1200 Subject: [PATCH 13/19] Remove Sprite.DrawAt. --- OpenRA.Game/Graphics/Renderable.cs | 2 +- OpenRA.Game/Graphics/ShroudRenderer.cs | 16 +++++++++------- OpenRA.Game/Graphics/Sprite.cs | 15 --------------- 3 files changed, 10 insertions(+), 23 deletions(-) diff --git a/OpenRA.Game/Graphics/Renderable.cs b/OpenRA.Game/Graphics/Renderable.cs index 072251ee46..b620af8c07 100644 --- a/OpenRA.Game/Graphics/Renderable.cs +++ b/OpenRA.Game/Graphics/Renderable.cs @@ -93,7 +93,7 @@ namespace OpenRA.Graphics public void BeforeRender(WorldRenderer wr) {} public void Render(WorldRenderer wr) { - sprite.DrawAt(ScreenPosition(wr), palette, scale); + Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.size*scale); } public void RenderDebugGeometry(WorldRenderer wr) diff --git a/OpenRA.Game/Graphics/ShroudRenderer.cs b/OpenRA.Game/Graphics/ShroudRenderer.cs index 3f8ef3ed2e..6dcc0b3b87 100644 --- a/OpenRA.Game/Graphics/ShroudRenderer.cs +++ b/OpenRA.Game/Graphics/ShroudRenderer.cs @@ -184,24 +184,26 @@ namespace OpenRA.Graphics if (starti != i) { - s[starti, j].DrawAt( + // Stretch a solid black sprite over the rows above + // TODO: This doesn't make sense for isometric terrain + Game.Renderer.WorldSpriteRenderer.DrawSprite( + s[starti, j], Game.CellSize * new float2(starti, j), pal, new float2(Game.CellSize * (i - starti), Game.CellSize)); starti = i + 1; } - s[i, j].DrawAt( - Game.CellSize * new float2(i, j), - pal); + Game.Renderer.WorldSpriteRenderer.DrawSprite(s[i, j], Game.CellSize * new float2(i, j), pal); starti = i + 1; last = s[i, j]; } + // Stretch a solid black sprite over the rows to the left + // TODO: This doesn't make sense for isometric terrain if (starti < clip.Right) - s[starti, j].DrawAt( - Game.CellSize * new float2(starti, j), - pal, + Game.Renderer.WorldSpriteRenderer.DrawSprite(s[starti, j], + Game.CellSize * new float2(starti, j), pal, new float2(Game.CellSize * (clip.Right - starti), Game.CellSize)); } } diff --git a/OpenRA.Game/Graphics/Sprite.cs b/OpenRA.Game/Graphics/Sprite.cs index 290524ec29..948643ffc4 100644 --- a/OpenRA.Game/Graphics/Sprite.cs +++ b/OpenRA.Game/Graphics/Sprite.cs @@ -55,21 +55,6 @@ namespace OpenRA.Graphics { return textureCoords[k]; } - - public void DrawAt(float2 location, PaletteReference pal) - { - Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size); - } - - public void DrawAt(float2 location, PaletteReference pal, float scale) - { - Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size*scale); - } - - public void DrawAt(float2 location, PaletteReference pal, float2 size) - { - Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size); - } } public enum TextureChannel From 90ab2477b4fbf1843107156d5f7ec5002eec1b1d Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 20 Sep 2013 00:14:19 +1200 Subject: [PATCH 14/19] Convert Sound to world coordinates. --- OpenRA.Game/Game.cs | 4 ++-- OpenRA.Game/Sound.cs | 40 +++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index 825f73af25..f4921e1498 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -137,8 +137,8 @@ namespace OpenRA using (new PerfSample("render")) { ++RenderFrame; - viewport.DrawRegions(worldRenderer, new DefaultInputHandler( orderManager.world )); - Sound.SetListenerPosition(viewport.CenterLocation); + viewport.DrawRegions(worldRenderer, new DefaultInputHandler(orderManager.world)); + Sound.SetListenerPosition(worldRenderer.Position(viewport.CenterLocation.ToInt2())); } PerfHistory.items["render"].Tick(); diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index 1b56b3a947..87bd17a828 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -91,7 +91,7 @@ namespace OpenRA return defaultDevices.Concat(alDevices).ToArray(); } - public static void SetListenerPosition(float2 position) { soundEngine.SetListenerPosition(position); } + public static void SetListenerPosition(WPos position) { soundEngine.SetListenerPosition(position); } static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier) { @@ -101,7 +101,7 @@ namespace OpenRA return null; return soundEngine.Play2D(sounds[name], - false, headRelative, PPos.FromWPosHackZ(pos).ToFloat2(), + false, headRelative, pos, InternalSoundVolume * volumeModifier, true); } @@ -115,7 +115,7 @@ namespace OpenRA public static void PlayVideo(byte[] raw) { rawSource = LoadSoundRaw(raw); - video = soundEngine.Play2D(rawSource, false, true, float2.Zero, InternalSoundVolume, false); + video = soundEngine.Play2D(rawSource, false, true, WPos.Zero, InternalSoundVolume, false); } public static void PlayVideo() @@ -174,7 +174,7 @@ namespace OpenRA if (sound == null) return; - music = soundEngine.Play2D(sound, false, true, float2.Zero, MusicVolume, false); + music = soundEngine.Play2D(sound, false, true, WPos.Zero, MusicVolume, false); currentMusic = m; MusicPlaying = true; } @@ -322,7 +322,7 @@ namespace OpenRA if (!String.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) soundEngine.Play2D(sounds[name], - false, true, float2.Zero, + false, true, WPos.Zero, InternalSoundVolume, attentuateVolume); return true; @@ -354,13 +354,13 @@ namespace OpenRA interface ISoundEngine { ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate); - ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume); + ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume); float Volume { get; set; } void PauseSound(ISound sound, bool paused); void StopSound(ISound sound); void SetAllSoundsPaused(bool paused); void StopAllSounds(); - void SetListenerPosition(float2 position); + void SetListenerPosition(WPos position); void SetSoundVolume(float volume, ISound music, ISound video); } @@ -397,7 +397,7 @@ namespace OpenRA { public bool isActive; public int frameStarted; - public float2 pos; + public WPos pos; public bool isRelative; public ISoundSource sound; } @@ -507,10 +507,10 @@ namespace OpenRA } const int maxInstancesPerFrame = 3; - const int groupDistance = 64; + const int groupDistance = 2730; const int groupDistanceSqr = groupDistance * groupDistance; - public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume) + public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { if (sound == null) { @@ -635,11 +635,12 @@ namespace OpenRA } } - public void SetListenerPosition(float2 position) + public void SetListenerPosition(WPos position) { - var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f }; + // Move the listener out of the plane so that sounds near the middle of the screen aren't too positional + Al.alListener3f(Al.AL_POSITION, position.X, position.Y, position.Z + 5*1024); - Al.alListener3f(Al.AL_POSITION, position.X, position.Y, 50); + var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f }; Al.alListenerfv(Al.AL_ORIENTATION, ref orientation[0]); Al.alListenerf(Al.AL_METERS_PER_UNIT, .01f); } @@ -669,19 +670,20 @@ namespace OpenRA public readonly int source = -1; float volume = 1f; - public OpenAlSound(int source, int buffer, bool looping, bool relative, float2 pos, float volume) + public OpenAlSound(int source, int buffer, bool looping, bool relative, WPos pos, float volume) { if (source == -1) return; this.source = source; Al.alSourcef(source, Al.AL_PITCH, 1f); Volume = volume; - Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, 0f); + Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, pos.Z); Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f); Al.alSourcei(source, Al.AL_BUFFER, buffer); Al.alSourcei(source, Al.AL_LOOPING, looping ? Al.AL_TRUE : Al.AL_FALSE); Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, relative ? 1 : 0); - Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, 160); - Al.alSourcef(source, Al.AL_MAX_DISTANCE, 3200 / Game.viewport.Zoom); + + Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, Game.viewport.WorldRect.Width / 8); + Al.alSourcef(source, Al.AL_MAX_DISTANCE, 2*Game.viewport.WorldRect.Width); Al.alSourcePlay(source); } @@ -728,7 +730,7 @@ namespace OpenRA return new NullSoundSource(); } - public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume) + public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume) { return new NullSound(); } @@ -737,7 +739,7 @@ namespace OpenRA public void StopSound(ISound sound) {} public void SetAllSoundsPaused(bool paused) {} public void StopAllSounds() {} - public void SetListenerPosition(float2 position) {} + public void SetListenerPosition(WPos position) {} public void SetSoundVolume(float volume, ISound music, ISound video) {} public float Volume { get; set; } From 68a0070fa69da675356a379fb61330d9bd4fce95 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 20 Sep 2013 18:53:06 +1200 Subject: [PATCH 15/19] Remove PPos hack from ScreenShaker. --- OpenRA.Game/Traits/World/ScreenShaker.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/OpenRA.Game/Traits/World/ScreenShaker.cs b/OpenRA.Game/Traits/World/ScreenShaker.cs index efd0aeffa5..fbfda7f741 100644 --- a/OpenRA.Game/Traits/World/ScreenShaker.cs +++ b/OpenRA.Game/Traits/World/ScreenShaker.cs @@ -11,16 +11,20 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.Graphics; namespace OpenRA.Traits { public class ScreenShakerInfo : TraitInfo { } - public class ScreenShaker : ITick + public class ScreenShaker : ITick, IWorldLoaded { + WorldRenderer worldRenderer; List shakeEffects = new List(); int ticks = 0; + public void WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; } + public void Tick(Actor self) { if (shakeEffects.Any()) @@ -46,7 +50,7 @@ namespace OpenRA.Traits float GetIntensity() { - var cp = ((PPos)Game.viewport.CenterLocation.ToInt2()).ToWPos(0); + var cp = worldRenderer.Position(Game.viewport.CenterLocation.ToInt2()); var intensity = 100 * 1024 * 1024 * shakeEffects.Sum( e => (float)e.Intensity / (e.Position - cp).LengthSquared); From b96c430f84bcd0bf02a8d8cbdd82dfb040cc5853 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Fri, 27 Sep 2013 15:53:24 +1200 Subject: [PATCH 16/19] Remove PVecInt from Viewport. --- OpenRA.Game/Graphics/Viewport.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 93aa963343..eb3ada7af7 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -159,12 +159,10 @@ namespace OpenRA.Graphics public void Center(IEnumerable actors) { - if (!actors.Any()) return; + if (!actors.Any()) + return; - var avgPos = actors - .Select(a => (PVecInt)a.CenterLocation) - .Aggregate((a, b) => a + b) / actors.Count(); - scrollPosition = NormalizeScrollPosition((avgPos.ToFloat2() - (1f / (2 * Zoom) * screenSize.ToFloat2())).ToInt2()); + Center(actors.Select(a => a.CenterPosition).Average().ToCPos().ToFloat2()); } // Rectangle (in viewport coords) that contains things to be drawn From 19e0c2a83fae14f1d7a2c4d40762a7f6f9687cb5 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 21 Sep 2013 18:31:12 +1200 Subject: [PATCH 17/19] Remove PPos and PVecInt. --- OpenRA.Game/Actor.cs | 1 - OpenRA.Game/CPos.cs | 1 - OpenRA.Game/OpenRA.Game.csproj | 2 - OpenRA.Game/PPos.cs | 107 --------------------------------- OpenRA.Game/PVecInt.cs | 79 ------------------------ OpenRA.Game/Sync.cs | 12 ---- 6 files changed, 202 deletions(-) delete mode 100644 OpenRA.Game/PPos.cs delete mode 100644 OpenRA.Game/PVecInt.cs diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 4fcd7f5f5e..39be1ac013 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -32,7 +32,6 @@ namespace OpenRA public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } } public CPos Location { get { return occupySpace.Value.TopLeft; } } - public PPos CenterLocation { get { return PPos.FromWPos(occupySpace.Value.CenterPosition); } } public WPos CenterPosition { get { return occupySpace.Value.CenterPosition; } } public WRot Orientation diff --git a/OpenRA.Game/CPos.cs b/OpenRA.Game/CPos.cs index 4a9151a269..cb43935556 100644 --- a/OpenRA.Game/CPos.cs +++ b/OpenRA.Game/CPos.cs @@ -39,7 +39,6 @@ namespace OpenRA public float2 ToFloat2() { return new float2(X, Y); } public int2 ToInt2() { return new int2(X, Y); } - public PPos ToPPos() { return new PPos(Game.CellSize * X, Game.CellSize * Y); } public WPos CenterPosition { get { return new WPos(1024 * X + 512, 1024 * Y + 512, 0); } } public WPos TopLeft { get { return new WPos(1024 * X, 1024 * Y, 0); } } diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 410110aeee..eca34a8364 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -85,8 +85,6 @@ - - diff --git a/OpenRA.Game/PPos.cs b/OpenRA.Game/PPos.cs deleted file mode 100644 index d965b5191e..0000000000 --- a/OpenRA.Game/PPos.cs +++ /dev/null @@ -1,107 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Drawing; - -namespace OpenRA -{ - /// - /// Pixel coordinate position in the world (fine). - /// - public struct PPos - { - public readonly int X, Y; - - public PPos(int x, int y) { X = x; Y = y; } - - public static readonly PPos Zero = new PPos(0, 0); - public static PPos FromWPos(WPos pos) - { - return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*pos.Y/1024); - } - - // Temporary hack for things that throw away altitude and - // cache screen positions directly. This can go once all - // the callers understand world coordinates - public static PPos FromWPosHackZ(WPos pos) - { - return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*(pos.Y - pos.Z)/1024); - } - - public static explicit operator PPos(int2 a) { return new PPos(a.X, a.Y); } - - public static explicit operator PVecInt(PPos a) { return new PVecInt(a.X, a.Y); } - - public static PPos operator +(PPos a, PVecInt b) { return new PPos(a.X + b.X, a.Y + b.Y); } - public static PVecInt operator -(PPos a, PPos b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } - public static PPos operator -(PPos a, PVecInt b) { return new PPos(a.X - b.X, a.Y - b.Y); } - - public static bool operator ==(PPos me, PPos other) { return (me.X == other.X && me.Y == other.Y); } - public static bool operator !=(PPos me, PPos other) { return !(me == other); } - - public static PPos Max(PPos a, PPos b) { return new PPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } - public static PPos Min(PPos a, PPos b) { return new PPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } - - public static PPos Lerp(PPos a, PPos b, int mul, int div) - { - return a + ((PVecInt)(b - a) * mul / div); - } - - public static PPos Average(params PPos[] list) - { - if (list == null || list.Length == 0) - throw new ArgumentException("PPos: Cannot calculate average of empty list."); - - var x = 0; - var y = 0; - foreach(var pos in list) - { - x += pos.X; - y += pos.Y; - } - - x /= list.Length; - y /= list.Length; - - return new PPos(x,y); - } - - public float2 ToFloat2() { return new float2(X, Y); } - public int2 ToInt2() { return new int2(X, Y); } - public CPos ToCPos() { return new CPos((int)(1f / Game.CellSize * X), (int)(1f / Game.CellSize * Y)); } - - public PPos Clamp(Rectangle r) - { - return new PPos(Math.Min(r.Right, Math.Max(X, r.Left)), - Math.Min(r.Bottom, Math.Max(Y, r.Top))); - } - - public WPos ToWPos(int z) - { - return new WPos(1024*X/Game.CellSize, - 1024*Y/Game.CellSize, - 1024*z/Game.CellSize); - } - - public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } - - public override bool Equals(object obj) - { - if (obj == null) - return false; - - PPos o = (PPos)obj; - return o == this; - } - - public override string ToString() { return "{0},{1}".F(X, Y); } - } -} diff --git a/OpenRA.Game/PVecInt.cs b/OpenRA.Game/PVecInt.cs deleted file mode 100644 index aed7981228..0000000000 --- a/OpenRA.Game/PVecInt.cs +++ /dev/null @@ -1,79 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 The OpenRA Developers (see AUTHORS) - * This file is part of OpenRA, which is free software. It is made - * available to you under the terms of the GNU General Public License - * as published by the Free Software Foundation. For more information, - * see COPYING. - */ -#endregion - -using System; -using System.Drawing; - -namespace OpenRA -{ - /// - /// Pixel coordinate vector (fine; integer) - /// - public struct PVecInt - { - public readonly int X, Y; - - public PVecInt(int x, int y) { X = x; Y = y; } - public PVecInt(Size p) { X = p.Width; Y = p.Height; } - - public static readonly PVecInt Zero = new PVecInt(0, 0); - public static PVecInt OneCell { get { return new PVecInt(Game.CellSize, Game.CellSize); } } - - public static explicit operator PVecInt(int2 a) { return new PVecInt(a.X, a.Y); } - - public static PVecInt FromRadius(int r) { return new PVecInt(r, r); } - - public static PVecInt operator +(PVecInt a, PVecInt b) { return new PVecInt(a.X + b.X, a.Y + b.Y); } - public static PVecInt operator -(PVecInt a, PVecInt b) { return new PVecInt(a.X - b.X, a.Y - b.Y); } - public static PVecInt operator *(int a, PVecInt b) { return new PVecInt(a * b.X, a * b.Y); } - public static PVecInt operator *(PVecInt b, int a) { return new PVecInt(a * b.X, a * b.Y); } - public static PVecInt operator /(PVecInt a, int b) { return new PVecInt(a.X / b, a.Y / b); } - - public static PVecInt operator -(PVecInt a) { return new PVecInt(-a.X, -a.Y); } - - public static bool operator ==(PVecInt me, PVecInt other) { return (me.X == other.X && me.Y == other.Y); } - public static bool operator !=(PVecInt me, PVecInt other) { return !(me == other); } - - public static PVecInt Max(PVecInt a, PVecInt b) { return new PVecInt(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); } - public static PVecInt Min(PVecInt a, PVecInt b) { return new PVecInt(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); } - - public static int Dot(PVecInt a, PVecInt b) { return a.X * b.X + a.Y * b.Y; } - - public PVecInt Sign() { return new PVecInt(Math.Sign(X), Math.Sign(Y)); } - public PVecInt Abs() { return new PVecInt(Math.Abs(X), Math.Abs(Y)); } - public int LengthSquared { get { return X * X + Y * Y; } } - public int Length { get { return (int)Math.Sqrt(LengthSquared); } } - - public float2 ToFloat2() { return new float2(X, Y); } - public int2 ToInt2() { return new int2(X, Y); } - public CVec ToCVec() { return new CVec(X / Game.CellSize, Y / Game.CellSize); } - - public PVecInt Clamp(Rectangle r) - { - return new PVecInt( - Math.Min(r.Right, Math.Max(X, r.Left)), - Math.Min(r.Bottom, Math.Max(Y, r.Top)) - ); - } - - public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } - - public override bool Equals(object obj) - { - if (obj == null) - return false; - - PVecInt o = (PVecInt)obj; - return o == this; - } - - public override string ToString() { return "{0},{1}".F(X, Y); } - } -} diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index 285450fe61..59c1a6af97 100755 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -36,8 +36,6 @@ namespace OpenRA {typeof(int2), ((Func)hash_int2).Method}, {typeof(CPos), ((Func)hash_CPos).Method}, {typeof(CVec), ((Func)hash_CVec).Method}, - {typeof(PPos), ((Func)hash_PPos).Method}, - {typeof(PVecInt), ((Func)hash_PVecInt).Method}, {typeof(WRange), ((Func)hash).Method}, {typeof(WPos), ((Func)hash).Method}, {typeof(WVec), ((Func)hash).Method}, @@ -115,16 +113,6 @@ namespace OpenRA { return ((i2.X * 5) ^ (i2.Y * 3)) / 4; } - - public static int hash_PPos(PPos i2) - { - return ((i2.X * 5) ^ (i2.Y * 3)) / 4; - } - - public static int hash_PVecInt(PVecInt i2) - { - return ((i2.X * 5) ^ (i2.Y * 3)) / 4; - } public static int hash_tdict(TypeDictionary d) { From 5f0bb4b6c256574f061ad05e778cc6894dc7b48e Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Sep 2013 21:15:46 +1300 Subject: [PATCH 18/19] Fix some style nits in WorldRenderer. --- OpenRA.Game/Graphics/WorldRenderer.cs | 44 +++++++++++++++------------ 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index 64710fa49a..ef588be876 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -155,21 +155,21 @@ namespace OpenRA.Graphics var pos = ScreenPxPosition(a.CenterPosition); var bounds = a.Bounds.Value; - var xy = pos + new float2(bounds.Left, bounds.Top); - var Xy = pos + new float2(bounds.Right, bounds.Top); - var xY = pos + new float2(bounds.Left, bounds.Bottom); - var XY = pos + new float2(bounds.Right, bounds.Bottom); + var tl = pos + new float2(bounds.Left, bounds.Top); + var tr = pos + new float2(bounds.Right, bounds.Top); + var bl = pos + new float2(bounds.Left, bounds.Bottom); + var br = pos + new float2(bounds.Right, bounds.Bottom); var wlr = Game.Renderer.WorldLineRenderer; - wlr.DrawLine(xy, xy + new float2(4, 0), c, c); - wlr.DrawLine(xy, xy + new float2(0, 4), c, c); - wlr.DrawLine(Xy, Xy + new float2(-4, 0), c, c); - wlr.DrawLine(Xy, Xy + new float2(0, 4), c, c); + wlr.DrawLine(tl, tl + new float2(4, 0), c, c); + wlr.DrawLine(tl, tl + new float2(0, 4), c, c); + wlr.DrawLine(tr, tr + new float2(-4, 0), c, c); + wlr.DrawLine(tr, tr + new float2(0, 4), c, c); - wlr.DrawLine(xY, xY + new float2(4, 0), c, c); - wlr.DrawLine(xY, xY + new float2(0, -4), c, c); - wlr.DrawLine(XY, XY + new float2(-4, 0), c, c); - wlr.DrawLine(XY, XY + new float2(0, -4), c, c); + wlr.DrawLine(bl, bl + new float2(4, 0), c, c); + wlr.DrawLine(bl, bl + new float2(0, -4), c, c); + wlr.DrawLine(br, br + new float2(-4, 0), c, c); + wlr.DrawLine(br, br + new float2(0, -4), c, c); } public void DrawRollover(Actor unit) @@ -192,9 +192,10 @@ namespace OpenRA.Graphics public void DrawRangeCircleWithContrast(Color fg, float2 location, float range, Color bg, int offset) { - if (offset > 0) { - DrawRangeCircle(bg, location, range + (float) offset/Game.CellSize); - DrawRangeCircle(bg, location, range - (float) offset/Game.CellSize); + if (offset > 0) + { + DrawRangeCircle(bg, location, range + (float)offset / Game.CellSize); + DrawRangeCircle(bg, location, range - (float)offset / Game.CellSize); } DrawRangeCircle(fg, location, range); @@ -209,8 +210,8 @@ namespace OpenRA.Graphics // Conversion between world and screen coordinates public float2 ScreenPosition(WPos pos) { - var c = Game.CellSize/1024f; - return new float2(c*pos.X, c*(pos.Y - pos.Z)); + var c = Game.CellSize / 1024f; + return new float2(c * pos.X, c * (pos.Y - pos.Z)); } public int2 ScreenPxPosition(WPos pos) @@ -223,8 +224,8 @@ namespace OpenRA.Graphics // For scaling vectors to pixel sizes in the voxel renderer public float[] ScreenVector(WVec vec) { - var c = Game.CellSize/1024f; - return new float[] {c*vec.X, c*vec.Y, c*vec.Z, 1}; + var c = Game.CellSize / 1024f; + return new float[] { c * vec.X, c * vec.Y, c * vec.Z, 1 }; } public int2 ScreenPxOffset(WVec vec) @@ -234,7 +235,10 @@ namespace OpenRA.Graphics return new int2((int)Math.Round(px[0]), (int)Math.Round(px[1] - px[2])); } - public float ScreenZPosition(WPos pos, int zOffset) { return (pos.Y + pos.Z + zOffset)*Game.CellSize/1024f; } + public float ScreenZPosition(WPos pos, int offset) + { + return (pos.Y + pos.Z + offset) * Game.CellSize / 1024f; + } public WPos Position(int2 screenPx) { From 8241718d0106e77df83519e8e42de5835657c467 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 29 Sep 2013 21:28:49 +1300 Subject: [PATCH 19/19] Fix double-rendering regression. --- OpenRA.Game/Traits/World/ScreenMap.cs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 283440b8e9..ca38c8cf26 100755 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -139,18 +139,14 @@ namespace OpenRA.Traits var top = (r.Top / info.BinSize).Clamp(0, rows - 1); var bottom = (r.Bottom / info.BinSize).Clamp(0, rows - 1); + var actorsInBox = new List(); for (var j = top; j <= bottom; j++) - { for (var i = left; i <= right; i++) - { - var ret = actors[j * cols + i] + actorsInBox.AddRange(actors[j * cols + i] .Where(kv => kv.Key.IsInWorld && kv.Value.IntersectsWith(r)) - .Select(kv => kv.Key); + .Select(kv => kv.Key)); - foreach (var a in ret) - yield return a; - } - } + return actorsInBox.Distinct(); } } }