daily update on 20240427 by nitload youmu

This commit is contained in:
YoumuLiu
2024-04-28 02:01:30 +08:00
parent f83a130074
commit 0e01d99e1e
35 changed files with 406 additions and 262 deletions
@@ -23,9 +23,9 @@ namespace StgSharp.Data
leastUnusedDisc = 0;
}
private static int leastUnusedID;
private int leastUnusedID;
public static int NewID()
public int NewID()
{
int ret = leastUnusedID;
if (ret == int.MaxValue)
@@ -36,7 +36,7 @@ namespace StgSharp.Data
return ret;
}
public static void ClearIDBuffer()
public void ClearIDBuffer()
{
leastUnusedID = 1;
}
+1 -1
View File
@@ -19,7 +19,7 @@ namespace StgSharp.Data
public SSDSegment FindSegment(int id, byte SSD)
{
return discList[SSD].FindSegment(id);
}
}
}
+11 -3
View File
@@ -32,7 +32,7 @@ using StgSharp.Data.FileIO;
using System;
using System.Collections.Generic;
using System.Reflection.Metadata.Ecma335;
using System.IO;
using System.Text;
namespace StgSharp.Data
@@ -52,10 +52,18 @@ namespace StgSharp.Data
public SSDSegment FindSegment(int id)
{
SSDSegment s = segments[id];
if (s.)
if (s.ID != id)
{
foreach (var item in segments)
{
if (item.ID == id)
{
s = item;
break;
}
}
}
return s;
}
}
@@ -39,7 +39,7 @@ namespace StgSharp.Data
{
public class SSDFolder : SSDSerializable, IEnumerable<SSDSegmentHead>
{
private SSD local;
private Area local;
private SSDrawHead _head;
internal int _folderID;
internal string _name;
@@ -110,7 +110,8 @@ namespace StgSharp.Data
public SSDraw CreateFile(string name, byte type)
{
SSDraw ret = new SSDraw(name + SerializableTypeCode.GetNameTail(type));
ret.ID = local.
ret.ID = local.NewID();
return ret;
}
//TODO 虚拟文件夹的GetBytes好难写
@@ -122,7 +123,7 @@ namespace StgSharp.Data
fileid.Add(4);
foreach (var item in files)
{
fileid.Add(item.);
fileid.Add(item.Value.ID);
}
return rawBytes.ToArray();
}
+1
View File
@@ -100,6 +100,7 @@ namespace StgSharp.Data.FileIO
{
}
return ret;
}
public void CreateRawFile(string outputFolder, bool rewrite)
@@ -30,6 +30,8 @@
//-----------------------------------------------------------------------
using StgSharp.Math;
using StgSharpDebug.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -42,133 +44,14 @@ namespace StgSharp.Graphics
{
public abstract partial class Form
{
private List<FrameAsyncThread> multiFrameAsyncThreadList = new List<FrameAsyncThread>();
private List<FrameAsyncThread> singleFrameAsyncThreadList = new List<FrameAsyncThread>();
private BluePaint renderLogic;
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show()
{
Init();
frameTimeProvider = new TimeSpanProvider(1 / 60.0, TimeSpanProvider.DefaultProvider);
MethodInfo[] methods = this.GetType().GetMethods(
BindingFlags.Public |
BindingFlags.Instance |
BindingFlags.DeclaredOnly);
GahterSignleFrameAsyncThread(methods);
GatherMultiFrameAsyncThread(methods);
//if no other operation
if (singleFrameAsyncThreadList.Count == 0)
{
while (!ShouldClose)
{
ProcessInput();
Main( );
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
return;
}
List<IGrouping<int, FrameAsyncThread>> threadGroup = singleFrameAsyncThreadList.GroupBy<FrameAsyncThread, int>((t) => t.Priority).ToList();
if (threadGroup.Count == 1)
{
int p = threadGroup.First().Key;
(Barrier, Barrier) bPair = FrameAsyncThread.CombineAsync(true, singleFrameAsyncThreadList);
FrameAsyncThread.AsyncStartAll(singleFrameAsyncThreadList);
switch (Scaler.SignOf(p))
{
case 0:
while (!ShouldClose)
{
bPair.Item1.SignalAndWait();
ProcessInput();
Main( );
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
bPair.Item2.SignalAndWait();
Interlocked.Add(ref _frameCount, 1);
frameTimeProvider.WaitNextSpan();
}
break;
case 1:
while (!ShouldClose)
{
bPair.Item1.SignalAndWait();
bPair.Item2.SignalAndWait();
ProcessInput();
Main( );
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
Interlocked.Add(ref _frameCount, 1);
frameTimeProvider.WaitNextSpan();
}
break;
case -1:
while (!ShouldClose)
{
ProcessInput();
Main( );
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
bPair.Item1.SignalAndWait();
bPair.Item2.SignalAndWait();
Interlocked.Add(ref _frameCount, 1);
frameTimeProvider.WaitNextSpan();
}
break;
default:
return;
}
FrameAsyncThread.TerminateAll(singleFrameAsyncThreadList);
bPair.Item1.SignalAndWait();
return;
}
threadGroup.Sort();
int priority = threadGroup.Count; //rearrange priority label
(Barrier, Barrier)[] barrierList = new (Barrier, Barrier)[priority];
for (int i = 0; i < priority; i++)
{
var group = threadGroup[i].ToList();
foreach (var t in group)
{
t.Priority = priority;
}
barrierList[i] = FrameAsyncThread.CombineAsync(true, group);
//setting thread sync
}
FrameAsyncThread.AsyncStartAll(singleFrameAsyncThreadList);
while (!ShouldClose)
{
barrierList[0].Item1.SignalAndWait();
int i = 0;
while (i < priority - 1)
{
barrierList[i].Item2.SignalAndWait();
barrierList[i + 1].Item1.SignalAndWait();
}
barrierList[priority - 1].Item1.SignalAndWait();
InternalIO.glfwSwapBuffers(windowID);
InternalIO.glfwPollEvents();
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
FrameAsyncThread.TerminateAll(singleFrameAsyncThreadList);
foreach ((Barrier, Barrier) bPair in barrierList)
{
bPair.Item1.SignalAndWait();
bPair.Item2.SignalAndWait();
}
FrameAsyncThread.WaitAll(singleFrameAsyncThreadList);
//InternalDeinit();
}
private void GahterSignleFrameAsyncThread(MethodInfo[] methods)
@@ -190,32 +73,10 @@ namespace StgSharp.Graphics
}
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
FrameAsyncThread thread = new(s, attr._priority);
singleFrameAsyncThreadList.Add(thread);
//singleFrameAsyncThreadList.Add(thread);
}
}
private void GatherMultiFrameAsyncThread(MethodInfo[] methods)
{
if (methods.Length == 0)
{
return;
}
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
MultiFrameActivityAttribute attr = m.GetCustomAttribute<MultiFrameActivityAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
FrameAsyncThread thread = new(s, 0);
multiFrameAsyncThreadList.Add(thread);
}
}
}
}
+4
View File
@@ -53,7 +53,11 @@ namespace StgSharpDebug.Logic
public void Start()
{
foreach (var pipeline in beginNode.OutputInterface)
{
}
}
}
+25 -20
View File
@@ -34,6 +34,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
@@ -44,24 +45,28 @@ namespace StgSharp.Logic
public abstract class BluePaintNode
{
private BluePaintNodeAction mainOperation;
private BluePaint local;
private bool survivalTask;
private Dictionary<string, BluePaintPipeline> inputInterfaces;
private Dictionary<string, BluePaintPipeline> outputInterface;
private bool running;
private string name;
private Task mainTask;
internal Dictionary<string, BluePaintPipeline> InputInterfaces => inputInterfaces;
internal Dictionary<string, BluePaintPipeline> OutputInterface => outputInterface;
internal BluePaintNode(string name, bool isTaskSurvival)
{
this.name = name;
SurvivalTask = isTaskSurvival;
SurvivalTask = isTaskSurvival;
}
protected BluePaintNode(string name, BluePaintNodeAction operation)
{
this.name = name;
@@ -75,35 +80,35 @@ namespace StgSharp.Logic
public void Run()
{
if (survivalTask)
foreach (var item in inputInterfaces)
{
if (mainTask == null)
{
mainTask = new Task(
() =>
{
while (local.IsRunning)
{
mainOperation(in inputInterfaces, in outputInterface);
}
}
);
}
return;
item.Value.WaitForStart();
}
mainOperation(in inputInterfaces, in outputInterface);
}//--------------------------------- end of class -----------------------------
}
public class BluePaintPipeline
{
private Barrier formerCompleteBarrier;
private SemaphoreSlim formerCompleteSemaphore;
private BluePaintPipelineArgs args;
public BluePaintPipeline()
{
formerCompleteSemaphore = new SemaphoreSlim(initialCount: 0,maxCount:1);
}
public void CompleteAndWriteData(BluePaintPipelineArgs args)
{
formerCompleteBarrier.SignalAndWait();
formerCompleteSemaphore.Release();
this.args = args;
}
public void WaitForStart()
{
formerCompleteSemaphore.Release();
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+dd6e8247bf5c1a1ddc9401e652ebeee72ff913e1")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+f83a130074f9a4a253b83ad3df194f5811b18e95")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/dd6e8247bf5c1a1ddc9401e652ebeee72ff913e1/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/f83a130074f9a4a253b83ad3df194f5811b18e95/*"}}