daily update on 20240828 by nitload youmu, autotexture added

This commit is contained in:
Nitload
2024-08-28 10:58:31 +08:00
parent d082071f2d
commit 1ee4e4a42f
586 changed files with 60910 additions and 123106 deletions
@@ -29,7 +29,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp;
using StgSharp.Logic;
using System;
using System.Collections.Generic;
@@ -43,7 +43,7 @@ using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
/// <summary>
/// A sets of complex logic designed for running in multi threads environment.
@@ -79,11 +79,6 @@ namespace StgSharp.Logic
public BlueprintNode BeginLayer => beginNode;
public BlueprintNode EndLayer => endNode;
internal SemaphoreSlim RunningStat
{
get => runningStat;
}
public bool IsRunning
{
get => runningStat.CurrentCount == 0;
@@ -95,6 +90,11 @@ namespace StgSharp.Logic
get => terminate;
set => terminate = value;
}
internal SemaphoreSlim RunningStat
{
get => runningStat;
}
/**/
public void AddNode(BlueprintNode node, bool isNative)
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BlueprintActionNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
@@ -6,17 +36,18 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharpDebug.Logic
namespace StgSharp.BluePrint
{
public class BlueprintActionNode : IConvertableToBlueprintNode
{
private Action<Dictionary<string, BlueprintPipeline>, Dictionary<string, BlueprintPipeline>> mainAction;
private string[] inPorts;
private string[] outPorts;
private Action<Dictionary<string, BlueprintPipeline>, Dictionary<string, BlueprintPipeline>> mainAction;
internal BlueprintActionNode()
{
}
public string[] InputInterfacesName => inPorts;
@@ -27,5 +58,6 @@ namespace StgSharpDebug.Logic
{
mainAction?.Invoke(input, output);
}
}
}
@@ -42,7 +42,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
/// <summary>
@@ -92,11 +92,11 @@ namespace StgSharp.Logic
)
#pragma warning restore CS8618
{
if (inputPorts == null || inputPorts.Length == 0)
if ((inputPorts == null) || (inputPorts.Length == 0))
{
throw new ArgumentNullException(nameof(inputPorts));
}
if (outputPorts == null || outputPorts.Length == 0)
if ((outputPorts == null) || (outputPorts.Length == 0))
{
throw new ArgumentNullException(nameof(outputPorts));
}
@@ -115,11 +115,6 @@ namespace StgSharp.Logic
}
}
internal IConvertableToBlueprintNode Value
{
get => mainOperation;
}
public bool IsNative
{
get => nativeRequested;
@@ -156,6 +151,11 @@ namespace StgSharp.Logic
internal Dictionary<string, BlueprintPipeline> InputInterfaces => _inputInterfaces;
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => _outputInterfaces;
internal IConvertableToBlueprintNode Value
{
get => mainOperation;
}
public void AddAfter(
BlueprintNode former,
@@ -262,10 +262,10 @@ namespace StgSharp.Logic
#endregion
}//--------------------------------- end of class -----------------------------------
public class BlueprintNodeRunException : Exception
{
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BlueprintRunner.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Data;
@@ -8,20 +38,57 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
using StgSharp.Threading;
namespace StgSharp.BluePrint
{
public static class BlueprintRunner
{
private static int _callingThread;
private static ConcurrentStack<Blueprint> blueprintInWaiting = new ConcurrentStack<Blueprint>();
private static NodeRunner[] allAvailableTask = new NodeRunner[1];
private static SemaphoreSlim bpLock = new SemaphoreSlim(0,1);
private static NodeRunner[] allAvailableTask = new NodeRunner[1];
private static CancellationTokenSource cts = new CancellationTokenSource();
private static ConcurrentStack<Blueprint> blueprintInWaiting = new ConcurrentStack<Blueprint>();
private static int _callingThread;
private static SemaphoreSlim bpLock = new SemaphoreSlim(0, 1);
internal static bool IsValidCalling
{
get
{
if ((NodeRunner.CurrentBlueprint == null) || //no bp running at all
((blueprintInWaiting.Count == 0) && (NodeRunner.CurrentBlueprint.IsRunning == false))) // a bp is quiting
{
//in case no bp is running
return true;
}
int? id = Task.CurrentId;
if (id is null)
{
// in case calling from main thread and current running bp
//Console.WriteLine($"\t{_callingThread}");
//Console.WriteLine($"\t{Thread.CurrentThread.ManagedThreadId}");
return _callingThread == Thread.CurrentThread.ManagedThreadId;
}
foreach (NodeRunner item in allAvailableTask)
{
if (item.Id == id)
{
//if calling from any bp running task
return true;
}
}
return false;
}
}
public static void Run(Blueprint blueprint, Func<bool> terminateInstructor)
{
//Console.WriteLine();
if (blueprint == null) return;
if (blueprint == null)
{
return;
}
if (terminateInstructor == null)
{
throw new ArgumentNullException(nameof(terminateInstructor));
@@ -35,87 +102,23 @@ namespace StgSharp.Logic
{
//Console.WriteLine("valid and run");
if (InterruptAndRunNewBp(blueprint))
do { } while(InterruptAndRunNewBp(NodeRunner.CurrentBlueprint));
{
do { } while (InterruptAndRunNewBp(NodeRunner.CurrentBlueprint));
}
}
else
{
bpLock.Wait();
if (InterruptAndRunNewBp(blueprint))
{
do { } while (InterruptAndRunNewBp(NodeRunner.CurrentBlueprint));
}
bpLock.Release();
}
Interlocked.Exchange(ref _callingThread, -1);
}
internal static bool IsValidCalling
{
get
{
if (NodeRunner.CurrentBlueprint == null || //no bp running at all
(blueprintInWaiting.Count == 0 && NodeRunner.CurrentBlueprint.IsRunning == false)) // a bp is quiting
{
//in case no bp is running
return true;
}
int? id = Task.CurrentId;
if (id is null)
{
// in case calling from main thread and current running bp
//Console.WriteLine($"\t{_callingThread}");
//Console.WriteLine($"\t{Thread.CurrentThread.ManagedThreadId}");
return _callingThread == Thread.CurrentThread.ManagedThreadId;
}
foreach (var item in allAvailableTask)
{
if (item.Id == id)
{
//if calling from any bp running task
return true;
}
}
return false;
}
}
internal static bool InterruptAndRunNewBp(Blueprint newBp)
{
Debug.Assert(newBp != null);
if (newBp != NodeRunner.CurrentBlueprint && NodeRunner.CurrentBlueprint != null)
{
//if a running bp exists
blueprintInWaiting.Push(NodeRunner.CurrentBlueprint);
}
//load new bp to current bp
Interlocked.Exchange(ref NodeRunner.CurrentBlueprint!, newBp);
Interlocked.Exchange(ref _callingThread, Thread.CurrentThread.ManagedThreadId);
//run beginning node to init it first.
if (!NodeRunner.CurrentBlueprint.IsRunning)
{
(NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode)!.Run();
}
//refresh all tasks
for (int i = 0; i < allAvailableTask.Length; i++)
{
var item = allAvailableTask[i];
if (item is null || item.IsCompleted)
{
allAvailableTask[i] = NodeRunner.Run();
}
}
BlueprintNode node;
while (!cts.Token.IsCancellationRequested
&& NodeRunner.CurrentBlueprint.RequestNextNativeNode(out node))
{
node.Run();
if (!NodeRunner.CurrentBlueprint.IsRunning)
{
break;
}
}
(NodeRunner.CurrentBlueprint.EndLayer as EndingNode)!.Run();
return blueprintInWaiting.TryPeek(out NodeRunner.CurrentBlueprint);
}
public static void SetMaxTaskCount(int size)
{
@@ -135,41 +138,81 @@ namespace StgSharp.Logic
}
Array.Resize(ref allAvailableTask, size);
}
public static void Terminate()
{
cts.Cancel();
NodeRunner.CurrentBlueprint.Terminate();
foreach (var task in allAvailableTask)
foreach (NodeRunner task in allAvailableTask)
{
task.Cts.Cancel();
}
foreach (var bp in blueprintInWaiting)
foreach (Blueprint bp in blueprintInWaiting)
{
bp.Terminate();
}
blueprintInWaiting.Clear();
}
internal static bool InterruptAndRunNewBp(Blueprint newBp)
{
Debug.Assert(newBp != null);
if ((newBp != NodeRunner.CurrentBlueprint) && (NodeRunner.CurrentBlueprint != null))
{
//if a running bp exists
blueprintInWaiting.Push(NodeRunner.CurrentBlueprint);
}
//load new bp to current bp
Interlocked.Exchange(ref NodeRunner.CurrentBlueprint!, newBp);
Interlocked.Exchange(ref _callingThread, Thread.CurrentThread.ManagedThreadId);
//run beginning node to init it first.
if (!NodeRunner.CurrentBlueprint.IsRunning)
{
(NodeRunner.CurrentBlueprint.BeginLayer as BeginningNode)!.Run();
}
//refresh all tasks
for (int i = 0; i < allAvailableTask.Length; i++)
{
NodeRunner item = allAvailableTask[i];
if ((item is null) || item.IsCompleted)
{
allAvailableTask[i] = NodeRunner.Run();
}
}
BlueprintNode node;
while (!cts.Token.IsCancellationRequested
&& NodeRunner.CurrentBlueprint.RequestNextNativeNode(out node))
{
node.Run();
if (!NodeRunner.CurrentBlueprint.IsRunning)
{
break;
}
}
(NodeRunner.CurrentBlueprint.EndLayer as EndingNode)!.Run();
return blueprintInWaiting.TryPeek(out NodeRunner.CurrentBlueprint);
}
}
internal class NodeRunner: CancellableTask
internal class NodeRunner : CancellableTask
{
private static Blueprint _current;
internal static ref Blueprint CurrentBlueprint
{
get => ref _current;
}
private static Blueprint _current;
internal NodeRunner() : base()
{
_startup = InternalRun;
}
internal static ref Blueprint CurrentBlueprint
{
get => ref _current;
}
internal static NodeRunner Run()
{
var ret = new NodeRunner() { _startup = InternalRun};
NodeRunner ret = new NodeRunner { _startup = InternalRun };
ret.taskInternal = Task.Run(ret.InternalAction);
return ret;
}
@@ -178,7 +221,7 @@ namespace StgSharp.Logic
{
//Console.WriteLine("Task Begin");
BlueprintNode item;
while (CurrentBlueprint != null && CurrentBlueprint.IsRunning && !token.IsCancellationRequested
while ((CurrentBlueprint != null) && CurrentBlueprint.IsRunning && !token.IsCancellationRequested
&& CurrentBlueprint.RequestNexGlobalNode(out item))
{
//Console.WriteLine($"Get node of {item.Name}, going to run.");
@@ -186,5 +229,6 @@ namespace StgSharp.Logic
}
//Console.WriteLine("Task Completed");
}
}//------------------------------------- End of Class ------------------------------------------
}
@@ -1,35 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BpNodeActionAttribute.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
[AttributeUsage(AttributeTargets.Method)]
public sealed class BpNodeActionAttribute : Attribute
{
private string[] _input;
private string[] _output;
private int _operationSpan;
public string[] InputPort => _input;
public string[] OutputPort => _output;
public int OperationSpan => _operationSpan;
public BpNodeActionAttribute(string[] inputPort, string[] outputPort, int operationSpan)
{
_input = inputPort;
_output = outputPort;
this._operationSpan = operationSpan;
}
public BpNodeActionAttribute(string[] inputPort, string[] outputPort)
{
_input = inputPort;
_output = outputPort;
this._operationSpan = 1;
}
public BpNodeActionAttribute(int operationSpan)
{
_input = Array.Empty<string>();
@@ -37,5 +50,23 @@ namespace StgSharp.Logic
_operationSpan = operationSpan;
}
public BpNodeActionAttribute(string[] inputPort, string[] outputPort)
{
_input = inputPort;
_output = outputPort;
this._operationSpan = 1;
}
public BpNodeActionAttribute(string[] inputPort, string[] outputPort, int operationSpan)
{
_input = inputPort;
_output = outputPort;
this._operationSpan = operationSpan;
}
public string[] InputPort => _input;
public string[] OutputPort => _output;
public int OperationSpan => _operationSpan;
}
}
@@ -1,24 +1,55 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BpNodeBuilder.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
public static class BpNodeConverter
{
public static IConvertableToBlueprintNode AsBlueprintNodeMainExecution(this BlueprintNodeOperation startUp)
{
if (startUp == null)
{
throw new ArgumentNullException(nameof(startUp));
}
var attributeArray = startUp.Method.GetCustomAttributes(typeof(BpNodeActionAttribute), false);
var attri = (BpNodeActionAttribute)attributeArray[0];
if (attributeArray.Length < 0 || attri == null)
object[] attributeArray = startUp.Method.GetCustomAttributes(typeof(BpNodeActionAttribute), false);
BpNodeActionAttribute attri = (BpNodeActionAttribute)attributeArray[0];
if ((attributeArray.Length < 0) || (attri == null))
{
throw new InvalidCastException($"Delegate {nameof(startUp)} is not marked by {typeof(BpNodeActionAttribute)}");
}
return new DefaultConvertableToBlueprintNode(startUp,attri.InputPort, attri.OutputPort);
return new DefaultConvertableToBlueprintNode(startUp, attri.InputPort, attri.OutputPort);
}
public static IConvertableToBlueprintNode AsBlueprintNodeMainExecution(this Action startUp)
@@ -27,13 +58,13 @@ namespace StgSharp.Logic
{
throw new ArgumentNullException(nameof(startUp));
}
var attributeArray = startUp.Method.GetCustomAttributes(typeof(BpNodeActionAttribute), false);
var attri = (BpNodeActionAttribute)attributeArray[0];
if (attributeArray.Length < 0 || attri == null)
object[] attributeArray = startUp.Method.GetCustomAttributes(typeof(BpNodeActionAttribute), false);
BpNodeActionAttribute attri = (BpNodeActionAttribute)attributeArray[0];
if ((attributeArray.Length < 0) || (attri == null))
{
throw new InvalidCastException($"Delegate {nameof(startUp)} is not marked by {typeof(BpNodeActionAttribute)}");
}
return new CrossFrameOperation(startUp,attri.OperationSpan);
return new CrossFrameOperation(startUp, attri.OperationSpan);
}
}
@@ -1,21 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
/*
public class CrossCycleProcess:BlueprintNode
{
public CrossCycleProcess(string name, Action operation)
:base()
{
}
}
/**/
}
@@ -0,0 +1,83 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CrossFrameBlueprintNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.BluePrint;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.BluePrint
{
public class CrossFrameOperation : IConvertableToBlueprintNode
{
private int currentCount;
private readonly int cycleCount;
public CrossFrameOperation(Action startup, int cycleCount)
{
MainExecution = startup;
this.cycleCount = (cycleCount > 1) ? cycleCount : throw new ArgumentException(
$"{$"The {typeof(CrossFrameOperation).Name} crosses only one cycle, "}{$"please use a {typeof(BlueprintNode).Name} instead."}");
this.cycleCount = cycleCount;
currentCount = cycleCount;
}
public Action MainExecution { get; private protected set; }
public static string InputInterfacesName => "TaskIn";
public static string OutputInterfacesName => "TaskOut";
public void ExecuteMain(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
{
if (currentCount < cycleCount)
{
Interlocked.Increment(ref currentCount);
}
else
{
Interlocked.Exchange(ref currentCount, 0);
Task.Run(MainExecution);
}
//Console.WriteLine(currentCount);
BlueprintPipeline.SkipAll(output);
}
string[] IConvertableToBlueprintNode.InputInterfacesName => [InputInterfacesName];
string[] IConvertableToBlueprintNode.OutputInterfacesName => [OutputInterfacesName];
}
}
@@ -1,12 +1,46 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IConvertableToBlueprintNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
public delegate void BlueprintNodeOperation(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output);
public interface IConvertableToBlueprintNode
{
#pragma warning disable CA1819
public string[] InputInterfacesName { get; }
#pragma warning restore CA1819
@@ -15,34 +49,36 @@ namespace StgSharp.Logic
public string[] OutputInterfacesName { get; }
#pragma warning restore CA1819
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ExecuteMain(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
}
internal class DefaultConvertableToBlueprintNode : IConvertableToBlueprintNode
{
private string[] _input;
private string[] _output;
private BlueprintNodeOperation _execution;
string[] IConvertableToBlueprintNode.InputInterfacesName => _input;
string[] IConvertableToBlueprintNode.OutputInterfacesName => _output;
void IConvertableToBlueprintNode.ExecuteMain(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
{
_execution(in input, in output);
}
public DefaultConvertableToBlueprintNode(BlueprintNodeOperation execution, string[] input, string[] output)
{
_input = input;
_output = output;
_execution = execution;
}
}
public delegate void BlueprintNodeOperation(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output);
void IConvertableToBlueprintNode.ExecuteMain(in Dictionary<string, BlueprintPipeline> input, in Dictionary<string, BlueprintPipeline> output)
{
_execution(in input, in output);
}
string[] IConvertableToBlueprintNode.InputInterfacesName => _input;
string[] IConvertableToBlueprintNode.OutputInterfacesName => _output;
}
}
+46 -43
View File
@@ -38,11 +38,12 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
public class BlueprintPipeline
{
private BlueprintNode after;
private BlueprintNode former;
private BlueprintPipelineArgs args;
@@ -59,14 +60,55 @@ namespace StgSharp.Logic
public BlueprintNode Former => former;
public int Level => former.Level;
public BlueprintPipelineArgs Args
{
get => args;
set => args = value;
}
public int Level => former.Level;
public static void SkipAll(Dictionary<string, BlueprintPipeline> ports)
{
if (ports == null)
{
throw new ArgumentNullException(nameof(ports));
}
foreach (KeyValuePair<string, BlueprintPipeline> item in ports)
{
if (item.Value != null)
{
item.Value.CompleteAndSkip();
}
}
}
public static void WaitAll(Dictionary<string, BlueprintPipeline> ports)
{
if (ports == null)
{
throw new ArgumentNullException(nameof(ports));
}
foreach (KeyValuePair<string, BlueprintPipeline> item in ports)
{
if (item.Value != null)
{
item.Value.WaitForStart();
}
}
}
public void WaitForStart()
{
//Console.WriteLine($"Waiting \t{former.ContextName}\t->\t{after.ContextName}");
formerCompleteSemaphore.Wait();
}
~BlueprintPipeline()
{
formerCompleteSemaphore.Dispose();
}
#region pipline op
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -85,52 +127,13 @@ namespace StgSharp.Logic
#endregion
public static void SkipAll(Dictionary<string, BlueprintPipeline> ports)
{
if (ports == null)
{
throw new ArgumentNullException(nameof(ports));
}
foreach (var item in ports)
{
if (item.Value!=null)
{
item.Value.CompleteAndSkip();
}
}
}
public static void WaitAll(Dictionary<string, BlueprintPipeline> ports)
{
if (ports == null)
{
throw new ArgumentNullException(nameof(ports));
}
foreach (var item in ports)
{
if (item.Value!=null)
{
item.Value.WaitForStart();
}
}
}
public void WaitForStart()
{
//Console.WriteLine($"Waiting \t{former.ContextName}\t->\t{after.ContextName}");
formerCompleteSemaphore.Wait();
}
~BlueprintPipeline()
{
formerCompleteSemaphore.Dispose();
}
}
public abstract class BlueprintPipelineArgs
{
public object? Value { get; set; }
}
@@ -35,10 +35,11 @@ using System.Reflection.Emit;
using System.Security.Cryptography.X509Certificates;
using System.Text;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
public class RouteSwitch : BlueprintNode
{
private protected Dictionary<string, (BlueprintPipeline pipeline, Func<bool> openingRule)> outputDictionary;
public RouteSwitch(string name, bool isNative, string inputPorts) :
+52 -23
View File
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="SideNode.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
@@ -8,13 +38,14 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
namespace StgSharp.BluePrint
{
internal sealed class BeginningNode : BlueprintNode
{
private Blueprint _bp;
public BeginningNode( Blueprint bp ) : base(name: "BeginningNode",true, ["default"], ["default"]
public BeginningNode(Blueprint bp) : base(name: "BeginningNode", true, ["default"], ["default"]
)
{
_bp = bp;
@@ -28,13 +59,19 @@ namespace StgSharp.Logic
{
return;
}
foreach (var parameter in value)
foreach ((string name, BlueprintPipelineArgs arg) parameter in value)
{
OutputInterfaces[parameter.name].Args = parameter.arg;
}
}
}
public override void Run()
{
_bp.RunningStat.Wait();
BlueprintPipeline.SkipAll(_outputInterfaces);
}
public new void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
{
if (_outputInterfaces.ContainsKey(name))
@@ -44,18 +81,14 @@ namespace StgSharp.Logic
_outputInterfaces.Add(name, pipeline);
}
public override void Run()
{
_bp.RunningStat.Wait();
BlueprintPipeline.SkipAll(_outputInterfaces);
}
}
internal sealed class EndingNode : BlueprintNode
{
private Blueprint _bp;
public EndingNode(Blueprint bp) : base(name: "EndingNode",true, ["default"], ["default"]
public EndingNode(Blueprint bp) : base(name: "EndingNode", true, ["default"], ["default"]
)
{
_bp = bp;
@@ -63,12 +96,15 @@ namespace StgSharp.Logic
internal (string name, BlueprintPipelineArgs arg)[] OutputData
{
get
{
return InputInterfaces.Select(
key => (key.Key, key.Value.Args)).
ToArray();
}
get { return InputInterfaces.Select(key => (key.Key, key.Value.Args)).ToArray(); }
}
public override void Run()
{
BlueprintPipeline.WaitAll(_inputInterfaces);
Interlocked.Exchange(ref _bp.currentGlobalNodeIndex, 0);
Interlocked.Exchange(ref _bp.currentNativeNodeIndex, 0);
_bp.RunningStat.Release();
}
public new void SetCertainInputPort(string name, BlueprintPipeline pipeline)
@@ -80,12 +116,5 @@ namespace StgSharp.Logic
_inputInterfaces.Add(name, pipeline);
}
public override void Run()
{
BlueprintPipeline.WaitAll(_inputInterfaces);
Interlocked.Exchange(ref _bp.currentGlobalNodeIndex, 0);
Interlocked.Exchange(ref _bp.currentNativeNodeIndex, 0);
_bp.RunningStat.Release();
}
}
}