diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index ce6a8ee535..f33b810ad2 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -342,8 +342,6 @@ namespace OpenRA ModData = new ModData(mod, !Settings.Server.Dedicated); - Sound.Initialize(); - using (new PerfTimer("LoadMaps")) ModData.MapCache.LoadMaps(); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index c00871eef7..f68e6d4145 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -92,6 +92,8 @@ namespace OpenRA ChromeMetrics.Initialize(this); ChromeProvider.Initialize(this); + Game.Sound.Initialize(SoundLoaders, fileSystem); + if (VoxelLoader != null) VoxelLoader.Dispose(); VoxelLoader = new VoxelLoader(fileSystem); diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 2904219415..c3a65cd350 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -12,6 +12,7 @@ using System; using System.IO; using System.Linq; using System.Reflection; +using OpenRA.FileSystem; using OpenRA.GameRules; using OpenRA.Primitives; @@ -48,21 +49,21 @@ namespace OpenRA 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); return null; } - using (var stream = Game.ModData.ModFiles.Open(filename)) + using (var stream = fileSystem.Open(filename)) { byte[] rawData; int channels; int sampleBits; 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)) 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(LoadSound); + sounds = new Cache(s => LoadSound(loaders, fileSystem, s)); music = null; currentMusic = null; video = null;