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<PPos[]> cellProjection;
|
||||||
[FieldLoader.Ignore] CellLayer<List<MPos>> inverseCellProjection;
|
[FieldLoader.Ignore] CellLayer<List<MPos>> inverseCellProjection;
|
||||||
|
|
||||||
[FieldLoader.Ignore] Lazy<Ruleset> rules;
|
public Ruleset Rules { get; private set; }
|
||||||
public Ruleset Rules { get { return rules != null ? rules.Value : null; } }
|
|
||||||
|
|
||||||
[FieldLoader.Ignore] public ProjectedCellRegion ProjectedCellBounds;
|
[FieldLoader.Ignore] public ProjectedCellRegion ProjectedCellBounds;
|
||||||
[FieldLoader.Ignore] public CellRegion AllCells;
|
[FieldLoader.Ignore] public CellRegion AllCells;
|
||||||
@@ -301,21 +300,19 @@ namespace OpenRA
|
|||||||
|
|
||||||
void PostInit()
|
void PostInit()
|
||||||
{
|
{
|
||||||
rules = Exts.Lazy(() =>
|
try
|
||||||
{
|
{
|
||||||
try
|
Rules = Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions,
|
||||||
{
|
VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions);
|
||||||
return Ruleset.Load(modData, this, Tileset, RuleDefinitions, WeaponDefinitions,
|
}
|
||||||
VoiceDefinitions, NotificationDefinitions, MusicDefinitions, SequenceDefinitions);
|
catch (Exception e)
|
||||||
}
|
{
|
||||||
catch (Exception e)
|
InvalidCustomRules = true;
|
||||||
{
|
Rules = Ruleset.LoadDefaultsForTileSet(modData, Tileset);
|
||||||
InvalidCustomRules = true;
|
Log.Write("debug", "Failed to load rules for {0} with error {1}", Title, e.Message);
|
||||||
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 tl = new MPos(0, 0).ToCPos(this);
|
||||||
var br = new MPos(MapSize.X - 1, MapSize.Y - 1).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();
|
return candidates.Where(c => mapHeight.Contains((MPos)c)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Ruleset PreloadRules()
|
|
||||||
{
|
|
||||||
return rules.Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Save(IReadWritePackage toPackage)
|
public void Save(IReadWritePackage toPackage)
|
||||||
{
|
{
|
||||||
MapFormat = SupportedMapFormat;
|
MapFormat = SupportedMapFormat;
|
||||||
@@ -647,7 +639,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
// The first check ensures that the cell is within the valid map region, avoiding
|
// 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
|
// 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);
|
return CustomTerrain.Contains(uv) && ContainsAllProjectedCellsCovering(uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -186,19 +186,15 @@ namespace OpenRA
|
|||||||
if (MapCache[uid].Status != MapStatus.Available)
|
if (MapCache[uid].Status != MapStatus.Available)
|
||||||
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
throw new InvalidDataException("Invalid map uid: {0}".F(uid));
|
||||||
|
|
||||||
// Operate on a copy of the map to avoid gameplay state leaking into the cache
|
Map map;
|
||||||
var map = new Map(this, MapCache[uid].Package);
|
using (new Support.PerfTimer("Map"))
|
||||||
|
map = new Map(this, MapCache[uid].Package);
|
||||||
|
|
||||||
LoadTranslations(map);
|
LoadTranslations(map);
|
||||||
|
|
||||||
// Reinitialize all our assets
|
// Reinitialize all our assets
|
||||||
InitializeLoaders(map);
|
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
|
// Load music with map assets mounted
|
||||||
using (new Support.PerfTimer("Map.Music"))
|
using (new Support.PerfTimer("Map.Music"))
|
||||||
foreach (var entry in map.Rules.Music)
|
foreach (var entry in map.Rules.Music)
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
foreach (var testMap in maps)
|
foreach (var testMap in maps)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
Console.WriteLine("Testing map: {0}".F(testMap.Title));
|
||||||
testMap.PreloadRules();
|
|
||||||
|
|
||||||
// Run all rule checks on the map if it defines custom rules.
|
// Run all rule checks on the map if it defines custom rules.
|
||||||
if (testMap.RuleDefinitions != null || testMap.VoiceDefinitions != null || testMap.WeaponDefinitions != null)
|
if (testMap.RuleDefinitions != null || testMap.VoiceDefinitions != null || testMap.WeaponDefinitions != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user