Remove 700 usages of Component.Owner (#21100)

This commit is contained in:
DrSmugleaf
2023-10-19 12:34:31 -07:00
committed by GitHub
parent 5825ffb95c
commit f560f88eb5
261 changed files with 2291 additions and 2036 deletions

View File

@@ -39,7 +39,7 @@ public sealed class AmbientSoundOverlay : Overlay
if (ambientSound.Enabled)
{
if (_ambient.IsActive(ambientSound))
if (_ambient.IsActive((ent, ambientSound)))
{
worldHandle.DrawCircle(xformSystem.GetWorldPosition(xform), Size, Color.LightGreen.WithAlpha(Alpha * 2f));
}

View File

@@ -1,18 +1,16 @@
using System.Linq;
using System.Numerics;
using Content.Shared.Audio;
using Content.Shared.CCVar;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Shared.Audio;
using Robust.Shared.Log;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Random;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using System.Linq;
using System.Numerics;
using Robust.Client.GameObjects;
namespace Content.Client.Audio;
//TODO: This is using a incomplete version of the whole "only play nearest sounds" algo, that breaks down a bit should the ambient sound cap get hit.
@@ -50,7 +48,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
/// </summary>
private int MaxSingleSound => (int) (_maxAmbientCount / (16.0f / 6.0f));
private readonly Dictionary<AmbientSoundComponent, (IPlayingAudioStream? Stream, SoundSpecifier Sound, string Path)> _playingSounds = new();
private readonly Dictionary<Entity<AmbientSoundComponent>, (IPlayingAudioStream? Stream, SoundSpecifier Sound, string Path)> _playingSounds = new();
private readonly Dictionary<string, int> _playingCount = new();
public bool OverlayEnabled
@@ -80,7 +78,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
/// </summary>
/// <param name="component"></param>
/// <returns></returns>
public bool IsActive(AmbientSoundComponent component)
public bool IsActive(Entity<AmbientSoundComponent> component)
{
return _playingSounds.ContainsKey(component);
}
@@ -100,7 +98,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
private void OnShutdown(EntityUid uid, AmbientSoundComponent component, ComponentShutdown args)
{
if (!_playingSounds.Remove(component, out var sound))
if (!_playingSounds.Remove((uid, component), out var sound))
return;
sound.Stream?.Stop();
@@ -113,7 +111,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
{
_ambienceVolume = value;
foreach (var (comp, values) in _playingSounds)
foreach (var ((_, comp), values) in _playingSounds)
{
if (values.Stream == null)
continue;
@@ -188,7 +186,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
private readonly struct QueryState
{
public readonly Dictionary<string, List<(float Importance, AmbientSoundComponent)>> SourceDict = new();
public readonly Dictionary<string, List<(float Importance, Entity<AmbientSoundComponent>)>> SourceDict = new();
public readonly Vector2 MapPos;
public readonly TransformComponent Player;
public readonly EntityQuery<TransformComponent> Query;
@@ -226,7 +224,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
// Prioritize far away & loud sounds.
var importance = range * (ambientComp.Volume + 32);
state.SourceDict.GetOrNew(key).Add((importance, ambientComp));
state.SourceDict.GetOrNew(key).Add((importance, (ambientComp.Owner, ambientComp)));
return true;
}
@@ -240,9 +238,10 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
var mapPos = playerXform.MapPosition;
// Remove out-of-range ambiences
foreach (var (comp, sound) in _playingSounds)
foreach (var (ent, sound) in _playingSounds)
{
var entity = comp.Owner;
var entity = ent.Owner;
var comp = ent.Comp;
if (comp.Enabled &&
// Don't keep playing sounds that have changed since.
@@ -260,7 +259,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
}
sound.Stream?.Stop();
_playingSounds.Remove(comp);
_playingSounds.Remove((entity, comp));
_playingCount[sound.Path] -= 1;
if (_playingCount[sound.Path] == 0)
_playingCount.Remove(sound.Path);
@@ -285,11 +284,12 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
sources.Sort(static (a, b) => b.Importance.CompareTo(a.Importance));
foreach (var (_, comp) in sources)
foreach (var (_, ent) in sources)
{
var uid = comp.Owner;
var uid = ent.Owner;
var comp = ent.Comp;
if (_playingSounds.ContainsKey(comp) ||
if (_playingSounds.ContainsKey(ent) ||
metaQuery.GetComponent(uid).EntityPaused)
continue;
@@ -303,7 +303,7 @@ public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
if (stream == null)
continue;
_playingSounds[comp] = (stream, comp.Sound, key);
_playingSounds[ent] = (stream, comp.Sound, key);
playingCount++;
if (_playingSounds.Count >= _maxAmbientCount)