daily update on 20240901 by nitload youmu

This commit is contained in:
Nitload
2024-09-02 05:57:07 +08:00
parent 1ee4e4a42f
commit 0979123ac0
47 changed files with 869 additions and 707 deletions
@@ -0,0 +1,62 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="OpenGLControllingItemRender.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.OpenGL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.MVVM
{
public class OpenGLControllingItemRender : glRender
{
public override bool IsContextSharable => true;
protected override void CustomizeDeinit()
{
throw new NotImplementedException();
}
protected override void CustomizeInit()
{
throw new NotImplementedException();
}
protected override void Main()
{
throw new NotImplementedException();
}
}
}
+9 -3
View File
@@ -44,6 +44,7 @@ using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
using System.Diagnostics.CodeAnalysis;
namespace StgSharp.MVVM.View
{
@@ -61,7 +62,7 @@ namespace StgSharp.MVVM.View
private GetDataBindingEntryDelegate getDataBindingEntry;
private int usedFrame = 0;
private int usedFrame;
private IViewDesigner<ViewBase> _design;
private IViewRender<ViewBase> _render;
private IViewResponder<ViewBase> _responder;
@@ -87,6 +88,11 @@ namespace StgSharp.MVVM.View
}
}
internal bool IsWaitingWindowEvent
{
get => context.IsWaitingEvent;
}
public (int x, int y, int z) UnitCubeSize
{
get => unitCubeSize;
@@ -142,7 +148,7 @@ namespace StgSharp.MVVM.View
set => _responder = value;
}
public abstract void CustomizedInitialize(ViewModelBase viewModelBinding);
public abstract void CustomizedInitialize([NotNull]ViewModelBase viewModelBinding);
/// <summary>
/// Get the status of a certain key on the keyboard.
@@ -155,7 +161,7 @@ namespace StgSharp.MVVM.View
return InternalIO.glfwGetKey(context.ViewPortID, (int)key);
}
public void InternalInitialize(string name, (int, int, int) cubeSize, ViewModelBase viewModelBinding)
public void InternalInitialize(string name, (int, int, int) cubeSize, [NotNull]ViewModelBase viewModelBinding)
{
SelfName = name;
unitCubeSize = cubeSize;
@@ -28,13 +28,16 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Data;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
@@ -45,10 +48,40 @@ namespace StgSharp.MVVM.ViewModel
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate ref object BindingDataGetter();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void BindingDataSetter(ref object value);
public abstract partial class ViewModelBase
{
public bool MethodLookup(string methodName, out Action callback)
{
MethodInfo method = GetType().GetMethod(methodName);
try
{
callback = (Action)Delegate.CreateDelegate(typeof(Action), this, methodName);
return true;
}
catch (MissingMethodException)
{
callback = null!;
return false;
}
catch (MethodAccessException)
{
callback = null!;
return false;
}
catch (Exception)
{
throw;
}
}
}
[StructLayout(LayoutKind.Explicit)]
public unsafe struct DataBindingEntry
{
private IntPtr getterPtr, setterPtr;
[FieldOffset(0)] private M128 _mask;
[FieldOffset(0)] private IntPtr getterPtr;
[FieldOffset(8)] private IntPtr setterPtr;
public DataBindingEntry(
[NotNull] BindingDataGetter gettingCallback,
@@ -73,11 +106,39 @@ namespace StgSharp.MVVM.ViewModel
return ref ((delegate* unmanaged[Cdecl]<ref object>)getterPtr)();
}
public void SetData(ref object value)
public void SetValue(ref object value)
{
((delegate* unmanaged[Cdecl]<ref object, void>)setterPtr)(ref value);
}
public static bool operator ==(DataBindingEntry left, DataBindingEntry right)
{
return left._mask == right._mask;
}
public static bool operator !=(DataBindingEntry left, DataBindingEntry right)
{
return left._mask != right._mask;
}
public bool Equals(DataBindingEntry other)
{
return (_mask == other._mask);
}
public override bool Equals(object obj)
{
if (obj is not DataBindingEntry other)
{
return false;
}
return Equals(other);
}
public override int GetHashCode()
{
return _mask.GetHashCode();
}
}
#nullable restore
@@ -40,7 +40,6 @@ namespace StgSharp.MVVM.ViewModel
{
public abstract partial class ViewModelBase
{
private ViewBase _nextView, _currentView;
protected ViewBase CurrentView
+31 -11
View File
@@ -77,6 +77,19 @@ namespace StgSharp.MVVM.ViewModel
() =>
{
};
viewPortDisplay.FrameSizeCallback = (handle, width, height)
=>
{
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
OpenGLFunction.CurrentGL.Viewport(0, 0, width, height);
PrivateShow();
};
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
=>
{
PrivateShow();
};
}
protected ViewModelBase(float frameLength)
@@ -95,17 +108,30 @@ namespace StgSharp.MVVM.ViewModel
() =>
{
};
viewPortDisplay.FrameSizeCallback = (handle, width, height)
=>
{
InternalIO.glfwMakeContextCurrent(viewPortDisplay.ViewPortID);
OpenGLFunction.CurrentGL.Viewport(0, 0, width, height);
PrivateShow();
};
viewPortDisplay.FramePostionCallback = (handle, xpos, ypos)
=>
{
PrivateShow();
};
}
public ViewModelBase(ViewPort vbinding, int framespeed)
public ViewModelBase(ViewPort vBinding, int frameSpeed)
{
viewPortDisplay = vbinding;
viewPortDisplay = vBinding;
allView = new();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback = CountFps;
long frameLength = (framespeed > 0) ? ((1000L * 1000L) / framespeed) : 0;
long frameLength = (frameSpeed > 0) ? ((1000L * 1000L) / frameSpeed) : 0;
frameTimeProvider = new TimeSpanProvider(
frameLength, TimeSpanProvider.DefaultProvider
);
@@ -127,9 +153,9 @@ namespace StgSharp.MVVM.ViewModel
};
}
public ViewModelBase(ViewPort vbinding, float frameLength)
public ViewModelBase(ViewPort vBinding, float frameLength)
{
viewPortDisplay = vbinding;
viewPortDisplay = vBinding;
allView = new();
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
@@ -251,12 +277,6 @@ namespace StgSharp.MVVM.ViewModel
public abstract void CustomizeInitialize();
public Action MethodLookup(string methodName)
{
MethodInfo method = GetType().GetMethod(methodName);
return (method != null) ? ((Action)Delegate.CreateDelegate(typeof(Action), this, method)) : null;
}
/// <summary>
/// Resize the current form
/// </summary>
+14 -1
View File
@@ -43,7 +43,6 @@ namespace StgSharp.MVVM
{
public class ViewPort
{
private FrameBufferSizeHandler _sizeHandler;
private FramePositionHandler _positionHandler;
private int _width, _height;
@@ -132,5 +131,19 @@ namespace StgSharp.MVVM
}
}
private int _eventWaitingMask;
internal bool IsWaitingEvent
{
get => _eventWaitingMask == 1;
}
internal unsafe void InternalShowViewModelMain()
{
Interlocked.Exchange(ref _eventWaitingMask, 1);
InternalIO.glfwWaitEvents();
Interlocked.Exchange(ref _eventWaitingMask, 0);
}
}
}