daily update on 20240613 by nitload youmu[4

This commit is contained in:
Nitload
2024-06-14 05:30:19 +08:00
parent be6c2e6b92
commit 7fb220c523
50 changed files with 991 additions and 700 deletions
@@ -111,72 +111,4 @@ namespace StgSharp.Logic
}
public sealed class RouteHub : BlueprintNode
{
private Dictionary<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)> inputDictionary;
public RouteHub(string name, string[] inputPorts, string[] outputPorts) : base(name, inputPorts, outputPorts)
{
inputDictionary = new Dictionary<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)>();
}
public new int Level
{
get
{
if (levelAvailable)
{
return _level;
}
_level = 0;
foreach (KeyValuePair<string, BlueprintPipeline> item in _inputInterfaces)
{
if (item.Value == null)
{
continue;
}
if (_level <= item.Value.Level)
{
_level = item.Value.Level;
}
}
return _level;
}
}
public void PrependNode(BlueprintNode node, string portName, Func<bool> usingRule)
{
if (node == null)
{
throw new ArgumentNullException(nameof(node));
}
string indexName = $"{node.Name}.{portName}";
BlueprintPipeline p = new BlueprintPipeline(this, node);
node.InputInterfaces[portName] = p;
inputDictionary.Add(indexName, (p, usingRule));
}
public new void Run()
{
try
{
foreach (KeyValuePair<string, (BlueprintPipeline pipeline, Func<bool> controllingFunc)> item in inputDictionary)
{
item.Value.pipeline.WaitForStart();
if (item.Value.controllingFunc())
{
_outputInterfaces.First().Value.CompleteAndWriteData(item.Value.pipeline.Args);
}
}
}
catch (Exception)
{
throw;
}
}
}
}
@@ -44,7 +44,9 @@ namespace StgSharp.Logic
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
protected SemaphoreSlim CheckSubscriberSemaphore
=> _addSubscriberSemaphore;
{
get => _addSubscriberSemaphore;
}
public void AddSubscriber(TimeSpanProvider subscriber)
{
@@ -81,6 +83,8 @@ namespace StgSharp.Logic
}
public abstract void StartProvidingTime();
public abstract void StopProvidingTime();
protected abstract void AddSubscriberUnsynced(TimeSpanProvider subscriber);
protected abstract void RemoveSubscriberUnsynced(TimeSpanProvider subscriber);
+16 -14
View File
@@ -130,12 +130,6 @@ namespace StgSharp
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
public Action FrameUpdateMissCallback
{
get => _frameUpdateMissCallback;
set => _frameUpdateMissCallback = value;
}
public double SpanLength
{
get => (_spanLength * 1.0) / (1000L * 1000L);
@@ -176,18 +170,20 @@ namespace StgSharp
internal bool CheckTime(long microseconds)
{
//Console.Write("1 ");
if (microseconds - _spanBegin < _spanLength)
{
return true;
}
//Console.Write("2 ");
_spanBegin = microseconds;
timeSpanCount++;
//Console.Write("3 ");
if (_refreshCallback != null)
{
_refreshCallback();
}
//Console.Write("4 ");
if (_refreshSemaphore.CurrentCount == 0)
{
_refreshSemaphore.Release();
@@ -199,17 +195,23 @@ namespace StgSharp
_frameUpdateMissCallback();
}
}
if (timeSpanCount > _maxSpanCount)
{
return false;
}
return true;
//Console.Write("5 ");
//Console.WriteLine( $"{timeSpanCount}\n" );
return timeSpanCount < _maxSpanCount;
}
public static implicit operator int(TimeSpanProvider provider)
{
return provider.timeSpanCount.Value;
if (provider == null)
{
return 0;
}
return provider.ToInt32();
}
public int ToInt32()
{
return (int)timeSpanCount.Value;
}
}
}
@@ -27,8 +27,18 @@ namespace StgSharp.Logic
/// </summary>
public unsafe void Show()
{
while(0 == InternalIO.glfwWindowShouldClose(this.context.ViewPortID))
BuildGlobalKeyControl();
while(0 == InternalIO.glfwWindowShouldClose(this.viewPortDisplay.ViewPortID))
{
viewPortDisplay.FlushSize();
foreach (var item in this._globalKeyAction)
{
if (InternalIO.glfwGetKey(this.viewPortDisplay.ViewPortID, (int)item.Key.TargetKeyOrButtonID)
== item.Key.TriggeredStatus)
{
item.Value();
}
}
renderLogic.RunRepeatedly(() => ShouldClose);
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
@@ -15,14 +15,14 @@ namespace StgSharp.Logic
ViewPortDesigner designer, (int x, int y, int z) unitCubeSize
)
{
View ret = new View(this.context, designer,unitCubeSize);
View ret = new View(this.viewPortDisplay, designer,unitCubeSize);
allView.Add(ret);
return ret;
}
public T BuildRenderStream<T>(View v, (int, int, int) cube) where T : RenderStream
public T BuildRenderStream<T>(View view) where T : RenderStream
{
T ret = Activator.CreateInstance(typeof(T), v.Port, cube) as T ??
T ret = Activator.CreateInstance(typeof(T), view.Port, view.UnitCubeSize) as T ??
throw new InvalidOperationException("Cannot build new render stream.");
ret.timeProvider = this.frameTimeProvider;
ret.InternalInit();
+36 -18
View File
@@ -28,6 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Controlling.UsrActivity;
using StgSharp.Graphics;
using StgSharp.Math;
@@ -47,7 +48,7 @@ namespace StgSharp.Logic
private int _frameCount;
private int _frameSpeed;
private ViewPort context;
private ViewPort viewPortDisplay;
internal IntPtr monitor;
@@ -57,7 +58,11 @@ namespace StgSharp.Logic
protected ViewModelBase(int frameSpeed)
{
context = new ViewPort();
viewPortDisplay = new ViewPort(
name: "Hello, Stg#!",
size: (800, 600),
monitor: IntPtr.Zero
);
allView = new List<View>();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
@@ -76,11 +81,12 @@ namespace StgSharp.Logic
() =>
{
};
_globalKeyAction = new Dictionary<KeyTrigger, Action>();
}
public ViewModelBase(ViewPort vbinding, int framespeed)
{
context = vbinding;
viewPortDisplay = vbinding;
allView = new List<View>();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
@@ -88,10 +94,14 @@ namespace StgSharp.Logic
fpsCountProvider.SpanRefreshCallback =
() =>
{
/*
Console.Clear();
Console.WriteLine(FrameSpeed);
/**/
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
};
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
long frameLength = (framespeed > 0) ? ((1000L * 1000L) / framespeed) : 0;
frameTimeProvider = new TimeSpanProvider(
frameLength, TimeSpanProvider.DefaultProvider
);
@@ -99,6 +109,7 @@ namespace StgSharp.Logic
() =>
{
};
_globalKeyAction = new Dictionary<KeyTrigger, Action>();
}
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
@@ -110,19 +121,19 @@ namespace StgSharp.Logic
/// </summary>
public int Height
{
get => context.Height;
set { context.Height = value; }
get => viewPortDisplay.Height;
set { viewPortDisplay.Height = value; }
}
public string Name
{
get => context.Name;
get => viewPortDisplay.Name;
}
public bool ShouldClose
{
get => InternalIO.glfwWindowShouldClose(context.ViewPortID) != 0;
set => InternalIO.glfwSetWindowShouldClose(context.ViewPortID, value ? 1 : 0);
get => InternalIO.glfwWindowShouldClose(viewPortDisplay.ViewPortID) != 0;
set => InternalIO.glfwSetWindowShouldClose(viewPortDisplay.ViewPortID, value ? 1 : 0);
}
/// <summary>
@@ -137,7 +148,7 @@ namespace StgSharp.Logic
Height = (int)value.Y;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(context.ViewPortID, Width, Height);
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
}
}
}
@@ -147,20 +158,20 @@ namespace StgSharp.Logic
/// </summary>
public int Width
{
get => context.Width;
get => viewPortDisplay.Width;
set
{
context.Width = value;
viewPortDisplay.Width = value;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(context.ViewPortID, Width, Height);
InternalIO.glfwSetWindowSize(viewPortDisplay.ViewPortID, Width, Height);
}
}
}
public unsafe IntPtr WindowID
{
get => context.ViewPortID;
get => viewPortDisplay.ViewPortID;
}
@@ -170,7 +181,7 @@ namespace StgSharp.Logic
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(context.ViewPortID, handlerPtr);
InternalIO.glfwSetFramebufferSizeCallback(viewPortDisplay.ViewPortID, handlerPtr);
}
}
#pragma warning restore CA1044
@@ -186,7 +197,7 @@ namespace StgSharp.Logic
public void SetSize(vec2d size)
{
this.Size = size;
InternalIO.glfwSetWindowSize(this.context.ViewPortID, (int)size.X, (int)size.Y);
InternalIO.glfwSetWindowSize(this.viewPortDisplay.ViewPortID, (int)size.X, (int)size.Y);
}
@@ -203,7 +214,7 @@ namespace StgSharp.Logic
public void SetSizeLimit(vec2d minSize, vec2d maxSize)
{
InternalIO.glfwSetWindowSizeLimits(
this.context.ViewPortID,
this.viewPortDisplay.ViewPortID,
(int)minSize.X,
(int)minSize.Y,
(int)maxSize.X,
@@ -221,7 +232,7 @@ namespace StgSharp.Logic
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
//TODO 重做form的尺寸极限控制
InternalIO.glfwSetWindowSizeLimits(this.context.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
InternalIO.glfwSetWindowSizeLimits(this.viewPortDisplay.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
}
#region Key Control
@@ -243,7 +254,14 @@ namespace StgSharp.Logic
#endregion
protected abstract void BuildGlobalKeyControl();
private Dictionary<KeyTrigger, Action> _globalKeyAction;
protected Dictionary<KeyTrigger, Action> GlobalKeyAction
{
get => _globalKeyAction;
}
}
}