daily update on 20240828 by nitload youmu, autotexture added
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
/**/
|
||||
}
|
||||
+47
-5
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="Exception.cs"
|
||||
// file="CrossFrameBlueprintNode.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. All rights reserved.
|
||||
@@ -28,14 +28,56 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.BluePrint;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) :
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,34 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="CancellableTask.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.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
@@ -6,25 +36,16 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
namespace StgSharp.Threading
|
||||
{
|
||||
internal class CancellableTask
|
||||
{
|
||||
private CancellationTokenSource cts;
|
||||
private protected Task taskInternal;
|
||||
|
||||
private protected Action<CancellationToken> _startup;
|
||||
private protected Task taskInternal;
|
||||
private CancellationTokenSource cts;
|
||||
|
||||
public CancellationTokenSource Cts
|
||||
{
|
||||
get => cts;
|
||||
}
|
||||
|
||||
public int Id
|
||||
{
|
||||
get =>taskInternal.Id;
|
||||
}
|
||||
|
||||
private protected CancellableTask()
|
||||
private protected CancellableTask()
|
||||
{
|
||||
cts = new CancellationTokenSource();
|
||||
}
|
||||
@@ -35,16 +56,19 @@ namespace StgSharp.Logic
|
||||
cts = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public static CancellableTask Run(Action<CancellationToken> startup)
|
||||
public bool IsCompleted
|
||||
{
|
||||
var ret = new CancellableTask() { _startup = startup };
|
||||
ret.taskInternal = Task.Run(ret.InternalAction);
|
||||
return ret;
|
||||
get => taskInternal.IsCompleted;
|
||||
}
|
||||
|
||||
public bool IsCompleted
|
||||
{
|
||||
get => taskInternal.IsCompleted;
|
||||
public CancellationTokenSource Cts
|
||||
{
|
||||
get => cts;
|
||||
}
|
||||
|
||||
public int Id
|
||||
{
|
||||
get => taskInternal.Id;
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
@@ -52,9 +76,18 @@ namespace StgSharp.Logic
|
||||
Cts.Cancel();
|
||||
}
|
||||
|
||||
~CancellableTask()
|
||||
public static CancellableTask Run(Action<CancellationToken> startup)
|
||||
{
|
||||
Cts.Dispose();
|
||||
CancellableTask ret = new CancellableTask { _startup = startup };
|
||||
ret.taskInternal = Task.Run(ret.InternalAction);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static void WaitAll(IEnumerable<CancellableTask> tasks)
|
||||
{
|
||||
IEnumerable<Task> convertedTasks = tasks.Select<CancellableTask, Task>
|
||||
(ct => ct.taskInternal);
|
||||
Task.WaitAll(convertedTasks.ToArray());
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -64,17 +97,15 @@ namespace StgSharp.Logic
|
||||
_startup(Cts.Token);
|
||||
}
|
||||
|
||||
public static void WaitAll(IEnumerable<CancellableTask> tasks)
|
||||
{
|
||||
IEnumerable<Task> convertedTasks = tasks.Select<CancellableTask,Task>
|
||||
(ct=>ct.taskInternal);
|
||||
Task.WaitAll(convertedTasks.ToArray());
|
||||
}
|
||||
|
||||
public static implicit operator Task(CancellableTask task)
|
||||
public static implicit operator Task(CancellableTask task)
|
||||
{
|
||||
return task.taskInternal;
|
||||
}
|
||||
|
||||
~CancellableTask()
|
||||
{
|
||||
Cts.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="BidirectionalDictionary.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;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public sealed class BidirectionalDictionary<TFirst, TSecond> : IBidirectionalDictionary<TFirst, TSecond>
|
||||
{
|
||||
|
||||
private readonly Dictionary<TFirst, TSecond> _forward;
|
||||
private readonly Dictionary<TSecond, TFirst> _reverse;
|
||||
|
||||
public BidirectionalDictionary()
|
||||
{
|
||||
_forward = new Dictionary<TFirst, TSecond>();
|
||||
_reverse = new Dictionary<TSecond, TFirst>();
|
||||
}
|
||||
|
||||
public TFirst this[TSecond key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_reverse.TryGetValue(key,out TFirst value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
throw new ArgumentException($"Cannot find key {key!.ToString()} in dictionary.");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_reverse.TryGetValue(key,out TFirst origin))
|
||||
{
|
||||
_reverse[key] = value;
|
||||
_forward.Remove(origin);
|
||||
}
|
||||
else
|
||||
{
|
||||
_reverse.Add(key, value);
|
||||
}
|
||||
_forward.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public TSecond this[TFirst key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_forward.TryGetValue(key, out TSecond value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
throw new ArgumentException($"Cannot find key {key!.ToString()} in dictionary.");
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_forward.TryGetValue(key, out TSecond origin))
|
||||
{
|
||||
_forward[key] = value;
|
||||
_reverse.Remove(origin);
|
||||
}
|
||||
else
|
||||
{
|
||||
_forward.Add(key, value);
|
||||
}
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public ICollection<TFirst> FirstIndex => _forward.Keys;
|
||||
|
||||
public ICollection<TSecond> SecondIndex => _reverse.Keys;
|
||||
|
||||
public int Count => _forward.Count;
|
||||
|
||||
public IReadOnlyDictionary<TFirst, TSecond> Forward => new ReadOnlyDictionary<TFirst,TSecond>(_forward);
|
||||
|
||||
public IReadOnlyDictionary<TSecond, TFirst> Reverse => new ReadOnlyDictionary<TSecond,TFirst>(_reverse);
|
||||
|
||||
public void Add( KeyValuePair<TFirst, TSecond> item )
|
||||
{
|
||||
if (_forward.ContainsKey(item.Key) || _reverse.ContainsKey(item.Value))
|
||||
{
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(item.Key,item.Value);
|
||||
_reverse.Add(item.Value, item.Key);
|
||||
}
|
||||
|
||||
public void Add( TFirst key, TSecond value )
|
||||
{
|
||||
if (_forward.ContainsKey(key) || _reverse.ContainsKey(value))
|
||||
{
|
||||
throw new ArgumentException("Duplicate key or value.");
|
||||
}
|
||||
_forward.Add(key, value);
|
||||
_reverse.Add(value, key);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_forward.Clear();
|
||||
_reverse.Clear();
|
||||
}
|
||||
|
||||
public bool Contains( KeyValuePair<TFirst, TSecond> item )
|
||||
{
|
||||
return _forward.Contains(item) && _reverse.TryGetValue(item.Value, out TFirst var) && var!.Equals(item.Key) ;
|
||||
}
|
||||
|
||||
public bool Contains(TSecond key)
|
||||
{
|
||||
return _reverse.ContainsKey(key);
|
||||
}
|
||||
|
||||
public bool Contains(TFirst key)
|
||||
{
|
||||
return _forward.ContainsKey(key);
|
||||
}
|
||||
|
||||
public void CopyTo( KeyValuePair<TFirst, TSecond>[] array, int arrayIndex )
|
||||
{
|
||||
if (array == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(array));
|
||||
}
|
||||
if (arrayIndex < 0 || arrayIndex > array.Length)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(arrayIndex));
|
||||
}
|
||||
if (array.Length - arrayIndex < _forward.Count)
|
||||
{
|
||||
throw new ArgumentException("The array is too small to copy the elements.");
|
||||
}
|
||||
|
||||
foreach (var pair in _forward)
|
||||
{
|
||||
array[arrayIndex ++] = pair;
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<TFirst, TSecond>> GetEnumerator()
|
||||
{
|
||||
foreach (var pair in _forward)
|
||||
{
|
||||
yield return pair;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Remove( TFirst key ) { throw new NotImplementedException(); }
|
||||
|
||||
public bool Remove( KeyValuePair<TFirst, TSecond> item )
|
||||
{
|
||||
if (_forward.Remove(item.Key))
|
||||
{
|
||||
return _reverse.Remove(item.Value);
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool TryGetValue( TFirst key, out TSecond value )
|
||||
{
|
||||
return _forward.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TSecond key, out TFirst value)
|
||||
{
|
||||
return _reverse.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
public interface IBidirectionalDictionary<TFirst, TSecond> :
|
||||
IDictionary<TFirst, TSecond>
|
||||
{
|
||||
#pragma warning disable CA1033
|
||||
ICollection<TFirst> IDictionary<TFirst, TSecond>.Keys => FirstIndex;
|
||||
ICollection<TSecond> IDictionary<TFirst, TSecond>.Values => SecondIndex;
|
||||
bool IDictionary<TFirst, TSecond>.ContainsKey(TFirst key) => Contains(key);
|
||||
#pragma warning restore CA1033
|
||||
|
||||
public IReadOnlyDictionary<TFirst, TSecond> Forward { get; }
|
||||
public IReadOnlyDictionary<TSecond, TFirst> Reverse { get; }
|
||||
|
||||
public ICollection<TFirst> FirstIndex { get;}
|
||||
|
||||
public ICollection<TSecond> SecondIndex { get; }
|
||||
|
||||
public TFirst this[TSecond key] { get;set; }
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param name="key"> The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />. </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains an element with the
|
||||
/// specified key; otherwise, false.
|
||||
/// </returns>
|
||||
public bool Contains(TSecond key);
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the <see cref="IBidirectionalDictionary{TFirst, TSecond}" /> contains the
|
||||
/// specified key.
|
||||
/// </summary>
|
||||
/// <param name="key"> The value to locate in the <see cref="IBidirectionalDictionary{TFirst, TSecond}" />. </param>
|
||||
/// <returns>
|
||||
/// true if the <see cref="IBidirectionalDictionary{TFirst, TSecond}"/> contains an element with the
|
||||
/// specified key; otherwise, false.
|
||||
/// </returns>
|
||||
public bool Contains(TFirst key);
|
||||
|
||||
public bool TryGetValue(TSecond key, out TFirst value);
|
||||
}
|
||||
}
|
||||
+63
-31
@@ -1,29 +1,60 @@
|
||||
using System;
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="SizeFixedList.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;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
namespace StgSharp.Collections
|
||||
{
|
||||
internal class SizeFixedList<T> : IList<T>
|
||||
{
|
||||
private int capacity, _index;
|
||||
|
||||
private T[] values;
|
||||
private int capacity, _index;
|
||||
|
||||
public SizeFixedList(int size)
|
||||
{
|
||||
values = new T[size];
|
||||
}
|
||||
|
||||
public T this[int index]
|
||||
public T this[int index]
|
||||
{
|
||||
get => index<_index ? values[index] : throw new ArgumentOutOfRangeException(nameof(index));
|
||||
set
|
||||
get => (index < _index) ? values[index] : throw new ArgumentOutOfRangeException(nameof(index));
|
||||
set
|
||||
{
|
||||
if (true)
|
||||
if (index < _index)
|
||||
{
|
||||
values[index] = value ;
|
||||
values[index] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -32,10 +63,10 @@ namespace StgSharp.Logic
|
||||
}
|
||||
}
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public int Count => _index + 1;
|
||||
|
||||
public void Add(T item)
|
||||
{
|
||||
if (_index < capacity - 1)
|
||||
@@ -88,11 +119,11 @@ namespace StgSharp.Logic
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void Insert(int index, T item)
|
||||
void IList<T>.Insert(int index, T item)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
|
||||
public bool Remove(T item)
|
||||
{
|
||||
|
||||
@@ -108,25 +139,6 @@ namespace StgSharp.Logic
|
||||
return false;
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index <= _index)
|
||||
{
|
||||
values[index] = values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
yield return GetEnumerator();
|
||||
}
|
||||
|
||||
public void Resize(int newSize)
|
||||
{
|
||||
Array.Resize(ref values, newSize);
|
||||
}
|
||||
|
||||
public void RemoveAll(Predicate<T> predicate)
|
||||
{
|
||||
for (int i = _index; i > 0; i--)
|
||||
@@ -138,5 +150,25 @@ namespace StgSharp.Logic
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index <= _index)
|
||||
{
|
||||
values[index] = values[_index];
|
||||
_index--;
|
||||
}
|
||||
}
|
||||
|
||||
public void Resize(int newSize)
|
||||
{
|
||||
Array.Resize(ref values, newSize);
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
yield return GetEnumerator();
|
||||
}
|
||||
|
||||
}//------------------------------------- End of Class ------------------------------------------
|
||||
}
|
||||
@@ -35,17 +35,21 @@ namespace StgSharp
|
||||
{
|
||||
|
||||
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
|
||||
#if NET8_OR_GREATER
|
||||
,INumber
|
||||
#endif
|
||||
|
||||
{
|
||||
|
||||
internal dynamic _value;
|
||||
|
||||
internal readonly T _defualtAddValue;
|
||||
internal readonly T _defualtSubValue;
|
||||
internal readonly T _defualtValue;
|
||||
|
||||
internal dynamic _value;
|
||||
|
||||
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
|
||||
{
|
||||
var type = Type.GetTypeCode(defualtValue.GetType());
|
||||
TypeCode type = Type.GetTypeCode(defualtValue.GetType());
|
||||
switch (type)
|
||||
{
|
||||
case TypeCode.Byte:
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public class CrossFrameOperation : IConvertableToBlueprintNode
|
||||
{
|
||||
public Action MainExecution { get; private protected set; }
|
||||
|
||||
private readonly int cycleCount;
|
||||
private int currentCount;
|
||||
|
||||
public static string InputInterfacesName => "TaskIn";
|
||||
|
||||
public static string OutputInterfacesName => "TaskOut";
|
||||
|
||||
string[] IConvertableToBlueprintNode.InputInterfacesName => [InputInterfacesName];
|
||||
|
||||
string[] IConvertableToBlueprintNode.OutputInterfacesName => [OutputInterfacesName];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -39,24 +39,24 @@ namespace StgSharp
|
||||
{
|
||||
|
||||
internal PlainGeometry _boarder;
|
||||
internal SensorRuleHandler _rule;
|
||||
internal PlainGeometry _target;
|
||||
internal SensorRuleHandler _rule;
|
||||
|
||||
|
||||
public PlainGeometry boarder => _boarder;
|
||||
|
||||
public SensorRuleHandler Rule
|
||||
{
|
||||
get => _rule;
|
||||
set => _rule = value;
|
||||
}
|
||||
|
||||
public PlainGeometry target
|
||||
{
|
||||
get => _target;
|
||||
set => _target = value;
|
||||
}
|
||||
|
||||
public SensorRuleHandler Rule
|
||||
{
|
||||
get => _rule;
|
||||
set => _rule = value;
|
||||
}
|
||||
|
||||
public static Sensor<T> operator -(Sensor<T> sensor, SensorRuleHandler rule)
|
||||
{
|
||||
sensor._rule -= rule;
|
||||
|
||||
@@ -32,10 +32,11 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp
|
||||
namespace StgSharp.Timing
|
||||
{
|
||||
public class TimeFunction
|
||||
{
|
||||
|
||||
private float _beginning, _ending;
|
||||
private Func<float, float> _timeRelatedCalculation;
|
||||
private TimeSpanProvider _timeProvider;
|
||||
@@ -62,17 +63,17 @@ namespace StgSharp
|
||||
get => _timeProvider.CurrentSecond > _ending;
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public Func<float, float> TimeRelatedCalculation
|
||||
{
|
||||
get { return _timeRelatedCalculation; }
|
||||
set { _timeRelatedCalculation = value; }
|
||||
}
|
||||
|
||||
public static TimeFunction One
|
||||
{
|
||||
get => new TimeFunctionOne();
|
||||
}
|
||||
|
||||
public TimeSpanProvider TimeSpanProvider
|
||||
{
|
||||
get { return _timeProvider; }
|
||||
@@ -105,12 +106,6 @@ namespace StgSharp
|
||||
return new TimeFunction(_timeProvider, func, range);
|
||||
}
|
||||
|
||||
public virtual TimeFunction Reverse()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
return new TimeFunction(_timeProvider, p => _timeRelatedCalculation(range - p) ,range);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
@@ -118,6 +113,12 @@ namespace StgSharp
|
||||
_ending = _beginning + range;
|
||||
}
|
||||
|
||||
public virtual TimeFunction Reverse()
|
||||
{
|
||||
float range = _ending - _beginning;
|
||||
return new TimeFunction(_timeProvider, p => _timeRelatedCalculation(range - p), range);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -152,7 +153,7 @@ namespace StgSharp
|
||||
public new void Reset()
|
||||
#pragma warning restore CA1822
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2
-4
@@ -34,17 +34,15 @@ using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
namespace StgSharp.Timing
|
||||
{
|
||||
|
||||
|
||||
public abstract class TimeSourceProviderBase
|
||||
{
|
||||
|
||||
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
|
||||
|
||||
protected SemaphoreSlim CheckSubscriberSemaphore
|
||||
{
|
||||
{
|
||||
get => _addSubscriberSemaphore;
|
||||
}
|
||||
|
||||
+33
-32
@@ -28,13 +28,13 @@
|
||||
//
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.Logic;
|
||||
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp
|
||||
namespace StgSharp.Timing
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@@ -53,7 +53,7 @@ namespace StgSharp
|
||||
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
|
||||
private readonly TimeSourceProviderBase _timeSource;
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
|
||||
@@ -115,31 +115,6 @@ namespace StgSharp
|
||||
_subscribed = true;
|
||||
}
|
||||
|
||||
public int CurrentSpan
|
||||
{
|
||||
get => timeSpanCount.Value;
|
||||
}
|
||||
|
||||
public float CurrentSecond
|
||||
{
|
||||
get => timeSpanCount.Value * SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
|
||||
/// </summary>
|
||||
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
|
||||
|
||||
public double SpanLength
|
||||
{
|
||||
get => (_spanLength * 1.0) / (1000L * 1000L);
|
||||
}
|
||||
|
||||
public float SpanLengthLowPrecession
|
||||
{
|
||||
get => (_spanLength * 1.0f) / (1000 * 1000);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
|
||||
/// </summary>
|
||||
@@ -149,6 +124,31 @@ namespace StgSharp
|
||||
set => _refreshCallback = value;
|
||||
}
|
||||
|
||||
public double SpanLength
|
||||
{
|
||||
get => (_spanLength * 1.0) / (1000L * 1000L);
|
||||
}
|
||||
|
||||
public float CurrentSecond
|
||||
{
|
||||
get => timeSpanCount.Value * SpanLengthLowPrecession;
|
||||
}
|
||||
|
||||
public float SpanLengthLowPrecession
|
||||
{
|
||||
get => (_spanLength * 1.0f) / (1000 * 1000);
|
||||
}
|
||||
|
||||
public int CurrentSpan
|
||||
{
|
||||
get => timeSpanCount.Value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
|
||||
/// </summary>
|
||||
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
|
||||
|
||||
public void SubscribeToTimeSource(TimeSourceProviderBase serviceHandler)
|
||||
{
|
||||
if (serviceHandler == null)
|
||||
@@ -163,6 +163,11 @@ namespace StgSharp
|
||||
serviceHandler.AddSubscriber(this);
|
||||
}
|
||||
|
||||
public int ToInt32()
|
||||
{
|
||||
return timeSpanCount.Value;
|
||||
}
|
||||
|
||||
public void WaitNextSpan()
|
||||
{
|
||||
_refreshSemaphore.Wait();
|
||||
@@ -209,9 +214,5 @@ namespace StgSharp
|
||||
return provider.ToInt32();
|
||||
}
|
||||
|
||||
public int ToInt32()
|
||||
{
|
||||
return (int)timeSpanCount.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharpDebug.Logic
|
||||
{
|
||||
#nullable enable
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate ref object BindingDataGetter();
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void BindingDataSetter(ref object value);
|
||||
|
||||
public unsafe struct DataBindingEntry
|
||||
{
|
||||
private IntPtr getterPtr, setterPtr;
|
||||
|
||||
public DataBindingEntry(
|
||||
[NotNull] BindingDataGetter gettingCallback,
|
||||
[NotNull] BindingDataSetter settingCallback)
|
||||
{
|
||||
getterPtr = Marshal.GetFunctionPointerForDelegate(gettingCallback);
|
||||
setterPtr = Marshal.GetFunctionPointerForDelegate(settingCallback);
|
||||
}
|
||||
|
||||
public ref object GetValue()
|
||||
{
|
||||
return ref ((delegate* unmanaged[Cdecl]<ref object>)getterPtr)();
|
||||
}
|
||||
|
||||
public void SetData(ref object value)
|
||||
{
|
||||
((delegate* unmanaged[Cdecl]<ref object, void>)setterPtr)(ref value);
|
||||
}
|
||||
|
||||
public static DataBindingEntry NullBinding
|
||||
{
|
||||
get => new DataBindingEntry();
|
||||
}
|
||||
|
||||
public bool ExactEqual(DataBindingEntry other)
|
||||
{
|
||||
return getterPtr == other.getterPtr && setterPtr == other.setterPtr;
|
||||
}
|
||||
}
|
||||
|
||||
#nullable restore
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
private View _nextView, _currentView;
|
||||
|
||||
protected View CurrentView
|
||||
{
|
||||
get => _currentView;
|
||||
set => _nextView = value;
|
||||
}
|
||||
|
||||
protected void UseViewInNextFrame(string name)
|
||||
{
|
||||
if (allView.TryGetValue(name, out View v))
|
||||
{
|
||||
throw new KeyNotFoundException($"Cannot find View named {name} " +
|
||||
$"in current View Model of {this.GetType().FullName}");
|
||||
}
|
||||
CurrentView = v;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// CustomizeInit this form and render it on screen, and respond with operation
|
||||
/// </summary>
|
||||
public unsafe void Show()
|
||||
{
|
||||
CustomizeInitialize();
|
||||
//BuildGlobalKeyControl();
|
||||
while(0 == InternalIO.glfwWindowShouldClose(this.viewPortDisplay.ViewPortID))
|
||||
{
|
||||
viewPortDisplay.FlushSize();
|
||||
CurrentView.Use();
|
||||
RenderStream.PollEvents();
|
||||
frameTimeProvider.WaitNextSpan();
|
||||
Interlocked.Add(ref _frameCount, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void PrivateShow()
|
||||
{
|
||||
if(0 == InternalIO.glfwWindowShouldClose(this.viewPortDisplay.ViewPortID))
|
||||
{
|
||||
CurrentView.Use();
|
||||
RenderStream.PollEvents();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public partial class ViewModelBase
|
||||
{
|
||||
private Dictionary<string,View> allView;
|
||||
|
||||
public T BuildNewView<T>(string name,(int x, int y, int z) unitCubeSize)
|
||||
where T : View,new()
|
||||
{
|
||||
var ret = new T();
|
||||
ret.SelfName = name;
|
||||
ret.InternalInitialize(this);
|
||||
allView.Add(name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public T BuildRenderStream<T>(View view) where T : RenderStream
|
||||
{
|
||||
#nullable enable
|
||||
T? ret = Activator.CreateInstance(typeof(T), view.Port, view.UnitCubeSize) as T;
|
||||
#nullable restore
|
||||
if (ret == null)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Failed in creating a new {typeof(T).Name} instance when calling ShareContextWith."
|
||||
);
|
||||
}
|
||||
ret.timeProvider = this.frameTimeProvider;
|
||||
ret.PlatformSpecifiedInit();
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,329 +0,0 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ViewModel.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.Controlling.UsrActivity;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
using StgSharp.Math;
|
||||
|
||||
using StgSharpDebug.Logic;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Numerics;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Logic
|
||||
{
|
||||
public abstract partial class ViewModelBase
|
||||
{
|
||||
|
||||
private int _frameCount;
|
||||
private int _frameSpeed;
|
||||
private ViewPort viewPortDisplay;
|
||||
|
||||
internal IntPtr monitor;
|
||||
|
||||
internal TimeSpanProvider fpsCountProvider;
|
||||
internal TimeSpanProvider frameTimeProvider;
|
||||
internal Vector4 backgroundColor;
|
||||
|
||||
protected ViewModelBase(int frameSpeed)
|
||||
{
|
||||
viewPortDisplay = new ViewPort(
|
||||
name: "Hello, Stg#!",
|
||||
size: (800, 600),
|
||||
monitor: IntPtr.Zero
|
||||
);
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
protected ViewModelBase(float frameLength)
|
||||
{
|
||||
viewPortDisplay = new ViewPort(
|
||||
name: "Hello, Stg#!",
|
||||
size: (800, 600),
|
||||
monitor: IntPtr.Zero
|
||||
);
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long _frameLength = (FrameSpeed > 0) ? ((long)(1000 * frameLength)) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
_frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
}
|
||||
|
||||
public ViewModelBase(ViewPort vbinding, int framespeed)
|
||||
{
|
||||
viewPortDisplay = vbinding;
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long frameLength = (framespeed > 0) ? ((1000L * 1000L) / framespeed) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
viewPortDisplay.FrameSizeCallback = (handle, width, height)
|
||||
=>
|
||||
{
|
||||
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
|
||||
GlFunction.CurrentGL.Viewport(0, 0, width, height);
|
||||
PrivateShow();
|
||||
};
|
||||
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
|
||||
=>
|
||||
{
|
||||
PrivateShow();
|
||||
};
|
||||
}
|
||||
|
||||
public ViewModelBase(ViewPort vbinding, float frameLength)
|
||||
{
|
||||
viewPortDisplay = vbinding;
|
||||
allView = new();
|
||||
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
|
||||
_frameSpeed = 0;
|
||||
_frameCount = 0;
|
||||
fpsCountProvider.SpanRefreshCallback = CountFps;
|
||||
long _frameLength = (frameLength > 0) ? ((long)(1000 * frameLength)) : 0;
|
||||
frameTimeProvider = new TimeSpanProvider(
|
||||
_frameLength, TimeSpanProvider.DefaultProvider
|
||||
);
|
||||
frameTimeProvider.SpanRefreshCallback =
|
||||
() =>
|
||||
{
|
||||
};
|
||||
|
||||
viewPortDisplay.FrameSizeCallback = (handle, width, height)
|
||||
=>
|
||||
{
|
||||
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
|
||||
GlFunction.CurrentGL.Viewport(0, 0, width, height);
|
||||
PrivateShow();
|
||||
};
|
||||
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
|
||||
=>
|
||||
{
|
||||
PrivateShow();
|
||||
};
|
||||
}
|
||||
|
||||
public bool ShouldClose
|
||||
{
|
||||
get => InternalIO.glfwWindowShouldClose(viewPortDisplay.ViewPortID) != 0;
|
||||
set => InternalIO.glfwSetWindowShouldClose(viewPortDisplay.ViewPortID, value ? 1 : 0);
|
||||
}
|
||||
|
||||
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
|
||||
|
||||
public int FrameSpeed => _frameSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// Height of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Height
|
||||
{
|
||||
get => viewPortDisplay.Height;
|
||||
set { viewPortDisplay.Height = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public int Width
|
||||
{
|
||||
get => viewPortDisplay.Width;
|
||||
set
|
||||
{
|
||||
viewPortDisplay.Width = value;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ViewPort ViewPortBinding
|
||||
{
|
||||
get => viewPortDisplay;
|
||||
}
|
||||
|
||||
public unsafe IntPtr WindowID
|
||||
{
|
||||
get => viewPortDisplay.ViewPortID;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => viewPortDisplay.Name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Width of this form, represent in <see cref="int"/>
|
||||
/// </summary>
|
||||
public vec2d Size
|
||||
{
|
||||
get => new vec2d(Width, Height);
|
||||
set
|
||||
{
|
||||
Width = (int)value.X;
|
||||
Height = (int)value.Y;
|
||||
if (WindowID != IntPtr.Zero)
|
||||
{
|
||||
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable CA1044
|
||||
protected FrameBufferSizeHandler FrameSizeCallback
|
||||
{
|
||||
set
|
||||
{
|
||||
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
|
||||
InternalIO.glfwSetFramebufferSizeCallback(viewPortDisplay.ViewPortID, handlerPtr);
|
||||
}
|
||||
}
|
||||
#pragma warning restore CA1044
|
||||
|
||||
|
||||
public abstract bool TryGetObjectReference(string name,out DataBindingEntry entry);
|
||||
|
||||
public Action MethodLookup(string methodName)
|
||||
{
|
||||
MethodInfo method = GetType().GetMethod(methodName);
|
||||
return (method != null) ? ((Action)Delegate.CreateDelegate(typeof(Action), this, method)) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resize the current form
|
||||
/// </summary>
|
||||
/// <param name="size">
|
||||
/// A <see cref="vec2d"/> (width,height) representing the new size of current form
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSize(vec2d size)
|
||||
{
|
||||
this.Size = size;
|
||||
InternalIO.glfwSetWindowSize(this.viewPortDisplay.ViewPortID, (int)size.X, (int)size.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minSize">
|
||||
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
/// <param name="maxSize">
|
||||
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
|
||||
/// </param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(vec2d minSize, vec2d maxSize)
|
||||
{
|
||||
InternalIO.glfwSetWindowSizeLimits(
|
||||
this.viewPortDisplay.ViewPortID,
|
||||
(int)minSize.X,
|
||||
(int)minSize.Y,
|
||||
(int)maxSize.X,
|
||||
(int)maxSize.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the size limit of current form
|
||||
/// </summary>
|
||||
/// <param name="minWidth">Minimum width of current form</param>
|
||||
/// <param name="minHeight">Minimum height of current form</param>
|
||||
/// <param name="maxWidth">Maximum width of current form</param>
|
||||
/// <param name="maxHeight">Maximum height of current form</param>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
|
||||
{
|
||||
//TODO 重做form的尺寸极限控制
|
||||
InternalIO.glfwSetWindowSizeLimits(this.viewPortDisplay.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
private void CountFps()
|
||||
{
|
||||
/**/
|
||||
Console.Clear();
|
||||
Console.WriteLine(FrameSpeed);
|
||||
/**/
|
||||
Interlocked.Exchange(ref _frameSpeed, _frameCount);
|
||||
Interlocked.Exchange(ref _frameCount, 0);
|
||||
}
|
||||
|
||||
public DataBindingEntry this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.TryGetObjectReference(name, out DataBindingEntry entry))
|
||||
{
|
||||
return entry;
|
||||
}
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void CustomizeInitialize();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user