diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index fde21b6c23..ce6a8ee535 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -363,7 +363,7 @@ namespace OpenRA return; } - ModData.InitializeLoaders(); + ModData.InitializeLoaders(ModData.DefaultFileSystem); Renderer.InitializeFonts(ModData); if (Cursor != null) diff --git a/OpenRA.Game/Graphics/VoxelLoader.cs b/OpenRA.Game/Graphics/VoxelLoader.cs index 4153134c32..ab0b7a1135 100644 --- a/OpenRA.Game/Graphics/VoxelLoader.cs +++ b/OpenRA.Game/Graphics/VoxelLoader.cs @@ -13,6 +13,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; using OpenRA.FileFormats; +using OpenRA.FileSystem; using OpenRA.Primitives; namespace OpenRA.Graphics @@ -37,6 +38,7 @@ namespace OpenRA.Graphics readonly List vertices = new List(); readonly Cache, Voxel> voxels; + readonly IReadOnlyFileSystem fileSystem; IVertexBuffer vertexBuffer; int totalVertexCount; int cachedVertexCount; @@ -57,8 +59,9 @@ namespace OpenRA.Graphics return new SheetBuilder(SheetType.DualIndexed, allocate); } - public VoxelLoader() + public VoxelLoader(IReadOnlyFileSystem fileSystem) { + this.fileSystem = fileSystem; voxels = new Cache, Voxel>(LoadFile); vertices = new List(); totalVertexCount = 0; @@ -218,9 +221,9 @@ namespace OpenRA.Graphics { VxlReader vxl; HvaReader hva; - using (var s = Game.ModData.ModFiles.Open(files.First + ".vxl")) + using (var s = fileSystem.Open(files.First + ".vxl")) vxl = new VxlReader(s); - using (var s = Game.ModData.ModFiles.Open(files.Second + ".hva")) + using (var s = fileSystem.Open(files.Second + ".hva")) hva = new HvaReader(s, files.Second + ".hva"); return new Voxel(this, vxl, hva); } diff --git a/OpenRA.Game/Graphics/VoxelProvider.cs b/OpenRA.Game/Graphics/VoxelProvider.cs index 87e8131c55..e63aa2c3b2 100644 --- a/OpenRA.Game/Graphics/VoxelProvider.cs +++ b/OpenRA.Game/Graphics/VoxelProvider.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; +using OpenRA.FileSystem; namespace OpenRA.Graphics { @@ -19,20 +20,20 @@ namespace OpenRA.Graphics { static Dictionary> units; - public static void Initialize(ModData modData, string[] voxelFiles, List voxelNodes) + public static void Initialize(VoxelLoader loader, IReadOnlyFileSystem fileSystem, string[] voxelFiles, List voxelNodes) { units = new Dictionary>(); var sequences = MiniYaml.Merge(voxelFiles.Select( - s => MiniYaml.FromStream(modData.ModFiles.Open(s)))); + s => MiniYaml.FromStream(fileSystem.Open(s)))); foreach (var s in sequences) - LoadVoxelsForUnit(s.Key, s.Value); + LoadVoxelsForUnit(loader, s.Key, s.Value); - Game.ModData.VoxelLoader.RefreshBuffer(); + loader.RefreshBuffer(); } - static Voxel LoadVoxel(string unit, MiniYaml info) + static Voxel LoadVoxel(VoxelLoader voxelLoader, string unit, MiniYaml info) { var vxl = unit; var hva = unit; @@ -46,15 +47,15 @@ namespace OpenRA.Graphics hva = fields[1].Trim(); } - return Game.ModData.VoxelLoader.Load(vxl, hva); + return voxelLoader.Load(vxl, hva); } - static void LoadVoxelsForUnit(string unit, MiniYaml sequences) + static void LoadVoxelsForUnit(VoxelLoader loader, string unit, MiniYaml sequences) { Game.ModData.LoadScreen.Display(); try { - var seq = sequences.ToDictionary(my => LoadVoxel(unit, my)); + var seq = sequences.ToDictionary(my => LoadVoxel(loader, unit, my)); units.Add(unit, seq); } catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 996694d1d6..a985c04db9 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -85,7 +85,7 @@ namespace OpenRA LoadScreen.Display(); } - public void InitializeLoaders() + public void InitializeLoaders(IReadOnlyFileSystem fileSystem) { // all this manipulation of static crap here is nasty and breaks // horribly when you use ModData in unexpected ways. @@ -94,7 +94,7 @@ namespace OpenRA if (VoxelLoader != null) VoxelLoader.Dispose(); - VoxelLoader = new VoxelLoader(); + VoxelLoader = new VoxelLoader(fileSystem); CursorProvider = new CursorProvider(this); } @@ -164,11 +164,12 @@ namespace OpenRA // Operate on a copy of the map to avoid gameplay state leaking into the cache var map = new Map(MapCache[uid].Path); + var fileSystem = DefaultFileSystem; LoadTranslations(map); // Reinitialize all our assets - InitializeLoaders(); + InitializeLoaders(fileSystem); ModFiles.LoadFromManifest(Manifest); // Mount map package so custom assets can be used. @@ -182,9 +183,9 @@ namespace OpenRA // Load music with map assets mounted using (new Support.PerfTimer("Map.Music")) foreach (var entry in map.Rules.Music) - entry.Value.Load(DefaultFileSystem); + entry.Value.Load(fileSystem); - VoxelProvider.Initialize(this, Manifest.VoxelSequences, map.VoxelSequenceDefinitions); + VoxelProvider.Initialize(VoxelLoader, fileSystem, Manifest.VoxelSequences, map.VoxelSequenceDefinitions); VoxelLoader.Finish(); return map;