daily update on 20240610 by nitload youmu

This commit is contained in:
Nitload
2024-06-10 15:11:01 +08:00
parent c0093f7b5c
commit f6963b8e00
96 changed files with 2927 additions and 2290 deletions
@@ -125,14 +125,11 @@ namespace StgSharp.Logic
{
do
{
try
BlueprintNode node;
while (RequestNextNode(out node))
{
while (true)
{
RequestNextNode().Run();
}
node.Run();
}
catch (NodeClearException) { }
} while (!terminate());
}
@@ -199,16 +196,18 @@ namespace StgSharp.Logic
beginNode.InputData = parameters;
}
private BlueprintNode RequestNextNode()
private bool RequestNextNode(out BlueprintNode node)
{
if (currentNodeIndex < nodeList.Count)
{
BlueprintNode ret = nodeList[currentNodeIndex];
Interlocked.Increment(ref currentNodeIndex);
return ret;
node = ret;
return true;
}
Interlocked.Exchange(ref currentNodeIndex, 0);
throw new NodeClearException();
node = default!;
return false;
}
string[] IConvertableToBlueprintNode.InputInterfacesName
@@ -69,14 +69,14 @@ namespace StgSharp.Logic
public void CompleteAndSkip()
{
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
//Console.WriteLine($"Complete\t{former.ContextName}\t->\t{after.ContextName}");
formerCompleteSemaphore.Release();
}
public void CompleteAndWriteData(BlueprintPipelineArgs args)
{
this.args = args;
//Console.WriteLine($"Complete\t{former.Name}\t->\t{after.Name}");
//Console.WriteLine($"Complete\t{former.ContextName}\t->\t{after.ContextName}");
formerCompleteSemaphore.Release();
}
@@ -112,7 +112,7 @@ namespace StgSharp.Logic
public void WaitForStart()
{
//Console.WriteLine($"Waiting \t{former.Name}\t->\t{after.Name}");
//Console.WriteLine($"Waiting \t{former.ContextName}\t->\t{after.ContextName}");
formerCompleteSemaphore.Wait();
}
+51 -43
View File
@@ -36,10 +36,13 @@ namespace StgSharp
{
public class TimeFunction
{
private float _beginning, _ending;
private Func<float, float> _timeRelatedCalculation;
private TimeSpanProvider _timeProvider;
internal TimeFunction() { }
public TimeFunction(
TimeSpanProvider timeSpanProvider,
Func<float, float> timeRelatedCalculation,
@@ -55,13 +58,16 @@ namespace StgSharp
_ending = _timeProvider.CurrentSecond + range;
}
internal TimeFunction() { }
public bool IsComplete
public virtual bool IsComplete
{
get => _timeProvider.CurrentSecond > _ending;
}
public static TimeFunction One
{
get => new TimeFunctionOne();
}
public Func<float, float> TimeRelatedCalculation
{
get { return _timeRelatedCalculation; }
@@ -74,7 +80,7 @@ namespace StgSharp
set { _timeProvider = value; }
}
public float Calculate()
public virtual float Calculate()
{
if (_timeProvider.CurrentSecond < _ending)
{
@@ -83,64 +89,66 @@ namespace StgSharp
return _timeRelatedCalculation(_timeProvider.CurrentSecond - _beginning);
}
public void Reset()
{
float range = _ending - _beginning;
_beginning = _timeProvider.CurrentSecond;
_ending = _beginning + range;
}
public TimeFunction Renew(Func<float,float> func,float range)
{
return new TimeFunction(_timeProvider,func,range);
}
public TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
}
public static TimeFunction One
{
get => new TimeFunctionOne();
}
public static TimeFunction Proportional(TimeSpanProvider time,float begin, float range)
public static TimeFunction Proportional(TimeSpanProvider time, float begin, float range)
{
return new TimeFunction(
time, (float t) => t + begin, range
);
}
public virtual TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
return new TimeFunction(_timeProvider, funcPair.func, funcPair.range);
}
public virtual TimeFunction Renew(Func<float, float> func, float range)
{
return new TimeFunction(_timeProvider, func, range);
}
public void Reset()
{
float range = _ending - _beginning;
_beginning = _timeProvider.CurrentSecond;
_ending = _beginning + range;
}
}
public class TimeFunctionOne : TimeFunction
public sealed class TimeFunctionOne : TimeFunction
{
internal TimeFunctionOne() : base()
{
}
public new bool IsCompleted
public override bool IsComplete
{
get => true;
}
public new void Reset()
{
}
public new TimeFunction Renew(Func<float, float> func, float range)
{
throw new NotSupportedException();
}
public new TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
throw new NotSupportedException();
}
public float Calculate()
public override float Calculate()
{
return 1;
}
public override TimeFunction Renew((Func<float, float> func, float range) funcPair)
{
throw new NotSupportedException();
}
public override TimeFunction Renew(Func<float, float> func, float range)
{
throw new NotSupportedException();
}
#pragma warning disable CA1822
public new void Reset()
#pragma warning restore CA1822
{
}
}
}
@@ -0,0 +1,54 @@
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace StgSharp.Logic
{
public abstract partial class ViewModelBase
{
public void ShowViewPort()
{
}
private Blueprint renderLogic;
public Blueprint RenderLogic
{
get => renderLogic;
set => renderLogic = value;
}
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show()
{
while(0 == InternalIO.glfwWindowShouldClose(this.context.ViewPortID))
{
renderLogic.RunRepeatedly(() => ShouldClose);
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
}
public T BuildNewRenderStream<T>(View arg, (int x, int y, int z) unitCubeSize) where T : RenderStream
{
if (arg.ContextName == this.Name)
{
}
T? ret = Activator.CreateInstance(typeof(T), arg) as T;
if (ret == null)
{
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
}
ret!.InternalInit();
ret.timeProvider = this.frameTimeProvider;
return ret;
}
}
}
@@ -0,0 +1,32 @@
using StgSharp.Graphics;
using StgSharp.Graphics.GL;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Logic
{
public partial class ViewModelBase
{
private List<View> allView;
public View BuildNewView(
ViewPortDesigner designer, (int x, int y, int z) unitCubeSize
)
{
View ret = new View(this.context, designer,unitCubeSize);
allView.Add(ret);
return ret;
}
public T BuildRenderStream<T>(View v, (int, int, int) cube) where T : RenderStream
{
T ret = Activator.CreateInstance(typeof(T), v.Port, cube) as T ??
throw new InvalidOperationException("Cannot build new render stream.");
ret.timeProvider = this.frameTimeProvider;
ret.InternalInit();
return ret;
}
}
}
@@ -0,0 +1,249 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
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 context;
internal IntPtr monitor;
internal TimeSpanProvider fpsCountProvider;
internal TimeSpanProvider frameTimeProvider;
internal Vector4 backgroundColor;
protected ViewModelBase(int frameSpeed)
{
context = new ViewPort();
allView = new List<View>();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback =
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
};
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
frameTimeProvider = new TimeSpanProvider(
frameLength, TimeSpanProvider.DefaultProvider
);
frameTimeProvider.SpanRefreshCallback =
() =>
{
};
}
public ViewModelBase(ViewPort vbinding, int framespeed)
{
context = vbinding;
allView = new List<View>();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback =
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
};
long frameLength = (FrameSpeed > 0) ? ((1000L * 1000L) / FrameSpeed) : 0;
frameTimeProvider = new TimeSpanProvider(
frameLength, TimeSpanProvider.DefaultProvider
);
frameTimeProvider.SpanRefreshCallback =
() =>
{
};
}
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
public int FrameSpeed => _frameSpeed;
/// <summary>
/// Height of this form, represent in <see cref="int"/>
/// </summary>
public int Height
{
get => context.Height;
set { context.Height = value; }
}
public string Name
{
get => context.Name;
}
public bool ShouldClose
{
get => InternalIO.glfwWindowShouldClose(context.ViewPortID) != 0;
set => InternalIO.glfwSetWindowShouldClose(context.ViewPortID, value ? 1 : 0);
}
/// <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(context.ViewPortID, Width, Height);
}
}
}
/// <summary>
/// Width of this form, represent in <see cref="int"/>
/// </summary>
public int Width
{
get => context.Width;
set
{
context.Width = value;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(context.ViewPortID, Width, Height);
}
}
}
public unsafe IntPtr WindowID
{
get => context.ViewPortID;
}
#pragma warning disable CA1044
protected FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(context.ViewPortID, handlerPtr);
}
}
#pragma warning restore CA1044
/// <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.context.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.context.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.context.ViewPortID, minWidth, minHeight, maxWidth, maxHeight);
}
#region Key Control
protected KeyStatus CheckKey(KeyboardKey key)
{
return InternalIO.glfwGetKey(this.WindowID, (int)key);
}
protected KeyStatus CheckKey(Mouse key)
{
return InternalIO.glfwGetKey(this.WindowID, (int)key);
}
protected KeyStatus CheckKey(Joystick key)
{
return InternalIO.glfwGetKey(this.WindowID, (int)key);
}
#endregion
}
}