Ambience enhancements. (#7073)

This commit is contained in:
Moony
2022-03-12 16:20:31 -06:00
committed by GitHub
parent 6d2c5868a3
commit f5c92caef4
29 changed files with 290 additions and 68 deletions

View File

@@ -11,9 +11,13 @@ using Robust.Shared.Map;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Robust.Shared.Utility;
namespace Content.Client.Audio namespace Content.Client.Audio
{ {
//TODO: This is using a incomplete version of the whole "only play nearest sounds" algo, that breaks down a bit should the ambient sound cap get hit.
//TODO: This'll be fixed when GetEntitiesInRange produces consistent outputs.
/// <summary> /// <summary>
/// Samples nearby <see cref="AmbientSoundComponent"/> and plays audio. /// Samples nearby <see cref="AmbientSoundComponent"/> and plays audio.
/// </summary> /// </summary>
@@ -33,11 +37,11 @@ namespace Content.Client.Audio
/// <summary> /// <summary>
/// How many times we can be playing 1 particular sound at once. /// How many times we can be playing 1 particular sound at once.
/// </summary> /// </summary>
private int _maxSingleSound = 3; private int _maxSingleSound = 8;
private Dictionary<AmbientSoundComponent, (IPlayingAudioStream? Stream, string Sound)> _playingSounds = new(); private Dictionary<AmbientSoundComponent, (IPlayingAudioStream? Stream, string Sound)> _playingSounds = new();
private const float RangeBuffer = 0.5f; private const float RangeBuffer = 3f;
public override void Initialize() public override void Initialize()
{ {
@@ -56,6 +60,7 @@ namespace Content.Client.Audio
public override void Shutdown() public override void Shutdown()
{ {
base.Shutdown(); base.Shutdown();
ClearSounds();
var configManager = IoCManager.Resolve<IConfigurationManager>(); var configManager = IoCManager.Resolve<IConfigurationManager>();
configManager.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown); configManager.UnsubValueChanged(CCVars.AmbientCooldown, SetCooldown);
configManager.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount); configManager.UnsubValueChanged(CCVars.MaxAmbientSources, SetAmbientCount);
@@ -99,22 +104,7 @@ namespace Content.Client.Audio
var coordinates = playerManager.Coordinates; var coordinates = playerManager.Coordinates;
foreach (var (comp, (stream, _)) in _playingSounds.ToArray()) ProcessNearbyAmbience(coordinates);
{
if (!comp.Deleted && comp.Enabled && EntityManager.GetComponent<TransformComponent>(comp.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var range) &&
range <= comp.Range)
{
continue;
}
stream?.Stop();
_playingSounds.Remove(comp);
}
if (_playingSounds.Count >= _maxAmbientCount) return;
SampleNearby(coordinates);
} }
private void ClearSounds() private void ClearSounds()
@@ -127,57 +117,136 @@ namespace Content.Client.Audio
_playingSounds.Clear(); _playingSounds.Clear();
} }
/// <summary> private Dictionary<string, List<AmbientSoundComponent>> GetNearbySources(EntityCoordinates coordinates)
/// Get a list of ambient components in range and determine which ones to start playing.
/// </summary>
private void SampleNearby(EntityCoordinates coordinates)
{ {
var compsInRange = new List<AmbientSoundComponent>(); //TODO: Make this produce a hashset of nearby entities again.
var sourceDict = new Dictionary<string, List<AmbientSoundComponent>>(16);
foreach (var entity in _lookup.GetEntitiesInRange(coordinates, _maxAmbientRange, foreach (var entity in _lookup.GetEntitiesInRange(coordinates, _maxAmbientRange + RangeBuffer, LookupFlags.IncludeAnchored | LookupFlags.Approximate))
LookupFlags.Approximate | LookupFlags.IncludeAnchored))
{ {
if (!EntityManager.TryGetComponent(entity, out AmbientSoundComponent? ambientComp) || if (!EntityManager.TryGetComponent(entity, out AmbientSoundComponent? ambientComp) ||
_playingSounds.ContainsKey(ambientComp) ||
!ambientComp.Enabled || !ambientComp.Enabled ||
// We'll also do this crude distance check because it's what we're doing in the active loop above.
!EntityManager.GetComponent<TransformComponent>(entity).Coordinates.TryDistance(EntityManager, coordinates, out var range) || !EntityManager.GetComponent<TransformComponent>(entity).Coordinates.TryDistance(EntityManager, coordinates, out var range) ||
range > ambientComp.Range - RangeBuffer) range > ambientComp.Range)
{ {
continue; continue;
} }
compsInRange.Add(ambientComp); var key = ambientComp.Sound.GetSound();
if (!sourceDict.ContainsKey(key))
sourceDict[key] = new List<AmbientSoundComponent>(_maxSingleSound);
sourceDict[key].Add(ambientComp);
} }
while (_playingSounds.Count < _maxAmbientCount) foreach (var (key, val) in sourceDict)
{ {
if (compsInRange.Count == 0) break; sourceDict[key] = val.OrderByDescending(x =>
Transform(x.Owner).Coordinates.TryDistance(EntityManager, coordinates, out var dist) ? dist : float.MaxValue).ToList();
var comp = _random.PickAndTake(compsInRange);
var sound = comp.Sound.GetSound();
if (PlayingCount(sound) >= _maxSingleSound) continue;
var audioParams = AudioHelpers
.WithVariation(0.01f)
.WithVolume(comp.Volume)
.WithLoop(true)
.WithAttenuation(Attenuation.LinearDistance)
// Randomise start so 2 sources don't increase their volume.
.WithPlayOffset(_random.NextFloat())
.WithMaxDistance(comp.Range);
var stream = SoundSystem.Play(
Filter.Local(),
sound,
comp.Owner,
audioParams);
if (stream == null) continue;
_playingSounds[comp] = (stream, sound);
} }
return sourceDict;
}
/// <summary>
/// Get a list of ambient components in range and determine which ones to start playing.
/// </summary>
private void ProcessNearbyAmbience(EntityCoordinates coordinates)
{
var compsInRange= GetNearbySources(coordinates);
var keys = compsInRange.Keys.ToHashSet();
while (keys.Count != 0)
{
if (_playingSounds.Count >= _maxAmbientCount)
{
/*
// Go through and remove everything from compSet
foreach (var toRemove in keys.SelectMany(key => compsInRange[key]))
{
compSet.Remove(toRemove.Owner);
}
*/
break;
}
foreach (var key in keys)
{
if (_playingSounds.Count >= _maxAmbientCount)
break;
if (compsInRange[key].Count == 0)
{
keys.Remove(key);
continue;
}
var comp = compsInRange[key].Pop();
if (_playingSounds.ContainsKey(comp))
continue;
var sound = comp.Sound.GetSound();
if (PlayingCount(sound) >= _maxSingleSound)
{
keys.Remove(key);
/*foreach (var toRemove in compsInRange[key])
{
Logger.Debug($"removing {toRemove.Owner} from set.");
compSet.Remove(toRemove.Owner);
}*/
compsInRange[key].Clear(); // reduce work later should we overrun the max sounds.
continue;
}
var audioParams = AudioHelpers
.WithVariation(0.01f)
.WithVolume(comp.Volume)
.WithLoop(true)
.WithAttenuation(Attenuation.LinearDistance)
// Randomise start so 2 sources don't increase their volume.
.WithPlayOffset(_random.NextFloat(0.0f, 100.0f))
.WithMaxDistance(comp.Range);
var stream = SoundSystem.Play(
Filter.Local(),
sound,
comp.Owner,
audioParams);
if (stream == null) continue;
_playingSounds[comp] = (stream, sound);
}
}
foreach (var (comp, sound) in _playingSounds)
{
var entity = comp.Owner;
if (!comp.Enabled ||
!EntityManager.GetComponent<TransformComponent>(entity).Coordinates
.TryDistance(EntityManager, coordinates, out var range) ||
range > comp.Range)
{
_playingSounds[comp].Stream?.Stop();
_playingSounds.Remove(comp);
}
}
//TODO: Put this code back in place! Currently not done this way because of GetEntitiesInRange being funny.
/*
foreach (var (comp, sound) in _playingSounds)
{
if (compSet.Contains(comp.Owner)) continue;
Logger.Debug($"Cancelled {comp.Owner}");
_playingSounds[comp].Stream?.Stop();
_playingSounds.Remove(comp);
}
*/
} }
} }
} }

