daily update on 20240325 by nitload youmu
This commit is contained in:
@@ -494,24 +494,26 @@ namespace StgSharp.Graphics
|
||||
|
||||
}
|
||||
|
||||
//TODO 目前还不能加载任何任务
|
||||
//TODO 任务的启动逻辑需要重构
|
||||
|
||||
public class FrameAsyncThread
|
||||
{
|
||||
|
||||
private Thread _task;
|
||||
|
||||
protected SemaphoreSlim _frameCompleteSemaphore = new SemaphoreSlim(0, 1);
|
||||
protected SemaphoreSlim _refreshSemaphore;
|
||||
protected Barrier _drawCompleteBarrier;
|
||||
|
||||
private Thread _task;
|
||||
private int _terminateToken;
|
||||
|
||||
protected Barrier _frameSpeedSyncBarrier;
|
||||
protected Action _taskTODO;
|
||||
protected Func<bool> _terminateSignature;
|
||||
internal FrameOperationBuffer opBuffer;
|
||||
|
||||
internal FrameAsyncThread(Action action, IglFunc gl)
|
||||
{
|
||||
_taskTODO = action;
|
||||
opBuffer = new FrameOperationBuffer(gl);
|
||||
_terminateToken = 1;
|
||||
_drawCompleteBarrier = new Barrier(2);
|
||||
}
|
||||
|
||||
public Action TaskTODO
|
||||
@@ -520,48 +522,53 @@ namespace StgSharp.Graphics
|
||||
set => _taskTODO = value;
|
||||
}
|
||||
|
||||
public virtual SemaphoreSlim AsyncStart()
|
||||
|
||||
public Barrier TodoCompleteBarrier
|
||||
{
|
||||
get => _drawCompleteBarrier;
|
||||
}
|
||||
|
||||
public virtual void AsyncStart()
|
||||
{
|
||||
_task = new Thread(
|
||||
() =>
|
||||
{
|
||||
while (true)
|
||||
while (_terminateToken != 0)
|
||||
{
|
||||
_refreshSemaphore.Wait();
|
||||
_taskTODO();
|
||||
_frameCompleteSemaphore.Release();
|
||||
_drawCompleteBarrier.SignalAndWait();
|
||||
_frameSpeedSyncBarrier.SignalAndWait();
|
||||
}
|
||||
});
|
||||
_task.Start();
|
||||
return _frameCompleteSemaphore;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(params FrameAsyncThread[] taskList)
|
||||
{
|
||||
if (taskList.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(0, taskList.Length);
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
}
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(List<FrameAsyncThread> taskList)
|
||||
public static Barrier CombineAsync(bool needOuterMonitor, List<FrameAsyncThread> taskList)
|
||||
{
|
||||
if (taskList.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(taskList.Count);
|
||||
Barrier b = new Barrier(taskList.Count + (needOuterMonitor ? 1 : 0));
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
item._frameSpeedSyncBarrier = b;
|
||||
}
|
||||
return refresh;
|
||||
return b;
|
||||
}
|
||||
|
||||
public static Barrier CombineBeginningAsync(bool needOuterMonitor, params FrameAsyncThread[] taskList)
|
||||
{
|
||||
if (taskList.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Barrier b = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
|
||||
foreach (FrameAsyncThread item in taskList)
|
||||
{
|
||||
item._frameSpeedSyncBarrier = b;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
public static void ExchangeBuffer(FrameAsyncThread task0, FrameAsyncThread task1)
|
||||
@@ -571,6 +578,10 @@ namespace StgSharp.Graphics
|
||||
task1.opBuffer = cache;
|
||||
}
|
||||
|
||||
public void Terminate()
|
||||
{
|
||||
Interlocked.Exchange(ref _terminateToken, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -587,14 +598,17 @@ namespace StgSharp.Graphics
|
||||
internal sealed class AsyncRenderFrameTask : FrameAsyncThread
|
||||
{
|
||||
|
||||
|
||||
public AsyncRenderFrameTask(Form f) : base(null, f.gl)
|
||||
{
|
||||
TaskTODO = FrameOperation;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void FrameOperation()
|
||||
{
|
||||
while (opBuffer.CallNext()) {}
|
||||
while (opBuffer.CallNext()) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user