Allow cash ticking sound to overlap

This commit is contained in:
Gustas
2022-10-11 15:58:37 +03:00
committed by Matthias Mailänder
parent fde4f8d0e5
commit 347148e02f
6 changed files with 72 additions and 49 deletions

View File

@@ -33,7 +33,7 @@ namespace OpenRA.GameRules
{
FieldLoader.Load(this, y);
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(1f, false, a.Value)));
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(1f, SoundPool.DefaultInterruptType, a.Value)));
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
}
@@ -44,17 +44,17 @@ namespace OpenRA.GameRules
foreach (var t in classifiction.Value.Nodes)
{
var volumeModifier = 1f;
var volumeModifierNode = t.Value.Nodes.FirstOrDefault(x => x.Key == "VolumeModifier");
var volumeModifierNode = t.Value.Nodes.FirstOrDefault(x => x.Key == nameof(SoundPool.VolumeModifier));
if (volumeModifierNode != null)
volumeModifier = FieldLoader.GetValue<float>(volumeModifierNode.Key, volumeModifierNode.Value.Value);
var allowInterrupt = false;
var allowInterruptNode = t.Value.Nodes.FirstOrDefault(x => x.Key == "AllowInterrupt");
if (allowInterruptNode != null)
allowInterrupt = FieldLoader.GetValue<bool>(allowInterruptNode.Key, allowInterruptNode.Value.Value);
var interruptType = SoundPool.DefaultInterruptType;
var interruptTypeNode = t.Value.Nodes.FirstOrDefault(x => x.Key == nameof(SoundPool.InterruptType));
if (interruptTypeNode != null)
interruptType = FieldLoader.GetValue<SoundPool.InterruptType>(interruptTypeNode.Key, interruptTypeNode.Value.Value);
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
var sp = new SoundPool(volumeModifier, allowInterrupt, names);
var sp = new SoundPool(volumeModifier, interruptType, names);
ret.Add(t.Key, sp);
}
@@ -64,15 +64,17 @@ namespace OpenRA.GameRules
public class SoundPool
{
public enum InterruptType { DoNotPlay, Interrupt, Overlap }
public const InterruptType DefaultInterruptType = InterruptType.DoNotPlay;
public readonly float VolumeModifier;
public readonly bool AllowInterrupt;
public readonly InterruptType Type;
readonly string[] clips;
readonly List<string> liveclips = new List<string>();
public SoundPool(float volumeModifier, bool allowInterrupt, params string[] clips)
public SoundPool(float volumeModifier, InterruptType interruptType, params string[] clips)
{
VolumeModifier = volumeModifier;
AllowInterrupt = allowInterrupt;
Type = interruptType;
this.clips = clips;
}

View File

@@ -401,36 +401,49 @@ namespace OpenRA
if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer))
{
if (currentNotifications.TryGetValue(name, out var currentNotification))
ISound PlaySound()
{
if (!currentNotification.Complete)
var volume = InternalSoundVolume * volumeModifier * pool.VolumeModifier;
return soundEngine.Play2D(sounds[name], false, relative, pos, volume, attenuateVolume);
}
if (pool.Type == SoundPool.InterruptType.Overlap)
{
if (PlaySound() == null)
return false;
}
else if (voicedActor == null)
{
if (currentNotifications.TryGetValue(name, out var currentNotification) && !currentNotification.Complete)
{
if (pool.AllowInterrupt)
if (pool.Type == SoundPool.InterruptType.Interrupt)
soundEngine.StopSound(currentNotification);
else
else if (pool.Type == SoundPool.InterruptType.DoNotPlay)
return false;
}
}
else if (currentSounds.TryGetValue(actorId, out var currentSound))
{
if (!currentSound.Complete)
{
if (pool.AllowInterrupt)
soundEngine.StopSound(currentSound);
else
return false;
}
}
var volume = InternalSoundVolume * volumeModifier * pool.VolumeModifier;
var sound = soundEngine.Play2D(sounds[name], false, relative, pos, volume, attenuateVolume);
if (sound == null)
return false;
if (voicedActor != null)
currentSounds[actorId] = sound;
var sound = PlaySound();
if (sound == null)
return false;
else
currentNotifications[name] = sound;
}
else
currentNotifications[name] = sound;
{
if (currentSounds.TryGetValue(actorId, out var currentSound) && !currentSound.Complete)
{
if (pool.Type == SoundPool.InterruptType.Interrupt)
soundEngine.StopSound(currentSound);
else if (pool.Type == SoundPool.InterruptType.DoNotPlay)
return false;
}
var sound = PlaySound();
if (sound == null)
return false;
else
currentSounds[actorId] = sound;
}
}
return true;