daily update on 20240620 by nitload youmu
This commit is contained in:
@@ -35,6 +35,7 @@ using StgSharp.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
@@ -42,11 +43,6 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public delegate void BlueprintNodeAction(
|
||||
in Dictionary<string, BlueprintPipeline> inpput,
|
||||
in Dictionary<string, BlueprintPipeline> output);
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@@ -59,86 +55,69 @@ namespace StgSharp.Logic
|
||||
public class BlueprintNode : IComparable<BlueprintNode>
|
||||
#pragma warning restore CA1036
|
||||
{
|
||||
private BlueprintNodeAction mainOperation;
|
||||
|
||||
private protected bool levelAvailable, nativeRequested;
|
||||
private protected int _level;
|
||||
private string name;
|
||||
|
||||
private protected Dictionary<string, BlueprintPipeline> _inputInterfaces;
|
||||
private protected Dictionary<string, BlueprintPipeline> _outputInterfaces;
|
||||
|
||||
private protected int _level;
|
||||
private IConvertableToBlueprintNode mainOperation;
|
||||
private string name;
|
||||
|
||||
|
||||
internal BlueprintNode(string name,
|
||||
BlueprintNodeAction operation, bool isNative,
|
||||
string[] inputPorts,
|
||||
string[] outputPorts)
|
||||
IConvertableToBlueprintNode node, bool isNative)
|
||||
{
|
||||
this.levelAvailable = false;
|
||||
this.name = name;
|
||||
nativeRequested = isNative;
|
||||
mainOperation = operation;
|
||||
mainOperation = node;
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
if (inputPorts.Length == 0 )
|
||||
foreach (string portName in node.InputInterfacesName)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inputPorts));
|
||||
_inputInterfaces.Add(portName, null!);
|
||||
}
|
||||
if (outputPorts.Length == 0)
|
||||
|
||||
foreach (string portName in node.OutputInterfacesName)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(outputPorts));
|
||||
}
|
||||
foreach (var portName in inputPorts)
|
||||
{
|
||||
_inputInterfaces.Add(portName, null);
|
||||
}
|
||||
foreach (var portName in outputPorts)
|
||||
{
|
||||
_outputInterfaces.Add(portName, null);
|
||||
_outputInterfaces.Add(portName, null!);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BlueprintNode(string name, IConvertableToBlueprintNode convertable)
|
||||
{
|
||||
this.levelAvailable = false;
|
||||
this.name = name;
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
mainOperation = convertable.MainExecution;
|
||||
foreach (var soket in convertable.InputInterfacesName)
|
||||
{
|
||||
_inputInterfaces.Add(soket, null);
|
||||
}
|
||||
foreach (var soket in convertable.OutputInterfacesName)
|
||||
{
|
||||
_outputInterfaces.Add(soket, null);
|
||||
}
|
||||
}
|
||||
|
||||
public BlueprintNode(string name,
|
||||
public BlueprintNode(string name, bool isNative,
|
||||
string[] inputPorts,
|
||||
string[] outputPorts
|
||||
)
|
||||
{
|
||||
this.levelAvailable = false;
|
||||
if (inputPorts == null || inputPorts.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(inputPorts));
|
||||
}
|
||||
if (outputPorts == null || outputPorts.Length == 0)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(outputPorts));
|
||||
}
|
||||
levelAvailable = false;
|
||||
this.name = name;
|
||||
IsNative = isNative;
|
||||
_inputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
_outputInterfaces = new Dictionary<string, BlueprintPipeline>();
|
||||
if (inputPorts.Length * outputPorts.Length == 0)
|
||||
foreach (string portName in inputPorts)
|
||||
{
|
||||
throw new Exception();
|
||||
_inputInterfaces.Add(portName, null!);
|
||||
}
|
||||
foreach (var portName in inputPorts)
|
||||
foreach (string portName in outputPorts)
|
||||
{
|
||||
_inputInterfaces.Add(portName, null);
|
||||
}
|
||||
foreach (var portName in outputPorts)
|
||||
{
|
||||
_outputInterfaces.Add(portName, null);
|
||||
_outputInterfaces.Add(portName, null!);
|
||||
}
|
||||
}
|
||||
|
||||
internal IConvertableToBlueprintNode Value
|
||||
{
|
||||
get => mainOperation;
|
||||
}
|
||||
|
||||
public bool IsNative
|
||||
{
|
||||
get => nativeRequested;
|
||||
@@ -154,7 +133,7 @@ namespace StgSharp.Logic
|
||||
return _level;
|
||||
}
|
||||
_level = 0;
|
||||
foreach (var item in _inputInterfaces)
|
||||
foreach (KeyValuePair<string, BlueprintPipeline> item in _inputInterfaces)
|
||||
{
|
||||
if (item.Value == null)
|
||||
{
|
||||
@@ -213,21 +192,6 @@ namespace StgSharp.Logic
|
||||
SetCertainOutputPort(thisOutputPortName, pipeline);
|
||||
}
|
||||
|
||||
|
||||
public void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Console.WriteLine(name);
|
||||
BlueprintPipeline.WaitAll(_inputInterfaces);
|
||||
mainOperation(in _inputInterfaces, in _outputInterfaces);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public int CompareTo(BlueprintNode other)
|
||||
{
|
||||
#pragma warning disable CA1062
|
||||
@@ -235,12 +199,30 @@ namespace StgSharp.Logic
|
||||
#pragma warning restore CA1062
|
||||
}
|
||||
|
||||
|
||||
public virtual void Run()
|
||||
{
|
||||
try
|
||||
{
|
||||
//Console.WriteLine(name);
|
||||
BlueprintPipeline.WaitAll(_inputInterfaces);
|
||||
if (mainOperation != null)
|
||||
{
|
||||
mainOperation.ExecuteMain(in _inputInterfaces, in _outputInterfaces);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#region port operation
|
||||
|
||||
public BlueprintPipeline GetCertainInputPort(string name)
|
||||
{
|
||||
BlueprintPipeline ret;
|
||||
if (!_inputInterfaces.TryGetValue(name,out ret))
|
||||
if (!_inputInterfaces.TryGetValue(name, out ret))
|
||||
{
|
||||
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
|
||||
}
|
||||
@@ -283,15 +265,29 @@ namespace StgSharp.Logic
|
||||
|
||||
public interface IConvertableToBlueprintNode
|
||||
{
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public string[] InputInterfacesName { get; }
|
||||
public BlueprintNodeAction MainExecution { get; }
|
||||
public string[] OutputInterfacesName { get; }
|
||||
#pragma warning restore CA1819
|
||||
|
||||
|
||||
#pragma warning disable CA1819
|
||||
public string[] OutputInterfacesName { get; }
|
||||
#pragma warning restore CA1819
|
||||
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void ExecuteMain(
|
||||
in Dictionary<string, BlueprintPipeline> input,
|
||||
in Dictionary<string, BlueprintPipeline> output);
|
||||
}
|
||||
|
||||
|
||||
public class BlueprintNodeRunException : Exception
|
||||
{
|
||||
|
||||
protected BlueprintNodeRunException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
public BlueprintNodeRunException()
|
||||
{
|
||||
}
|
||||
@@ -308,9 +304,6 @@ namespace StgSharp.Logic
|
||||
{
|
||||
}
|
||||
|
||||
protected BlueprintNodeRunException(SerializationInfo info, StreamingContext context) : base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user