[Internal] Seperate InternalIO into different static classes. [Matrix] Fix logic error of compute model.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="InternalIO"
|
||||
// file="DefaultLog"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
@@ -25,62 +25,37 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
internal static unsafe partial class DefaultLog
|
||||
{
|
||||
|
||||
private const long MaxLogFileSize = 10 * 1024 * 1024; // 10 MB
|
||||
|
||||
internal const string NativeLibName =
|
||||
"StgSharp.Native";
|
||||
|
||||
internal const string SS_errorLog =
|
||||
"SS_errorlog.log";
|
||||
|
||||
private static LogType _currentLogLevel = LogType.Info;
|
||||
|
||||
internal static Dictionary<TypeCode, uint> GLtype = [];
|
||||
|
||||
internal static readonly GCHandle ssc_logHandle =
|
||||
GCHandle.Alloc(new byte[512], GCHandleType.Pinned);
|
||||
|
||||
internal static IntPtr _nativeLibPtr = IntPtr.Zero;
|
||||
|
||||
internal static SemaphoreSlim logSyncSemaphore = new(1, 1);
|
||||
|
||||
static InternalIO()
|
||||
{
|
||||
GLtype.Add(TypeCode.Single, glConst.FLOAT);
|
||||
GLtype.Add(TypeCode.Int32, glConst.INT);
|
||||
GLtype.Add(TypeCode.UInt32, glConst.UNSIGNED_INT);
|
||||
GLtype.Add(TypeCode.Int16, glConst.SHORT);
|
||||
GLtype.Add(TypeCode.UInt16, glConst.UNSIGNED_SHORT);
|
||||
GLtype.Add(TypeCode.SByte, glConst.BYTE);
|
||||
GLtype.Add(TypeCode.Byte, glConst.UNSIGNED_BYTE);
|
||||
}
|
||||
|
||||
internal static void InternalAppendLog(string log)
|
||||
{
|
||||
if (!File.Exists(SS_errorLog))
|
||||
if (!File.Exists(Native.LogPath))
|
||||
{
|
||||
FileStream stream = File.Create(SS_errorLog);
|
||||
FileStream stream = File.Create(Native.LogPath);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog)) {
|
||||
using (StreamWriter logStream = File.AppendText(Native.LogPath)) {
|
||||
logStream.WriteLine(log);
|
||||
}
|
||||
}
|
||||
@@ -96,32 +71,32 @@ namespace StgSharp.Internal
|
||||
{
|
||||
RotateLogFile();
|
||||
|
||||
if (!File.Exists(SS_errorLog))
|
||||
if (!File.Exists(Native.LogPath))
|
||||
{
|
||||
FileStream stream = File.Create(SS_errorLog);
|
||||
FileStream stream = File.Create(Native.LogPath);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog)) {
|
||||
using (StreamWriter logStream = File.AppendText(Native.LogPath)) {
|
||||
logStream.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{logType}] {logLine}");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
logSyncSemaphore.Release();
|
||||
_ = logSyncSemaphore.Release();
|
||||
}
|
||||
}
|
||||
|
||||
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
|
||||
{
|
||||
logSyncSemaphore.Wait();
|
||||
if (!File.Exists(SS_errorLog))
|
||||
if (!File.Exists(Native.LogPath))
|
||||
{
|
||||
FileStream stream = File.Create(SS_errorLog);
|
||||
FileStream stream = File.Create(Native.LogPath);
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
using (StreamWriter logStream = File.AppendText(SS_errorLog))
|
||||
using (StreamWriter logStream = File.AppendText(Native.LogPath))
|
||||
{
|
||||
logStream.WriteLine(beforeTime);
|
||||
logStream.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] [{logType}] {logLine}");
|
||||
@@ -136,13 +111,13 @@ namespace StgSharp.Internal
|
||||
|
||||
private static void RotateLogFile()
|
||||
{
|
||||
if (File.Exists(SS_errorLog) && new FileInfo(SS_errorLog).Length > MaxLogFileSize)
|
||||
if (File.Exists(Native.LogPath) && new FileInfo(Native.LogPath).Length > MaxLogFileSize)
|
||||
{
|
||||
string backupFile = SS_errorLog + ".backup";
|
||||
string backupFile = Native.LogPath + ".backup";
|
||||
if (File.Exists(backupFile)) {
|
||||
File.Delete(backupFile);
|
||||
}
|
||||
File.Move(SS_errorLog, backupFile);
|
||||
File.Move(Native.LogPath, backupFile);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-10
@@ -31,7 +31,7 @@ using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal partial class InternalIO
|
||||
internal static class BuiltInShader
|
||||
{
|
||||
|
||||
#region ControllingItemRender
|
||||
@@ -46,9 +46,7 @@ namespace StgSharp.Internal
|
||||
|
||||
#region CollisionTexture
|
||||
|
||||
internal static ReadOnlySpan<byte> CollisionTextureVertexShader
|
||||
{
|
||||
get => """
|
||||
internal static ReadOnlySpan<byte> CollisionTextureVertexShader => """
|
||||
#version 430 core
|
||||
layout(location = 0) in vec2 localCollisionCoord;
|
||||
layout(location = 1) in vec2 spaceCoord;
|
||||
@@ -75,11 +73,8 @@ namespace StgSharp.Internal
|
||||
gl_Position = vec4(angle, realCoord.y, dist, 1);
|
||||
}
|
||||
"""u8;
|
||||
}
|
||||
|
||||
internal static ReadOnlySpan<byte> CollisionTextureFragmentShader
|
||||
{
|
||||
get => """
|
||||
internal static ReadOnlySpan<byte> CollisionTextureFragmentShader => """
|
||||
#version 430 core
|
||||
out vec4 Color;
|
||||
|
||||
@@ -96,8 +91,7 @@ namespace StgSharp.Internal
|
||||
Color = vec4(dist,0,0,1);
|
||||
}
|
||||
"""u8;
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -32,14 +32,26 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal partial class InternalIO
|
||||
internal static partial class GraphicFramework
|
||||
{
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "glCheckShaderStat")]
|
||||
internal static uint[] GLtype = [];
|
||||
|
||||
static GraphicFramework()
|
||||
{
|
||||
GLtype[(int)TypeCode.Single] = glConst.FLOAT;
|
||||
GLtype[(int)TypeCode.Int32] = glConst.INT;
|
||||
GLtype[(int)TypeCode.UInt32] = glConst.UNSIGNED_INT;
|
||||
GLtype[(int)TypeCode.Int16] = glConst.SHORT;
|
||||
GLtype[(int)TypeCode.UInt16] = glConst.UNSIGNED_SHORT;
|
||||
GLtype[(int)TypeCode.SByte] = glConst.BYTE;
|
||||
GLtype[(int)TypeCode.Byte] = glConst.UNSIGNED_BYTE;
|
||||
}
|
||||
|
||||
[LibraryImport(Native.LibName, EntryPoint = "glCheckShaderStat")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
#pragma warning disable CA5392
|
||||
internal static partial int glCheckShaderStatus(
|
||||
@@ -52,27 +64,27 @@ namespace StgSharp.Internal
|
||||
|
||||
#region ssgc api define
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "initGL")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "initGL")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static partial void InternalInitGL(int majorVersion, int minorVersion);
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "loadGlfuncDefault", StringMarshalling = StringMarshalling.Utf8)]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "loadGlfuncDefault", StringMarshalling = StringMarshalling.Utf8)]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static partial IntPtr InternalLoadGlfuncDefault(string name);
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "linkShaderProgram")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "linkShaderProgram")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static unsafe partial uint InternalLinkShaderProgram(OpenglContext* context, uint shaderProgram);
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "readLog")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "readLog")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static unsafe partial IntPtr InternalReadSSCLog();
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "loadImageData", StringMarshalling = StringMarshalling.Utf8)]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "loadImageData", StringMarshalling = StringMarshalling.Utf8)]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static unsafe partial void InternalLoadImage(string fileName, ImageInfo* output, ImageLoader loader);
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "unloadImageData")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "unloadImageData")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
internal static unsafe partial void InternalUnloadImage(ImageInfo* output);
|
||||
|
||||
@@ -25,24 +25,21 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal unsafe partial class InternalIO
|
||||
internal static unsafe partial class GraphicFramework
|
||||
{
|
||||
|
||||
private static readonly GLFWFunction _glfw = new GLFWFunction();
|
||||
|
||||
public static GLFWFunction glfwContext => _glfw;
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "load_glfw_functions")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "load_glfw_functions")]
|
||||
internal static unsafe partial void glfwLoadLibrary(GLFWFunction* context);
|
||||
|
||||
internal static unsafe void LoadGlfw()
|
||||
@@ -116,14 +113,14 @@ namespace StgSharp.Internal
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void glfwGetMonitorWorkarea(
|
||||
internal static unsafe void glfwGetMonitorWorkArea(
|
||||
IntPtr monitor,
|
||||
int* xpos,
|
||||
int* ypos,
|
||||
int* xPos,
|
||||
int* yPos,
|
||||
int* width,
|
||||
int* height)
|
||||
{
|
||||
_glfw.glfwGetMonitorWorkarea(monitor, xpos, ypos, width, height);
|
||||
_glfw.glfwGetMonitorWorkarea(monitor, xPos, yPos, width, height);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -275,12 +272,12 @@ namespace StgSharp.Internal
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe void glfwSetWindowSizeLimits(
|
||||
IntPtr window,
|
||||
int minwidth,
|
||||
int minheight,
|
||||
int maxwidth,
|
||||
int maxheight)
|
||||
int minWidth,
|
||||
int minHeight,
|
||||
int maxWidth,
|
||||
int maxHeight)
|
||||
{
|
||||
_glfw.glfwSetWindowSizeLimits(window, minwidth, minheight, maxwidth, maxheight);
|
||||
_glfw.glfwSetWindowSizeLimits(window, minWidth, minHeight, maxWidth, maxHeight);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -799,6 +796,12 @@ namespace StgSharp.Internal
|
||||
return glfwGetProcAddress(Encoding.UTF8.GetBytes(procName));
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe IntPtr glfwGetProcAddress(ReadOnlySpan<byte> procName)
|
||||
{
|
||||
return glfwGetProcAddress(procName);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
internal static unsafe IntPtr glfwGetProcAddress(Span<byte> procName)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ using System.Runtime.InteropServices;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal static unsafe partial class InternalIO
|
||||
internal static unsafe partial class NativeIntrinsic
|
||||
{
|
||||
|
||||
private static readonly IntrinsicContext _intrinsicContext = new();
|
||||
@@ -68,7 +68,7 @@ namespace StgSharp.Internal
|
||||
}
|
||||
}
|
||||
|
||||
[LibraryImport(NativeLibName, EntryPoint = "load_intrinsic_function")]
|
||||
[LibraryImport(Native.LibName, EntryPoint = "load_intrinsic_function")]
|
||||
[UnmanagedCallConv(CallConvs =[ typeof(CallConvCdecl) ])]
|
||||
private static partial int LoadIntrinsicFunction(IntrinsicContext* context);
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="Native"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. 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.Tasks;
|
||||
|
||||
namespace StgSharp.Internal
|
||||
{
|
||||
internal static unsafe partial class Native
|
||||
{
|
||||
|
||||
internal const string LibName =
|
||||
"StgSharp.Native";
|
||||
|
||||
internal const string LogPath =
|
||||
"SS_error.log";
|
||||
|
||||
internal static IntPtr _libPtr = IntPtr.Zero;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
@@ -55,7 +56,7 @@ namespace StgSharp.Internal
|
||||
#region GLFW3 struct
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct GLFWcontext
|
||||
public unsafe struct glfwContext
|
||||
{
|
||||
|
||||
private delegate*<byte*> extensionSupported;
|
||||
@@ -286,8 +287,8 @@ namespace StgSharp.Internal
|
||||
private IntPtr cursor; // _GLFWcursor* cursor;
|
||||
// glfwVideomode videoMode; // 根据GLFWvidmode的定义转换
|
||||
private IntPtr monitor; // _GLFWmonitor* monitor;
|
||||
public fixed byte keys[glConst.GLFW_KEY_LAST + 1];
|
||||
public fixed byte mouseButtons[glConst.GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
public fixed byte keys[Constant.GLFW_KEY_LAST + 1];
|
||||
public fixed byte mouseButtons[Constant.GLFW_MOUSE_BUTTON_LAST + 1];
|
||||
|
||||
// _GLFWcontext viewPortDisplay; // 根据_GLFWcontext的定义转换
|
||||
|
||||
@@ -496,8 +497,8 @@ namespace StgSharp.Internal
|
||||
internal unsafe struct GLFWlibrary
|
||||
{
|
||||
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = glConst.GLFW_JOYSTICK_LAST + 1)]
|
||||
private GLFWjoystick[] joysticks = new GLFWjoystick[glConst.GLFW_JOYSTICK_LAST + 1];
|
||||
[MarshalAs(UnmanagedType.ByValArray, SizeConst = Constant.GLFW_JOYSTICK_LAST + 1)]
|
||||
private GLFWjoystick[] joysticks = new GLFWjoystick[Constant.GLFW_JOYSTICK_LAST + 1];
|
||||
|
||||
private GLFWallocator allocator;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
// file="publicType"
|
||||
// file="public"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload
|
||||
// Copyright (c) Nitload. All rights reserved.
|
||||
@@ -25,12 +25,11 @@
|
||||
//
|
||||
// -----------------------------------------------------------------------
|
||||
// -----------------------------------------------------------------------
|
||||
using StgSharp.Graphics.OpenGL;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp
|
||||
{
|
||||
@@ -44,4 +43,4 @@ namespace StgSharp
|
||||
InfoWarning,
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user