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 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs
index 2af9d1ebd8..84100ef33d 100644
--- a/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs
+++ b/Content.Client/EscapeMenu/UI/Tabs/AudioTab.xaml.cs
@@ -1,16 +1,12 @@
-using System;
using Content.Shared.CCVar;
-using Robust.Client.Audio.Midi;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared;
-using Robust.Shared.Maths;
using Robust.Shared.Configuration;
-using Robust.Shared.IoC;
-using Robust.Shared.Localization;
+using Range = Robust.Client.UserInterface.Controls.Range;
namespace Content.Client.EscapeMenu.UI.Tabs
{
@@ -25,16 +21,19 @@ namespace Content.Client.EscapeMenu.UI.Tabs
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
- AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
ApplyButton.OnPressed += OnApplyButtonPressed;
ResetButton.OnPressed += OnResetButtonPressed;
MasterVolumeSlider.OnValueChanged += OnMasterVolumeSliderChanged;
MidiVolumeSlider.OnValueChanged += OnMidiVolumeSliderChanged;
- AmbienceCheckBox.OnToggled += OnAmbienceCheckToggled;
+ AmbienceVolumeSlider.OnValueChanged += OnAmbienceVolumeSliderChanged;
+ AmbienceSoundsSlider.OnValueChanged += OnAmbienceSoundsSliderChanged;
LobbyMusicCheckBox.OnToggled += OnLobbyMusicCheckToggled;
+ AmbienceSoundsSlider.MinValue = _cfg.GetCVar(CCVars.MinMaxAmbientSourcesConfigured);
+ AmbienceSoundsSlider.MaxValue = _cfg.GetCVar(CCVars.MaxMaxAmbientSourcesConfigured);
+
Reset();
}
@@ -44,22 +43,27 @@ namespace Content.Client.EscapeMenu.UI.Tabs
ResetButton.OnPressed -= OnResetButtonPressed;
MasterVolumeSlider.OnValueChanged -= OnMasterVolumeSliderChanged;
MidiVolumeSlider.OnValueChanged -= OnMidiVolumeSliderChanged;
- AmbienceCheckBox.OnToggled -= OnAmbienceCheckToggled;
+ AmbienceVolumeSlider.OnValueChanged -= OnAmbienceVolumeSliderChanged;
base.Dispose(disposing);
}
- private void OnMasterVolumeSliderChanged(Robust.Client.UserInterface.Controls.Range range)
+ private void OnAmbienceVolumeSliderChanged(Range obj)
+ {
+ UpdateChanges();
+ }
+
+ private void OnAmbienceSoundsSliderChanged(Range obj)
+ {
+ UpdateChanges();
+ }
+
+ private void OnMasterVolumeSliderChanged(Range range)
{
_clydeAudio.SetMasterVolume(MasterVolumeSlider.Value / 100);
UpdateChanges();
}
- private void OnMidiVolumeSliderChanged(Robust.Client.UserInterface.Controls.Range range)
- {
- UpdateChanges();
- }
-
- private void OnAmbienceCheckToggled(BaseButton.ButtonEventArgs args)
+ private void OnMidiVolumeSliderChanged(Range range)
{
UpdateChanges();
}
@@ -73,7 +77,8 @@ namespace Content.Client.EscapeMenu.UI.Tabs
{
_cfg.SetCVar(CVars.AudioMasterVolume, MasterVolumeSlider.Value / 100);
_cfg.SetCVar(CVars.MidiVolume, LV100ToDB(MidiVolumeSlider.Value));
- _cfg.SetCVar(CCVars.AmbienceBasicEnabled, AmbienceCheckBox.Pressed);
+ _cfg.SetCVar(CCVars.AmbienceVolume, LV100ToDB(AmbienceVolumeSlider.Value));
+ _cfg.SetCVar(CCVars.MaxAmbientSources, (int)AmbienceSoundsSlider.Value);
_cfg.SetCVar(CCVars.LobbyMusicEnabled, LobbyMusicCheckBox.Pressed);
_cfg.SaveToFile();
UpdateChanges();
@@ -88,7 +93,8 @@ namespace Content.Client.EscapeMenu.UI.Tabs
{
MasterVolumeSlider.Value = _cfg.GetCVar(CVars.AudioMasterVolume) * 100;
MidiVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CVars.MidiVolume));
- AmbienceCheckBox.Pressed = _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
+ AmbienceVolumeSlider.Value = DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume));
+ AmbienceSoundsSlider.Value = _cfg.GetCVar(CCVars.MaxAmbientSources);
LobbyMusicCheckBox.Pressed = _cfg.GetCVar(CCVars.LobbyMusicEnabled);
UpdateChanges();
}
@@ -109,18 +115,23 @@ namespace Content.Client.EscapeMenu.UI.Tabs
private void UpdateChanges()
{
var isMasterVolumeSame =
- System.Math.Abs(MasterVolumeSlider.Value - _cfg.GetCVar(CVars.AudioMasterVolume) * 100) < 0.01f;
+ Math.Abs(MasterVolumeSlider.Value - _cfg.GetCVar(CVars.AudioMasterVolume) * 100) < 0.01f;
var isMidiVolumeSame =
- System.Math.Abs(MidiVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.MidiVolume))) < 0.01f;
- var isAmbienceSame = AmbienceCheckBox.Pressed == _cfg.GetCVar(CCVars.AmbienceBasicEnabled);
+ Math.Abs(MidiVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CVars.MidiVolume))) < 0.01f;
+ var isAmbientVolumeSame =
+ Math.Abs(AmbienceVolumeSlider.Value - DBToLV100(_cfg.GetCVar(CCVars.AmbienceVolume))) < 0.01f;
+ var isAmbientSoundsSame = (int)AmbienceSoundsSlider.Value == _cfg.GetCVar(CCVars.MaxAmbientSources);
var isLobbySame = LobbyMusicCheckBox.Pressed == _cfg.GetCVar(CCVars.LobbyMusicEnabled);
- var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbienceSame && isLobbySame;
+ var isEverythingSame = isMasterVolumeSame && isMidiVolumeSame && isAmbientVolumeSame && isAmbientSoundsSame && isLobbySame;
ApplyButton.Disabled = isEverythingSame;
ResetButton.Disabled = isEverythingSame;
MasterVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", MasterVolumeSlider.Value / 100));
MidiVolumeLabel.Text =
Loc.GetString("ui-options-volume-percent", ("volume", MidiVolumeSlider.Value / 100));
+ AmbienceVolumeLabel.Text =
+ Loc.GetString("ui-options-volume-percent", ("volume", AmbienceVolumeSlider.Value / 100));
+ AmbienceSoundsLabel.Text = ((int)AmbienceSoundsSlider.Value).ToString();
}
}
}
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index fa093fb33c..13d3835bc7 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -22,23 +22,40 @@ namespace Content.Shared.CCVar
*/
///
- /// Whether the basic 'hum' ambience will be enabled.
- ///
- public static readonly CVarDef AmbienceBasicEnabled =
- CVarDef.Create("ambience.basic_enabled", true, CVar.ARCHIVE | CVar.CLIENTONLY);
-
- ///
- /// How long we'll wait until re-sampling nearby objects for ambience.
+ /// How long we'll wait until re-sampling nearby objects for ambience. Should be pretty fast, but doesn't have to match the tick rate.
///
public static readonly CVarDef AmbientCooldown =
- CVarDef.Create("ambience.cooldown", 0.1f, CVar.REPLICATED | CVar.SERVER);
+ CVarDef.Create("ambience.cooldown", 0.1f, CVar.ARCHIVE | CVar.CLIENTONLY);
+ ///
+ /// How large of a range to sample for ambience.
+ ///
public static readonly CVarDef AmbientRange =
CVarDef.Create("ambience.range", 5f, CVar.REPLICATED | CVar.SERVER);
+ ///
+ /// Maximum simultaneous ambient sounds.
+ ///
public static readonly CVarDef MaxAmbientSources =
- CVarDef.Create("ambience.max_sounds", 64, CVar.REPLICATED | CVar.SERVER);
+ CVarDef.Create("ambience.max_sounds", 16, CVar.ARCHIVE | CVar.CLIENTONLY);
+ ///
+ /// The minimum value the user can set for ambience.max_sounds
+ ///
+ public static readonly CVarDef MinMaxAmbientSourcesConfigured =
+ CVarDef.Create("ambience.min_max_sounds_configured", 16, CVar.REPLICATED | CVar.SERVER | CVar.CHEAT);
+
+ ///
+ /// The maximum value the user can set for ambience.max_sounds
+ ///
+ public static readonly CVarDef MaxMaxAmbientSourcesConfigured =
+ CVarDef.Create("ambience.max_max_sounds_configured", 64, CVar.REPLICATED | CVar.SERVER | CVar.CHEAT);
+
+ ///
+ /// Ambience volume.
+ ///
+ public static readonly CVarDef AmbienceVolume =
+ CVarDef.Create("ambience.volume", 0.0f, CVar.ARCHIVE | CVar.CLIENTONLY);
/*
* Status
*/
diff --git a/Resources/Audio/Ambience/Objects/flowing_water_open.ogg b/Resources/Audio/Ambience/Objects/flowing_water_open.ogg
new file mode 100644
index 0000000000..3c6e136edf
Binary files /dev/null and b/Resources/Audio/Ambience/Objects/flowing_water_open.ogg differ
diff --git a/Resources/Audio/Ambience/Objects/license.txt b/Resources/Audio/Ambience/Objects/license.txt
index 1a671be530..36750672e0 100644
--- a/Resources/Audio/Ambience/Objects/license.txt
+++ b/Resources/Audio/Ambience/Objects/license.txt
@@ -1,4 +1,6 @@
circular_saw.ogg - https://freesound.org/people/derjuli/sounds/448133/ and clipped - CC0-1.0
gas_pump - https://freesound.org/people/karinalarasart/sounds/441419/ - CC0-1.0
-gas_hiss - https://freesound.org/people/geodylabs/sounds/122803/ - CC BY 3.0
+gas_hiss - https://freesound.org/people/geodylabs/sounds/122803/ - CC-BY-3.0
gas_vent - https://freesound.org/people/kyles/sounds/453642/ - CC0-1.0
+flowing_water_open - https://freesound.org/people/sterferny/sounds/382322/ - CC0-1.0
+server_fans - https://freesound.org/people/DeVern/sounds/610761/ - CC-BY-3.0
diff --git a/Resources/Audio/Ambience/Objects/server_fans.ogg b/Resources/Audio/Ambience/Objects/server_fans.ogg
new file mode 100644
index 0000000000..3af452a188
Binary files /dev/null and b/Resources/Audio/Ambience/Objects/server_fans.ogg differ
diff --git a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
index eb06d65f58..11a5f5e2fc 100644
--- a/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
+++ b/Resources/Locale/en-US/escape-menu/ui/options-menu.ftl
@@ -13,7 +13,8 @@ ui-options-reset-all = Reset All
ui-options-master-volume = Master Volume:
ui-options-midi-volume = MIDI (Instrument) Volume:
-ui-options-ambient-hum = Ambient Hum
+ui-options-ambience-volume = Ambience volume:
+ui-options-ambience-max-sounds = Ambience simultaneous sounds:
ui-options-lobby-music = Lobby Music
ui-options-volume-label = Volume
ui-options-volume-percent = { TOSTRING($volume, "P0") }
@@ -152,4 +153,4 @@ ui-options-function-loadout9 = Hotbar Loadout 9
## Network menu
-ui-options-net-interp-ratio = Network Smoothing
\ No newline at end of file
+ui-options-net-interp-ratio = Network Smoothing
diff --git a/Resources/Prototypes/Entities/Structures/Machines/research.yml b/Resources/Prototypes/Entities/Structures/Machines/research.yml
index 613c37ab87..df5125c468 100644
--- a/Resources/Prototypes/Entities/Structures/Machines/research.yml
+++ b/Resources/Prototypes/Entities/Structures/Machines/research.yml
@@ -29,7 +29,11 @@
SheetSteel1:
min: 1
max: 2
-
+ - type: AmbientSound
+ volume: -9
+ range: 5
+ sound:
+ path: /Audio/Ambience/Objects/server_fans.ogg
- type: entity
id: BaseResearchAndDevelopmentPointSource
parent: BaseMachinePowered
diff --git a/Resources/Prototypes/Entities/Structures/hydro_tray.yml b/Resources/Prototypes/Entities/Structures/hydro_tray.yml
index ed8ac3c5d3..13f02d018d 100644
--- a/Resources/Prototypes/Entities/Structures/hydro_tray.yml
+++ b/Resources/Prototypes/Entities/Structures/hydro_tray.yml
@@ -39,4 +39,8 @@
- type: Wires
BoardName: "HydroponicsTray"
LayoutId: HydroponicsTray
-
+ - type: AmbientSound
+ volume: -9
+ range: 5
+ sound:
+ path: /Audio/Ambience/Objects/flowing_water_open.ogg