Files
OpenRA/OpenRA.Game/Graphics/CursorSequence.cs
RoosterDragon d671e1de01 Create a separate FrameCache for caching sprite frames.
We split the caching SpriteLoader into a SpriteCache and FrameCache. SpriteLoader instead becomes a holder for static loading methods.

Only a few classes loaded sprite frames, and they all use it with a transient cache. By moving this method into a new class, we can lose the now redundant frame cache, saving on memory significantly since the frame data array can be reclaimed by the GC. This saves ~58 MiB on frames and ~4 MiB on the caching dictionary in simple tests.
2014-10-14 22:06:11 +01:00

55 lines
1.6 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2014 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
namespace OpenRA.Graphics
{
public class CursorSequence
{
readonly int start, length;
readonly string palette;
public int Start { get { return start; } }
public int End { get { return start + length; } }
public int Length { get { return length; } }
public string Palette { get { return palette; } }
public readonly int2 Hotspot;
Sprite[] sprites;
public CursorSequence(SpriteCache cache, string cursorSrc, string palette, MiniYaml info)
{
sprites = cache[cursorSrc];
var d = info.ToDictionary();
start = Exts.ParseIntegerInvariant(d["start"].Value);
this.palette = palette;
if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*"))
length = sprites.Length - start;
else if (d.ContainsKey("length"))
length = Exts.ParseIntegerInvariant(d["length"].Value);
else if (d.ContainsKey("end"))
length = Exts.ParseIntegerInvariant(d["end"].Value) - start;
else
length = 1;
if (d.ContainsKey("x"))
Exts.TryParseIntegerInvariant(d["x"].Value, out Hotspot.X);
if (d.ContainsKey("y"))
Exts.TryParseIntegerInvariant(d["y"].Value, out Hotspot.Y);
}
public Sprite GetSprite(int frame)
{
return sprites[(frame % length) + start];
}
}
}