From 2d6eebfae2ff5e8d7c09a719e2ee35cc19db2450 Mon Sep 17 00:00:00 2001
From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Date: Sat, 28 Aug 2021 02:28:49 -0700
Subject: [PATCH] Rename GridCoordinates to FallbackCoordinates and move
GetFallbackCoordinates to shared
---
.../GameObjects/EntitySystems/AudioSystem.cs | 62 +++++++------------
.../GameObjects/EntitySystems/AudioSystem.cs | 28 ++-------
.../EntitySystemMessages/AudioMessages.cs | 4 +-
.../GameObjects/Systems/SharedAudioSystem.cs | 27 ++++++++
4 files changed, 56 insertions(+), 65 deletions(-)
create mode 100644 Robust.Shared/GameObjects/Systems/SharedAudioSystem.cs
diff --git a/Robust.Client/GameObjects/EntitySystems/AudioSystem.cs b/Robust.Client/GameObjects/EntitySystems/AudioSystem.cs
index 528a03887b..906f3c6da8 100644
--- a/Robust.Client/GameObjects/EntitySystems/AudioSystem.cs
+++ b/Robust.Client/GameObjects/EntitySystems/AudioSystem.cs
@@ -15,7 +15,7 @@ using Robust.Shared.Utility;
namespace Robust.Client.GameObjects
{
[UsedImplicitly]
- public class AudioSystem : EntitySystem, IAudioSystem
+ public class AudioSystem : SharedAudioSystem, IAudioSystem
{
[Dependency] private readonly IResourceCache _resourceCache = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
@@ -61,7 +61,7 @@ namespace Robust.Client.GameObjects
return;
}
- var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.GridCoordinates, ev.AudioParams);
+ var stream = (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
if (stream != null)
{
stream.NetIdentifier = ev.Identifier;
@@ -80,8 +80,8 @@ namespace Robust.Client.GameObjects
private void PlayAudioEntityHandler(PlayAudioEntityMessage ev)
{
var stream = EntityManager.TryGetEntity(ev.EntityUid, out var entity) ?
- (PlayingStream?) Play(ev.FileName, entity, ev.GridCoordinates, ev.AudioParams)
- : (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.GridCoordinates, ev.AudioParams);
+ (PlayingStream?) Play(ev.FileName, entity, ev.FallbackCoordinates, ev.AudioParams)
+ : (PlayingStream?) Play(ev.FileName, ev.Coordinates, ev.FallbackCoordinates, ev.AudioParams);
if (stream != null)
{
@@ -131,7 +131,7 @@ namespace Robust.Client.GameObjects
// TODO Remove when coordinates can't be NaN
if (mapPos == null || !float.IsFinite(mapPos.Value.X) || !float.IsFinite(mapPos.Value.Y))
- mapPos = stream.TrackingGridCoordinates?.ToMap(_entityManager);
+ mapPos = stream.TrackingFallbackCoordinates?.ToMap(_entityManager);
if (mapPos != null)
{
@@ -170,7 +170,6 @@ namespace Robust.Client.GameObjects
{
stream.Source.SetVelocity(stream.TrackingEntity.GlobalLinearVelocity());
}
-
}
}
}
@@ -231,14 +230,14 @@ namespace Robust.Client.GameObjects
///
/// The resource path to the OGG Vorbis file to play.
/// The entity "emitting" the audio.
- /// The coordinates at which to play the audio when entity doesn't exist.
+ /// The map or grid coordinates at which to play the audio when entity is invalid.
///
- private IPlayingAudioStream? Play(string filename, IEntity entity, EntityCoordinates gridCoordinates,
+ private IPlayingAudioStream? Play(string filename, IEntity entity, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
if (_resourceCache.TryGetResource(new ResourcePath(filename), out var audio))
{
- return Play(audio, entity, gridCoordinates, audioParams);
+ return Play(audio, entity, fallbackCoordinates, audioParams);
}
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
@@ -250,9 +249,9 @@ namespace Robust.Client.GameObjects
///
/// The audio stream to play.
/// The entity "emitting" the audio.
- /// The coordinates at which to play the audio when entity doesn't exist.
+ /// The map or grid coordinates at which to play the audio when entity is invalid.
///
- private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, EntityCoordinates gridCoordinates,
+ private IPlayingAudioStream? Play(AudioStream stream, IEntity entity, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
var source = _clyde.CreateAudioSource(stream);
@@ -270,7 +269,7 @@ namespace Robust.Client.GameObjects
{
Source = source,
TrackingEntity = entity,
- TrackingGridCoordinates = gridCoordinates,
+ TrackingFallbackCoordinates = fallbackCoordinates,
Volume = audioParams?.Volume ?? 0
};
_playingClydeStreams.Add(playing);
@@ -282,14 +281,14 @@ namespace Robust.Client.GameObjects
///
/// The resource path to the OGG Vorbis file to play.
/// The coordinates at which to play the audio.
- /// The coordinates at which to play the audio.
+ /// The map or grid coordinates at which to play the audio when coordinates are invalid.
///
- private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, EntityCoordinates gridCoordinates,
+ private IPlayingAudioStream? Play(string filename, EntityCoordinates coordinates, EntityCoordinates fallbackCoordinates,
AudioParams? audioParams = null)
{
if (_resourceCache.TryGetResource(new ResourcePath(filename), out var audio))
{
- return Play(audio, coordinates, gridCoordinates, audioParams);
+ return Play(audio, coordinates, fallbackCoordinates, audioParams);
}
Logger.Error($"Server tried to play audio file {filename} which does not exist.");
@@ -301,13 +300,13 @@ namespace Robust.Client.GameObjects
///
/// The audio stream to play.
/// The coordinates at which to play the audio.
- /// The coordinates at which to play the audio.
+ /// The map or grid coordinates at which to play the audio when coordinates are invalid.
///
private IPlayingAudioStream? Play(AudioStream stream, EntityCoordinates coordinates,
- EntityCoordinates gridCoordinates, AudioParams? audioParams = null)
+ EntityCoordinates fallbackCoordinates, AudioParams? audioParams = null)
{
var source = _clyde.CreateAudioSource(stream);
- if (!source.SetPosition(gridCoordinates.Position))
+ if (!source.SetPosition(fallbackCoordinates.Position))
{
source.Dispose();
Logger.Warning($"Can't play positional audio \"{stream.Name}\", can't set position.");
@@ -316,7 +315,7 @@ namespace Robust.Client.GameObjects
if (!coordinates.IsValid(_entityManager))
{
- coordinates = gridCoordinates;
+ coordinates = fallbackCoordinates;
}
ApplyAudioParams(audioParams, source);
@@ -326,7 +325,7 @@ namespace Robust.Client.GameObjects
{
Source = source,
TrackingCoordinates = coordinates,
- TrackingGridCoordinates = gridCoordinates,
+ TrackingFallbackCoordinates = fallbackCoordinates,
Volume = audioParams?.Volume ?? 0
};
_playingClydeStreams.Add(playing);
@@ -352,7 +351,7 @@ namespace Robust.Client.GameObjects
public IClydeAudioSource Source = default!;
public IEntity TrackingEntity = default!;
public EntityCoordinates? TrackingCoordinates;
- public EntityCoordinates? TrackingGridCoordinates;
+ public EntityCoordinates? TrackingFallbackCoordinates;
public bool Done;
public float Volume;
@@ -377,30 +376,13 @@ namespace Robust.Client.GameObjects
///
public IPlayingAudioStream? Play(Filter playerFilter, string filename, IEntity entity, AudioParams? audioParams = null)
{
- return Play(filename, entity, GetGridCoordinates(entity.Transform.MapPosition), audioParams);
+ return Play(filename, entity, GetFallbackCoordinates(entity.Transform.MapPosition), audioParams);
}
///
public IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
- return Play(filename, coordinates, GetGridCoordinates(coordinates.ToMap(_entityManager)), audioParams);
- }
-
- private EntityCoordinates GetGridCoordinates(MapCoordinates mapCoordinates)
- {
- if (_mapManager.TryFindGridAt(mapCoordinates, out var mapGrid))
- {
- return new EntityCoordinates(mapGrid.GridEntityId,
- mapGrid.WorldToLocal(mapCoordinates.Position));
- }
-
- if (_mapManager.HasMapEntity(mapCoordinates.MapId))
- {
- return new EntityCoordinates(_mapManager.GetMapEntityId(mapCoordinates.MapId),
- mapCoordinates.Position);
- }
-
- return EntityCoordinates.Invalid;
+ return Play(filename, coordinates, GetFallbackCoordinates(coordinates.ToMap(_entityManager)), audioParams);
}
}
}
diff --git a/Robust.Server/GameObjects/EntitySystems/AudioSystem.cs b/Robust.Server/GameObjects/EntitySystems/AudioSystem.cs
index df8d369315..ad7780d99b 100644
--- a/Robust.Server/GameObjects/EntitySystems/AudioSystem.cs
+++ b/Robust.Server/GameObjects/EntitySystems/AudioSystem.cs
@@ -11,9 +11,8 @@ using Robust.Shared.Players;
namespace Robust.Server.GameObjects
{
[UsedImplicitly]
- public class AudioSystem : EntitySystem, IAudioSystem
+ public class AudioSystem : SharedAudioSystem, IAudioSystem
{
- [Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IEntityManager _entityManager = default!;
private const int AudioDistanceRange = 25;
@@ -97,13 +96,13 @@ namespace Robust.Server.GameObjects
var id = CacheIdentifier();
- var gridCoordinates = GetGridCoordinates(entity.Transform.MapPosition);
+ var fallbackCoordinates = GetFallbackCoordinates(entity.Transform.MapPosition);
var msg = new PlayAudioEntityMessage
{
FileName = filename,
Coordinates = entity.Transform.Coordinates,
- GridCoordinates = gridCoordinates,
+ FallbackCoordinates = fallbackCoordinates,
EntityUid = entity.Uid,
AudioParams = audioParams ?? AudioParams.Default,
Identifier = id,
@@ -126,13 +125,13 @@ namespace Robust.Server.GameObjects
var id = CacheIdentifier();
- var gridCoordinates = GetGridCoordinates(coordinates.ToMap(_entityManager));
+ var fallbackCoordinates = GetFallbackCoordinates(coordinates.ToMap(_entityManager));
var msg = new PlayAudioPositionalMessage
{
FileName = filename,
Coordinates = coordinates,
- GridCoordinates = gridCoordinates,
+ FallbackCoordinates = fallbackCoordinates,
AudioParams = audioParams ?? AudioParams.Default,
Identifier = id
};
@@ -145,22 +144,5 @@ namespace Robust.Server.GameObjects
return new AudioSourceServer(this, id, playerFilter.Recipients.ToArray());
}
-
- private EntityCoordinates GetGridCoordinates(MapCoordinates mapCoordinates)
- {
- if (_mapManager.TryFindGridAt(mapCoordinates, out var mapGrid))
- {
- return new EntityCoordinates(mapGrid.GridEntityId,
- mapGrid.WorldToLocal(mapCoordinates.Position));
- }
-
- if (_mapManager.HasMapEntity(mapCoordinates.MapId))
- {
- return new EntityCoordinates(_mapManager.GetMapEntityId(mapCoordinates.MapId),
- mapCoordinates.Position);
- }
-
- return EntityCoordinates.Invalid;
- }
}
}
diff --git a/Robust.Shared/GameObjects/EntitySystemMessages/AudioMessages.cs b/Robust.Shared/GameObjects/EntitySystemMessages/AudioMessages.cs
index aabc7e1a8e..3f2e809bee 100644
--- a/Robust.Shared/GameObjects/EntitySystemMessages/AudioMessages.cs
+++ b/Robust.Shared/GameObjects/EntitySystemMessages/AudioMessages.cs
@@ -33,7 +33,7 @@ namespace Robust.Shared.GameObjects
public class PlayAudioPositionalMessage : AudioMessage
{
public EntityCoordinates Coordinates { get; set; }
- public EntityCoordinates GridCoordinates { get; set; }
+ public EntityCoordinates FallbackCoordinates { get; set; }
}
[Serializable, NetSerializable]
@@ -41,6 +41,6 @@ namespace Robust.Shared.GameObjects
{
public EntityUid EntityUid { get; set; }
public EntityCoordinates Coordinates { get; set; }
- public EntityCoordinates GridCoordinates { get; set; }
+ public EntityCoordinates FallbackCoordinates { get; set; }
}
}
diff --git a/Robust.Shared/GameObjects/Systems/SharedAudioSystem.cs b/Robust.Shared/GameObjects/Systems/SharedAudioSystem.cs
new file mode 100644
index 0000000000..4bfd34ad47
--- /dev/null
+++ b/Robust.Shared/GameObjects/Systems/SharedAudioSystem.cs
@@ -0,0 +1,27 @@
+using Robust.Shared.IoC;
+using Robust.Shared.Map;
+
+namespace Robust.Shared.GameObjects
+{
+ public class SharedAudioSystem : EntitySystem
+ {
+ [Dependency] private readonly IMapManager _mapManager = default!;
+
+ protected EntityCoordinates GetFallbackCoordinates(MapCoordinates mapCoordinates)
+ {
+ if (_mapManager.TryFindGridAt(mapCoordinates, out var mapGrid))
+ {
+ return new EntityCoordinates(mapGrid.GridEntityId,
+ mapGrid.WorldToLocal(mapCoordinates.Position));
+ }
+
+ if (_mapManager.HasMapEntity(mapCoordinates.MapId))
+ {
+ return new EntityCoordinates(_mapManager.GetMapEntityId(mapCoordinates.MapId),
+ mapCoordinates.Position);
+ }
+
+ return EntityCoordinates.Invalid;
+ }
+ }
+}