This commit is contained in:
Nitload
2024-06-10 15:12:08 +08:00
parent f6963b8e00
commit be6c2e6b92
305 changed files with 28336 additions and 5938 deletions
-53
View File
@@ -1,53 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Get.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.Controlling;
using StgSharp.Graphics;
using StgSharp.Logic;
using StgSharp.Math;
namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Get the status of a certain key on the keyboard.
/// </summary>
/// <param name="form"></param>
/// <param name="key"></param>
/// <returns></returns>
public static KeyStatus GetKeyStatus(Form form, KeyboardKey key)
{
return InternalIO.glfwGetKey(form.id, (int)key);
}
}
}
File diff suppressed because it is too large Load Diff
-155
View File
@@ -1,155 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="InternalIO.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.Geometries;
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
#if Windows
#endif
namespace StgSharp
{
public enum LogType
{
Error,
Warning,
Info,
InfoError,
InfoWarning,
}
internal static unsafe partial class InternalIO
{
internal const string SS_errorLog =
"SS_errorlog.log";
internal const string SSC_libName =
"StgSharpC";
internal static Dictionary<TypeCode, uint> GLtype =
new Dictionary<TypeCode, uint>();
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
internal static readonly GCHandle ssc_logHandle =
GCHandle.Alloc(new byte[512], GCHandleType.Pinned);
internal static IntPtr SSClibPtr = IntPtr.Zero;
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))
{
FileStream stream = File.Create(SS_errorLog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorLog))
{
logStream.WriteLine(log);
}
}
[Obsolete("Not completed", true)]
internal static IntPtr InternalLoadProc<T>(IntPtr lib, string name) where T : Delegate
{
try
{
IntPtr procPtr =
#if Windows
IntPtr.Zero;
#elif Linux
#endif
return procPtr;
}
catch (Exception)
{
throw;
}
}
internal static void InternalWriteLog(string logLine, LogType logType)
{
logSyncSemaphore.Wait();
if (!File.Exists(SS_errorLog))
{
FileStream stream = File.Create(SS_errorLog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorLog))
{
logStream.WriteLine($"{logType}\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release();
}
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
{
logSyncSemaphore.Wait();
if (!File.Exists(InternalIO.SS_errorLog))
{
FileStream stream = File.Create(InternalIO.SS_errorLog);
stream.Close();
}
using (StreamWriter logStream = File.AppendText(SS_errorLog))
{
logStream.WriteLine(beforeTime);
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
}
}
}
-220
View File
@@ -1,220 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyControl.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using System;
namespace StgSharp
{
public enum KeyboardKey : int
{
UNKNOWN = -1,
None = 0,
SPACE = 32,
APOSTROPHE = 39/*'*/,
COMMA = 44/*,*/,
MINUS = 45/*-*/,
PERIOD = 46/*.*/,
SLASH = 47/*/*/,
ZERO = 48,
ONE = 49,
TWO = 50,
THREE = 51,
FOUR = 52,
FIVE = 53,
SIX = 54,
SEVEN = 55,
EIGHT = 56,
NINE = 57,
SEMICOLON = 59/*,*/,
EQUAL = 61/*=*/,
A = 65,
B = 66,
C = 67,
D = 68,
E = 69,
F = 70,
G = 71,
H = 72,
I = 73,
J = 74,
K = 75,
L = 76,
M = 77,
N = 78,
O = 79,
P = 80,
Q = 81,
R = 82,
S = 83,
T = 84,
U = 85,
V = 86,
W = 87,
X = 88,
Y = 89,
Z = 90,
LeftBracket = 91/*[*/,
BACKSLASH = 92/*\*/,
RightBracket = 93/*]*/,
GraveAccent = 96/*`*/,
World1 = 161/*non-US#1*/,
World2 = 162/*non-US#2*/,
ESCAPE = 256,
ENTER = 257,
TAB = 258,
BACKSPACE = 259,
INSERT = 260,
DELETE = 261,
RIGHT = 262,
LEFT = 263,
DOWN = 264,
UP = 265,
PgUp = 266,
PgDown = 267,
HOME = 268,
END = 269,
CapsLock = 280,
ScrollLock = 281,
NumLock = 282,
PrintScreen = 283,
PAUSE = 284,
F1 = 290,
F2 = 291,
F3 = 292,
F4 = 293,
F5 = 294,
F6 = 295,
F7 = 296,
F8 = 297,
F9 = 298,
F10 = 299,
F11 = 300,
F12 = 301,
F13 = 302,
F14 = 303,
F15 = 304,
F16 = 305,
F17 = 306,
F18 = 307,
F19 = 308,
F20 = 309,
F21 = 310,
F22 = 311,
F23 = 312,
F24 = 313,
F25 = 314,
NumPad0 = 320,
NumPad1 = 321,
NumPad2 = 322,
NumPad3 = 323,
NumPad4 = 324,
NumPad5 = 325,
NumPad6 = 326,
NumPad7 = 327,
NumPad8 = 328,
NumPad9 = 329,
NumPadDec = 330,
NumPadSiv = 331,
NumPadMul = 332,
NumPadSub = 333,
NumPadAdd = 334,
NumPadAnter = 335,
NumPadEqual = 336,
LeftShift = 340,
LeftControl = 341,
LeftAlt = 342,
LeftSuper = 343,
RightShift = 344,
RightControl = 345,
RightAlt = 346,
RightSuper = 347,
Menu = 348
}
#pragma warning disable CA1707
#pragma warning disable CA1712
#pragma warning disable CA1008
[System.Flags]
public enum Joystick : int
{
JOYSTICK_1 = 0,
JOYSTICK_2 = 1,
JOYSTICK_3 = 2,
JOYSTICK_4 = 3,
JOYSTICK_5 = 4,
JOYSTICK_6 = 5,
JOYSTICK_7 = 6,
JOYSTICK_8 = 7,
JOYSTICK_9 = 8,
JOYSTICK_10 = 9,
JOYSTICK_11 = 10,
JOYSTICK_12 = 11,
JOYSTICK_13 = 12,
JOYSTICK_14 = 13,
JOYSTICK_15 = 14,
JOYSTICK_16 = 15,
JOYSTICK_LAST = JOYSTICK_16
}
[System.Flags]
public enum Mouse : int
{
BUTTON_1 = 0,
BUTTON_2 = 1,
BUTTON_3 = 2,
BUTTON_4 = 3,
BUTTON_5 = 4,
BUTTON_6 = 5,
BUTTON_7 = 6,
BUTTON_8 = 7,
BUTTON_LAST = BUTTON_8,
BUTTON_LEFT = BUTTON_1,
BUTTON_RIGHT = BUTTON_2,
BUTTON_MIDDLE = BUTTON_3
}
#pragma warning restore CA1707
#pragma warning restore CA1712
#pragma warning restore CA7008
internal enum InputEquipment
{
Keyboard,
Mouse,
Joystick
}
public enum KeyStatus : int
{
RELEASE = 0,
PRESS = 1
}
}
@@ -1,39 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp
{
[AttributeUsage( AttributeTargets.Method)]
public class KeyEventAttribute:Attribute
{
internal int _keyTarget;
internal int _equipment;
internal int _keyStat;
public KeyEventAttribute(KeyboardKey key ,KeyStatus status)
{
_equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)key;
_keyStat = (int)status;
}
public KeyEventAttribute(Joystick joystick, KeyStatus status)
{
_equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)joystick;
_keyStat = (int)status;
}
public KeyEventAttribute(Mouse mouse, KeyStatus status)
{
_equipment = (int)InputEquipment.Keyboard;
_keyTarget = (int)mouse;
_keyStat = (int)status;
}
}
}
@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class Form
{
Dictionary<KeyboardKey, KeyBoardEvent> keyEventDictionary = new Dictionary<KeyboardKey, KeyBoardEvent>();
internal void InternalLoadInput(MethodInfo[] methods)
{
if (methods.Length == 0)
{
return;
}
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
KeyEventAttribute attr = m.GetCustomAttribute<KeyEventAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
}
}
internal void InternalProcessInput()
{
}
}
public delegate void KeyBoardEvent(KeyboardKey key, KeyStatus status);
public delegate void MouseEvent(Mouse mouse, KeyStatus status);
public delegate void JoystickEvent(Joystick joystick, KeyStatus status);
}
-75
View File
@@ -1,75 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeLine.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.Entities;
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
namespace StgSharp.Controlling
{
internal static partial class TimeLine
{
private static bool isPaused = false;
private static bool renderChainStarted;
internal static TimelineBlock currentOperation;
internal static Queue<Form> formList = new Queue<Form>();
public static TimelineBlock CurrentOperation
{
get => currentOperation;
set
{
if ((currentOperation == default) ||
currentOperation.isComplete)
{
currentOperation = value;
}
}
}
internal static bool RenderStarted => renderChainStarted;
internal static void RenderAll()
{
renderChainStarted = true;
}
}
}
@@ -1,51 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimelineBlock.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Controlling
{
public abstract class TimelineBlock
{
public abstract bool isComplete
{
get;
}
public abstract bool GetShouldComplete();
/*
A virtual method api to define what should program do
in a framecycle, an int value is required to express
the result of the cycle, that if there is any error in the cycle
*/
public abstract int OnUpdating();
}
}
@@ -1,110 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="KeyboardButton.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.Controls;
using StgSharp.Geometries;
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Controls
{
public class KeyboardButton : ControllingItem
{
private PlainGeometryMesh current;
private AnimationBuilder switchAnimationBuilder;
private Action? enableAction;
private Action? disableAction;
private Action? confirmAction;
public bool IsHighLighted { get; internal set; }
public bool IsDisabled { get; internal set; }
public event Action EnableEvent
{
add { enableAction += value; }
remove { enableAction -= value; }
}
public event Action DisableEvent
{
add { disableAction += value; }
remove { disableAction -= value; }
}
public event Action ConfirmEvent
{
add { confirmAction += value; }
remove { confirmAction -= value; }
}
public void Enable(AnimationBuilder animation)
{
if (!IsDisabled)
{
return;
}
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
{
switchAnimationBuilder = animation;
}
if( enableAction != null)enableAction();
}
public void Disable(AnimationBuilder animation)
{
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
{
switchAnimationBuilder = animation;
}
if (disableAction != null) disableAction();
}
public void Highlight(AnimationBuilder animation)
{
if (switchAnimationBuilder.IsComplete || switchAnimationBuilder == null)
{
switchAnimationBuilder = animation;
}
if (confirmAction != null) confirmAction();
}
public override IEnumerator<PlainGeometryMesh> GetEnumerator()
{
current.Texture = switchAnimationBuilder.GetAnimationFrame();
yield return current;
}
}//----------------------------------- End of class --------------------------------------------
}
@@ -1,47 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public partial class ViewModel
{
Dictionary<KeyboardKey, KeyBoardEvent> keyEventDictionary = new Dictionary<KeyboardKey, KeyBoardEvent>();
internal void InternalLoadInput(MethodInfo[] methods)
{
if (methods.Length == 0)
{
return;
}
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
KeyEventAttribute attr = m.GetCustomAttribute<KeyEventAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
}
}
internal void InternalProcessInput()
{
}
}
public delegate void KeyBoardEvent(KeyboardKey key, KeyStatus status);
public delegate void MouseEvent(Mouse mouse, KeyStatus status);
public delegate void JoystickEvent(Joystick joystick, KeyStatus status);
}
@@ -1,100 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="CodeCounter.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.Data;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Data
{
public static class CodeSeparator
{
public static List<(T, ulong)> CountCodeFrequency<T>(T[] rawArray) where T : struct
{
Dictionary<T, ulong> frequencyCollection = new Dictionary<T, ulong>();
foreach (var item in rawArray)
{
if (frequencyCollection.ContainsKey(item))
{
frequencyCollection[item] += 1;
}
else
{
frequencyCollection.Add(item, 1);
}
}
return frequencyCollection.OrderByDescending(pair => pair.Value)
.Select(pair => (pair.Key, pair.Value)).ToList();
}
public static unsafe T[] SeparateCode<T>(string filePath) where T : struct
{
byte[] allByte = File.ReadAllBytes(filePath);
List<T> rawList = new List<T>();
fixed (byte* allBytePtr = allByte)
{
for (int i = 0; i < allByte.Length; i += Marshal.SizeOf<T>())
{
T t = new T();
t = *(T*)(allBytePtr + i);
rawList.Add(t);
}
}
return rawList.ToArray();
}
public static unsafe T[] SeparateCode<T>(byte[] stream) where T : struct
{
List<T> rawList = new List<T>();
fixed (byte* allBytePtr = stream)
{
for (int i = 0; i < stream.Length; i += Marshal.SizeOf<T>())
{
T t = new T();
t = *(T*)(allBytePtr + i);
rawList.Add(t);
}
}
return rawList.ToArray();
}
}
}
@@ -1,82 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EncodStream.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.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Data
{
public class EncodeStream
{
byte[] buffer;
BitArray bufferArray;
byte count;
List<byte> data;
public EncodeStream()
{
count = 0;
buffer = new byte[1];
data = new List<byte>();
bufferArray = new BitArray(8, true);
}
public List<byte> EncodeData
=> data;
public int Length => data.Count;
public string Output => Encoding.UTF8.GetString(data.ToArray());
public void WriteBits<T>(HuffmanKey<T> key) where T : struct
{
BitArray bit = key.GetBitArray();
for (int i = 0; i < bit.Count; i++)
{
if (count == 8)
{
bufferArray.CopyTo(buffer, 0);
data.Add(buffer[0]);
count = 0;
}
bufferArray[count] = bit[i];
count++;
}
}
}
}
-55
View File
@@ -1,55 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Encoder.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.Data;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Data
{
public static class Encode
{
public static void Freeze<T>(
Dictionary<T, HuffmanKey<T>> indexDict
)
where T : struct
{
foreach (var key in indexDict)
{
key.Value.Freeze();
}
}
}
}
@@ -1,237 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="HuffmanTree.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.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Xml;
using System.Xml.Linq;
namespace StgSharp.Data
{
public partial class HuffmanTree<T> where T : struct
{
HuffmanNodeList<T> leaves;
internal HuffmanTree(HuffmanNodeList<T> nodeList)
{
leaves = nodeList;
}
public HuffmanNodeList<T> LeafList
=> leaves;
public TreeNode<T> Root
=> leaves.Last;
public static HuffmanTree<T> BuildHuffmanTree(List<(T, ulong)> metaData)
{
if (metaData.Count <= 3)
{
throw new Exception("Data is too little, no need to compress");
}
HuffmanNodeList<T> leaves = new HuffmanNodeList<T>();
HuffmanNodeList<T> all = new HuffmanNodeList<T>();
foreach (var item in metaData)
{
leaves.Add(new TreeNode<T>(item));
}
while (leaves.Count > 2)
{
TreeNode<T> node, toMove;
if (leaves.Last._frequency < leaves.BeforeLast._frequency)
{
if (leaves.BeforeLast._frequency < leaves.OverLast._frequency)
{
//第三节点最大
node = new TreeNode<T>(leaves.BeforeLast, leaves.Last);
toMove = leaves.RemoveAndGetLast; all.Add(toMove);
toMove = leaves.RemoveAndGetLast; all.Add(toMove);
leaves.Add(node);
}
else
{
//第二节点最大
node = (leaves.Last._frequency < leaves.OverLast._frequency) ?
(new TreeNode<T>(leaves.OverLast, leaves.Last)) :
(new TreeNode<T>(leaves.Last, leaves.OverLast));
toMove = leaves.RemoveAndGetLast; all.Add(toMove);
toMove = leaves.RemoveAndGetBeforeLast; all.Add(toMove);
leaves.Add(node);
}
}
else
{
if (leaves.Last._frequency < leaves.OverLast._frequency)
{
//第三节点最大
node = new TreeNode<T>(leaves.Last, leaves.BeforeLast);
toMove = leaves.RemoveAndGetLast; all.Add(toMove);
toMove = leaves.RemoveAndGetLast; all.Add(toMove);
leaves.Add(node);
}
else
{
//第一节点最大
node = (leaves.BeforeLast._frequency < leaves.OverLast._frequency) ?
(new TreeNode<T>(leaves.OverLast, leaves.BeforeLast)) :
(new TreeNode<T>(leaves.BeforeLast, leaves.OverLast));
toMove = leaves.RemoveAndGetBeforeLast; all.Add(toMove);
toMove = leaves.RemoveAndGetBeforeLast; all.Add(toMove);
leaves.Add(node);
}
}
leaves = new HuffmanNodeList<T>(leaves.OrderByDescending(pair => pair.frequency)
.Select(pair => pair).ToList());
}
TreeNode<T> lastOne = leaves[0];
TreeNode<T> lastTwo = leaves[1];
TreeNode<T> root = (lastOne.frequency > lastTwo.frequency) ?
(new TreeNode<T>(lastOne, lastTwo)) :
(new TreeNode<T>(lastTwo, lastOne));
all.Add(lastOne);
all.Add(lastTwo);
all.Add(root);
leaves = all;
return new HuffmanTree<T>(all);
}
}
public class HuffmanNodeList<T> : List<TreeNode<T>> where T : struct
{
public HuffmanNodeList() : base()
{
}
public HuffmanNodeList(IEnumerable<TreeNode<T>> values) : base(values)
{ }
public TreeNode<T> BeforeLast
=> this[Count - 2];
public TreeNode<T> Last
=> this[Count - 1];
public TreeNode<T> OverLast
=> this[Count - 3];
public TreeNode<T> RemoveAndGetBeforeLast
{
get
{
TreeNode<T> ret = this[Count - 2];
RemoveAt(Count - 2);
return ret;
}
}
public TreeNode<T> RemoveAndGetLast
{
get
{
TreeNode<T> ret = this[Count - 1];
RemoveAt(Count - 1);
return ret;
}
}
public TreeNode<T> RemoveAndGetOverLast
{
get
{
TreeNode<T> ret = this[Count - 3];
RemoveAt(Count - 3);
return ret;
}
}
public void Add(T element, ulong f)
{
base.Add(new TreeNode<T>(element, f));
}
}
public class TreeNode<T> where T : struct
{
internal ulong _frequency;
internal TreeNode<T> _left;
internal TreeNode<T> _right;
internal T? _value;
internal TreeNode(TreeNode<T> left, TreeNode<T> right)
{
_left = left;
_right = right;
_value = null;
_frequency = left._frequency + right._frequency;
}
public TreeNode((T, ulong) data)
{
_value = data.Item1;
_frequency = data.Item2;
}
public TreeNode(T? value, ulong frequncy)
{
_value = value;
_frequency = frequncy;
}
public ulong frequency => _frequency;
public TreeNode<T> Left => _left;
public TreeNode<T> Right => _right;
public T? Value => _value;
}
}
@@ -1,189 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MappingTable.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;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace StgSharp.Data
{
public partial class HuffmanTree<T> where T : struct
{
public Dictionary<T, HuffmanKey<T>> BuildHuffmanDictionary()
{
Dictionary<T, HuffmanKey<T>> ret = new Dictionary<T, HuffmanKey<T>>();
TreeNode<T> root = Root;
HuffmanKey<T> key = new HuffmanKey<T>();
key = key.SetSide(KeySide.Right);
InternalBuildDictionary(ret, root, key);
return ret;
}
public void InternalBuildDictionary(
Dictionary<T, HuffmanKey<T>> dict,
TreeNode<T> node,
HuffmanKey<T> valueTemp
)
{
HuffmanKey<T> nativeNode = new HuffmanKey<T>(valueTemp.bitList);
nativeNode.AddIndexLevel();
//检查左节点
if (node._left.Value == null)
{
//左节点不是叶子节点,继续搜索
InternalBuildDictionary(
dict,
node._left,
nativeNode.SetSide(KeySide.Left));
}
else
{
//左节点是叶子节点,添加值
dict.Add(node._left.Value.Value, nativeNode.SetSide(KeySide.Left));
}
//检查右节点
if (node._right.Value == null)
{
//右节点不是叶子节点,继续搜索
InternalBuildDictionary(
dict,
node._right,
nativeNode.SetSide(KeySide.Right));
}
else
{
//右节点是叶子节点,添加值
dict.Add(node._right.Value.Value, nativeNode.SetSide(KeySide.Right));
}
//这里检查自己是不是叶子节点
//但是上面已经检查过了,不需要被检查
}
}
public class HuffmanKey<T> where T : struct
{
internal List<bool> bitList;
internal BitArray code;
public HuffmanKey()
{
bitList = new List<bool>();
bitList.Add(false);
}
public HuffmanKey(List<bool> former)
{
bitList = new List<bool>(former);
}
public bool IsSupported
{
get
{
return
(typeof(T) == typeof(byte)) ||
(typeof(T) == typeof(uint)) ||
(typeof(T) == typeof(ushort)) ||
(typeof(T) == typeof(ulong)) ||
#if NET7_0_OR_GREATER
typeof(T) == typeof(UInt128) ||
#endif
(typeof(T) == typeof(M128));
}
}
public unsafe void AddIndexLevel()
{
bitList.Add(true);
}
public void Freeze()
{
if (code != null)
{
return;
}
bitList.RemoveAt(0);
code = new BitArray(bitList.ToArray());
}
public BitArray GetBitArray()
{
if (code == null)
{
List<bool> list = new List<bool>(bitList);
list.RemoveAt(0);
return new BitArray(list.ToArray());
}
return code;
}
public unsafe byte[] GetBytes()
{
byte[] bytes = new byte[(bitList.Count / 8) + 1];
BitArray array = new BitArray(bitList.ToArray());
array.CopyTo(bytes, 0);
return bytes;
}
public unsafe HuffmanKey<T> SetSide(KeySide side)
{
HuffmanKey<T> newKey = new HuffmanKey<T>(bitList);
newKey.bitList[newKey.bitList.Count - 1] = side == KeySide.Left;
return newKey;
}
public override string ToString()
{
string str = string.Empty;
foreach (var bit in bitList)
{
str += $"{bit} ";
}
return str;
}
}
public enum KeySide
{
Left,
Right
}
}
@@ -1,46 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Data
{
public partial class Area
{
private static byte leastUnusedDisc;
public byte NewDisc(byte raidWith)
{
byte ret = leastUnusedDisc;
leastUnusedDisc++;
return ret;
}
public void ClearDiscIDBuffer()
{
leastUnusedDisc = 0;
}
private int leastUnusedID;
public int NewID()
{
int ret = leastUnusedID;
if (ret == int.MaxValue)
{
throw new ArgumentOutOfRangeException("Reaches max IDs that one ssd file can provide.");
}
leastUnusedID++;
return ret;
}
public void ClearIDBuffer()
{
leastUnusedID = 1;
}
}
}
@@ -1,161 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BitArray.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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace StgSharp.Data
{
public static partial class Serializer
{
public static void Deserialize(byte[] stream, out BitArray target)
{
List<bool> boolStream = new List<bool>(4 * stream.Length);
int i = 0, count = 0;
foreach (byte b in stream)
{
uint raw = b;
for (i = 0; i < 4; i++)
{
switch (raw & 0b11)
{
case (uint)BoolMap.True_0:
boolStream.Add(true);
break;
case (uint)BoolMap.False_0:
boolStream.Add(false);
break;
case (uint)BoolMap.None_0:
goto end;
default:
throw new Exception();
}
raw >>= 2;
count++;
continue;
end:
{
break;
}
}
}
while (boolStream.Count > count)
{
boolStream.RemoveAt(count);
}
target = new BitArray(boolStream.ToArray());
}
/// <summary>
/// Serialize a <see cref="BitArray"/>, useful when writing
/// a Huffman tree index dictionary to file.
/// </summary>
/// <param name="bits"></param>
/// <returns></returns>
/// <exception cref="Exception"></exception>
public static byte[] Serialize(BitArray bits)
{
int size = (bits.Count / 4) + 1;
List<byte> ret = new List<byte>(size);
int count = 0, total = 0; byte temp = new byte();
for (int i = 0; i < bits.Count; i++)
{
if (count == 4)
{
ret.Add(temp);
count = 0;
temp = 0;
total++;
}
switch (count)
{
case 0:
temp |= (byte)(bits[i] ? BoolMap.True_0 : BoolMap.False_0);
break;
case 1:
temp |= (byte)(bits[i] ? BoolMap.True_1 : BoolMap.False_1);
break;
case 2:
temp |= (byte)(bits[i] ? BoolMap.True_2 : BoolMap.False_2);
break;
case 3:
temp |= (byte)(bits[i] ? BoolMap.True_3 : BoolMap.False_3);
break;
default:
throw new Exception();
}
count++;
}
for (; count < 4; count++)
{
switch (count)
{
case 1:
temp |= (byte)BoolMap.None_1;
break;
case 2:
temp |= (byte)BoolMap.None_2;
break;
case 3:
temp |= (byte)BoolMap.None_3;
break;
default:
throw new Exception();
}
continue;
}
ret.Add(temp);
return ret.ToArray();
}
}
internal enum BoolMap : byte
{
False_0 = 0b00000010,
True_0 = 0b00000001,
None_0 = 0b00000011,
False_1 = 0b00001000,
True_1 = 0b00000100,
None_1 = 0b00001100,
False_2 = 0b00100000,
True_2 = 0b00010000,
None_2 = 0b00110000,
False_3 = 0b10000000,
True_3 = 0b01000000,
None_3 = 0b11000000,
}
}
@@ -1,97 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Dictionary.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;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace StgSharp.Data
{
/// <summary>
/// A class contains a sets of methods to serialize several types
/// </summary>
public static partial class Serializer
{
/**/
public static void Deserialize(byte[] data, out Dictionary<byte, BitArray> dict)
{
dict = new Dictionary<byte, BitArray>();
int stat = 0; byte key = 0;
byte[] raw = new byte[0];
foreach (var b in data)
{
switch (stat)
{
case 0: //getting key
if (raw.Length != 0)
{
BitArray bits;
Deserialize(raw, out bits);
dict.Add(key, bits);
}
key = b;
stat -= 1;
break;
case -1: //getting length
raw = new byte[b];
stat = b;
break;
default:
raw[raw.Length - stat] = b;
stat--;
break;
}
}
}
/**/
public static byte[] Serialize(Dictionary<byte, BitArray> table)
{
using (var stream = new MemoryStream())
{
foreach (var pair in table)
{
stream.WriteByte(pair.Key);
byte[] keyCode = Serialize(pair.Value);
stream.WriteByte((byte)keyCode.Length);
stream.Write(keyCode, 0, keyCode.Length);
}
return stream.ToArray();
}
}
}
}
@@ -1,59 +0,0 @@
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public abstract class ICoord
{
private Matrix44 coordMat;
private Matrix44 origin;
public ICoord()
{
}
//A matrix can convert vertex to global coord.
public Matrix44 GlobalCoordTransformation
{
get
{
return coordMat * origin;
}
}
public vec3d Origin
{
get => origin.colum3.XYZ;
internal set => origin.colum3.XYZ = value;
}
public vec3d X_axis
{
get => coordMat.colum0.XYZ;
internal set => coordMat.colum0.XYZ = value;
}
public vec3d Y_axis
{
get => coordMat.colum1.XYZ;
internal set => coordMat.colum1.XYZ = value;
}
public vec3d Z_axis
{
get => coordMat.colum2.XYZ;
set => coordMat.colum2.XYZ = value;
}
protected ref Matrix44 CoordMat
{
get => ref coordMat;
}
}
}
@@ -1,144 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Math
{
public static partial class GeometryScaler
{
internal const float DegToRad = 180 / Scaler.Pi;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Degree ToDegree(float value)
{
return new Degree(value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sin(Radius r)
{
return MathF.Sin(r._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Tan(Radius r)
{
return MathF.Tan(r._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Cos(Radius r)
{
return MathF.Cos(r._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Sin(Degree r)
{
return MathF.Sin(r._degree/DegToRad);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Tan(Degree r)
{
return MathF.Tan(r._degree / DegToRad);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float Cos(Degree r)
{
return MathF.Cos(r._degree / DegToRad);
}
}
public struct Degree
{
internal float _degree;
internal Degree(float dgree)
{
_degree = dgree;
}
public static implicit operator Radius(Degree d)
{
return new Radius(d._degree / GeometryScaler.DegToRad);
}
}
public struct Radius
{
internal float _radius;
public static Radius Zero
{
get =>new Radius(0);
}
public Radius(float radius)
{
_radius = radius;
}
[Obsolete("Unsafe, you may forget this is radius.",true)]
public Radius() { }
public static implicit operator Degree(Radius r)
{
return new Degree(r._radius * 180 / Scaler.Pi);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator -(Radius r)
{
return new Radius(-r._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator -(Radius left, Radius Right)
{
return new Radius(left._radius - Right._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator /(Radius left, Radius right)
{
return left._radius / right._radius;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator +(Radius left, Radius Right)
{
return new Radius(left._radius + Right._radius);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator *(Radius left, float right)
{
return new Radius(left._radius * right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Radius operator /(Radius left, float right)
{
return new Radius(left._radius / right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Radius left, Radius right)
{
return left._radius == right._radius;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Radius left, Radius right)
{
return left._radius != right._radius;
}
}
}
@@ -1,87 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Arc.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;
namespace StgSharp.Geometries
{
/// <summary>
/// Part of a circle. All points on a arc has the same distance to their center.
/// </summary>
public class Arc : PlainGeometry
{
internal Func<int, vec3d> movBeginOperation = GeometryOperation.DefaultMotion;
internal Func<int, vec3d> movCenterOperation = GeometryOperation.DefaultMotion;
internal Func<int, vec3d> movEndOperation = GeometryOperation.DefaultMotion;
internal Point beginPoint;
internal Point center;
internal Point endPoint;
internal override int[] Indices => throw new NotImplementedException();
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
public override Plain GetPlain()
{
return new Plain(this.center, this.beginPoint, this.endPoint);
}
public virtual vec3d MovBegin(int tick)
{
return movBeginOperation.Invoke(tick);
}
public virtual vec3d MoveCenter(int tick)
{
return movCenterOperation.Invoke(tick);
}
public virtual vec3d MovEnd(int tick)
{
return movEndOperation.Invoke(tick);
}
internal override void UpdateCoordinate(int tick)
{
tick = time;
center.Position = this.coordinate.Origin + MoveCenter(tick);
beginPoint.Position = this.coordinate.Origin + MovBegin(tick);
endPoint.Position = this.coordinate.Origin + MovEnd(tick);
}
}
}
@@ -1,88 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Circle.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;
namespace StgSharp.Geometries
{
/// <summary>
/// A collection of all point on the same plain and has the same distance to a point
/// </summary>
public class Circle : PlainGeometry
{
internal Point center;
internal Func<int,vec3d> movBeginOperation = GeometryOperation.DefaultMotion;
internal Func<int,vec3d> movCenterOperation = GeometryOperation.DefaultMotion;
internal Func<int,vec3d> movEndOperation = GeometryOperation.DefaultMotion;
internal Point pointOnCircle;
internal Point pointOnPlain;
internal override int[] Indices => throw new NotImplementedException();
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
public override Plain GetPlain()
{
return new Plain(center, pointOnCircle, pointOnPlain);
}
public virtual vec3d MoveCenter(int tick)
{
return movCenterOperation.Invoke(tick);
}
public virtual vec3d UpdatePlain(int tick)
{
return movEndOperation.Invoke(tick);
}
public virtual vec3d UpdateRadius(int tick)
{
return movBeginOperation.Invoke(tick);
}
internal override void UpdateCoordinate(int tick)
{
tick = time;
center.Position = this.coordinate.Origin + MoveCenter(tick);
pointOnCircle.Position = this.coordinate.Origin + UpdateRadius(tick);
pointOnPlain.Position = this.coordinate.Origin + UpdatePlain(tick);
}
}
}
@@ -1,39 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpressionHandler.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Geometries
{
public delegate float ExpressionHandler
(
Counter<uint> tickCounter,
float beginRange,
float endRange
);
}
@@ -1,78 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GemoryException.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.Runtime.Serialization;
namespace StgSharp.Geometries
{
public unsafe class ToUpperDimensionException : Exception
{
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ToUpperDimensionException()
{
}
public ToUpperDimensionException(string message) : base(message)
{
}
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
/// </summary>
public class UnusedVertexException : Exception
{
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public UnusedVertexException()
{
}
public UnusedVertexException(string message) : base(message)
{
}
public UnusedVertexException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
@@ -1,139 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IInstancing.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.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Geometries
{
public interface IInstancing<T> where T : IInstancing<T>
{
public int BufferId
{
get;
set;
}
public vec3d CenterPositionGlobal
{
get;
set;
}
public vec3d Coord
{
get { return GlobalBuffer.CoordList[BufferId].XYZ; }
set { GlobalBuffer.CoordList[BufferId] = new vec4d( value.vec); }
}
public PlainInstancingBuffer<T> GlobalBuffer
{
get;
internal set;
}
public float Rotation
{
get { return GlobalBuffer.CoordList[BufferId].W; }
set
{
vec4d temp = GlobalBuffer.CoordList[BufferId];
temp.W = value;
GlobalBuffer.CoordList[BufferId] = temp;
}
}
public float Scale
{
get { return GlobalBuffer.ScalingList[BufferId]; }
set { GlobalBuffer.ScalingList[BufferId] = value; }
}
public GeometryMotion Motion
{
get; set;
}
public void Move()
{
(vec3d coord , float rotation) =(Coord, Rotation);
Motion.RunMotion(ref coord, ref rotation);
(Coord,Rotation) = (coord, rotation);
}
}
public class ParticleOnPlain : IInstancing<ParticleOnPlain>
{
public ParticleOnPlain(PlainInstancingBuffer<ParticleOnPlain> buffer)
{
if (buffer == null)
{
throw new ArgumentNullException(paramName: nameof(buffer));
}
GlobalBuffer = buffer;
BufferId = buffer.CreateInstanceID();
buffer.InstanceList.Add(this);
}
public int BufferId
{
get;
set;
}
public PlainInstancingBuffer<ParticleOnPlain> GlobalBuffer
{
get;
set;
}
public GeometryMotion Motion
{
get;
set;
}
vec3d IInstancing<ParticleOnPlain>.CenterPositionGlobal
{
get;
set;
}
}
}
@@ -1,39 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpressionHandler.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp.Geometries
{
public delegate float ExpressionHandler
(
Counter<uint> tickCounter,
float beginRange,
float endRange
);
}
@@ -1,78 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GemoryException.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.Runtime.Serialization;
namespace StgSharp.Geometries
{
public unsafe class ToUpperDimensionException : Exception
{
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public ToUpperDimensionException()
{
}
public ToUpperDimensionException(string message) : base(message)
{
}
public ToUpperDimensionException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>
/// 当几何体调用了过多的CalcVec方法时,产生UnusedVertexException异常
/// </summary>
public class UnusedVertexException : Exception
{
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public UnusedVertexException()
{
}
public UnusedVertexException(string message) : base(message)
{
}
public UnusedVertexException(string message, Exception innerException) : base(message, innerException)
{
}
}
}
@@ -1,52 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GeometryOperation.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;
namespace StgSharp.Geometries
{
/// <summary>
/// Caculate the movement of a point.
/// </summary>
/// <param name="tick">The game tick represent time passed by</param>
/// <returns>A 3d vector representing movement</returns>
public delegate vec3d GetLocationHandler(int tick);
public static unsafe class GeometryOperation
{
public static vec3d DefualtMotion(int tick)
{
return default(vec3d);
}
}
}
@@ -1,107 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Line.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.Numerics;
namespace StgSharp.Geometries
{
public class Line : PlainGeometry
{
internal Point basePoint;
internal Point beginPoint;
internal Point endPoint;
internal Func<int,vec3d> movBegin;
internal Func<int,vec3d> movEnd;
internal Line(Vector4 begin, Vector4 end)
{
beginPoint = new Point(begin);
endPoint = new Point(end);
}
public Line()
{
}
public Line(Point begin, Point end)
{
this.beginPoint = begin;
this.endPoint = end;
}
internal override int[] Indices => throw new NotSupportedException();
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
public override Plain GetPlain()
{
throw new ToUpperDimensionException();
}
/// <summary>
/// Move begin side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="Func{T, TResult}"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
public virtual vec3d MoveBeginPoint(int tick)
{
return movBegin(time);
}
/// <summary>
/// Move end side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="Func{T,TResult}"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
/// <returns></returns>
public virtual vec3d MoveEndPoint(int tick)
{
return movEnd.Invoke(time);
}
internal override void UpdateCoordinate(int tick)
{
beginPoint.Position = coordinate.Origin + MoveBeginPoint(time);
endPoint.Position = coordinate.Origin + MoveEndPoint(time);
}
}
}
@@ -1,99 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="PlainGeometry.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Math;
using System;
namespace StgSharp.Geometries
{
/// <summary>
/// 平面几何体。包含三角形,对称四边形,自由多边形等。最多可由16个点参数定义。
/// </summary>
public abstract class PlainGeometry: IGeometry
{
protected TimeSpanProvider time;
internal ICoord coordinate;
internal Matrix24 textureFrame;
public PlainGeometry()
{
}
vec4d IGeometry.this[int index]
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
/// <summary>
/// Tick time this geometry eas crested
/// </summary>
public int BornTime => time;
public ICoord ReferenceCoordinate => this.coordinate;
internal abstract int[] Indices { get; }
int IGeometry.VertexCount => throw new NotImplementedException();
vec4d[] IGeometry.VertexStream => throw new NotImplementedException();
/// <summary>
/// Get all sides of this <see cref="PlainGeometry"/>.
/// </summary>
/// <returns>A array contains all straight <see cref="Line"/>s of current geometry item.</returns>
public abstract Line[] GetAllSides();
/// <summary>
/// Get a flat <see cref="Plain"/> cincide with current geometry.
/// </summary>
/// <returns></returns>
public abstract Plain GetPlain();
internal abstract void UpdateCoordinate(int tick);
void IGeometry.GetVertexHandle(ICoord coordinate, int count)
{
throw new NotImplementedException();
}
void IGeometry.Transform(Matrix44 transFormMatrix)
{
throw new NotImplementedException();
}
//public abstract Rectangle GetRenderFrame();
}
}
@@ -1,107 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Point.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.Numerics;
using System.Runtime.InteropServices;
using System.Threading;
namespace StgSharp.Geometries
{
public unsafe class Point
{
internal readonly bool isVertex;
internal vec3d position;
internal Point(vec3d p)
{
position = p;
}
internal Point(Vector4 vector)
{
position = new vec3d(vector);
}
public Point() { }
public Point(float x, float y, float z)
{
position = new vec3d(x, y, z);
}
public bool IsVertex => isVertex;
public vec3d Position
{
get => position;
set => position = value;
}
public float X
{
get => position.X;
set => position.X = value;
}
public float Y
{
get => position.Y;
set => position.Y = value;
}
public float Z
{
get => position.Z;
set => position.Z = value;
}
public bool IsInGeometry(PlainGeometry geo)
{
throw new NotImplementedException();
}
/// <summary>
/// Update the coordinate of the point. If this is a moving point,
/// (Points on sides or surface if other geometry items)
/// please do not define any motion here, codes will be ignored by program
/// </summary>
/// <param name="tick">Time passes since the program begin, counted by frames</param>
public virtual void Update(uint tick) { }
}
}
@@ -1,42 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Class1.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.Text;
namespace StgSharp.Geometries
{
public class SpaceCoordinate
{
}
}
-277
View File
@@ -1,277 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ViewModel.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
namespace StgSharp.Graphics
{
/// <summary>
///
/// </summary>
public abstract unsafe partial class ViewModel
{
private int _frameCount;
private int _frameSpeed;
private IntPtr windowID;
internal ViewModel sharedForm;
internal int height;
internal int width;
internal IntPtr monitor;
internal string name;
internal TimeSpanProvider fpsCountProvider;
internal TimeSpanProvider frameTimeProvider;
internal Vector4 backgroundColor;
protected ViewModel((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 =
() =>
{
};
height = size.height;
width = size.width;
this.name = name;
}
protected ViewModel()
{
fpsCountProvider = new TimeSpanProvider(1.0, TimeSpanProvider.DefaultProvider);
_frameSpeed = 0;
_frameCount = 0;
fpsCountProvider.SpanRefreshCallback =
() =>
{
Interlocked.Exchange(ref _frameSpeed, _frameCount);
Interlocked.Exchange(ref _frameCount, 0);
};
frameTimeProvider = new TimeSpanProvider(
(1000L * 1000L) / 60, TimeSpanProvider.DefaultProvider
);
frameTimeProvider.SpanRefreshCallback =
() =>
{
};
height = 800;
width = 600;
name = new StackFrame(1, false).
GetMethod()!.DeclaringType!.Name;
}
public int CurrentFrameCount => frameTimeProvider.CurrentSpan;
public int FrameSpeed => _frameSpeed;
/// <summary>
/// Height of this form, represent in <see cref="int"/>
/// </summary>
public int Height
{
get => height;
set
{
height = value;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
public bool ShouldClose
{
get => InternalIO.glfwWindowShouldClose(windowID) != 0;
set => InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
}
/// <summary>
/// Width of this form, represent in <see cref="int"/>
/// </summary>
public vec2d Size
{
get => new vec2d(width, height);
set
{
width = (int)value.X;
height = (int)value.Y;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
/// <summary>
/// Width of this form, represent in <see cref="int"/>
/// </summary>
public int Width
{
get => width;
set
{
width = value;
if (WindowID != IntPtr.Zero)
{
InternalIO.glfwSetWindowSize(windowID, Width, Height);
}
}
}
public unsafe IntPtr WindowID
{
get => windowID;
internal set => windowID = value;
}
internal unsafe IntPtr id => windowID;
#pragma warning disable CA1044
protected FrameBufferSizeHandler FrameSizeCallback
{
set
{
IntPtr handlerPtr = Marshal.GetFunctionPointerForDelegate(value);
InternalIO.glfwSetFramebufferSizeCallback(windowID, handlerPtr);
}
}
#pragma warning restore CA1044
#region Key Control
protected KeyStatus CheckKey(KeyboardKey key)
{
return InternalIO.glfwGetKey(this.WindowID,(int)key);
}
protected KeyStatus CheckKey(Mouse key)
{
return InternalIO.glfwGetKey(this.WindowID, (int)key);
}
protected KeyStatus CheckKey(Joystick key)
{
return InternalIO.glfwGetKey(this.WindowID, (int)key);
}
#endregion
/// <summary>
/// Set all necessary metadata to current form instance
/// </summary>
public void SetMetadata(int width, int height, string name, IntPtr monitor, ViewModel sharedForm)
{
this.width = width;
this.height = height;
this.name = name;
this.sharedForm = sharedForm;
this.monitor = monitor;
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="size">
/// A <see cref="vec2d"/> (width,height) representing the new size of current form
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSize(vec2d size)
{
this.Size = size;
InternalIO.glfwSetWindowSize(this.windowID, (int)size.X, (int)size.Y);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minSize">
/// Minimum size of current form. In form of a <see cref="vec2d"/> of (width,height)
/// </param>
/// <param name="maxSize">
/// Maximum size of current form. In form of a <see cref="vec2d"/> of (width,height)
/// </param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(vec2d minSize, vec2d maxSize)
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
(int)minSize.X,
(int)minSize.Y,
(int)maxSize.X,
(int)maxSize.Y);
}
/// <summary>
/// Set the size limit of current form
/// </summary>
/// <param name="minWidth">Minimum width of current form</param>
/// <param name="minHeight">Minimum height of current form</param>
/// <param name="maxWidth">Maximum width of current form</param>
/// <param name="maxHeight">Maximum height of current form</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetSizeLimit(int minWidth, int minHeight, int maxWidth, int maxHeight)
{
//TODO 重做form的尺寸极限控制
InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight);
}
}
}
@@ -1,117 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FormThreadAttribute.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.Text;
namespace StgSharp.Graphics
{
/// <summary>
/// Mark that a method in a <see cref="Form"/>
/// should be called when rendering.
/// </summary>
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class RenderActivityAttribute : Attribute
{
internal bool _isRenderProgress;
internal int _priority;
public RenderActivityAttribute()
{
_priority = (int)RenderPriority.Default;
}
public RenderActivityAttribute(RenderPriority priority)
{
_priority = (int)priority;
}
public RenderActivityAttribute(int priority)
{
_priority = priority;
}
public int Priority { get => _priority; set => _priority = value; }
}
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class MultiFrameActivityAttribute : Attribute
{
internal int _minFrameCount;
}
/// <summary>
/// Priority level of a render activity.
/// </summary>
public enum RenderPriority : int
{
/// <summary>
/// One level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_1 = -1,
/// <summary>
/// Two level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_2 = -2,
/// <summary>
/// Three level higher than <see cref="RenderPriority.Default"/>.
/// </summary>
Pre_3 = -3,
/// <summary>
/// One level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_1 = 1,
/// <summary>
/// Two level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_2 = 2,
/// <summary>
/// Three level lower than <see cref="RenderPriority.Default"/>.
/// </summary>
Aft_3 = 3,
/// <summary>
/// Highest priority, in <see cref="RenderPriority"/>, it is <see cref="Pre_3"/>.
/// </summary>
Highest = Pre_3,
/// <summary>
/// Default priority, usually <see cref="Form.Main"/> is in this priority.
/// </summary>
Default = 0,
/// <summary>
/// Lowest priority, in <see cref="RenderPriority"/>, it is <see cref="Aft_3"/>.
/// </summary>
Least = Aft_3,
}
}
@@ -1,127 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FormThreading.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 StgSharp.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public abstract partial class ViewModel
{
private Blueprint renderLogic;
public Blueprint RenderLogic
{
get => renderLogic;
set => renderLogic = value;
}
/// <summary>
/// Init this form and render it on screen, and respond with operation
/// </summary>
public unsafe void Show()
{
while (!ShouldClose)
{
renderLogic.RunRepeatedly(() => ShouldClose);
frameTimeProvider.WaitNextSpan();
Interlocked.Add(ref _frameCount, 1);
}
}
public T BuildMainRenderStream<T>((int x, int y, int z) unitCubeSize) where T : RenderStream
{
RenderStreamConstructArgs args = new RenderStreamConstructArgs();
args.UnitCubeSize = unitCubeSize;
args.Name = this.name;
args.Height = this.Height;
args.Width = this.Width;
T? ret = Activator.CreateInstance(typeof(T), args) as T;
if (ret == null)
{
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
}
ret!.InternalInit();
this.WindowID = ret.CanvasHandle;
ret.timeProvider = this.frameTimeProvider;
return ret;
}
public T BuildNewRenderStream<T>(RenderStreamConstructArgs arg, (int x, int y, int z) unitCubeSize) where T : RenderStream
{
T? ret = Activator.CreateInstance(typeof(T), arg) as T;
if (ret == null)
{
throw new InvalidOperationException("Failed in building a new RenderStream when calling AsMainStreamOf");
}
ret!.InternalInit();
this.WindowID = ret.CanvasHandle;
ret.timeProvider = this.frameTimeProvider;
return ret;
}
/*
private void GatherSingleFrameAsyncThread(MethodInfo[] methods)
{
if (methods.Length == 0)
{
return;
}
foreach (MethodInfo m in methods) //find all methods decorated by RenderActivityAttribute
{
RenderActivityAttribute attr = m.GetCustomAttribute<RenderActivityAttribute>(false);
if (attr == null)
{
continue;
}
if (!m.IsStatic && (m.GetParameters().Length != 0) && (m.ReturnType != typeof(void)))
{
throw new NotSupportedException("A render activity cannot have parameters, returning value or be static.");
}
ThreadStart s = (ThreadStart)Delegate.CreateDelegate(typeof(ThreadStart), this, m);
FrameAsyncThread thread = new(s, attr._priority);
//singleFrameAsyncThreadList.Add(thread);
}
}
/**/
}
}
@@ -1,640 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FrameAsyncThread.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.Data;
using StgSharp.Math;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal sealed class FrameOperationBuffer
{
private IntPtr _func;
private ConcurrentQueue<IntPtr> _funcQueue;
private readonly unsafe GLcontext* currentContext;
public unsafe FrameOperationBuffer()
{
currentContext = GL.api;
_funcQueue = new ConcurrentQueue<IntPtr>();
}
public unsafe bool CallNext()
{
if (_funcQueue.TryDequeue(out _func))
{
((delegate*<FrameOperationBuffer, GLcontext*, void>)_func)(this, currentContext);
return true;
}
else
{
return false;
}
}
#region gl param queue
private ConcurrentQueue<M128> paramQueue = new ConcurrentQueue<M128>();
private ConcurrentQueue<glArrayHandle> streamQueue = new ConcurrentQueue<glArrayHandle>();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void MethodEnqueue(IntPtr p)
{
_funcQueue.Enqueue(p);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(vec4d v)
{
paramQueue.Enqueue(v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(M128 m)
{
paramQueue.Enqueue(m);
//Console.Write(paramQueue.Count + streamQueue.Count);
//Console.Write($":{m.ToString(16)}\n");
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(uint u0)
{
M128 m = default;
m.Write<uint>(0, u0);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(uint u0, uint u1)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(ulong u0, ulong u1)
{
M128 m = default;
m.Write<ulong>(0, u0);
m.Write<ulong>(1, u1);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(uint u0, uint u1, uint u2)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
m.Write<uint>(2, u2);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(float f0, float f1, float f2)
{
M128 m = default;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(float f0, float f1, float f2, float f3)
{
M128 m = default;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
m.Write<float>(2, f2);
m.Write<float>(3, f3);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(IntPtr p)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void ParamEnqueue(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void ParamEnqueue(glHandle handle, glHandle handle1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(int i0)
{
M128 m = default;
m.Write<int>(0, i0);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(int i0, int i1)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(int i0, int i1, int i2)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(int i0, int i1, int i2, int i3)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
m.Write<int>(3, i3);
this.ParamEnqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue(string str)
{
byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
//Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void ParamEnqueue<T>(T[] array) where T : struct
{
streamQueue.Enqueue(glArrayHandle.Alloc<T>(array));
//Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out glArrayHandle arrayHandle)
{
if (!streamQueue.TryDequeue(out arrayHandle))
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function:", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryDequeue(out M128 m)
{
m = new();
bool ret = paramQueue.TryDequeue(out m);
Console.WriteLine(m.ToString(16));
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void TryDequeue(out vec4d v)
{
M128 m;
if (this.TryDequeue(out m))
{
v = *(vec4d*)&m;
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue<T>(out T[] array)
{
glArrayHandle output = default;
if (streamQueue.TryDequeue(out output))
{
array = output.a as T[];
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
i2 = ret.Read<int>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2, out int i3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
i2 = ret.Read<int>(2);
i3 = ret.Read<int>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p = (IntPtr)ret.Read<ulong>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p0, out IntPtr p1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p0 = (IntPtr)ret.Read<ulong>(0);
p1 = (IntPtr)ret.Read<ulong>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2, out float f3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
f3 = ret.Read<uint>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2, out uint u3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
u3 = ret.Read<uint>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
/*
internal void SetContext(GLcontext* p)
{
context = p;
}
/**/
#endregion gl param queue
}
public class FrameAsyncThread
{
private int _priority;
private Thread _task;
private volatile int _terminateToken;
protected Barrier _frameSpeedSyncBarrier;
protected Barrier _spanCompleteBarrier;
protected ThreadStart _taskTODO;
public FrameAsyncThread(ThreadStart action, int priority)
{
_taskTODO = action;
_terminateToken = 1;
_spanCompleteBarrier = new Barrier(2);
_priority = priority;
}
public int Priority
{
get => _priority;
internal set => _priority = value;
}
public ThreadStart TaskTODO
{
get => _taskTODO;
set => _taskTODO = value;
}
public Barrier TodoCompleteBarrier
=> _spanCompleteBarrier;
public void AsyncStart()
{
_task = new Thread(
() =>
{
while (true)
{
_frameSpeedSyncBarrier.SignalAndWait();
if (_terminateToken == 0)
{
break;
}
_taskTODO();
_spanCompleteBarrier.SignalAndWait();
}
});
_task.Start();
}
public static void AsyncStartAll(IEnumerable<FrameAsyncThread> threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t.AsyncStart();
}
}
public static (Barrier, Barrier) CombineAsync(bool needOuterMonitor, IEnumerable<FrameAsyncThread> taskList)
{
if (taskList.Count() == 0)
{
return (null, null);
}
Barrier b_start = new Barrier(taskList.Count() + (needOuterMonitor ? 1 : 0));
Barrier b_complete = new Barrier(taskList.Count() + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = b_start;
item._spanCompleteBarrier = b_complete;
}
return (b_start, b_complete);
}
public static (Barrier, Barrier) CombineAsync(bool needOuterMonitor, params FrameAsyncThread[] taskList)
{
if (taskList.Length == 0)
{
return (null, null);
}
Barrier b_start = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
Barrier b_complete = new Barrier(taskList.Length + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = b_start;
item._spanCompleteBarrier = b_complete;
}
return (b_start, b_complete);
}
public static Barrier CombineAsyncAfter(Barrier begin, bool needOuterMonitor, IEnumerable<FrameAsyncThread> taskList)
{
if (taskList.Count() == 0)
{
return null;
}
Barrier b_complete = new Barrier(taskList.Count() + (needOuterMonitor ? 1 : 0));
foreach (FrameAsyncThread item in taskList)
{
item._frameSpeedSyncBarrier = begin;
item._spanCompleteBarrier = b_complete;
}
return b_complete;
}
public void Terminate()
{
Interlocked.Exchange(ref _terminateToken, 0);
}
public static void TerminateAll(params FrameAsyncThread[] threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t.Terminate();
}
}
public static void TerminateAll(IEnumerable<FrameAsyncThread> threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t.Terminate();
}
}
public static void WaitAll(IEnumerable<FrameAsyncThread> threadList)
{
foreach (FrameAsyncThread t in threadList)
{
t._task.Join();
}
}
}
}
@@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public class FormFormatter
{
}
public abstract unsafe partial class ViewModel
{
static internal Dictionary<IntPtr, ViewModel> activatedForms ;
public static void ShowForm<T>(FormFormatter f) where T : ViewModel
{
if (activatedForms == null)
{
activatedForms = new Dictionary<IntPtr, ViewModel>();
}
}
}
}
@@ -1,167 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="texture.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.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
public unsafe class Texture
{
internal static bool[] unitActivated = new bool[16];
private IntPtr binding;
internal glHandleSet _textureHandle;
internal Image[] sourceList;
internal Texture(int n, glRenderStream binding)
{
sourceList = new Image[n];
this.binding = binding.ContextHandle;
_textureHandle = GL.GenTextures(n);
}
public void Activate(TextureUnit unit)
{
GL.ActiveTexture((uint)unit);
}
public void Bind2D(int index)
{
GL.BindTexture(GLconst.TEXTURE_2D, _textureHandle[index]);
}
/// <summary>
/// </summary>
/// <param name="name"> </param>
/// <param name="index"> </param>
/// <param name="loader"> </param>
public unsafe void LoadTexture(int index, string name, ImageLoader loader)
{
ImageInfo info = default;
InternalIO.InternalLoadImage(name, &info, loader);
sourceList[index] = new Image(info);
if (sourceList[index].info.pixelPtr != IntPtr.Zero)
{
uint channel;
switch (sourceList[index].info.channel)
{
case 1:
channel = GLconst.RED; break;
case 2:
channel = GLconst.RG; break;
case 3:
channel = GLconst.RGB; break;
case 4:
channel = GLconst.RGBA; break;
default:
channel = 0;
break;
}
GL.TextureImage2d<byte>(
GLconst.TEXTURE_2D, 0, channel,
(uint)sourceList[index].Width, (uint)sourceList[index].Height,
channel, GLconst.UNSIGNED_BYTE,
sourceList[index].pixelArrayHandle
);
}
else
{
InternalIO.InternalWriteLog($"Failed to load image file of \"{name}\".", LogType.Error);
}
}
#region texture setting
public void Set2dFilterProperty(
Filter onMinify, Filter onMagnify)
{
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MIN_FILTER, (int)onMinify);
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_MAG_FILTER, (int)onMagnify);
}
public void Set2dWrapProperty(
Wrap onHorizontial, Wrap onVertical)
{
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_S, (int)onHorizontial);
GL.TextureParameter(GLconst.TEXTURE_2D, GLconst.TEXTURE_WRAP_T, (int)onVertical);
}
#endregion texture setting
}
public enum Filter
{
Nearest = GLconst.NEAREST,
Linear = GLconst.LINEAR,
Nearest_LinearMipmap = GLconst.NEAREST_MIPMAP_LINEAR,
Linear_LinearMipmap = GLconst.LINEAR_MIPMAP_LINEAR,
Nearest_NearestMipmap = GLconst.NEAREST_MIPMAP_NEAREST,
Linear_NearestMipmap = GLconst.LINEAR_MIPMAP_NEAREST,
}
public enum TextureUnit
{
Unit0 = GLconst.TEXTURE0,
Unit1 = GLconst.TEXTURE1,
Unit2 = GLconst.TEXTURE2,
Unit3 = GLconst.TEXTURE3,
Unit4 = GLconst.TEXTURE4,
Unit5 = GLconst.TEXTURE5,
Unit6 = GLconst.TEXTURE6,
Unit7 = GLconst.TEXTURE7,
Unit8 = GLconst.TEXTURE8,
Unit9 = GLconst.TEXTURE9,
Unit10 = GLconst.TEXTURE10,
Unit11 = GLconst.TEXTURE11,
Unit12 = GLconst.TEXTURE12,
Unit13 = GLconst.TEXTURE13,
Unit14 = GLconst.TEXTURE14,
Unit15 = GLconst.TEXTURE15,
}
public enum Wrap
{
Repeat = GLconst.REPEAT,
MirroredRepeat = GLconst.MIRRORED_REPEAT,
ClampToEdge = GLconst.CLAMP_TO_EDGE,
ClampToBorder = GLconst.CLAMP_TO_BORDER,
}
}
@@ -1,187 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ShaderGenerator.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderGenerator
{
private Dictionary<int,ShaderParameter> uniformDefine;
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
public Uniform<T> DefineUniform<T>(string name, int index) where T : struct
{
ShaderParameter p = new ShaderParameter(name,ShaderParameter.TypeMarshal<T>());
uniformDefine.Add(index,p);
//return new Uniform<T>();
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private List<string> codeList;
private List<ShaderParameter> inputList;
private string name;
private ShaderParameter outPut;
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
if (inputParams.Length != function.ParameterCount)
{
// Param list length not equal
throw new ArgumentException("Provided parameters does not match function's parameter list.");
}
if (!ShaderParameter.IsSameType(outPut, function.outPut))
{
// Type of returning value not qual
throw new Exception("Provided parameters does not match function's parameter list.");
}
for (int i = 0; i < inputParams.Length; i++)
{
if (!ShaderParameter.IsSameType(function.inputList[i], inputParams[i]))
{
// Input type not match
throw new Exception("Provided parameters does not match function's parameter list.");
}
}
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
}
codeLine += $"{function.name}(";
foreach (ShaderParameter inputParam in inputParams)
{
codeLine += inputParam.name;
}
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
public static readonly ShaderParameter Void = new ShaderParameter(string.Empty, InternalShaderType.Void);
internal readonly bool isReadOnly;
internal readonly string name;
internal readonly InternalShaderType type;
public ShaderParameter(string name, InternalShaderType type)
{
this.name = name;
this.type = type;
isReadOnly = false;
}
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
{
return param1.type == param2.type;
}
else
{
throw new Exception("Struct is currently not supported.");
}
}
public static InternalShaderType TypeMarshal<T>() where T : struct
{
switch (Type.GetTypeCode(typeof(T)))
{
case TypeCode.Single:
return InternalShaderType.Float;
case TypeCode.Double:
return InternalShaderType.Double;
case TypeCode.Int32:
return InternalShaderType.Int;
case TypeCode.UInt32:
return InternalShaderType.UInt;
default:
break;
}
switch (typeof(T).Name)
{
case "vec4d":
return InternalShaderType.Vector4;
case "Matrix2x2":
return InternalShaderType.Matrix2x2;
case "Matrix2x3":
return InternalShaderType.Matrix2x3;
case "Matrix2x4":
return InternalShaderType.Matrix2x4;
case "Matrix3x2":
return InternalShaderType.Matrix3x2;
case "Matrix3x3":
return InternalShaderType.Matrix3x3;
case "Matrix3x4":
return InternalShaderType.Matrix3x4;
case "Matrix4x2":
return InternalShaderType.Matrix4x2;
case "Matrix4x3":
return InternalShaderType.Matrix4x3;
case "Matrix4x4":
return InternalShaderType.Matrix4x4;
default:
throw new ArgumentException("Not supported shader data type.");
}
}
}
public enum InternalShaderType
{
#pragma warning disable CS1591
Struct, Void,
Int, UInt,
Float, Double,
Vector2, Vector3, Vector4,
VectorD2, VectorD3, VectorD4,
Matrix2x2, Matrix2x3, Matrix2x4,
Matrix3x2, Matrix3x3, Matrix3x4,
Matrix4x2, Matrix4x3, Matrix4x4,
#pragma warning restore CS1591
}
}
@@ -1,64 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Graphics.ShaderEdit
{
public class ShaderStructMember
{
internal InternalShaderType type;
internal object value;
}
public class ShaderStruct
{
internal Dictionary<glSHandle, ShaderStructMember> uniformPair;
public ShaderStruct(params (glSHandle, ShaderStructMember)[] UniformPais)
{
uniformPair = new Dictionary<glSHandle, ShaderStructMember>();
if (UniformPais.Length == 0)
{
return;
}
foreach (var item in UniformPais)
{
uniformPair.Add(item.Item1,item.Item2);
}
}
internal ShaderStruct() { }
public unsafe void SetAllUniforms()
{
GLcontext* gl = GL.api;
foreach (var uniform in uniformPair)
{
int id = uniform.Key.Value;
ShaderStructMember s = uniform.Value;
switch (s.type)
{
case InternalShaderType.Struct: throw new ArgumentException(
"Incorrect type \"Struct\" defined in this self define type");
case InternalShaderType.Void:throw new ArgumentException(
"Incorrect type \"Void\" defined in this self define type");
case InternalShaderType.Float:
gl->glUniform1f(id, (float)s.value);
break;
case InternalShaderType.Int:
gl->glUniform1f(id, (int)s.value);
break;
default:
throw new NotImplementedException();
throw new ArgumentException(
"Incorrect type \"Unknown\" defined in this self define type");
}
}
}
}
}
-288
View File
@@ -1,288 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="framework.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
#if Windows
// using Windows.Win32;
#endif
namespace StgSharp
{
internal partial class InternalIO
{
#region api call
[DllImport(SSC_libname, EntryPoint = "glfwInit")] internal static extern unsafe int glfwInit();
[DllImport(SSC_libname, EntryPoint = "glfwTerminate")] internal static extern unsafe void glfwTerminate();
[DllImport(SSC_libname, EntryPoint = "glfwInitHint")] internal static extern unsafe void glfwInitHint(int hint, int value);
[DllImport(SSC_libname, EntryPoint = "glfwGetVersion")] internal static extern unsafe void glfwGetVersion(int* major, int* minor, int* rev);
[DllImport(SSC_libname, EntryPoint = "glfwGetVersionString")] internal static extern unsafe byte* glfwGetVersionString();
[DllImport(SSC_libname, EntryPoint = "glfwGetError")] internal static extern unsafe int glfwGetError(byte** description);
[DllImport(SSC_libname, EntryPoint = "glfwSetErrorCallback")] internal static extern unsafe GLFWerrorfun glfwSetErrorCallback(GLFWerrorfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitors")] internal static extern unsafe IntPtr* glfwGetMonitors(int* count);
[DllImport(SSC_libname, EntryPoint = "glfwGetPrimaryMonitor")] internal static extern unsafe IntPtr glfwGetPrimaryMonitor();
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorPos")] internal static extern unsafe void glfwGetMonitorPos(IntPtr monitor, int* xpos, int* ypos);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorWorkarea")] internal static extern unsafe void glfwGetMonitorWorkarea(IntPtr monitor, int* xpos, int* ypos, int* width, int* height);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorPhysicalSize")] internal static extern unsafe void glfwGetMonitorPhysicalSize(IntPtr monitor, int* widthMM, int* heightMM);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorContentScale")] internal static extern unsafe void glfwGetMonitorContentScale(IntPtr monitor, float* xscale, float* yscale);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorName")] internal static extern unsafe byte* glfwGetMonitorName(IntPtr monitor);
[DllImport(SSC_libname, EntryPoint = "glfwSetMonitorUserPointer")] internal static extern unsafe void glfwSetMonitorUserPointer(IntPtr monitor, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwGetMonitorUserPointer")] internal static extern unsafe void* glfwGetMonitorUserPointer(IntPtr monitor);
[DllImport(SSC_libname, EntryPoint = "glfwSetMonitorCallback")] internal static extern unsafe GLFWmonitorfun glfwSetMonitorCallback(GLFWmonitorfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwGetVideoModes")] internal static extern unsafe GLFWvidmode* glfwGetVideoModes(IntPtr monitor, int* count);
[DllImport(SSC_libname, EntryPoint = "glfwGetVideoMode")] internal static extern unsafe GLFWvidmode* glfwGetVideoMode(IntPtr monitor);
[DllImport(SSC_libname, EntryPoint = "glfwSetGamma")] internal static extern unsafe void glfwSetGamma(IntPtr monitor, float gamma);
[DllImport(SSC_libname, EntryPoint = "glfwGetGammaRamp")] internal static extern unsafe GLFWgammaramp* glfwGetGammaRamp(IntPtr monitor);
[DllImport(SSC_libname, EntryPoint = "glfwSetGammaRamp")] internal static extern unsafe void glfwSetGammaRamp(IntPtr monitor, GLFWgammaramp* ramp);
[DllImport(SSC_libname, EntryPoint = "glfwDefaultWindowHints")] internal static extern unsafe void glfwDefaultWindowHints();
[DllImport(SSC_libname, EntryPoint = "glfwWindowHint")] internal static extern unsafe void glfwWindowHint(int hint, int value);
[DllImport(SSC_libname, EntryPoint = "glfwWindowHintString")] internal static extern unsafe void glfwWindowHintString(int hint, byte* value);
[DllImport(SSC_libname, EntryPoint = "glfwCreateWindow")] internal static extern unsafe IntPtr glfwCreateWindow(int width, int height, byte[] title, IntPtr monitor, IntPtr share);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(IntPtr window, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(IntPtr window, byte* title);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(IntPtr window, int count, GLFWimage* images);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowPos")] internal static extern unsafe void glfwGetWindowPos(IntPtr window, int* xpos, int* ypos);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPos")] internal static extern unsafe void glfwSetWindowPos(IntPtr window, int xpos, int ypos);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowSize")] internal static extern unsafe void glfwGetWindowSize(IntPtr window, int* width, int* height);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeLimits")] internal static extern unsafe void glfwSetWindowSizeLimits(IntPtr window, int minwidth, int minheight, int maxwidth, int maxheight);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAspectRatio")] internal static extern unsafe void glfwSetWindowAspectRatio(IntPtr window, int numer, int denom);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSize")] internal static extern unsafe void glfwSetWindowSize(IntPtr window, int width, int height);
[DllImport(SSC_libname, EntryPoint = "glfwGetFramebufferSize")] internal static extern unsafe void glfwGetFramebufferSize(IntPtr window, int* width, int* height);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowFrameSize")] internal static extern unsafe void glfwGetWindowFrameSize(IntPtr window, int* left, int* top, int* right, int* bottom);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowContentScale")] internal static extern unsafe void glfwGetWindowContentScale(IntPtr window, float* xscale, float* yscale);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(IntPtr window, float opacity);
[DllImport(SSC_libname, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMonitor")] internal static extern unsafe void glfwSetWindowMonitor(IntPtr window, IntPtr monitor, int xpos, int ypos, int width, int height, int refreshRate);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowAttrib")] internal static extern unsafe int glfwGetWindowAttrib(IntPtr window, int attrib);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(IntPtr window, int attrib, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(IntPtr window, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, GLFWwindowposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(IntPtr window, GLFWwindowclosefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(IntPtr window, GLFWwindowrefreshfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(IntPtr window, GLFWwindowfocusfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(IntPtr window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwPollEvents")] internal static extern unsafe void glfwPollEvents();
[DllImport(SSC_libname, EntryPoint = "glfwWaitEvents")] internal static extern unsafe void glfwWaitEvents();
[DllImport(SSC_libname, EntryPoint = "glfwWaitEventsTimeout")] internal static extern unsafe void glfwWaitEventsTimeout(double timeout);
[DllImport(SSC_libname, EntryPoint = "glfwPostEmptyEvent")] internal static extern unsafe void glfwPostEmptyEvent();
[DllImport(SSC_libname, EntryPoint = "glfwGetInputMode")] internal static extern unsafe int glfwGetInputMode(IntPtr window, int mode);
[DllImport(SSC_libname, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(IntPtr window, int mode, int value);
[DllImport(SSC_libname, EntryPoint = "glfwRawMouseMotionSupported")] internal static extern unsafe int glfwRawMouseMotionSupported();
[DllImport(SSC_libname, EntryPoint = "glfwGetKeyName")] internal static extern unsafe byte* glfwGetKeyName(int key, int scancode);
[DllImport(SSC_libname, EntryPoint = "glfwGetKeyScancode")] internal static extern unsafe int glfwGetKeyScancode(int key);
[DllImport(SSC_libname, EntryPoint = "glfwGetKey")] internal static extern unsafe KeyStatus glfwGetKey(IntPtr window, int key);
[DllImport(SSC_libname, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(IntPtr window, int button);
[DllImport(SSC_libname, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(IntPtr window, double* xpos, double* ypos);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPos")] internal static extern unsafe void glfwSetCursorPos(IntPtr window, double xpos, double ypos);
[DllImport(SSC_libname, EntryPoint = "glfwCreateCursor")] internal static extern unsafe GLFWcursor* glfwCreateCursor(GLFWimage* image, int xhot, int yhot);
[DllImport(SSC_libname, EntryPoint = "glfwCreateStandardCursor")] internal static extern unsafe GLFWcursor* glfwCreateStandardCursor(int shape);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyCursor")] internal static extern unsafe void glfwDestroyCursor(GLFWcursor* cursor);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursor")] internal static extern unsafe void glfwSetCursor(IntPtr window, GLFWcursor* cursor);
[DllImport(SSC_libname, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(IntPtr window, GLFWkeyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(IntPtr window, GLFWcharfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(IntPtr window, GLFWcharmodsfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(IntPtr window, GLFWmousebuttonfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(IntPtr window, GLFWcursorposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(IntPtr window, GLFWcursorenterfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(IntPtr window, GLFWscrollfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(IntPtr window, GLFWdropfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwJoystickPresent")] internal static extern unsafe int glfwJoystickPresent(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickAxes")] internal static extern unsafe float* glfwGetJoystickAxes(int jid, int* count);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickButtons")] internal static extern unsafe byte* glfwGetJoystickButtons(int jid, int* count);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickHats")] internal static extern unsafe byte* glfwGetJoystickHats(int jid, int* count);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickName")] internal static extern unsafe byte* glfwGetJoystickName(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickGUID")] internal static extern unsafe byte* glfwGetJoystickGUID(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwSetJoystickUserPointer")] internal static extern unsafe void glfwSetJoystickUserPointer(int jid, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwGetJoystickUserPointer")] internal static extern unsafe void* glfwGetJoystickUserPointer(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwJoystickIsGamepad")] internal static extern unsafe int glfwJoystickIsGamepad(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwSetJoystickCallback")] internal static extern unsafe GLFWjoystickfun glfwSetJoystickCallback(GLFWjoystickfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwUpdateGamepadMappings")] internal static extern unsafe int glfwUpdateGamepadMappings(byte* str);
[DllImport(SSC_libname, EntryPoint = "glfwGetGamepadName")] internal static extern unsafe byte* glfwGetGamepadName(int jid);
[DllImport(SSC_libname, EntryPoint = "glfwGetGamepadState")] internal static extern unsafe int glfwGetGamepadState(int jid, GLFWgamepadstate* state);
[DllImport(SSC_libname, EntryPoint = "glfwSetClipboardString")] internal static extern unsafe void glfwSetClipboardString(IntPtr window, byte* str);
[DllImport(SSC_libname, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetTime")] internal static extern unsafe double glfwGetTime();
[DllImport(SSC_libname, EntryPoint = "glfwSetTime")] internal static extern unsafe void glfwSetTime(double time);
[DllImport(SSC_libname, EntryPoint = "glfwGetTimerValue")] internal static extern unsafe ulong* glfwGetTimerValue();
[DllImport(SSC_libname, EntryPoint = "glfwGetTimerFrequency")] internal static extern unsafe ulong* glfwGetTimerFrequency();
[DllImport(SSC_libname, EntryPoint = "glfwMakeContextCurrent")] internal static extern unsafe void glfwMakeContextCurrent(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetCurrentContext")] internal static extern unsafe IntPtr glfwGetCurrentContext();
[DllImport(SSC_libname, EntryPoint = "glfwSwapBuffers")] internal static extern unsafe void glfwSwapBuffers(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwSwapInterval")] internal static extern unsafe void glfwSwapInterval(int interval);
[DllImport(SSC_libname, EntryPoint = "glfwExtensionSupported")] internal static extern unsafe int glfwExtensionSupported(byte* extension);
[DllImport(SSC_libname, EntryPoint = "glfwGetProcAddress", CharSet = CharSet.Ansi)] internal static extern unsafe IntPtr glfwGetProcAddress(string procname);
[DllImport(SSC_libname, EntryPoint = "glfwVulkanSupported")] internal static extern unsafe int glfwVulkanSupported();
[DllImport(SSC_libname, EntryPoint = "glfwGetRequiredInstanceExtensions")] internal static extern unsafe byte** glfwGetRequiredInstanceExtensions(uint* count);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetInstanceProcAddress")] internal extern unsafe static GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, byte* procname);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetPhysicalDevicePresentationSupport")] internal extern unsafe static int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint* queuefamily);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal extern unsafe static VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion api call
}
}
-452
View File
@@ -1,452 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ArrayList.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Graphics;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
[StructLayout(LayoutKind.Explicit, Size = 8)]
internal struct LogSeperator
{
[FieldOffset(0)] public ulong all;
[FieldOffset(0)] public long all_s;
[FieldOffset(4)] public uint high;
[FieldOffset(4)] public int high_s;
[FieldOffset(0)] public uint low;
[FieldOffset(0)] public int low_s;
public LogSeperator(uint high, uint low)
{
this.high = high;
this.low = low;
}
}
/// <summary>
/// A linear data structure with dynamic length.
/// It contains a <see cref="List{T}"/> of <see cref="Array"/>,
/// each <see cref="Array"/> is twice longer than the former one.
/// </summary>
/// <typeparam name="T"></typeparam>
public class DynamicArrayList<T>
{
private List<T[]> arrayIndexList;
private LogSeperator indexpair;
private int lastMain = 0;
// main index to the last used element
private int lastSub = 0;
private int length;
private int subLength = 1;
// sub index to the last used element
private Queue<int> unusedMainIndex;
private Queue<int> unusedSubIndex;
public DynamicArrayList()
{
arrayIndexList = [new T[1]];
length = 0;
unusedMainIndex = new Queue<int>();
unusedSubIndex = new Queue<int>();
unusedMainIndex.Enqueue(0);
unusedSubIndex.Enqueue(0);
}
/// <summary>
/// Init a <see cref="DynamicArrayList{T}"/> with a certain amount of elements prepared.
/// </summary>
/// <param name="count">Amount of elements to be prepared.</param>
public DynamicArrayList(int count)
{
arrayIndexList = new List<T[]>();
length = count;
unusedMainIndex = new();
unusedSubIndex = new();
SeprateIndex(count);
int subcount = 1;
for (int i = 0; i < indexpair.high_s; i++)
{
arrayIndexList.Add(new T[count]);
for (int j = 0; j < subcount; j++)
{
unusedMainIndex.Enqueue(i);
unusedSubIndex.Enqueue(j);
}
count >>= 1;
}
if (indexpair.low_s != 0)
{
arrayIndexList.Add(new T[1 >> indexpair.high_s]);
for (int j = 0; j < indexpair.high_s; j++)
{
unusedMainIndex.Enqueue(indexpair.high_s);
unusedSubIndex.Enqueue(j);
}
}
}
/// <summary>
/// Create a new instance of <see cref="DynamicArrayList{T}"/>,
/// and fill the begining ones of elemtns as given instance.
/// </summary>
/// <param name="count">Amount of beginning elements to be filled</param>
/// <param name="instace"></param>
public DynamicArrayList(int count, T instace)
{
arrayIndexList = new List<T[]>();
length = count;
unusedMainIndex = new();
unusedSubIndex = new();
SeprateIndex(count);
int subcount = 1;
for (int i = 0; i < indexpair.high_s; i++)
{
arrayIndexList.Add(new T[count]);
for (int j = 0; j < subcount; j++)
{
unusedMainIndex.Enqueue(i);
unusedSubIndex.Enqueue(j);
}
count >>= 1;
}
if (indexpair.low_s != 0)
{
arrayIndexList.Add(new T[1 >> indexpair.high_s]);
for (int j = 0; j < indexpair.high_s; j++)
{
unusedMainIndex.Enqueue(indexpair.high_s);
unusedSubIndex.Enqueue(j);
}
}
}
internal T this[long index]
{
get
{
indexpair.all_s = index;
if (
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
return arrayIndexList[indexpair.high_s][indexpair.low_s];
}
set
{
indexpair.all_s = index;
if (
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
arrayIndexList[indexpair.high_s][indexpair.low_s] = value;
}
}
public T this[int index]
{
get
{
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
SeprateIndex(index);
return arrayIndexList[indexpair.high_s][indexpair.low_s];
}
set
{
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
SeprateIndex(index);
arrayIndexList[indexpair.high_s][indexpair.low_s] = value;
}
}
public T this[uint index]
{
get
{
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
SeprateIndex(index);
return arrayIndexList[indexpair.high_s][indexpair.low_s];
}
set
{
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
SeprateIndex(index);
arrayIndexList[indexpair.high_s][indexpair.low_s] = value;
}
}
public int Count => length;
/// <summary>
/// Length of this <see cref="DynamicArrayList{T}"/>
/// </summary>
public int Length => length;
public int Add(T item)
{
// this list is tite, all item is side by side
if (unusedMainIndex.Count == 0)
{
// no extra space, a new sub array is needed
if (lastSub + 1 == 1 << lastMain)
{
subLength <<= 1;
arrayIndexList.Add(new T[subLength]);
lastMain++;
lastSub = 0;
arrayIndexList[lastMain][0] = item;
length++;
subLength = 1;
return length - 1;
}
length++;
lastSub++;
arrayIndexList[lastMain][lastSub] = item;
subLength = 1;
return length - 1;
}
length++;
int main = unusedMainIndex.Dequeue();
int sub = unusedSubIndex.Dequeue();
arrayIndexList[main][sub] = item;
subLength = 1;
return sub + (1 << main);
}
public void Clear()
{
arrayIndexList.Clear();
arrayIndexList.Add(new T[1]);
unusedMainIndex.Clear();
unusedSubIndex.Clear();
length = 0;
unusedMainIndex.Enqueue(0);
unusedSubIndex.Enqueue(0);
}
public bool Contains(T item)
{
foreach (T[] list in arrayIndexList)
{
foreach (T i in list)
{
if (i.Equals(item))
{
return true;
}
}
}
return false;
}
public void CopyTo(DynamicArrayList<T> target)
{
target.arrayIndexList.Clear();
int length = 1;
foreach (T[] tList in target.arrayIndexList)
{
T[] newIndex = new T[length];
Buffer.BlockCopy(tList, 0, newIndex, 0, length);
target.arrayIndexList.Add(newIndex);
length <<= 1;
}
target.lastMain = lastMain;
target.lastSub = lastSub;
target.length = length;
target.unusedMainIndex = new Queue<int>(unusedMainIndex.ToArray());
target.unusedSubIndex = new Queue<int>(unusedSubIndex.ToArray());
}
public int IndexOf(T item)
{
int index = 1;
foreach (T[] list in arrayIndexList)
{
int subindex = 0;
foreach (T i in list)
{
if (i.Equals(item))
{
return (index + subindex) - 1;
}
subindex++;
}
index <<= 1;
}
return -1;
}
[Obsolete("This method is not same, you may read data form an empty index.", false)]
public bool Remove(T item)
{
int index = 0;
foreach (T[] list in arrayIndexList)
{
int subindex = 0;
foreach (T i in list)
{
if (i.Equals(item))
{
list[subindex] = default;
if ((subindex == lastSub) && (index == lastMain))
{
if (lastSub == 0)
{
lastMain = (lastMain == 0) ? 0 : (lastMain - 1);
lastSub = arrayIndexList[lastMain].Length - 1;
}
else
{
lastSub--;
}
length--;
return true;
}
unusedMainIndex.Enqueue(index);
unusedSubIndex.Enqueue(subindex);
return true;
}
subindex++;
}
index++;
}
return false;
}
[Obsolete("This method is not same, you may read data form an empty index.", false)]
public void RemoveAt(int index)
{
if ((index > length) || (index < 0))
{
throw new ArgumentOutOfRangeException(nameof(index));
}
SeprateIndex(index);
//the last element was removed.
if (index + 1 == length)
{
//the last array can be disposed
if (lastSub == 0)
{
arrayIndexList.RemoveAt(lastMain);
lastMain--;
lastSub = (length / 2) - 1;
}
length--;
return;
}
unusedMainIndex.Enqueue(indexpair.high_s);
unusedSubIndex.Enqueue(indexpair.low_s);
}
public void ShowStructure()
{
foreach (T[] l in arrayIndexList)
{
foreach (T item in l)
{
Console.Write($"{item}\t");
}
Console.Write("\n\n");
}
}
private void SeprateIndex(uint ulongIndex)
{
indexpair.high = ulongIndex;
int mainindex = 0;
while (indexpair.high > 1)
{
indexpair.all >>= 1;
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= 32 - mainindex;
}
private void SeprateIndex(int longIndex)
{
indexpair.high_s = longIndex;
int mainindex = 0;
while (indexpair.high > 1)
{
indexpair.all >>= 1;
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= 32 - mainindex;
}
}
}
-64
View File
@@ -1,64 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BluePaint.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.Logic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharpDebug.Logic
{
public class BluePaint
{
private bool running;
private List<BluePaintNode> allNode;
private BluePaintNode beginNode;
public bool IsRunning
{
get => running; set => running = value;
}
public void Start()
{
foreach (var pipeline in beginNode.OutputInterface)
{
}
}
}
}
-119
View File
@@ -1,119 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BluePaintNode.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 StgSharpDebug.Logic;
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 BluePaintNodeAction(
in Dictionary<string, BluePaintPipeline> inpput,
in Dictionary<string, BluePaintPipeline> output);
public abstract class BluePaintNode
{
private BluePaintNodeAction mainOperation;
private BluePaint local;
private Dictionary<string, BluePaintPipeline> inputInterfaces;
private Dictionary<string, BluePaintPipeline> outputInterface;
private bool running;
private string name;
internal Dictionary<string, BluePaintPipeline> InputInterfaces => inputInterfaces;
internal Dictionary<string, BluePaintPipeline> OutputInterface => outputInterface;
internal BluePaintNode(string name, bool isTaskSurvival)
{
this.name = name;
SurvivalTask = isTaskSurvival;
}
protected BluePaintNode(string name, BluePaintNodeAction operation)
{
this.name = name;
mainOperation = operation;
}
internal bool SurvivalTask
{
get; set;
}
public void Run()
{
foreach (var item in inputInterfaces)
{
item.Value.WaitForStart();
}
mainOperation(in inputInterfaces, in outputInterface);
}//--------------------------------- end of class -----------------------------
}
public class BluePaintPipeline
{
private SemaphoreSlim formerCompleteSemaphore;
private BluePaintPipelineArgs args;
public BluePaintPipeline()
{
formerCompleteSemaphore = new SemaphoreSlim(initialCount: 0,maxCount:1);
}
public void CompleteAndWriteData(BluePaintPipelineArgs args)
{
formerCompleteSemaphore.Release();
this.args = args;
}
public void WaitForStart()
{
formerCompleteSemaphore.Release();
}
}
public abstract class BluePaintPipelineArgs
{
}
}
-167
View File
@@ -1,167 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharpDebug.Logic
{
public class Blueprint
{
private BlueprintNode beginNode;
private Dictionary<string, BlueprintNode> allNode;
private Func<bool> terminate;
private int currentNodeIndex = 0;
private List<Task> allThread;
private List<BlueprintNode> nativeNodeList;
private List<BlueprintNode> nodeList;
public Blueprint()
{
allThread = new List<Task>();
nodeList = new List<BlueprintNode>();
nativeNodeList = new List<BlueprintNode>();
terminate = () => false;
}
public bool IsRunning => allThread.Any(t => t.Status == TaskStatus.Running);
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(
() =>
{
while (true)
{
try
{
while (true)
{
RequestNextNode().Run();
}
}
catch (NodeClearException) { }
if (terminate())
{
return;
}
}
}
));
}
}
/// <summary>
/// Run all nodes in current blueprint once.
/// </summary>
public void Run()
{
foreach (var t in allThread)
{
t.Start();
}
foreach (var node in nativeNodeList)
{
node.Run();
}
Task.WaitAll(allThread.ToArray());
}
/// <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)
{
terminate = terminateInstructor;
foreach (var t in allThread)
{
t.Start();
}
foreach (var node in nativeNodeList)
{
node.Run();
}
foreach (var node in nativeNodeList)
{
node.Run();
}
}
private BlueprintNode RequestNextNode()
{
if (currentNodeIndex < nodeList.Count)
{
BlueprintNode ret = nodeList[currentNodeIndex];
Interlocked.Increment(ref currentNodeIndex);
return ret;
}
throw new NodeClearException();
}
}
internal class NodeClearException : Exception
{
}
}
-186
View File
@@ -1,186 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 StgSharpDebug.Logic;
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);
public abstract class BlueprintNode:IComparable<BlueprintNode>
{
private Blueprint local;
private BlueprintNodeAction mainOperation;
private bool levelAvailabel, nativeRequested;
private Dictionary<string, BlueprintPipeline> inputInterfaces;
private Dictionary<string, BlueprintPipeline> outputInterface;
private int level;
private string name;
protected BlueprintNode(string name, BlueprintNodeAction operation)
{
this.levelAvailabel = false;
this.name = name;
mainOperation = operation;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterface = new Dictionary<string, BlueprintPipeline>();
}
internal BlueprintNode(string name, bool isNative)
{
this.levelAvailabel = false;
this.name = name;
nativeRequested = isNative;
inputInterfaces = new Dictionary<string, BlueprintPipeline>();
outputInterface = new Dictionary<string, BlueprintPipeline>();
}
public bool IsNative => nativeRequested;
public int Level
{
get
{
if (levelAvailabel)
{
return level;
}
level = 0;
foreach (var item in inputInterfaces)
{
if (level <= item.Value.Level)
{
level = item.Value.Level;
}
}
level += 1;
return level;
}
}
internal Dictionary<string, BlueprintPipeline> InputInterfaces => inputInterfaces;
internal Dictionary<string, BlueprintPipeline> OutputInterface => outputInterface;
public void AddAfter(
BlueprintNode former,
string formerOutputPortName,
string thisInputPortName)
{
this.levelAvailabel = false;
BlueprintPipeline pipeline = new BlueprintPipeline(former,this);
}
public void Run()
{
try
{
foreach (var item in inputInterfaces)
{
item.Value.WaitForStart();
}
mainOperation(in inputInterfaces, in outputInterface);
}
catch (Exception)
{
throw;
}
}
int IComparable<BlueprintNode>.CompareTo(BlueprintNode other)
{
return this.Level.CompareTo(other.Level);
}
}//--------------------------------- end of class -----------------------------
public class BlueprintNodeRunException : Exception
{
private Exception realException;
public BlueprintNodeRunException(string message, Exception ex) : base(message, ex)
{
}
public BlueprintNodeRunException(Exception ex):base("",ex)
{
}
}
public class BlueprintPipeline
{
private BlueprintNode former;
private BlueprintNode after;
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 Former => former;
public BlueprintNode After => after;
public int Level => former.Level;
public void CompleteAndWriteData(BlueprintPipelineArgs args)
{
formerCompleteSemaphore.Release();
this.args = args;
}
public void WaitForStart()
{
formerCompleteSemaphore.Release();
}
}
public abstract class BlueprintPipelineArgs
{
}
}
-58
View File
@@ -1,58 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Control.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.Entities;
using StgSharp.Geometries;
using StgSharp.Math;
namespace StgSharp
{
public partial class Control
{
internal Line bottomBoader;
internal Line leftBoader;
internal Line rightBoader;
internal Line topBoader;
public Line BottomBoarder => bottomBoader;
public Line LeftBoarder => leftBoader;
public Line RightBoarder => rightBoader;
public Line TopBoarder => topBoader;
private void initContainers()
{
}
}
}
-69
View File
@@ -1,69 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="LogicValue.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.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
/// <summary>
/// A pair of <see cref="bool"/> value
/// </summary>
[StructLayout(LayoutKind.Explicit, Size = 2)]
public struct Bool2
{
/// <summary>
/// The first <see cref="bool"/> value.
/// </summary>
[FieldOffset(0)] public bool bool0;
/// <summary>
/// The second <see cref="bool"/> value.
/// </summary>
[FieldOffset(1)] public bool bool1;
[FieldOffset(0)] public byte byte0;
[FieldOffset(1)] public bool byte1;
/// <summary>
/// A <see cref="ushort"/> value.
/// The lower byte is <see cref="bool0"/>,
/// and higher byte is <see cref="bool1"/>.
/// </summary>
[FieldOffset(0)] public ushort Value;
}
}
-469
View File
@@ -1,469 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glParamQueue.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.Data;
using StgSharp.Graphics;
using StgSharp.Math;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Logic
{
internal unsafe class GLparamQueue
{
private ConcurrentQueue<M128> paramQueue;
private ConcurrentQueue<glArrayHandle> streamQueue;
internal GLcontext* context;
public GLparamQueue()
{
paramQueue = new ConcurrentQueue<M128>();
streamQueue = new ConcurrentQueue<glArrayHandle>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(vec4d v)
{
paramQueue.Enqueue(v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(M128 m)
{
paramQueue.Enqueue(m);
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0)
{
M128 m = default;
m.Write<uint>(0, u0);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0)
{
M128 m = default;
m.Write<int>(0, i0);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(string str)
{
byte[] code = Encoding.UTF8.GetBytes(str);
streamQueue.Enqueue(glArrayHandle.Alloc<byte>(code));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue<T>(T[] array) where T : struct
{
streamQueue.Enqueue(glArrayHandle.Alloc<T>(array));
Console.WriteLine(paramQueue.Count + streamQueue.Count);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(ulong u0, ulong u1)
{
M128 m = default;
m.Write<ulong>(0, u0);
m.Write<ulong>(1, u1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(IntPtr p0, IntPtr p1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)p0);
m.Write<ulong>(1, (ulong)p1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(glHandle handle, glHandle handle1)
{
M128 m = default;
m.Write<ulong>(0, (ulong)handle.valuePtr);
m.Write<ulong>(1, (ulong)handle1.valuePtr);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(uint u0, uint u1, uint u2)
{
M128 m = default;
m.Write<uint>(0, u0);
m.Write<uint>(1, u1);
m.Write<uint>(2, u2);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2)
{
M128 m = default;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(float f0, float f1, float f2, float f3)
{
M128 m = default;
m.Write<float>(0, f0);
m.Write<float>(1, f1);
m.Write<float>(2, f2);
m.Write<float>(3, f3);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Enqueue(int i0, int i1, int i2, int i3)
{
M128 m = default;
m.Write<int>(0, i0);
m.Write<int>(1, i1);
m.Write<int>(2, i2);
m.Write<int>(3, i3);
this.Enqueue(m);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out glArrayHandle arrayHandle)
{
if (!streamQueue.TryDequeue(out arrayHandle))
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function:", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryDequeue(out M128 m)
{
bool ret = paramQueue.TryDequeue(out m);
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out vec4d v)
{
M128 m;
if (this.TryDequeue(out m))
{
v = *(vec4d*)&m;
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue<T>(out T[] array)
{
glArrayHandle output = default;
if (streamQueue.TryDequeue(out output))
{
array = output.a as T[];
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p = (IntPtr)ret.Read<ulong>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out IntPtr p0, out IntPtr p1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
p0 = (IntPtr)ret.Read<ulong>(0);
p1 = (IntPtr)ret.Read<ulong>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
i2 = ret.Read<int>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out int i0, out int i1, out int i2, out int i3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
i0 = ret.Read<int>(0);
i1 = ret.Read<int>(1);
i2 = ret.Read<int>(2);
i3 = ret.Read<int>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out float f0, out float f1, out float f2, out float f3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
f0 = ret.Read<uint>(0);
f1 = ret.Read<uint>(1);
f2 = ret.Read<uint>(2);
f3 = ret.Read<uint>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void TryDequeue(out uint u0, out uint u1, out uint u2, out uint u3)
{
M128 ret;
if (this.TryDequeue(out ret))
{
u0 = ret.Read<uint>(0);
u1 = ret.Read<uint>(1);
u2 = ret.Read<uint>(2);
u3 = ret.Read<uint>(3);
}
else
{
InternalIO.InternalWriteLog("No param in buffer when calling gl function.", LogType.Error);
throw new Exception();
}
}
/*
internal void SetContext(GLcontext* p)
{
context = p;
}
/**/
}
}
-155
View File
@@ -1,155 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="M128.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
#if NET5_0_OR_GREATER
using System.Runtime.Intrinsics;
#endif
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Pack = 16)]
public unsafe struct M128
{
[FieldOffset(0)] internal Vector4 vec;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public T Read<T>(int index) where T : struct
{
fixed (Vector4* p = &vec)
{
return *(((T*)p) + index);
}
}
public override string ToString()
{
return string.Empty;
}
public string ToString(int sample)
{
string str = string.Empty;
for (int i = 15; i >= 0; i--)
{
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
}
return str;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Write<T>(int index, T value) where T : struct
#if NET8_0_OR_GREATER
, INumber
#endif
{
fixed (Vector4* p = &vec)
{
*(((T*)p) + index) = value;
}
}
#if NET5_0_OR_GREATER
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<byte>(M128 m)
{
return Vector128.As<float, byte>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<sbyte>(M128 m)
{
return Vector128.As<float, sbyte>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<short>(M128 m)
{
return Vector128.As<float, short>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<ushort>(M128 m)
{
return Vector128.As<float, ushort>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<int>(M128 m)
{
return Vector128.As<float, int>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<uint>(M128 m)
{
return Vector128.As<float, uint>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<long>(M128 m)
{
return Vector128.As<float, long>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<ulong>(M128 m)
{
return Vector128.As<float, ulong>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<float>(M128 m)
{
return Vector128.As<float, float>(m.vec.AsVector128());
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static explicit operator Vector128<double>(M128 m)
{
return Vector128.As<float, double>(m.vec.AsVector128());
}
#endif
}
}
@@ -1,72 +0,0 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.VectorTransform.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.Numerics;
using System.Runtime.CompilerServices;
namespace StgSharp.Math
{
public static unsafe partial class VectorCalc
{
public static vec2d To2D(vec3d vec, CoordinatePlain plain)
{
switch (plain)
{
case CoordinatePlain.XY:
return new vec2d(vec.X, vec.Y);
break;
case CoordinatePlain.YZ:
return new vec2d(vec.Y, vec.Z);
break;
case CoordinatePlain.XZ:
return new vec2d(vec.X, vec.Z);
break;
default:
return default(vec2d);
break;
}
}
public static vec3d To3D(vec2d vec)
{
return new vec3d(vec.X, vec.Y, 0.0f);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static vec3d To3D(Vector4 vector)
{
return new vec3d(vector);
}
}
}
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
de50efab9ad17092195f29830b896b77e872265cfb93d08224b3e1a0bc0b0dca
@@ -0,0 +1,15 @@
is_global = true
build_property.CsWin32InputMetadataPaths = C:\Users\Nitlo\.nuget\packages\microsoft.windows.sdk.win32metadata\55.0.45-preview\Windows.Win32.winmd|C:\Users\Nitlo\.nuget\packages\microsoft.windows.wdk.win32metadata\0.9.9-experimental\Windows.Wdk.winmd
build_property.CsWin32InputDocPaths = C:\Users\Nitlo\.nuget\packages\microsoft.windows.sdk.win32docs\0.1.42-alpha\apidocs.msgpack
build_property.TargetFramework = netstandard2.1
build_property.TargetPlatformMinVersion = 7.0
build_property.UsingMicrosoftNETSdkWeb =
build_property.ProjectTypeGuids =
build_property.InvariantGlobalization =
build_property.PlatformNeutralAssembly =
build_property.EnforceExtendedAnalyzerRules =
build_property._SupportedPlatformList = Linux,macOS,Windows
build_property.RootNamespace = StgSharp
build_property.ProjectDir = D:\NitloadIndustry\研究项目\1-Flagship\TH2020\ProjectFile\源代码\StgSharp\
build_property.EnableComHosting =
build_property.EnableGeneratedComInterfaceComImportInterop =
+1 -1
View File
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "ZPDe1JI7Wx6qgAfoUxccO7bepdlHRo3d3YlIJ3OaR4SOQAO2IFjQgv3H5Y8S5d37x/fP3pn350jCofkiCwCIsw==",
"dgSpecHash": "6vH7gozY3nlutAvycQCQBpFugaBd+eT4Uj5P/nMDlmS2xt5e7Cw17gX8+p3vXVTBjKgDitDDnucb2v8GcacRcw==",
"success": true,
"projectFilePath": "D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\源代码\\StgSharp\\StgSharp.csproj",
"expectedPackageFiles": [
@@ -1 +1 @@
10a5597183260351018995f463258da2d5589454468940a16d3a53d17785c9e0
ce2864c500078b726caaf79382f20f5fe8c787b07bda81dd387eddbce2a0954f
@@ -1 +1 @@
6e1c38d1590cf376451723047286bd9f89272ce1
28f63d3bc726f046f56812aba0ce94432bcf3fa0d93682df4908bad19488c21c
File diff suppressed because one or more lines are too long