From 5af1d0ea8b5a54cd1f1b48308176318032a457ea Mon Sep 17 00:00:00 2001 From: Hannah Giovanna Dawson Date: Sat, 20 Jan 2024 03:40:00 +0000 Subject: [PATCH] Fixes round restart audio clipping (#24044) * Fix round end audio clipping * weh --------- Co-authored-by: metalgearsloth --- Content.Client/Audio/BackgroundAudioSystem.cs | 21 +++++++++++++++++++ .../GameTicking/Managers/ClientGameTicker.cs | 2 ++ .../GameTicking/GameTicker.RoundFlow.cs | 3 ++- .../GameTicking/SharedGameTicker.cs | 8 ++++++- 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Content.Client/Audio/BackgroundAudioSystem.cs b/Content.Client/Audio/BackgroundAudioSystem.cs index 09ac1efcd6..27b2dcb1b7 100644 --- a/Content.Client/Audio/BackgroundAudioSystem.cs +++ b/Content.Client/Audio/BackgroundAudioSystem.cs @@ -1,6 +1,7 @@ using Content.Client.GameTicking.Managers; using Content.Client.Lobby; using Content.Shared.CCVar; +using Content.Shared.GameTicking; using JetBrains.Annotations; using Robust.Client; using Robust.Client.State; @@ -39,6 +40,8 @@ public sealed class BackgroundAudioSystem : EntitySystem _client.PlayerLeaveServer += OnLeave; _gameTicker.LobbySongUpdated += LobbySongUpdated; + + SubscribeNetworkEvent(PlayRestartSound); } public override void Shutdown() @@ -129,4 +132,22 @@ public sealed class BackgroundAudioSystem : EntitySystem { LobbyStream = _audio.Stop(LobbyStream); } + + private void PlayRestartSound(RoundRestartCleanupEvent ev) + { + if (!_configManager.GetCVar(CCVars.LobbyMusicEnabled)) + return; + + var file = _gameTicker.RestartSound; + if (string.IsNullOrEmpty(file)) + { + return; + } + + var volume = _lobbyParams.WithVolume(_lobbyParams.Volume + + SharedAudioSystem.GainToVolume( + _configManager.GetCVar(CCVars.LobbyMusicVolume))); + + _audio.PlayGlobal(file, Filter.Local(), false, volume); + } } diff --git a/Content.Client/GameTicking/Managers/ClientGameTicker.cs b/Content.Client/GameTicking/Managers/ClientGameTicker.cs index a62ebab1b7..a33a7a8e72 100644 --- a/Content.Client/GameTicking/Managers/ClientGameTicker.cs +++ b/Content.Client/GameTicking/Managers/ClientGameTicker.cs @@ -35,6 +35,7 @@ namespace Content.Client.GameTicking.Managers [ViewVariables] public bool AreWeReady { get; private set; } [ViewVariables] public bool IsGameStarted { get; private set; } [ViewVariables] public string? LobbySong { get; private set; } + [ViewVariables] public string? 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; } @@ -151,6 +152,7 @@ namespace Content.Client.GameTicking.Managers { // Force an update in the event of this song being the same as the last. SetLobbySong(message.LobbySong, true); + RestartSound = message.RestartSound; // Don't open duplicate windows (mainly for replays). if (_window?.RoundId == message.RoundId) diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs index 081cf533cd..c3e33f90ee 100644 --- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs +++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs @@ -385,9 +385,10 @@ 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 = _audio.GetSound(new SoundCollectionSpecifier("RoundEnd")); RaiseNetworkEvent(new RoundEndMessageEvent(gamemodeTitle, roundEndText, roundDuration, RoundId, - listOfPlayerInfoFinal.Length, listOfPlayerInfoFinal, LobbySong)); + listOfPlayerInfoFinal.Length, listOfPlayerInfoFinal, LobbySong, sound)); } private async void SendRoundEndDiscordMessage() diff --git a/Content.Shared/GameTicking/SharedGameTicker.cs b/Content.Shared/GameTicking/SharedGameTicker.cs index dac33fe5a7..7778588f97 100644 --- a/Content.Shared/GameTicking/SharedGameTicker.cs +++ b/Content.Shared/GameTicking/SharedGameTicker.cs @@ -166,6 +166,10 @@ namespace Content.Shared.GameTicking public int PlayerCount { get; } public RoundEndPlayerInfo[] AllPlayersEndInfo { get; } public string? LobbySong; + + /// + /// Sound gets networked due to how entity lifecycle works between client / server and to avoid clipping. + /// public string? RestartSound; public RoundEndMessageEvent( @@ -175,7 +179,8 @@ namespace Content.Shared.GameTicking int roundId, int playerCount, RoundEndPlayerInfo[] allPlayersEndInfo, - string? lobbySong) + string? lobbySong, + string? restartSound) { GamemodeTitle = gamemodeTitle; RoundEndText = roundEndText; @@ -184,6 +189,7 @@ namespace Content.Shared.GameTicking PlayerCount = playerCount; AllPlayersEndInfo = allPlayersEndInfo; LobbySong = lobbySong; + RestartSound = restartSound; } } -- 2.51.2