]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Refactor audio system to send collection IDs over the network (#33610)
authorpathetic meowmeow <uhhadd@gmail.com>
Sun, 23 Feb 2025 12:14:56 +0000 (07:14 -0500)
committerGitHub <noreply@github.com>
Sun, 23 Feb 2025 12:14:56 +0000 (23:14 +1100)
21 files changed:
Content.Client/Audio/ClientGlobalSoundSystem.cs
Content.Client/Audio/ContentAudioSystem.LobbyMusic.cs
Content.Client/Disposal/Systems/DisposalUnitSystem.cs
Content.Client/GameTicking/Managers/ClientGameTicker.cs
Content.Client/Light/Visualizers/PoweredLightVisualizerSystem.cs
Content.Client/Trigger/TimerTriggerVisualizerSystem.cs
Content.Server/Audio/ServerGlobalSoundSystem.cs
Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Content.Server/Cargo/Systems/CargoSystem.Telepad.cs
Content.Server/Chat/Systems/ChatSystem.cs
Content.Server/GameTicking/GameTicker.RoundFlow.cs
Content.Server/Light/EntitySystems/HandheldLightSystem.cs
Content.Server/Nuke/NukeSystem.cs
Content.Server/Nutrition/EntitySystems/CreamPieSystem.cs
Content.Server/Radiation/Systems/GeigerSystem.cs
Content.Server/Salvage/Expeditions/SalvageExpeditionComponent.cs
Content.Server/Salvage/SalvageSystem.Expeditions.cs
Content.Server/Salvage/SalvageSystem.Runner.cs
Content.Shared/Audio/SharedGlobalSoundSystem.cs
Content.Shared/GameTicking/SharedGameTicker.cs
Content.Shared/Sound/SharedEmitSoundSystem.cs

index 50c3971d95addda6943793639959f9cb63407daf..882ab1be6d3f5748c5f770a6bc37d25e1a37f8c9 100644 (file)
@@ -66,7 +66,7 @@ public sealed class ClientGlobalSoundSystem : SharedGlobalSoundSystem
     {
         if(!_adminAudioEnabled) return;
 
-        var stream = _audio.PlayGlobal(soundEvent.Filename, Filter.Local(), false, soundEvent.AudioParams);
+        var stream = _audio.PlayGlobal(soundEvent.Specifier, Filter.Local(), false, soundEvent.AudioParams);
         _adminAudio.Add(stream?.Entity);
     }
 
@@ -75,13 +75,13 @@ public sealed class ClientGlobalSoundSystem : SharedGlobalSoundSystem
         // Either the cvar is disabled or it's already playing
         if(!_eventAudioEnabled || _eventAudio.ContainsKey(soundEvent.Type)) return;
 
-        var stream = _audio.PlayGlobal(soundEvent.Filename, Filter.Local(), false, soundEvent.AudioParams);
+        var stream = _audio.PlayGlobal(soundEvent.Specifier, Filter.Local(), false, soundEvent.AudioParams);
         _eventAudio.Add(soundEvent.Type, stream?.Entity);
     }
 
     private void PlayGameSound(GameGlobalSoundEvent soundEvent)
     {
-        _audio.PlayGlobal(soundEvent.Filename, Filter.Local(), false, soundEvent.AudioParams);
+        _audio.PlayGlobal(soundEvent.Specifier, Filter.Local(), false, soundEvent.AudioParams);
     }
 
     private void StopStationEventMusic(StopStationEventMusic soundEvent)
index 7d7d77f51a3fd250702cc32953082c165a90a351..fda2c0062c707fafe8e37f37c52485161d38f5e9 100644 (file)
@@ -218,7 +218,7 @@ public sealed partial class ContentAudioSystem
             return;
 
         var file = _gameTicker.RestartSound;
-        if (string.IsNullOrEmpty(file))
+        if (ResolvedSoundSpecifier.IsNullOrEmpty(file))
         {
             return;
         }
