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.
This commit is contained in:
RoosterDragon
2014-10-14 20:04:56 +01:00
parent 2a15c44d91
commit d671e1de01
9 changed files with 45 additions and 40 deletions

View File

@@ -21,12 +21,12 @@ namespace OpenRA.Graphics
public class SequenceProvider
{
readonly Lazy<Sequences> sequences;
public readonly SpriteLoader SpriteLoader;
public readonly SpriteCache SpriteCache;
public SequenceProvider(SequenceCache cache, Map map)
{
this.sequences = Exts.Lazy(() => cache.LoadSequences(map));
this.SpriteLoader = cache.SpriteLoader;
this.SpriteCache = cache.SpriteCache;
}
public Sequence GetSequence(string unitName, string sequenceName)
@@ -70,8 +70,8 @@ namespace OpenRA.Graphics
public class SequenceCache
{
readonly ModData modData;
readonly Lazy<SpriteLoader> spriteLoader;
public SpriteLoader SpriteLoader { get { return spriteLoader.Value; } }
readonly Lazy<SpriteCache> spriteCache;
public SpriteCache SpriteCache { get { return spriteCache.Value; } }
readonly Dictionary<string, UnitSequences> sequenceCache = new Dictionary<string, UnitSequences>();
@@ -79,7 +79,7 @@ namespace OpenRA.Graphics
{
this.modData = modData;
spriteLoader = Exts.Lazy(() => new SpriteLoader(modData.SpriteLoaders, tileSet.Extensions, new SheetBuilder(SheetType.Indexed)));
spriteCache = Exts.Lazy(() => new SpriteCache(modData.SpriteLoaders, tileSet.Extensions, new SheetBuilder(SheetType.Indexed)));
}
public Sequences LoadSequences(Map map)
@@ -128,7 +128,7 @@ namespace OpenRA.Graphics
{
try
{
unitSequences.Add(kvp.Key, new Sequence(spriteLoader.Value, node.Key, kvp.Key, kvp.Value));
unitSequences.Add(kvp.Key, new Sequence(spriteCache.Value, node.Key, kvp.Key, kvp.Value));
}
catch (FileNotFoundException ex)
{