mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-15 11:40:52 +01:00
* Moved IPauseManager from server to shared. * Moved ITimerManager from Timers to Timing. * Added missing IConsoleHost to server/client RegisterIoC. Tests work again.
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using Robust.Shared.Exceptions;
|
|
using Robust.Shared.IoC;
|
|
|
|
namespace Robust.Shared.Timing
|
|
{
|
|
internal sealed class TimerManager : ITimerManager
|
|
{
|
|
[Dependency] private readonly IRuntimeLog _runtimeLog = default!;
|
|
|
|
private readonly List<(Timer, CancellationToken)> _timers
|
|
= new();
|
|
|
|
public void AddTimer(Timer timer, CancellationToken cancellationToken = default)
|
|
{
|
|
_timers.Add((timer, cancellationToken));
|
|
}
|
|
|
|
public void UpdateTimers(FrameEventArgs frameEventArgs)
|
|
{
|
|
// Manual for loop so we can modify the list while enumerating.
|
|
// ReSharper disable once ForCanBeConvertedToForeach
|
|
for (var i = 0; i < _timers.Count; i++)
|
|
{
|
|
var (timer, cancellationToken) = _timers[i];
|
|
|
|
if (cancellationToken.IsCancellationRequested)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
timer.Update(frameEventArgs.DeltaSeconds, _runtimeLog);
|
|
}
|
|
|
|
_timers.RemoveAll(timer => !timer.Item1.IsActive || timer.Item2.IsCancellationRequested);
|
|
}
|
|
}
|
|
}
|