Remove legacy sound code and simplify platform init.

This commit is contained in:
Paul Chote
2016-08-01 17:39:06 +01:00
parent de85a76c90
commit 9437a86e7e
9 changed files with 38 additions and 92 deletions

View File

@@ -11,8 +11,6 @@
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using OpenRA.FileSystem;
using OpenRA.GameRules;
using OpenRA.Primitives;
@@ -42,21 +40,9 @@ namespace OpenRA
ISound video;
MusicInfo currentMusic;
public Sound(string engineName)
public Sound(IPlatform platform, SoundSettings soundSettings)
{
var enginePath = Platform.ResolvePath(".", "OpenRA.Platforms." + engineName + ".dll");
soundEngine = CreateDevice(Assembly.LoadFile(enginePath));
}
static ISoundEngine CreateDevice(Assembly platformDll)
{
foreach (PlatformAttribute r in platformDll.GetCustomAttributes(typeof(PlatformAttribute), false))
{
var factory = (IDeviceFactory)r.Type.GetConstructor(Type.EmptyTypes).Invoke(null);
return factory.CreateSound();
}
throw new InvalidOperationException("Platform DLL is missing PlatformAttribute to tell us what type to use!");
soundEngine = platform.CreateSound(soundSettings.Device);
}
ISoundSource LoadSound(ISoundLoader[] loaders, IReadOnlyFileSystem fileSystem, string filename)
@@ -92,12 +78,7 @@ namespace OpenRA
public SoundDevice[] AvailableDevices()
{
var defaultDevices = new[]
{
new SoundDevice("Null", null, "Output Disabled")
};
return defaultDevices.Concat(soundEngine.AvailableDevices()).ToArray();
return soundEngine.AvailableDevices();
}
public void SetListenerPosition(WPos position)