From 206088efb4b0412fe742ab5e5c110de46e9acb7d Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 30 Jul 2016 14:50:42 +0100 Subject: [PATCH] General code cleanup in OpenAlSoundEngine.cs. --- OpenRA.Platforms.Default/OpenAlSoundEngine.cs | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs index 5f76074ea7..86791cdf58 100644 --- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -46,9 +46,9 @@ namespace OpenRA.Platforms.Default const int GroupDistanceSqr = GroupDistance * GroupDistance; const int PoolSize = 32; - IntPtr device; + readonly Dictionary sourcePool = new Dictionary(); float volume = 1f; - Dictionary sourcePool = new Dictionary(); + IntPtr device; static string[] QueryDevices(string label, int type) { @@ -66,7 +66,7 @@ namespace OpenRA.Platforms.Default do { var str = Marshal.PtrToStringAuto(next); - next += UnicodeEncoding.Default.GetByteCount(str) + 1; + next += Encoding.Default.GetByteCount(str) + 1; devices.Add(str); } while (Marshal.ReadByte(next) != 0); @@ -255,13 +255,13 @@ namespace OpenRA.Platforms.Default public void SetSoundVolume(float volume, ISound music, ISound video) { - var sounds = sourcePool.Select(s => s.Key).Where(b => + var sounds = sourcePool.Keys.Where(key => { int state; - AL10.alGetSourcei(b, AL10.AL_SOURCE_STATE, out state); + AL10.alGetSourcei(key, AL10.AL_SOURCE_STATE, out state); return (state == AL10.AL_PLAYING || state == AL10.AL_PAUSED) && - (music == null || b != ((OpenAlSound)music).Source) && - (video == null || b != ((OpenAlSound)video).Source); + (music == null || key != ((OpenAlSound)music).Source) && + (video == null || key != ((OpenAlSound)video).Source); }); foreach (var s in sounds) @@ -343,8 +343,8 @@ namespace OpenRA.Platforms.Default class OpenAlSound : ISound { - public readonly uint Source = uint.MaxValue; - float volume = 1f; + public readonly uint Source; + float volume; public OpenAlSound(uint source, uint buffer, bool looping, bool relative, WPos pos, float volume) { @@ -365,15 +365,8 @@ namespace OpenRA.Platforms.Default public float Volume { - get - { - return volume; - } - - set - { - AL10.alSourcef(Source, AL10.AL_GAIN, volume = value); - } + get { return volume; } + set { AL10.alSourcef(Source, AL10.AL_GAIN, volume = value); } } public float SeekPosition