Extract default TileSet/Sequence dictionaries to ModData.
This commit is contained in:
@@ -24,8 +24,8 @@ namespace OpenRA
|
||||
public readonly IReadOnlyDictionary<string, SoundInfo> Voices;
|
||||
public readonly IReadOnlyDictionary<string, SoundInfo> Notifications;
|
||||
public readonly IReadOnlyDictionary<string, MusicInfo> Music;
|
||||
public readonly IReadOnlyDictionary<string, TileSet> TileSets;
|
||||
public readonly IReadOnlyDictionary<string, SequenceProvider> Sequences;
|
||||
public readonly TileSet TileSet;
|
||||
public readonly SequenceProvider Sequences;
|
||||
|
||||
public Ruleset(
|
||||
IDictionary<string, ActorInfo> actors,
|
||||
@@ -33,16 +33,16 @@ namespace OpenRA
|
||||
IDictionary<string, SoundInfo> voices,
|
||||
IDictionary<string, SoundInfo> notifications,
|
||||
IDictionary<string, MusicInfo> music,
|
||||
IDictionary<string, TileSet> tileSets,
|
||||
IDictionary<string, SequenceProvider> sequences)
|
||||
TileSet tileSet,
|
||||
SequenceProvider sequences)
|
||||
{
|
||||
Actors = new ReadOnlyDictionary<string, ActorInfo>(actors);
|
||||
Weapons = new ReadOnlyDictionary<string, WeaponInfo>(weapons);
|
||||
Voices = new ReadOnlyDictionary<string, SoundInfo>(voices);
|
||||
Notifications = new ReadOnlyDictionary<string, SoundInfo>(notifications);
|
||||
Music = new ReadOnlyDictionary<string, MusicInfo>(music);
|
||||
TileSets = new ReadOnlyDictionary<string, TileSet>(tileSets);
|
||||
Sequences = new ReadOnlyDictionary<string, SequenceProvider>(sequences);
|
||||
TileSet = tileSet;
|
||||
Sequences = sequences;
|
||||
|
||||
foreach (var a in Actors.Values)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,6 @@ namespace OpenRA
|
||||
readonly Dictionary<string, SoundInfo> voiceCache = 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, TileSet> tileSetCache = new Dictionary<string, TileSet>();
|
||||
|
||||
public event EventHandler LoadingProgress;
|
||||
void RaiseProgress()
|
||||
@@ -43,6 +42,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
public Ruleset Load(IReadOnlyFileSystem fileSystem,
|
||||
TileSet tileSet,
|
||||
MiniYaml additionalRules,
|
||||
MiniYaml additionalWeapons,
|
||||
MiniYaml additionalVoices,
|
||||
@@ -57,7 +57,6 @@ namespace OpenRA
|
||||
Dictionary<string, SoundInfo> voices;
|
||||
Dictionary<string, SoundInfo> notifications;
|
||||
Dictionary<string, MusicInfo> music;
|
||||
Dictionary<string, TileSet> tileSets;
|
||||
|
||||
using (new PerfTimer("Actors"))
|
||||
actors = LoadYamlRules(fileSystem, actorCache, m.Rules, additionalRules,
|
||||
@@ -79,12 +78,8 @@ namespace OpenRA
|
||||
music = LoadYamlRules(fileSystem, musicCache, m.Music, additionalMusic,
|
||||
k => new MusicInfo(k.Key, k.Value));
|
||||
|
||||
using (new PerfTimer("TileSets"))
|
||||
tileSets = LoadTileSets(fileSystem, tileSetCache, m.TileSets);
|
||||
|
||||
// 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, additionalSequences));
|
||||
return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences);
|
||||
var sequences = tileSet != null ? new SequenceProvider(fileSystem, modData, tileSet, additionalSequences) : null;
|
||||
return new Ruleset(actors, weapons, voices, notifications, music, tileSet, sequences);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -93,9 +88,9 @@ namespace OpenRA
|
||||
/// </summary>
|
||||
public Ruleset Load(IReadOnlyFileSystem fileSystem, Map map = null)
|
||||
{
|
||||
return map != null ? Load(fileSystem, map.RuleDefinitions, map.WeaponDefinitions,
|
||||
map.VoiceDefinitions, map.NotificationDefinitions, map.MusicDefinitions,
|
||||
map.SequenceDefinitions) : Load(fileSystem, null, null, null, null, null, null);
|
||||
return map != null ? Load(fileSystem, modData.DefaultTileSets[map.Tileset], map.RuleDefinitions,
|
||||
map.WeaponDefinitions,map.VoiceDefinitions, map.NotificationDefinitions, map.MusicDefinitions,
|
||||
map.SequenceDefinitions) : Load(fileSystem, null, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
Dictionary<string, T> LoadYamlRules<T>(IReadOnlyFileSystem fileSystem,
|
||||
|
||||
@@ -169,10 +169,9 @@ namespace OpenRA
|
||||
[FieldLoader.Ignore] CellLayer<PPos[]> cellProjection;
|
||||
[FieldLoader.Ignore] CellLayer<List<MPos>> inverseCellProjection;
|
||||
|
||||
[FieldLoader.Ignore] Lazy<TileSet> cachedTileSet;
|
||||
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
||||
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
||||
public SequenceProvider SequenceProvider { get { return Rules.Sequences[Tileset]; } }
|
||||
public SequenceProvider SequenceProvider { get { return Rules.Sequences; } }
|
||||
|
||||
[FieldLoader.Ignore] public ProjectedCellRegion ProjectedCellBounds;
|
||||
[FieldLoader.Ignore] public CellRegion AllCells;
|
||||
@@ -307,8 +306,6 @@ namespace OpenRA
|
||||
return modData.DefaultRules;
|
||||
});
|
||||
|
||||
cachedTileSet = Exts.Lazy(() => Rules.TileSets[Tileset]);
|
||||
|
||||
var tl = new MPos(0, 0).ToCPos(this);
|
||||
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this);
|
||||
AllCells = new CellRegion(Grid.Type, tl, br);
|
||||
@@ -388,7 +385,7 @@ namespace OpenRA
|
||||
// Odd-height ramps get bumped up a level to the next even height layer
|
||||
if ((height & 1) == 1)
|
||||
{
|
||||
var ti = cachedTileSet.Value.GetTileInfo(MapTiles.Value[uv]);
|
||||
var ti = Rules.TileSet.GetTileInfo(MapTiles.Value[uv]);
|
||||
if (ti != null && ti.RampType != 0)
|
||||
height += 1;
|
||||
}
|
||||
@@ -624,7 +621,7 @@ namespace OpenRA
|
||||
|
||||
public byte[] SavePreview()
|
||||
{
|
||||
var tileset = Rules.TileSets[Tileset];
|
||||
var tileset = Rules.TileSet;
|
||||
var resources = Rules.Actors["world"].TraitInfos<ResourceTypeInfo>()
|
||||
.ToDictionary(r => r.ResourceType, r => r.TerrainType);
|
||||
|
||||
@@ -875,7 +872,7 @@ namespace OpenRA
|
||||
public void FixOpenAreas()
|
||||
{
|
||||
var r = new Random();
|
||||
var tileset = Rules.TileSets[Tileset];
|
||||
var tileset = Rules.TileSet;
|
||||
|
||||
for (var j = Bounds.Top; j < Bounds.Bottom; j++)
|
||||
{
|
||||
@@ -923,7 +920,7 @@ namespace OpenRA
|
||||
{
|
||||
var custom = CustomTerrain[uv];
|
||||
terrainIndex = cachedTerrainIndexes[uv] =
|
||||
custom != byte.MaxValue ? custom : cachedTileSet.Value.GetTerrainIndex(MapTiles.Value[uv]);
|
||||
custom != byte.MaxValue ? custom : Rules.TileSet.GetTerrainIndex(MapTiles.Value[uv]);
|
||||
}
|
||||
|
||||
return (byte)terrainIndex;
|
||||
@@ -931,7 +928,7 @@ namespace OpenRA
|
||||
|
||||
public TerrainTypeInfo GetTerrainInfo(CPos cell)
|
||||
{
|
||||
return cachedTileSet.Value[GetTerrainIndex(cell)];
|
||||
return Rules.TileSet[GetTerrainIndex(cell)];
|
||||
}
|
||||
|
||||
public CPos Clamp(CPos cell)
|
||||
|
||||
@@ -35,10 +35,16 @@ namespace OpenRA
|
||||
public VoxelLoader VoxelLoader { get; private set; }
|
||||
public CursorProvider CursorProvider { get; private set; }
|
||||
public FS ModFiles = new FS();
|
||||
public IReadOnlyFileSystem DefaultFileSystem { get { return ModFiles; } }
|
||||
|
||||
readonly Lazy<Ruleset> defaultRules;
|
||||
public Ruleset DefaultRules { get { return defaultRules.Value; } }
|
||||
public IReadOnlyFileSystem DefaultFileSystem { get { return ModFiles; } }
|
||||
|
||||
readonly Lazy<IReadOnlyDictionary<string, TileSet>> defaultTileSets;
|
||||
public IReadOnlyDictionary<string, TileSet> DefaultTileSets { get { return defaultTileSets.Value; } }
|
||||
|
||||
readonly Lazy<IReadOnlyDictionary<string, SequenceProvider>> defaultSequences;
|
||||
public IReadOnlyDictionary<string, SequenceProvider> DefaultSequences { get { return defaultSequences.Value; } }
|
||||
|
||||
public ModData(string mod, bool useLoadScreen = false)
|
||||
{
|
||||
@@ -74,6 +80,24 @@ namespace OpenRA
|
||||
SpriteSequenceLoader.OnMissingSpriteError = s => Log.Write("debug", s);
|
||||
|
||||
defaultRules = Exts.Lazy(() => RulesetCache.Load(DefaultFileSystem));
|
||||
defaultTileSets = Exts.Lazy(() =>
|
||||
{
|
||||
var items = new Dictionary<string, TileSet>();
|
||||
|
||||
foreach (var file in Manifest.TileSets)
|
||||
{
|
||||
var t = new TileSet(DefaultFileSystem, file);
|
||||
items.Add(t.Id, t);
|
||||
}
|
||||
|
||||
return (IReadOnlyDictionary<string, TileSet>)(new ReadOnlyDictionary<string, TileSet>(items));
|
||||
});
|
||||
|
||||
defaultSequences = Exts.Lazy(() =>
|
||||
{
|
||||
var items = DefaultTileSets.ToDictionary(t => t.Key, t => new SequenceProvider(DefaultFileSystem, this, t.Value, null));
|
||||
return (IReadOnlyDictionary<string, SequenceProvider>)(new ReadOnlyDictionary<string, SequenceProvider>(items));
|
||||
});
|
||||
|
||||
initialThreadId = System.Threading.Thread.CurrentThread.ManagedThreadId;
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace OpenRA
|
||||
Map = map;
|
||||
Timestep = orderManager.LobbyInfo.GlobalSettings.Timestep;
|
||||
|
||||
TileSet = map.Rules.TileSets[Map.Tileset];
|
||||
TileSet = map.Rules.TileSet;
|
||||
SharedRandom = new MersenneTwister(orderManager.LobbyInfo.GlobalSettings.RandomSeed);
|
||||
|
||||
var worldActorType = type == WorldType.Editor ? "EditorWorld" : "World";
|
||||
|
||||
Reference in New Issue
Block a user