From d3783f024438ca325a0cd1d973c5d826e68ca2f3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 8 Mar 2015 18:57:12 +0000 Subject: [PATCH] Introduce ISpriteSequence interface. --- OpenRA.Game/Graphics/Animation.cs | 4 +- OpenRA.Game/Graphics/Sequence.cs | 40 ++++++++++++++----- OpenRA.Game/Graphics/SequenceProvider.cs | 14 +++---- OpenRA.Mods.RA/Graphics/TeslaZapRenderable.cs | 4 +- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/OpenRA.Game/Graphics/Animation.cs b/OpenRA.Game/Graphics/Animation.cs index 135d2a4e29..fcd3325bea 100644 --- a/OpenRA.Game/Graphics/Animation.cs +++ b/OpenRA.Game/Graphics/Animation.cs @@ -16,7 +16,7 @@ namespace OpenRA.Graphics public class Animation { readonly int defaultTick = 40; // 25 fps == 40 ms - public Sequence CurrentSequence { get; private set; } + public ISpriteSequence CurrentSequence { get; private set; } public bool IsDecoration = false; public Func Paused; @@ -177,7 +177,7 @@ namespace OpenRA.Graphics } } - public Sequence GetSequence(string sequenceName) + public ISpriteSequence GetSequence(string sequenceName) { return sequenceProvider.GetSequence(name, sequenceName); } diff --git a/OpenRA.Game/Graphics/Sequence.cs b/OpenRA.Game/Graphics/Sequence.cs index 916af8dbac..5eb52fa56d 100644 --- a/OpenRA.Game/Graphics/Sequence.cs +++ b/OpenRA.Game/Graphics/Sequence.cs @@ -13,21 +13,39 @@ using System.Linq; namespace OpenRA.Graphics { - public class Sequence + public interface ISpriteSequence + { + string Name { get; } + int Start { get; } + int Length { get; } + int Stride { get; } + int Facings { get; } + int Tick { get; } + int ZOffset { get; } + int ShadowStart { get; } + int ShadowZOffset { get; } + int[] Frames { get; } + + Sprite GetSprite(int frame); + Sprite GetSprite(int frame, int facing); + Sprite GetShadow(int frame, int facing); + } + + public class Sequence : ISpriteSequence { readonly Sprite[] sprites; readonly bool reverseFacings, transpose; - public readonly string Name; - public readonly int Start; - public readonly int Length; - public readonly int Stride; - public readonly int Facings; - public readonly int Tick; - public readonly int ZOffset; - public readonly int ShadowStart; - public readonly int ShadowZOffset; - public readonly int[] Frames; + public string Name { get; private set; } + public int Start { get; private set; } + public int Length { get; private set; } + public int Stride { get; private set; } + public int Facings { get; private set; } + public int Tick { get; private set; } + public int ZOffset { get; private set; } + public int ShadowStart { get; private set; } + public int ShadowZOffset { get; private set; } + public int[] Frames { get; private set; } public Sequence(SpriteCache cache, string unit, string name, MiniYaml info) { diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index 075d2cdd3e..8342f916cd 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -15,8 +15,8 @@ using System.Linq; namespace OpenRA.Graphics { - using Sequences = IReadOnlyDictionary>>; - using UnitSequences = Lazy>; + using Sequences = IReadOnlyDictionary>>; + using UnitSequences = Lazy>; public class SequenceProvider { @@ -29,13 +29,13 @@ namespace OpenRA.Graphics this.SpriteCache = cache.SpriteCache; } - public Sequence GetSequence(string unitName, string sequenceName) + public ISpriteSequence GetSequence(string unitName, string sequenceName) { UnitSequences unitSeq; if (!sequences.Value.TryGetValue(unitName, out unitSeq)) throw new InvalidOperationException("Unit `{0}` does not have any sequences defined.".F(unitName)); - Sequence seq; + ISpriteSequence seq; if (!unitSeq.Value.TryGetValue(sequenceName, out seq)) throw new InvalidOperationException("Unit `{0}` does not have a sequence named `{1}`".F(unitName, sequenceName)); @@ -125,9 +125,9 @@ namespace OpenRA.Graphics return new ReadOnlyDictionary(items); } - IReadOnlyDictionary CreateUnitSequences(MiniYamlNode node) + IReadOnlyDictionary CreateUnitSequences(MiniYamlNode node) { - var unitSequences = new Dictionary(); + var unitSequences = new Dictionary(); foreach (var kvp in node.Value.ToDictionary()) { @@ -144,7 +144,7 @@ namespace OpenRA.Graphics } } - return new ReadOnlyDictionary(unitSequences); + return new ReadOnlyDictionary(unitSequences); } public void Dispose() diff --git a/OpenRA.Mods.RA/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.RA/Graphics/TeslaZapRenderable.cs index 28d25da0ef..194536cf4f 100644 --- a/OpenRA.Mods.RA/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.RA/Graphics/TeslaZapRenderable.cs @@ -94,7 +94,7 @@ namespace OpenRA.Mods.RA.Graphics yield return z; } - static IEnumerable DrawZapWandering(WorldRenderer wr, float2 from, float2 to, Sequence s, string pal) + static IEnumerable DrawZapWandering(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, string pal) { var z = float2.Zero; /* hack */ var dist = to - from; @@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA.Graphics return renderables; } - static IEnumerable DrawZap(WorldRenderer wr, float2 from, float2 to, Sequence s, out float2 p, string palette) + static IEnumerable DrawZap(WorldRenderer wr, float2 from, float2 to, ISpriteSequence s, out float2 p, string palette) { var dist = to - from; var q = new float2(-dist.Y, dist.X);