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.
Method is now called ToDictionary.
- Cached a few invocations into locals which should prevent some redundant evaluation.
- Added ToDictionary overloads that take projection functions for the keys and elements, since several callsites were doing a subsequent Linq.ToDictionary call to get this.
This allows you to use just some of the frames of an animation
which has multiple facings.
For example, if you have an animation which has 8 facings, and 6 frames
of animation per facing, but you only want to show 3 of them, you can now do:
Facings: 8
Length: 3 # the number of frames in each facing to actually use
Stride: 6 # the number of frames per facing present in the SHP
If Stride is not specified, it defaults to Length, which is the old behavior.
It is an error to specify a stride less than the length -- this would produce
overlapping facings, or weirder.