diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index abc443deab..deed94a085 100755 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -259,7 +259,7 @@ namespace OpenRA foreach(var mod in Mod.AllMods) Console.WriteLine("\t{0}: {1} ({2})", mod.Key, mod.Value.Title, mod.Value.Version); - Sound.Create(); + Sound.Create(Settings.Sound.Engine); InitializeWithMods(Settings.Game.Mods); } diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index cc16695d1d..4bbc9cdb19 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -76,6 +76,7 @@ namespace OpenRA.GameRules public bool Shuffle = false; public bool Repeat = false; public bool ShellmapMusic = true; + public string Engine = "AL"; } public class PlayerSettings diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index cb0beda273..5fbc99ec59 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -37,9 +37,21 @@ namespace OpenRA return soundEngine.AddSoundSourceFromMemory(rawData, 1, 16, 22050); } - public static void Create() + static ISoundEngine CreateEngine(string engine) { - soundEngine = new OpenAlSoundEngine(); + switch (engine) + { /* todo: if someone cares about pluggable crap here, ship this out */ + case "AL": return new OpenAlSoundEngine(); + case "Null": return new NullSoundEngine(); + + default: + throw new InvalidOperationException("Unsupported sound engine: {0}".F (engine)); + } + } + + public static void Create(string engine) + { + soundEngine = CreateEngine(engine); } public static void Initialize() @@ -495,4 +507,35 @@ namespace OpenRA } } } + + class NullSoundEngine : ISoundEngine + { + public ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate) + { + return new NullSoundSource(); + } + + public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume) + { + return new NullSound(); + } + + public void PauseSound(ISound sound, bool paused) {} + public void StopSound(ISound sound) {} + public void SetAllSoundsPaused(bool paused) {} + public void StopAllSounds() {} + public void SetListenerPosition(float2 position) {} + public void SetSoundVolume(float volume, ISound music, ISound video) {} + + public float Volume { get; set; } + } + + class NullSoundSource : ISoundSource {} + + class NullSound : ISound + { + public float Volume { get; set; } + public float SeekPosition { get { return 0; } } + public bool Playing { get { return false; } } + } }