#2039 fixed - add Sound.Engine config item, default is "AL" for OpenAL sound engine; "Null" gives you no sound

This commit is contained in:
Chris Forbes
2012-04-24 20:23:41 +12:00
parent 84a50e8e86
commit 6e3aa46008
3 changed files with 47 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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

View File

@@ -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; } }
}
}