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:
@@ -29,7 +29,7 @@ namespace OpenRA.Graphics
|
||||
public readonly int ShadowZOffset;
|
||||
public readonly int[] Frames;
|
||||
|
||||
public Sequence(SpriteLoader loader, string unit, string name, MiniYaml info)
|
||||
public Sequence(SpriteCache cache, string unit, string name, MiniYaml info)
|
||||
{
|
||||
var srcOverride = info.Value;
|
||||
Name = name;
|
||||
@@ -50,7 +50,7 @@ namespace OpenRA.Graphics
|
||||
|
||||
// Apply offset to each sprite in the sequence
|
||||
// Different sequences may apply different offsets to the same frame
|
||||
sprites = loader.LoadAllSprites(srcOverride ?? unit).Select(
|
||||
sprites = cache[srcOverride ?? unit].Select(
|
||||
s => new Sprite(s.sheet, s.bounds, s.offset + offset, s.channel, blendMode)).ToArray();
|
||||
|
||||
if (!d.ContainsKey("Length"))
|
||||
|
||||
Reference in New Issue
Block a user