From bbac9ac61a426666a2500268f0f5f4c34c597c07 Mon Sep 17 00:00:00 2001 From: Turupawn Date: Sat, 6 Aug 2016 20:01:33 -0600 Subject: [PATCH] Same unit command sounds wont overlap anymore Responding to Travis inquiries Changed Hashtable for Ditctionary + avoiding code duplication More small code nits another nit --- OpenRA.Game/Sound/Sound.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs index 4c2ce54884..80548da444 100644 --- a/OpenRA.Game/Sound/Sound.cs +++ b/OpenRA.Game/Sound/Sound.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Collections.Generic; using System.IO; using OpenRA.FileSystem; using OpenRA.GameRules; @@ -39,6 +40,7 @@ namespace OpenRA ISound music; ISound video; MusicInfo currentMusic; + Dictionary currentSounds = new Dictionary(); public Sound(IPlatform platform, SoundSettings soundSettings) { @@ -348,9 +350,18 @@ namespace OpenRA var name = prefix + clip + suffix; if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer)) - soundEngine.Play2D(sounds[name], + { + var sound = soundEngine.Play2D(sounds[name], false, relative, pos, InternalSoundVolume * volumeModifier, attenuateVolume); + if (id != 0) + { + if (currentSounds.ContainsKey(id)) + soundEngine.StopSound(currentSounds[id]); + + currentSounds[id] = sound; + } + } return true; }