Audio fixes (#22324)
This commit is contained in:
@@ -14,6 +14,9 @@ namespace Content.Client.Audio;
|
||||
[UsedImplicitly]
|
||||
public sealed class BackgroundAudioSystem : EntitySystem
|
||||
{
|
||||
/*
|
||||
* TODO: Nuke this system and merge into contentaudiosystem
|
||||
*/
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly IBaseClient _client = 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 EntityUid? _lobbyStream;
|
||||
public EntityUid? LobbyStream;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -109,7 +112,7 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
||||
|
||||
public void StartLobbyMusic()
|
||||
{
|
||||
if (_lobbyStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
|
||||
if (LobbyStream != null || !_configManager.GetCVar(CCVars.LobbyMusicEnabled))
|
||||
return;
|
||||
|
||||
var file = _gameTicker.LobbySong;
|
||||
@@ -118,12 +121,12 @@ public sealed class BackgroundAudioSystem : EntitySystem
|
||||
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;
|
||||
}
|
||||
|
||||
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.
|
||||
if (_state.CurrentState is not GameplayState)
|
||||
{
|
||||
FadeOut(_ambientMusicStream);
|
||||
Audio.Stop(_ambientMusicStream);
|
||||
_ambientMusicStream = null;
|
||||
_musicProto = null;
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Shared;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -37,6 +38,24 @@ public sealed partial class ContentAudioSystem : SharedContentAudioSystem
|
||||
base.Initialize();
|
||||
UpdatesOutsidePrediction = true;
|
||||
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()
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using Content.Server.GameTicking.Events;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Server.Audio;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Audio;
|
||||
@@ -14,10 +16,16 @@ public sealed class ContentAudioSystem : SharedContentAudioSystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundCleanup);
|
||||
SubscribeLocalEvent<RoundStartingEvent>(OnRoundStart);
|
||||
_protoManager.PrototypesReloaded += OnProtoReload;
|
||||
}
|
||||
|
||||
private void OnRoundCleanup(RoundRestartCleanupEvent ev)
|
||||
{
|
||||
SilenceAudio();
|
||||
}
|
||||
|
||||
private void OnProtoReload(PrototypesReloadedEventArgs obj)
|
||||
{
|
||||
if (!obj.ByType.ContainsKey(typeof(AudioPresetPrototype)))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Audio.Components;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
|
||||
namespace Content.Shared.Audio;
|
||||
@@ -18,4 +19,14 @@ public abstract class SharedContentAudioSystem : EntitySystem
|
||||
base.Initialize();
|
||||
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