diff --git a/Content.Client/Audio/AmbientSoundSystem.cs b/Content.Client/Audio/AmbientSoundSystem.cs index a9db3f54bf..ac684f8822 100644 --- a/Content.Client/Audio/AmbientSoundSystem.cs +++ b/Content.Client/Audio/AmbientSoundSystem.cs @@ -24,6 +24,7 @@ namespace Content.Client.Audio public sealed class AmbientSoundSystem : SharedAmbientSoundSystem { [Dependency] private EntityLookupSystem _lookup = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IRobustRandom _random = default!; @@ -33,25 +34,28 @@ namespace Content.Client.Audio private float _maxAmbientRange; private float _cooldown; private float _accumulator; + private float _ambienceVolume = 0.0f; /// /// How many times we can be playing 1 particular sound at once. /// - private int _maxSingleSound = 8; + private int MaxSingleSound => (int) (_maxAmbientCount / (16.0f / 6.0f)); private Dictionary _playingSounds = new(); private const float RangeBuffer = 3f; + + public override void Initialize() { base.Initialize(); UpdatesOutsidePrediction = true; - var configManager = IoCManager.Resolve(); - configManager.OnValueChanged(CCVars.AmbientCooldown, SetCooldown, true); - configManager.OnValueChanged(CCVars.MaxAmbientSources, SetAmbientCount, true); - configManager.OnValueChanged(CCVars.AmbientRange, SetAmbientRange, true); + _cfg.OnValueChanged(CCVars.AmbientCooldown, SetCooldown, true); + _cfg.OnValueChanged(CCVars.MaxAmbientSources, SetAmbientCount, true); + _cfg.OnValueChanged(CCVars.AmbientRange, SetAmbientRange, true); + _cfg.OnValueChanged(CCVars.AmbienceVolume, SetAmbienceVolume, true); SubscribeLocalEvent(OnShutdown); } @@ -61,6 +65,7 @@ namespace Content.Client.Audio sound.Stream?.Stop(); } + private void SetAmbienceVolume(float value) => _ambienceVolume = value; private void SetCooldown(float value) => _cooldown = value; private void SetAmbientCount(int value) => _maxAmbientCount = value; private void SetAmbientRange(float value) => _maxAmbientRange = value; @@ -69,10 +74,11 @@ namespace Content.Client.Audio { base.Shutdown(); ClearSounds(); - var configManager = IoCManager.Resolve(); - configManager.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown); - configManager.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount); - configManager.UnsubValueChanged(CCVars.AmbientRange, SetAmbientRange); + + _cfg.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown); + _cfg.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount); + _cfg.UnsubValueChanged(CCVars.AmbientRange, SetAmbientRange); + _cfg.UnsubValueChanged(CCVars.AmbienceVolume, SetAmbienceVolume); } private int PlayingCount(string countSound) @@ -143,7 +149,7 @@ namespace Content.Client.Audio var key = ambientComp.Sound.GetSound(); if (!sourceDict.ContainsKey(key)) - sourceDict[key] = new List(_maxSingleSound); + sourceDict[key] = new List(MaxSingleSound); sourceDict[key].Add(ambientComp); } @@ -151,7 +157,7 @@ namespace Content.Client.Audio foreach (var (key, val) in sourceDict) { sourceDict[key] = val.OrderByDescending(x => - Transform(x.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var dist) ? dist : float.MaxValue).ToList(); + Transform(x.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var dist) ? dist * (x.Volume + 32) : float.MaxValue).ToList(); } return sourceDict; @@ -198,7 +204,7 @@ namespace Content.Client.Audio var sound = comp.Sound.GetSound(); - if (PlayingCount(sound) >= _maxSingleSound) + if (PlayingCount(sound) >= MaxSingleSound) { keys.Remove(key); /*foreach (var toRemove in compsInRange[key]) @@ -212,7 +218,7 @@ namespace Content.Client.Audio var audioParams = AudioHelpers .WithVariation(0.01f) - .WithVolume(comp.Volume) + .WithVolume(comp.Volume + _ambienceVolume) .WithLoop(true) .WithAttenuation(Attenuation.LinearDistance) // Randomise start so 2 sources don't increase their volume. diff --git a/Content.Client/Audio/BackgroundAudioSystem.cs b/Content.Client/Audio/BackgroundAudioSystem.cs index 9e4ce2d1ad..2d946f0367 100644 --- a/Content.Client/Audio/BackgroundAudioSystem.cs +++ b/Content.Client/Audio/BackgroundAudioSystem.cs @@ -29,8 +29,8 @@ namespace Content.Client.Audio private SoundCollectionPrototype _ambientCollection = default!; - private AudioParams _ambientParams = new(-10f, 1, "Master", 0, 0, 0, true, 0f); - private AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f); + private readonly AudioParams _ambientParams = new(-10f, 1, "Master", 0, 0, 0, true, 0f); + private readonly AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f); private IPlayingAudioStream? _ambientStream; private IPlayingAudioStream? _lobbyStream; @@ -41,7 +41,7 @@ namespace Content.Client.Audio _ambientCollection = _prototypeManager.Index("AmbienceBase"); - _configManager.OnValueChanged(CCVars.AmbienceBasicEnabled, AmbienceCVarChanged); + _configManager.OnValueChanged(CCVars.AmbienceVolume, AmbienceCVarChanged); _configManager.OnValueChanged(CCVars.LobbyMusicEnabled, LobbyMusicCVarChanged); _stateManager.OnStateChanged += StateManagerOnStateChanged; @@ -75,7 +75,7 @@ namespace Content.Client.Audio { StartLobbyMusic(); } - else if (args.NewState is GameScreen && _configManager.GetCVar(CCVars.AmbienceBasicEnabled)) + else if (args.NewState is GameScreen) { StartAmbience(); } @@ -94,10 +94,7 @@ namespace Content.Client.Audio else { EndLobbyMusic(); - if (_configManager.GetCVar(CCVars.AmbienceBasicEnabled)) - { - StartAmbience(); - } + StartAmbience(); } } @@ -107,13 +104,9 @@ namespace Content.Client.Audio EndLobbyMusic(); } - private void AmbienceCVarChanged(bool ambienceEnabled) + private void AmbienceCVarChanged(float volume) { - if (!ambienceEnabled) - { - EndAmbience(); - } - else if (_stateManager.CurrentState is GameScreen) + if (_stateManager.CurrentState is GameScreen) { StartAmbience(); } @@ -127,7 +120,7 @@ namespace Content.Client.Audio { EndAmbience(); var file = _robustRandom.Pick(_ambientCollection.PickFiles).ToString(); - _ambientStream = SoundSystem.Play(Filter.Local(), file, _ambientParams); + _ambientStream = SoundSystem.Play(Filter.Local(), file, _ambientParams.WithVolume(_ambientParams.Volume + _configManager.GetCVar(CCVars.AmbienceVolume))); } private void EndAmbience() diff --git a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml index dffb932b78..b6f235ab2b 100644 --- a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml +++ b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml @@ -35,8 +35,33 @@