SoundSystem (#3467)

* Converted some audio calls over to the new system.

* Update Submodule.
This commit is contained in:
Acruid
2021-03-01 20:42:54 -08:00
committed by GitHub
parent 609fcf25ac
commit 91cea56a5a
10 changed files with 37 additions and 37 deletions

View File

@@ -1,8 +1,8 @@
using Content.Shared.GameObjects.Components.PDA; using Content.Shared.GameObjects.Components.PDA;
using Robust.Client.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Players; using Robust.Shared.Players;
namespace Content.Client.GameObjects.Components.PDA namespace Content.Client.GameObjects.Components.PDA
@@ -16,11 +16,11 @@ namespace Content.Client.GameObjects.Components.PDA
switch(message) switch(message)
{ {
case PDAUplinkBuySuccessMessage _ : case PDAUplinkBuySuccessMessage _ :
EntitySystem.Get<AudioSystem>().Play("/Audio/Effects/kaching.ogg", Owner, AudioParams.Default.WithVolume(-2f)); SoundSystem.Play(Filter.Local(), "/Audio/Effects/kaching.ogg", Owner, AudioParams.Default.WithVolume(-2f));
break; break;
case PDAUplinkInsufficientFundsMessage _ : case PDAUplinkInsufficientFundsMessage _ :
EntitySystem.Get<AudioSystem>().Play("/Audio/Effects/error.ogg", Owner, AudioParams.Default); SoundSystem.Play(Filter.Local(), "/Audio/Effects/error.ogg", Owner, AudioParams.Default);
break; break;
} }

View File

@@ -1,10 +1,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using Content.Shared.GameObjects.Components.Sound; using Content.Shared.GameObjects.Components.Sound;
using Content.Shared.Physics; using Content.Shared.Physics;
using Robust.Client.GameObjects; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Network; using Robust.Shared.Network;
using Robust.Shared.Player;
using Robust.Shared.Players; using Robust.Shared.Players;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -17,7 +18,6 @@ namespace Content.Client.GameObjects.Components.Sound
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
private readonly Dictionary<ScheduledSound, IPlayingAudioStream> _audioStreams = new(); private readonly Dictionary<ScheduledSound, IPlayingAudioStream> _audioStreams = new();
private AudioSystem _audioSystem;
public override void StopAllSounds() public override void StopAllSounds()
{ {
@@ -52,15 +52,14 @@ namespace Content.Client.GameObjects.Components.Sound
Owner.SpawnTimer((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() => Owner.SpawnTimer((int) schedule.Delay + (_random.Next((int) schedule.RandomDelay)),() =>
{ {
if (!schedule.Play) return; // We make sure this hasn't changed. if (!schedule.Play) return; // We make sure this hasn't changed.
if (_audioSystem == null) _audioSystem = EntitySystem.Get<AudioSystem>();
if (!_audioStreams.ContainsKey(schedule)) if (!_audioStreams.ContainsKey(schedule))
{ {
_audioStreams.Add(schedule,_audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams)); _audioStreams.Add(schedule,SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams));
} }
else else
{ {
_audioStreams[schedule] = _audioSystem.Play(schedule.Filename, Owner, schedule.AudioParams); _audioStreams[schedule] = SoundSystem.Play(Filter.Local(), schedule.Filename, Owner, schedule.AudioParams);
} }
if (schedule.Times == 0) return; if (schedule.Times == 0) return;
@@ -93,7 +92,7 @@ namespace Content.Client.GameObjects.Components.Sound
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
if (EntitySystem.TryGet(out _audioSystem)) _audioSystem.OcclusionCollisionMask = (int) CollisionGroup.Impassable; SoundSystem.OcclusionCollisionMask = (int) CollisionGroup.Impassable;
} }
public override void ExposeData(ObjectSerializer serializer) public override void ExposeData(ObjectSerializer serializer)

View File

@@ -100,7 +100,7 @@ namespace Content.Server.GameObjects.Components.Singularity
private SpriteComponent? _spriteComponent; private SpriteComponent? _spriteComponent;
private RadiationPulseComponent? _radiationPulseComponent; private RadiationPulseComponent? _radiationPulseComponent;
private AudioSystem _audioSystem = null!; private AudioSystem _audioSystem = null!;
private AudioSystem.AudioSourceServer? _playingSound; private IPlayingAudioStream? _playingSound;
public override void Initialize() public override void Initialize()
{ {

View File

@@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -20,6 +20,7 @@ using Robust.Shared.Log;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Maths; using Robust.Shared.Maths;
using Robust.Shared.Physics; using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -211,12 +212,11 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
/// <param name="targetPos">Target position on the map to shoot at.</param> /// <param name="targetPos">Target position on the map to shoot at.</param>
private void Fire(IEntity shooter, Vector2 targetPos) private void Fire(IEntity shooter, Vector2 targetPos)
{ {
var soundSystem = EntitySystem.Get<AudioSystem>();
if (ShotsLeft == 0) if (ShotsLeft == 0)
{ {
if (_soundEmpty != null) if (_soundEmpty != null)
{ {
soundSystem.PlayAtCoords(_soundEmpty, Owner.Transform.Coordinates); SoundSystem.Play(Filter.Broadcast(), _soundEmpty, Owner.Transform.Coordinates);
} }
return; return;
} }
@@ -225,7 +225,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
var projectile = TakeProjectile(shooter.Transform.Coordinates); var projectile = TakeProjectile(shooter.Transform.Coordinates);
if (projectile == null) if (projectile == null)
{ {
soundSystem.PlayAtCoords(_soundEmpty, Owner.Transform.Coordinates); SoundSystem.Play(Filter.Broadcast(), _soundEmpty, Owner.Transform.Coordinates);
return; return;
} }
@@ -266,7 +266,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
soundSystem.PlayAtCoords(_soundGunshot, Owner.Transform.Coordinates); SoundSystem.Play(Filter.Broadcast(), _soundGunshot, Owner.Transform.Coordinates);
_lastFire = _gameTiming.CurTime; _lastFire = _gameTiming.CurTime;
return; return;
@@ -316,7 +316,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged.Barrels
var soundCollection = prototypeManager.Index<SoundCollectionPrototype>(ammo.SoundCollectionEject); var soundCollection = prototypeManager.Index<SoundCollectionPrototype>(ammo.SoundCollectionEject);
var randomFile = robustRandom.Pick(soundCollection.PickFiles); var randomFile = robustRandom.Pick(soundCollection.PickFiles);
EntitySystem.Get<AudioSystem>().PlayAtCoords(randomFile, entity.Transform.Coordinates, AudioParams.Default.WithVolume(-1)); SoundSystem.Play(Filter.Broadcast(), randomFile, entity.Transform.Coordinates, AudioParams.Default.WithVolume(-1));
} }
/// <summary> /// <summary>

View File

@@ -4,9 +4,11 @@ using Content.Server.Interfaces.Chat;
using Content.Server.Interfaces.GameTicking; using Content.Server.Interfaces.GameTicking;
using Content.Shared.GameTicking; using Content.Shared.GameTicking;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Timer = Robust.Shared.Timing.Timer; using Timer = Robust.Shared.Timing.Timer;
@@ -80,7 +82,7 @@ namespace Content.Server.GameObjects.EntitySystems
_chatManager.DispatchStationAnnouncement(Loc.GetString("An emergency shuttle has been sent. ETA: {0} minutes.", RoundEndCountdownTime.Minutes), Loc.GetString("Station")); _chatManager.DispatchStationAnnouncement(Loc.GetString("An emergency shuttle has been sent. ETA: {0} minutes.", RoundEndCountdownTime.Minutes), Loc.GetString("Station"));
Get<AudioSystem>().PlayGlobal("/Audio/Announcements/shuttlecalled.ogg"); SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlecalled.ogg");
ExpectedCountdownEnd = _gameTiming.CurTime + RoundEndCountdownTime; ExpectedCountdownEnd = _gameTiming.CurTime + RoundEndCountdownTime;
Timer.Spawn(RoundEndCountdownTime, EndRound, _roundEndCancellationTokenSource.Token); Timer.Spawn(RoundEndCountdownTime, EndRound, _roundEndCancellationTokenSource.Token);
@@ -104,7 +106,7 @@ namespace Content.Server.GameObjects.EntitySystems
_chatManager.DispatchStationAnnouncement(Loc.GetString("The emergency shuttle has been recalled."), Loc.GetString("Station")); _chatManager.DispatchStationAnnouncement(Loc.GetString("The emergency shuttle has been recalled."), Loc.GetString("Station"));
Get<AudioSystem>().PlayGlobal("/Audio/Announcements/shuttlerecalled.ogg"); SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/shuttlerecalled.ogg");
_roundEndCancellationTokenSource.Cancel(); _roundEndCancellationTokenSource.Cancel();
_roundEndCancellationTokenSource = new CancellationTokenSource(); _roundEndCancellationTokenSource = new CancellationTokenSource();

View File

@@ -9,13 +9,13 @@ using Content.Server.Mobs.Roles.Suspicion;
using Content.Server.Players; using Content.Server.Players;
using Content.Shared; using Content.Shared;
using Content.Shared.GameObjects.Components.Mobs.State; using Content.Shared.GameObjects.Components.Mobs.State;
using Robust.Server.GameObjects;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Configuration; using Robust.Shared.Configuration;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Timing; using Robust.Shared.Timing;
using Timer = Robust.Shared.Timing.Timer; using Timer = Robust.Shared.Timing.Timer;
@@ -48,9 +48,9 @@ namespace Content.Server.GameTicking.GameRules
_chatManager.DispatchServerAnnouncement(Loc.GetString("There are traitors on the station! Find them, and kill them!")); _chatManager.DispatchServerAnnouncement(Loc.GetString("There are traitors on the station! Find them, and kill them!"));
bool Predicate(IPlayerSession session) => session.ContentData()?.Mind?.HasRole<SuspicionTraitorRole>() ?? false; var filter = Filter.Empty()
.AddWhere(session => ((IPlayerSession)session).ContentData()?.Mind?.HasRole<SuspicionTraitorRole>() ?? false);
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Misc/tatoralert.ogg", AudioParams.Default, Predicate); SoundSystem.Play(filter, "/Audio/Misc/tatoralert.ogg", AudioParams.Default);
EntitySystem.Get<SuspicionEndTimerSystem>().EndTime = _endTime; EntitySystem.Get<SuspicionEndTimerSystem>().EndTime = _endTime;
EntitySystem.Get<ServerDoorSystem>().AccessType = ServerDoorSystem.AccessTypes.AllowAllNoExternal; EntitySystem.Get<ServerDoorSystem>().AccessType = ServerDoorSystem.AccessTypes.AllowAllNoExternal;

View File

@@ -1,12 +1,11 @@
using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.Chat;
using Content.Server.Mobs.Roles.Traitor; using Content.Server.Mobs.Roles.Traitor;
using Content.Server.Players; using Content.Server.Players;
using Robust.Server.GameObjects;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player;
namespace Content.Server.GameTicking.GameRules namespace Content.Server.GameTicking.GameRules
{ {
@@ -18,9 +17,9 @@ namespace Content.Server.GameTicking.GameRules
{ {
_chatManager.DispatchServerAnnouncement(Loc.GetString("Hello crew! Have a good shift!")); _chatManager.DispatchServerAnnouncement(Loc.GetString("Hello crew! Have a good shift!"));
bool Predicate(IPlayerSession session) => session.ContentData()?.Mind?.HasRole<TraitorRole>() ?? false; var filter = Filter.Empty()
.AddWhere(session => ((IPlayerSession)session).ContentData()?.Mind?.HasRole<TraitorRole>() ?? false);
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Misc/tatoralert.ogg", AudioParams.Default, Predicate); SoundSystem.Play(filter, "/Audio/Misc/tatoralert.ogg", AudioParams.Default);
} }
} }
} }

View File

@@ -1,12 +1,13 @@
#nullable enable #nullable enable
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using Content.Server.GameObjects.Components.Power.ApcNetComponents; using Content.Server.GameObjects.Components.Power.ApcNetComponents;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Server.GameObjects; using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Timer = Robust.Shared.Timing.Timer; using Timer = Robust.Shared.Timing.Timer;
@@ -68,7 +69,7 @@ namespace Content.Server.StationEvents
_announceCancelToken = new CancellationTokenSource(); _announceCancelToken = new CancellationTokenSource();
Timer.Spawn(3000, () => Timer.Spawn(3000, () =>
{ {
EntitySystem.Get<AudioSystem>().PlayGlobal("/Audio/Announcements/power_on.ogg"); SoundSystem.Play(Filter.Broadcast(), "/Audio/Announcements/power_on.ogg");
}, _announceCancelToken.Token); }, _announceCancelToken.Token);
_powered.Clear(); _powered.Clear();

View File

@@ -1,9 +1,8 @@
#nullable enable #nullable enable
using Content.Server.Interfaces.Chat; using Content.Server.Interfaces.Chat;
using Robust.Server.GameObjects;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Player;
namespace Content.Server.StationEvents namespace Content.Server.StationEvents
{ {
@@ -121,7 +120,7 @@ namespace Content.Server.StationEvents
if (StartAudio != null) if (StartAudio != null)
{ {
EntitySystem.Get<AudioSystem>().PlayGlobal(StartAudio, AudioParams.Default.WithVolume(-10f)); SoundSystem.Play(Filter.Broadcast(), StartAudio, AudioParams.Default.WithVolume(-10f));
} }
Announced = true; Announced = true;
@@ -141,7 +140,7 @@ namespace Content.Server.StationEvents
if (EndAudio != null) if (EndAudio != null)
{ {
EntitySystem.Get<AudioSystem>().PlayGlobal(EndAudio, AudioParams.Default.WithVolume(-10f)); SoundSystem.Play(Filter.Broadcast(), EndAudio, AudioParams.Default.WithVolume(-10f));
} }
Started = false; Started = false;