daily update on 20240320 by nitload youmu
This commit is contained in:
@@ -32,6 +32,7 @@ using StgSharp.Math;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
@@ -47,6 +48,12 @@ namespace StgSharp.Graphics
|
||||
private ConcurrentQueue<IntPtr> _funcQueue;
|
||||
private readonly unsafe GLcontext* currentContext;
|
||||
|
||||
public unsafe FrameOperationBuffer(IglFunc gl)
|
||||
{
|
||||
currentContext = gl.Context;
|
||||
_funcQueue = new ConcurrentQueue<IntPtr>();
|
||||
}
|
||||
|
||||
public unsafe bool CallNext()
|
||||
{
|
||||
if (_funcQueue.TryDequeue(out _func))
|
||||
@@ -481,22 +488,60 @@ namespace StgSharp.Graphics
|
||||
|
||||
#endregion gl param queue
|
||||
|
||||
|
||||
}
|
||||
|
||||
//TODO 任务组绑定机制有问题,现在一次只能绑定两个
|
||||
//TODO 目前还不能加载任何任务
|
||||
//TODO 任务的启动逻辑需要重构
|
||||
|
||||
internal class FrameAsyncTask
|
||||
public class FrameAsyncTask
|
||||
{
|
||||
|
||||
private SemaphoreSlim _refrshSemaphore;
|
||||
private SemaphoreSlim _frameCompleteSemaphore;
|
||||
private Task _task;
|
||||
private FrameOperationBuffer opBuffer = new FrameOperationBuffer();
|
||||
protected SemaphoreSlim _frameCompleteSemaphore = new SemaphoreSlim(0, 1);
|
||||
protected SemaphoreSlim _refreshSemaphore;
|
||||
private Task _task;
|
||||
protected Action _taskTODO;
|
||||
protected Func<bool> _terminateSignature;
|
||||
internal FrameOperationBuffer opBuffer;
|
||||
|
||||
internal FrameAsyncTask(GLonUpdate gl)
|
||||
public Action TaskTODO
|
||||
{
|
||||
get => _taskTODO;
|
||||
set => _taskTODO = value;
|
||||
}
|
||||
|
||||
internal FrameAsyncTask(Action action, IglFunc gl)
|
||||
{
|
||||
_taskTODO = action;
|
||||
opBuffer = new FrameOperationBuffer(gl);
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(params FrameAsyncTask[] taskList)
|
||||
{
|
||||
if (taskList.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(taskList.Length);
|
||||
foreach (FrameAsyncTask item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
}
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(List<FrameAsyncTask> taskList)
|
||||
{
|
||||
if (taskList.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(taskList.Count);
|
||||
foreach (FrameAsyncTask item in taskList)
|
||||
{
|
||||
item._refreshSemaphore = refresh;
|
||||
}
|
||||
return refresh;
|
||||
}
|
||||
|
||||
public static void ExchangeBuffer(FrameAsyncTask task0, FrameAsyncTask task1)
|
||||
@@ -506,25 +551,51 @@ namespace StgSharp.Graphics
|
||||
task1.opBuffer = cache;
|
||||
}
|
||||
|
||||
public async Task StartAsync()
|
||||
public virtual SemaphoreSlim StartAsync()
|
||||
{
|
||||
_task = new Task(
|
||||
() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
_refreshSemaphore.Wait();
|
||||
_taskTODO();
|
||||
_frameCompleteSemaphore.Release();
|
||||
}
|
||||
});
|
||||
_task.Start();
|
||||
await _task;
|
||||
return _frameCompleteSemaphore;
|
||||
}
|
||||
|
||||
public static SemaphoreSlim CombineAsync(FrameAsyncTask task0, FrameAsyncTask task1)
|
||||
|
||||
}
|
||||
|
||||
|
||||
internal sealed class AsyncUpdateDataTask : FrameAsyncTask
|
||||
{
|
||||
public AsyncUpdateDataTask(Form f) : base(f.Main, f.GL)
|
||||
{
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(2);
|
||||
task0._refrshSemaphore = refresh;
|
||||
task1._refrshSemaphore = refresh;
|
||||
return refresh;
|
||||
}
|
||||
public static SemaphoreSlim AsyncWait(FrameAsyncTask task0, FrameAsyncTask task1)
|
||||
}
|
||||
|
||||
internal sealed class AsyncRenderFrameTask : FrameAsyncTask
|
||||
{
|
||||
|
||||
public AsyncRenderFrameTask(Form f) : base(null, f.gl)
|
||||
{
|
||||
SemaphoreSlim refresh = new SemaphoreSlim(2);
|
||||
task0._refrshSemaphore = refresh;
|
||||
task1._refrshSemaphore = refresh;
|
||||
return refresh;
|
||||
TaskTODO = new (
|
||||
() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
FrameOperation();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void FrameOperation()
|
||||
{
|
||||
while (opBuffer.CallNext()){}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user