daily update on 20240501 by nitload youmu, tracking blueprint coruptr

This commit is contained in:
YoumuLiu
2024-05-02 05:47:27 +08:00
parent 0cd01ed9dd
commit 6324e578ab
60 changed files with 2564 additions and 307 deletions
+2 -2
View File
@@ -127,10 +127,10 @@ namespace StgSharp
using (StreamWriter logStream = File.AppendText(SS_errorlog))
{
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine($"{logType}\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
logSyncSemaphore.Release();
}
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
@@ -97,6 +97,7 @@ namespace StgSharp
public static void Terminate()
{
MainTimeProvider.Terminate();
InternalIO.glfwTerminate();
}
public static void Track(
+61 -20
View File
@@ -32,6 +32,7 @@ using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
@@ -59,26 +60,65 @@ namespace StgSharp.Graphics
internal Vector4 backgroundColor;
internal TimeSpanProvider fpsCountProvider;
internal TimeSpanProvider frameTimeProvider;
internal RenderStream mainRenderStream;
internal int height;
internal IntPtr monitor;
internal string name;
internal Form sharedForm;
internal int width;
protected Form()
public Form()
{
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback = new TimeSpanRefeshCallback(
fpsCountProvider.SpanRefreshCallback =
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
//Console.Clear();
//Console.WriteLine(_frameSpeed);
});
};
frameTimeProvider = new TimeSpanProvider(
1000L * 1000L / 60, TimeSpanProvider.DefaultProvider
);
frameTimeProvider.SpanRefreshCallback =
() =>
{
Interlocked.Increment(ref _frameCount);
};
height = 800;
width = 600;
name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
}
protected Form((int width, int height) size, string name)
{
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback =
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
//Console.Clear();
//Console.WriteLine(_frameSpeed);
};
frameTimeProvider = new TimeSpanProvider(
1000L * 1000L / 60, TimeSpanProvider.DefaultProvider
);
frameTimeProvider.SpanRefreshCallback =
() =>
{
Interlocked.Increment(ref _frameCount);
Console.WriteLine(1);
};
height = size.height;
width = size.width;
this.name = name;
}
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
@@ -93,7 +133,10 @@ namespace StgSharp.Graphics
set
{
height = value;
InternalIO.glfwSetWindowSize(windowID, Width, Height);
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
@@ -113,7 +156,10 @@ namespace StgSharp.Graphics
{
width = (int)value.X;
height = (int)value.Y;
InternalIO.glfwSetWindowSize(windowID, Width, Height);
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
@@ -126,12 +172,19 @@ namespace StgSharp.Graphics
set
{
width = value;
InternalIO.glfwSetWindowSize(windowID, Width, Height);
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
public unsafe IntPtr WindowID => windowID;
public unsafe IntPtr WindowID
{
get => windowID;
internal set => windowID = value;
}
internal unsafe IntPtr id => windowID;
@@ -172,18 +225,6 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
@@ -29,8 +29,7 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using StgSharpDebug.Logic;
using StgSharp.Logic;
using System;
using System.Collections.Generic;
@@ -46,15 +45,28 @@ namespace StgSharp.Graphics
{
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()
{
int a = 0;
while (!ShouldClose)
{
a++;
renderLogic.RunRepeatedly(() => ShouldClose);
frameTimeProvider.WaitNextSpan();
}
}
private void GahterSignleFrameAsyncThread(MethodInfo[] methods)
/*
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
{
if (methods.Length == 0)
{
@@ -76,7 +88,7 @@ namespace StgSharp.Graphics
//singleFrameAsyncThreadList.Add(thread);
}
}
/**/
}
}
+44 -34
View File
@@ -42,25 +42,35 @@ namespace StgSharp.Graphics
{
internal static unsafe partial class GL
{
private static IntPtr api;
internal static GLcontext* api;
private static ref GLcontext Context
{
get { return ref *(GLcontext*)api; }
}
public static IntPtr CurrentContextHandle
{
get { return (IntPtr)api; }
set { api = value; }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ActiveTexture(uint type)
{
api->glActiveTexture(type);
Context.glActiveTexture(type);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AttachShader(glHandle program, glHandle shader)
{
api->glAttachShader(program.Value, shader.Value);
Context.glAttachShader(program.Value, shader.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindBuffer(BufferType bufferType, glHandle handle)
{
api->glBindBuffer((uint)bufferType, handle.Value);
Context.glBindBuffer((uint)bufferType, handle.Value);
}
/// <summary>
@@ -72,13 +82,13 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindFrameBuffer(FrameBufferTarget target, glHandle handle)
{
api->glBindFramebuffer((uint)target, handle.Value);
Context.glBindFramebuffer((uint)target, handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindTexture(uint type, glHandle texture)
{
api->glBindTexture(type, texture.Value);
Context.glBindTexture(type, texture.Value);
}
@@ -86,43 +96,43 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void BindVertexArray(glHandle handle)
{
api->glBindVertexArray(handle.Value);
Context.glBindVertexArray(handle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Clear(MaskBufferBit mask)
{
api->glClear((uint)mask);
Context.glClear((uint)mask);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearColor(float R, float G, float B, float A)
{
api->glClearColor(R, G, B, A);
Context.glClearColor(R, G, B, A);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void ClearGraphicError()
{
while (api->glGetError() != 0) { }
while (Context.glGetError() != 0) { }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void CompileShader(glHandle shaderhandle)
{
api->glCompileShader(shaderhandle.Value);
Context.glCompileShader(shaderhandle.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandle CreateGraphicProgram()
{
return glHandle.Alloc(api->glCreateProgram());
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glHandle CreateProgram()
{
return glHandle.Alloc(api->glCreateProgram());
return glHandle.Alloc(Context.glCreateProgram());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -131,7 +141,7 @@ namespace StgSharp.Graphics
glHandleSet h = new glHandleSet(count);
for (int i = 0; i < count; i++)
{
h.SetValue(i, api->glCreateProgram());
h.SetValue(i, Context.glCreateProgram());
}
return h;
}
@@ -143,10 +153,10 @@ namespace StgSharp.Graphics
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
uint id = Context.glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
uint error = Context.glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
@@ -184,20 +194,20 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffer(glHandle handle)
{
api->glDeleteBuffers(1, (uint*)handle.Handle);
Context.glDeleteBuffers(1, (uint*)handle.Handle);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteBuffers(glHandleSet handle)
{
api->glDeleteBuffers(handle.length, (uint*)handle.Handle);
Context.glDeleteBuffers(handle.length, (uint*)handle.Handle);
handle.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void DeleteVertexArrays(glHandleSet arrays)
{
api->glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
Context.glDeleteVertexArrays(arrays.length, (uint*)arrays.Handle);
arrays.Release();
}
@@ -225,20 +235,20 @@ namespace StgSharp.Graphics
LogType.Error);
return;
}
api->glDrawElements((uint)mode, count, a, (void*)ptr);
Context.glDrawElements((uint)mode, count, a, (void*)ptr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Enable(GLOperation operation)
{
api->glEnable((uint)operation);
Context.glEnable((uint)operation);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe glHandleSet GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenBuffers(count, (uint*)h.Handle);
Context.glGenBuffers(count, (uint*)h.Handle);
return h;
}
@@ -246,7 +256,7 @@ namespace StgSharp.Graphics
public static unsafe glHandleSet GenTextures(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenTextures(count, (uint*)h.Handle);
Context.glGenTextures(count, (uint*)h.Handle);
return h;
}
@@ -254,7 +264,7 @@ namespace StgSharp.Graphics
public static unsafe glHandleSet GenVertexArrays(int count)
{
glHandleSet h = new glHandleSet(count);
api->glGenVertexArrays(count, (uint*)h.Handle);
Context.glGenVertexArrays(count, (uint*)h.Handle);
return h;
}
@@ -264,7 +274,7 @@ namespace StgSharp.Graphics
byte[] code = Encoding.UTF8.GetBytes(name);
fixed (byte* ptr = code)
{
return glSHandle.Alloc(api->glGetUniformLocation(program.Value, ptr));
return glSHandle.Alloc(Context.glGetUniformLocation(program.Value, ptr));
}
}
@@ -274,7 +284,7 @@ namespace StgSharp.Graphics
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
Context.glShaderSource(shaderHandle.Value, 1, &streamPtr, (void*)0);
}
}
@@ -294,7 +304,7 @@ namespace StgSharp.Graphics
{
int size = Marshal.SizeOf<T>();
T* p = &bufferData;
api->glBufferData(
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)p,
@@ -311,7 +321,7 @@ namespace StgSharp.Graphics
}
fixed (void* bufferPtr = bufferArray)
{
api->glBufferData(
Context.glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
@@ -323,14 +333,14 @@ namespace StgSharp.Graphics
public static void SetVertexAttribute(uint index, int size, TypeCode t, bool normalized, uint stride, int pointer)
{
uint type = InternalIO.GLtype[t];
api->glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
api->glEnableVertexAttribArray(index);
Context.glVertexAttribPointer(index, size, type, normalized ? 1 : 0, stride, (void*)pointer);
Context.glEnableVertexAttribArray(index);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
{
api->glTexImage2D(
Context.glTexImage2D(
(uint)target, level, internalformat, width, height, 0, format, type, pixels.valuePtr
);
}
@@ -338,19 +348,19 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void TextureParameter(int target, uint pname, int param)
{
api->glTexParameteri((uint)target, pname, param);
Context.glTexParameteri((uint)target, pname, param);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UseProgram(glHandle program)
{
api->glUseProgram(program.Value);
Context.glUseProgram(program.Value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Viewport(int x, int y, uint width, uint height)
{
api->glViewport(x, y, width, height);
Context.glViewport(x, y, width, height);
}
}
@@ -73,7 +73,7 @@ namespace StgSharp.Graphics
internal unsafe Shader(glHandleSet handle, ShaderType usage)
{
this.handle = handle;
context = (IntPtr)GL.api;
context = GL.CurrentContextHandle;
type = usage;
}
@@ -137,7 +137,7 @@ namespace StgSharp.Graphics
internal unsafe Uniform(
ShaderProgram program, string name)
{
this.binding = (IntPtr)GL.api;
this.binding = GL.CurrentContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
@@ -181,7 +181,7 @@ namespace StgSharp.Graphics
internal unsafe Uniform(
ShaderProgram program, string name)
{
this.binding = (IntPtr)GL.api;
this.binding = GL.CurrentContextHandle;
id = GL.GetUniformLocation(program.handle, name);
}
@@ -203,51 +203,51 @@ namespace StgSharp.Graphics
public unsafe static void SetValue(Uniform<Matrix44> uniform, Matrix44 mat)
{
Matrix44 temp = mat;
api->glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&mat);
Context.glUniformMatrix4fv(uniform.id.Value, 1, false, (float*)&mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static void SetValue(Uniform<float, float, float, float> uniform, vec4d vec)
{
vec4d temp = vec;
api->glUniform1fv(uniform.id.Value , 4, &temp);
Context.glUniform1fv(uniform.id.Value , 4, &temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe static void SetValue(Uniform<vec4d> uniform, vec4d vec)
{
vec4d temp = vec;
api->glUniform1fv(uniform.id.Value , 4, &temp);
Context.glUniform1fv(uniform.id.Value , 4, &temp);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetValue(Uniform<float> uniform, float v0)
{
api->glUniform1f(uniform.id.Value , v0);
Context.glUniform1f(uniform.id.Value , v0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetValue(Uniform<int> uniform, int i0)
{
api->glUniform1i(uniform.id.Value , i0);
Context.glUniform1i(uniform.id.Value , i0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetValue(Uniform<float, float> uniform, float v0, float v1)
{
api->glUniform2f(uniform.id.Value , v0, v1);
Context.glUniform2f(uniform.id.Value , v0, v1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2)
{
api->glUniform3f(uniform.id.Value , v0, v1, v2);
Context.glUniform3f(uniform.id.Value , v0, v1, v2);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3)
{
api->glUniform4f(uniform.id.Value , v0, v1, v2, v3);
Context.glUniform4f(uniform.id.Value , v0, v1, v2, v3);
}
}
+20 -20
View File
@@ -63,7 +63,7 @@ namespace StgSharp.Graphics
public static unsafe void LoadGLapi(this glRenderStream stream)
{
GLcontext* context = (GLcontext*)stream.ContextHandle;
GLfuncLoader loader = InternalIO.glfwGetProcAddress;
delegate*<string,IntPtr> loader = &InternalIO.glfwGetProcAddress;
#pragma warning disable CS8909
if (((GLcontext*)stream.ContextHandle)->glGetString != (delegate*<uint, IntPtr>)IntPtr.Zero)
#pragma warning restore CS8909
@@ -999,7 +999,7 @@ namespace StgSharp.Graphics
}
}
internal static unsafe void LoadGLcore10(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore10(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core10)
{
@@ -1063,7 +1063,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.0 APIs");
}
internal static unsafe void LoadGLcore11(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore11(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core11)
{
@@ -1093,7 +1093,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.1 APIs");
}
internal static unsafe void LoadGLcore12(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore12(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core12)
{
@@ -1113,7 +1113,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.2 APIs");
}
internal static unsafe void LoadGLcore13(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore13(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core13)
{
@@ -1138,7 +1138,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.3 APIs");
}
internal static unsafe void LoadGLcore14(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore14(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core14)
{
@@ -1163,7 +1163,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.4 APIs");
}
internal static unsafe void LoadGLcore15(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore15(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core15)
{
@@ -1198,7 +1198,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 1.5 APIs");
}
internal static unsafe void LoadGLcore20(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore20(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core20)
{
@@ -1307,7 +1307,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.0 APIs");
}
internal static unsafe void LoadGLcore21(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore21(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core21)
{
@@ -1329,7 +1329,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 2.1 APIs");
}
internal static unsafe void LoadGLcore30(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore30(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core30)
{
@@ -1429,7 +1429,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.0 APIs");
}
internal static unsafe void LoadGLcore31(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore31(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core31)
{
@@ -1460,7 +1460,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.1 APIs");
}
internal static unsafe void LoadGLcore32(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore32(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core32)
{
@@ -1495,7 +1495,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.2 APIs");
}
internal static unsafe void LoadGLcore33(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore33(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core33)
{
@@ -1539,7 +1539,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 3.3 APIs");
}
internal static unsafe void LoadGLcore40(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore40(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core40)
{
@@ -1601,7 +1601,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.0 APIs");
}
internal static unsafe void LoadGLcore41(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore41(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core41)
{
@@ -1705,7 +1705,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.1 APIs");
}
internal static unsafe void LoadGLcore42(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore42(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core42)
{
@@ -1733,7 +1733,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.2 APIs");
}
internal static unsafe void LoadGLcore43(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore43(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core43)
{
@@ -1793,7 +1793,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.3 APIs");
}
internal static unsafe void LoadGLcore44(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore44(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core44)
{
@@ -1818,7 +1818,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.4 APIs");
}
internal static unsafe void LoadGLcore45(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore45(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core45)
{
@@ -1944,7 +1944,7 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.5 APIs");
}
internal static unsafe void LoadGLcore46(GLcontext* contextPtr, GLfuncLoader load)
internal static unsafe void LoadGLcore46(GLcontext* contextPtr, delegate*<string, IntPtr> load)
{
if (!core46)
{
@@ -1,4 +1,5 @@
using StgSharp.Math;
using StgSharp.Logic;
using StgSharp.Math;
using System;
using System.Collections.Generic;
@@ -12,6 +13,20 @@ namespace StgSharp.Graphics
{
public abstract partial class glRenderStream: RenderStream
{
public static T AsMainStreamOf<T>(Form f, (int x, int y, int z) unitCubeSize) where T : glRenderStream
{
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
args.UnitCubeSize = unitCubeSize;
args.Name = f.name;
args.Height = f.Height;
args.Width = f.Width;
T ret = Activator.CreateInstance(typeof(T), args) as T;
ret!.InternalInit();
f.WindowID = ret.CanvasHandle;
return ret;
}
protected sealed override void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up)
{
NativeCamera.SetViewDirection(position, direction, up);
@@ -53,34 +68,18 @@ namespace StgSharp.Graphics
/// </exception>
public unsafe void MakeAsCurrentContext()
{
if (CanvasHandle == default)
if (ContextHandle == default)
{
IntPtr windowPtr;
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (SharedCanvas == IntPtr.Zero)
{
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(Width, Height, tittleBytes, Monitor, SharedCanvas);
}
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
else
{
CanvasHandle = windowPtr;
}
ContextHandle = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
GLcontext* contextID = (GLcontext*)ContextHandle;
*contextID = new GLcontext();
contextID->glGetString = (delegate*<uint, IntPtr>)IntPtr.Zero;
}
GL.api = (GLcontext*)ContextHandle;
InternalIO.glfwMakeContextCurrent(CanvasHandle);
if (GL.CurrentContextHandle != ContextHandle)
{
GL.CurrentContextHandle = ContextHandle;
Console.WriteLine($"context set as {(ulong)GL.CurrentContextHandle}");
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -96,10 +95,12 @@ namespace StgSharp.Graphics
Init();
}
internal sealed override void InternalDraw()
internal sealed override void InternalDraw(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output)
{
MakeAsCurrentContext();
Main();
Main(in input, in output);
}
+1 -1
View File
@@ -71,7 +71,7 @@ namespace StgSharp.Graphics
{
if (info.pixelPtr!= IntPtr.Zero)
{
Marshal.FreeHGlobal(info.pixelPtr);
// Marshal.FreeHGlobal(info.pixelPtr);
}
}
+22 -5
View File
@@ -28,6 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Logic;
using StgSharp.Math;
using System;
@@ -41,7 +42,7 @@ using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract class RenderStream
public abstract class RenderStream: IConvertableToBlueprintNode
{
private IntPtr canvasHandle;
@@ -55,7 +56,7 @@ namespace StgSharp.Graphics
protected string name;
private Camera nativeCamera;
protected RenderStream(RenderStreamConstructArgs args)
public RenderStream(RenderStreamConstructArgs args)
{
height = args.Height;
monitor = args.Monitor;
@@ -143,6 +144,15 @@ namespace StgSharp.Graphics
}
}
protected abstract string[] InputPortsName { get; }
protected abstract string[] OutputPortsName { get; }
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
/// <summary>
/// Set the size limit of current form
/// </summary>
@@ -159,7 +169,7 @@ namespace StgSharp.Graphics
protected abstract void NativeCameraViewRange(Radius FieldOfRange,vec2d offset, (float frontDepth, float backDepth ) viewDepth );
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
/// <summary>
/// Get <see cref="Uniform{Matrix44}"/> uniform from a shader.
/// Get <see cref="Uniform{T}"/>(T is <see cref="Matrix44"/>) uniform from a shader.
/// This uniform will be used as projection matrix of this camera.
/// Additionally, for multi-shader rendering, each shader requires a uniform,
/// so do not ignore return value of this method.
@@ -174,7 +184,9 @@ namespace StgSharp.Graphics
#endregion
#region internal operation
internal abstract void InternalDraw();
internal abstract void InternalDraw(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
internal abstract void InternalInit();
internal abstract void InternalTerminate();
#endregion
@@ -182,8 +194,11 @@ namespace StgSharp.Graphics
#region public operation
protected abstract void Deinit();
protected abstract void Init();
protected abstract void Main();
protected abstract void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
#endregion
#region public resource generator
@@ -191,6 +206,8 @@ namespace StgSharp.Graphics
protected abstract Shader CreateShaderSegment(ShaderType type, int count);
protected abstract ShaderProgram CreateShaderProgram();
#endregion
}
@@ -36,7 +36,7 @@ namespace StgSharp.Graphics.ShaderEdit
public unsafe void SetAllUniforms()
{
GLcontext* gl = GL.api;
GLcontext* gl = (GLcontext*) GL.CurrentContextHandle;
foreach (var uniform in uniformPair)
{
int id = uniform.Key.Value;
@@ -0,0 +1,247 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Blueprint.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;
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
namespace StgSharp.Logic
{
public class Blueprint : IConvertableToBlueprintNode
{
private BeginningNode beginNode;
private Dictionary<string, BlueprintNode> allNode;
private EndingNode endNode;
private Func<bool> terminate;
private int currentNodeIndex = 0;
private List<Task> allThread;
private List<BlueprintNode> nativeNodeList;
private List<BlueprintNode> nodeList;
public Blueprint()
{
allNode = new Dictionary<string, BlueprintNode>();
allThread = new List<Task>();
nodeList = new List<BlueprintNode>();
nativeNodeList = new List<BlueprintNode>();
terminate = () => true;
beginNode = new BeginningNode();
endNode = new EndingNode();
}
public BlueprintNode BeginLayer => beginNode;
public BlueprintNode EndLayer => endNode;
public bool IsRunning => allThread.Any(t => t.Status == TaskStatus.Running);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (string name, BlueprintPipelineArgs arg)[] GetOutput()
{
return endNode.OutputData;
}
public void Init(int threadCount)
{
foreach (var item in allNode)
{
if (item.Value.IsNative)
{
nativeNodeList.Add(item.Value);
}
else
{
nodeList.Add(item.Value);
}
}
nativeNodeList.Sort();
nodeList.Sort();
if (threadCount > nodeList.Count)
{
InternalIO.InternalWriteLog(
"Thread setting error: amount of threads of this blueprint is larger than amount of nodes.", LogType.Warning);
threadCount = nodeList.Count;
}
for (int i = 0; i < threadCount; i++)
{
allThread.Add(new Task(
() =>
{
do
{
try
{
while (true)
{
RequestNextNode().Run();
}
}
catch (NodeClearException) { }
} while (!terminate());
}
));
}
}
/// <summary>
/// Run all nodes repeatedly until it is instructed to terminate.
/// </summary>
/// <param name="terminateInstructor">Instructor to terminate all tasks. Returns <see langword="true"/> if tasks should terminate</param>
public void RunRepeatedly(Func<bool> terminateInstructor)
{
if (allThread.Count != 0)
{
MultiThreadRun(terminateInstructor);
return;
}
SingleThreadRun(terminateInstructor);
}
private void MultiThreadRun(Func<bool> terminateInstructor)
{
if (terminate != terminateInstructor)
{
terminate = terminateInstructor;
if (allThread.Count != 0)
{
foreach (var t in allThread)
{
t.Start();
}
}
}
beginNode.Run();
foreach (var node in nativeNodeList)
{
node.Run();
}
EndLayer.Run();
}
private void SingleThreadRun(Func<bool> terminateInstructor)
{
foreach (var node in nativeNodeList)
{
nodeList.Add(node);
}
nodeList.Sort();
beginNode.Run();
foreach (var item in nodeList)
{
item.Run();
}
EndLayer.Run();
}
public void AddNativeNode(BlueprintNode node)
{
node.IsNative = true;
allNode.Add(node.Name, node);
}
public void AddAsyncNode(BlueprintNode node)
{
node.IsNative = false;
allNode.Add(node.Name, node);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetInput(params (string name, BlueprintPipelineArgs arg)[] parameters)
{
beginNode.InputData = parameters;
}
private BlueprintNode RequestNextNode()
{
if (currentNodeIndex < nodeList.Count)
{
BlueprintNode ret = nodeList[currentNodeIndex];
Interlocked.Increment(ref currentNodeIndex);
return ret;
}
Interlocked.Exchange(ref currentNodeIndex, 0);
throw new NodeClearException();
}
string[] IConvertableToBlueprintNode.InputInterfacesName
{
get
{
return beginNode.OutputInterfaces.Select(
p => p.Key).ToArray();
}
}
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution
{
get
{
return (in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output)
=>
{
beginNode.Run();
foreach (var node in nativeNodeList)
{
node.Run();
}
endNode.Run();
};
}
}
string[] IConvertableToBlueprintNode.OutputInterfacesName
{
get
{
return beginNode.OutputInterfaces.Select(
p => p.Key).ToArray();
}
}
}
internal class NodeClearException : Exception
{
}
}
@@ -0,0 +1,293 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BlueprintNode.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.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
public delegate void BlueprintNodeAction(
in Dictionary<string, BlueprintPipeline> inpput,
in Dictionary<string, BlueprintPipeline> output);
/// <summary>
///
/// </summary>
/// <risk>
/// Reset pipeline has risk, this operation is a direct operation to port
/// in current node, the port on the other node cannot get the change.
/// </risk>
public class BlueprintNode : IComparable<BlueprintNode>
{
private Blueprint local;
private BlueprintNodeAction mainOperation;
private bool levelAvailabel, nativeRequested;
private int level;
private string name;
protected Dictionary<string, BlueprintPipeline> inputInterfaces;
protected Dictionary<string, BlueprintPipeline> outputInterfaces;
internal BlueprintNode(string name,
BlueprintNodeAction operation, bool isNative,
string[] inputPorts,
string[] outputPorts)
{
this.levelAvailabel = false;
this.name = name;
nativeRequested = isNative;
mainOperation = operation;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
if (inputPorts.Length * outputPorts.Length == 0)
{
throw new Exception();
}
foreach (var portName in inputPorts)
{
inputInterfaces.Add(portName, null);
}
foreach (var portName in outputPorts)
{
outputInterfaces.Add(portName, null);
}
}
public BlueprintNode(string name, IConvertableToBlueprintNode convertable)
{
this.levelAvailabel = false;
this.name = name;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
mainOperation = convertable.MainExecution;
foreach (var soket in convertable.InputInterfacesName)
{
inputInterfaces.Add(soket, null);
}
foreach (var soket in convertable.OutputInterfacesName)
{
outputInterfaces.Add(soket, null);
}
}
public BlueprintNode(string name,
string[] inputPorts,
string[] outputPorts
)
{
this.levelAvailabel = false;
this.name = name;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterfaces = new Dictionary<string, BlueprintPipeline>();
if (inputPorts.Length * outputPorts.Length == 0)
{
throw new Exception();
}
foreach (var portName in inputPorts)
{
inputInterfaces.Add(portName, null);
}
foreach (var portName in outputPorts)
{
outputInterfaces.Add(portName, null);
}
}
public bool IsNative
{
get => nativeRequested;
internal set => nativeRequested = value;
}
public int Level
{
get
{
if (levelAvailabel)
{
return level;
}
level = 0;
foreach (var item in inputInterfaces)
{
if (item.Value == null)
{
continue;
}
if (level <= item.Value.Level)
{
level = item.Value.Level;
}
}
level += 1;
return level;
}
}
public string Name => name;
internal Dictionary<string, BlueprintPipeline> InputInterfaces => inputInterfaces;
internal Dictionary<string, BlueprintPipeline> OutputInterfaces => outputInterfaces;
public void AddAfter(
BlueprintNode former,
string formerOutputPortName,
string thisInputPortName)
{
this.levelAvailabel = false;
BlueprintPipeline pipeline = new BlueprintPipeline(former, this);
if (former is BeginningNode bnode)
{
bnode.SetCertainOutputPort(formerOutputPortName, pipeline);
}
else
{
former.SetCertainOutputPort(formerOutputPortName, pipeline);
}
SetCertainInputPort(thisInputPortName, pipeline);
}
public void AddBefore(
BlueprintNode after,
string thisOutputPortName,
string afterInputPortName)
{
this.levelAvailabel = false;
BlueprintPipeline pipeline = new BlueprintPipeline(this, after);
if (after is EndingNode enode)
{
enode.SetCertainInputPort(afterInputPortName, pipeline);
}
else
{
after.SetCertainInputPort(afterInputPortName, pipeline);
}
SetCertainOutputPort(thisOutputPortName, pipeline);
}
public void Run()
{
try
{
BlueprintPipeline.WaitAll(inputInterfaces);
mainOperation(in inputInterfaces, in outputInterfaces);
}
catch (Exception)
{
throw;
}
}
int IComparable<BlueprintNode>.CompareTo(BlueprintNode other)
{
return this.Level.CompareTo(other.Level);
}
#region port operation
public BlueprintPipeline GetCertainInputPort(string name)
{
if (!inputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
return inputInterfaces[name];
}
public BlueprintPipeline GetCertainOutputPort(string name)
{
if (!outputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
return outputInterfaces[name];
}
public void SetCertainInputPort(string name, BlueprintPipeline pipeline)
{
if (!inputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
inputInterfaces[name] = pipeline;
}
public void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
{
if (!outputInterfaces.ContainsKey(name))
{
throw new Exception($"Cannot find the interface named {name} in node {Name}.");
}
outputInterfaces[name] = pipeline;
}
#endregion
}//--------------------------------- end of class -----------------------------
public interface IConvertableToBlueprintNode
{
public string[] InputInterfacesName { get; }
public BlueprintNodeAction MainExecution { get; }
public string[] OutputInterfacesName { get; }
}
public class BlueprintNodeRunException : Exception
{
public BlueprintNodeRunException(Exception ex) : base(string.Empty, ex)
{
}
public BlueprintNodeRunException(string message, Exception ex) : base(message, ex)
{
}
}
}
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
/*
public class CrossCycleProcess:BlueprintNode
{
public CrossCycleProcess(string name, Action operation)
:base()
{
}
}
/**/
}
@@ -0,0 +1,124 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PipeLine.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.Security.Authentication.ExtendedProtection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
public class BlueprintPipeline
{
private BlueprintNode after;
private BlueprintNode former;
private BlueprintPipelineArgs args;
private SemaphoreSlim formerCompleteSemaphore;
public BlueprintPipeline(BlueprintNode former, BlueprintNode after)
{
this.former = former;
this.after = after;
formerCompleteSemaphore = new SemaphoreSlim(initialCount: 0, maxCount: 1);
}
public BlueprintNode After => after;
public BlueprintNode Former => former;
public int Level => former.Level;
public BlueprintPipelineArgs Value
{
get => args;
set => args = value;
}
public void CompleteAndSkip()
{
Console.WriteLine(Former.Name);
Console.WriteLine($"{former.Name}\t->\t{after.Name}\tComplete");
formerCompleteSemaphore.Release();
}
public void CompleteAndWriteData(BlueprintPipelineArgs args)
{
this.args = args;
Console.WriteLine($"{former.Name}\t->\t{after.Name}\tComplete");
formerCompleteSemaphore.Release();
}
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.Name}\t->\t{after.Name}");
formerCompleteSemaphore.Wait();
}
}
public abstract class BlueprintPipelineArgs
{
}
}
@@ -0,0 +1,84 @@
using StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
internal sealed class BeginningNode:BlueprintNode
{
public BeginningNode():base(name : "BeginningNode",null,
true, ["default"], ["default"]
) { }
internal (string name, BlueprintPipelineArgs arg)[] InputData
{
set
{
if (value == null)
{
return;
}
foreach (var parameter in value)
{
OutputInterfaces[parameter.name].Value = parameter.arg;
}
}
}
public new void SetCertainOutputPort(string name, BlueprintPipeline pipeline)
{
if (outputInterfaces.ContainsKey(name))
{
outputInterfaces[name] = pipeline;
}
outputInterfaces.Add(name,pipeline);
}
public new void Run()
{
BlueprintPipeline.SkipAll(outputInterfaces);
}
}
internal sealed class EndingNode : BlueprintNode
{
public EndingNode():base(name:"EndingNode",
operation: (
in Dictionary<string , BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output
) =>
{
},
true, ["default"], ["default"]
) { }
internal (string name, BlueprintPipelineArgs arg)[] OutputData
{
get
{
return InputInterfaces.Select(
key => (key.Key, key.Value.Value) ).
ToArray();
}
}
public new void SetCertainInputPort(string name, BlueprintPipeline pipeline)
{
if (inputInterfaces.ContainsKey(name))
{
inputInterfaces[name] = pipeline;
}
inputInterfaces.Add(name, pipeline);
}
public new void Run()
{
BlueprintPipeline.WaitAll(inputInterfaces);
}
}
}
+17 -15
View File
@@ -36,8 +36,6 @@ using System.Threading;
namespace StgSharp
{
public delegate void TimeSpanRefeshCallback();
/// <summary>
/// A microsecond-accuracy timer. It will refresh every a certain time span.
@@ -48,7 +46,7 @@ namespace StgSharp
private Action<SemaphoreFullException> _frameUpdateMissCallback = null;
private readonly int _maxSpanCount;
private TimeSpanRefeshCallback _refeshCallback;
private Action _refreshCallback;
private SemaphoreSlim _refreshSemaphore = new SemaphoreSlim(0, 1);
private long _spanBegin;
private readonly long _spanLength;
@@ -58,37 +56,38 @@ namespace StgSharp
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <param name="spanMicroSeconds"></param>
/// <param name="provider"></param>
public TimeSpanProvider(long spanLength, TimeSourceProviderBase provider)
public TimeSpanProvider(long spanMicroSeconds, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
_spanLength = spanMicroSeconds;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
_refeshCallback = () => { };
_refreshCallback = new Action(() => { });
}
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span.
/// Length of a single time span is defined in seconds.
/// </summary>
/// <param name="spanLength"></param>
/// <param name="spanSeconds"></param>
/// <param name="provider"></param>
public TimeSpanProvider(double spanLength, TimeSourceProviderBase provider)
public TimeSpanProvider(double spanSeconds, TimeSourceProviderBase provider)
{
_spanLength = (long)(spanLength * 1000L * 1000L);
_spanLength = (long)(spanSeconds * 1000L * 1000L);
_spanBegin = -_spanLength;
_maxSpanCount = int.MaxValue;
provider.AddSubscriber(this);
_subscribed = true;
_refeshCallback = () => { };
_refreshCallback = new Action(() => { });
}
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <param name="maxSpan"></param>
/// <param name="provider"></param>
public TimeSpanProvider(long spanLength, int maxSpan, TimeSourceProviderBase provider)
{
@@ -118,10 +117,10 @@ namespace StgSharp
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
public TimeSpanRefeshCallback SpanRefreshCallback
public Action SpanRefreshCallback
{
get => _refeshCallback;
set => _refeshCallback = value;
get => _refreshCallback;
set => _refreshCallback = value;
}
public void SubscribeToTimeSource(TimeSourceProviderBase serviceHandler)
@@ -147,7 +146,10 @@ namespace StgSharp
timeSpanCount++;
try
{
_refeshCallback();
if (_refreshCallback != null)
{
_refreshCallback();
}
_refreshSemaphore.Release();
}
catch (SemaphoreFullException ex)
+3 -3
View File
@@ -140,7 +140,7 @@ namespace StgSharp.Graphics
cameraAtt.colum2.vec
);
float angle = -r._radius;
Console.WriteLine(angle);
//Console.WriteLine(angle);
Matrix22 rotation = new Matrix22(
Scaler.Cos(angle), -Scaler.Sin(angle),
Scaler.Sin(angle), Scaler.Cos( angle)
@@ -161,7 +161,7 @@ namespace StgSharp.Graphics
cameraAtt.colum1.vec
);
float angle = -r._radius;
Console.WriteLine(angle);
//Console.WriteLine(angle);
Matrix22 rotation = new Matrix22(
Scaler.Cos(angle), -Scaler.Sin(angle),
Scaler.Sin(angle), Scaler.Cos(angle)
@@ -182,7 +182,7 @@ namespace StgSharp.Graphics
cameraAtt.colum2.vec
);
float angle = -r._radius;
Console.WriteLine(angle);
//Console.WriteLine(angle);
Matrix22 rotation = new Matrix22(
Scaler.Cos(angle), -Scaler.Sin(angle),
Scaler.Sin(angle), Scaler.Cos(angle)
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0e01d99e1e84e75ad10fb2549531cf2a303a1304")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+0cd01ed9ddc7e151899218121d69a29650b39b34")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -22,16 +22,16 @@ D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net\Stg
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net\StgSharp\obj\Debug\netstandard2.1\refint\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net\StgSharp\obj\Debug\netstandard2.1\StgSharp.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\.Net\StgSharp\obj\Debug\netstandard2.1\ref\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.deps.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.csproj.AssemblyReference.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.GeneratedMSBuildEditorConfig.editorconfig
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.AssemblyInfoInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.AssemblyInfo.cs
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.csproj.CoreCompileInputs.cache
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.sourcelink.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\refint\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.deps.json
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\bin\Debug\netstandard2.1\StgSharp.xml
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\ref\StgSharp.dll
D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\obj\Debug\netstandard2.1\StgSharp.sourcelink.json
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/f83a130074f9a4a253b83ad3df194f5811b18e95/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/0cd01ed9ddc7e151899218121d69a29650b39b34/*"}}