Remove use delay cancellation tokens (#14405)

This commit is contained in:
Leon Friedrich
2023-03-06 05:42:04 +13:00
committed by GitHub
parent 4fd98f102b
commit a9b268af49
2 changed files with 5 additions and 18 deletions

View File

@@ -25,9 +25,7 @@ namespace Content.Shared.Timing
[DataField("remainingDelay")] [DataField("remainingDelay")]
public TimeSpan? RemainingDelay; public TimeSpan? RemainingDelay;
public CancellationTokenSource? CancellationTokenSource; public bool ActiveDelay => DelayEndTime != null;
public bool ActiveDelay => CancellationTokenSource is { Token: { IsCancellationRequested: false } };
} }
[Serializable, NetSerializable] [Serializable, NetSerializable]

View File

@@ -73,12 +73,12 @@ public sealed class UseDelaySystem : EntitySystem
var curTime = _gameTiming.CurTime; var curTime = _gameTiming.CurTime;
var mQuery = EntityManager.GetEntityQuery<MetaDataComponent>(); var mQuery = EntityManager.GetEntityQuery<MetaDataComponent>();
// TODO refactor this to use active components
foreach (var delay in _activeDelays) foreach (var delay in _activeDelays)
{ {
if (delay.DelayEndTime == null || if (delay.DelayEndTime == null ||
curTime > delay.DelayEndTime || curTime > delay.DelayEndTime ||
Deleted(delay.Owner, mQuery) || Deleted(delay.Owner, mQuery))
delay.CancellationTokenSource?.Token.IsCancellationRequested == true)
{ {
toRemove.Add(delay); toRemove.Add(delay);
} }
@@ -86,7 +86,6 @@ public sealed class UseDelaySystem : EntitySystem
foreach (var delay in toRemove) foreach (var delay in toRemove)
{ {
delay.CancellationTokenSource = null;
delay.DelayEndTime = null; delay.DelayEndTime = null;
_activeDelays.Remove(delay); _activeDelays.Remove(delay);
Dirty(delay); Dirty(delay);
@@ -98,9 +97,8 @@ public sealed class UseDelaySystem : EntitySystem
if (!Resolve(uid, ref component, false)) if (!Resolve(uid, ref component, false))
return; return;
if (component.ActiveDelay || Deleted(uid)) return; if (component.ActiveDelay)
return;
component.CancellationTokenSource = new CancellationTokenSource();
DebugTools.Assert(!_activeDelays.Contains(component)); DebugTools.Assert(!_activeDelays.Contains(component));
_activeDelays.Add(component); _activeDelays.Add(component);
@@ -123,8 +121,6 @@ public sealed class UseDelaySystem : EntitySystem
public void Cancel(UseDelayComponent component) public void Cancel(UseDelayComponent component)
{ {
component.CancellationTokenSource?.Cancel();
component.CancellationTokenSource = null;
component.DelayEndTime = null; component.DelayEndTime = null;
_activeDelays.Remove(component); _activeDelays.Remove(component);
Dirty(component); Dirty(component);
@@ -134,11 +130,4 @@ public sealed class UseDelaySystem : EntitySystem
cooldown.CooldownEnd = _gameTiming.CurTime; cooldown.CooldownEnd = _gameTiming.CurTime;
} }
} }
public void Restart(UseDelayComponent component)
{
component.CancellationTokenSource?.Cancel();
component.CancellationTokenSource = null;
BeginDelay(component.Owner, component);
}
} }