diff --git a/Content.Client/GameObjects/Components/DoAfterComponent.cs b/Content.Client/GameObjects/Components/DoAfterComponent.cs index 14a15cf249..a658ca78de 100644 --- a/Content.Client/GameObjects/Components/DoAfterComponent.cs +++ b/Content.Client/GameObjects/Components/DoAfterComponent.cs @@ -18,7 +18,7 @@ namespace Content.Client.GameObjects.Components public IReadOnlyDictionary DoAfters => _doAfters; private readonly Dictionary _doAfters = new(); - + public readonly List<(TimeSpan CancelTime, ClientDoAfter Message)> CancelledDoAfters = new(); public DoAfterGui? Gui { get; set; } @@ -54,7 +54,7 @@ namespace Content.Client.GameObjects.Components if (Gui != null && !Gui.Disposed) return; - Gui = new DoAfterGui {AttachedEntity = Owner}; + Gui = new DoAfterGui {AttachedEntity = Owner, FirstDraw = true}; foreach (var (_, doAfter) in _doAfters) { diff --git a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs index a2f35bdddb..265e0ecc08 100644 --- a/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs +++ b/Content.Client/GameObjects/EntitySystems/DoAfter/DoAfterSystem.cs @@ -5,6 +5,7 @@ using Content.Client.GameObjects.Components; using Content.Shared.GameObjects.EntitySystems; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Client.Graphics; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Timing; @@ -25,6 +26,7 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter * DoAfterComponent handles network messages inbound as well as storing the DoAfter data. * It'll also handle overall cleanup when one is removed (i.e. removing it from DoAfterGui). */ + [Dependency] private readonly IEyeManager _eyeManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; /// @@ -32,10 +34,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter /// public const float ExcessTime = 0.5f; - // Each component in range will have its own vBox which we need to keep track of so if they go out of range or - // come into range it needs altering - private readonly HashSet _knownComponents = new(); - private IEntity? _attachedEntity; public override void Initialize() @@ -54,40 +52,37 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter base.Update(frameTime); var currentTime = _gameTiming.CurTime; - var foundComps = new HashSet(); // Can't see any I guess? if (_attachedEntity == null || _attachedEntity.Deleted) return; + var viewbox = _eyeManager.GetWorldViewport().Enlarged(2.0f); + foreach (var comp in ComponentManager.EntityQuery(true)) { - if (!_knownComponents.Contains(comp)) - { - _knownComponents.Add(comp); - } - var doAfters = comp.DoAfters.ToList(); + var compPos = comp.Owner.Transform.WorldPosition; - if (doAfters.Count == 0) + if (doAfters.Count == 0 || + comp.Owner.Transform.MapID != _attachedEntity.Transform.MapID || + !viewbox.Contains(compPos)) { - if (comp.Gui != null) - comp.Gui.FirstDraw = true; - + comp.Disable(); continue; } - var range = (comp.Owner.Transform.WorldPosition - _attachedEntity.Transform.WorldPosition).Length + 0.01f; + var range = (compPos - _attachedEntity.Transform.WorldPosition).Length + + 0.01f; - if (comp.Owner != _attachedEntity && !ExamineSystemShared.InRangeUnOccluded( - _attachedEntity.Transform.MapPosition, - comp.Owner.Transform.MapPosition, range, - entity => entity == comp.Owner || entity == _attachedEntity)) + if (comp.Owner != _attachedEntity && + !ExamineSystemShared.InRangeUnOccluded( + _attachedEntity.Transform.MapPosition, + comp.Owner.Transform.MapPosition, range, + entity => entity == comp.Owner || entity == _attachedEntity)) { - if (comp.Gui != null) - comp.Gui.FirstDraw = true; - - return; + comp.Disable(); + continue; } comp.Enable(); @@ -108,7 +103,9 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter // Don't predict cancellation if it's already finished. if (elapsedTime > doAfter.Delay) + { continue; + } // Predictions if (doAfter.BreakOnUserMove) @@ -122,7 +119,9 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter if (doAfter.BreakOnTargetMove) { - if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) && !targetEntity.Transform.Coordinates.InRange(EntityManager, doAfter.TargetGrid, doAfter.MovementThreshold)) + if (EntityManager.TryGetEntity(doAfter.TargetUid, out var targetEntity) && + !targetEntity.Transform.Coordinates.InRange(EntityManager, doAfter.TargetGrid, + doAfter.MovementThreshold)) { comp.Cancel(id, currentTime); continue; @@ -140,18 +139,6 @@ namespace Content.Client.GameObjects.EntitySystems.DoAfter comp.Remove(cancelled.Message); } } - - // Remove any components that we no longer need to track - foundComps.Add(comp); - } - - foreach (var comp in foundComps) - { - if (!_knownComponents.Contains(comp)) - { - _knownComponents.Remove(comp); - comp.Disable(); - } } } }