Unstable 1.8.4.0
This commit is contained in:
@@ -122,7 +122,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
static void MuffleBuffer(float[] buffer, int sampleRate)
|
||||
{
|
||||
var filter = new LowpassFilter(sampleRate, 1600);
|
||||
var filter = new LowpassFilter(sampleRate, SoundPlayer.MuffleFilterFrequency);
|
||||
filter.Process(buffer);
|
||||
}
|
||||
|
||||
|
||||
@@ -258,11 +258,11 @@ namespace OpenAL
|
||||
|
||||
public static void GetInteger(IntPtr device, int param, out int data)
|
||||
{
|
||||
int[] dataArr = new int[1];
|
||||
GCHandle handle = GCHandle.Alloc(dataArr,GCHandleType.Pinned);
|
||||
data = 0; // (Optimization: let's pin an integer on the stack instead of an array on the heap, which previously allocated almost a GB of memory)
|
||||
GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);
|
||||
GetIntegerv(device, param, 1, handle.AddrOfPinnedObject());
|
||||
data = Marshal.ReadInt32(handle.AddrOfPinnedObject());
|
||||
handle.Free();
|
||||
data = dataArr[0];
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -62,6 +62,8 @@ namespace Barotrauma.Sounds
|
||||
public float BaseNear;
|
||||
public float BaseFar;
|
||||
|
||||
public bool MuteBackgroundMusic;
|
||||
|
||||
public Sound(SoundManager owner, string filename, bool stream, bool streamsReliably, ContentXElement xElement = null, bool getFullPath = true)
|
||||
{
|
||||
Owner = owner;
|
||||
@@ -102,19 +104,22 @@ namespace Barotrauma.Sounds
|
||||
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);
|
||||
if (Owner.CountPlayingInstances(this) >= MaxSimultaneousInstances) { return null; }
|
||||
return new SoundChannel(this, gain, new Vector3(position.X, position.Y, 0.0f), 1.0f, range * 0.4f, range, SoundManager.SoundCategoryDefault, 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);
|
||||
if (Owner.CountPlayingInstances(this) >= MaxSimultaneousInstances) { return null; }
|
||||
return new SoundChannel(this, gain, new Vector3(position.X, position.Y, 0.0f), freqMult, range * 0.4f, range, SoundManager.SoundCategoryDefault, 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);
|
||||
if (Owner.CountPlayingInstances(this) >= MaxSimultaneousInstances) { return null; }
|
||||
return new SoundChannel(this, gain, position, freqMult, BaseNear, BaseFar, SoundManager.SoundCategoryDefault, muffle);
|
||||
}
|
||||
|
||||
public virtual SoundChannel Play(float gain)
|
||||
@@ -127,7 +132,7 @@ namespace Barotrauma.Sounds
|
||||
return Play(BaseGain);
|
||||
}
|
||||
|
||||
public virtual SoundChannel Play(float? gain, string category)
|
||||
public virtual SoundChannel Play(float? gain, Identifier category)
|
||||
{
|
||||
if (Owner.CountPlayingInstances(this) >= MaxSimultaneousInstances) { return null; }
|
||||
return new SoundChannel(this, gain ?? BaseGain, null, 1.0f, BaseNear, BaseFar, category);
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace Barotrauma.Sounds
|
||||
private set;
|
||||
}
|
||||
|
||||
public SoundSourcePool(int sourceCount = SoundManager.SOURCE_COUNT)
|
||||
public SoundSourcePool(int sourceCount = SoundManager.SourceCount)
|
||||
{
|
||||
int alError;
|
||||
|
||||
@@ -398,8 +398,8 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
private string category;
|
||||
public string Category
|
||||
private Identifier category;
|
||||
public Identifier Category
|
||||
{
|
||||
get { return category; }
|
||||
set
|
||||
@@ -434,6 +434,8 @@ namespace Barotrauma.Sounds
|
||||
private readonly uint[] unqueuedBuffers;
|
||||
private readonly float[] streamBufferAmplitudes;
|
||||
|
||||
public bool MuteBackgroundMusic;
|
||||
|
||||
public int StreamSeekPos
|
||||
{
|
||||
get { return streamSeekPos; }
|
||||
@@ -481,7 +483,7 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
public SoundChannel(Sound sound, float gain, Vector3? position, float freqMult, float near, float far, string category, bool muffle = false)
|
||||
public SoundChannel(Sound sound, float gain, Vector3? position, float freqMult, float near, float far, Identifier category, bool muffle = false)
|
||||
{
|
||||
Sound = sound;
|
||||
|
||||
|
||||
@@ -11,7 +11,12 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
class SoundManager : IDisposable
|
||||
{
|
||||
public const int SOURCE_COUNT = 32;
|
||||
public const int SourceCount = 32;
|
||||
public static readonly Identifier SoundCategoryDefault = "default".ToIdentifier();
|
||||
public static readonly Identifier SoundCategoryUi = "ui".ToIdentifier();
|
||||
public static readonly Identifier SoundCategoryWaterAmbience = "waterambience".ToIdentifier();
|
||||
public static readonly Identifier SoundCategoryMusic = "music".ToIdentifier();
|
||||
public static readonly Identifier SoundCategoryVoip = "voip".ToIdentifier();
|
||||
|
||||
public bool Disabled
|
||||
{
|
||||
@@ -196,7 +201,7 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
private readonly Dictionary<string, CategoryModifier> categoryModifiers = new Dictionary<string, CategoryModifier>();
|
||||
private readonly Dictionary<Identifier, CategoryModifier> categoryModifiers = new Dictionary<Identifier, CategoryModifier>();
|
||||
|
||||
public SoundManager()
|
||||
{
|
||||
@@ -204,7 +209,7 @@ namespace Barotrauma.Sounds
|
||||
updateChannelsThread = null;
|
||||
|
||||
sourcePools = new SoundSourcePool[2];
|
||||
playingChannels[(int)SourcePoolIndex.Default] = new SoundChannel[SOURCE_COUNT];
|
||||
playingChannels[(int)SourcePoolIndex.Default] = new SoundChannel[SourceCount];
|
||||
playingChannels[(int)SourcePoolIndex.Voice] = new SoundChannel[16];
|
||||
|
||||
string deviceName = GameSettings.CurrentConfig.Audio.AudioOutputDevice;
|
||||
@@ -334,7 +339,7 @@ namespace Barotrauma.Sounds
|
||||
return false;
|
||||
}
|
||||
|
||||
sourcePools[(int)SourcePoolIndex.Default] = new SoundSourcePool(SOURCE_COUNT);
|
||||
sourcePools[(int)SourcePoolIndex.Default] = new SoundSourcePool(SourceCount);
|
||||
sourcePools[(int)SourcePoolIndex.Voice] = new SoundSourcePool(16);
|
||||
|
||||
ReloadSounds();
|
||||
@@ -353,11 +358,19 @@ namespace Barotrauma.Sounds
|
||||
throw new System.IO.FileNotFoundException("Sound file \"" + filename + "\" doesn't exist!");
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
||||
sw.Start();
|
||||
#endif
|
||||
Sound newSound = new OggSound(this, filename, stream, null);
|
||||
lock (loadedSounds)
|
||||
{
|
||||
loadedSounds.Add(newSound);
|
||||
}
|
||||
#if DEBUG
|
||||
sw.Stop();
|
||||
System.Diagnostics.Debug.WriteLine($"Loaded sound \"{filename}\" ({sw.ElapsedMilliseconds} ms).");
|
||||
#endif
|
||||
return newSound;
|
||||
}
|
||||
|
||||
@@ -535,10 +548,9 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCategoryGainMultiplier(string category, float gain, int index=0)
|
||||
public void SetCategoryGainMultiplier(Identifier category, float gain, int index=0)
|
||||
{
|
||||
if (Disabled) { return; }
|
||||
category = category.ToLower();
|
||||
lock (categoryModifiers)
|
||||
{
|
||||
if (!categoryModifiers.ContainsKey(category))
|
||||
@@ -566,10 +578,9 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
public float GetCategoryGainMultiplier(string category, int index = -1)
|
||||
public float GetCategoryGainMultiplier(Identifier category, int index = -1)
|
||||
{
|
||||
if (Disabled) { return 0.0f; }
|
||||
category = category.ToLower();
|
||||
lock (categoryModifiers)
|
||||
{
|
||||
if (categoryModifiers == null || !categoryModifiers.TryGetValue(category, out CategoryModifier categoryModifier)) { return 1.0f; }
|
||||
@@ -589,11 +600,10 @@ namespace Barotrauma.Sounds
|
||||
}
|
||||
}
|
||||
|
||||
public void SetCategoryMuffle(string category, bool muffle)
|
||||
public void SetCategoryMuffle(Identifier category, bool muffle)
|
||||
{
|
||||
if (Disabled) { return; }
|
||||
|
||||
category = category.ToLower();
|
||||
lock (categoryModifiers)
|
||||
{
|
||||
if (!categoryModifiers.ContainsKey(category))
|
||||
@@ -614,18 +624,17 @@ 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 == category) { playingChannels[i][j].Muffled = muffle; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GetCategoryMuffle(string category)
|
||||
public bool GetCategoryMuffle(Identifier category)
|
||||
{
|
||||
if (Disabled) { return false; }
|
||||
|
||||
category = category.ToLower();
|
||||
lock (categoryModifiers)
|
||||
{
|
||||
if (categoryModifiers == null || !categoryModifiers.TryGetValue(category, out CategoryModifier categoryModifier)) { return false; }
|
||||
@@ -657,6 +666,7 @@ namespace Barotrauma.Sounds
|
||||
DebugConsole.ThrowError("Playback device has been disconnected. You can select another available device in the settings.");
|
||||
SetAudioOutputDevice("<disconnected>");
|
||||
Disconnected = true;
|
||||
TryRefreshDevice();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -672,10 +682,10 @@ namespace Barotrauma.Sounds
|
||||
{
|
||||
voipAttenuatedGain = 1.0f;
|
||||
}
|
||||
SetCategoryGainMultiplier("default", VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier("ui", VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier("waterambience", VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier("music", VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier(SoundCategoryDefault, VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier(SoundCategoryUi, VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier(SoundCategoryWaterAmbience, VoipAttenuatedGain, 1);
|
||||
SetCategoryGainMultiplier(SoundCategoryMusic, VoipAttenuatedGain, 1);
|
||||
|
||||
if (GameSettings.CurrentConfig.Audio.DynamicRangeCompressionEnabled)
|
||||
{
|
||||
@@ -721,11 +731,11 @@ namespace Barotrauma.Sounds
|
||||
|
||||
public void ApplySettings()
|
||||
{
|
||||
SetCategoryGainMultiplier("default", GameSettings.CurrentConfig.Audio.SoundVolume, 0);
|
||||
SetCategoryGainMultiplier("ui", GameSettings.CurrentConfig.Audio.UiVolume, 0);
|
||||
SetCategoryGainMultiplier("waterambience", GameSettings.CurrentConfig.Audio.SoundVolume, 0);
|
||||
SetCategoryGainMultiplier("music", GameSettings.CurrentConfig.Audio.MusicVolume, 0);
|
||||
SetCategoryGainMultiplier("voip", Math.Min(GameSettings.CurrentConfig.Audio.VoiceChatVolume, 1.0f), 0);
|
||||
SetCategoryGainMultiplier(SoundCategoryDefault, GameSettings.CurrentConfig.Audio.SoundVolume, 0);
|
||||
SetCategoryGainMultiplier(SoundCategoryUi, GameSettings.CurrentConfig.Audio.UiVolume, 0);
|
||||
SetCategoryGainMultiplier(SoundCategoryWaterAmbience, GameSettings.CurrentConfig.Audio.SoundVolume, 0);
|
||||
SetCategoryGainMultiplier(SoundCategoryMusic, GameSettings.CurrentConfig.Audio.MusicVolume, 0);
|
||||
SetCategoryGainMultiplier(SoundCategoryVoip, Math.Min(GameSettings.CurrentConfig.Audio.VoiceChatVolume, 1.0f), 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -872,5 +882,52 @@ namespace Barotrauma.Sounds
|
||||
throw new Exception("Failed to close ALC device!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void TryRefreshDevice()
|
||||
{
|
||||
DebugConsole.NewMessage("Refreshing audio playback device");
|
||||
|
||||
List<string> deviceList = Alc.GetStringList(IntPtr.Zero, Alc.OutputDevicesSpecifier).ToList();
|
||||
int alcError = Alc.GetError(IntPtr.Zero);
|
||||
if (alcError != Alc.NoError)
|
||||
{
|
||||
DebugConsole.ThrowError("Failed to list available audio playback devices: " + alcError.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (deviceList.Any())
|
||||
{
|
||||
string device;
|
||||
|
||||
if (deviceList.Find(n => n.Equals(GameSettings.CurrentConfig.Audio.AudioOutputDevice, StringComparison.OrdinalIgnoreCase))
|
||||
is string availablePreviousDevice)
|
||||
{
|
||||
DebugConsole.NewMessage($" Previous device choice available: {availablePreviousDevice}");
|
||||
device = availablePreviousDevice;
|
||||
}
|
||||
else
|
||||
{
|
||||
device = Alc.GetString(IntPtr.Zero, Alc.DefaultDeviceSpecifier);
|
||||
DebugConsole.NewMessage($" Reverting to default device: {device}");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(device))
|
||||
{
|
||||
device = deviceList[0];
|
||||
DebugConsole.NewMessage($" No default device found, resorting to first available device: {device}");
|
||||
}
|
||||
|
||||
// Save the new device choice and initialize it
|
||||
var currentConfig = GameSettings.CurrentConfig;
|
||||
currentConfig.Audio.AudioOutputDevice = device;
|
||||
GameSettings.SetCurrentConfig(currentConfig);
|
||||
GameMain.SoundManager.InitializeAlcDevice(device);
|
||||
}
|
||||
|
||||
if (GUI.SettingsMenuOpen)
|
||||
{
|
||||
SettingsMenu.Instance?.CreateAudioAndVCTab(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Barotrauma.Extensions;
|
||||
using Barotrauma.IO;
|
||||
using Barotrauma.Sounds;
|
||||
using Microsoft.Xna.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Barotrauma.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace Barotrauma
|
||||
{
|
||||
@@ -16,6 +15,8 @@ namespace Barotrauma
|
||||
private const float MusicLerpSpeed = 1.0f;
|
||||
private const float UpdateMusicInterval = 5.0f;
|
||||
|
||||
public const float MuffleFilterFrequency = 600;
|
||||
|
||||
const int MaxMusicChannels = 6;
|
||||
|
||||
private readonly static BackgroundMusic[] currentMusic = new BackgroundMusic[MaxMusicChannels];
|
||||
@@ -28,9 +29,9 @@ namespace Barotrauma
|
||||
private static float updateMusicTimer;
|
||||
|
||||
//ambience
|
||||
private static Sound waterAmbienceIn => SoundPrefab.WaterAmbienceIn.ActivePrefab.Sound;
|
||||
private static Sound waterAmbienceOut => SoundPrefab.WaterAmbienceOut.ActivePrefab.Sound;
|
||||
private static Sound waterAmbienceMoving => SoundPrefab.WaterAmbienceMoving.ActivePrefab.Sound;
|
||||
private static SoundPrefab waterAmbienceIn => SoundPrefab.WaterAmbienceIn.ActivePrefab;
|
||||
private static SoundPrefab waterAmbienceOut => SoundPrefab.WaterAmbienceOut.ActivePrefab;
|
||||
private static SoundPrefab waterAmbienceMoving => SoundPrefab.WaterAmbienceMoving.ActivePrefab;
|
||||
private static readonly HashSet<SoundChannel> waterAmbienceChannels = new HashSet<SoundChannel>();
|
||||
|
||||
private static float ambientSoundTimer;
|
||||
@@ -190,9 +191,12 @@ namespace Barotrauma
|
||||
{
|
||||
if (volume < 0.01f) { return; }
|
||||
if (chn is not null) { waterAmbienceChannels.Remove(chn); }
|
||||
chn = sound.Play(volume, "waterambience");
|
||||
chn.Looping = true;
|
||||
waterAmbienceChannels.Add(chn);
|
||||
chn = sound.Play(volume, SoundManager.SoundCategoryWaterAmbience);
|
||||
if (chn != null)
|
||||
{
|
||||
chn.Looping = true;
|
||||
waterAmbienceChannels.Add(chn);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -213,9 +217,9 @@ namespace Barotrauma
|
||||
}
|
||||
}
|
||||
|
||||
updateWaterAmbience(waterAmbienceIn, ambienceVolume * (1.0f - movementSoundVolume) * insideSubFactor);
|
||||
updateWaterAmbience(waterAmbienceMoving, ambienceVolume * movementSoundVolume * insideSubFactor);
|
||||
updateWaterAmbience(waterAmbienceOut, 1.0f - insideSubFactor);
|
||||
updateWaterAmbience(waterAmbienceIn.Sound, ambienceVolume * (1.0f - movementSoundVolume) * insideSubFactor * waterAmbienceIn.Volume);
|
||||
updateWaterAmbience(waterAmbienceMoving.Sound, ambienceVolume * movementSoundVolume * insideSubFactor * waterAmbienceMoving.Volume);
|
||||
updateWaterAmbience(waterAmbienceOut.Sound, (1.0f - insideSubFactor) * waterAmbienceOut.Volume);
|
||||
}
|
||||
|
||||
private static void UpdateWaterFlowSounds(float deltaTime)
|
||||
@@ -306,6 +310,7 @@ namespace Barotrauma
|
||||
if (flowSoundChannels[i] == null || !flowSoundChannels[i].IsPlaying)
|
||||
{
|
||||
flowSoundChannels[i] = FlowSounds[i].Sound.Play(1.0f, FlowSoundRange, soundPos);
|
||||
if (flowSoundChannels[i] == null) { continue; }
|
||||
flowSoundChannels[i].Looping = true;
|
||||
}
|
||||
flowSoundChannels[i].Gain = Math.Max(flowVolumeRight[i], flowVolumeLeft[i]);
|
||||
@@ -483,8 +488,20 @@ namespace Barotrauma
|
||||
if (sound == null) { return null; }
|
||||
return PlaySound(sound, position, volume ?? sound.BaseGain, range ?? sound.BaseFar, 1.0f, hullGuess);
|
||||
}
|
||||
public static SoundChannel PlaySound(RoundSound sound, Vector2 position, float? volume = null, Hull hullGuess = null)
|
||||
{
|
||||
return PlaySound(
|
||||
sound.Sound,
|
||||
position,
|
||||
volume ?? sound.Volume,
|
||||
sound.Range,
|
||||
ignoreMuffling: sound.IgnoreMuffling,
|
||||
hullGuess: hullGuess,
|
||||
freqMult: sound.GetRandomFrequencyMultiplier(),
|
||||
muteBackgroundMusic: sound.MuteBackgroundMusic);
|
||||
}
|
||||
|
||||
public static SoundChannel PlaySound(Sound sound, Vector2 position, float? volume = null, float? range = null, float? freqMult = null, Hull hullGuess = null, bool ignoreMuffling = false)
|
||||
public static SoundChannel PlaySound(Sound sound, Vector2 position, float? volume = null, float? range = null, float? freqMult = null, Hull hullGuess = null, bool ignoreMuffling = false, bool muteBackgroundMusic = false)
|
||||
{
|
||||
if (sound == null)
|
||||
{
|
||||
@@ -500,7 +517,12 @@ namespace Barotrauma
|
||||
return null;
|
||||
}
|
||||
bool muffle = !ignoreMuffling && ShouldMuffleSound(Character.Controlled, position, far, hullGuess);
|
||||
return sound.Play(volume ?? sound.BaseGain, far, freqMult ?? 1.0f, position, muffle: muffle);
|
||||
var channel = sound.Play(volume ?? sound.BaseGain, far, freqMult ?? 1.0f, position, muffle: muffle);
|
||||
if (channel != null)
|
||||
{
|
||||
channel.MuteBackgroundMusic = muteBackgroundMusic;
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
public static void DisposeDisabledMusic()
|
||||
@@ -669,7 +691,22 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
LogCurrentMusic();
|
||||
updateMusicTimer = UpdateMusicInterval;
|
||||
updateMusicTimer = UpdateMusicInterval;
|
||||
if (mainTrack != null)
|
||||
{
|
||||
updateMusicTimer += mainTrack.MinimumPlayDuration;
|
||||
}
|
||||
}
|
||||
|
||||
bool muteBackgroundMusic = false;
|
||||
for (int i = 0; i < SoundManager.SourceCount; i++)
|
||||
{
|
||||
SoundChannel playingSoundChannel = GameMain.SoundManager.GetSoundChannelFromIndex(SoundManager.SourcePoolIndex.Default, i);
|
||||
if (playingSoundChannel is { MuteBackgroundMusic: true, IsPlaying: true })
|
||||
{
|
||||
muteBackgroundMusic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int activeTrackCount = targetMusic.Count(m => m != null);
|
||||
@@ -705,7 +742,7 @@ namespace Barotrauma
|
||||
DisposeMusicChannel(i);
|
||||
|
||||
currentMusic[i] = targetMusic[i];
|
||||
musicChannel[i] = currentMusic[i].Sound.Play(0.0f, i == noiseLoopIndex ? "default" : "music");
|
||||
musicChannel[i] = currentMusic[i].Sound.Play(0.0f, i == noiseLoopIndex ? SoundManager.SoundCategoryDefault : SoundManager.SoundCategoryMusic);
|
||||
if (targetMusic[i].ContinueFromPreviousTime)
|
||||
{
|
||||
musicChannel[i].StreamSeekPos = targetMusic[i].PreviousTime;
|
||||
@@ -724,10 +761,14 @@ namespace Barotrauma
|
||||
if (musicChannel[i] == null || !musicChannel[i].IsPlaying)
|
||||
{
|
||||
musicChannel[i]?.Dispose();
|
||||
musicChannel[i] = currentMusic[i].Sound.Play(0.0f, i == noiseLoopIndex ? "default" : "music");
|
||||
musicChannel[i] = currentMusic[i].Sound.Play(0.0f, i == noiseLoopIndex ? SoundManager.SoundCategoryDefault : SoundManager.SoundCategoryMusic);
|
||||
musicChannel[i].Looping = true;
|
||||
}
|
||||
float targetGain = targetMusic[i].Volume;
|
||||
if (muteBackgroundMusic)
|
||||
{
|
||||
targetGain = 0.0f;
|
||||
}
|
||||
if (targetMusic[i].DuckVolume)
|
||||
{
|
||||
targetGain *= (float)Math.Sqrt(1.0f / activeTrackCount);
|
||||
@@ -841,6 +882,51 @@ namespace Barotrauma
|
||||
}
|
||||
|
||||
Submarine targetSubmarine = Character.Controlled?.Submarine;
|
||||
|
||||
float intensity = (GameMain.GameSession?.EventManager?.MusicIntensity ?? 0) * 100.0f;
|
||||
|
||||
float enemyDistThreshold = 5000.0f;
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
enemyDistThreshold = Math.Max(enemyDistThreshold, Math.Max(targetSubmarine.Borders.Width, targetSubmarine.Borders.Height) * 2.0f);
|
||||
}
|
||||
|
||||
List<Character> monsterMusicCharacters = new List<Character>();
|
||||
foreach (Character character in Character.CharacterList)
|
||||
{
|
||||
if (character.IsDead || !character.Enabled) { continue; }
|
||||
if (character.AIController is not EnemyAIController { Enabled: true } enemyAI) { continue; }
|
||||
if (!enemyAI.AttackHumans && !enemyAI.AttackRooms) { continue; }
|
||||
|
||||
bool specificMonsterMusicAvailable =
|
||||
musicClips.Any(m => IsSuitableMusicClip(m, character.Params.MusicType, intensity));
|
||||
|
||||
if (specificMonsterMusicAvailable)
|
||||
{
|
||||
float maxDistSqr = MathF.Pow(enemyDistThreshold * character.Params.MusicRangeMultiplier, 2);
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, targetSubmarine.WorldPosition) < maxDistSqr)
|
||||
{
|
||||
monsterMusicCharacters.Add(character);
|
||||
}
|
||||
}
|
||||
else if (Character.Controlled != null)
|
||||
{
|
||||
if (Vector2.DistanceSquared(character.WorldPosition, Character.Controlled.WorldPosition) < maxDistSqr)
|
||||
{
|
||||
monsterMusicCharacters.Add(character);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (monsterMusicCharacters.Any())
|
||||
{
|
||||
Character chosenCharacter = monsterMusicCharacters.GetRandomByWeight(c => c.Params.MusicCommonness, Rand.RandSync.Unsynced);
|
||||
return chosenCharacter.Params.MusicType;
|
||||
}
|
||||
|
||||
if (targetSubmarine != null && targetSubmarine.AtDamageDepth)
|
||||
{
|
||||
return "deep".ToIdentifier();
|
||||
@@ -865,41 +951,6 @@ namespace Barotrauma
|
||||
if (totalArea > 0.0f && floodedArea / totalArea > 0.25f) { return "flooded".ToIdentifier(); }
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
float enemyDistThreshold = 5000.0f;
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
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 not EnemyAIController { Enabled: true } enemyAI) { continue; }
|
||||
if (!enemyAI.AttackHumans && !enemyAI.AttackRooms) { continue; }
|
||||
|
||||
if (targetSubmarine != null)
|
||||
{
|
||||
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)
|
||||
@@ -956,7 +1007,7 @@ namespace Barotrauma
|
||||
PlayDamageSound(damageType, damage, bodyPosition, 800.0f);
|
||||
}
|
||||
|
||||
public static void PlayDamageSound(string damageType, float damage, Vector2 position, float range = 2000.0f, IEnumerable<Identifier> tags = null)
|
||||
public static void PlayDamageSound(string damageType, float damage, Vector2 position, float range = 2000.0f, IEnumerable<Identifier> tags = null, float gain = 1.0f)
|
||||
{
|
||||
var suitableSounds = damageSounds.Where(s =>
|
||||
s.DamageType == damageType &&
|
||||
@@ -972,14 +1023,14 @@ namespace Barotrauma
|
||||
s.DamageRange == Vector2.Zero || (randomizedDamage >= s.DamageRange.X && randomizedDamage <= s.DamageRange.Y));
|
||||
|
||||
var damageSound = suitableSounds.GetRandomUnsynced();
|
||||
damageSound?.Sound?.Play(1.0f, range, position, muffle: !damageSound.IgnoreMuffling && ShouldMuffleSound(Character.Controlled, position, range, null));
|
||||
damageSound?.Sound?.Play(gain, range, position, muffle: !damageSound.IgnoreMuffling && ShouldMuffleSound(Character.Controlled, position, range, null));
|
||||
}
|
||||
|
||||
public static void PlayUISound(GUISoundType soundType)
|
||||
{
|
||||
GUISound.GUISoundPrefabs
|
||||
.Where(s => s.Type == soundType)
|
||||
.GetRandomUnsynced()?.Sound?.Play(null, "ui");
|
||||
.GetRandomUnsynced()?.Sound?.Play(null, SoundManager.SoundCategoryUi);
|
||||
}
|
||||
|
||||
public static void PlayUISound(GUISoundType? soundType)
|
||||
|
||||
@@ -183,6 +183,9 @@ namespace Barotrauma
|
||||
public readonly ContentPath SoundPath;
|
||||
public readonly ContentXElement Element;
|
||||
public readonly Identifier ElementName;
|
||||
|
||||
public readonly float Volume;
|
||||
|
||||
public Sound Sound { get; private set; }
|
||||
|
||||
public SoundPrefab(ContentXElement element, SoundsFile file, bool stream = false) : base(file, element)
|
||||
@@ -191,6 +194,8 @@ namespace Barotrauma
|
||||
Element = element;
|
||||
ElementName = element.NameAsIdentifier();
|
||||
Sound = GameMain.SoundManager.LoadSound(element, stream: stream);
|
||||
|
||||
Volume = element.GetAttributeFloat(nameof(Volume), 1.0f);
|
||||
}
|
||||
|
||||
public bool IsPlaying()
|
||||
@@ -235,7 +240,6 @@ namespace Barotrauma
|
||||
|
||||
public readonly Identifier Type;
|
||||
public readonly bool DuckVolume;
|
||||
public readonly float Volume;
|
||||
|
||||
public readonly Vector2 IntensityRange;
|
||||
public readonly bool MuteIntensityTracks;
|
||||
@@ -244,6 +248,10 @@ namespace Barotrauma
|
||||
public readonly bool StartFromRandomTime;
|
||||
public readonly bool ContinueFromPreviousTime;
|
||||
public int PreviousTime;
|
||||
/// <summary>
|
||||
/// The music is forced to play at least for this long when it triggers, even if the situation changes and makes the music no longer suitable.
|
||||
/// </summary>
|
||||
public readonly float MinimumPlayDuration;
|
||||
|
||||
public BackgroundMusic(ContentXElement element, SoundsFile file) : base(element, file, stream: true)
|
||||
{
|
||||
@@ -255,9 +263,9 @@ namespace Barotrauma
|
||||
{
|
||||
ForceIntensityTrack = element.GetAttributeFloat(nameof(ForceIntensityTrack), 0.0f);
|
||||
}
|
||||
Volume = element.GetAttributeFloat(nameof(Volume), 1.0f);
|
||||
StartFromRandomTime = element.GetAttributeBool(nameof(StartFromRandomTime), false);
|
||||
ContinueFromPreviousTime = element.GetAttributeBool(nameof(ContinueFromPreviousTime), false);
|
||||
ContinueFromPreviousTime = element.GetAttributeBool(nameof(ContinueFromPreviousTime), false);
|
||||
MinimumPlayDuration = element.GetAttributeFloat(nameof(MinimumPlayDuration), 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ namespace Barotrauma.Sounds
|
||||
soundChannel = null;
|
||||
}
|
||||
}
|
||||
chn = new SoundChannel(this, gain, null, 1.0f, 1.0f, 3.0f, "video", false);
|
||||
chn = new SoundChannel(this, gain, null, 1.0f, 1.0f, 3.0f, "video".ToIdentifier(), false);
|
||||
lock (mutex)
|
||||
{
|
||||
soundChannel = chn;
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Barotrauma.Sounds
|
||||
|
||||
soundChannel = null;
|
||||
|
||||
SoundChannel chn = new SoundChannel(this, 1.0f, null, 1.0f, 0.4f, 1.0f, "voip", false);
|
||||
SoundChannel chn = new SoundChannel(this, 1.0f, null, 1.0f, 0.4f, 1.0f, SoundManager.SoundCategoryVoip, false);
|
||||
soundChannel = chn;
|
||||
Gain = 1.0f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user