Remove lazy loading of map rules.
This commit is contained in:
@@ -155,8 +155,7 @@ namespace OpenRA
|
||||
[FieldLoader.Ignore] CellLayer<PPos[]> cellProjection;
|
||||
[FieldLoader.Ignore] CellLayer<List<MPos>> inverseCellProjection;
|
||||
|
||||
[FieldLoader.Ignore] Lazy<Ruleset> 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;
|
||||
@@ -300,22 +299,20 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
void PostInit()
|
||||
{
|
||||
rules = Exts.Lazy(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions,
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user