Add VolumeModifier support to sound definitions.
This commit is contained in:
@@ -33,7 +33,7 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
FieldLoader.Load(this, y);
|
FieldLoader.Load(this, y);
|
||||||
|
|
||||||
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(0, a.Value)));
|
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(0, 1f, a.Value)));
|
||||||
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
|
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,8 +48,13 @@ namespace OpenRA.GameRules
|
|||||||
if (rateLimitNode != null)
|
if (rateLimitNode != null)
|
||||||
rateLimit = FieldLoader.GetValue<int>(rateLimitNode.Key, rateLimitNode.Value.Value);
|
rateLimit = FieldLoader.GetValue<int>(rateLimitNode.Key, rateLimitNode.Value.Value);
|
||||||
|
|
||||||
|
var volumeModifier = 1f;
|
||||||
|
var volumeModifierNode = t.Value.Nodes.FirstOrDefault(x => x.Key == "VolumeModifier");
|
||||||
|
if (volumeModifierNode != null)
|
||||||
|
volumeModifier = FieldLoader.GetValue<float>(volumeModifierNode.Key, volumeModifierNode.Value.Value);
|
||||||
|
|
||||||
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
|
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
|
||||||
var sp = new SoundPool(rateLimit, names);
|
var sp = new SoundPool(rateLimit, volumeModifier, names);
|
||||||
ret.Add(t.Key, sp);
|
ret.Add(t.Key, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +64,15 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
public class SoundPool
|
public class SoundPool
|
||||||
{
|
{
|
||||||
|
public readonly float VolumeModifier;
|
||||||
readonly string[] clips;
|
readonly string[] clips;
|
||||||
readonly int rateLimit;
|
readonly int rateLimit;
|
||||||
readonly List<string> liveclips = new List<string>();
|
readonly List<string> liveclips = new List<string>();
|
||||||
long lastPlayed = 0;
|
long lastPlayed = 0;
|
||||||
|
|
||||||
public SoundPool(int rateLimit, params string[] clips)
|
public SoundPool(int rateLimit, float volumeModifier, params string[] clips)
|
||||||
{
|
{
|
||||||
|
VolumeModifier = volumeModifier;
|
||||||
this.clips = clips;
|
this.clips = clips;
|
||||||
this.rateLimit = rateLimit;
|
this.rateLimit = rateLimit;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -352,7 +352,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
var id = voicedActor != null ? voicedActor.ActorID : 0;
|
var id = voicedActor != null ? voicedActor.ActorID : 0;
|
||||||
|
|
||||||
string clip;
|
SoundPool pool;
|
||||||
var suffix = rules.DefaultVariant;
|
var suffix = rules.DefaultVariant;
|
||||||
var prefix = rules.DefaultPrefix;
|
var prefix = rules.DefaultPrefix;
|
||||||
|
|
||||||
@@ -361,16 +361,17 @@ namespace OpenRA
|
|||||||
if (!rules.VoicePools.Value.ContainsKey(definition))
|
if (!rules.VoicePools.Value.ContainsKey(definition))
|
||||||
throw new InvalidOperationException("Can't find {0} in voice pool.".F(definition));
|
throw new InvalidOperationException("Can't find {0} in voice pool.".F(definition));
|
||||||
|
|
||||||
clip = rules.VoicePools.Value[definition].GetNext();
|
pool = rules.VoicePools.Value[definition];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!rules.NotificationsPools.Value.ContainsKey(definition))
|
if (!rules.NotificationsPools.Value.ContainsKey(definition))
|
||||||
throw new InvalidOperationException("Can't find {0} in notification pool.".F(definition));
|
throw new InvalidOperationException("Can't find {0} in notification pool.".F(definition));
|
||||||
|
|
||||||
clip = rules.NotificationsPools.Value[definition].GetNext();
|
pool = rules.NotificationsPools.Value[definition];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var clip = pool.GetNext();
|
||||||
if (string.IsNullOrEmpty(clip))
|
if (string.IsNullOrEmpty(clip))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -388,7 +389,7 @@ namespace OpenRA
|
|||||||
{
|
{
|
||||||
var sound = soundEngine.Play2D(sounds[name],
|
var sound = soundEngine.Play2D(sounds[name],
|
||||||
false, relative, pos,
|
false, relative, pos,
|
||||||
InternalSoundVolume * volumeModifier, attenuateVolume);
|
InternalSoundVolume * volumeModifier * pool.VolumeModifier, attenuateVolume);
|
||||||
if (id != 0)
|
if (id != 0)
|
||||||
{
|
{
|
||||||
if (currentSounds.ContainsKey(id))
|
if (currentSounds.ContainsKey(id))
|
||||||
|
|||||||
Reference in New Issue
Block a user