Unstable v0.1300.0.0 (February 19th 2021)

This commit is contained in:
Joonas Rikkonen
2021-02-25 13:44:23 +02:00
parent b772654326
commit 24cbef485a
441 changed files with 21343 additions and 8562 deletions
@@ -41,7 +41,7 @@ namespace Barotrauma.Sounds
//MuffleBuffer(floatBuffer, reader.Channels);
CastBuffer(floatBuffer, buffer, readSamples);
return readSamples * 2;
return readSamples;
}
static void MuffleBuffer(float[] buffer, int sampleRate, int channelCount)
@@ -76,8 +76,6 @@ namespace Barotrauma.Sounds
protected set;
}
public bool IgnoreMuffling { get; set; }
/// <summary>
/// How many instances of the same sound clip can be playing at the same time
/// </summary>
@@ -736,11 +736,6 @@ namespace Barotrauma.Sounds
if (FilledByNetwork)
{
if (Sound is VoipSound voipSound)
{
voipSound.ApplyFilters(buffer, readSamples);
}
if (readSamples <= 0)
{
streamAmplitude *= 0.5f;
@@ -752,13 +747,18 @@ namespace Barotrauma.Sounds
}
else
{
if (Sound is VoipSound voipSound)
{
voipSound.ApplyFilters(buffer, readSamples);
}
decayTimer = 0;
}
}
else if (Sound.StreamsReliably)
{
streamSeekPos += readSamples;
if (readSamples < STREAM_BUFFER_SIZE)
streamSeekPos += readSamples * 2;
if (readSamples * 2 < STREAM_BUFFER_SIZE)
{
if (looping)
{
@@ -775,7 +775,7 @@ namespace Barotrauma.Sounds
{
streamBufferAmplitudes[index] = readAmplitude;
Al.BufferData<short>(streamBuffers[index], Sound.ALFormat, buffer, readSamples, Sound.SampleRate);
Al.BufferData<short>(streamBuffers[index], Sound.ALFormat, buffer, readSamples * 2, Sound.SampleRate);
alError = Al.GetError();
if (alError != Al.NoError)
@@ -561,13 +561,13 @@ namespace Barotrauma.Sounds
}
}
public void SetCategoryMuffle(string category,bool muffle)
public void SetCategoryMuffle(string category, bool muffle)
{
if (Disabled) { return; }
category = category.ToLower();
if (categoryModifiers == null) categoryModifiers = new Dictionary<string, CategoryModifier>();
if (categoryModifiers == null) { categoryModifiers = new Dictionary<string, CategoryModifier>(); }
if (!categoryModifiers.ContainsKey(category))
{
categoryModifiers.Add(category, new CategoryModifier(0, 1.0f, muffle));
@@ -585,7 +585,7 @@ namespace Barotrauma.Sounds
{
if (playingChannels[i][j] != null && playingChannels[i][j].IsPlaying)
{
if (playingChannels[i][j].Category.ToLower() == category) playingChannels[i][j].Muffled = muffle;
if (playingChannels[i][j]?.Category.ToLower() == category) { playingChannels[i][j].Muffled = muffle; }
}
}
}
@@ -597,7 +597,7 @@ namespace Barotrauma.Sounds
if (Disabled) { return false; }
category = category.ToLower();
if (categoryModifiers == null || !categoryModifiers.ContainsKey(category)) return false;
if (categoryModifiers == null || !categoryModifiers.ContainsKey(category)) { return false; }
return categoryModifiers[category].Muffle;
}
@@ -706,9 +706,11 @@ namespace Barotrauma.Sounds
}
bool areStreamsPlaying = false;
ManualResetEvent streamMre = null;
void UpdateStreaming()
{
streamMre = new ManualResetEvent(false);
bool killThread = false;
while (!killThread)
{
@@ -745,14 +747,20 @@ namespace Barotrauma.Sounds
}
}
}
streamMre.WaitOne(10);
streamMre.Reset();
lock (threadDeathMutex)
{
areStreamsPlaying = !killThread;
}
Thread.Sleep(10); //TODO: use a separate thread for network audio?
}
}
public void ForceStreamUpdate()
{
streamMre?.Set();
}
private void ReloadSounds()
{
for (int i = loadedSounds.Count - 1; i >= 0; i--)
@@ -195,14 +195,21 @@ namespace Barotrauma
{
case "music":
var newMusicClip = new BackgroundMusic(soundElement);
musicClips.AddIfNotNull(newMusicClip);
if (loadedSoundElements != null)
if (File.Exists(newMusicClip.File))
{
if (newMusicClip.Type.Equals("menu", StringComparison.OrdinalIgnoreCase))
musicClips.AddIfNotNull(newMusicClip);
if (loadedSoundElements != null)
{
targetMusic[0] = newMusicClip;
if (newMusicClip.Type.Equals("menu", StringComparison.OrdinalIgnoreCase))
{
targetMusic[0] = newMusicClip;
}
}
}
else
{
DebugConsole.NewMessage($"Music file \"{newMusicClip.File}\" not found.");
}
break;
case "splash":
SplashSounds.AddIfNotNull(GameMain.SoundManager.LoadSound(soundElement, false));
@@ -411,7 +418,11 @@ namespace Barotrauma
if (animController.HeadInWater)
{
ambienceVolume = 1.0f;
ambienceVolume += animController.Limbs[0].LinearVelocity.Length();
float limbSpeed = animController.Limbs[0].LinearVelocity.Length();
if (MathUtils.IsValid(limbSpeed))
{
ambienceVolume += limbSpeed;
}
}
}
@@ -455,6 +466,13 @@ namespace Barotrauma
GameAnalyticsManager.AddErrorEventOnce("SoundPlayer.UpdateWaterAmbience:InvalidVolume", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
movementSoundVolume = 0.0f;
}
if (!MathUtils.IsValid(insideSubFactor))
{
string errorMsg = "Failed to update water ambience volume - inside sub value invalid (" + insideSubFactor + ")";
DebugConsole.Log(errorMsg);
GameAnalyticsManager.AddErrorEventOnce("SoundPlayer.UpdateWaterAmbience:InvalidVolume", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg);
insideSubFactor = 0.0f;
}
}
for (int i = 0; i < 3; i++)
@@ -477,9 +495,10 @@ namespace Barotrauma
break;
}
// Consider the volume set in sounds.xml
if (sound != null) { volume *= sound.BaseGain; }
if (sound == null) { continue; }
// Consider the volume set in sounds.xml
volume *= sound.BaseGain;
if ((waterAmbienceChannels[i] == null || !waterAmbienceChannels[i].IsPlaying) && volume > 0.01f)
{
waterAmbienceChannels[i] = sound.Play(volume, "waterambience");
@@ -759,7 +778,7 @@ namespace Barotrauma
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, float? freqMult = null, Hull hullGuess = null)
public static SoundChannel PlaySound(Sound sound, Vector2 position, float? volume = null, float? range = null, float? freqMult = null, Hull hullGuess = null, bool ignoreMuffling = false)
{
if (sound == null)
{
@@ -774,7 +793,7 @@ namespace Barotrauma
{
return null;
}
bool muffle = !sound.IgnoreMuffling && ShouldMuffleSound(Character.Controlled, position, far, hullGuess);
bool muffle = !ignoreMuffling && ShouldMuffleSound(Character.Controlled, position, far, hullGuess);
return sound.Play(volume ?? sound.BaseGain, far, freqMult ?? 1.0f, position, muffle: muffle);
}
@@ -875,7 +894,17 @@ namespace Barotrauma
if (currentMusic[i] == null || (musicChannel[i] == null || !musicChannel[i].IsPlaying))
{
DisposeMusicChannel(i);
currentMusic[i] = GameMain.SoundManager.LoadSound(targetMusic[i].File, true);
try
{
currentMusic[i] = GameMain.SoundManager.LoadSound(targetMusic[i].File, true);
}
catch (System.IO.InvalidDataException e)
{
DebugConsole.ThrowError($"Failed to load the music clip \"{targetMusic[i].File}\".", e);
musicClips.Remove(targetMusic[i]);
targetMusic[i] = null;
break;
}
musicChannel[i] = currentMusic[i].Play(0.0f, "music");
if (targetMusic[i].ContinueFromPreviousTime)
{
@@ -959,7 +988,7 @@ namespace Barotrauma
return "wreck";
}
if (Level.IsLoadedOutpost && Character.Controlled.Submarine == Level.Loaded.StartOutpost)
if (Level.IsLoadedOutpost)
{
// Only return music type for location types which have music tracks defined
var locationType = Level.Loaded.StartLocation?.Type?.Identifier?.ToLowerInvariant();
@@ -971,13 +1000,17 @@ namespace Barotrauma
}
Submarine targetSubmarine = Character.Controlled?.Submarine;
if ((targetSubmarine != null && targetSubmarine.AtDamageDepth) ||
(GameMain.GameScreen != null && Screen.Selected == GameMain.GameScreen && Level.Loaded != null && Level.Loaded.GetRealWorldDepth(GameMain.GameScreen.Cam.Position.Y) > Level.Loaded.RealWorldCrushDepth))
if (targetSubmarine != null && targetSubmarine.AtDamageDepth)
{
return "deep";
}
if (GameMain.GameScreen != null && Screen.Selected == GameMain.GameScreen && Submarine.MainSub != null &&
Level.Loaded != null && Level.Loaded.GetRealWorldDepth(GameMain.GameScreen.Cam.Position.Y) > Submarine.MainSub.RealWorldCrushDepth)
{
return "deep";
}
if (targetSubmarine != null)
if (targetSubmarine != null)
{
float floodedArea = 0.0f;
float totalArea = 0.0f;
@@ -1001,7 +1034,7 @@ namespace Barotrauma
foreach (Character character in Character.CharacterList)
{
if (character.IsDead || !character.Enabled) continue;
if (!(character.AIController is EnemyAIController enemyAI) || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) { continue; }
if (!(character.AIController is EnemyAIController enemyAI) || !enemyAI.Enabled || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) { continue; }
if (targetSubmarine != null)
{
@@ -1025,7 +1058,8 @@ namespace Barotrauma
{
return "levelend";
}
if (Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0)
if (Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0 &&
Level.Loaded?.Type == LevelData.LevelType.LocationConnection)
{
return "start";
}
@@ -107,7 +107,7 @@ namespace Barotrauma.Sounds
readAmount += buf.Length;
}
}
return readAmount*2;
return readAmount;
}
public override void Dispose()
@@ -1,4 +1,5 @@
using Barotrauma.Networking;
using Barotrauma.IO;
using Barotrauma.Networking;
using Microsoft.Xna.Framework;
using OpenAL;
using System;
@@ -35,14 +36,15 @@ namespace Barotrauma.Sounds
public float Near { get; private set; }
public float Far { get; private set; }
private static BiQuad[] muffleFilters = new BiQuad[]
private BiQuad[] muffleFilters = new BiQuad[]
{
new LowpassFilter(VoipConfig.FREQUENCY, 800)
};
private static BiQuad[] radioFilters = new BiQuad[]
private BiQuad[] radioFilters = new BiQuad[]
{
new BandpassFilter(VoipConfig.FREQUENCY, 2000)
};
private const float PostRadioFilterBoost = 1.2f;
private float gain;
public float Gain
@@ -104,7 +106,7 @@ namespace Barotrauma.Sounds
if (gain * GameMain.Config.VoiceChatVolume > 1.0f) //TODO: take distance into account?
{
fVal = Math.Clamp(fVal * gain * GameMain.Config.VoiceChatVolume, -1.0f, 1.0f);
fVal = Math.Clamp(fVal * gain * GameMain.Config.VoiceChatVolume, -1f, 1f);
}
if (UseMuffleFilter)
@@ -118,7 +120,7 @@ namespace Barotrauma.Sounds
{
foreach (var filter in radioFilters)
{
fVal = filter.Process(fVal);
fVal = Math.Clamp(filter.Process(fVal) * PostRadioFilterBoost, -1f, 1f);
}
}
buffer[i] = FloatToShort(fVal);
@@ -154,7 +156,7 @@ namespace Barotrauma.Sounds
{
VoipConfig.Decoder.Decode(compressedBuffer, 0, compressedSize, buffer, 0, VoipConfig.BUFFER_SIZE);
bufferID++;
return VoipConfig.BUFFER_SIZE * 2;
return VoipConfig.BUFFER_SIZE;
}
if (bufferID < queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1)) bufferID = queue.LatestBufferID - (VoipQueue.BUFFER_COUNT - 1);
}