]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Audio fixes (#22324)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Mon, 11 Dec 2023 10:26:55 +0000 (21:26 +1100)
committerGitHub <noreply@github.com>
Mon, 11 Dec 2023 10:26:55 +0000 (21:26 +1100)
Content.Client/Audio/BackgroundAudioSystem.cs
Content.Client/Audio/ContentAudioSystem.AmbientMusic.cs
Content.Client/Audio/ContentAudioSystem.cs
Content.Server/Audio/ContentAudioSystem.cs
Content.Shared/Audio/SharedContentAudioSystem.cs

index 3206cfde299aa1f5910ba0b24322eaff80a767c5..09ac1efcd6580bc4cb962e886b0d599959a2cc90 100644 (file)
@@ -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);
     }
 }
index 6eb25aec1e74ec50ad2318c86278a580928b1368..0fc0c18b62bcbc76b48317bc2238aa701853b05b 100644 (file)
@@ -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;
index 2dc950ee265c860091b5a7bb853ccdaa24b080a2..603b1086d8b1bce6174e33633205706f541f5dd0 100644 (file)
@@ -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()
index 1c5625b0b832b79732300b5fe6184f860e19a1d0..51bd3183b632e814211a55c9d619a6a224259692 100644 (file)
@@ -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)))
index 3563f2f8462bebadfefedd36cd26fdce409c4c67..932174981f5e6a720239c8f6f60f6fdad0b82ad8 100644 (file)
@@ -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);
+        }
+    }
 }