diff --git a/src/LogicLooper/ILogicLooper.cs b/src/LogicLooper/ILogicLooper.cs index 40ee318..b67d0ec 100644 --- a/src/LogicLooper/ILogicLooper.cs +++ b/src/LogicLooper/ILogicLooper.cs @@ -11,7 +11,7 @@ public interface ILogicLooper : IDisposable int Id { get; } /// - /// Gets an approximately count of running actions. + /// Gets an approximate count of running actions. /// int ApproximatelyRunningActions { get; } @@ -25,6 +25,11 @@ public interface ILogicLooper : IDisposable /// double TargetFrameRate { get; } + /// + /// Gets a current frame that elapsed since beginning the looper is started. + /// + long CurrentFrame { get; } + /// /// Registers a loop-frame action to the looper and returns to wait for completion. /// diff --git a/src/LogicLooper/LogicLooper.cs b/src/LogicLooper/LogicLooper.cs index 4db2767..8935049 100644 --- a/src/LogicLooper/LogicLooper.cs +++ b/src/LogicLooper/LogicLooper.cs @@ -48,24 +48,16 @@ public sealed class LogicLooper : ILogicLooper, IDisposable private int _isShuttingDown = 0; private long _frame = 0; - /// - /// Gets a unique identifier of the looper. - /// + /// public int Id => _looperId; - /// - /// Gets an approximately count of running actions. - /// + /// public int ApproximatelyRunningActions => _tail; - /// - /// Gets a duration of the last processed frame. - /// + /// public TimeSpan LastProcessingDuration => TimeSpan.FromMilliseconds(_lastProcessingDuration); - /// - /// Gets a target frame rate of the looper. - /// + /// public double TargetFrameRate => _targetFrameRate; /// @@ -73,6 +65,9 @@ public sealed class LogicLooper : ILogicLooper, IDisposable /// internal int ThreadId => _runLoopThread.ManagedThreadId; + /// + public long CurrentFrame => _frame; + public LogicLooper(int targetFrameRate, int initialActionsCapacity = 16) : this(TimeSpan.FromMilliseconds(1000 / (double)targetFrameRate), initialActionsCapacity) { diff --git a/src/LogicLooper/ManualLogicLooper.cs b/src/LogicLooper/ManualLogicLooper.cs index e2223f6..2c46df8 100644 --- a/src/LogicLooper/ManualLogicLooper.cs +++ b/src/LogicLooper/ManualLogicLooper.cs @@ -23,6 +23,9 @@ public sealed class ManualLogicLooper : ILogicLooper /// public double TargetFrameRate { get; } + /// + public long CurrentFrame => _frame; + public ManualLogicLooper(double targetFrameRate) { if (targetFrameRate == 0) throw new ArgumentOutOfRangeException(nameof(targetFrameRate), "TargetFrameRate must be greater than 0."); diff --git a/test/LogicLooper.Test/ManualLogicLooperTest.cs b/test/LogicLooper.Test/ManualLogicLooperTest.cs index 560d688..38c0958 100644 --- a/test/LogicLooper.Test/ManualLogicLooperTest.cs +++ b/test/LogicLooper.Test/ManualLogicLooperTest.cs @@ -53,12 +53,16 @@ public void Tick() looper.ApproximatelyRunningActions.Should().Be(1); count.Should().Be(0); + looper.CurrentFrame.Should().Be(0); looper.Tick().Should().BeTrue(); count.Should().Be(1); + looper.CurrentFrame.Should().Be(1); looper.Tick().Should().BeTrue(); count.Should().Be(2); + looper.CurrentFrame.Should().Be(2); looper.Tick().Should().BeFalse(); count.Should().Be(3); + looper.CurrentFrame.Should().Be(3); looper.ApproximatelyRunningActions.Should().Be(0); t1.IsCompletedSuccessfully.Should().BeTrue();