Audio fixes (#22324)
This commit is contained in:
@@ -14,6 +14,9 @@ namespace Content.Client.Audio;
|
|||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
public sealed class BackgroundAudioSystem : EntitySystem
|
public sealed class BackgroundAudioSystem : EntitySystem
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
|
* TODO: Nuke this system and merge into contentaudiosystem
|
||||||
|
*/
|
||||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly IBaseClient _client = default!;
|
[Dependency] private readonly IBaseClient _client = default!;
|
||||||
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
[Dependency] private readonly IConfigurationManager _configManager = default!;
|
||||||
@@ -22,7 +25,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
|||||||
|
|
||||||
private readonly AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f);
|
private readonly AudioParams _lobbyParams = new(-5f, 1, "Master", 0, 0, 0, true, 0f);
|
||||||
|
|
||||||
private EntityUid? _lobbyStream;
|
public EntityUid? LobbyStream;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
@@ -109,7 +112,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
|||||||
|
|
||||||
public void StartLobbyMusic()
|
public void StartLobbyMusic()
|
||||||
{
|
{
|
||||||
if (_lobbyStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
|
if (LobbyStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var file = _gameTicker.LobbySong;
|
var file = _gameTicker.LobbySong;
|
||||||
@@ -118,12 +121,12 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_lobbyStream = _audio.PlayGlobal(file, Filter.Local(), false,
|
LobbyStream = _audio.PlayGlobal(file, Filter.Local(), false,
|
||||||
_lobbyParams.WithVolume(_lobbyParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume))))?.Entity;
|
_lobbyParams.WithVolume(_lobbyParams.Volume + SharedAudioSystem.GainToVolume(_configManager.GetCVar(CCVars.LobbyMusicVolume))))?.Entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EndLobbyMusic()
|
private void EndLobbyMusic()
|
||||||
{
|
{
|
||||||
_lobbyStream = _audio.Stop(_lobbyStream);
|
LobbyStream = _audio.Stop(LobbyStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ public sealed partial class ContentAudioSystem
|
|||||||
// Update still runs in lobby so just ignore it.
|
// Update still runs in lobby so just ignore it.
|
||||||
if (_state.CurrentState is not GameplayState)
|
if (_state.CurrentState is not GameplayState)
|
||||||
{
|
{
|
||||||
FadeOut(_ambientMusicStream);
|
Audio.Stop(_ambientMusicStream);
|
||||||
_ambientMusicStream = null;
|
_ambientMusicStream = null;
|
||||||
_musicProto = null;
|
_musicProto = null;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.CCVar;
|
using Content.Shared.CCVar;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Robust.Client.GameObjects;
|
using Robust.Client.GameObjects;
|
||||||
using Robust.Shared;
|
using Robust.Shared;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
@@ -37,6 +38,24 @@ public sealed partial class ContentAudioSystem : SharedContentAudioSystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
UpdatesOutsidePrediction = true;
|
UpdatesOutsidePrediction = true;
|
||||||
InitializeAmbientMusic();
|
InitializeAmbientMusic();
|
||||||
|
SubscribeNetworkEvent<RoundRestartCleanupEvent>(OnRoundCleanup);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnRoundCleanup(RoundRestartCleanupEvent ev)
|
||||||
|
{
|
||||||
|
_fadingOut.Clear();
|
||||||
|
|
||||||
|
// Preserve lobby music but everything else should get dumped.
|
||||||
|
var lobbyStream = EntityManager.System<BackgroundAudioSystem>().LobbyStream;
|
||||||
|
TryComp(lobbyStream, out AudioComponent? audioComp);
|
||||||
|
var oldGain = audioComp?.Gain;
|
||||||
|
|
||||||
|
SilenceAudio();
|
||||||
|
|
||||||
|
if (oldGain != null)
|
||||||
|
{
|
||||||
|
Audio.SetGain(lobbyStream, oldGain.Value, audioComp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Shutdown()
|
public override void Shutdown()
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using Content.Server.GameTicking.Events;
|
using Content.Server.GameTicking.Events;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
|
using Content.Shared.GameTicking;
|
||||||
using Robust.Server.Audio;
|
using Robust.Server.Audio;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Audio.Components;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.Audio;
|
namespace Content.Server.Audio;
|
||||||
@@ -14,10 +16,16 @@ public sealed class ContentAudioSystem : SharedContentAudioSystem
|
|||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundCleanup);
|
||||||
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
|
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
|
||||||
_protoManager.PrototypesReloaded += OnProtoReload;
|
_protoManager.PrototypesReloaded += OnProtoReload;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnRoundCleanup(RoundRestartCleanupEvent ev)
|
||||||
|
{
|
||||||
|
SilenceAudio();
|
||||||
|
}
|
||||||
|
|
||||||
private void OnProtoReload(PrototypesReloadedEventArgs obj)
|
private void OnProtoReload(PrototypesReloadedEventArgs obj)
|
||||||
{
|
{
|
||||||
if (!obj.ByType.ContainsKey(typeof(AudioPresetPrototype)))
|
if (!obj.ByType.ContainsKey(typeof(AudioPresetPrototype)))
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Robust.Shared.Audio;
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Audio.Components;
|
||||||
using Robust.Shared.Audio.Systems;
|
using Robust.Shared.Audio.Systems;
|
||||||
|
|
||||||
namespace Content.Shared.Audio;
|
namespace Content.Shared.Audio;
|
||||||
@@ -18,4 +19,14 @@ public abstract class SharedContentAudioSystem : EntitySystem
|
|||||||
base.Initialize();
|
base.Initialize();
|
||||||
Audio.OcclusionCollisionMask = (int) CollisionGroup.Impassable;
|
Audio.OcclusionCollisionMask = (int) CollisionGroup.Impassable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void SilenceAudio()
|
||||||
|
{
|
||||||
|
var query = AllEntityQuery<AudioComponent>();
|
||||||
|
|
||||||
|
while (query.MoveNext(out var uid, out var comp))
|
||||||
|
{
|
||||||
|
Audio.SetGain(uid, 0f, comp);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user