mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 17:47:24 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
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 partial class TimerManager : ITimerManager
|
|
{
|
|
[Dependency] private 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);
|
|
}
|
|
}
|
|
}
|