From 72a99544917a367e167961dae309ec2734e2a860 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 25 Feb 2013 18:03:44 +1300 Subject: [PATCH] Simplify PaletteReference interface. --- OpenRA.Game/Graphics/ShroudRenderer.cs | 6 ++-- OpenRA.Game/Graphics/WorldRenderer.cs | 28 ++++--------------- .../Orders/PlaceBuildingOrderGenerator.cs | 2 +- .../SupportPowers/ChronoshiftPower.cs | 2 +- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/OpenRA.Game/Graphics/ShroudRenderer.cs b/OpenRA.Game/Graphics/ShroudRenderer.cs index 466e90da2d..4d467b67dd 100644 --- a/OpenRA.Game/Graphics/ShroudRenderer.cs +++ b/OpenRA.Game/Graphics/ShroudRenderer.cs @@ -149,14 +149,14 @@ namespace OpenRA.Graphics { s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - pal.RowIndex(wr), + pal.Index, new float2(Game.CellSize * (i - starti), Game.CellSize)); starti = i + 1; } s[i, j].DrawAt( Game.CellSize * new float2(i, j), - pal.RowIndex(wr)); + pal.Index); starti = i + 1; last = s[i, j]; } @@ -164,7 +164,7 @@ namespace OpenRA.Graphics if (starti < clip.Right) s[starti, j].DrawAt( Game.CellSize * new float2(starti, j), - pal.RowIndex(wr), + pal.Index, new float2(Game.CellSize * (clip.Right - starti), Game.CellSize)); } } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index fb66548ffd..ff2e750a0b 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -19,28 +19,12 @@ namespace OpenRA.Graphics { public class PaletteReference { - string name; - int index; + public readonly string Name; + public readonly int Index; public PaletteReference(string name, int index) { - this.name = name; - this.index = index; - } - - public static PaletteReference FromName(string name) - { - return new PaletteReference(name, -1); - } - - public int RowIndex(WorldRenderer wr) - { - if (index == -1) - { - // Too spammy to enable by default - //Log.Write("perf", "Late resolution of palette reference {0}", name); - index = wr.GetPaletteIndex(name); - } - return index; + Name = name; + Index = index; } } @@ -113,7 +97,7 @@ namespace OpenRA.Graphics terrainRenderer.Draw(this, Game.viewport); foreach (var a in world.traitDict.ActorsWithTraitMultiple(world)) foreach (var r in a.Trait.RenderAsTerrain(this, a.Actor)) - r.Sprite.DrawAt(r.Pos, r.Palette.RowIndex(this), r.Scale); + r.Sprite.DrawAt(r.Pos, r.Palette.Index, r.Scale); foreach (var a in world.Selection.Actors) if (!a.Destroyed) @@ -126,7 +110,7 @@ namespace OpenRA.Graphics world.OrderGenerator.RenderBeforeWorld(this, world); foreach (var image in SpritesToRender()) - image.Sprite.DrawAt(image.Pos, image.Palette.RowIndex(this), image.Scale); + image.Sprite.DrawAt(image.Pos, image.Palette.Index, image.Scale); // added for contrails foreach (var a in world.ActorsWithTrait()) diff --git a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs index 5dde8116ac..d630adba81 100755 --- a/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs +++ b/OpenRA.Mods.RA/Orders/PlaceBuildingOrderGenerator.cs @@ -99,7 +99,7 @@ namespace OpenRA.Mods.RA.Orders foreach (var r in preview) r.Sprite.DrawAt(topLeft.ToPPos().ToFloat2() + r.Pos, - r.Palette.RowIndex(wr), + r.Palette.Index, r.Scale*r.Sprite.size); var res = world.WorldActor.Trait(); diff --git a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs index 5875c93a51..b4459b961b 100755 --- a/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs +++ b/OpenRA.Mods.RA/SupportPowers/ChronoshiftPower.cs @@ -245,7 +245,7 @@ namespace OpenRA.Mods.RA var targetCell = unit.Location + (xy - sourceLocation); foreach (var r in unit.Render(wr)) r.Sprite.DrawAt(r.Pos - Traits.Util.CenterOfCell(unit.Location).ToFloat2() + Traits.Util.CenterOfCell(targetCell).ToFloat2(), - r.Palette.RowIndex(wr), + r.Palette.Index, r.Scale*r.Sprite.size); } }