Use IReadOnlyFileSystem in voxel loader.
This commit is contained in:
@@ -363,7 +363,7 @@ namespace OpenRA
|
||||
return;
|
||||
}
|
||||
|
||||
ModData.InitializeLoaders();
|
||||
ModData.InitializeLoaders(ModData.DefaultFileSystem);
|
||||
Renderer.InitializeFonts(ModData);
|
||||
|
||||
if (Cursor != null)
|
||||
|
||||
@@ -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<Vertex[]> vertices = new List<Vertex[]>();
|
||||
readonly Cache<Pair<string, string>, Voxel> voxels;
|
||||
readonly IReadOnlyFileSystem fileSystem;
|
||||
IVertexBuffer<Vertex> 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<Pair<string, string>, Voxel>(LoadFile);
|
||||
vertices = new List<Vertex[]>();
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<string, Dictionary<string, Voxel>> units;
|
||||
|
||||
public static void Initialize(ModData modData, string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||
public static void Initialize(VoxelLoader loader, IReadOnlyFileSystem fileSystem, string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||
{
|
||||
units = new Dictionary<string, Dictionary<string, Voxel>>();
|
||||
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user