daily update on 20240320 by nitload youmu
This commit is contained in:
@@ -32,6 +32,7 @@ using StgSharpDebug.Logic;
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
@@ -48,7 +49,8 @@ namespace StgSharp
|
||||
private long _spanBegin;
|
||||
private readonly long _spanLength;
|
||||
private bool _subscribed;
|
||||
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
|
||||
private Counter<int> timeSpanCount = new Counter<int>(-1, 1, 1);
|
||||
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0,1);
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
|
||||
@@ -61,19 +63,36 @@ namespace StgSharp
|
||||
provider.AddSubscriber(this);
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span.
|
||||
/// Length of a single time span is defined in seconds.
|
||||
/// </summary>
|
||||
/// <param name="spanLength"></param>
|
||||
/// <parma name="provider"></parma>
|
||||
public TimeSpanProvider(double spanLength, TimeSourceProviderBase provider)
|
||||
{
|
||||
_spanLength = ((int)spanLength) * 1000L * 1000L; _spanBegin = -_spanLength;
|
||||
provider.AddSubscriber(this);
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
|
||||
/// </summary>
|
||||
/// <param name="spanLength"></param>
|
||||
/// <parma name="provider"></parma>
|
||||
public TimeSpanProvider(long spanLength, uint maxSpan, TimeSourceProviderBase provider)
|
||||
public TimeSpanProvider(long spanLength, int maxSpan, TimeSourceProviderBase provider)
|
||||
{
|
||||
_spanLength = spanLength;
|
||||
if (maxSpan <= 0)
|
||||
{
|
||||
maxSpan = int.MaxValue;
|
||||
}
|
||||
_spanLength = spanLength; _spanBegin = -_spanLength;
|
||||
provider.AddSubscriber(this);
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
|
||||
/// </summary>
|
||||
@@ -105,15 +124,39 @@ namespace StgSharp
|
||||
{
|
||||
_spanBegin = microseconds;
|
||||
timeSpanCount++;
|
||||
}
|
||||
if (timeSpanCount > _maxSpanCount)
|
||||
{
|
||||
return false;
|
||||
try
|
||||
{
|
||||
_refreshSemaphore.Release();
|
||||
}
|
||||
catch(SemaphoreFullException ex)
|
||||
{
|
||||
if (_frameUpdateMissCallback != null)
|
||||
{
|
||||
_frameUpdateMissCallback(ex);
|
||||
}
|
||||
}
|
||||
if (timeSpanCount > _maxSpanCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static implicit operator uint(TimeSpanProvider provider)
|
||||
private Action<SemaphoreFullException> _frameUpdateMissCallback = null;
|
||||
|
||||
public Action<SemaphoreFullException> FrameUpdateMissCallback
|
||||
{
|
||||
get { return _frameUpdateMissCallback; }
|
||||
set { _frameUpdateMissCallback = value;}
|
||||
}
|
||||
|
||||
public void WaitNextSpan()
|
||||
{
|
||||
_refreshSemaphore.Wait();
|
||||
}
|
||||
|
||||
public static implicit operator int(TimeSpanProvider provider)
|
||||
{
|
||||
return provider.timeSpanCount.Value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user