Move Renderable into its own file.
This commit is contained in:
53
OpenRA.Game/Graphics/Renderable.cs
Normal file
53
OpenRA.Game/Graphics/Renderable.cs
Normal file
@@ -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<Renderable>
|
||||||
|
{
|
||||||
|
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); }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -65,18 +65,10 @@ namespace OpenRA.Graphics
|
|||||||
public PaletteReference Palette(string name) { return palettes[name]; }
|
public PaletteReference Palette(string name) { return palettes[name]; }
|
||||||
public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); }
|
public void AddPalette(string name, Palette pal, bool allowModifiers) { palette.AddPalette(name, pal, allowModifiers); }
|
||||||
|
|
||||||
class SpriteComparer : IComparer<Renderable>
|
|
||||||
{
|
|
||||||
public int Compare(Renderable x, Renderable y)
|
|
||||||
{
|
|
||||||
return (x.Z + x.ZOffset).CompareTo(y.Z + y.ZOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerable<Renderable> SpritesToRender()
|
IEnumerable<Renderable> SpritesToRender()
|
||||||
{
|
{
|
||||||
var bounds = Game.viewport.WorldBounds(world);
|
var bounds = Game.viewport.WorldBounds(world);
|
||||||
var comparer = new SpriteComparer();
|
var comparer = new RenderableComparer();
|
||||||
|
|
||||||
var actors = world.FindUnits(
|
var actors = world.FindUnits(
|
||||||
bounds.TopLeftAsCPos().ToPPos(),
|
bounds.TopLeftAsCPos().ToPPos(),
|
||||||
|
|||||||
@@ -224,6 +224,7 @@
|
|||||||
<Compile Include="Traits\DebugPauseState.cs" />
|
<Compile Include="Traits\DebugPauseState.cs" />
|
||||||
<Compile Include="Network\UPnP.cs" />
|
<Compile Include="Network\UPnP.cs" />
|
||||||
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
|
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
|
||||||
|
<Compile Include="Graphics\Renderable.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -152,37 +152,6 @@ namespace OpenRA.Traits
|
|||||||
bool CrushableBy(string[] crushClasses, Player owner);
|
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 interface ITraitInfo { object Create(ActorInitializer init); }
|
||||||
|
|
||||||
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
|
public class TraitInfo<T> : ITraitInfo where T : new() { public virtual object Create(ActorInitializer init) { return new T(); } }
|
||||||
|
|||||||
Reference in New Issue
Block a user