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
@@ -8,21 +8,22 @@ namespace StgSharp.Controlling.UsrActivity
public struct KeyTrigger: ITrigger,IEquatable<KeyTrigger>
{
public KeyboardKey TargetKey;
private KeyboardKey _targetKey;
private KeyStatus _triggerStat;
int ITrigger.TargetKeyOrButtonID => (int)TargetKey;
public int TargetKeyOrButtonID => (int)_targetKey;
KeyStatus ITrigger.TriggeredStatus => _triggerStat;
public KeyStatus TriggeredStatus => _triggerStat;
public KeyTrigger(KeyboardKey targetKey)
public KeyTrigger(KeyboardKey targetKey, KeyStatus targetStat)
{
this.TargetKey = targetKey;
this._targetKey = targetKey;
this._triggerStat = targetStat;
}
public static bool operator ==(KeyTrigger left, KeyTrigger right)
{
return left._triggerStat == right._triggerStat && left.TargetKey == right.TargetKey;
return left._triggerStat == right._triggerStat && left._targetKey == right._targetKey;
}
public static bool operator !=(KeyTrigger left, KeyTrigger right)
@@ -37,12 +38,12 @@ namespace StgSharp.Controlling.UsrActivity
public override int GetHashCode()
{
return (int)TargetKey + 17 * (int)_triggerStat;
return (int)_targetKey + 17 * (int)_triggerStat;
}
public override string ToString()
{
return $"Key {TargetKey} triggered when {_triggerStat}";
return $"Key {_targetKey} triggered when {_triggerStat}";
}
bool IEquatable<KeyTrigger>.Equals(KeyTrigger other)
+1 -1
View File
@@ -121,7 +121,7 @@ namespace StgSharp
public static void Terminate()
{
MainTimeProvider.Terminate();
MainTimeProvider.StopProvidingTime();
InternalIO.glfwTerminate();
}
+12 -6
View File
@@ -39,19 +39,17 @@ using System.Threading;
namespace StgSharp
{
public partial class StgSharp
public static partial class StgSharp
{
internal static StgSharpTime mainTimeProvider = new StgSharpTime();
internal static StgSharpTime mainTimeProvider;
internal static StgSharpTime MainTimeProvider => mainTimeProvider;
internal static TimeSourceProviderBase MainTimeProvider => mainTimeProvider;
}
public sealed class StgSharpTime : TimeSourceProviderBase
{
private static long accuracy;
private static Stopwatch mainProvider = new Stopwatch();
private static List<TimeSpanProvider> subscriberList = new List<TimeSpanProvider>();
@@ -61,7 +59,7 @@ namespace StgSharp
{
}
public static StgSharpTime OnlyInstance => StgSharp.MainTimeProvider;
public static TimeSourceProviderBase OnlyInstance => StgSharp.MainTimeProvider;
public override sealed void StartProvidingTime()
{
@@ -111,6 +109,14 @@ namespace StgSharp
subscriberList.Remove(subscriber);
}
public override void StopProvidingTime()
{
lock (mainProvider)
{
mainProvider.Stop();
}
}
private void ProvideTime()
{
long totalMS, internalFrequncy = Stopwatch.Frequency;
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Graphics
{
public static class ImageProcessor
{
public static void Resize(Image i, int width, int height, ImageMovement move)
{
if (i == null)
{
throw new ArgumentNullException(nameof(i));
}
Array.Resize(ref i.data, width * height * i.ChannelCount);
i.Height = height;
i.Width = width;
switch (move)
{
case ImageMovement.Discard:
break;
case ImageMovement.Top:
break;
default:
throw new NotSupportedException("Invalid or not supported data remanence");
}
}
}
[Flags]
public enum ImageMovement
{
#pragma warning disable CA1008
Discard = 0,
#pragma warning restore CA1008
Top = 1,
Bottom = 2,
Left = 4,
Right = 8,
TopLeft = Top | Left,
BottomLeft = Bottom | Left,
TopRight = Top | Right,
BottomRight = Bottom | Right,
}
}
@@ -278,7 +278,7 @@ namespace StgSharp.Graphics
double virtualCursorPosX, virtualCursorPosY;
bool rawMouseMotion;
// _GLFWcontext context; // 根据_GLFWcontext的定义转换
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
// Callbacks are represented as IntPtr since we don't need the actual function pointers in C#
internal struct Callbacks
@@ -71,6 +71,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Load an <see cref="Image"/> to certain texture.
/// </summary>
/// <param name="index"> </param>
/// <param name="i"> </param>
@@ -224,7 +224,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Link the shader to current context.
/// Link the shader to current viewPortDisplay.
/// </summary>
public unsafe void Link()
{
@@ -247,7 +247,7 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Let the current context use this shader.
/// Let the current viewPortDisplay use this shader.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Use()
@@ -56,9 +56,9 @@ namespace StgSharp.Graphics.GL
private static string glExtensionList;
/// <summary>
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> context.
/// Load all supported OpenGL APIs and bind them to given <see cref="ViewPort"/> viewPortDisplay.
/// </summary>
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL context</param>
/// <param name="vp">The <see cref="ViewPort"/> used as current OpenGL viewPortDisplay</param>
public static unsafe void LoadGLapi(this ViewPort vp)
{
GLcontext* context = (GLcontext*)vp.GraphicHandle;
@@ -56,11 +56,11 @@ namespace StgSharp.Graphics.GL
}
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
/// current form as current OpenGL context.
/// Init an OpenGl viewPortDisplay if current form has not been binded to any viewPortDisplay. and set the viewPortDisplay binded to
/// current form as current OpenGL viewPortDisplay.
/// </summary>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
/// Something goes wrong and StgSharp fails in creating a new OpenGL viewPortDisplay.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
@@ -73,7 +73,6 @@ namespace StgSharp.Graphics.GL
if (glFunc.CurrentContextHandle != ContextHandle)
{
glFunc.CurrentContextHandle = ContextHandle;
//Console.WriteLine($"context set as {(ulong)glFunc.CurrentContextHandle}");
InternalIO.glfwMakeContextCurrent(CanvasHandle);
}
}
@@ -89,7 +88,6 @@ namespace StgSharp.Graphics.GL
in Dictionary<string, BlueprintPipeline> output)
{
MakeAsCurrentContext();
ProcessInput();
Main(in input, in output);
}
+29 -20
View File
@@ -45,6 +45,7 @@ namespace StgSharp.Graphics
{
public class Image : ISSDSerializable, IImageProvider
{
internal byte[] data;
internal ImageInfo info;
@@ -55,27 +56,40 @@ namespace StgSharp.Graphics
//int length = info.width * info.height * info.channel;
}
public ref byte[] DataStream
{
get => ref data;
}
public unsafe Image()
{
info = new ImageInfo();
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height => info.Height;
public ref byte[] DataStream
{
get => ref data;
}
public (int width, int height) Size
{
get => (info.Width, info.Height);
}
public ImageChannel Channel => info.Channel;
public int ChannelCount => info.ChannelCount;
public int Height
{
get => info.Height;
internal set => info.Height = value;
}
public int Width
{
get => info.Width;
internal set => info.Width = value;
}
public SerializableTypeCode SSDTypeCode => SerializableTypeCode.PixelImage;
public int Width => info.Width;
public void FromBytes(byte[] stream)
{
}
public static unsafe Image FromFile(string route, ImageLoader loader)
{
@@ -139,11 +153,6 @@ namespace StgSharp.Graphics
return data;
}
public void FromBytes(byte[] stream)
{
}
public Image ProvideImage()
{
throw new NotImplementedException();
@@ -219,12 +228,6 @@ namespace StgSharp.Graphics
set => height = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public int StreamSize
{
get => width * height * channelCount;
@@ -236,6 +239,12 @@ namespace StgSharp.Graphics
set => width = value;
}
public IntPtr StreamPtr
{
get => pixelPtr;
internal set => pixelPtr = value;
}
public override string ToString()
{
return $"{channel}\t{width}\t{height}\t{(ulong)StreamPtr}";
+54 -91
View File
@@ -45,51 +45,17 @@ namespace StgSharp.Graphics
{
public abstract class RenderStream : IConvertableToBlueprintNode
{
private ViewPort primeArgs;
private protected (int x, int y, int z) _coordStretch;
private Camera nativeCamera;
public ViewPort Port => primeArgs;
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
private IntPtr monitor;
private IntPtr sharedCanvas;
private ViewPort primeArgs;
internal TimeSpanProvider timeProvider;
/*
protected RenderStream(View v, bool isSharing)
{
if (v == null)
{
throw new ArgumentNullException(nameof(v));
}
if (isSharing)
{
primeArgs = v;
}
else
{
View? newArgs = args.Clone() as View;
primeArgs = newArgs;
}
monitor = args.Monitor;
_coordStretch = args.UnitCubeSize;
NativeCamera = new Camera();
}
/**/
public RenderStream(ViewPort v, (int,int,int) unitCubeSize)
public RenderStream(ViewPort v, (int, int, int) unitCubeSize)
{
if (v == null)
{
@@ -97,48 +63,8 @@ namespace StgSharp.Graphics
}
primeArgs = v;
monitor = v!.Monitor;
_coordStretch = unitCubeSize;
NativeCamera = new Camera();
}
public FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
}
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public int Height
{
get => primeArgs.Height;
internal set
{
primeArgs.Height = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
}
public IntPtr Monitor
{
get => monitor;
internal set => monitor = value;
}
public string Name
{
get => primeArgs.Name;
}
public IntPtr SharedCanvas
{
get => sharedCanvas;
internal set => sharedCanvas = value;
nativeCamera = new Camera();
}
public (int width, int height) Size
@@ -152,14 +78,55 @@ namespace StgSharp.Graphics
}
}
public string[] InputInterfacesName => InputPortsName;
public string[] OutputInterfacesName => OutputPortsName;
public FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(CanvasHandle, handlerPtr);
}
}
public int Height
{
get => primeArgs.Height;
internal set { primeArgs.Height = value; }
}
public int Width
{
get => primeArgs.Width;
internal set
{
primeArgs.Width = value;
InternalIO.glfwSetWindowSize(this.CanvasHandle, Width, Height);
}
internal set { primeArgs.Width = value; }
}
public IntPtr Monitor
{
get => primeArgs.Monitor;
internal set => primeArgs.Monitor = value;
}
public string Name
{
get => primeArgs.Name;
}
public vec2d GlobalCoordSize => ((Width * 1.0f) / _coordStretch.x, (Height * 1.0f) / _coordStretch.y);
public ViewPort Port => primeArgs;
internal IntPtr CanvasHandle { get => primeArgs.ViewPortID; }
internal IntPtr ContextHandle
{
get => primeArgs.GraphicHandle;
private protected set => primeArgs.GraphicHandle = value;
}
protected internal Camera NativeCamera
@@ -200,7 +167,9 @@ namespace StgSharp.Graphics
where TSource : RenderStream
where TTarget : RenderStream
{
TTarget target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
#nullable enable
TTarget? target = Activator.CreateInstance(typeof(TTarget), source.primeArgs, source._coordStretch) as TTarget;
#nullable restore
if (target == null)
{
throw new InvalidOperationException(
@@ -208,17 +177,12 @@ namespace StgSharp.Graphics
);
}
target.timeProvider = source.timeProvider;
target.Init();
target.InternalInit();
return target;
}
string[] IConvertableToBlueprintNode.InputInterfacesName => InputPortsName;
BlueprintNodeAction IConvertableToBlueprintNode.MainExecution => InternalDraw;
string[] IConvertableToBlueprintNode.OutputInterfacesName => OutputPortsName;
#region native camera operation
protected abstract void NativeCameraViewRange(Radius fieldOfRange, vec2d offset, (float frontDepth, float backDepth) viewDepth);
protected abstract void NativeCameraViewTarget(vec3d position, vec3d direction, vec3d up);
@@ -251,7 +215,6 @@ namespace StgSharp.Graphics
protected abstract void Main(
in Dictionary<string, BlueprintPipeline> input,
in Dictionary<string, BlueprintPipeline> output);
protected abstract void ProcessInput();
#endregion
@@ -12,15 +12,15 @@ namespace StgSharp.Graphics
{
public TexturePipeline(Image i)
{
value = i;
_value = i;
}
private Image value;
private Image _value;
public Image Value
public new Image Value
{
get => value;
set => value = value ?? throw new ArgumentNullException(nameof(value));
get => _value;
set => _value = value ?? throw new ArgumentNullException(nameof(value));
}
}
}
+15 -44
View File
@@ -49,22 +49,15 @@ namespace StgSharp.Graphics
public unsafe partial class View
{
private (int w, int h) sizeCache;
private (int x, int y, int z) unitCubeSize;
private ViewPort context;
private ViewPortDesigner design;
public ViewPort Port
{
get => context;
}
public View(ViewPort vp, ViewPortDesigner design)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = (1, 1, 1);
localLogic = new Logic.Blueprint();
this.design = design;
@@ -74,30 +67,27 @@ namespace StgSharp.Graphics
public View(ViewPort vp, ViewPortDesigner design, (int, int, int) cubeSize)
{
context = vp;
sizeCache = (0, 0);
unitCubeSize = cubeSize;
localLogic = new Logic.Blueprint();
}
public (int x, int y, int z) UnitCubeSize
{
get => unitCubeSize;
}
public bool Activated { get; internal set; }
public int Height
{
get
{
if (context.Height != sizeCache.h)
{
sizeCache.h = context.Height;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.h = value;
context.Height = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
get => context.Height;
internal set { context.Height = value; }
}
public int Width
{
get => context.Width;
internal set { context.Width = value; }
}
public IntPtr Monitor => context.Monitor;
@@ -108,28 +98,9 @@ namespace StgSharp.Graphics
public string SelfName { get; set; }
public (int x, int y, int z) UnitCubeSize
public ViewPort Port
{
get => unitCubeSize;
}
public int Width
{
get
{
if (context.Width != sizeCache.w)
{
sizeCache.w = context.Width;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
return sizeCache.h;
}
internal set
{
sizeCache.w = value;
context.Width = value;
InternalIO.glfwSetWindowSize(ViewHandle, context.Height, context.Width);
}
get => context;
}
}
+98 -22
View File
@@ -1,7 +1,38 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ViewPort.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.Math;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Threading;
@@ -10,37 +41,82 @@ namespace StgSharp.Graphics
{
public class ViewPort
{
public int Width { get; set; }
public int Height { get; set; }
private int _width, _height;
public string Name { get; set; }
internal ViewPort()
{
_height = 800;
_width = 600;
Name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
Monitor = IntPtr.Zero;
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
if (ViewPortID == IntPtr.Zero)
{
throw new InvalidOperationException("Unable to create viewport handle.");
}
}
public ViewPort(vec2d size, string name, IntPtr monitor)
{
_width = (int)size.X;
_height = (int)size.Y;
Name = name;
Monitor = monitor;
ViewPortID = InternalIO.glfwCreateWindow(_width, _height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
if (ViewPortID == IntPtr.Zero)
{
throw new InvalidOperationException("Unable to create viewport handle.");
}
}
public unsafe int Height
{
get
{
return _height;
}
set
{
InternalIO.glfwSetWindowSize(this.ViewPortID, _width, value);
}
}
public unsafe int Width
{
get
{
return _width;
}
set
{
InternalIO.glfwSetWindowSize(this.ViewPortID, value, _height);
}
}
public IntPtr GraphicHandle { get; internal set; }
public IntPtr Monitor { get; internal set; }
public IntPtr ViewPortID { get; private set; }
public IntPtr GraphicHandle { get; internal set; }
internal ViewPort()
public string Name { get; set; }
public void Close()
{
Height = 800;
Width = 600;
Name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
Monitor = IntPtr.Zero;
ViewPortID = InternalIO.glfwCreateWindow(Width,Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
InternalIO.glfwSetWindowShouldClose(this.ViewPortID,1);
}
public ViewPort(vec2d size,string name, IntPtr monitor)
internal unsafe void FlushSize()
{
Height = (int) size.Y;
Width = (int) size.X;
Name = name;
Monitor = monitor;
ViewPortID = InternalIO.glfwCreateWindow(Width, Height,
Encoding.UTF8.GetBytes(Name), Monitor, IntPtr.Zero
);
fixed (int* wptr = &_width, hptr = &_height)
{
InternalIO.glfwGetWindowSize(ViewPortID, wptr, hptr);
}
}
}
}
@@ -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;
}
}
}
@@ -208,10 +208,5 @@ namespace StgSharp.Stg
VertexArray.BindNull();
}
protected override void ProcessInput()
{
throw new NotImplementedException();
}
}
}
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Release")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c0093f7b5c77291172cde7e3e38beabb126adf08")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+be6c2e6b92a328d0b68af669d50e92dd9bbff42b")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]