v0.10.5.1

This commit is contained in:
Juan Pablo Arce
2020-09-22 11:31:56 -03:00
parent 44032d0ae0
commit 0002ad2c50
343 changed files with 12276 additions and 5023 deletions
@@ -114,12 +114,17 @@ namespace Barotrauma.Sounds
public virtual SoundChannel Play(float gain, float range, Vector2 position, bool muffle = false)
{
return new SoundChannel(this, gain, new Vector3(position.X, position.Y, 0.0f), range * 0.4f, range, "default", muffle);
return new SoundChannel(this, gain, new Vector3(position.X, position.Y, 0.0f), 1.0f, range * 0.4f, range, "default", muffle);
}
public virtual SoundChannel Play(Vector3? position, float gain, bool muffle = false)
public virtual SoundChannel Play(float gain, float range, float freqMult, Vector2 position, bool muffle = false)
{
return new SoundChannel(this, gain, position, BaseNear, BaseFar, "default", muffle);
return new SoundChannel(this, gain, new Vector3(position.X, position.Y, 0.0f), freqMult, range * 0.4f, range, "default", muffle);
}
public virtual SoundChannel Play(Vector3? position, float gain, float freqMult = 1.0f, bool muffle = false)
{
return new SoundChannel(this, gain, position, freqMult, BaseNear, BaseFar, "default", muffle);
}
public virtual SoundChannel Play(float gain)
@@ -135,7 +140,7 @@ namespace Barotrauma.Sounds
public virtual SoundChannel Play(float? gain, string category)
{
if (Owner.CountPlayingInstances(this) >= MaxSimultaneousInstances) { return null; }
return new SoundChannel(this, gain ?? BaseGain, null, BaseNear, BaseFar, category);
return new SoundChannel(this, gain ?? BaseGain, null, 1.0f, BaseNear, BaseFar, category);
}
static protected void CastBuffer(float[] inBuffer, short[] outBuffer, int length)
@@ -3,6 +3,7 @@ using OpenAL;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
namespace Barotrauma.Sounds
{
@@ -100,28 +101,34 @@ namespace Barotrauma.Sounds
{
if (float.IsNaN(position.Value.X))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.X is NaN");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.X is NaN", appendStackTrace: true);
return;
}
if (float.IsNaN(position.Value.Y))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.Y is NaN");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.Y is NaN", appendStackTrace: true);
return;
}
if (float.IsNaN(position.Value.Z))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.Z is NaN");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.Z is NaN", appendStackTrace: true);
return;
}
if (float.IsInfinity(position.Value.X))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.X is Infinity");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.X is Infinity", appendStackTrace: true);
return;
}
if (float.IsInfinity(position.Value.Y))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.Y is Infinity");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.Y is Infinity", appendStackTrace: true);
return;
}
if (float.IsInfinity(position.Value.Z))
{
throw new Exception("Failed to set source's position: " + debugName + ", position.Z is Infinity");
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", position.Z is Infinity", appendStackTrace: true);
return;
}
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
@@ -129,14 +136,16 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to enable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to enable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.Source3f(alSource, Al.Position, position.Value.X, position.Value.Y, position.Value.Z);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's position: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to set source's position: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
else
@@ -146,14 +155,16 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to disable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to disable source's relative flag: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.Source3f(alSource, Al.Position, 0.0f, 0.0f, 0.0f);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset source's position: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to reset source's position: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
@@ -175,7 +186,8 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's reference distance: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to set source's reference distance: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
@@ -195,7 +207,8 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's max distance: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to set source's max distance: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
@@ -206,6 +219,8 @@ namespace Barotrauma.Sounds
get { return gain; }
set
{
if (!MathUtils.IsValid(value)) { return; }
gain = Math.Clamp(value, 0.0f, 1.0f);
if (ALSourceIndex < 0) { return; }
@@ -219,7 +234,8 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's gain: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to set source's gain: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
@@ -241,12 +257,41 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's looping state: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to set source's looping state: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
}
public float frequencyMultiplier;
public float FrequencyMultiplier
{
get
{
return frequencyMultiplier;
}
set
{
if (value < 0.25f || value > 4.0f)
{
DebugConsole.ThrowError($"Frequency multiplier out of range: {value}" + Environment.StackTrace);
}
frequencyMultiplier = Math.Clamp(value, 0.25f, 4.0f);
if (ALSourceIndex < 0) { return; }
uint alSource = Sound.Owner.GetSourceFromIndex(Sound.SourcePoolIndex, ALSourceIndex);
Al.Sourcef(alSource, Al.Pitch, frequencyMultiplier);
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to set source's frequency multiplier: " + debugName + ", " + Al.GetErrorString(alError));
}
}
}
public bool FilledByNetwork
{
get;
@@ -276,7 +321,8 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.SourceStop(alSource);
@@ -284,7 +330,8 @@ namespace Barotrauma.Sounds
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to stop source: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to stop source: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.Sourcei(alSource, Al.Buffer, muffled ? (int)Sound.ALMuffledBuffer : (int)Sound.ALBuffer);
@@ -292,21 +339,24 @@ namespace Barotrauma.Sounds
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to bind buffer to source: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to bind buffer to source: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.SourcePlay(alSource);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to replay source: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to replay source: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
Al.Sourcei(alSource, Al.SampleOffset, playbackPos);
alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to reset playback position: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to reset playback position: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return;
}
}
}
@@ -329,7 +379,8 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to get source's playback position: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return 0.0f;
}
return Sound.GetAmplitudeAtPlaybackPos(playbackPos);
}
@@ -408,14 +459,15 @@ namespace Barotrauma.Sounds
int alError = Al.GetError();
if (alError != Al.NoError)
{
throw new Exception("Failed to determine playing state from source: " + debugName + ", " + Al.GetErrorString(alError));
DebugConsole.ThrowError("Failed to determine playing state from source: " + debugName + ", " + Al.GetErrorString(alError), appendStackTrace: true);
return false;
}
bool playing = state == Al.Playing;
return playing;
}
}
public SoundChannel(Sound sound, float gain, Vector3? position, float near, float far, string category, bool muffle = false)
public SoundChannel(Sound sound, float gain, Vector3? position, float freqMult, float near, float far, string category, bool muffle = false)
{
Sound = sound;
@@ -517,6 +569,7 @@ namespace Barotrauma.Sounds
this.Position = position;
this.Gain = gain;
this.FrequencyMultiplier = freqMult;
this.Looping = false;
this.Near = near;
this.Far = far;
@@ -632,10 +685,10 @@ namespace Barotrauma.Sounds
public void UpdateStream()
{
if (!IsStream) { throw new Exception("Called UpdateStream on a non-streamed sound channel!"); }
try
{
if (!IsStream) { throw new Exception("Called UpdateStream on a non-streamed sound channel!"); }
Monitor.Enter(mutex);
if (!reachedEndSample)
{
@@ -630,10 +630,10 @@ namespace Barotrauma
{
var sound = GetSound(soundTag);
if (sound == null) { return null; }
return PlaySound(sound, position, volume ?? sound.BaseGain, range ?? sound.BaseFar, hullGuess);
return PlaySound(sound, position, volume ?? sound.BaseGain, range ?? sound.BaseFar, 1.0f, hullGuess);
}
public static SoundChannel PlaySound(Sound sound, Vector2 position, float? volume = null, float? range = null, Hull hullGuess = null)
public static SoundChannel PlaySound(Sound sound, Vector2 position, float? volume = null, float? range = null, float? freqMult = null, Hull hullGuess = null)
{
if (sound == null)
{
@@ -649,7 +649,7 @@ namespace Barotrauma
return null;
}
bool muffle = !sound.IgnoreMuffling && ShouldMuffleSound(Character.Controlled, position, far, hullGuess);
return sound.Play(volume ?? sound.BaseGain, far, position, muffle: muffle);
return sound.Play(volume ?? sound.BaseGain, far, freqMult ?? 1.0f, position, muffle: muffle);
}
private static void UpdateMusic(float deltaTime)
@@ -60,7 +60,7 @@ namespace Barotrauma.Sounds
throw new InvalidOperationException();
}
public override SoundChannel Play(Vector3? position, float gain, bool muffle = false)
public override SoundChannel Play(Vector3? position, float gain, float freqMult = 1.0f, bool muffle = false)
{
throw new InvalidOperationException();
}
@@ -76,7 +76,7 @@ namespace Barotrauma.Sounds
soundChannel = null;
}
}
chn = new SoundChannel(this, gain, null, 1.0f, 3.0f, "video", false);
chn = new SoundChannel(this, gain, null, 1.0f, 1.0f, 3.0f, "video", false);
lock (mutex)
{
soundChannel = chn;
@@ -75,7 +75,7 @@ namespace Barotrauma.Sounds
soundChannel = null;
SoundChannel chn = new SoundChannel(this, 1.0f, null, 0.4f, 1.0f, "voip", false);
SoundChannel chn = new SoundChannel(this, 1.0f, null, 1.0f, 0.4f, 1.0f, "voip", false);
soundChannel = chn;
Gain = 1.0f;
}
@@ -130,7 +130,7 @@ namespace Barotrauma.Sounds
throw new InvalidOperationException();
}
public override SoundChannel Play(Vector3? position, float gain, bool muffle = false)
public override SoundChannel Play(Vector3? position, float gain, float freqMult = 1.0f, bool muffle = false)
{
throw new InvalidOperationException();
}