From b8b27f11af4ce3df8f73a1990ce72579f8945cb2 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 5 Jul 2015 11:02:33 +0100 Subject: [PATCH] Remove stub map constructor. --- OpenRA.Game/GameRules/RulesetCache.cs | 30 ++++++++++++++++++------ OpenRA.Game/Graphics/SequenceProvider.cs | 2 +- OpenRA.Game/Map/Map.cs | 3 --- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/GameRules/RulesetCache.cs b/OpenRA.Game/GameRules/RulesetCache.cs index fe3c3ec673..a9a512e502 100755 --- a/OpenRA.Game/GameRules/RulesetCache.cs +++ b/OpenRA.Game/GameRules/RulesetCache.cs @@ -19,6 +19,8 @@ namespace OpenRA { public sealed class RulesetCache : IDisposable { + static readonly List NoMapRules = new List(); + readonly ModData modData; readonly Dictionary actorCache = new Dictionary(); @@ -43,7 +45,7 @@ namespace OpenRA public Ruleset LoadDefaultRules() { - return LoadMapRules(new Map()); + return LoadMapRules(null); } public Ruleset LoadMapRules(Map map) @@ -58,20 +60,34 @@ namespace OpenRA Dictionary tileSets; using (new PerfTimer("Actors")) - actors = LoadYamlRules(actorCache, m.Rules, map.RuleDefinitions, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y)); + actors = LoadYamlRules(actorCache, m.Rules, + map != null ? map.RuleDefinitions : NoMapRules, + (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y)); + using (new PerfTimer("Weapons")) - weapons = LoadYamlRules(weaponCache, m.Weapons, map.WeaponDefinitions, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); + weapons = LoadYamlRules(weaponCache, m.Weapons, + map != null ? map.WeaponDefinitions : NoMapRules, + (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value)); + using (new PerfTimer("Voices")) - voices = LoadYamlRules(voiceCache, m.Voices, map.VoiceDefinitions, (k, _) => new SoundInfo(k.Value)); + voices = LoadYamlRules(voiceCache, m.Voices, + map != null ? map.VoiceDefinitions : NoMapRules, + (k, _) => new SoundInfo(k.Value)); + using (new PerfTimer("Notifications")) - notifications = LoadYamlRules(notificationCache, m.Notifications, map.NotificationDefinitions, (k, _) => new SoundInfo(k.Value)); + notifications = LoadYamlRules(notificationCache, m.Notifications, + map != null ? map.NotificationDefinitions : NoMapRules, + (k, _) => new SoundInfo(k.Value)); + using (new PerfTimer("Music")) - music = LoadYamlRules(musicCache, m.Music, new List(), (k, _) => new MusicInfo(k.Key, k.Value)); + music = LoadYamlRules(musicCache, m.Music, + NoMapRules, + (k, _) => new MusicInfo(k.Key, k.Value)); + using (new PerfTimer("TileSets")) tileSets = LoadTileSets(tileSetCache, sequenceCaches, m.TileSets); var sequences = sequenceCaches.ToDictionary(kvp => kvp.Key, kvp => new SequenceProvider(kvp.Value, map)); - return new Ruleset(actors, weapons, voices, notifications, music, tileSets, sequences); } diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index 1c021c7447..198f9ffbc5 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -120,7 +120,7 @@ namespace OpenRA.Graphics public Sequences LoadSequences(Map map) { using (new Support.PerfTimer("LoadSequences")) - return Load(map.SequenceDefinitions); + return Load(map != null ? map.SequenceDefinitions : new List()); } Sequences Load(List sequenceNodes) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index 986f98271b..25dc8b82d7 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -261,9 +261,6 @@ namespace OpenRA throw new InvalidOperationException("Required file {0} not present in this map".F(filename)); } - /// A stub constructor that doesn't produce a valid map. Do not use. - public Map() { } - /// /// Initializes a new map created by the editor or importer. /// The map will not recieve a valid UID until after it has been saved and reloaded.