Remove TileSetData and separate TileSet from Sequences
This commit is contained in:
@@ -13,6 +13,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Support;
|
||||
|
||||
namespace OpenRA
|
||||
@@ -28,6 +29,7 @@ namespace OpenRA
|
||||
readonly Dictionary<string, MusicInfo> musicCache = new Dictionary<string, MusicInfo>();
|
||||
readonly Dictionary<string, string> movieCache = new Dictionary<string, string>();
|
||||
readonly Dictionary<string, TileSet> tileSetCache = new Dictionary<string, TileSet>();
|
||||
readonly Dictionary<string, SequenceCache> sequenceCaches = new Dictionary<string, SequenceCache>();
|
||||
|
||||
public Action OnProgress = () => { if (Game.modData != null && Game.modData.LoadScreen != null) Game.modData.LoadScreen.Display(); };
|
||||
|
||||
@@ -73,10 +75,12 @@ namespace OpenRA
|
||||
movies = LoadYamlRules(movieCache, m.Movies, new List<MiniYamlNode>(), (k, v) => k.Value.Value);
|
||||
OnProgress();
|
||||
using (new PerfTimer("TileSets"))
|
||||
tileSets = LoadTileSets(tileSetCache, m.TileSets);
|
||||
tileSets = LoadTileSets(tileSetCache, sequenceCaches, m.TileSets);
|
||||
|
||||
var sequences = sequenceCaches.ToDictionary((kvp) => kvp.Key, (kvp) => new SequenceProvider(kvp.Value, map));
|
||||
|
||||
OnProgress();
|
||||
return new Ruleset(actors, weapons, voices, notifications, music, movies, tileSets);
|
||||
return new Ruleset(actors, weapons, voices, notifications, music, movies, tileSets, sequences);
|
||||
}
|
||||
|
||||
Dictionary<string, T> LoadYamlRules<T>(
|
||||
@@ -108,7 +112,7 @@ namespace OpenRA
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
Dictionary<string, TileSet> LoadTileSets(Dictionary<string, TileSet> itemCache, string[] files)
|
||||
Dictionary<string, TileSet> LoadTileSets(Dictionary<string, TileSet> itemCache, Dictionary<string, SequenceCache> sequenceCaches, string[] files)
|
||||
{
|
||||
var items = new Dictionary<string, TileSet>();
|
||||
|
||||
@@ -124,6 +128,10 @@ namespace OpenRA
|
||||
t = new TileSet(modData, file);
|
||||
itemCache.Add(file, t);
|
||||
|
||||
// every time we load a tile set, we create a sequence cache for it
|
||||
var sc = new SequenceCache(modData, t);
|
||||
sequenceCaches.Add(t.Id, sc);
|
||||
|
||||
items.Add(t.Id, t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,10 +20,12 @@ namespace OpenRA.Graphics
|
||||
public class SequenceProvider
|
||||
{
|
||||
readonly Lazy<IReadOnlyDictionary<string, Lazy<IReadOnlyDictionary<string, Sequence>>>> sequences;
|
||||
public readonly SpriteLoader SpriteLoader;
|
||||
|
||||
public SequenceProvider(Map map)
|
||||
public SequenceProvider(SequenceCache cache, Map map)
|
||||
{
|
||||
this.sequences = Exts.Lazy(() => map.Rules.TileSets[map.Tileset].Data.SequenceCache.LoadSequences(map));
|
||||
this.sequences = Exts.Lazy(() => cache.LoadSequences(map));
|
||||
this.SpriteLoader = cache.SpriteLoader;
|
||||
}
|
||||
|
||||
public Sequence GetSequence(string unitName, string sequenceName)
|
||||
@@ -61,7 +63,8 @@ namespace OpenRA.Graphics
|
||||
public class SequenceCache
|
||||
{
|
||||
readonly ModData modData;
|
||||
readonly TileSet tileSet;
|
||||
readonly Lazy<SpriteLoader> spriteLoader;
|
||||
public SpriteLoader SpriteLoader { get { return spriteLoader.Value; } }
|
||||
|
||||
readonly Dictionary<string, Lazy<IReadOnlyDictionary<string, Sequence>>> sequenceCache = new Dictionary<string, Lazy<IReadOnlyDictionary<string, Sequence>>>();
|
||||
|
||||
@@ -70,7 +73,8 @@ namespace OpenRA.Graphics
|
||||
public SequenceCache(ModData modData, TileSet tileSet)
|
||||
{
|
||||
this.modData = modData;
|
||||
this.tileSet = tileSet;
|
||||
|
||||
spriteLoader = Exts.Lazy(() => new SpriteLoader(tileSet.Extensions, new SheetBuilder(SheetType.Indexed)));
|
||||
}
|
||||
|
||||
public IReadOnlyDictionary<string, Lazy<IReadOnlyDictionary<string, Sequence>>> LoadSequences(Map map)
|
||||
@@ -103,7 +107,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
t = Exts.Lazy(() => (IReadOnlyDictionary<string, Sequence>)new ReadOnlyDictionary<string, Sequence>(
|
||||
node.Value.NodesDict.ToDictionary(x => x.Key, x =>
|
||||
new Sequence(tileSet.Data.SpriteLoader, node.Key, x.Key, x.Value))));
|
||||
new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value))));
|
||||
sequenceCache.Add(key, t);
|
||||
items.Add(node.Key, t);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace OpenRA
|
||||
|
||||
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
||||
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
||||
public SequenceProvider SequenceProvider { get; private set; }
|
||||
public SequenceProvider SequenceProvider { get { return Rules.Sequences[Tileset]; } }
|
||||
|
||||
public static Map FromTileset(TileSet tileset)
|
||||
{
|
||||
@@ -246,7 +246,6 @@ namespace OpenRA
|
||||
void PostInit()
|
||||
{
|
||||
rules = Exts.Lazy(() => Game.modData.RulesetCache.LoadMapRules(this));
|
||||
SequenceProvider = new SequenceProvider(this);
|
||||
}
|
||||
|
||||
public Ruleset PreloadRules()
|
||||
|
||||
@@ -12,6 +12,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
@@ -24,6 +25,7 @@ namespace OpenRA
|
||||
public readonly IReadOnlyDictionary<string, MusicInfo> Music;
|
||||
public readonly IReadOnlyDictionary<string, string> Movies;
|
||||
public readonly IReadOnlyDictionary<string, TileSet> TileSets;
|
||||
public readonly IReadOnlyDictionary<string, SequenceProvider> Sequences;
|
||||
|
||||
public Ruleset(
|
||||
IDictionary<string, ActorInfo> actors,
|
||||
@@ -32,7 +34,8 @@ namespace OpenRA
|
||||
IDictionary<string, SoundInfo> notifications,
|
||||
IDictionary<string, MusicInfo> music,
|
||||
IDictionary<string, string> movies,
|
||||
IDictionary<string, TileSet> tileSets)
|
||||
IDictionary<string, TileSet> tileSets,
|
||||
IDictionary<string, SequenceProvider> sequences)
|
||||
{
|
||||
this.Actors = new ReadOnlyDictionary<string, ActorInfo>(actors);
|
||||
this.Weapons = new ReadOnlyDictionary<string, WeaponInfo>(weapons);
|
||||
@@ -41,6 +44,7 @@ namespace OpenRA
|
||||
this.Music = new ReadOnlyDictionary<string, MusicInfo>(music);
|
||||
this.Movies = new ReadOnlyDictionary<string, string>(movies);
|
||||
this.TileSets = new ReadOnlyDictionary<string, TileSet>(tileSets);
|
||||
this.Sequences = new ReadOnlyDictionary<string, SequenceProvider>(sequences);
|
||||
}
|
||||
|
||||
public IEnumerable<KeyValuePair<string, MusicInfo>> InstalledMusic { get { return Music.Where(m => m.Value.Exists); } }
|
||||
|
||||
@@ -82,20 +82,6 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSetData
|
||||
{
|
||||
Lazy<SpriteLoader> spriteLoader;
|
||||
public SpriteLoader SpriteLoader { get { return spriteLoader.Value; } }
|
||||
|
||||
public readonly SequenceCache SequenceCache;
|
||||
|
||||
public TileSetData(ModData modData, TileSet tileSet)
|
||||
{
|
||||
spriteLoader = Exts.Lazy(() => new SpriteLoader(tileSet.Extensions, new SheetBuilder(SheetType.Indexed)));
|
||||
SequenceCache = new SequenceCache(modData, tileSet);
|
||||
}
|
||||
}
|
||||
|
||||
public class TileSet
|
||||
{
|
||||
public readonly string Name;
|
||||
@@ -111,9 +97,6 @@ namespace OpenRA
|
||||
|
||||
static readonly string[] Fields = { "Name", "Id", "SheetSize", "Palette", "Extensions" };
|
||||
|
||||
[FieldLoader.IgnoreAttribute]
|
||||
public readonly TileSetData Data;
|
||||
|
||||
public TileSet(ModData modData, string filepath)
|
||||
{
|
||||
var yaml = MiniYaml.DictFromFile(filepath);
|
||||
@@ -128,8 +111,6 @@ namespace OpenRA
|
||||
// Templates
|
||||
Templates = yaml["Templates"].NodesDict.Values
|
||||
.Select(y => new TileTemplate(y)).ToDictionary(t => t.Id);
|
||||
|
||||
Data = new TileSetData(modData, this);
|
||||
}
|
||||
|
||||
public TileSet(string name, string id, string palette, string[] extensions)
|
||||
|
||||
@@ -95,7 +95,7 @@ namespace OpenRA.Mods.RA
|
||||
{
|
||||
var ts = Game.modData.Manifest.TileSize;
|
||||
var data = Exts.MakeArray<byte>(ts.Width * ts.Height, _ => (byte)info.ShroudColor);
|
||||
var s = map.Rules.TileSets[map.Tileset].Data.SpriteLoader.SheetBuilder.Add(data, ts);
|
||||
var s = map.SequenceProvider.SpriteLoader.SheetBuilder.Add(data, ts);
|
||||
unexploredTile = new Sprite(s.sheet, s.bounds, s.offset, s.channel, info.ShroudBlend);
|
||||
}
|
||||
else
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
||||
return false;
|
||||
|
||||
currentFilename = filename;
|
||||
currentSprites = world.Map.Rules.TileSets[world.Map.Tileset].Data.SpriteLoader.LoadAllSprites(filename);
|
||||
currentSprites = world.Map.SequenceProvider.SpriteLoader.LoadAllSprites(filename);
|
||||
currentFrame = 0;
|
||||
frameSlider.MaximumValue = (float)currentSprites.Length - 1;
|
||||
frameSlider.Ticks = currentSprites.Length;
|
||||
|
||||
Reference in New Issue
Block a user