View File

@@ -8,6 +8,7 @@ using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -20,9 +21,10 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
[UsedImplicitly] [UsedImplicitly]
public sealed class GasPressurePumpSystem : EntitySystem public sealed class GasPressurePumpSystem : EntitySystem
{ {
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private AdminLogSystem _adminLogSystem = default!; [Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -59,6 +61,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|| !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet))
{ {
appearance?.SetData(PumpVisuals.Enabled, false); appearance?.SetData(PumpVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(pump.Owner, false);
return; return;
} }
@@ -67,12 +70,14 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
if (MathHelper.CloseToPercent(pump.TargetPressure, outputStartingPressure)) if (MathHelper.CloseToPercent(pump.TargetPressure, outputStartingPressure))
{ {
appearance?.SetData(PumpVisuals.Enabled, false); appearance?.SetData(PumpVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(pump.Owner, false);
return; // No need to pump gas if target has been reached. return; // No need to pump gas if target has been reached.
} }
if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0) if (inlet.Air.TotalMoles > 0 && inlet.Air.Temperature > 0)
{ {
appearance?.SetData(PumpVisuals.Enabled, true); appearance?.SetData(PumpVisuals.Enabled, true);
_ambientSoundSystem.SetAmbience(pump.Owner, true);
// We calculate the necessary moles to transfer using our good ol' friend PV=nRT. // We calculate the necessary moles to transfer using our good ol' friend PV=nRT.
var pressureDelta = pump.TargetPressure - outputStartingPressure; var pressureDelta = pump.TargetPressure - outputStartingPressure;

View File

@@ -20,6 +20,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
[UsedImplicitly] [UsedImplicitly]
public sealed class GasValveSystem : EntitySystem public sealed class GasValveSystem : EntitySystem
{ {
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -68,11 +70,13 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
{ {
inlet.AddAlwaysReachable(outlet); inlet.AddAlwaysReachable(outlet);
outlet.AddAlwaysReachable(inlet); outlet.AddAlwaysReachable(inlet);
_ambientSoundSystem.SetAmbience(component.Owner, true);
} }
else else
{ {
inlet.RemoveAlwaysReachable(outlet); inlet.RemoveAlwaysReachable(outlet);
outlet.RemoveAlwaysReachable(inlet); outlet.RemoveAlwaysReachable(inlet);
_ambientSoundSystem.SetAmbience(component.Owner, false);
} }
} }
} }

View File

@@ -6,6 +6,7 @@ using Content.Server.NodeContainer;
using Content.Server.NodeContainer.Nodes; using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Binary.Components; using Content.Shared.Atmos.Piping.Binary.Components;
using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Interaction; using Content.Shared.Interaction;
@@ -21,8 +22,9 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
{ {
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private AdminLogSystem _adminLogSystem = default!; [Dependency] private readonly AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -59,6 +61,8 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
|| !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(pump.OutletName, out PipeNode? outlet))
{ {
appearance?.SetData(PumpVisuals.Enabled, false); appearance?.SetData(PumpVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(pump.Owner, false);
_ambientSoundSystem.SetAmbience(pump.Owner, false);
return; return;
} }
@@ -74,6 +78,7 @@ namespace Content.Server.Atmos.Piping.Binary.EntitySystems
return; return;
appearance?.SetData(PumpVisuals.Enabled, true); appearance?.SetData(PumpVisuals.Enabled, true);
_ambientSoundSystem.SetAmbience(pump.Owner, true);
// We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters. // We multiply the transfer rate in L/s by the seconds passed since the last process to get the liters.
var transferRatio = (float)(pump.TransferRate * (_gameTiming.CurTime - device.LastProcess).TotalSeconds) / inlet.Air.Volume; var transferRatio = (float)(pump.TransferRate * (_gameTiming.CurTime - device.LastProcess).TotalSeconds) / inlet.Air.Volume;

View File

@@ -9,6 +9,7 @@ using Content.Server.UserInterface;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Trinary.Components; using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
@@ -28,6 +29,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private AdminLogSystem _adminLogSystem = default!; [Dependency] private AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -50,7 +52,10 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
component.Enabled = false; component.Enabled = false;
if (TryComp(uid, out AppearanceComponent? appearance)) if (TryComp(uid, out AppearanceComponent? appearance))
{
appearance.SetData(FilterVisuals.Enabled, false); appearance.SetData(FilterVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(component.Owner, false);
}
DirtyUI(uid, component); DirtyUI(uid, component);
_userInterfaceSystem.TryCloseAll(uid, GasFilterUiKey.Key); _userInterfaceSystem.TryCloseAll(uid, GasFilterUiKey.Key);
@@ -69,6 +74,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
|| outletNode.Air.Pressure >= Atmospherics.MaxOutputPressure) // No need to transfer if target is full. || outletNode.Air.Pressure >= Atmospherics.MaxOutputPressure) // No need to transfer if target is full.
{ {
appearance?.SetData(FilterVisuals.Enabled, false); appearance?.SetData(FilterVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(filter.Owner, false);
return; return;
} }
@@ -78,6 +84,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
if (transferRatio <= 0) if (transferRatio <= 0)
{ {
appearance?.SetData(FilterVisuals.Enabled, false); appearance?.SetData(FilterVisuals.Enabled, false);
_ambientSoundSystem.SetAmbience(filter.Owner, false);
return; return;
} }
@@ -94,6 +101,14 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
var target = filterNode.Air.Pressure < Atmospherics.MaxOutputPressure ? filterNode : inletNode; var target = filterNode.Air.Pressure < Atmospherics.MaxOutputPressure ? filterNode : inletNode;
_atmosphereSystem.Merge(target.Air, filteredOut); _atmosphereSystem.Merge(target.Air, filteredOut);
if (filteredOut.Pressure != 0f)
{
_ambientSoundSystem.SetAmbience(filter.Owner, true);
}
else
{
_ambientSoundSystem.SetAmbience(filter.Owner, false);
}
} }
_atmosphereSystem.Merge(outletNode.Air, removed); _atmosphereSystem.Merge(outletNode.Air, removed);

View File

@@ -7,6 +7,7 @@ using Content.Server.NodeContainer.Nodes;
using Content.Shared.Atmos; using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping; using Content.Shared.Atmos.Piping;
using Content.Shared.Atmos.Piping.Trinary.Components; using Content.Shared.Atmos.Piping.Trinary.Components;
using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Popups; using Content.Shared.Popups;
@@ -21,6 +22,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
[Dependency] private UserInterfaceSystem _userInterfaceSystem = default!; [Dependency] private UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private AdminLogSystem _adminLogSystem = default!; [Dependency] private AdminLogSystem _adminLogSystem = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -59,7 +61,10 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
// TODO ATMOS: Cache total moles since it's expensive. // TODO ATMOS: Cache total moles since it's expensive.
if (!mixer.Enabled) if (!mixer.Enabled)
{
_ambientSoundSystem.SetAmbience(mixer.Owner, false);
return; return;
}
if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer)) if (!EntityManager.TryGetComponent(uid, out NodeContainerComponent? nodeContainer))
return; return;
@@ -67,13 +72,18 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
if (!nodeContainer.TryGetNode(mixer.InletOneName, out PipeNode? inletOne) if (!nodeContainer.TryGetNode(mixer.InletOneName, out PipeNode? inletOne)
|| !nodeContainer.TryGetNode(mixer.InletTwoName, out PipeNode? inletTwo) || !nodeContainer.TryGetNode(mixer.InletTwoName, out PipeNode? inletTwo)
|| !nodeContainer.TryGetNode(mixer.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(mixer.OutletName, out PipeNode? outlet))
{
_ambientSoundSystem.SetAmbience(mixer.Owner, false);
return; return;
}
var outputStartingPressure = outlet.Air.Pressure; var outputStartingPressure = outlet.Air.Pressure;
if (outputStartingPressure >= mixer.TargetPressure) if (outputStartingPressure >= mixer.TargetPressure)
return; // Target reached, no need to mix. return; // Target reached, no need to mix.
var generalTransfer = (mixer.TargetPressure - outputStartingPressure) * outlet.Air.Volume / Atmospherics.R; var generalTransfer = (mixer.TargetPressure - outputStartingPressure) * outlet.Air.Volume / Atmospherics.R;
var transferMolesOne = inletOne.Air.Temperature > 0 ? mixer.InletOneConcentration * generalTransfer / inletOne.Air.Temperature : 0f; var transferMolesOne = inletOne.Air.Temperature > 0 ? mixer.InletOneConcentration * generalTransfer / inletOne.Air.Temperature : 0f;
@@ -102,7 +112,10 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
return; return;
if (transferMolesOne <= 0 || transferMolesTwo <= 0) if (transferMolesOne <= 0 || transferMolesTwo <= 0)
{
_ambientSoundSystem.SetAmbience(mixer.Owner, false);
return; return;
}
if (inletOne.Air.TotalMoles < transferMolesOne || inletTwo.Air.TotalMoles < transferMolesTwo) if (inletOne.Air.TotalMoles < transferMolesOne || inletTwo.Air.TotalMoles < transferMolesTwo)
{ {
@@ -125,6 +138,7 @@ namespace Content.Server.Atmos.Piping.Trinary.EntitySystems
var removed = inletTwo.Air.Remove(transferMolesTwo); var removed = inletTwo.Air.Remove(transferMolesTwo);
_atmosphereSystem.Merge(outlet.Air, removed); _atmosphereSystem.Merge(outlet.Air, removed);
} }
_ambientSoundSystem.SetAmbience(mixer.Owner, true);
} }
private void OnMixerInteractHand(EntityUid uid, GasMixerComponent component, InteractHandEvent args) private void OnMixerInteractHand(EntityUid uid, GasMixerComponent component, InteractHandEvent args)

View File

@@ -13,6 +13,7 @@ using Content.Shared.Atmos;
using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Atmos.Visuals; using Content.Shared.Atmos.Visuals;
using Content.Shared.Audio;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -24,6 +25,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -52,6 +54,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|| !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe)) || !nodeContainer.TryGetNode(vent.InletName, out PipeNode? pipe))
{ {
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off); appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
_ambientSoundSystem.SetAmbience(vent.Owner, false);
return; return;
} }
@@ -61,6 +64,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (environment == null) if (environment == null)
{ {
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off); appearance?.SetData(VentPumpVisuals.State, VentPumpState.Off);
_ambientSoundSystem.SetAmbience(vent.Owner, false);
return; return;
} }
@@ -70,6 +74,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0) if (vent.PumpDirection == VentPumpDirection.Releasing && pipe.Air.Pressure > 0)
{ {
appearance?.SetData(VentPumpVisuals.State, VentPumpState.Out); appearance?.SetData(VentPumpVisuals.State, VentPumpState.Out);
_ambientSoundSystem.SetAmbience(vent.Owner, true);
if (environment.Pressure > vent.MaxPressure) if (environment.Pressure > vent.MaxPressure)
return; return;

View File

@@ -14,6 +14,7 @@ using Content.Shared.Atmos;
using Content.Shared.Atmos.Piping.Unary.Visuals; using Content.Shared.Atmos.Piping.Unary.Visuals;
using Content.Shared.Atmos.Monitor; using Content.Shared.Atmos.Monitor;
using Content.Shared.Atmos.Piping.Unary.Components; using Content.Shared.Atmos.Piping.Unary.Components;
using Content.Shared.Audio;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -25,6 +26,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
[Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!; [Dependency] private readonly AtmosphereSystem _atmosphereSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -44,6 +46,7 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
if (scrubber.Welded) if (scrubber.Welded)
{ {
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Welded); appearance?.SetData(ScrubberVisuals.State, ScrubberState.Welded);
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
return; return;
} }
@@ -57,8 +60,10 @@ namespace Content.Server.Atmos.Piping.Unary.EntitySystems
|| !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet)) || !nodeContainer.TryGetNode(scrubber.OutletName, out PipeNode? outlet))
{ {
appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off); appearance?.SetData(ScrubberVisuals.State, ScrubberState.Off);
_ambientSoundSystem.SetAmbience(scrubber.Owner, false);
return; return;
} }
_ambientSoundSystem.SetAmbience(scrubber.Owner, true);
var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, true); var environment = _atmosphereSystem.GetTileMixture(EntityManager.GetComponent<TransformComponent>(scrubber.Owner).Coordinates, true);

View File

@@ -16,7 +16,7 @@ namespace Content.Shared.Audio
[DataField("enabled")] [DataField("enabled")]
public bool Enabled { get; set; } = true; public bool Enabled { get; set; } = true;
[DataField("sound")] [DataField("sound", required: true)]
public SoundSpecifier Sound = default!; public SoundSpecifier Sound = default!;
/// <summary> /// <summary>

View File

@@ -31,13 +31,13 @@ namespace Content.Shared.CCVar
/// How long we'll wait until re-sampling nearby objects for ambience. /// How long we'll wait until re-sampling nearby objects for ambience.
/// </summary> /// </summary>
public static readonly CVarDef<float> AmbientCooldown = public static readonly CVarDef<float> AmbientCooldown =
CVarDef.Create("ambience.cooldown", 0.5f, CVar.REPLICATED | CVar.SERVER); CVarDef.Create("ambience.cooldown", 0.1f, CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<float> AmbientRange = public static readonly CVarDef<float> AmbientRange =
CVarDef.Create("ambience.range", 5f, CVar.REPLICATED | CVar.SERVER); CVarDef.Create("ambience.range", 5f, CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<int> MaxAmbientSources = public static readonly CVarDef<int> MaxAmbientSources =
CVarDef.Create("ambience.max_sounds", 6, CVar.REPLICATED | CVar.SERVER); CVarDef.Create("ambience.max_sounds", 64, CVar.REPLICATED | CVar.SERVER);
/* /*
* Status * Status

View File

@@ -1,3 +1,4 @@
using Content.Shared.Audio;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Interaction.Events; using Content.Shared.Interaction.Events;
using Content.Shared.Maps; using Content.Shared.Maps;
@@ -16,6 +17,7 @@ namespace Content.Shared.SubFloor
[Dependency] protected readonly IMapManager MapManager = default!; [Dependency] protected readonly IMapManager MapManager = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!; [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly TrayScannerSystem _trayScannerSystem = default!; [Dependency] private readonly TrayScannerSystem _trayScannerSystem = default!;
[Dependency] private readonly SharedAmbientSoundSystem _ambientSoundSystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -181,6 +183,10 @@ namespace Content.Shared.SubFloor
appearance.SetData(SubFloorVisuals.Covered, hideComp.IsUnderCover); appearance.SetData(SubFloorVisuals.Covered, hideComp.IsUnderCover);
appearance.SetData(SubFloorVisuals.ScannerRevealed, hideComp.RevealedBy.Count != 0); appearance.SetData(SubFloorVisuals.ScannerRevealed, hideComp.RevealedBy.Count != 0);
if (hideComp.BlockAmbience && hideComp.IsUnderCover)
_ambientSoundSystem.SetAmbience(uid, false);
else if (hideComp.BlockAmbience && !hideComp.IsUnderCover)
_ambientSoundSystem.SetAmbience(uid, true);
} }
} }

View File

@@ -29,6 +29,15 @@ namespace Content.Shared.SubFloor
[DataField("blockInteractions")] [DataField("blockInteractions")]
public bool BlockInteractions { get; set; } = true; public bool BlockInteractions { get; set; } = true;
/// <summary>
/// Whether this entity's ambience should be disabled when underneath the floor.
/// </summary>
/// <remarks>
/// Useful for cables and piping, gives maint it's distinct noise.
/// </remarks>
[DataField("blockAmbience")]
public bool BlockAmbience { get; set; } = true;
/// <summary> /// <summary>
/// When revealed using some scanning tool, what transparency should be used to draw this item? /// When revealed using some scanning tool, what transparency should be used to draw this item?
/// </summary> /// </summary>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1 +1,4 @@
circular_saw.ogg - https://freesound.org/people/derjuli/sounds/448133/ and clipped - CC0-1.0 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_vent - https://freesound.org/people/kyles/sounds/453642/ - CC0-1.0

View File

@@ -22,6 +22,7 @@ shell-need-between-arguments = Need {$lower} to {$upper} arguments!
shell-entity-is-not-mob = Target entity is not a mob! shell-entity-is-not-mob = Target entity is not a mob!
shell-invalid-entity-id = Invalid entity ID. shell-invalid-entity-id = Invalid entity ID.
shell-invalid-grid-id = Invalid grid ID. shell-invalid-grid-id = Invalid grid ID.
shell-invalid-map-id = Invalid map ID.
shell-invalid-entity-uid = {$uid} is not a valid entity uid shell-invalid-entity-uid = {$uid} is not a valid entity uid
shell-entity-uid-must-be-number = EntityUid must be a number. shell-entity-uid-must-be-number = EntityUid must be a number.
shell-could-not-find-entity = Could not find entity {$entity} shell-could-not-find-entity = Could not find entity {$entity}
@@ -34,3 +35,5 @@ shell-timespan-minutes-must-be-correct = {$span} is not a valid minutes timespan
shell-argument-must-be-prototype = Argument {$index} must be a ${prototypeName}! shell-argument-must-be-prototype = Argument {$index} must be a ${prototypeName}!
shell-argument-number-must-be-between = Argument {$index} must be a number between {$lower} and {$upper}! shell-argument-number-must-be-between = Argument {$index} must be a number between {$lower} and {$upper}!
shell-argument-station-id-invalid = Argument {$index} must be a valid station id! shell-argument-station-id-invalid = Argument {$index} must be a valid station id!
shell-argument-map-id-invalid = Argument {$index} must be a valid map id!
shell-argument-number-invalid = Argument {$index} must be a valid number!

View File

@@ -7,6 +7,7 @@
mode: AlignTileAny mode: AlignTileAny
components: components:
- type: AmbientSound - type: AmbientSound
volume: -6
range: 7 range: 7
sound: sound:
path: /Audio/Ambience/Objects/gravity_gen_hum.ogg path: /Audio/Ambience/Objects/gravity_gen_hum.ogg

View File

@@ -7,7 +7,7 @@
components: components:
- type: AmbientOnPowered - type: AmbientOnPowered
- type: AmbientSound - type: AmbientSound
volume: -14 volume: -9
range: 3 range: 3
sound: sound:
path: /Audio/Ambience/Objects/vending_machine_hum.ogg path: /Audio/Ambience/Objects/vending_machine_hum.ogg

View File

@@ -8,6 +8,7 @@
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide - type: SubFloorHide
blockInteractions: false blockInteractions: false
blockAmbience: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
inlet: inlet:
@@ -50,6 +51,12 @@
- type: Construction - type: Construction
graph: GasBinary graph: GasBinary
node: pressurepump node: pressurepump
- type: AmbientSound
enabled: false
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_pump.ogg
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase
@@ -82,6 +89,12 @@
- type: Construction - type: Construction
graph: GasBinary graph: GasBinary
node: volumepump node: volumepump
- type: AmbientSound
enabled: false
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_pump.ogg
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase
@@ -107,6 +120,12 @@
- type: Construction - type: Construction
graph: GasBinary graph: GasBinary
node: passivegate node: passivegate
- type: AmbientSound
enabled: true
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_hiss.ogg
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase
@@ -148,6 +167,12 @@
- type: Construction - type: Construction
graph: GasBinary graph: GasBinary
node: valve node: valve
- type: AmbientSound
enabled: false
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_hiss.ogg
- type: entity - type: entity
parent: GasBinaryBase parent: GasBinaryBase

View File

@@ -65,6 +65,12 @@
- type: Tag - type: Tag
tags: tags:
- Pipe - Pipe
- type: AmbientSound
enabled: true
volume: -15
range: 2
sound:
path: /Audio/Ambience/Objects/gas_hiss.ogg
#Note: The PipeDirection of the PipeNode should be the south-facing version, because the entity starts at an angle of 0 (south) #Note: The PipeDirection of the PipeNode should be the south-facing version, because the entity starts at an angle of 0 (south)

View File

@@ -8,6 +8,7 @@
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide - type: SubFloorHide
blockInteractions: false blockInteractions: false
blockAmbience: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
inlet: inlet:
@@ -58,6 +59,12 @@
- type: Construction - type: Construction
graph: GasTrinary graph: GasTrinary
node: filter node: filter
- type: AmbientSound
enabled: false
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_hiss.ogg
- type: entity - type: entity
parent: GasFilter parent: GasFilter
@@ -136,6 +143,12 @@
- type: Construction - type: Construction
graph: GasTrinary graph: GasTrinary
node: mixer node: mixer
- type: AmbientSound
enabled: false
volume: -9
range: 5
sound:
path: /Audio/Ambience/Objects/gas_hiss.ogg
- type: entity - type: entity
parent: GasMixer parent: GasMixer

View File

@@ -8,6 +8,7 @@
- type: AtmosDevice - type: AtmosDevice
- type: SubFloorHide - type: SubFloorHide
blockInteractions: false blockInteractions: false
blockAmbience: false
- type: NodeContainer - type: NodeContainer
nodes: nodes:
pipe: pipe:
@@ -51,6 +52,12 @@
graph: GasUnary graph: GasUnary
node: ventpump node: ventpump
- type: VentCritterSpawnLocation - type: VentCritterSpawnLocation
- type: AmbientSound
enabled: false
volume: -12
range: 5
sound:
path: /Audio/Ambience/Objects/gas_vent.ogg
- type: entity - type: entity
parent: GasUnaryBase parent: GasUnaryBase
@@ -115,6 +122,12 @@
- type: Construction - type: Construction
graph: GasUnary graph: GasUnary
node: ventscrubber node: ventscrubber
- type: AmbientSound
enabled: false
volume: -12
range: 5
sound:
path: /Audio/Ambience/Objects/gas_vent.ogg
- type: entity - type: entity
parent: GasUnaryBase parent: GasUnaryBase

View File

@@ -5,7 +5,7 @@
components: components:
- type: Clickable - type: Clickable
- type: AmbientSound - type: AmbientSound
volume: -10 volume: -4
range: 14 range: 14
sound: sound:
path: /Audio/Effects/singularity.ogg path: /Audio/Effects/singularity.ogg

View File

@@ -8,7 +8,7 @@
components: components:
- type: AmbientOnPowered - type: AmbientOnPowered
- type: AmbientSound - type: AmbientSound
volume: -15 volume: -9
range: 2 range: 2
sound: sound:
path: /Audio/Ambience/Objects/hdd_buzz.ogg path: /Audio/Ambience/Objects/hdd_buzz.ogg

View File

@@ -33,6 +33,8 @@
- !type:DoActsBehavior - !type:DoActsBehavior
acts: ["Destruction"] acts: ["Destruction"]
- type: SubFloorHide - type: SubFloorHide
blockAmbience: false
blockInteractions: false
- type: Construction - type: Construction
graph: CableTerminal graph: CableTerminal
node: cable_terminal node: cable_terminal

View File

@@ -86,6 +86,12 @@
visuals: visuals:
- type: CableVisualizer - type: CableVisualizer
base: hvcable_ base: hvcable_
- type: AmbientSound
enabled: true
volume: -15
range: 2
sound:
path: /Audio/Ambience/Objects/emf_buzz.ogg
- type: entity - type: entity
parent: CableBase parent: CableBase
@@ -132,6 +138,12 @@
visuals: visuals:
- type: CableVisualizer - type: CableVisualizer
base: mvcable_ base: mvcable_
- type: AmbientSound
enabled: true
volume: -16
range: 2
sound:
path: /Audio/Ambience/Objects/emf_buzz.ogg
- type: entity - type: entity
parent: CableBase parent: CableBase
@@ -181,3 +193,9 @@
visuals: visuals:
- type: CableVisualizer - type: CableVisualizer
base: lvcable_ base: lvcable_
- type: AmbientSound
enabled: true
volume: -17
range: 2
sound:
path: /Audio/Ambience/Objects/emf_buzz.ogg

View File

@@ -8,6 +8,7 @@
mode: SnapgridCenter mode: SnapgridCenter
components: components:
- type: AmbientSound - type: AmbientSound
volume: -7
range: 3 range: 3
sound: sound:
path: /Audio/Ambience/Objects/periodic_beep.ogg path: /Audio/Ambience/Objects/periodic_beep.ogg

View File

@@ -7,7 +7,7 @@
components: components:
- type: AmbientSound - type: AmbientSound
range: 4 range: 4
volume: -5 volume: -4
sound: sound:
path: /Audio/Effects/shuttle_thruster.ogg path: /Audio/Effects/shuttle_thruster.ogg
- type: Transform - type: Transform
@@ -60,7 +60,7 @@
map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"] map: ["enum.ThrusterVisualLayers.ThrustingUnshaded"]
shader: unshaded shader: unshaded
offset: 0, 1 offset: 0, 1
- type: entity - type: entity
id: DebugThruster id: DebugThruster
parent: BaseThruster parent: BaseThruster