v1.4.4.1 (Blood in the Water Update)
This commit is contained in:
@@ -31,6 +31,7 @@ namespace Barotrauma.Sounds
|
||||
return;
|
||||
}
|
||||
|
||||
Loading = true;
|
||||
TaskPool.Add(
|
||||
$"LoadSamples {filename}",
|
||||
LoadSamples(reader),
|
||||
@@ -46,6 +47,7 @@ namespace Barotrauma.Sounds
|
||||
playbackAmplitude = result.PlaybackAmplitude;
|
||||
Owner.KillChannels(this); // prevents INVALID_OPERATION error
|
||||
buffers?.Dispose(); buffers = null;
|
||||
Loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public readonly bool StreamsReliably;
|
||||
|
||||
public bool Loading { get; protected set; }
|
||||
|
||||
private readonly SoundManager.SourcePoolIndex sourcePoolIndex = SoundManager.SourcePoolIndex.Default;
|
||||
public virtual SoundManager.SourcePoolIndex SourcePoolIndex
|
||||
{
|
||||
@@ -84,18 +86,34 @@ namespace Barotrauma.Sounds
|
||||
return Owner.IsPlaying(this);
|
||||
}
|
||||
|
||||
public bool LogWarningIfStillLoading()
|
||||
{
|
||||
if (Loading)
|
||||
{
|
||||
if (Level.Loaded is not { Generating: true })
|
||||
{
|
||||
DebugConsole.AddWarning($"Attempted to play the sound {this} while it was still loading.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public virtual SoundChannel Play(float gain, float range, Vector2 position, bool muffle = false)
|
||||
{
|
||||
LogWarningIfStillLoading();
|
||||
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(float gain, float range, float freqMult, Vector2 position, bool muffle = false)
|
||||
{
|
||||
LogWarningIfStillLoading();
|
||||
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)
|
||||
{
|
||||
LogWarningIfStillLoading();
|
||||
return new SoundChannel(this, gain, position, freqMult, BaseNear, BaseFar, "default", muffle);
|
||||
}
|
||||
|
||||
|
||||
@@ -262,6 +262,9 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
public const float MinFrequencyMultiplier = 0.25f;
|
||||
public const float MaxFrequencyMultiplier = 4.0f;
|
||||
|
||||
public float frequencyMultiplier;
|
||||
public float FrequencyMultiplier
|
||||
{
|
||||
@@ -271,11 +274,11 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value < 0.25f || value > 4.0f)
|
||||
if (value is < MinFrequencyMultiplier or > MaxFrequencyMultiplier)
|
||||
{
|
||||
DebugConsole.ThrowError($"Frequency multiplier out of range: {value}" + Environment.StackTrace.CleanupStackTrace());
|
||||
}
|
||||
frequencyMultiplier = Math.Clamp(value, 0.25f, 4.0f);
|
||||
frequencyMultiplier = Math.Clamp(value, MinFrequencyMultiplier, MaxFrequencyMultiplier);
|
||||
|
||||
if (ALSourceIndex < 0) { return; }
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Barotrauma.Sounds
|
||||
listenerPosition = value;
|
||||
Al.Listener3f(Al.Position,value.X,value.Y,value.Z);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
if (alError != Al.NoError && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to set listener position: " + Al.GetErrorString(alError));
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace Barotrauma.Sounds
|
||||
listenerOrientation[0] = value.X; listenerOrientation[1] = value.Y; listenerOrientation[2] = value.Z;
|
||||
Al.Listenerfv(Al.Orientation, listenerOrientation);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
if (alError != Al.NoError && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to set listener target vector: " + Al.GetErrorString(alError));
|
||||
}
|
||||
@@ -83,7 +83,7 @@ namespace Barotrauma.Sounds
|
||||
listenerOrientation[3] = value.X; listenerOrientation[4] = value.Y; listenerOrientation[5] = value.Z;
|
||||
Al.Listenerfv(Al.Orientation, listenerOrientation);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
if (alError != Al.NoError && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to set listener up vector: " + Al.GetErrorString(alError));
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace Barotrauma.Sounds
|
||||
listenerGain = value;
|
||||
Al.Listenerf(Al.Gain, listenerGain);
|
||||
int alError = Al.GetError();
|
||||
if (alError != Al.NoError)
|
||||
if (alError != Al.NoError && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to set listener gain: " + Al.GetErrorString(alError));
|
||||
}
|
||||
@@ -860,14 +860,14 @@ namespace Barotrauma.Sounds
|
||||
|
||||
ReleaseResources(false);
|
||||
|
||||
if (!Alc.MakeContextCurrent(IntPtr.Zero))
|
||||
if (!Alc.MakeContextCurrent(IntPtr.Zero) && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to detach the current ALC context! (error code: " + Alc.GetError(alcDevice).ToString() + ")");
|
||||
}
|
||||
|
||||
Alc.DestroyContext(alcContext);
|
||||
|
||||
if (!Alc.CloseDevice(alcDevice))
|
||||
if (!Alc.CloseDevice(alcDevice) && !GameMain.IsExiting)
|
||||
{
|
||||
throw new Exception("Failed to close ALC device!");
|
||||
}
|
||||
|
||||
@@ -632,7 +632,8 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
IEnumerable<BackgroundMusic> suitableIntensityMusic = Enumerable.Empty<BackgroundMusic>();
|
||||
if (targetMusic[mainTrackIndex] is { MuteIntensityTracks: false } mainTrack && Screen.Selected == GameMain.GameScreen)
|
||||
BackgroundMusic mainTrack = targetMusic[mainTrackIndex];
|
||||
if (mainTrack is not { MuteIntensityTracks: true } && Screen.Selected == GameMain.GameScreen)
|
||||
{
|
||||
float intensity = currentIntensity;
|
||||
if (mainTrack?.ForceIntensityTrack != null)
|
||||
@@ -770,11 +771,16 @@ namespace Barotrauma
|
||||
|
||||
private static IEnumerable<BackgroundMusic> GetSuitableMusicClips(Identifier musicType, float currentIntensity)
|
||||
{
|
||||
return musicClips.Where(music =>
|
||||
music != null &&
|
||||
music.Type == musicType &&
|
||||
return musicClips.Where(music => IsSuitableMusicClip(music, musicType, currentIntensity));
|
||||
}
|
||||
|
||||
private static bool IsSuitableMusicClip(BackgroundMusic music, Identifier musicType, float currentIntensity)
|
||||
{
|
||||
return
|
||||
music != null &&
|
||||
music.Type == musicType &&
|
||||
currentIntensity >= music.IntensityRange.X &&
|
||||
currentIntensity <= music.IntensityRange.Y);
|
||||
currentIntensity <= music.IntensityRange.Y;
|
||||
}
|
||||
|
||||
private static Identifier GetCurrentMusicType()
|
||||
@@ -858,35 +864,42 @@ namespace Barotrauma
|
||||
|
||||
if (totalArea > 0.0f && floodedArea / totalArea > 0.25f) { return "flooded".ToIdentifier(); }
|
||||
}
|
||||
|
||||
float enemyDistThreshold = 5000.0f;
|
||||
|
||||
if (targetSubmarine != null)
|
||||
float intensity = (GameMain.GameSession?.EventManager?.MusicIntensity ?? 0) * 100.0f;
|
||||
bool anyMonsterMusicAvailable =
|
||||
musicClips.Any(m => IsSuitableMusicClip(m, "monster".ToIdentifier(), intensity) || IsSuitableMusicClip(m, "monsterambience".ToIdentifier(), intensity));
|
||||
|
||||
if (anyMonsterMusicAvailable)
|
||||
{
|
||||
enemyDistThreshold = Math.Max(enemyDistThreshold, Math.Max(targetSubmarine.Borders.Width, targetSubmarine.Borders.Height) * 2.0f);
|
||||
}
|
||||
|
||||
foreach (Character character in Character.CharacterList)
|
||||
{
|
||||
if (character.IsDead || !character.Enabled) continue;
|
||||
if (!(character.AIController is EnemyAIController enemyAI) || !enemyAI.Enabled || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) { continue; }
|
||||
|
||||
float enemyDistThreshold = 5000.0f;
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, targetSubmarine.WorldPosition) < enemyDistThreshold * enemyDistThreshold)
|
||||
{
|
||||
return "monster".ToIdentifier();
|
||||
}
|
||||
enemyDistThreshold = Math.Max(enemyDistThreshold, Math.Max(targetSubmarine.Borders.Width, targetSubmarine.Borders.Height) * 2.0f);
|
||||
}
|
||||
else if (Character.Controlled != null)
|
||||
foreach (Character character in Character.CharacterList)
|
||||
{
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, Character.Controlled.WorldPosition) < enemyDistThreshold * enemyDistThreshold)
|
||||
if (character.IsDead || !character.Enabled) { continue; }
|
||||
if (character.AIController is not EnemyAIController { Enabled: true } enemyAI) { continue; }
|
||||
if (!enemyAI.AttackHumans && !enemyAI.AttackRooms) { continue; }
|
||||
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
return "monster".ToIdentifier();
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, targetSubmarine.WorldPosition) < enemyDistThreshold * enemyDistThreshold)
|
||||
{
|
||||
return "monster".ToIdentifier();
|
||||
}
|
||||
}
|
||||
else if (Character.Controlled != null)
|
||||
{
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, Character.Controlled.WorldPosition) < enemyDistThreshold * enemyDistThreshold)
|
||||
{
|
||||
return "monster".ToIdentifier();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (GameMain.GameSession != null)
|
||||
{
|
||||
if (Submarine.Loaded != null && Level.Loaded != null && Submarine.MainSub != null && Submarine.MainSub.AtEndExit)
|
||||
|
||||
@@ -34,6 +34,8 @@ namespace Barotrauma.Sounds
|
||||
public bool UseRadioFilter;
|
||||
public bool UseMuffleFilter;
|
||||
|
||||
public bool UsingRadio;
|
||||
|
||||
public float Near { get; private set; }
|
||||
public float Far { get; private set; }
|
||||
|
||||
@@ -55,7 +57,7 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
if (soundChannel == null) { return; }
|
||||
gain = value;
|
||||
soundChannel.Gain = value * GameSettings.CurrentConfig.Audio.VoiceChatVolume;
|
||||
soundChannel.Gain = value * GameSettings.CurrentConfig.Audio.VoiceChatVolume * client.VoiceVolume;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,8 +66,11 @@ namespace Barotrauma.Sounds
|
||||
get { return soundChannel?.CurrentAmplitude ?? 0.0f; }
|
||||
}
|
||||
|
||||
public VoipSound(string name, SoundManager owner, VoipQueue q) : base(owner, $"VoIP ({name})", true, true, getFullPath: false)
|
||||
private Client client;
|
||||
|
||||
public VoipSound(Client targetClient, SoundManager owner, VoipQueue q) : base(owner, $"VoIP ({targetClient.Name})", true, true, getFullPath: false)
|
||||
{
|
||||
client = targetClient;
|
||||
decoder = VoipConfig.CreateDecoder();
|
||||
|
||||
ALFormat = Al.FormatMono16;
|
||||
@@ -99,7 +104,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public void ApplyFilters(short[] buffer, int readSamples)
|
||||
{
|
||||
float finalGain = gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume;
|
||||
float finalGain = gain * GameSettings.CurrentConfig.Audio.VoiceChatVolume * client.VoiceVolume;
|
||||
for (int i = 0; i < readSamples; i++)
|
||||
{
|
||||
float fVal = ShortToFloat(buffer[i]);
|
||||
|
||||
Reference in New Issue
Block a user