Disable now-invalid sequence caching.
This commit is contained in:
@@ -18,7 +18,7 @@ using OpenRA.Support;
|
|||||||
|
|
||||||
namespace OpenRA
|
namespace OpenRA
|
||||||
{
|
{
|
||||||
public sealed class RulesetCache : IDisposable
|
public sealed class RulesetCache
|
||||||
{
|
{
|
||||||
static readonly List<MiniYamlNode> NoMapRules = new List<MiniYamlNode>();
|
static readonly List<MiniYamlNode> NoMapRules = new List<MiniYamlNode>();
|
||||||
|
|
||||||
@@ -30,7 +30,6 @@ namespace OpenRA
|
|||||||
readonly Dictionary<string, SoundInfo> notificationCache = new Dictionary<string, SoundInfo>();
|
readonly Dictionary<string, SoundInfo> notificationCache = new Dictionary<string, SoundInfo>();
|
||||||
readonly Dictionary<string, MusicInfo> musicCache = new Dictionary<string, MusicInfo>();
|
readonly Dictionary<string, MusicInfo> musicCache = new Dictionary<string, MusicInfo>();
|
||||||
readonly Dictionary<string, TileSet> tileSetCache = new Dictionary<string, TileSet>();
|
readonly Dictionary<string, TileSet> tileSetCache = new Dictionary<string, TileSet>();
|
||||||
readonly Dictionary<string, SequenceCache> sequenceCaches = new Dictionary<string, SequenceCache>();
|
|
||||||
|
|
||||||
public event EventHandler LoadingProgress;
|
public event EventHandler LoadingProgress;
|
||||||
void RaiseProgress()
|
void RaiseProgress()
|
||||||
@@ -85,9 +84,10 @@ namespace OpenRA
|
|||||||
k => new MusicInfo(k.Key, k.Value));
|
k => new MusicInfo(k.Key, k.Value));
|
||||||
|
|
||||||
using (new PerfTimer("TileSets"))
|
using (new PerfTimer("TileSets"))
|
||||||
tileSets = LoadTileSets(fileSystem, tileSetCache, sequenceCaches, m.TileSets);
|
tileSets = LoadTileSets(fileSystem, tileSetCache, m.TileSets);
|
||||||
|
|
||||||
var sequences = sequenceCaches.ToDictionary(kvp => kvp.Key, kvp => new SequenceProvider(fileSystem, kvp.Value, map));
|
// TODO: only initialize, and then cache, the provider for the given map
|
||||||
|
var sequences = tileSets.ToDictionary(t => t.Key, t => new SequenceProvider(fileSystem, modData, t.Value, map));
|
||||||
return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences);
|
return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,8 +122,7 @@ namespace OpenRA
|
|||||||
return itemSet;
|
return itemSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, TileSet> LoadTileSets(IReadOnlyFileSystem fileSystem, Dictionary<string, TileSet> itemCache,
|
Dictionary<string, TileSet> LoadTileSets(IReadOnlyFileSystem fileSystem, Dictionary<string, TileSet> itemCache, string[] files)
|
||||||
Dictionary<string, SequenceCache> sequenceCaches, string[] files)
|
|
||||||
{
|
{
|
||||||
var items = new Dictionary<string, TileSet>();
|
var items = new Dictionary<string, TileSet>();
|
||||||
|
|
||||||
@@ -136,23 +135,11 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
t = new TileSet(fileSystem, file);
|
t = new TileSet(fileSystem, file);
|
||||||
itemCache.Add(file, t);
|
itemCache.Add(file, t);
|
||||||
|
|
||||||
// every time we load a tile set, we create a sequence cache for it
|
|
||||||
var sc = new SequenceCache(modData, fileSystem, t);
|
|
||||||
sequenceCaches.Add(t.Id, sc);
|
|
||||||
|
|
||||||
items.Add(t.Id, t);
|
items.Add(t.Id, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
foreach (var cache in sequenceCaches.Values)
|
|
||||||
cache.Dispose();
|
|
||||||
sequenceCaches.Clear();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,15 +42,22 @@ namespace OpenRA.Graphics
|
|||||||
IReadOnlyDictionary<string, ISpriteSequence> ParseSequences(ModData modData, TileSet tileSet, SpriteCache cache, MiniYamlNode node);
|
IReadOnlyDictionary<string, ISpriteSequence> ParseSequences(ModData modData, TileSet tileSet, SpriteCache cache, MiniYamlNode node);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SequenceProvider
|
public class SequenceProvider : IDisposable
|
||||||
{
|
{
|
||||||
|
readonly ModData modData;
|
||||||
|
readonly TileSet tileSet;
|
||||||
readonly Lazy<Sequences> sequences;
|
readonly Lazy<Sequences> sequences;
|
||||||
public readonly SpriteCache SpriteCache;
|
readonly Lazy<SpriteCache> spriteCache;
|
||||||
|
public SpriteCache SpriteCache { get { return spriteCache.Value; } }
|
||||||
|
|
||||||
public SequenceProvider(IReadOnlyFileSystem fileSystem, SequenceCache cache, Map map)
|
readonly Dictionary<string, UnitSequences> sequenceCache = new Dictionary<string, UnitSequences>();
|
||||||
|
|
||||||
|
public SequenceProvider(IReadOnlyFileSystem fileSystem, ModData modData, TileSet tileSet, Map map)
|
||||||
{
|
{
|
||||||
sequences = Exts.Lazy(() => cache.LoadSequences(fileSystem, map));
|
this.modData = modData;
|
||||||
SpriteCache = cache.SpriteCache;
|
this.tileSet = tileSet;
|
||||||
|
sequences = Exts.Lazy(() => LoadSequences(fileSystem, map));
|
||||||
|
spriteCache = Exts.Lazy(() => new SpriteCache(fileSystem, modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISpriteSequence GetSequence(string unitName, string sequenceName)
|
public ISpriteSequence GetSequence(string unitName, string sequenceName)
|
||||||
@@ -89,33 +96,6 @@ namespace OpenRA.Graphics
|
|||||||
return unitSeq.Value.Keys;
|
return unitSeq.Value.Keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Preload()
|
|
||||||
{
|
|
||||||
SpriteCache.SheetBuilder.Current.CreateBuffer();
|
|
||||||
foreach (var unitSeq in sequences.Value.Values)
|
|
||||||
foreach (var seq in unitSeq.Value.Values) { }
|
|
||||||
SpriteCache.SheetBuilder.Current.ReleaseBuffer();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class SequenceCache : IDisposable
|
|
||||||
{
|
|
||||||
readonly ModData modData;
|
|
||||||
readonly TileSet tileSet;
|
|
||||||
readonly Lazy<SpriteCache> spriteCache;
|
|
||||||
public SpriteCache SpriteCache { get { return spriteCache.Value; } }
|
|
||||||
|
|
||||||
readonly Dictionary<string, UnitSequences> sequenceCache = new Dictionary<string, UnitSequences>();
|
|
||||||
|
|
||||||
public SequenceCache(ModData modData, IReadOnlyFileSystem fileSystem, TileSet tileSet)
|
|
||||||
{
|
|
||||||
this.modData = modData;
|
|
||||||
this.tileSet = tileSet;
|
|
||||||
|
|
||||||
// Every time we load a tile set, we create a sequence cache for it
|
|
||||||
spriteCache = Exts.Lazy(() => new SpriteCache(fileSystem, modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Sequences LoadSequences(IReadOnlyFileSystem fileSystem, Map map)
|
public Sequences LoadSequences(IReadOnlyFileSystem fileSystem, Map map)
|
||||||
{
|
{
|
||||||
using (new Support.PerfTimer("LoadSequences"))
|
using (new Support.PerfTimer("LoadSequences"))
|
||||||
@@ -150,6 +130,14 @@ namespace OpenRA.Graphics
|
|||||||
return new ReadOnlyDictionary<string, UnitSequences>(items);
|
return new ReadOnlyDictionary<string, UnitSequences>(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Preload()
|
||||||
|
{
|
||||||
|
SpriteCache.SheetBuilder.Current.CreateBuffer();
|
||||||
|
foreach (var unitSeq in sequences.Value.Values)
|
||||||
|
foreach (var seq in unitSeq.Value.Values) { }
|
||||||
|
SpriteCache.SheetBuilder.Current.ReleaseBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (spriteCache.IsValueCreated)
|
if (spriteCache.IsValueCreated)
|
||||||
|
|||||||
@@ -192,7 +192,6 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
if (LoadScreen != null)
|
if (LoadScreen != null)
|
||||||
LoadScreen.Dispose();
|
LoadScreen.Dispose();
|
||||||
RulesetCache.Dispose();
|
|
||||||
MapCache.Dispose();
|
MapCache.Dispose();
|
||||||
if (VoxelLoader != null)
|
if (VoxelLoader != null)
|
||||||
VoxelLoader.Dispose();
|
VoxelLoader.Dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user