diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index bc577324e1..48430c4c2d 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -155,8 +155,7 @@ namespace OpenRA [FieldLoader.Ignore] CellLayer cellProjection; [FieldLoader.Ignore] CellLayer> inverseCellProjection; - [FieldLoader.Ignore] Lazy rules; - public Ruleset Rules { get { return rules != null ? rules.Value : null; } } + public Ruleset Rules { get; private set; } [FieldLoader.Ignore] public ProjectedCellRegion ProjectedCellBounds; [FieldLoader.Ignore] public CellRegion AllCells; @@ -301,21 +300,19 @@ namespace OpenRA void PostInit() { - rules = Exts.Lazy(() => + try { - try - { - return Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions, - VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions); - } - catch (Exception e) - { - InvalidCustomRules = true; - Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message); - } + Rules = Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions, + VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions); + } + catch (Exception e) + { + InvalidCustomRules = true; + Rules = Ruleset.LoadDefaultsForTileSet(modData, Tileset); + Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message); + } - return Ruleset.LoadDefaultsForTileSet(modData, Tileset); - }); + Rules.Sequences.Preload(); var tl = new MPos(0, 0).ToCPos(this); var br = new MPos(MapSize.X - 1, MapSize.Y - 1).ToCPos(this); @@ -423,11 +420,6 @@ namespace OpenRA return candidates.Where(c => mapHeight.Contains((MPos)c)).ToArray(); } - public Ruleset PreloadRules() - { - return rules.Value; - } - public void Save(IReadWritePackage toPackage) { MapFormat = SupportedMapFormat; @@ -647,7 +639,7 @@ namespace OpenRA { // The first check ensures that the cell is within the valid map region, avoiding // potential crashes in deeper code. All CellLayers have the same geometry, and - // CustomTerrain is convenient (cellProjection may be null and others are Lazy). + // CustomTerrain is convenient. return CustomTerrain.Contains(uv) && ContainsAllProjectedCellsCovering(uv); } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index acd79db162..e1a0cc3497 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -186,19 +186,15 @@ namespace OpenRA if (MapCache[uid].Status != MapStatus.Available) throw new InvalidDataException("Invalid map uid: {0}".F(uid)); - // Operate on a copy of the map to avoid gameplay state leaking into the cache - var map = new Map(this, MapCache[uid].Package); + Map map; + using (new Support.PerfTimer("Map")) + map = new Map(this, MapCache[uid].Package); LoadTranslations(map); // Reinitialize all our assets InitializeLoaders(map); - using (new Support.PerfTimer("Map.PreloadRules")) - map.PreloadRules(); - using (new Support.PerfTimer("Map.SequenceProvider.Preload")) - map.Rules.Sequences.Preload(); - // Load music with map assets mounted using (new Support.PerfTimer("Map.Music")) foreach (var entry in map.Rules.Music) diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs index ee47648cdb..1e0a13ce11 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckYaml.cs @@ -87,7 +87,6 @@ namespace OpenRA.Mods.Common.UtilityCommands foreach (var testMap in maps) { Console.WriteLine("Testing map: {0}".F(testMap.Title)); - testMap.PreloadRules(); // Run all rule checks on the map if it defines custom rules. if (testMap.RuleDefinitions != null || testMap.VoiceDefinitions != null || testMap.WeaponDefinitions != null)