daily update on 20240528 by nitload youmu

This commit is contained in:
Nitload
2024-05-28 17:45:54 +08:00
parent de399e22c2
commit 70890e3e33
88 changed files with 10678 additions and 5761 deletions
+44 -8
View File
@@ -43,15 +43,17 @@ namespace StgSharp
public class TimeSpanProvider
{
private Action _frameUpdateMissCallback = null;
private readonly int _maxSpanCount;
private Action _frameUpdateMissCallback = () => { };
private Action _refreshCallback;
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
private long _spanBegin;
private readonly long _spanLength;
private bool _subscribed;
private Counter<int> timeSpanCount = new Counter<int>(-1, 1, 1);
private readonly int _maxSpanCount;
private long _spanBegin;
private readonly long _spanLength;
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
private readonly TimeSourceProviderBase _timeSource;
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
@@ -60,6 +62,11 @@ namespace StgSharp
/// <param name="provider"></param>
public TimeSpanProvider(long spanMicroSeconds, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_timeSource = provider;
_spanLength = spanMicroSeconds;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
@@ -75,6 +82,10 @@ namespace StgSharp
/// <param name="provider"></param>
public TimeSpanProvider(double spanSeconds, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
_spanLength = (long)(spanSeconds * 1000L * 1000L);
_spanBegin = -_spanLength;
_maxSpanCount = int.MaxValue;
@@ -91,6 +102,10 @@ namespace StgSharp
/// <param name="provider"></param>
public TimeSpanProvider(long spanLength, int maxSpan, TimeSourceProviderBase provider)
{
if (provider == null)
{
throw new ArgumentNullException(nameof(provider));
}
if (maxSpan <= 0)
{
maxSpan = int.MaxValue;
@@ -101,7 +116,14 @@ namespace StgSharp
}
public int CurrentSpan
=> timeSpanCount.Value;
{
get => timeSpanCount.Value;
}
public float CurrentSecond
{
get => timeSpanCount.Value * SpanLengthLowPrecession;
}
/// <summary>
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
@@ -114,6 +136,16 @@ namespace StgSharp
set => _frameUpdateMissCallback = value;
}
public double SpanLength
{
get => (_spanLength * 1.0) / (1000L * 1000L);
}
public float SpanLengthLowPrecession
{
get => (_spanLength * 1.0f) / (1000 * 1000);
}
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
@@ -125,6 +157,10 @@ namespace StgSharp
public void SubscribeToTimeSource(TimeSourceProviderBase serviceHandler)
{
if (serviceHandler == null)
{
throw new ArgumentNullException(nameof(serviceHandler));
}
if (_subscribed)
{
return;
@@ -144,7 +180,7 @@ namespace StgSharp
{
return true;
}
_spanBegin = microseconds;
timeSpanCount++;