From a9b268af49e1e4e36f60af17bcacf6476fa22f4c Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 6 Mar 2023 05:42:04 +1300 Subject: [PATCH] Remove use delay cancellation tokens (#14405) --- Content.Shared/Timing/UseDelayComponent.cs | 4 +--- Content.Shared/Timing/UseDelaySystem.cs | 19 ++++--------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/Content.Shared/Timing/UseDelayComponent.cs b/Content.Shared/Timing/UseDelayComponent.cs index e6884ebee2..8960ad688c 100644 --- a/Content.Shared/Timing/UseDelayComponent.cs +++ b/Content.Shared/Timing/UseDelayComponent.cs @@ -25,9 +25,7 @@ namespace Content.Shared.Timing [DataField("remainingDelay")] public TimeSpan? RemainingDelay; - public CancellationTokenSource? CancellationTokenSource; - - public bool ActiveDelay => CancellationTokenSource is { Token: { IsCancellationRequested: false } }; + public bool ActiveDelay => DelayEndTime != null; } [Serializable, NetSerializable] diff --git a/Content.Shared/Timing/UseDelaySystem.cs b/Content.Shared/Timing/UseDelaySystem.cs index 3626370d89..f6dcdafe41 100644 --- a/Content.Shared/Timing/UseDelaySystem.cs +++ b/Content.Shared/Timing/UseDelaySystem.cs @@ -73,12 +73,12 @@ public sealed class UseDelaySystem : EntitySystem var curTime = _gameTiming.CurTime; var mQuery = EntityManager.GetEntityQuery(); + // TODO refactor this to use active components foreach (var delay in _activeDelays) { if (delay.DelayEndTime == null || curTime > delay.DelayEndTime || - Deleted(delay.Owner, mQuery) || - delay.CancellationTokenSource?.Token.IsCancellationRequested == true) + Deleted(delay.Owner, mQuery)) { toRemove.Add(delay); } @@ -86,7 +86,6 @@ public sealed class UseDelaySystem : EntitySystem foreach (var delay in toRemove) { - delay.CancellationTokenSource = null; delay.DelayEndTime = null; _activeDelays.Remove(delay); Dirty(delay); @@ -98,9 +97,8 @@ public sealed class UseDelaySystem : EntitySystem if (!Resolve(uid, ref component, false)) return; - if (component.ActiveDelay || Deleted(uid)) return; - - component.CancellationTokenSource = new CancellationTokenSource(); + if (component.ActiveDelay) + return; DebugTools.Assert(!_activeDelays.Contains(component)); _activeDelays.Add(component); @@ -123,8 +121,6 @@ public sealed class UseDelaySystem : EntitySystem public void Cancel(UseDelayComponent component) { - component.CancellationTokenSource?.Cancel(); - component.CancellationTokenSource = null; component.DelayEndTime = null; _activeDelays.Remove(component); Dirty(component); @@ -134,11 +130,4 @@ public sealed class UseDelaySystem : EntitySystem cooldown.CooldownEnd = _gameTiming.CurTime; } } - - public void Restart(UseDelayComponent component) - { - component.CancellationTokenSource?.Cancel(); - component.CancellationTokenSource = null; - BeginDelay(component.Owner, component); - } }