diff --git a/OpenRA.Game/Graphics/Renderable.cs b/OpenRA.Game/Graphics/Renderable.cs new file mode 100644 index 0000000000..97adc81611 --- /dev/null +++ b/OpenRA.Game/Graphics/Renderable.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright 2007-2013 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.Collections.Generic; + +namespace OpenRA.Graphics +{ + public class RenderableComparer : IComparer + { + public int Compare(Renderable x, Renderable y) + { + return (x.Z + x.ZOffset).CompareTo(y.Z + y.ZOffset); + } + } + + public struct Renderable + { + public readonly Sprite Sprite; + public readonly float2 Pos; + public readonly PaletteReference Palette; + public readonly int Z; + public readonly int ZOffset; + public float Scale; + + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, int zOffset, float scale) + { + Sprite = sprite; + Pos = pos; + Palette = palette; + Z = z; + ZOffset = zOffset; + Scale = scale; + } + + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z) + : this(sprite, pos, palette, z, 0, 1f) { } + + public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, float scale) + : this(sprite, pos, palette, z, 0, scale) { } + + public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } + public Renderable WithPalette(PaletteReference newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } + public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } + public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } + } +} diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index b3dd017af4..6dd39fb3c3 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -65,18 +65,10 @@ namespace OpenRA.Graphics public PaletteReference Palette(string name) { return palettes[name]; } public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); } - class SpriteComparer : IComparer - { - public int Compare(Renderable x, Renderable y) - { - return (x.Z + x.ZOffset).CompareTo(y.Z + y.ZOffset); - } - } - IEnumerable SpritesToRender() { var bounds = Game.viewport.WorldBounds(world); - var comparer = new SpriteComparer(); + var comparer = new RenderableComparer(); var actors = world.FindUnits( bounds.TopLeftAsCPos().ToPPos(), diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index a6f99c8a59..29cf8054bf 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -224,6 +224,7 @@ + diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 30d6c152d2..6b94417d81 100755 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -152,37 +152,6 @@ namespace OpenRA.Traits bool CrushableBy(string[] crushClasses, Player owner); } - public struct Renderable - { - public readonly Sprite Sprite; - public readonly float2 Pos; - public readonly PaletteReference Palette; - public readonly int Z; - public readonly int ZOffset; - public float Scale; - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, int zOffset, float scale) - { - Sprite = sprite; - Pos = pos; - Palette = palette; - Z = z; - ZOffset = zOffset; - Scale = scale; /* default */ - } - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z) - : this(sprite, pos, palette, z, 0, 1f) { } - - public Renderable(Sprite sprite, float2 pos, PaletteReference palette, int z, float scale) - : this(sprite, pos, palette, z, 0, scale) { } - - public Renderable WithScale(float newScale) { return new Renderable(Sprite, Pos, Palette, Z, ZOffset, newScale); } - public Renderable WithPalette(PaletteReference newPalette) { return new Renderable(Sprite, Pos, newPalette, Z, ZOffset, Scale); } - public Renderable WithZOffset(int newOffset) { return new Renderable(Sprite, Pos, Palette, Z, newOffset, Scale); } - public Renderable WithPos(float2 newPos) { return new Renderable(Sprite, newPos, Palette, Z, ZOffset, Scale); } - } - public interface ITraitInfo { object Create(ActorInitializer init); } public class TraitInfo : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }