Use IReadOnlyFileSystem in voxel loader.

This commit is contained in:
Paul Chote
2016-02-15 02:50:34 +00:00
parent 9341055f50
commit 6fde09c075
4 changed files with 22 additions and 17 deletions

View File

@@ -363,7 +363,7 @@ namespace OpenRA
return; return;
} }
ModData.InitializeLoaders(); ModData.InitializeLoaders(ModData.DefaultFileSystem);
Renderer.InitializeFonts(ModData); Renderer.InitializeFonts(ModData);
if (Cursor != null) if (Cursor != null)

View File

@@ -13,6 +13,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.FileSystem;
using OpenRA.Primitives; using OpenRA.Primitives;
namespace OpenRA.Graphics namespace OpenRA.Graphics
@@ -37,6 +38,7 @@ namespace OpenRA.Graphics
readonly List<Vertex[]> vertices = new List<Vertex[]>(); readonly List<Vertex[]> vertices = new List<Vertex[]>();
readonly Cache<Pair<string, string>, Voxel> voxels; readonly Cache<Pair<string, string>, Voxel> voxels;
readonly IReadOnlyFileSystem fileSystem;
IVertexBuffer<Vertex> vertexBuffer; IVertexBuffer<Vertex> vertexBuffer;
int totalVertexCount; int totalVertexCount;
int cachedVertexCount; int cachedVertexCount;
@@ -57,8 +59,9 @@ namespace OpenRA.Graphics
return new SheetBuilder(SheetType.DualIndexed, allocate); return new SheetBuilder(SheetType.DualIndexed, allocate);
} }
public VoxelLoader() public VoxelLoader(IReadOnlyFileSystem fileSystem)
{ {
this.fileSystem = fileSystem;
voxels = new Cache<Pair<string, string>, Voxel>(LoadFile); voxels = new Cache<Pair<string, string>, Voxel>(LoadFile);
vertices = new List<Vertex[]>(); vertices = new List<Vertex[]>();
totalVertexCount = 0; totalVertexCount = 0;
@@ -218,9 +221,9 @@ namespace OpenRA.Graphics
{ {
VxlReader vxl; VxlReader vxl;
HvaReader hva; HvaReader hva;
using (var s = Game.ModData.ModFiles.Open(files.First + ".vxl")) using (var s = fileSystem.Open(files.First + ".vxl"))
vxl = new VxlReader(s); 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"); hva = new HvaReader(s, files.Second + ".hva");
return new Voxel(this, vxl, hva); return new Voxel(this, vxl, hva);
} }

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem;
namespace OpenRA.Graphics namespace OpenRA.Graphics
{ {
@@ -19,20 +20,20 @@ namespace OpenRA.Graphics
{ {
static Dictionary<string, Dictionary<string, Voxel>> units; 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>>(); units = new Dictionary<string, Dictionary<string, Voxel>>();
var sequences = MiniYaml.Merge(voxelFiles.Select( var sequences = MiniYaml.Merge(voxelFiles.Select(
s => MiniYaml.FromStream(modData.ModFiles.Open(s)))); s => MiniYaml.FromStream(fileSystem.Open(s))));
foreach (var s in sequences) 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 vxl = unit;
var hva = unit; var hva = unit;
@@ -46,15 +47,15 @@ namespace OpenRA.Graphics
hva = fields[1].Trim(); 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(); Game.ModData.LoadScreen.Display();
try try
{ {
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my)); var seq = sequences.ToDictionary(my => LoadVoxel(loader, unit, my));
units.Add(unit, seq); units.Add(unit, seq);
} }
catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art catch (FileNotFoundException) { } // Do nothing; we can crash later if we actually wanted art

View File

@@ -85,7 +85,7 @@ namespace OpenRA
LoadScreen.Display(); LoadScreen.Display();
} }
public void InitializeLoaders() public void InitializeLoaders(IReadOnlyFileSystem fileSystem)
{ {
// all this manipulation of static crap here is nasty and breaks // all this manipulation of static crap here is nasty and breaks
// horribly when you use ModData in unexpected ways. // horribly when you use ModData in unexpected ways.
@@ -94,7 +94,7 @@ namespace OpenRA
if (VoxelLoader != null) if (VoxelLoader != null)
VoxelLoader.Dispose(); VoxelLoader.Dispose();
VoxelLoader = new VoxelLoader(); VoxelLoader = new VoxelLoader(fileSystem);
CursorProvider = new CursorProvider(this); 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 // Operate on a copy of the map to avoid gameplay state leaking into the cache
var map = new Map(MapCache[uid].Path); var map = new Map(MapCache[uid].Path);
var fileSystem = DefaultFileSystem;
LoadTranslations(map); LoadTranslations(map);
// Reinitialize all our assets // Reinitialize all our assets
InitializeLoaders(); InitializeLoaders(fileSystem);
ModFiles.LoadFromManifest(Manifest); ModFiles.LoadFromManifest(Manifest);
// Mount map package so custom assets can be used. // Mount map package so custom assets can be used.
@@ -182,9 +183,9 @@ namespace OpenRA
// 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)
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(); VoxelLoader.Finish();
return map; return map;