(gecko) Return the ISound when playing sounds, so you can stop it later
This commit is contained in:
@@ -48,34 +48,46 @@ namespace OpenRA
|
||||
|
||||
public static void SetListenerPosition(float2 position) { soundEngine.SetListenerPosition(position); }
|
||||
|
||||
public static void Play(string name)
|
||||
public static ISound Play(string name)
|
||||
{
|
||||
return Play(name, float2.Zero);
|
||||
}
|
||||
|
||||
public static ISound Play(string name, float2 pos)
|
||||
{
|
||||
if (name == "" || name == null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
var sound = sounds[name];
|
||||
soundEngine.Play2D(sound, false, true, float2.Zero, InternalSoundVolume);
|
||||
return soundEngine.Play2D(sound, false, false, pos, InternalSoundVolume);
|
||||
}
|
||||
|
||||
public static void Play(string name, float2 pos)
|
||||
|
||||
public static ISound Play(string name, float volumeModifier)
|
||||
{
|
||||
return Play(name, float2.Zero, volumeModifier);
|
||||
}
|
||||
|
||||
public static ISound Play(string name, float2 pos, float volumeModifier)
|
||||
{
|
||||
if (name == "" || name == null)
|
||||
return;
|
||||
return null;
|
||||
|
||||
var sound = sounds[name];
|
||||
soundEngine.Play2D(sound, false, false, pos, InternalSoundVolume);
|
||||
return soundEngine.Play2D(sound, false, false, pos, InternalSoundVolume * volumeModifier);
|
||||
}
|
||||
|
||||
public static void PlayToPlayer(Player player, string name)
|
||||
public static ISound PlayToPlayer(Player player, string name)
|
||||
{
|
||||
if( player == player.World.LocalPlayer )
|
||||
Play( name );
|
||||
return PlayToPlayer(player, name, float2.Zero);
|
||||
}
|
||||
|
||||
public static void PlayToPlayer(Player player, string name, float2 pos)
|
||||
public static ISound PlayToPlayer(Player player, string name, float2 pos)
|
||||
{
|
||||
if (player == player.World.LocalPlayer)
|
||||
Play(name, pos);
|
||||
return Play(name, pos);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void PlayVideo(byte[] raw)
|
||||
@@ -117,7 +129,7 @@ namespace OpenRA
|
||||
|
||||
public static void PlayMusic(string name)
|
||||
{
|
||||
PlayMusicThen(name, () => {});
|
||||
PlayMusicThen(name, () => { });
|
||||
}
|
||||
public static void PlayMusicThen(string name, Action then)
|
||||
{
|
||||
@@ -147,6 +159,12 @@ namespace OpenRA
|
||||
soundEngine.PauseSound(music, false);
|
||||
}
|
||||
|
||||
public static void StopSound(ISound sound)
|
||||
{
|
||||
if (sound != null)
|
||||
soundEngine.StopSound(sound);
|
||||
}
|
||||
|
||||
public static void StopMusic()
|
||||
{
|
||||
if (music != null)
|
||||
@@ -168,7 +186,7 @@ namespace OpenRA
|
||||
public static float GlobalVolume
|
||||
{
|
||||
get { return soundEngine.Volume; }
|
||||
set { soundEngine.Volume = value;}
|
||||
set { soundEngine.Volume = value; }
|
||||
}
|
||||
|
||||
static float soundVolumeModifier = 1.0f;
|
||||
@@ -182,7 +200,7 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
static float InternalSoundVolume { get { return SoundVolume*soundVolumeModifier; } }
|
||||
static float InternalSoundVolume { get { return SoundVolume * soundVolumeModifier; } }
|
||||
public static float SoundVolume
|
||||
{
|
||||
get { return Game.Settings.Sound.SoundVolume; }
|
||||
@@ -217,12 +235,12 @@ namespace OpenRA
|
||||
|
||||
public static float MusicSeekPosition
|
||||
{
|
||||
get { return (music != null)? music.SeekPosition : 0; }
|
||||
get { return (music != null) ? music.SeekPosition : 0; }
|
||||
}
|
||||
|
||||
public static float VideoSeekPosition
|
||||
{
|
||||
get { return (video != null)? video.SeekPosition : 0; }
|
||||
get { return (video != null) ? video.SeekPosition : 0; }
|
||||
}
|
||||
|
||||
// Returns true if it played a phrase
|
||||
@@ -241,7 +259,7 @@ namespace OpenRA
|
||||
if (clip == null)
|
||||
return false;
|
||||
|
||||
var variantext = (vi.Variants.ContainsKey(variant) && !vi.DisableVariants.Contains(phrase))?
|
||||
var variantext = (vi.Variants.ContainsKey(variant) && !vi.DisableVariants.Contains(phrase)) ?
|
||||
vi.Variants[variant][voicedUnit.ActorID % vi.Variants[variant].Length] : vi.DefaultVariant;
|
||||
Play(clip + variantext);
|
||||
return true;
|
||||
@@ -261,8 +279,9 @@ namespace OpenRA
|
||||
void SetSoundVolume(float volume, ISound music, ISound video);
|
||||
}
|
||||
|
||||
interface ISoundSource {}
|
||||
interface ISound
|
||||
interface ISoundSource { }
|
||||
|
||||
public interface ISound
|
||||
{
|
||||
float Volume { get; set; }
|
||||
float SeekPosition { get; }
|
||||
@@ -350,7 +369,7 @@ namespace OpenRA
|
||||
|
||||
public void PauseSound(ISound sound, bool paused)
|
||||
{
|
||||
int key = ((OpenAlSound) sound).source;
|
||||
int key = ((OpenAlSound)sound).source;
|
||||
int state;
|
||||
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
||||
if (state == Al.AL_PLAYING && paused)
|
||||
@@ -375,13 +394,13 @@ namespace OpenRA
|
||||
|
||||
public void SetSoundVolume(float volume, ISound music, ISound video)
|
||||
{
|
||||
var sounds = sourcePool.Select(s => s.Key).Where( b =>
|
||||
var sounds = sourcePool.Select(s => s.Key).Where(b =>
|
||||
{
|
||||
int state;
|
||||
Al.alGetSourcei(b, Al.AL_SOURCE_STATE, out state);
|
||||
return ((state == Al.AL_PLAYING || state == Al.AL_PAUSED) &&
|
||||
((music != null)? b != ((OpenAlSound) music).source : true) &&
|
||||
((video != null)? b != ((OpenAlSound) video).source : true));
|
||||
((music != null) ? b != ((OpenAlSound)music).source : true) &&
|
||||
((video != null) ? b != ((OpenAlSound)video).source : true));
|
||||
}).ToList();
|
||||
foreach (var s in sounds)
|
||||
{
|
||||
@@ -391,7 +410,7 @@ namespace OpenRA
|
||||
|
||||
public void StopSound(ISound sound)
|
||||
{
|
||||
int key = ((OpenAlSound) sound).source;
|
||||
int key = ((OpenAlSound)sound).source;
|
||||
int state;
|
||||
Al.alGetSourcei(key, Al.AL_SOURCE_STATE, out state);
|
||||
if (state == Al.AL_PLAYING || state == Al.AL_PAUSED)
|
||||
@@ -411,7 +430,7 @@ namespace OpenRA
|
||||
|
||||
public void SetListenerPosition(float2 position)
|
||||
{
|
||||
var orientation = new [] { 0f, 0f, 1f, 0f, -1f, 0f };
|
||||
var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f };
|
||||
|
||||
Al.alListener3f(Al.AL_POSITION, position.X, position.Y, 50);
|
||||
Al.alListenerfv(Al.AL_ORIENTATION, ref orientation[0]);
|
||||
@@ -476,7 +495,7 @@ namespace OpenRA
|
||||
{
|
||||
float pos;
|
||||
Al.alGetSourcef(source, Al.AL_SAMPLE_OFFSET, out pos);
|
||||
return pos/22050f;
|
||||
return pos / 22050f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user