Use IReadOnlyFileSystem in Sound code.

This commit is contained in:
Paul Chote
2016-02-15 03:05:55 +00:00
parent d1d3d72edb
commit b9f8301959
3 changed files with 9 additions and 8 deletions

View File

@@ -342,8 +342,6 @@ namespace OpenRA
ModData = new ModData(mod, !Settings.Server.Dedicated); ModData = new ModData(mod, !Settings.Server.Dedicated);
Sound.Initialize();
using (new PerfTimer("LoadMaps")) using (new PerfTimer("LoadMaps"))
ModData.MapCache.LoadMaps(); ModData.MapCache.LoadMaps();

View File

@@ -92,6 +92,8 @@ namespace OpenRA
ChromeMetrics.Initialize(this); ChromeMetrics.Initialize(this);
ChromeProvider.Initialize(this); ChromeProvider.Initialize(this);
Game.Sound.Initialize(SoundLoaders, fileSystem);
if (VoxelLoader != null) if (VoxelLoader != null)
VoxelLoader.Dispose(); VoxelLoader.Dispose();
VoxelLoader = new VoxelLoader(fileSystem); VoxelLoader = new VoxelLoader(fileSystem);

View File

@@ -12,6 +12,7 @@ using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using OpenRA.FileSystem;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -48,21 +49,21 @@ namespace OpenRA
throw new InvalidOperationException("Platform DLL is missing PlatformAttribute to tell us what type to use!"); throw new InvalidOperationException("Platform DLL is missing PlatformAttribute to tell us what type to use!");
} }
ISoundSource LoadSound(string filename) ISoundSource LoadSound(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem, string filename)
{ {
if (!Game.ModData.ModFiles.Exists(filename)) if (!fileSystem.Exists(filename))
{ {
Log.Write("sound", "LoadSound, file does not exist: {0}", filename); Log.Write("sound", "LoadSound, file does not exist: {0}", filename);
return null; return null;
} }
using (var stream = Game.ModData.ModFiles.Open(filename)) using (var stream = fileSystem.Open(filename))
{ {
byte[] rawData; byte[] rawData;
int channels; int channels;
int sampleBits; int sampleBits;
int sampleRate; int sampleRate;
foreach (var loader in Game.ModData.SoundLoaders) foreach (var loader in loaders)
if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate)) if (loader.TryParseSound(stream, filename, out rawData, out channels, out sampleBits, out sampleRate))
return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate); return soundEngine.AddSoundSourceFromMemory(rawData, channels, sampleBits, sampleRate);
@@ -70,9 +71,9 @@ namespace OpenRA
} }
} }
public void Initialize() public void Initialize(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem)
{ {
sounds = new Cache<string, ISoundSource>(LoadSound); sounds = new Cache<string, ISoundSource>(s => LoadSound(loaders, fileSystem, s));
music = null; music = null;
currentMusic = null; currentMusic = null;
video = null; video = null;