index 2fe56fcce9904f810b22a04aa0bd951955e269a0..da548c1e540c493104721309063b326485aa9ac0 100644 (file)
@@ -144,7 +144,7 @@ public sealed class DisposalUnitSystem : SharedDisposalUnitSystem
                         {
                             KeyFrames =
                             {
-                                new AnimationTrackPlaySound.KeyFrame(_audioSystem.GetSound(unit.FlushSound), 0)
+                                new AnimationTrackPlaySound.KeyFrame(_audioSystem.ResolveSound(unit.FlushSound), 0)
                             }
                         });
                 }
index 3d5775a3c59c9084a1d679992a662270f3d9cce5..170b24c02a5dbcc1f60ba9a5236398f4543fb090 100644 (file)
@@ -10,6 +10,7 @@ using Robust.Client.Graphics;
 using Robust.Client.State;
 using Robust.Client.UserInterface;
 using Robust.Shared.Prototypes;
+using Robust.Shared.Audio;
 
 namespace Content.Client.GameTicking.Managers
 {
@@ -26,7 +27,7 @@ namespace Content.Client.GameTicking.Managers
 
         [ViewVariables] public bool AreWeReady { get; private set; }
         [ViewVariables] public bool IsGameStarted { get; private set; }
-        [ViewVariables] public string? RestartSound { get; private set; }
+        [ViewVariables] public ResolvedSoundSpecifier? RestartSound { get; private set; }
         [ViewVariables] public string? LobbyBackground { get; private set; }
         [ViewVariables] public bool DisallowedLateJoin { get; private set; }
         [ViewVariables] public string? ServerInfoBlob { get; private set; }
index 2dc7f5a8226aab27563ed131c4698f629392236a..ee81641d2631c27e5140271c9741efc4181e1e85 100644 (file)
@@ -122,7 +122,7 @@ public sealed class PoweredLightVisualizerSystem : VisualizerSystem<PoweredLight
 
         if (comp.BlinkingSound != null)
         {
-            var sound = _audio.GetSound(comp.BlinkingSound);
+            var sound = _audio.ResolveSound(comp.BlinkingSound);
             blinkingAnim.AnimationTracks.Add(new AnimationTrackPlaySound()
             {
                 KeyFrames =
index 44c92456a1f7d62b9aeff5f3b21bab13b95503d5..4bea26b47b59d533e21197357d423eebc67e1211 100644 (file)
@@ -33,7 +33,7 @@ public sealed class TimerTriggerVisualizerSystem : VisualizerSystem<TimerTrigger
         {
             comp.PrimingAnimation.AnimationTracks.Add(
                 new AnimationTrackPlaySound() {
-                    KeyFrames = { new AnimationTrackPlaySound.KeyFrame(_audioSystem.GetSound(comp.PrimingSound), 0) }
+                    KeyFrames = { new AnimationTrackPlaySound.KeyFrame(_audioSystem.ResolveSound(comp.PrimingSound), 0) }
                 }
             );
         }
index 3d30be8eeaecf4f48810a1e90954f0e01d9042ff..c54cafc8c535d6198fc896ec641d8be5dd08e1d8 100644 (file)
@@ -19,9 +19,9 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
         _conHost.UnregisterCommand("playglobalsound");
     }
 
-    public void PlayAdminGlobal(Filter playerFilter, string filename, AudioParams? audioParams = null, bool replay = true)
+    public void PlayAdminGlobal(Filter playerFilter, ResolvedSoundSpecifier specifier, AudioParams? audioParams = null, bool replay = true)
     {
-        var msg = new AdminSoundEvent(filename, audioParams);
+        var msg = new AdminSoundEvent(specifier, audioParams);
         RaiseNetworkEvent(msg, playerFilter, recordReplay: replay);
     }
 
@@ -32,9 +32,9 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
         return stationFilter;
     }
 
-    public void PlayGlobalOnStation(EntityUid source, string filename, AudioParams? audioParams = null)
+    public void PlayGlobalOnStation(EntityUid source, ResolvedSoundSpecifier specifier, AudioParams? audioParams = null)
     {
-        var msg = new GameGlobalSoundEvent(filename, audioParams);
+        var msg = new GameGlobalSoundEvent(specifier, audioParams);
         var filter = GetStationAndPvs(source);
         RaiseNetworkEvent(msg, filter);
     }
@@ -52,13 +52,13 @@ public sealed class ServerGlobalSoundSystem : SharedGlobalSoundSystem
 
     public void DispatchStationEventMusic(EntityUid source, SoundSpecifier sound, StationEventMusicType type)
     {
-        DispatchStationEventMusic(source, _audio.GetSound(sound), type);
+        DispatchStationEventMusic(source, _audio.ResolveSound(sound), type);
     }
 
-    public void DispatchStationEventMusic(EntityUid source, string sound, StationEventMusicType type)
+    public void DispatchStationEventMusic(EntityUid source, ResolvedSoundSpecifier specifier, StationEventMusicType type)
     {
         var audio = AudioParams.Default.WithVolume(-8);
-        var msg = new StationEventMusicEvent(sound, type, audio);
+        var msg = new StationEventMusicEvent(specifier, type, audio);
 
         var filter = GetStationAndPvs(source);
         RaiseNetworkEvent(msg, filter);
index 2c86a5590a5625151bc74b02e72ad3c7174db2ff..1552f136788679a17dbc5d8472dd611361bf54c3 100644 (file)
@@ -369,7 +369,7 @@ namespace Content.Server.Cargo.Systems
 
         private void PlayDenySound(EntityUid uid, CargoOrderConsoleComponent component)
         {
-            _audio.PlayPvs(_audio.GetSound(component.ErrorSound), uid);
+            _audio.PlayPvs(_audio.ResolveSound(component.ErrorSound), uid);
         }
 
         private static CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id)
index 5b6997407763b870bea13e7582e3543c160fa210..41fbf12a0c6033cc7786ce0898b37227fe2e1d95 100644 (file)
@@ -92,7 +92,7 @@ public sealed partial class CargoSystem
             var currentOrder = comp.CurrentOrders.First();
             if (FulfillOrder(currentOrder, xform.Coordinates, comp.PrinterOutput))
             {
-                _audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
+                _audio.PlayPvs(_audio.ResolveSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
 
                 if (_station.GetOwningStation(uid) is { } station)
                     UpdateOrders(station);
index 674a82053ada2c00eee0a358b98c4c8f4ff26e33..50d5a778f3e8da94d8999b971f71f2c811c3ab79 100644 (file)
@@ -328,7 +328,7 @@ public sealed partial class ChatSystem : SharedChatSystem
         _chatManager.ChatMessageToAll(ChatChannel.Radio, message, wrappedMessage, default, false, true, colorOverride);
         if (playSound)
         {
-            _audio.PlayGlobal(announcementSound == null ? DefaultAnnouncementSound : _audio.GetSound(announcementSound), Filter.Broadcast(), true, AudioParams.Default.WithVolume(-2f));
+            _audio.PlayGlobal(announcementSound == null ? DefaultAnnouncementSound : _audio.ResolveSound(announcementSound), Filter.Broadcast(), true, AudioParams.Default.WithVolume(-2f));
         }
         _adminLogger.Add(LogType.Chat, LogImpact.Low, $"Global station announcement from {sender}: {message}");
     }
index 40e3303c2d72c7617ea9cf3048c99a17eb89bc76..7ab6cfdc63a83366c80fd4ddcdc2a15418e138c6 100644 (file)
@@ -585,7 +585,7 @@ namespace Content.Server.GameTicking
 
             // This ordering mechanism isn't great (no ordering of minds) but functions
             var listOfPlayerInfoFinal = listOfPlayerInfo.OrderBy(pi => pi.PlayerOOCName).ToArray();
-            var sound = RoundEndSoundCollection == null ? null : _audio.GetSound(new SoundCollectionSpecifier(RoundEndSoundCollection));
+            var sound = RoundEndSoundCollection == null ? null : _audio.ResolveSound(new SoundCollectionSpecifier(RoundEndSoundCollection));
 
             var roundEndMessageEvent = new RoundEndMessageEvent(
                 gamemodeTitle,
index a1977d5a463f147cac888759609b10b98b64ea3c..2c8d18539ffed7df8569c4f0876cca95a9dac780 100644 (file)
@@ -202,7 +202,7 @@ namespace Content.Server.Light.EntitySystems
             if (!_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
                 !TryComp(uid, out battery))
             {
-                _audio.PlayPvs(_audio.GetSound(component.TurnOnFailSound), uid);
+                _audio.PlayPvs(_audio.ResolveSound(component.TurnOnFailSound), uid);
                 _popup.PopupEntity(Loc.GetString("handheld-light-component-cell-missing-message"), uid, user);
                 return false;
             }
@@ -212,7 +212,7 @@ namespace Content.Server.Light.EntitySystems
             // Simple enough.
             if (component.Wattage > battery.CurrentCharge)
             {
-                _audio.PlayPvs(_audio.GetSound(component.TurnOnFailSound), uid);
+                _audio.PlayPvs(_audio.ResolveSound(component.TurnOnFailSound), uid);
                 _popup.PopupEntity(Loc.GetString("handheld-light-component-cell-dead-message"), uid, user);
                 return false;
             }
index 84118931b109793fbaa8be38fedb6835db618d62..aa1fe3240102756f002031479ab1f122931ef1fc 100644 (file)
@@ -49,7 +49,7 @@ public sealed class NukeSystem : EntitySystem
     ///     Used to calculate when the nuke song should start playing for maximum kino with the nuke sfx
     /// </summary>
     private float _nukeSongLength;
-    private string _selectedNukeSong = String.Empty;
+    private ResolvedSoundSpecifier _selectedNukeSong = String.Empty;
 
     /// <summary>
     ///     Time to leave between the nuke song and the nuke alarm playing.
@@ -302,7 +302,7 @@ public sealed class NukeSystem : EntitySystem
 
         // Start playing the nuke event song so that it ends a couple seconds before the alert sound
         // should play
-        if (nuke.RemainingTime <= _nukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong && !string.IsNullOrEmpty(_selectedNukeSong))
+        if (nuke.RemainingTime <= _nukeSongLength + nuke.AlertSoundTime + NukeSongBuffer && !nuke.PlayedNukeSong && !ResolvedSoundSpecifier.IsNullOrEmpty(_selectedNukeSong))
         {
             _sound.DispatchStationEventMusic(uid, _selectedNukeSong, StationEventMusicType.Nuke);
             nuke.PlayedNukeSong = true;
@@ -311,7 +311,7 @@ public sealed class NukeSystem : EntitySystem
         // play alert sound if time is running out
         if (nuke.RemainingTime <= nuke.AlertSoundTime && !nuke.PlayedAlertSound)
         {
-            _sound.PlayGlobalOnStation(uid, _audio.GetSound(nuke.AlertSound), new AudioParams{Volume = -5f});
+            _sound.PlayGlobalOnStation(uid, _audio.ResolveSound(nuke.AlertSound), new AudioParams{Volume = -5f});
             _sound.StopStationEventMusic(uid, StationEventMusicType.Nuke);
             nuke.PlayedAlertSound = true;
             UpdateAppearance(uid, nuke);
@@ -469,7 +469,7 @@ public sealed class NukeSystem : EntitySystem
         var posText = $"({x}, {y})";
 
         // We are collapsing the randomness here, otherwise we would get separate random song picks for checking duration and when actually playing the song afterwards
-        _selectedNukeSong = _audio.GetSound(component.ArmMusic);
+        _selectedNukeSong = _audio.ResolveSound(component.ArmMusic);
 
         // warn a crew
         var announcement = Loc.GetString("nuke-component-announcement-armed",
@@ -478,7 +478,7 @@ public sealed class NukeSystem : EntitySystem
         var sender = Loc.GetString("nuke-component-announcement-sender");
         _chatSystem.DispatchStationAnnouncement(stationUid ?? uid, announcement, sender, false, null, Color.Red);
 
-        _sound.PlayGlobalOnStation(uid, _audio.GetSound(component.ArmSound));
+        _sound.PlayGlobalOnStation(uid, _audio.ResolveSound(component.ArmSound));
         _nukeSongLength = (float) _audio.GetAudioLength(_selectedNukeSong).TotalSeconds;
 
         // turn on the spinny light
@@ -519,7 +519,7 @@ public sealed class NukeSystem : EntitySystem
         _chatSystem.DispatchStationAnnouncement(uid, announcement, sender, false);
 
         component.PlayedNukeSong = false;
-        _sound.PlayGlobalOnStation(uid, _audio.GetSound(component.DisarmSound));
+        _sound.PlayGlobalOnStation(uid, _audio.ResolveSound(component.DisarmSound));
         _sound.StopStationEventMusic(uid, StationEventMusicType.Nuke);
 
         // reset nuke remaining time to either itself or the minimum time, whichever is higher
index b107e47c79d1a2b6bd407e29b6fa90a3acfab87e..cdcfcc1f21199d15a55948d6c60fe65b2fde91bd 100644 (file)
@@ -43,7 +43,7 @@ namespace Content.Server.Nutrition.EntitySystems
         {
             // The entity is deleted, so play the sound at its position rather than parenting
             var coordinates = Transform(uid).Coordinates;
-            _audio.PlayPvs(_audio.GetSound(creamPie.Sound), coordinates, AudioParams.Default.WithVariation(0.125f));
+            _audio.PlayPvs(_audio.ResolveSound(creamPie.Sound), coordinates, AudioParams.Default.WithVariation(0.125f));
 
             if (EntityManager.TryGetComponent(uid, out FoodComponent? foodComp))
             {
index a0bc5dd7394cdb4e5e93774f939a9d9d64252fd6..9b6ed3178157a3c007185627f0b60de21993dfcd 100644 (file)
@@ -161,7 +161,7 @@ public sealed class GeigerSystem : SharedGeigerSystem
         if (!_player.TryGetSessionByEntity(component.User.Value, out var session))
             return;
 
-        var sound = _audio.GetSound(sounds);
+        var sound = _audio.ResolveSound(sounds);
         var param = sounds.Params.WithLoop(true).WithVolume(-4f);
 
         component.Stream = _audio.PlayGlobal(sound, session, param)?.Entity;
index ff3c8176fd0747b9c61e045cf0ac22620481002f..2fa54fd11f8233e258752d1a665ce70a88cfb6e2 100644 (file)
@@ -56,5 +56,5 @@ public sealed partial class SalvageExpeditionComponent : SharedSalvageExpedition
     /// Song selected on MapInit so we can predict the audio countdown properly.
     /// </summary>
     [DataField]
-    public SoundPathSpecifier SelectedSong;
+    public ResolvedSoundSpecifier SelectedSong;
 }
index 923880169d5d5baaad0eec101ee30ad7e12222ed..65583b38f576fbd6aac2859701100b2edb043241 100644 (file)
@@ -69,8 +69,7 @@ public sealed partial class SalvageSystem
 
     private void OnExpeditionMapInit(EntityUid uid, SalvageExpeditionComponent component, MapInitEvent args)
     {
-        var selectedFile = _audio.GetSound(component.Sound);
-        component.SelectedSong = new SoundPathSpecifier(selectedFile, component.Sound.Params);
+        component.SelectedSong = _audio.ResolveSound(component.Sound);
     }
 
     private void OnExpeditionShutdown(EntityUid uid, SalvageExpeditionComponent component, ComponentShutdown args)
index 921d966709418f631e60628ea001a98aa905329f..98cff49f99943b02e32b0b17612ef4b14f75bddf 100644 (file)
@@ -144,7 +144,7 @@ public sealed partial class SalvageSystem
         while (query.MoveNext(out var uid, out var comp))
         {
             var remaining = comp.EndTime - _timing.CurTime;
-            var audioLength = _audio.GetAudioLength(comp.SelectedSong.Path.ToString());
+            var audioLength = _audio.GetAudioLength(comp.SelectedSong);
 
             if (comp.Stage < ExpeditionStage.FinalCountdown && remaining < TimeSpan.FromSeconds(45))
             {
index 7ad07c21aa15b7c663c84f69aab7c34cff41b5e7..b2ed5dc90d5c40e428117259787a330c68e02241 100644 (file)
@@ -14,11 +14,11 @@ public abstract class SharedGlobalSoundSystem : EntitySystem
 [Serializable, NetSerializable]
 public class GlobalSoundEvent : EntityEventArgs
 {
-    public string Filename;
+    public ResolvedSoundSpecifier Specifier;
     public AudioParams? AudioParams;
-    public GlobalSoundEvent(string filename, AudioParams? audioParams = null)
+    public GlobalSoundEvent(ResolvedSoundSpecifier specifier, AudioParams? audioParams = null)
     {
-        Filename = filename;
+        Specifier = specifier;
         AudioParams = audioParams;
     }
 }
@@ -29,7 +29,7 @@ public class GlobalSoundEvent : EntityEventArgs
 [Serializable, NetSerializable]
 public sealed class AdminSoundEvent : GlobalSoundEvent
 {
-    public AdminSoundEvent(string filename, AudioParams? audioParams = null) : base(filename, audioParams){}
+    public AdminSoundEvent(ResolvedSoundSpecifier specifier, AudioParams? audioParams = null) : base(specifier, audioParams){}
 }
 
 /// <summary>
@@ -38,7 +38,7 @@ public sealed class AdminSoundEvent : GlobalSoundEvent
 [Serializable, NetSerializable]
 public sealed class GameGlobalSoundEvent : GlobalSoundEvent
 {
-    public GameGlobalSoundEvent(string filename, AudioParams? audioParams = null) : base(filename, audioParams){}
+    public GameGlobalSoundEvent(ResolvedSoundSpecifier specifier, AudioParams? audioParams = null) : base(specifier, audioParams){}
 }
 
 public enum StationEventMusicType : byte
@@ -54,8 +54,8 @@ public sealed class StationEventMusicEvent : GlobalSoundEvent
 {
     public StationEventMusicType Type;
 
-    public StationEventMusicEvent(string filename, StationEventMusicType type, AudioParams? audioParams = null) : base(
-        filename, audioParams)
+    public StationEventMusicEvent(ResolvedSoundSpecifier specifier, StationEventMusicType type, AudioParams? audioParams = null) : base(
+        specifier, audioParams)
     {
         Type = type;
     }
index 015889b1523d70a2ae34c4abf72e71e4d2a5c028..050d4826cb4ad65d1bc9376f72757b978f58eb39 100644 (file)
@@ -6,6 +6,7 @@ using Robust.Shared.Serialization;
 using Robust.Shared.Serialization.Markdown.Mapping;
 using Robust.Shared.Serialization.Markdown.Value;
 using Robust.Shared.Timing;
+using Robust.Shared.Audio;
 
 namespace Content.Shared.GameTicking
 {
@@ -196,7 +197,7 @@ namespace Content.Shared.GameTicking
         /// <summary>
         /// Sound gets networked due to how entity lifecycle works between client / server and to avoid clipping.
         /// </summary>
-        public string? RestartSound;
+        public ResolvedSoundSpecifier? RestartSound;
 
         public RoundEndMessageEvent(
             string gamemodeTitle,
@@ -205,7 +206,7 @@ namespace Content.Shared.GameTicking
             int roundId,
             int playerCount,
             RoundEndPlayerInfo[] allPlayersEndInfo,
-            string? restartSound)
+            ResolvedSoundSpecifier? restartSound)
         {
             GamemodeTitle = gamemodeTitle;
             RoundEndText = roundEndText;
index 30744b68644cbc978811973728336000710175dd..67aabbb74d2da8ff5e7d936613656f578fc73885 100644 (file)
@@ -187,7 +187,7 @@ public abstract class SharedEmitSoundSystem : EntitySystem
 
         if (_netMan.IsServer && sound != null)
         {
-            _audioSystem.PlayPvs(_audioSystem.GetSound(sound), uid, AudioParams.Default.WithVolume(volume));
+            _audioSystem.PlayPvs(_audioSystem.ResolveSound(sound), uid, AudioParams.Default.WithVolume(volume));
         }
     }