using System.Collections.Generic; using SM.Base.Contexts; namespace SM.Base.Time { /// /// Represents a stopwatch. /// public class Stopwatch { private static List _activeStopwatches = new List(); /// /// Contains how much time already has passed. (in seconds) /// public float Elapsed { get; private set; } /// /// Starts the stopwatch. /// public virtual void Start() { _activeStopwatches.Add(this); } /// /// Performs a tick. /// /// private protected virtual void Tick(UpdateContext context) { Elapsed += context.Deltatime; } /// /// Stops the stopwatch. /// public virtual void Stop() { _activeStopwatches.Remove(this); } /// /// Resets the stopwatch. /// public void Reset() { Elapsed = 0; } internal static void PerformTicks(UpdateContext context) { for (var i = 0; i < _activeStopwatches.Count; i++) { _activeStopwatches[i].Tick(context); } } } }