From 6ec29cae23eca8c2e53ef5c2e3cf19a64b6ba23b Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Tue, 17 Dec 2024 10:31:05 +0000 Subject: [PATCH 1/2] move proxy stuff from EntitySystem to EntManProxy --- .../GameObjects/EntManProxy.Events.cs | 97 +++++++++++++++++++ .../{EntitySystem.Proxy.cs => EntManProxy.cs} | 45 ++++++--- Robust.Shared/GameObjects/EntitySystem.cs | 92 +----------------- 3 files changed, 129 insertions(+), 105 deletions(-) create mode 100644 Robust.Shared/GameObjects/EntManProxy.Events.cs rename Robust.Shared/GameObjects/{EntitySystem.Proxy.cs => EntManProxy.cs} (97%) diff --git a/Robust.Shared/GameObjects/EntManProxy.Events.cs b/Robust.Shared/GameObjects/EntManProxy.Events.cs new file mode 100644 index 00000000000..d913a38e8f2 --- /dev/null +++ b/Robust.Shared/GameObjects/EntManProxy.Events.cs @@ -0,0 +1,97 @@ +using System.Runtime.CompilerServices; +using Robust.Shared.Network; +using Robust.Shared.Player; + +namespace Robust.Shared.GameObjects; + +public abstract partial class EntManProxy +{ + protected void RaiseLocalEvent(T message) where T : notnull + { + EntityManager.EventBus.RaiseEvent(EventSource.Local, message); + } + + protected void RaiseLocalEvent(ref T message) where T : notnull + { + EntityManager.EventBus.RaiseEvent(EventSource.Local, ref message); + } + + protected void RaiseLocalEvent(object message) + { + EntityManager.EventBus.RaiseEvent(EventSource.Local, message); + } + + protected void QueueLocalEvent(EntityEventArgs message) + { + EntityManager.EventBus.QueueEvent(EventSource.Local, message); + } + + protected void RaiseNetworkEvent(EntityEventArgs message) + { + EntityManager.EntityNetManager?.SendSystemNetworkMessage(message); + } + + protected void RaiseNetworkEvent(EntityEventArgs message, INetChannel channel) + { + EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, channel); + } + + protected void RaiseNetworkEvent(EntityEventArgs message, ICommonSession session) + { + EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); + } + + /// + /// Raises a networked event with some filter. + /// + /// The event to send + /// The filter that specifies recipients + /// Optional bool specifying whether or not to save this event to replays. + protected void RaiseNetworkEvent(EntityEventArgs message, Filter filter, bool recordReplay = true) + { + if (recordReplay) + ReplayMan.RecordServerMessage(message); + + foreach (var session in filter.Recipients) + { + EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); + } + } + + protected void RaiseNetworkEvent(EntityEventArgs message, EntityUid recipient) + { + if (PlayerManager.TryGetSessionByEntity(recipient, out var session)) + EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); + } + + protected void RaiseLocalEvent(EntityUid uid, TEvent args, bool broadcast = false) + where TEvent : notnull + { + EntityManager.EventBus.RaiseLocalEvent(uid, args, broadcast); + } + + protected void RaiseLocalEvent(EntityUid uid, object args, bool broadcast = false) + { + EntityManager.EventBus.RaiseLocalEvent(uid, args, broadcast); + } + + protected void RaiseLocalEvent(EntityUid uid, ref TEvent args, bool broadcast = false) + where TEvent : notnull + { + EntityManager.EventBus.RaiseLocalEvent(uid, ref args, broadcast); + } + + protected void RaiseLocalEvent(EntityUid uid, ref object args, bool broadcast = false) + { + EntityManager.EventBus.RaiseLocalEvent(uid, ref args, broadcast); + } + + /// + /// Sends a networked message to the server, while also repeatedly raising it locally for every time this tick gets re-predicted. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + protected void RaisePredictiveEvent(T msg) where T : EntityEventArgs + { + EntityManager.RaisePredictiveEvent(msg); + } +} diff --git a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs b/Robust.Shared/GameObjects/EntManProxy.cs similarity index 97% rename from Robust.Shared/GameObjects/EntitySystem.Proxy.cs rename to Robust.Shared/GameObjects/EntManProxy.cs index d1ad1e07b4c..88ac5fcef22 100644 --- a/Robust.Shared/GameObjects/EntitySystem.Proxy.cs +++ b/Robust.Shared/GameObjects/EntManProxy.cs @@ -6,13 +6,43 @@ using Robust.Shared.Containers; using Robust.Shared.Map; using Robust.Shared.Maths; +using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Timing; +using Robust.Shared.Replays; namespace Robust.Shared.GameObjects; -public partial class EntitySystem +/// +/// Base abstract class for classes that have an that can have methods proxied for convenience. +/// +/// +/// In an instead of using the verbose EntityManager.HasComponent(uid), you can use the proxy HasComp(uid). +/// +public abstract partial class EntManProxy { + #region Managers + + /// + /// The reference to use for proxy methods. + /// + /// + /// This cannot use as some non-interfaced methods are used. + /// + [IoC.Dependency] protected readonly EntityManager EntityManager = default!; + + /// + /// The reference to use for raising network events. + /// + [IoC.Dependency] protected readonly ISharedPlayerManager PlayerManager = default!; + + /// + /// The reference to use for raising network events. + /// + [IoC.Dependency] protected readonly IReplayRecordingManager ReplayMan = default!; + + #endregion + #region Entity LifeStage /// @@ -928,19 +958,6 @@ protected IEnumerable EntityQuery(bool includePaused = false) wh #endregion - #region Networked Events - - /// - /// Sends a networked message to the server, while also repeatedly raising it locally for every time this tick gets re-predicted. - /// - [MethodImpl(MethodImplOptions.AggressiveInlining)] - protected void RaisePredictiveEvent(T msg) where T : EntityEventArgs - { - EntityManager.RaisePredictiveEvent(msg); - } - - #endregion - #region NetEntities [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Robust.Shared/GameObjects/EntitySystem.cs b/Robust.Shared/GameObjects/EntitySystem.cs index d4e7b875f78..504aecd46ab 100644 --- a/Robust.Shared/GameObjects/EntitySystem.cs +++ b/Robust.Shared/GameObjects/EntitySystem.cs @@ -7,10 +7,7 @@ using Robust.Shared.IoC; using Robust.Shared.Localization; using Robust.Shared.Log; -using Robust.Shared.Network; -using Robust.Shared.Player; using Robust.Shared.Reflection; -using Robust.Shared.Replays; namespace Robust.Shared.GameObjects { @@ -21,12 +18,9 @@ namespace Robust.Shared.GameObjects /// This class is instantiated by the EntitySystemManager, and any IoC Dependencies will be resolved. /// [Reflect(false), PublicAPI] - public abstract partial class EntitySystem : IEntitySystem, IPostInjectInit + public abstract partial class EntitySystem : EntManProxy, IEntitySystem, IPostInjectInit { - [Dependency] protected readonly EntityManager EntityManager = default!; [Dependency] protected readonly ILogManager LogManager = default!; - [Dependency] private readonly ISharedPlayerManager _playerMan = default!; - [Dependency] private readonly IReplayRecordingManager _replayMan = default!; [Dependency] protected readonly ILocalizationManager Loc = default!; public ISawmill Log { get; private set; } = default!; @@ -93,90 +87,6 @@ public virtual void Shutdown() ShutdownSubscriptions(); } - #region Event Proxy - - protected void RaiseLocalEvent(T message) where T : notnull - { - EntityManager.EventBus.RaiseEvent(EventSource.Local, message); - } - - protected void RaiseLocalEvent(ref T message) where T : notnull - { - EntityManager.EventBus.RaiseEvent(EventSource.Local, ref message); - } - - protected void RaiseLocalEvent(object message) - { - EntityManager.EventBus.RaiseEvent(EventSource.Local, message); - } - - protected void QueueLocalEvent(EntityEventArgs message) - { - EntityManager.EventBus.QueueEvent(EventSource.Local, message); - } - - protected void RaiseNetworkEvent(EntityEventArgs message) - { - EntityManager.EntityNetManager?.SendSystemNetworkMessage(message); - } - - protected void RaiseNetworkEvent(EntityEventArgs message, INetChannel channel) - { - EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, channel); - } - - protected void RaiseNetworkEvent(EntityEventArgs message, ICommonSession session) - { - EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); - } - - /// - /// Raises a networked event with some filter. - /// - /// The event to send - /// The filter that specifies recipients - /// Optional bool specifying whether or not to save this event to replays. - protected void RaiseNetworkEvent(EntityEventArgs message, Filter filter, bool recordReplay = true) - { - if (recordReplay) - _replayMan.RecordServerMessage(message); - - foreach (var session in filter.Recipients) - { - EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); - } - } - - protected void RaiseNetworkEvent(EntityEventArgs message, EntityUid recipient) - { - if (_playerMan.TryGetSessionByEntity(recipient, out var session)) - EntityManager.EntityNetManager?.SendSystemNetworkMessage(message, session.Channel); - } - - protected void RaiseLocalEvent(EntityUid uid, TEvent args, bool broadcast = false) - where TEvent : notnull - { - EntityManager.EventBus.RaiseLocalEvent(uid, args, broadcast); - } - - protected void RaiseLocalEvent(EntityUid uid, object args, bool broadcast = false) - { - EntityManager.EventBus.RaiseLocalEvent(uid, args, broadcast); - } - - protected void RaiseLocalEvent(EntityUid uid, ref TEvent args, bool broadcast = false) - where TEvent : notnull - { - EntityManager.EventBus.RaiseLocalEvent(uid, ref args, broadcast); - } - - protected void RaiseLocalEvent(EntityUid uid, ref object args, bool broadcast = false) - { - EntityManager.EventBus.RaiseLocalEvent(uid, ref args, broadcast); - } - - #endregion - #region Static Helpers /* NOTE: Static helpers relating to EntitySystems are here rather than in a From 06e4ea4cde9b89d83b1c2bdaa4a7abcd58901a7b Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Tue, 17 Dec 2024 10:31:07 +0000 Subject: [PATCH 2/2] add proxy to BoundUserInterface --- .../Components/UserInterface/BoundUserInterface.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs b/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs index 07f622e40c3..b991a0510c9 100644 --- a/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs +++ b/Robust.Shared/GameObjects/Components/UserInterface/BoundUserInterface.cs @@ -9,10 +9,9 @@ namespace Robust.Shared.GameObjects /// /// An abstract class to override to implement bound user interfaces. /// - public abstract class BoundUserInterface : IDisposable + public abstract class BoundUserInterface : EntManProxy, IDisposable { - [Dependency] protected readonly IEntityManager EntMan = default!; - [Dependency] protected readonly ISharedPlayerManager PlayerManager = default!; + protected IEntityManager EntMan => EntityManager; protected readonly SharedUserInterfaceSystem UiSystem; public readonly Enum UiKey;