Make yaml check utility load each map separately to reduce memory usage.
This commit is contained in:
committed by
Matthias Mailänder
parent
695b7865d3
commit
c51327c4cc
@@ -117,7 +117,7 @@ namespace OpenRA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IReadWritePackage> EnumerateMapPackagesWithoutCaching(MapClassification classification = MapClassification.System)
|
public IEnumerable<IReadWritePackage> EnumerateMapDirPackages(MapClassification classification = MapClassification.System)
|
||||||
{
|
{
|
||||||
// Utility mod that does not support maps
|
// Utility mod that does not support maps
|
||||||
if (!modData.Manifest.Contains<MapGrid>())
|
if (!modData.Manifest.Contains<MapGrid>())
|
||||||
@@ -143,16 +143,29 @@ namespace OpenRA
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name))
|
using (var package = (IReadWritePackage)modData.ModFiles.OpenPackage(name))
|
||||||
{
|
yield return package;
|
||||||
foreach (var map in package.Contents)
|
|
||||||
{
|
|
||||||
if (package.OpenPackage(map, modData.ModFiles) is IReadWritePackage mapPackage)
|
|
||||||
yield return mapPackage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<(IReadWritePackage package, string map)> EnumerateMapDirPackagesAndNames(MapClassification classification = MapClassification.System)
|
||||||
|
{
|
||||||
|
var mapDirPackages = EnumerateMapDirPackages(classification);
|
||||||
|
|
||||||
|
foreach (var mapDirPackage in mapDirPackages)
|
||||||
|
foreach (var map in mapDirPackage.Contents)
|
||||||
|
yield return (mapDirPackage, map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<IReadWritePackage> EnumerateMapPackagesWithoutCaching(MapClassification classification = MapClassification.System)
|
||||||
|
{
|
||||||
|
var mapDirPackages = EnumerateMapDirPackages(classification);
|
||||||
|
|
||||||
|
foreach (var mapDirPackage in mapDirPackages)
|
||||||
|
foreach (var map in mapDirPackage.Contents)
|
||||||
|
if (mapDirPackage.OpenPackage(map, modData.ModFiles) is IReadWritePackage mapPackage)
|
||||||
|
yield return mapPackage;
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<Map> EnumerateMapsWithoutCaching(MapClassification classification = MapClassification.System)
|
public IEnumerable<Map> EnumerateMapsWithoutCaching(MapClassification classification = MapClassification.System)
|
||||||
{
|
{
|
||||||
foreach (var mapPackage in EnumerateMapPackagesWithoutCaching(classification))
|
foreach (var mapPackage in EnumerateMapPackagesWithoutCaching(classification))
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
ObjectCreator.MissingTypeAction = s => EmitError($"Missing Type: {s}");
|
ObjectCreator.MissingTypeAction = s => EmitError($"Missing Type: {s}");
|
||||||
FieldLoader.UnknownFieldAction = (s, f) => EmitError($"FieldLoader: Missing field `{s}` on `{f.Name}`");
|
FieldLoader.UnknownFieldAction = (s, f) => EmitError($"FieldLoader: Missing field `{s}` on `{f.Name}`");
|
||||||
|
|
||||||
var maps = new List<Map>();
|
var maps = new List<(IReadWritePackage package, string map)>();
|
||||||
if (args.Length < 2)
|
if (args.Length < 2)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Testing mod: {modData.Manifest.Metadata.Title}");
|
Console.WriteLine($"Testing mod: {modData.Manifest.Metadata.Title}");
|
||||||
@@ -78,40 +78,15 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Use all system maps for lint checking
|
// Use all system maps for lint checking
|
||||||
maps = modData.MapCache.EnumerateMapsWithoutCaching().ToList();
|
maps = modData.MapCache.EnumerateMapDirPackagesAndNames().ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
maps.Add(new Map(modData, new Folder(Platform.EngineDir).OpenPackage(args[1], modData.ModFiles)));
|
maps.Add((new Folder(Platform.EngineDir), args[1]));
|
||||||
|
|
||||||
foreach (var testMap in maps)
|
foreach (var map in maps)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"Testing map: {testMap.Title}");
|
var testMap = new Map(modData, map.package.OpenPackage(map.map, modData.ModFiles));
|
||||||
|
TestMap(testMap, modData);
|
||||||
// Lint tests can't be trusted if the map rules are bogus
|
|
||||||
// so report that problem then skip the tests
|
|
||||||
if (testMap.InvalidCustomRules)
|
|
||||||
{
|
|
||||||
EmitError(testMap.InvalidCustomRulesException.ToString());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run all rule checks on the map if it defines custom rules.
|
|
||||||
if (testMap.RuleDefinitions != null || testMap.VoiceDefinitions != null || testMap.WeaponDefinitions != null)
|
|
||||||
CheckRules(modData, testMap.Rules, testMap);
|
|
||||||
|
|
||||||
// Run all map-level checks here.
|
|
||||||
foreach (var customMapPassType in modData.ObjectCreator.GetTypesImplementing<ILintMapPass>())
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var customMapPass = (ILintMapPass)modData.ObjectCreator.CreateBasic(customMapPassType);
|
|
||||||
customMapPass.Run(EmitError, EmitWarning, modData, testMap);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
EmitError($"{customMapPassType} failed with exception: {e}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (errors > 0)
|
if (errors > 0)
|
||||||
@@ -127,6 +102,37 @@ namespace OpenRA.Mods.Common.UtilityCommands
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestMap(Map map, ModData modData)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Testing map: {map.Title}");
|
||||||
|
|
||||||
|
// Lint tests can't be trusted if the map rules are bogus
|
||||||
|
// so report that problem then skip the tests
|
||||||
|
if (map.InvalidCustomRules)
|
||||||
|
{
|
||||||
|
EmitError(map.InvalidCustomRulesException.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run all rule checks on the map if it defines custom rules.
|
||||||
|
if (map.RuleDefinitions != null || map.VoiceDefinitions != null || map.WeaponDefinitions != null)
|
||||||
|
CheckRules(modData, map.Rules, map);
|
||||||
|
|
||||||
|
// Run all map-level checks here.
|
||||||
|
foreach (var customMapPassType in modData.ObjectCreator.GetTypesImplementing<ILintMapPass>())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var customMapPass = (ILintMapPass)modData.ObjectCreator.CreateBasic(customMapPassType);
|
||||||
|
customMapPass.Run(EmitError, EmitWarning, modData, map);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
EmitError($"{customMapPassType} failed with exception: {e}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CheckRules(ModData modData, Ruleset rules, Map map = null)
|
void CheckRules(ModData modData, Ruleset rules, Map map = null)
|
||||||
{
|
{
|
||||||
foreach (var customRulesPassType in modData.ObjectCreator.GetTypesImplementing<ILintRulesPass>())
|
foreach (var customRulesPassType in modData.ObjectCreator.GetTypesImplementing<ILintRulesPass>())
|
||||||
|
|||||||
Reference in New Issue
Block a user