daily update on 2024.03.18 by itload youmu

This commit is contained in:
YoumuLiu
2024-03-19 02:41:04 +08:00
parent 15bf989285
commit 0c50c6282e
200 changed files with 7663 additions and 3455 deletions
+33 -2
View File
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -7,6 +37,7 @@ namespace StgSharp
{
public static unsafe partial class Operation
{
/// <summary>
/// Get the status of a certain key on the keyboard.
/// </summary>
@@ -15,7 +46,7 @@ namespace StgSharp
/// <returns></returns>
public static KeyStatus GetKeyStatus(Form form, Key key)
{
return InternalIO.glfwGetKey(form.windowID, (int)key);
return InternalIO.glfwGetKey(form.id, (int)key);
}
}
+31 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLIO.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.Math;
+59 -26
View File
@@ -1,11 +1,42 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Threading;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
#if Windows
@@ -24,10 +55,6 @@ namespace StgSharp
internal static unsafe partial class InternalIO
{
internal static Dictionary<TypeCode, uint> GLtype =
new Dictionary<TypeCode, uint>();
internal static IntPtr SSClibPtr = IntPtr.Zero;
internal const string SS_errorlog =
"SS_errorlog.log";
@@ -35,9 +62,16 @@ namespace StgSharp
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);
@@ -49,6 +83,20 @@ namespace StgSharp
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
{
@@ -68,8 +116,9 @@ namespace StgSharp
}
}
internal static void InternalAppendLog(string log)
internal static void InternalWriteLog(string logLine, LogType logType)
{
logSyncSemaphore.Wait();
if (!File.Exists(SS_errorlog))
{
FileStream stream = File.Create(SS_errorlog);
@@ -78,12 +127,12 @@ namespace StgSharp
using (StreamWriter logStream = File.AppendText(SS_errorlog))
{
logStream.WriteLine(log);
logStream.WriteLine($"{logType}\t@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
}
internal static SemaphoreSlim logSyncSemaphore = new SemaphoreSlim(1, 1);
internal static void InternalWriteLog(string beforeTime, string logLine, LogType logType)
{
logSyncSemaphore.Wait();
@@ -102,21 +151,5 @@ namespace StgSharp
logSyncSemaphore.Release(1);
}
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@\t{DateTime.Now.ToString("o")}");
logStream.WriteLine(logLine);
}
logSyncSemaphore.Release(1);
}
}
}
+154 -124
View File
@@ -1,133 +1,163 @@
namespace StgSharp
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
namespace StgSharp
{
public static partial class Operation
{
public enum Key : int
{
UNKNOWN = -1,
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,
LEFT_BRACKET = 91/*[*/,
BACKSLASH = 92/*\*/,
RIGHT_BRACKET = 93/*]*/,
GRAVE_ACCENT = 96/*`*/,
WORLD_1 = 161/*non-US#1*/,
WORLD_2 = 162/*non-US#2*/,
ESCAPE = 256,
ENTER = 257,
TAB = 258,
BACKSPACE = 259,
INSERT = 260,
DELETE = 261,
RIGHT = 262,
LEFT = 263,
DOWN = 264,
UP = 265,
PAGE_UP = 266,
PAGE_DOWN = 267,
HOME = 268,
END = 269,
CAPS_LOCK = 280,
SCROLL_LOCK = 281,
NUM_LOCK = 282,
PRINT_SCREEN = 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,
KP_0 = 320,
KP_1 = 321,
KP_2 = 322,
KP_3 = 323,
KP_4 = 324,
KP_5 = 325,
KP_6 = 326,
KP_7 = 327,
KP_8 = 328,
KP_9 = 329,
KP_DECIMAL = 330,
KP_DIVIDE = 331,
KP_MULTIPLY = 332,
KP_SUBTRACT = 333,
KP_ADD = 334,
KP_ENTER = 335,
KP_EQUAL = 336,
LEFT_SHIFT = 340,
LEFT_CONTROL = 341,
LEFT_ALT = 342,
LEFT_SUPER = 343,
RIGHT_SHIFT = 344,
RIGHT_CONTROL = 345,
RIGHT_ALT = 346,
RIGHT_SUPER = 347,
MENU = 348
UNKNOWN = -1,
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,
LEFT_BRACKET = 91/*[*/,
BACKSLASH = 92/*\*/,
RIGHT_BRACKET = 93/*]*/,
GRAVE_ACCENT = 96/*`*/,
WORLD_1 = 161/*non-US#1*/,
WORLD_2 = 162/*non-US#2*/,
ESCAPE = 256,
ENTER = 257,
TAB = 258,
BACKSPACE = 259,
INSERT = 260,
DELETE = 261,
RIGHT = 262,
LEFT = 263,
DOWN = 264,
UP = 265,
PAGE_UP = 266,
PAGE_DOWN = 267,
HOME = 268,
END = 269,
CAPS_LOCK = 280,
SCROLL_LOCK = 281,
NUM_LOCK = 282,
PRINT_SCREEN = 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,
KP_0 = 320,
KP_1 = 321,
KP_2 = 322,
KP_3 = 323,
KP_4 = 324,
KP_5 = 325,
KP_6 = 326,
KP_7 = 327,
KP_8 = 328,
KP_9 = 329,
KP_DECIMAL = 330,
KP_DIVIDE = 331,
KP_MULTIPLY = 332,
KP_SUBTRACT = 333,
KP_ADD = 334,
KP_ENTER = 335,
KP_EQUAL = 336,
LEFT_SHIFT = 340,
LEFT_CONTROL = 341,
LEFT_ALT = 342,
LEFT_SUPER = 343,
RIGHT_SHIFT = 344,
RIGHT_CONTROL = 345,
RIGHT_ALT = 346,
RIGHT_SUPER = 347,
MENU = 348
}
public enum Joystick:int
public enum Joystick : int
{
JOYSTICK_1 = 0,
JOYSTICK_2 = 1,
@@ -164,7 +194,7 @@
BUTTON_MIDDLE = BUTTON_3
}
}
public enum KeyStatus : int
+40 -11
View File
@@ -1,5 +1,36 @@
using StgSharp.Entities;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -9,24 +40,19 @@ namespace StgSharp.Controlling
{
internal static partial class TimeLine
{
internal static Queue<Form> formList = new Queue<Form>();
private static bool isPaused = false;
private static bool renderChainStarted;
internal static TimelineBlock currentOperation;
private static bool isPaused = false;
internal static bool RenderStarted
{
get { return renderChainStarted; }
}
internal static Queue<Form> formList = new Queue<Form>();
public static TimelineBlock CurrentOperation
{
get { return currentOperation; }
get => currentOperation;
set
{
if (currentOperation == default ||
if ((currentOperation == default) ||
currentOperation.isComplete)
{
currentOperation = value;
@@ -35,6 +61,9 @@ namespace StgSharp.Controlling
}
internal static bool RenderStarted => renderChainStarted;
internal static void RenderAll()
{
renderChainStarted = true;
+34 -2
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Controlling
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
{
@@ -8,12 +38,14 @@
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();
public abstract bool GetShouldComplete();
}
}
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Entities
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BehaviorArgs.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.Entities
{
public abstract class BehaviorArgs
{
+44 -7
View File
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EliteEnemy.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 System;
using System.Collections.Generic;
@@ -7,20 +37,19 @@ namespace StgSharp.Entities
{
public class EliteEnemy : IEntity
{
public bool _selectalbe;
internal Launcher<EntityPartical> _awardLauncher;
internal LinkedList<Launcher<EntityPartical>> _commonBulletLauncher;
internal Launcher<EntityPartical> _dieBulletLauncher;
public bool _selectalbe;
public Launcher<EntityPartical> AwardLauncher { get; set; }
public LinkedList<Launcher<EntityPartical>> CommonBulletLauncher { get; set; }
public Launcher<EntityPartical> DieBulletLauncher { get; set; }
internal void InternalDieOperation(Control home)
public virtual void OnRender()
{
_dieBulletLauncher.Launch();
_awardLauncher.Launch();
new NotImplementedException();
}
public override void OnRenderFrame()
@@ -33,8 +62,16 @@ namespace StgSharp.Entities
this.OnRender();
}
public virtual void OnRender() => new NotImplementedException();
public virtual void OnUpdate()
{
new NotImplementedException();
}
internal void InternalDieOperation(Control home)
{
_dieBulletLauncher.Launch();
_awardLauncher.Launch();
}
public virtual void OnUpdate() => new NotImplementedException();
}
}
+37 -6
View File
@@ -1,28 +1,59 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Enemy.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;
namespace StgSharp.Entities
{
public class Enemy : IEntity
{
public bool _selectalbe;
internal Launcher<EntityPartical> _awardLauncher;
internal Launcher<EntityPartical> _commonBulletLauncher;
internal Launcher<EntityPartical> _dieBulletLauncher;
public bool _selectalbe;
public Launcher<EntityPartical> AwardLauncher { get; set; }
public Launcher<EntityPartical> CommonBulletLauncher { get; set; }
public Launcher<EntityPartical> DieBulletLauncher { get; set; }
public override void OnRenderFrame()
{
CommonBulletLauncher.Launch();
}
internal void InternalDieOperation(Control home)
{
_dieBulletLauncher.Launch();
_awardLauncher.Launch();
}
public override void OnRenderFrame()
{
CommonBulletLauncher.Launch();
}
}
}
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Entities
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EntityPartical.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.Entities
{
public abstract class EntityPartical : IEntity
{
+45 -13
View File
@@ -1,4 +1,34 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IEntity.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.Math;
using System.Collections.Generic;
@@ -7,19 +37,20 @@ namespace StgSharp
{
public abstract class IEntity
{
internal Point _pos;
protected uint _bornTick;
internal Point _basePoint;
internal LinkedList<PlainGeometry> _collisionBox;
internal Sensor<PlainGeometry> _collisionSensor;
internal string _texture;
internal Point _position;
internal Point _basePoint;
internal GetLocationHandler _movHandler;
protected uint _bornTick;
internal Point _pos;
internal Point _position;
internal string _texture;
public LinkedList<PlainGeometry> CollisionBox
{
get { return _collisionBox; }
set { _collisionBox = value; }
get => _collisionBox;
set => _collisionBox = value;
}
/// <summary>
@@ -27,17 +58,17 @@ namespace StgSharp
/// </summary>
public Sensor<PlainGeometry> CollisionSensor
{
get { return _collisionSensor; }
set { _collisionSensor = value; }
get => _collisionSensor;
set => _collisionSensor = value;
}
public string Texture { get; set; }
/// <summary>
/// A 2D vector presenting the position of an enemy entity, position can also be visited by X, Y
/// </summary>
public Vec2d Location { get; }
public string Texture { get; set; }
/// <summary>
/// X position of an enenmy entity
/// </summary>
@@ -48,11 +79,12 @@ namespace StgSharp
/// </summary>
public float Y { get; set; }
public abstract void OnRenderFrame();
public void SetLocation(Point p)
{
_pos = p;
}
public abstract void OnRenderFrame();
}
}
+35 -4
View File
@@ -1,23 +1,54 @@
using StgSharp.Entities;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Launcher.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.Math;
namespace StgSharp
{
public class Launcher<T> where T : IEntity
{
internal EntityPartical _bulletSample; //发射的子弹类型
/*
*用于发射其他的实体,主要是子弹 和 掉落物
*/
internal Vec2d _center; //发射器的参考位置,运动轨迹的方程应当基于这个参考点构建
internal Counter<int> _internalParameter; //发射器的内部计时器
internal EntityPartical _bulletSample; //发射的子弹类型
internal uint[] launchtick; //发射子弹的内部计时
public EntityPartical Bullet
{
get { return _bulletSample; }
set { _bulletSample = value; }
get => _bulletSample;
set => _bulletSample = value;
}
internal virtual void Launch()
+33 -1
View File
@@ -1,12 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Partical.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;
namespace StgSharp
{
public class Partical : IEntity
{
public override void OnRenderFrame()
{
throw new NotImplementedException();
}
}
}
+33 -5
View File
@@ -1,13 +1,41 @@
namespace StgSharp
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Player.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
{
public abstract class Player : IEntity
{
internal float _velocity;
public float Velocity
{
get { return _velocity; }
}
public float Velocity => _velocity;
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GlobalSetting.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.CompilerServices;
@@ -9,6 +39,7 @@ namespace StgSharp
{
public static unsafe partial class StgSharp
{
/// <summary>
/// Init an instance of OpenGL program,
/// This method should be called before any other StgSharp api.
@@ -28,17 +59,20 @@ namespace StgSharp
public static class GlobalSetting
{
private static bool vSyncActivated;
public static bool VSyncActivated
{
get { return vsyncActivated; }
get => vsyncActivated;
set
{
InternalIO.glfwSwapInterval(value ? 1 : 0);
vsyncActivated = value;
}
}
}
}
}
+69 -37
View File
@@ -1,4 +1,34 @@
// using StgSharp.Envitronment;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Platform.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.Envitronment;
// using StgSharp.Envitronment.Win32;
// using StgSharp.Graphics;
// using StgSharp.Math;
@@ -36,9 +66,17 @@ namespace StgSharp
public static partial class StgSharp
{
internal static GraphicAPI API = default;
private static bool vsyncActivated;
/// <summary>
/// Version of current StgSharp platform.
/// Main version represent in hundred's digit,
/// and sub version represent in ten's digit.
/// </summary>
public const long version = 430;
private static uint markCount = 0;
private static bool vsyncActivated;
internal static GraphicAPI API = default;
public static void Mark(bool needConsole)
{
@@ -49,12 +87,34 @@ namespace StgSharp
}
}
/// <summary>
/// Version of current StgSharp platform.
/// Main version represent in hundred's digit,
/// and sub version represent in ten's digit.
/// </summary>
public const long version = 430;
public static void Track(
object target,
string message,
bool isConsole,
[CallerFilePath] string filePath = "",
[CallerMemberName] string callerName = "",
[CallerLineNumber] int lineNumber = 0
)
{
Type t = target.GetType();
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
FieldInfo[] fieldInfo = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
foreach (FieldInfo field in fieldInfo)
{
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
}
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
log += $"Additional information:\n{message}\n";
if (isConsole)
{
Console.WriteLine(log);
}
else
{
InternalIO.InternalWriteLog(log, LogType.Info);
}
}
/// <summary>
/// Write a log message to log file, and mark the level of this message.
@@ -99,33 +159,5 @@ namespace StgSharp
}
}
public static void Track(
object target,
string message,
bool isConsole,
[CallerFilePath] string filePath = "",
[CallerMemberName] string callerName = "",
[CallerLineNumber] int lineNumber = 0
)
{
Type t = target.GetType();
string log = $"Tracked object: {nameof(target)}\t\tType:{t.Name}\n";
FieldInfo[] fieldInfo = t.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
log += "|\tFieldName\t|\tFieldType\t|\tFieldValue\t|\n";
foreach (FieldInfo field in fieldInfo)
{
log += $"|{field.Name}\t\t|{field.FieldType}\t\t|{field.GetValue(target)}\t\t|\n";
}
log += $"Tracking at:\n{filePath}\t{callerName}\tline {lineNumber}\n";
log += $"Additional information:\n{message}\n";
if (isConsole)
{
Console.WriteLine(log);
}
else
{
InternalIO.InternalWriteLog(log, LogType.Info);
}
}
}
}
@@ -1,79 +0,0 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp
{
public static partial class StgSharp
{
private static Stopwatch mainProvider = new Stopwatch();
private static List<TimeProvider> subscriberList = new List<TimeProvider>();
private static Thread timeProvideThread;
private static long accuracy;
private static void ProvideTime()
{
long totalMS, previousFrameMS = 0,
internalFrequncy = Stopwatch.Frequency;
lock (mainProvider)
{
mainProvider.Restart();
}
while (mainProvider.IsRunning)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
foreach (TimeProvider subscriber in subscriberList)
{
subscriber.CheckTime(totalMS);
}
}
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public static void TimerActivate(int maxFrameUpdateSensitiveTimeProviderCount)
{
if (!mainProvider.IsRunning)
{
mainProvider.Start();
//speed test
long totalMS, previousSecondMS = 0,
internalFrequncy = Stopwatch.Frequency;
for (int i = 0; i < 100; i++)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
for (int t = 0; t < 10; t++)
{
if (totalMS < 1000)
{
subscriberList.Add(new TimeProvider(100L));
}
}
}
mainProvider.Stop();
subscriberList.Clear();
totalMS = (mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L))) / 100L;
accuracy = totalMS * 2 / 3;
mainProvider.Reset();
timeProvideThread = new Thread(new ThreadStart(ProvideTime));
timeProvideThread.Start();
}
}
public static void SubscribeTimeProvider(TimeProvider provider)
{
}
public static void TimerDeactivate()
{
lock (mainProvider)
{
mainProvider.Stop();
}
}
}
}
@@ -0,0 +1,129 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeProvider.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.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
namespace StgSharp
{
public partial class StgSharp
{
internal static StgSharpTime mainTimeProvider;
}
public sealed class StgSharpTime : TimeSourceProviderBase
{
private static long accuracy;
private static Stopwatch mainProvider = new Stopwatch();
private static List<TimeSpanProvider> subscriberList = new List<TimeSpanProvider>();
private static Thread timeProvideThread;
internal StgSharpTime()
{
}
public static StgSharpTime OnlyInstance
=> StgSharp.mainTimeProvider;
public override sealed void StartProvidingTime()
{
if (mainProvider.IsRunning)
{
return;
}
mainProvider.Start();
//speed test
long totalMS, internalFrequncy = Stopwatch.Frequency;
for (int i = 0; i < 100; i++)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
for (int t = 0; t < 10; t++)
{
if (totalMS < 1000)
{
subscriberList.Add(new TimeSpanProvider(100L, TimeSpanProvider.DefaultProvider));
}
}
}
mainProvider.Stop();
subscriberList.Clear();
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L)) / 100L;
accuracy = (totalMS * 2) / 3;
mainProvider.Reset();
timeProvideThread = new Thread(new ThreadStart(ProvideTime));
timeProvideThread.Start();
}
[MethodImpl(MethodImplOptions.NoOptimization)]
public static void TimerActivate(int maxFrameUpdateSensitiveTimeProviderCount)
{
}
protected override sealed void AddSubscriberUnsynced(TimeSpanProvider subscriber)
{
subscriberList.Add(subscriber);
}
protected override sealed void RemoveSubscriberUnsynced(TimeSpanProvider subscriber)
{
subscriberList.Remove(subscriber);
}
private void ProvideTime()
{
long totalMS, internalFrequncy = Stopwatch.Frequency;
lock (mainProvider)
{
mainProvider.Restart();
}
while (mainProvider.IsRunning)
{
totalMS = mainProvider.ElapsedTicks / (internalFrequncy / (1000L * 1000L));
foreach (TimeSpanProvider subscriber in subscriberList)
{
if (subscriber.CheckTime(totalMS))
{
};
}
}
}
}
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
@@ -8,20 +39,40 @@ namespace StgSharp.Geometries
/// </summary>
public class Arc : PlainGeometry
{
internal Point center;
internal Point beginPoint;
internal Point center;
internal Point endPoint;
internal GetLocationHandler movCenterOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movBeginOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movCenterOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movEndOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal override int[] Indices => throw new NotImplementedException();
public virtual vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
public virtual vec3d MovBegin(uint tick) => movBeginOperation.Invoke(tick);
public override Plain GetPlain()
{
return new Plain(this.center, this.beginPoint, this.endPoint);
}
public virtual vec3d MovEnd(uint tick) => movEndOperation.Invoke(tick);
public virtual vec3d MovBegin(uint tick)
{
return movBeginOperation.Invoke(tick);
}
public virtual vec3d MoveCenter(uint tick)
{
return movCenterOperation.Invoke(tick);
}
public virtual vec3d MovEnd(uint tick)
{
return movEndOperation.Invoke(tick);
}
internal override void UpdateCoordinate(uint tick)
{
@@ -31,12 +82,5 @@ namespace StgSharp.Geometries
endPoint.Position = this.coordinate.origin + MovEnd(tick);
}
public override Line[] GetAllSides() => throw new NotImplementedException();
public override Plain GetPlain()
{
return new Plain(this.center, this.beginPoint, this.endPoint);
}
}
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
@@ -8,27 +39,42 @@ namespace StgSharp.Geometries
/// </summary>
public class Circle : PlainGeometry
{
internal Point center;
internal GetLocationHandler movBeginOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movCenterOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movEndOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal Point pointOnCircle;
internal Point pointOnPlain;
internal GetLocationHandler movCenterOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movBeginOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal GetLocationHandler movEndOperation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal override int[] Indices => throw new NotImplementedException();
public virtual vec3d MoveCenter(uint tick) => movCenterOperation.Invoke(tick);
public virtual vec3d UpdateRadius(uint tick) => movBeginOperation.Invoke(tick);
public virtual vec3d UpdatePlain(uint tick) => movEndOperation.Invoke(tick);
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
public override Plain GetPlain()
{
return new Plain(center, pointOnCircle, pointOnPlain);
}
public virtual vec3d MoveCenter(uint tick)
{
return movCenterOperation.Invoke(tick);
}
public virtual vec3d UpdatePlain(uint tick)
{
return movEndOperation.Invoke(tick);
}
public virtual vec3d UpdateRadius(uint tick)
{
return movBeginOperation.Invoke(tick);
}
internal override void UpdateCoordinate(uint tick)
{
@@ -38,9 +84,5 @@ namespace StgSharp.Geometries
pointOnPlain.Position = this.coordinate.origin + UpdatePlain(tick);
}
public override Line[] GetAllSides()
{
throw new NotImplementedException();
}
}
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cordinate.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;
@@ -12,30 +43,13 @@ namespace StgSharp.Geometries
[StructLayout(LayoutKind.Sequential)]
public struct PartialPlainCoordinate
{
/// <summary>
/// The origin of this coordinate.
/// </summary>
public vec3d origin;
internal Matrix3x2 axis;
/// <summary>
/// The horizontial axis of the coordinate.
/// Point to the right direction.
/// </summary>
public vec3d axis_H
{
get { return axis.colum0; }
}
/// <summary>
/// The vertical axis of the coordinate.
/// Point to the top direction.
/// </summary>
public vec3d axis_V
{
get { return axis.colum1; }
}
public PartialPlainCoordinate
(
vec3d origin,
@@ -52,6 +66,18 @@ namespace StgSharp.Geometries
axis.colum1 = vertical;
}
/// <summary>
/// The horizontial axis of the coordinate.
/// Point to the right direction.
/// </summary>
public vec3d axis_H => axis.colum0;
/// <summary>
/// The vertical axis of the coordinate.
/// Point to the top direction.
/// </summary>
public vec3d axis_V => axis.colum1;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d GetRealLocate(Vec2d raletiveLocation)
{
@@ -1,4 +1,34 @@
namespace StgSharp.Geometries
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
(
@@ -1,10 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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()
{
}
@@ -17,9 +51,6 @@ namespace StgSharp.Geometries
{
}
protected ToUpperDimensionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
/// <summary>
@@ -27,6 +58,10 @@ namespace StgSharp.Geometries
/// </summary>
public class UnusedVertexException : Exception
{
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public UnusedVertexException()
{
}
@@ -39,8 +74,5 @@ namespace StgSharp.Geometries
{
}
protected UnusedVertexException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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
{
@@ -11,10 +41,12 @@ namespace StgSharp.Geometries
public static unsafe class GeometryOperation
{
public static vec3d DefualtMotion(uint tick)
{
return default(vec3d);
}
}
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -6,24 +37,13 @@ namespace StgSharp.Geometries
{
public class Line : PlainGeometry
{
internal Point basePoint;
internal Point beginPoint;
internal Point endPoint;
internal GetLocationHandler movBegin;
internal GetLocationHandler movEnd;
internal override int[] Indices
{
get { throw new Exception(); }
}
public Line(Point begin, Point end)
{
this.beginPoint = begin;
this.endPoint = end;
}
internal Line(Vector4 begin, Vector4 end)
{
beginPoint = new Point(begin);
@@ -32,31 +52,15 @@ namespace StgSharp.Geometries
public Line() { }
/// <summary>
/// Move begin side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="GetLocationHandler"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
public virtual vec3d MoveBeginPoint(uint tick)
=> movBegin.Invoke(time);
/// <summary>
/// Move end side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="GetLocationHandler"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
/// <returns></returns>
public virtual vec3d MoveEndPoint(uint tick)
=> movEnd.Invoke(time);
internal override void UpdateCoordinate(uint tick)
public Line(Point begin, Point end)
{
beginPoint.Position = coordinate.origin + MoveBeginPoint(time);
endPoint.Position = coordinate.origin + MoveEndPoint(time);
this.beginPoint = begin;
this.endPoint = end;
}
internal override int[] Indices => throw new Exception();
public override Line[] GetAllSides()
{
throw new NotImplementedException();
@@ -66,5 +70,35 @@ namespace StgSharp.Geometries
{
throw new ToUpperDimensionException();
}
/// <summary>
/// Move begin side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="GetLocationHandler"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
public virtual vec3d MoveBeginPoint(uint tick)
{
return movBegin.Invoke(time);
}
/// <summary>
/// Move end side of a line.
/// It is recommended to override this function rather than
/// loading an <see cref="GetLocationHandler"/> with same function.
/// </summary>
/// <param name="tick">Time passed since current line was created.</param>
/// <returns></returns>
public virtual vec3d MoveEndPoint(uint tick)
{
return movEnd.Invoke(time);
}
internal override void UpdateCoordinate(uint tick)
{
beginPoint.Position = coordinate.origin + MoveBeginPoint(time);
endPoint.Position = coordinate.origin + MoveEndPoint(time);
}
}
}
@@ -1,19 +1,46 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Parallelogram.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.Math;
namespace StgSharp.Geometries
{
public class Parallelogram : Polygon4
{
internal Point center;
internal readonly GetLocationHandler movCenterOperation =
new GetLocationHandler(GeometryOperation.DefualtMotion);
public GetLocationHandler MovCenterOperation { get { return movCenterOperation; } }
public GetLocationHandler MovVertex01Operation { get { return moveVertex0Operation; } }
public GetLocationHandler MovVertex02Operation { get { return moveVertex1Operation; } }
public Parallelogram(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
@@ -35,6 +62,10 @@ namespace StgSharp.Geometries
}
}
public GetLocationHandler MovCenterOperation => movCenterOperation;
public GetLocationHandler MovVertex01Operation => moveVertex0Operation;
public GetLocationHandler MovVertex02Operation => moveVertex1Operation;
public virtual vec3d MovCenter(uint tick)
{
return movCenterOperation.Invoke(tick);
@@ -46,7 +77,7 @@ namespace StgSharp.Geometries
/// <param name="tick">Current time tick</param>
/// <returns></returns>
/// <exception cref="UnusedVertexException">Geometry overdefined</exception>
public sealed override vec3d MoveVertex2(uint tick)
public override sealed vec3d MoveVertex2(uint tick)
{
throw new UnusedVertexException();
}
@@ -57,12 +88,12 @@ namespace StgSharp.Geometries
/// <param name="tick">Current time tick</param>
/// <returns></returns>
/// <exception cref="UnusedVertexException">Geometry overdefined</exception>
public sealed override vec3d MoveVertex3(uint tick)
public override sealed vec3d MoveVertex3(uint tick)
{
throw new UnusedVertexException();
}
internal sealed override void UpdateCoordinate(uint tick)
internal override sealed void UpdateCoordinate(uint tick)
{
}
@@ -1,16 +1,48 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Plain.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.Numerics;
namespace StgSharp.Geometries
{
public unsafe class Plain
{
internal readonly float d = -1;
internal vec3d origin;
internal vec3d vec1;
internal vec3d vec2;
internal vec3d plainParameter;
internal readonly float d = -1;
internal vec3d vec1;
internal vec3d vec2;
internal Plain(Vector4 origin, Vector4 p1, Vector4 p2)
{
@@ -23,11 +55,11 @@ namespace StgSharp.Geometries
public Plain(vec3d o, vec3d v1, vec3d v2)
{
this.origin = o;
this.vec1 = v1 - v2 * (v1.Y / v2.Y); //计算平面在xz平面上的方向投影
this.vec2 = v2 - vec1 * (v2.X / v1.X); //计算平面在yz平面上的方向投影
this.vec1 = v1 - (v2 * (v1.Y / v2.Y)); //计算平面在xz平面上的方向投影
this.vec2 = v2 - (vec1 * (v2.X / v1.X)); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算plainParameter.Z;
plainParameter.Z = origin.Z - vec1.Z * (origin.X / vec1.X) - vec2.Z * (origin.Y / vec2.Y);
plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y));
//根据plainParameter.Z和对应的方向矢量计算plainParameter.X和plainParameter.Y
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
@@ -44,11 +76,11 @@ namespace StgSharp.Geometries
vec3d v2 = p3.Position - origin;
vec1 = v1 - v2 * (v1.Y / v2.Y); //计算平面在xz平面上的方向投影
vec2 = v2 - vec1 * (v2.X / v1.X); //计算平面在yz平面上的方向投影
vec1 = v1 - (v2 * (v1.Y / v2.Y)); //计算平面在xz平面上的方向投影
vec2 = v2 - (vec1 * (v2.X / v1.X)); //计算平面在yz平面上的方向投影
//|origin|-k1*|vec1|-k2*|vec2|计算plainParameter.Z;
plainParameter.Z = origin.Z - vec1.Z * (origin.X / vec1.X) - vec2.Z * (origin.Y / vec2.Y);
plainParameter.Z = origin.Z - (vec1.Z * (origin.X / vec1.X)) - (vec2.Z * (origin.Y / vec2.Y));
//根据plainParameter.Z和对应的方向矢量计算plainParameter.X和plainParameter.Y
plainParameter.X = vec1.X * (vec1.Z / plainParameter.Z);
plainParameter.Y = vec2.Y * (vec2.Z / plainParameter.Z);
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
namespace StgSharp.Geometries
@@ -8,34 +38,25 @@ namespace StgSharp.Geometries
/// </summary>
public abstract class PlainGeometry
{
protected TimeProvider time;
protected TimeSpanProvider time;
internal PartialPlainCoordinate coordinate;
internal Matrix2x4 textureFrame;
public PartialPlainCoordinate ReferenceCoordinate
public PlainGeometry()
{
get => this.coordinate;
}
/// <summary>
/// Tick time this geometry eas crested
/// </summary>
/// </summary>
public uint BornTime => time;
public PartialPlainCoordinate ReferenceCoordinate => this.coordinate;
internal abstract int[] Indices { get; }
public PlainGeometry(Form form)
{
time = new TimeProvider(form);
}
public PlainGeometry()
{ }
internal abstract void UpdateCoordinate(uint tick);
/// <summary>
/// Get all sides of this <see cref="PlainGeometry"/>.
/// </summary>
@@ -48,6 +69,9 @@ namespace StgSharp.Geometries
/// <returns></returns>
public abstract Plain GetPlain();
internal abstract void UpdateCoordinate(uint tick);
//public abstract Rectangle GetRenderFrame();
}
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -8,10 +39,9 @@ namespace StgSharp.Geometries
{
public unsafe class Point
{
internal vec3d position;
internal readonly bool isVertex;
public Point() { }
internal readonly bool isVertex;
internal vec3d position;
internal Point(vec3d p)
{
@@ -23,47 +53,40 @@ namespace StgSharp.Geometries
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 { return position; }
set { position = value; }
get => position;
set => position = value;
}
public float X
{
get { return position.X; }
set { position.X = value; }
get => position.X;
set => position.X = value;
}
public float Y
{
get { return position.Y; }
set { position.Y = value; }
get => position.Y;
set => position.Y = value;
}
public float Z
{
get { return position.Z; }
set { position.Z = value; }
get => position.Z;
set => position.Z = value;
}
public bool IsVertex => isVertex;
/// <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) { }
public bool IsInGeometry(PlainGeometry geo)
{
throw new NotImplementedException();
@@ -75,6 +98,15 @@ namespace StgSharp.Geometries
}
/// <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,11 +1,43 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon4.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.Math;
using System.Numerics;
namespace StgSharp.Geometries
{
public class Polygon4 : PlainGeometry
{
internal readonly GetLocationHandler moveVertex0Operation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal readonly GetLocationHandler moveVertex1Operation = new GetLocationHandler(GeometryOperation.DefualtMotion);
internal readonly GetLocationHandler moveVertex2Operation = new GetLocationHandler(GeometryOperation.DefualtMotion);
@@ -61,50 +93,39 @@ namespace StgSharp.Geometries
vertexMat.mat.colum3 = new Vector4(v3x, v3y, v3z, 0);
}
public GetLocationHandler MovVertex0Operaion { get { return moveVertex0Operation; } }
public GetLocationHandler MovVertex1Operaion { get { return moveVertex1Operation; } }
public GetLocationHandler MovVertex2Operaion { get { return moveVertex2Operation; } }
public GetLocationHandler MovVertex3Operaion { get { return moveVertex3Operation; } }
internal sealed override int[] Indices
{
get
{
return new int[6] {
0,1,2,
0,2,3};
}
}
public Mat4 VertexBuffer
{
get { return vertexMat.mat; }
}
public GetLocationHandler MovVertex0Operaion => moveVertex0Operation;
public GetLocationHandler MovVertex1Operaion => moveVertex1Operation;
public GetLocationHandler MovVertex2Operaion => moveVertex2Operation;
public GetLocationHandler MovVertex3Operaion => moveVertex3Operation;
public Point Vertex0
{
get => new Point(vertexMat.mat.colum0);
set { vertexMat.mat.colum0 = value.position.vec; }
set => vertexMat.mat.colum0 = value.position.vec;
}
public Point Vertex1
{
get => new Point(vertexMat.mat.colum1);
set { vertexMat.mat.colum1 = value.position.vec; }
set => vertexMat.mat.colum1 = value.position.vec;
}
public Point Vertex2
{
get => new Point(vertexMat.mat.colum2);
set { vertexMat.mat.colum1 = value.position.vec; }
set => vertexMat.mat.colum1 = value.position.vec;
}
public Mat4 VertexBuffer => vertexMat.mat;
internal override sealed int[] Indices => new int[6] { 0, 1, 2, 0, 2, 3 };
internal Point Vertex3
{
get => new Point(vertexMat.mat.colum3);
set { vertexMat.mat.colum1 = value.position.vec; }
set => vertexMat.mat.colum1 = value.position.vec;
}
@@ -131,21 +152,30 @@ namespace StgSharp.Geometries
}
public virtual vec3d MoveVertex0(uint tick)
=> moveVertex0Operation(tick);
{
return moveVertex0Operation(tick);
}
public virtual vec3d MoveVertex1(uint tick)
=> moveVertex1Operation(tick);
{
return moveVertex1Operation(tick);
}
public virtual vec3d MoveVertex2(uint tick)
=> moveVertex2Operation(tick);
{
return moveVertex2Operation(tick);
}
public virtual vec3d MoveVertex3(uint tick)
=> moveVertex3Operation(tick);
{
return moveVertex3Operation(tick);
}
internal override void UpdateCoordinate(uint tick)
{
}
}
}
@@ -1,12 +1,44 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon5.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.Math;
using StgSharp.Math.Linear;
using System.Numerics;
namespace StgSharp.Geometries
{
public unsafe class Polygon5 : PlainGeometry
{
internal Point _refOrigin;
internal GetLocationHandler movP01Operation = default;
internal GetLocationHandler movP02Operation = default;
@@ -35,57 +67,46 @@ namespace StgSharp.Geometries
}
public GetLocationHandler MovP01Operation { get => movP01Operation; }
public GetLocationHandler MovP02Operation { get => movP02Operation; }
public GetLocationHandler MovP03Operation { get => movP03Operation; }
public GetLocationHandler MovP04Operation { get => movP04Operation; }
public GetLocationHandler MovP05Operation { get => movP05Operation; }
public mat5 VertexBuffer
{
get { return vertexMat; }
}
public GetLocationHandler MovP01Operation => movP01Operation;
public GetLocationHandler MovP02Operation => movP02Operation;
public GetLocationHandler MovP03Operation => movP03Operation;
public GetLocationHandler MovP04Operation => movP04Operation;
public GetLocationHandler MovP05Operation => movP05Operation;
public Point Vertex0
{
get => new Point(vertexMat.vec0);
set { vertexMat.vec0 = value.position.vec; }
set => vertexMat.vec0 = value.position.vec;
}
public Point Vertex1
{
get => new Point(vertexMat.vec1);
set { vertexMat.vec1 = value.position.vec; }
set => vertexMat.vec1 = value.position.vec;
}
public Point Vertex2
{
get => new Point(vertexMat.vec2);
set { vertexMat.vec2 = value.position.vec; }
set => vertexMat.vec2 = value.position.vec;
}
public Point Vertex3
{
get => new Point(vertexMat.vec3);
set { vertexMat.vec3 = value.position.vec; }
set => vertexMat.vec3 = value.position.vec;
}
public Point Vertex4
{
get => new Point(vertexMat.vec4);
set { vertexMat.vec4 = value.position.vec; }
set => vertexMat.vec4 = value.position.vec;
}
internal override int[] Indices
{
get
{
return new int[9]{
0,1,2,
0,2,3,
0,3,4};
}
}
public mat5 VertexBuffer => vertexMat;
internal override int[] Indices => new int[9] { 0, 1, 2, 0, 2, 3, 0, 3, 4 };
public override Line[] GetAllSides()
{
return new Line[5]
@@ -103,15 +124,30 @@ namespace StgSharp.Geometries
return new Plain(Vertex0, Vertex1, Vertex2);
}
public virtual vec3d movVertex01(uint tick) => movP01Operation.Invoke(time);
public virtual vec3d movVertex01(uint tick)
{
return movP01Operation.Invoke(time);
}
public virtual vec3d movVertex02(uint tick) => movP02Operation.Invoke(time);
public virtual vec3d movVertex02(uint tick)
{
return movP02Operation.Invoke(time);
}
public virtual vec3d movVertex03(uint tick) => movP03Operation.Invoke(time);
public virtual vec3d movVertex03(uint tick)
{
return movP03Operation.Invoke(time);
}
public virtual vec3d movVertex04(uint tick) => movP04Operation.Invoke(time);
public virtual vec3d movVertex04(uint tick)
{
return movP04Operation.Invoke(time);
}
public virtual vec3d movVertex05(uint tick) => movP05Operation.Invoke(time);
public virtual vec3d movVertex05(uint tick)
{
return movP05Operation.Invoke(time);
}
internal override void UpdateCoordinate(uint tick)
@@ -123,5 +159,6 @@ namespace StgSharp.Geometries
vertexMat.vec3 = (coordinate.origin + movVertex04(nowTick)).vec;
vertexMat.vec4 = (coordinate.origin + movVertex05(nowTick)).vec;
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Polygon6.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.Math;
using StgSharp.Math.Linear;
@@ -8,6 +38,7 @@ namespace StgSharp.Geometries
{
public class Polygon6 : PlainGeometry
{
internal Point _refOrigin;
internal GetLocationHandler movVertex0Operation;
internal GetLocationHandler movVertex1Operation;
@@ -17,61 +48,51 @@ namespace StgSharp.Geometries
internal GetLocationHandler movVertex5Operation;
internal mat6 vertexMat;
public GetLocationHandler MovVertex0Operation { get => movVertex0Operation; }
public GetLocationHandler MovVertex1Operation { get => movVertex1Operation; }
public GetLocationHandler MovVertex2Operation { get => movVertex2Operation; }
public GetLocationHandler MovVertex3Operation { get => movVertex3Operation; }
public GetLocationHandler MovVertex4Operation { get => movVertex4Operation; }
public GetLocationHandler MovVertex5Operation { get => movVertex5Operation; }
internal override int[] Indices
{
get
{
return new int[12] {
0,1,2,
0,2,3,
0,3,4,
0,4,5};
}
}
public GetLocationHandler MovVertex0Operation => movVertex0Operation;
public GetLocationHandler MovVertex1Operation => movVertex1Operation;
public GetLocationHandler MovVertex2Operation => movVertex2Operation;
public GetLocationHandler MovVertex3Operation => movVertex3Operation;
public GetLocationHandler MovVertex4Operation => movVertex4Operation;
public GetLocationHandler MovVertex5Operation => movVertex5Operation;
public Point Vertex0
{
get => new Point(vertexMat.vec0);
set { vertexMat.vec0 = value.position.vec; }
set => vertexMat.vec0 = value.position.vec;
}
public Point Vertex1
{
get => new Point(vertexMat.vec1);
set { vertexMat.vec1 = value.position.vec; }
set => vertexMat.vec1 = value.position.vec;
}
public Point Vertex2
{
get => new Point(vertexMat.vec2);
set { vertexMat.vec2 = value.position.vec; }
set => vertexMat.vec2 = value.position.vec;
}
public Point Vertex3
{
get => new Point(vertexMat.vec3);
set { vertexMat.vec3 = value.position.vec; }
set => vertexMat.vec3 = value.position.vec;
}
public Point Vertex4
{
get => new Point(vertexMat.vec4);
set { vertexMat.vec4 = value.position.vec; }
set => vertexMat.vec4 = value.position.vec;
}
public Point Vertex5
{
get => new Point(vertexMat.vec5);
set { vertexMat.vec5 = value.position.vec; }
set => vertexMat.vec5 = value.position.vec;
}
internal override int[] Indices => new int[12] { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5 };
public override Line[] GetAllSides()
{
return new Line[6]
@@ -131,5 +152,6 @@ namespace StgSharp.Geometries
vertexMat.vec4 = origin + movVertex4(nowTick).vec;
vertexMat.vec5 = origin + movVertex5(nowTick).vec;
}
}
}
@@ -1,10 +1,42 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Rectangle.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.Numerics;
namespace StgSharp.Geometries
{
public class Rectangle : Parallelogram
{
public Rectangle(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
@@ -30,7 +62,10 @@ namespace StgSharp.Geometries
/// </summary>
/// <param name="tick">当前游戏刻</param>
/// <returns></returns>
public virtual vec3d MovCenter(uint tick) => default(vec3d);
public virtual vec3d MovCenter(uint tick)
{
return default(vec3d);
}
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Square.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.Numerics;
namespace StgSharp.Geometries
@@ -9,6 +40,7 @@ namespace StgSharp.Geometries
/// </summary>
public class Square : Rectangle
{
public Square(
float v0x, float v0y, float v0z,
float v1x, float v1y, float v1z,
@@ -21,7 +53,7 @@ namespace StgSharp.Geometries
{
}
public sealed override vec3d MoveVertex1(uint tick)
public override sealed vec3d MoveVertex1(uint tick)
{
return default;
}
@@ -1,5 +1,36 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Triangle.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.Math;
using System.Numerics;
namespace StgSharp.Geometries
@@ -46,15 +77,9 @@ namespace StgSharp.Geometries
public GetLocationHandler MovVertex02Operation => this.movVertex02Opearion;
public GetLocationHandler MovVertex03Operation => this.movVertex03Opearion;
public Mat3 VertexBuffer
{
get { return vertexMat.mat; }
}
public Mat3 VertexBuffer => vertexMat.mat;
internal sealed override int[] Indices
{
get { return new int[3] { 0, 1, 2 }; }
}
internal override sealed int[] Indices => new int[3] { 0, 1, 2 };
public override Line[] GetAllSides()
{
@@ -73,18 +98,28 @@ namespace StgSharp.Geometries
return new Plain(this.vertexMat.mat.colum0, this.vertexMat.mat.colum1, this.vertexMat.mat.colum2);
}
public virtual vec3d MovVertex01(uint tick) => movVertex01Opearion.Invoke(tick);
public virtual vec3d MovVertex01(uint tick)
{
return movVertex01Opearion.Invoke(tick);
}
public virtual vec3d MovVertex02(uint tick) => movVertex02Opearion.Invoke(tick);
public virtual vec3d MovVertex02(uint tick)
{
return movVertex02Opearion.Invoke(tick);
}
public virtual vec3d MovVertex03(uint tick) => movVertex03Opearion.Invoke(tick);
public virtual vec3d MovVertex03(uint tick)
{
return movVertex03Opearion.Invoke(tick);
}
internal sealed override void UpdateCoordinate(uint tick)
internal override sealed void UpdateCoordinate(uint tick)
{
tick = time;
vertexMat.mat.colum0 = coordinate.origin.vec + MovVertex01(time).vec;
vertexMat.mat.colum1 = coordinate.origin.vec + MovVertex02(time).vec;
vertexMat.mat.colum2 = coordinate.origin.vec + MovVertex03(time).vec;
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
+297 -159
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="StructDefine.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.InteropServices;
/**/
@@ -16,6 +46,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWcontext
{
private int client;
private int source;
private int major, minor, revision;
@@ -51,6 +82,7 @@ namespace StgSharp.Graphics
internal struct egl
{
/*
EGLConfig config;
EGLContext handle;
@@ -60,16 +92,19 @@ namespace StgSharp.Graphics
private void* handle;
private void* surface;
private void* client;
}
internal struct osmesa
{
//OSMesaContext handle;
private void* handle;
private int width;
private int height;
private void* buffer;
}
// This is defined in platform.h
@@ -79,6 +114,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWvidmode
{
/*! The width, in screen coordinates, of the video mode.
*/
public int width;
@@ -97,11 +133,13 @@ namespace StgSharp.Graphics
/*! The refresh rate, in Hz, of the video mode.
*/
private int refreshRate;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWgammaramp
{
/*! An array of value describing the response of the red channel.
*/
private ushort* red;
@@ -114,11 +152,13 @@ namespace StgSharp.Graphics
/*! The number of elements in each array.
*/
private uint size;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWimage
{
/*! The width, in pixels, of this image.
*/
private int width;
@@ -128,11 +168,13 @@ namespace StgSharp.Graphics
/*! The pixel data of this image, arranged left-to-right, top-to-bottom.
*/
private byte* pixels;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWgamepadstate
{
/*! The states of each [gamepad button](@ref gamepad_buttons), `GLFW_PRESS`
* or `GLFW_RELEASE`.
*/
@@ -141,11 +183,13 @@ namespace StgSharp.Graphics
* to 1.0 inclusive.
*/
public fixed float axes[6];
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWallocator
{
//GLFWallocatefun allocate;
private IntPtr allocate;
@@ -156,11 +200,13 @@ namespace StgSharp.Graphics
private IntPtr deallocate;
private void* user;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmonitor
{
private byte[] name = new byte[128];
private void* userPointer;
@@ -185,53 +231,116 @@ namespace StgSharp.Graphics
public GLFWmonitor()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWwindow
{
//struct GLFWwindow* next in GLFW
public IntPtr next = IntPtr.Zero;
public GLFWwindow* next;
public bool resizable = false;
public bool decorated = false;
public bool autoIconify = false;
public bool floating = false;
public bool focusOnShow = false;
public bool mousePassthrough = false;
public bool shouldClose = false;
public void* userPointer = (void*)0;
public bool doublebuffer = false;
public GLFWvidmode videoMode = default;
public IntPtr monitor = IntPtr.Zero; //public GLFWmonitor* monitor;
public GLFWcursor* cursor = (GLFWcursor*)0;
private int resizable;
private int decorated;
private int autoIconify;
private int floating;
private int focusOnShow;
private int mousePassthrough;
internal int shouldClose;
private void* userPointer = (void*)0;
private bool doubleBuffer;
private GLFWvidmode videoMode = default;
private IntPtr monitor = IntPtr.Zero; //public GLFWmonitor* monitor;
private GLFWcursor* cursor = (GLFWcursor*)0;
public int minwidth = 0, minheight = 0;
public int maxwidth = 0, maxheight = 0;
public int numer = 0, denom = 0;
public bool stickyKeys = false;
public bool stickyMouseButtons = false;
public bool lockKeyMods = false;
public int cursorMode = 0;
public fixed byte mouseButtons[8];
public fixed byte keys[349];
private int minWidth = 0, minHeight = 0;
private int maxWidth = 0, maxHeight = 0;
private int numer = 0, denom = 0;
private int stickyKeys;
private int stickyMouseButtons;
private int lockKeyMods;
private int cursorMode = 0;
private fixed byte mouseButtons[8];
private fixed byte keys[349];
// Virtual cursor position when cursor is disabled
public double virtualCursorPosX = 0, virtualCursorPosY = 0;
public bool rawMouseMotion = false;
private int rawMouseMotion;
public GLFWcontext context = default;
private fixed long callBacks[17];
public GLFWwindow()
{
}
public bool AutoIconify
{
get => autoIconify != 0;
set => autoIconify = value ? 1 : 0;
}
public bool Decorated
{
get => decorated != 0;
set => decorated = value ? 1 : 0;
}
public bool Floating
{
get => floating != 0;
set => floating = value ? 1 : 0;
}
public bool FocusOnShow
{
get => focusOnShow != 0;
set => focusOnShow = value ? 1 : 0;
}
public bool LockKeyMods
{
get => lockKeyMods != 0;
set => lockKeyMods = value ? 1 : 0;
}
public bool MousePassThrough
{
get => mousePassthrough != 0;
set => mousePassthrough = value ? 1 : 0;
}
public bool RawMouseMotion { get => rawMouseMotion != 0; set => rawMouseMotion = value ? 1 : 0; }
public bool Resizable
{
get => resizable != 0;
set => resizable = value ? 1 : 0;
}
public bool ShouldClose
{
get => shouldClose != 0;
set => shouldClose = value ? 1 : 0;
}
public bool StickyKey
{
get => stickyKeys != 0;
set => stickyKeys = value ? 1 : 0;
}
public bool StickyMouseButtons
{
get => stickyMouseButtons != 0;
set => stickyMouseButtons = value ? 1 : 0;
}
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWwindowCallback
{
}
[StructLayout(LayoutKind.Sequential)]
public struct GLFWcursor
{
//GLFWcursor* next;
private IntPtr next;
@@ -259,6 +368,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWinitconfig
{
private GLFWbool hatButtons;
private int angleType;
private int platformID;
@@ -266,26 +376,12 @@ namespace StgSharp.Graphics
//PFN_vkGetInstanceProcAddr vulkanLoader;
private IntPtr vulkanLoader;
private struct ns
{
private GLFWbool menubar;
private GLFWbool chdir;
}
private struct x11
{
private GLFWbool xcbVulkanSurface;
}
private struct wl
{
private int libdecorMode;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWwndconfig
{
private int xpos;
private int ypos;
private int width;
@@ -303,56 +399,66 @@ namespace StgSharp.Graphics
private GLFWbool mousePassthrough;
private GLFWbool scaleToMonitor;
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[256];
public Ns()
{
}
}
internal Ns ns = new Ns();
internal struct X11
{
public fixed byte className[256];
public fixed byte instanceName[256];
public X11()
{
}
}
internal X11 x11 = new X11();
internal struct Win32
{
private GLFWbool keymenu;
}
internal Win32 win32 = new Win32();
internal struct Wl
{
public fixed byte appId[256];
public Wl()
{
}
}
internal Wl wl = new Wl();
public GLFWwndconfig()
{
}
internal struct Ns
{
private GLFWbool retina = false;
public fixed byte frameName[256];
public Ns()
{
}
}
internal struct X11
{
public fixed byte className[256];
public fixed byte instanceName[256];
public X11()
{
}
}
internal struct Win32
{
private GLFWbool keymenu;
}
internal struct Wl
{
public fixed byte appId[256];
public Wl()
{
}
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWctxconfig
{
private int client;
private int source;
private int major;
@@ -367,21 +473,25 @@ namespace StgSharp.Graphics
//GLFWwindow* share;
private IntPtr share;
internal struct Nsgl
{
private GLFWbool offline;
}
internal Nsgl nsgl = new Nsgl();
public GLFWctxconfig()
{
}
internal struct Nsgl
{
private GLFWbool offline;
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWfbconfig
{
private int redBits;
private int greenBits;
private int blueBits;
@@ -399,25 +509,18 @@ namespace StgSharp.Graphics
private GLFWbool doublebuffer;
private GLFWbool transparent;
private uintptr_t handle;
}
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct GLFWlibrary
{
private GLFWbool initialized;
private GLFWallocator allocator;
private GLFWplatform platform;
internal unsafe struct Hints
{
private GLFWinitconfig init;
private GLFWfbconfig framebuffer;
private GLFWwndconfig window;
private GLFWctxconfig context;
private int refreshRate;
}
internal Hints hints = new Hints();
//GLFWerror* errorListHead;
@@ -448,8 +551,30 @@ namespace StgSharp.Graphics
private GLFWls contextSlot;
private GLFWmutex errorLock;
internal Egl egl = new Egl();
internal Osmesa osmesa = new Osmesa();
internal Callbacks callbacks = new Callbacks();
public GLFWlibrary()
{
}
internal unsafe struct Hints
{
private GLFWinitconfig init;
private GLFWfbconfig framebuffer;
private GLFWwndconfig window;
private GLFWctxconfig context;
private int refreshRate;
}
internal unsafe struct timer
{
private ulong offset;
// This is defined in platform.h
@@ -459,6 +584,7 @@ namespace StgSharp.Graphics
internal unsafe struct Egl
{
internal int platform;
internal void* display;
internal int major, minor;
@@ -466,7 +592,7 @@ namespace StgSharp.Graphics
internal bool KHR_create_context;
internal bool KHR_create_context_no_error;
internal bool KHR_colorspace;
internal bool KHR_colorSpace;
internal bool KHR_get_all_proc_addresses;
internal bool KHR_context_flush_control;
internal bool EXT_client_extensions;
@@ -501,12 +627,12 @@ namespace StgSharp.Graphics
internal IntPtr GetPlatformDisplayEXT;
internal IntPtr CreatePlatformWindowSurfaceEXT;
}
internal Egl egl = new Egl();
}
internal unsafe struct Osmesa
{
private void* handle;
private IntPtr CreateContextExt;
@@ -516,12 +642,12 @@ namespace StgSharp.Graphics
private IntPtr GetColorBuffer;
private IntPtr GetDepthBuffer;
private IntPtr GetProcAddress;
}
internal Osmesa osmesa = new Osmesa();
}
internal unsafe struct vk
{
private GLFWbool available;
private void* handle;
private fixed ulong extensions[2];
@@ -537,33 +663,34 @@ namespace StgSharp.Graphics
public vk()
{
}
}
internal unsafe struct Callbacks
{
private IntPtr monitor;
private IntPtr joystick;
}
internal Callbacks callbacks = new Callbacks();
public GLFWlibrary()
{
}
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapelement
{
private byte type;
private byte index;
private sbyte axisScale;
private sbyte axisOffset;
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWmapping
{
private fixed byte name[128];
private fixed byte guid[33];
@@ -575,11 +702,13 @@ namespace StgSharp.Graphics
public GLFWmapping()
{ }
}
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWjoystick
{
private GLFWbool allocated;
private GLFWbool connected;
private float* axes;
@@ -601,6 +730,7 @@ namespace StgSharp.Graphics
public GLFWjoystick()
{ }
}
[StructLayout(LayoutKind.Sequential)]
@@ -614,6 +744,7 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
public unsafe struct GLFWplatform
{
private int platformID;
// init
@@ -623,73 +754,75 @@ namespace StgSharp.Graphics
//void (* terminate) (void);
private IntPtr terminate;
// input
#region input
/* void (* getCursorPos) (GLFWwindow*, double*, double*);
void (* setCursorPos) (GLFWwindow*, double, double);
void (* setCursorMode) (GLFWwindow*, int);
void (* setRawMouseMotion) (GLFWwindow*, GLFWbool);
GLFWbool(*rawMouseMotionSupported)(void);
GLFWbool(*createCursor)(GLFWcursor*,const GLFWimage*,int,int);
GLFWbool(*createStandardCursor)(GLFWcursor*, int);
void (* destroyCursor) (GLFWcursor*);
void (* setCursor) (GLFWwindow*, GLFWcursor*);
const byte* (*getScancodeName)(int);
int (* getKeyScancode) (int);
void (* setClipboardString) (const byte*);
const byte* (*getClipboardString)(void);
GLFWbool(*initJoysticks)(void);
void (* terminateJoysticks) (void);
GLFWbool(*pollJoystick)(GLFWjoystick*, int);
const byte* (*getMappingName)(void);
void (* updateGamepadGUID) (byte*);
// monitor
void (* freeMonitor) (GLFWmonitor*);
void (* getMonitorPos) (GLFWmonitor*, int*, int*);
void (* getMonitorContentScale) (GLFWmonitor*, float*, float*);
void (* getMonitorWorkarea) (GLFWmonitor*, int*, int*, int*, int*);
GLFWvidmode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, GLFWvidmode*);
GLFWbool(*getGammaRamp)(GLFWmonitor*, GLFWgammaramp*);
void (* setGammaRamp) (GLFWmonitor*,const GLFWgammaramp*);
void (* setCursorPos) (GLFWwindow*, double, double);
void (* setCursorMode) (GLFWwindow*, int);
void (* setRawMouseMotion) (GLFWwindow*, GLFWbool);
GLFWbool(*rawMouseMotionSupported)(void);
GLFWbool(*createCursor)(GLFWcursor*,const GLFWimage*,int,int);
GLFWbool(*createStandardCursor)(GLFWcursor*, int);
void (* destroyCursor) (GLFWcursor*);
void (* setCursor) (GLFWwindow*, GLFWcursor*);
const byte* (*getScancodeName)(int);
int (* getKeyScancode) (int);
void (* setClipboardString) (const byte*);
const byte* (*getClipboardString)(void);
GLFWbool(*initJoysticks)(void);
void (* terminateJoysticks) (void);
GLFWbool(*pollJoystick)(GLFWjoystick*, int);
const byte* (*getMappingName)(void);
void (* updateGamepadGUID) (byte*);
// monitor
void (* freeMonitor) (GLFWmonitor*);
void (* getMonitorPos) (GLFWmonitor*, int*, int*);
void (* getMonitorContentScale) (GLFWmonitor*, float*, float*);
void (* getMonitorWorkarea) (GLFWmonitor*, int*, int*, int*, int*);
GLFWvidmode* (* getVideoModes) (GLFWmonitor*, int*);
void (* getVideoMode) (GLFWmonitor*, GLFWvidmode*);
GLFWbool(*getGammaRamp)(GLFWmonitor*, GLFWgammaramp*);
void (* setGammaRamp) (GLFWmonitor*,const GLFWgammaramp*);
// window
GLFWbool(*createWindow)(GLFWwindow*,const GLFWwndconfig*,const GLFWctxconfig*,const GLFWfbconfig*);
void (* destroyWindow) (GLFWwindow*);
void (* setWindowTitle) (GLFWwindow*,const byte*);
void (* setWindowTitle) (GLFWwindow*,const byte*);
void (* setWindowIcon) (GLFWwindow*, int,const GLFWimage*);
void (* getWindowPos) (GLFWwindow*, int*, int*);
void (* setWindowPos) (GLFWwindow*, int, int);
void (* getWindowSize) (GLFWwindow*, int*, int*);
void (* setWindowSize) (GLFWwindow*, int, int);
void (* setWindowSizeLimits) (GLFWwindow*, int, int, int, int);
void (* setWindowAspectRatio) (GLFWwindow*, int, int);
void (* getFramebufferSize) (GLFWwindow*, int*, int*);
void (* getWindowFrameSize) (GLFWwindow*, int*, int*, int*, int*);
void (* getWindowContentScale) (GLFWwindow*, float*, float*);
void (* iconifyWindow) (GLFWwindow*);
void (* restoreWindow) (GLFWwindow*);
void (* maximizeWindow) (GLFWwindow*);
void (* showWindow) (GLFWwindow*);
void (* hideWindow) (GLFWwindow*);
void (* requestWindowAttention) (GLFWwindow*);
void (* focusWindow) (GLFWwindow*);
void (* setWindowMonitor) (GLFWwindow*, GLFWmonitor*, int, int, int, int, int);
GLFWbool(*windowFocused)(GLFWwindow*);
GLFWbool(*windowIconified)(GLFWwindow*);
GLFWbool(*windowVisible)(GLFWwindow*);
GLFWbool(*windowMaximized)(GLFWwindow*);
GLFWbool(*windowHovered)(GLFWwindow*);
GLFWbool(*framebufferTransparent)(GLFWwindow*);
float (* getWindowOpacity) (GLFWwindow*);
void (* setWindowResizable) (GLFWwindow*, GLFWbool);
void (* setWindowDecorated) (GLFWwindow*, GLFWbool);
void (* setWindowFloating) (GLFWwindow*, GLFWbool);
void (* setWindowOpacity) (GLFWwindow*, float);
void (* setWindowMousePassthrough) (GLFWwindow*, GLFWbool);
void (* pollEvents) (void);
void (* waitEvents) (void);
void (* waitEventsTimeout) (double);
void (* postEmptyEvent) (void);
void (* setWindowPos) (GLFWwindow*, int, int);
void (* getWindowSize) (GLFWwindow*, int*, int*);
void (* setWindowSize) (GLFWwindow*, int, int);
void (* setWindowSizeLimits) (GLFWwindow*, int, int, int, int);
void (* setWindowAspectRatio) (GLFWwindow*, int, int);
void (* getFramebufferSize) (GLFWwindow*, int*, int*);
void (* getWindowFrameSize) (GLFWwindow*, int*, int*, int*, int*);
void (* getWindowContentScale) (GLFWwindow*, float*, float*);
void (* iconifyWindow) (GLFWwindow*);
void (* restoreWindow) (GLFWwindow*);
void (* maximizeWindow) (GLFWwindow*);
void (* showWindow) (GLFWwindow*);
void (* hideWindow) (GLFWwindow*);
void (* requestWindowAttention) (GLFWwindow*);
void (* focusWindow) (GLFWwindow*);
void (* setWindowMonitor) (GLFWwindow*, GLFWmonitor*, int, int, int, int, int);
GLFWbool(*windowFocused)(GLFWwindow*);
GLFWbool(*windowIconified)(GLFWwindow*);
GLFWbool(*windowVisible)(GLFWwindow*);
GLFWbool(*windowMaximized)(GLFWwindow*);
GLFWbool(*windowHovered)(GLFWwindow*);
GLFWbool(*framebufferTransparent)(GLFWwindow*);
float (* getWindowOpacity) (GLFWwindow*);
void (* setWindowResizable) (GLFWwindow*, GLFWbool);
void (* setWindowDecorated) (GLFWwindow*, GLFWbool);
void (* setWindowFloating) (GLFWwindow*, GLFWbool);
void (* setWindowOpacity) (GLFWwindow*, float);
void (* setWindowMousePassthrough) (GLFWwindow*, GLFWbool);
void (* pollEvents) (void);
void (* waitEvents) (void);
void (* waitEventsTimeout) (double);
void (* postEmptyEvent) (void);
*/
#endregion
internal IntPtr setCursorPos;
internal IntPtr setCursorMode;
internal IntPtr setRawMouseMotion;
@@ -776,6 +909,7 @@ namespace StgSharp.Graphics
internal IntPtr VkPhysicalDevice;
internal IntPtr GLFWwindow;
}
[StructLayout(LayoutKind.Sequential)]
@@ -790,12 +924,14 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Sequential)]
internal unsafe struct VkExtensionProperties
{
private fixed byte extensionName[256];
private uint specVersion;
public VkExtensionProperties()
{
}
}
/*
@@ -816,11 +952,13 @@ namespace StgSharp.Graphics
[StructLayout(LayoutKind.Explicit, Size = 16)]
public struct uintptr_t
{
[FieldOffset(0)]
private long part1;
[FieldOffset(8)]
private long part2;
}
#endregion GLFW3 struct
@@ -1,4 +1,34 @@
/*
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiDefine.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
/*
* This file is created to link functions in OpenGL to version in C#
* The name of delegates and organization to init all these delegates
* are refferd from GLAD1 in agreement of MIT license generated from
@@ -7,12 +37,19 @@
using StgSharp.Math;
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace StgSharp.Graphics
{
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
#endregion
/// <summary>
/// Function handler to load an opengl function by serching its name.
/// </summary>
@@ -143,12 +180,6 @@ namespace StgSharp.Graphics
//[UnmanagedFunctionPointer(callingConvention: CallingConvention.Cdecl, CharSet = CharSet.Ansi)] internal unsafe delegate VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion
#region StgSharpDele
public unsafe delegate void FrameBufferSizeHandler(IntPtr window, uint width, uint height);
#endregion
#region glDEBUG
+35 -5
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glConst.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;
namespace StgSharp.Graphics
{
@@ -22,10 +52,10 @@ namespace StgSharp.Graphics
internal const int GLFW_HAT_RIGHT = 2;
internal const int GLFW_HAT_DOWN = 4;
internal const int GLFW_HAT_LEFT = 8;
internal const int GLFW_HAT_RIGHT_UP = (GLFW_HAT_RIGHT | GLFW_HAT_UP);
internal const int GLFW_HAT_RIGHT_DOWN = (GLFW_HAT_RIGHT | GLFW_HAT_DOWN);
internal const int GLFW_HAT_LEFT_UP = (GLFW_HAT_LEFT | GLFW_HAT_UP);
internal const int GLFW_HAT_LEFT_DOWN = (GLFW_HAT_LEFT | GLFW_HAT_DOWN);
internal const int GLFW_HAT_RIGHT_UP = GLFW_HAT_RIGHT | GLFW_HAT_UP;
internal const int GLFW_HAT_RIGHT_DOWN = GLFW_HAT_RIGHT | GLFW_HAT_DOWN;
internal const int GLFW_HAT_LEFT_UP = GLFW_HAT_LEFT | GLFW_HAT_UP;
internal const int GLFW_HAT_LEFT_DOWN = GLFW_HAT_LEFT | GLFW_HAT_DOWN;
internal const int GLFW_KEY_UNKNOWN = -1;
internal const int GLFW_KEY_SPACE = 32;
internal const int GLFW_KEY_APOSTROPHE = 39;
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Graphics
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glEnum.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.Graphics
{
internal enum VkStructureType : uint
{
+61 -29
View File
@@ -1,4 +1,35 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glType.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 System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -9,35 +40,10 @@ using System.Text;
namespace StgSharp.Graphics
{
public delegate IntPtr GLfuncLoader(string name);
internal delegate void GLVULKANPROCNV();
#region GLFW_dele
internal unsafe delegate void GLFWwindowsizefun(GLFWwindow* window, int width, int height);
internal unsafe delegate void GLFWwindowrefreshfun(GLFWwindow* window);
internal unsafe delegate void GLFWwindowposfun(GLFWwindow* window, int xpos, int ypos);
internal unsafe delegate void GLFWwindowmaximizefun(GLFWwindow* window, int maximized);
internal unsafe delegate void GLFWwindowiconifyfun(GLFWwindow* window, int iconified);
internal unsafe delegate void GLFWwindowfocusfun(GLFWwindow* window, int focused);
internal unsafe delegate void GLFWwindowcontentscalefun(GLFWwindow* window, float xscale, float yscale);
internal unsafe delegate void GLFWwindowclosefun(GLFWwindow* window);
internal unsafe delegate void GLFWvkproc();
internal unsafe delegate void GLFWscrollfun(GLFWwindow* window, double xoffset, double yoffset);
internal unsafe delegate void GLFWmousebuttonfun(GLFWwindow* window, int button, int action, int mods);
internal unsafe delegate void GLFWmonitorfun(GLFWmonitor* monitor, int monitorevent);
internal unsafe delegate void GLFWkeyfun(GLFWwindow* window, int key, int scancode, int action, int mods);
internal unsafe delegate void GLFWjoystickfun(int jid, int keyevent);
public unsafe delegate void GLFWglproc();
internal unsafe delegate void FramebuffersizeHandler(IntPtr window, int width, int height); //window is the pointer to a GLFWwindow instance
internal unsafe delegate void GLFWerrorfun(int error_code, sbyte* description);
internal unsafe delegate void GLFWdropfun(GLFWwindow* window, int path_count, sbyte*[] paths);
internal unsafe delegate void GLFWcursorposfun(GLFWwindow* window, double xpos, double ypos);
internal unsafe delegate void GLFWcursorenterfun(GLFWwindow* window, int entered);
internal unsafe delegate void GLFWcharmodsfun(GLFWwindow* window, uint codepoint, int mods);
internal unsafe delegate void GLFWcharfun(GLFWwindow* window, uint codepoint);
#endregion
public unsafe struct GLhandleARB
{
@@ -80,6 +86,32 @@ namespace StgSharp.Graphics
}
public delegate IntPtr GLfuncLoader(string name);
#region GLFW_dele
internal unsafe delegate void GLFWwindowsizefun(GLFWwindow* window, int width, int height);
internal unsafe delegate void GLFWwindowrefreshfun(GLFWwindow* window);
internal unsafe delegate void GLFWwindowposfun(GLFWwindow* window, int xpos, int ypos);
internal unsafe delegate void GLFWwindowmaximizefun(GLFWwindow* window, int maximized);
internal unsafe delegate void GLFWwindowiconifyfun(GLFWwindow* window, int iconified);
internal unsafe delegate void GLFWwindowfocusfun(GLFWwindow* window, int focused);
internal unsafe delegate void GLFWwindowcontentscalefun(GLFWwindow* window, float xscale, float yscale);
internal unsafe delegate void GLFWwindowclosefun(GLFWwindow* window);
internal unsafe delegate void GLFWvkproc();
internal unsafe delegate void GLFWscrollfun(GLFWwindow* window, double xoffset, double yoffset);
internal unsafe delegate void GLFWmousebuttonfun(GLFWwindow* window, int button, int action, int mods);
internal unsafe delegate void GLFWmonitorfun(GLFWmonitor* monitor, int monitorevent);
internal unsafe delegate void GLFWkeyfun(GLFWwindow* window, int key, int scancode, int action, int mods);
internal unsafe delegate void GLFWjoystickfun(int jid, int keyevent);
public unsafe delegate void GLFWglproc();
internal unsafe delegate void FramebuffersizeHandler(IntPtr window, int width, int height); //window is the pointer to a GLFWwindow instance
internal unsafe delegate void GLFWerrorfun(int error_code, sbyte* description);
internal unsafe delegate void GLFWdropfun(GLFWwindow* window, int path_count, sbyte*[] paths);
internal unsafe delegate void GLFWcursorposfun(GLFWwindow* window, double xpos, double ypos);
internal unsafe delegate void GLFWcursorenterfun(GLFWwindow* window, int entered);
internal unsafe delegate void GLFWcharmodsfun(GLFWwindow* window, uint codepoint, int mods);
internal unsafe delegate void GLFWcharfun(GLFWwindow* window, uint codepoint);
#endregion
}
+107 -129
View File
@@ -1,20 +1,41 @@
using StgSharp;
using StgSharp.Controlling;
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Form.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.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Threading;
@@ -23,52 +44,45 @@ namespace StgSharp.Graphics
/// <summary>
///
/// </summary>
public abstract partial class Form
public abstract unsafe partial class Form
{
#region metadata
internal LinkedList<Control> allControl;
internal Vector4 backgroundColor;
internal IglFunc gl;
internal unsafe IntPtr graphicContextID;
internal IntPtr graphicContextID;
internal int height;
internal IntPtr monitor;
internal string name;
internal Form sharedForm;
internal int width;
internal IntPtr windowID;
protected readonly TimeProvider FrameTimeFrocider;
private GLFWwindow* windowID;
internal TimeSpanProvider frameTimeProvider;
#endregion metadata
#region form thread setting
private bool isSingleThread = true;
#endregion form thread setting
#region glapicount
private int missingAPIcount = 0;
private int problemAPIcount = 0;
#endregion glapicount
#region form main
#region form thread setting
private bool isSingleThread = true;
#endregion form thread setting
private int _shouldClose = 0;
protected Form()
{
}
/// <summary>
/// OpenGL package used by current form context.
/// OpenGL package binded to current form context.
/// A OpenGL context is only binded to current form.
/// </summary>
public IglFunc GL
{
get => gl;
internal set => gl = value;
}
public IglFunc GL => gl;
/// <summary>
/// Height of this form, represent in <see cref="int"/>
@@ -82,24 +96,13 @@ namespace StgSharp.Graphics
/// <summary>
/// Representing
/// </summary>
public bool IsDoubleRendering
{
get { return isSingleThread; }
}
public bool IsDoubleRendering => isSingleThread;
public bool ShouldClose
{
get
{
Interlocked.Exchange(ref _shouldClose, InternalIO.glfwWindowShouldClose(windowID));
return 0 != _shouldClose;
}
get => InternalIO.glfwWindowShouldClose(windowID) != 0;
set
{
InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
Interlocked.Exchange(ref _shouldClose, value ? 1 : 0);
}
set => InternalIO.glfwSetWindowShouldClose(windowID, value ? 1 : 0);
}
/// <summary>
@@ -107,7 +110,7 @@ namespace StgSharp.Graphics
/// </summary>
public Vec2d Size
{
get { return new Vec2d(width, height); }
get => new Vec2d(width, height);
set
{
width = (int)value.X;
@@ -124,10 +127,9 @@ namespace StgSharp.Graphics
set => width = value;
}
internal bool IsSingleThread
{
get { return isSingleThread; }
}
public unsafe IntPtr WindowID => (IntPtr)windowID;
internal unsafe GLFWwindow* id => windowID;
protected FrameBufferSizeHandler FrameBufferSizeCallback
{
@@ -138,12 +140,15 @@ namespace StgSharp.Graphics
}
}
internal bool IsSingleThread => isSingleThread;
/// <summary>
/// Init an OpenGl context if current form has not been binded to any context.
/// and set the context binded to current form as current OpenGL context.
/// Init an OpenGl context if current form has not been binded to any context. and set the context binded to
/// current form as current OpenGL context.
/// </summary>
/// <exception cref="Exception">Something goes wrong and
/// StgSharp fails in creating a new OpenGL context. </exception>
/// <exception cref="Exception">
/// Something goes wrong and StgSharp fails in creating a new OpenGL context.
/// </exception>
public unsafe void MakeAsCurrentContext()
{
if (windowID == default)
@@ -152,21 +157,19 @@ namespace StgSharp.Graphics
byte[] tittleBytes = Encoding.UTF8.GetBytes(name);
if (sharedForm == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, sharedForm.windowID);
windowPtr = InternalIO.glfwCreateWindow(width, height, tittleBytes, monitor, sharedForm.windowID);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
else
{
windowID = windowPtr;
windowID = (GLFWwindow*)windowPtr;
}
graphicContextID = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(GLcontext)));
@@ -191,18 +194,6 @@ namespace StgSharp.Graphics
this.monitor = monitor;
}
/// <summary>
/// Resize the current form
/// </summary>
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
/// Resize the current form
/// </summary>
@@ -217,18 +208,15 @@ namespace StgSharp.Graphics
}
/// <summary>
/// Set the size limit of current form
/// Resize the 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 curent 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)
/// <param name="width">New width of the window</param>
/// <param name="height">New height of the window</param>
public void SetSize(int width, int height)
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
minWidth, minHeight, maxWidth, maxHeight);
this.Width = width;
this.Height = height;
InternalIO.glfwSetWindowSize(this.windowID, width, height);
}
/// <summary>
@@ -245,19 +233,26 @@ namespace StgSharp.Graphics
{
InternalIO.glfwSetWindowSizeLimits(
this.windowID,
(int)minSize.X, (int)minSize.Y, (int)maxSize.X, (int)maxSize.Y);
(int)minSize.X,
(int)minSize.Y,
(int)maxSize.X,
(int)maxSize.Y);
}
unsafe ~Form()
{
Marshal.FreeHGlobal(graphicContextID);
}
/// <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 curent 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)
{ InternalIO.glfwSetWindowSizeLimits(this.windowID, minWidth, minHeight, maxWidth, maxHeight); }
#region form main
unsafe ~Form() { Marshal.FreeHGlobal(graphicContextID); }
private static unsafe delegate*<void> pollEventPtr = &InternalIO.glfwPollEvents;
private static unsafe delegate*<void> swapBufferPtr = &InternalSwapBuffers;
public abstract void Deinit(params object[] args);
@@ -268,22 +263,14 @@ namespace StgSharp.Graphics
public abstract void Init(params object[] args);
/// <summary>
/// Behaviour of current form when in a render cycle.
/// When this form
/// Behaviour of current form when in a render cycle. When this form
/// </summary>
/// <param name="args"></param>
public abstract void Main(params object[] args);
public unsafe void PollEvents()
{
if (isSingleThread)
{
InternalIO.glfwPollEvents();
}
else
{
gl.frameworkHandleEnqueue((IntPtr)pollEventPtr);
}
InternalIO.glfwPollEvents();
}
/// <summary>
@@ -303,61 +290,49 @@ namespace StgSharp.Graphics
{
Main(args);
SwapBuffers();
PollEvents();
}
}
else
{
GLonUpdate update = new GLonUpdate((GLcontext*)graphicContextID);
FrameThread renderThread = new FrameThread(update);
FrameThread updateThread = new FrameThread(update);
renderThread.SetNext(updateThread);
updateThread.SetNext(renderThread);
FrameAsyncTask renderTask = new FrameAsyncTask(update);
FrameAsyncTask updateTask = new FrameAsyncTask(update);
gl = update;
int a = 0;
while (!ShouldClose)
{
renderTask.StartAsync();
updateTask.StartAsync();
FrameAsyncTask.CombineAsync(renderTask, updateTask);
SwapBuffers();
PollEvents();
}
//TODO 对逻辑线程和渲染线程进行同步,两种gl模式包需要改名字
}
}
}
internal static unsafe void InternalSwapBuffers()
internal static unsafe void InternalSwapBuffers(FrameOperationBuffer operationBuffer, GLcontext* context)
{
IntPtr winHandle = default;
InternalIO.glfwSwapBuffers(winHandle);
IntPtr window = default;
operationBuffer.TryDequeue(out window);
InternalIO.glfwSwapBuffers((GLFWwindow*)window);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalDeinit(params object[] args)
{
Deinit(args);
}
internal void InternalDeinit(params object[] args) { Deinit(args); }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalInit(params object[] args)
{
Init(args);
}
internal unsafe void SwapBuffers()
{
if (isSingleThread)
{
InternalIO.glfwSwapBuffers(windowID);
}
else
{
M128 m = new M128();
m.Write<ulong>(0, (ulong)windowID);
gl.frameworkHandleEnqueue((IntPtr)swapBufferPtr, m);
}
InternalIO.glfwSwapBuffers(windowID);
}
/// <summary>
/// Get OpenGL library of this form's context.
/// </summary>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs </returns>
/// <returns>A <see cref="IglFunc"/> package contains all opengl APIs</returns>
protected IglFunc GetGL()
{
if (StgSharp.API == GraphicAPI.GL)
@@ -366,7 +341,9 @@ namespace StgSharp.Graphics
}
else
{
InternalIO.InternalWriteLog("Attempt to get OpenGL API package in other graphic envitronment.", LogType.Error);
InternalIO.InternalWriteLog(
"Attempt to get OpenGL API package in other graphic envitronment.",
LogType.Error);
throw new InvalidOperationException("Attempt to get OpenGL API package in other graphic envitronment.");
}
}
@@ -396,7 +373,8 @@ namespace StgSharp.Graphics
throw new ArgumentException("Amount of threads should be bigger than 0");
}
}
#endregion form main
}
}
@@ -1,11 +1,39 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="FrameAsyncTask.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.Runtime.CompilerServices;
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;
@@ -14,9 +42,10 @@ namespace StgSharp.Graphics
{
internal sealed class FrameOperationBuffer
{
private readonly unsafe GLcontext* currentContext;
private IntPtr _func;
private ConcurrentQueue<IntPtr> _funcQueue;
private readonly unsafe GLcontext* currentContext;
public unsafe bool CallNext()
{
@@ -451,50 +480,52 @@ namespace StgSharp.Graphics
/**/
#endregion gl param queue
}
internal sealed class FrameThread
//TODO 任务组绑定机制有问题,现在一次只能绑定两个
//TODO 目前还不能加载任何任务
//TODO 任务的启动逻辑需要重构
internal class FrameAsyncTask
{
private Thread _thread;
private FrameOperationBuffer renderBuffer;
private SemaphoreSlim renderCompleteSemaphore = new SemaphoreSlim(1, 1);
private SemaphoreSlim renderStartSemaphore;
private bool shouldTerminate;
private FrameOperationBuffer updateBuffer;
internal FrameThread(GLonUpdate gl)
private SemaphoreSlim _refrshSemaphore;
private SemaphoreSlim _frameCompleteSemaphore;
private Task _task;
private FrameOperationBuffer opBuffer = new FrameOperationBuffer();
internal FrameAsyncTask(GLonUpdate gl)
{
updateBuffer = gl.ActivatedOperationBuffer;
_thread = new Thread(new ThreadStart(PrivateMain));
}
public bool IsRunning
public static void ExchangeBuffer(FrameAsyncTask task0, FrameAsyncTask task1)
{
get { return _thread.IsAlive; }
FrameOperationBuffer cache = task0.opBuffer;
task0.opBuffer = task1.opBuffer;
task1.opBuffer = cache;
}
public void Start()
public async Task StartAsync()
{
_thread.Start();
_task.Start();
await _task;
}
public void Terminate()
public static SemaphoreSlim CombineAsync(FrameAsyncTask task0, FrameAsyncTask task1)
{
shouldTerminate = true;
SemaphoreSlim refresh = new SemaphoreSlim(2);
task0._refrshSemaphore = refresh;
task1._refrshSemaphore = refresh;
return refresh;
}
public static SemaphoreSlim AsyncWait(FrameAsyncTask task0, FrameAsyncTask task1)
{
SemaphoreSlim refresh = new SemaphoreSlim(2);
task0._refrshSemaphore = refresh;
task1._refrshSemaphore = refresh;
return refresh;
}
private void PrivateMain()
{
renderStartSemaphore.Wait();
while (shouldTerminate && renderBuffer.CallNext())
{ }
renderCompleteSemaphore.Release();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetNext(FrameThread thread)
{
renderStartSemaphore = thread.renderCompleteSemaphore;
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BufferObjectBase.cs"
// Project: StgSharp
// AuthorGroup: Nitload Space
// Copyright (c) Nitload Space. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the “Software”), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and
// this permission notice shall be included in all copies
// or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”,
// WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics
/// </summary>
public abstract class BufferObjectBase : IDisposable
{
protected glHandleSet _bufferHandle;
protected IglFunc GL;
@@ -19,10 +50,7 @@ namespace StgSharp.Graphics
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public glHandle this[int index]
{
get { return _bufferHandle[index]; }
}
public glHandle this[int index] => _bufferHandle[index];
/// <summary>
/// Bind a buffer instance to OpenGL
@@ -30,6 +58,12 @@ namespace StgSharp.Graphics
/// <param name="index">Index of handle of the object in this instance to be bind</param>
public abstract void Bind(int index);
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
/// <inheritdoc/>
public override string ToString()
{
@@ -43,10 +77,5 @@ namespace StgSharp.Graphics
Dispose(disposing: false);
}
public void Dispose()
{
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="EBO.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;
@@ -15,6 +45,7 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe class ElementBuffer : BufferObjectBase
{
internal ElementBuffer(int n, IglFunc gl)
{
GL = gl;
@@ -41,5 +72,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VAO.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.Runtime.CompilerServices;
using System.Text;
@@ -7,6 +37,7 @@ namespace StgSharp.Graphics
{
public unsafe class VertexArray : BufferObjectBase
{
internal VertexArray(int n, IglFunc gl)
{
GL = gl;
@@ -42,5 +73,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="VBO.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;
@@ -12,6 +42,7 @@ namespace StgSharp.Graphics
{
public unsafe class VertexBuffer : BufferObjectBase
{
internal VertexBuffer(int n, IglFunc glFunc)
{
GL = glFunc;
@@ -72,5 +103,6 @@ namespace StgSharp.Graphics
_bufferHandle.Release();
}
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -12,10 +42,11 @@ namespace StgSharp.Graphics
{
public unsafe class Texture
{
internal static bool[] unitActivated = new bool[16];
private IglFunc GL;
internal glHandleSet _textureHandle;
internal Image[] sourceList;
private IglFunc GL;
internal Texture(int n, IglFunc gl)
{
@@ -96,6 +127,7 @@ namespace StgSharp.Graphics
}
#endregion texture setting
}
public enum Filter
+67 -44
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLhandle.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.Data.Common;
using System.Linq;
@@ -18,12 +48,14 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe struct glHandle
{
internal glHandleSet source;
internal uint* valuePtr;
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
private glHandle(IntPtr handle)
{
this.valuePtr = (uint*)handle;
source = null;
}
internal glHandle(uint* val, glHandleSet set)
@@ -32,15 +64,9 @@ namespace StgSharp.Graphics
valuePtr = val;
}
private glHandle(IntPtr handle)
[Obsolete("Cannot init instance of this type", true)]
public glHandle()
{
this.valuePtr = (uint*)handle;
source = null;
}
public static glHandle Zero
{
get { return Alloc(0); }
}
public IntPtr Handle
@@ -75,13 +101,9 @@ namespace StgSharp.Graphics
}
}
internal uint DirectValue
{
get
{
return *valuePtr;
}
}
public static glHandle Zero => Alloc(0);
internal uint DirectValue => *valuePtr;
public static glHandle Alloc(uint value)
{
@@ -97,10 +119,12 @@ namespace StgSharp.Graphics
{
return new glHandle(handle);
}
}
public unsafe struct glSHandle
{
internal glHandleSet source;
internal int* valuePtr;
@@ -110,29 +134,25 @@ namespace StgSharp.Graphics
valuePtr = val;
}
public static glSHandle Zero
{
get { return Alloc(0); }
}
public static glSHandle Zero => Alloc(0);
internal int DirectValue
{
get { return *valuePtr; }
}
internal int DirectValue => *valuePtr;
public static glSHandle Alloc(int value)
{
glSHandle ret = default;
ret.source = new glHandleSet(1);
ret.valuePtr = (int*)ret.source.handle;
*ret.valuePtr = (int)value;
*ret.valuePtr = value;
return ret;
}
}
//TODO 发现一个大问题,paramQueue大多数时候取出的是数组,不是数组句柄,也就是说其内存将被长期固定且不能回收,这是内存泄漏
public unsafe class glArrayHandle
{
internal readonly Array a;
internal GCHandle handle;
@@ -142,20 +162,6 @@ namespace StgSharp.Graphics
handle = GCHandle.Alloc(array, GCHandleType.Pinned);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
{
Array copy = new T[array.Length];
array.CopyTo(copy, 0);
return new glArrayHandle(copy);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public IntPtr AddressOfArray()
{
@@ -169,11 +175,26 @@ namespace StgSharp.Graphics
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle Alloc<T>(T[] array) where T : struct
{
return new glArrayHandle(array);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static glArrayHandle CopyAlloc<T>(T[] array) where T : struct
{
Array copy = new T[array.Length];
array.CopyTo(copy, 0);
return new glArrayHandle(copy);
}
public void Release()
{
handle.Free();
handle = default;
}
}
/// <summary>
@@ -181,9 +202,10 @@ namespace StgSharp.Graphics
/// </summary>
public unsafe class glHandleSet
{
private readonly uint[] _value;
internal uint* handle;
internal int length;
private readonly uint[] _value;
public glHandleSet(int count)
{
@@ -212,13 +234,13 @@ namespace StgSharp.Graphics
{
throw new IndexOutOfRangeException();
}
return new glSHandle((int*)handle + index, this);
return new glSHandle(((int*)handle) + index, this);
}
}
public static void Copy(in glHandleSet source, glHandleSet target)
{
if (source == null || target == null)
if ((source == null) || (target == null))
{
throw new NullReferenceException();
}
@@ -279,5 +301,6 @@ namespace StgSharp.Graphics
{
_value[index] = value;
}
}
}
+91 -60
View File
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonRender.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 StgSharp.Math;
using System;
@@ -12,23 +42,15 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonRender : IglFunc
{
internal GLcontext* api;
private FrameTimeoutException refreshSIgnal = new FrameTimeoutException();
internal GLcontext* api;
internal GLonRender(GLcontext* context)
{
api = context;
}
GLcontext* IglFunc.Context
{
get => api;
}
void IglFunc.SwitchContext()
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.ActiveTexture(uint type)
{
@@ -87,35 +109,6 @@ namespace StgSharp.Graphics
while (api->glGetError() != 0) { }
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
ret.SetValue(i, id);
}
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.CompileShader(glHandle shaderhandle)
{
@@ -139,6 +132,25 @@ namespace StgSharp.Graphics
return h;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
glHandleSet IglFunc.CreateShaderSet(int count, ShaderType type)
{
glHandleSet ret = new glHandleSet(count);
uint t = (uint)type;
for (int i = 0; i < count; i++)
{
uint id = api->glCreateShader(t);
if (id == 0)
{
uint error = api->glGetError();
InternalIO.InternalWriteLog($"Failed in creating shader: {error}", LogType.Error);
throw new Exception();
}
ret.SetValue(i, id);
}
return ret;
}
unsafe IntPtr IglFunc.CreateWindowHandle(
int width, int height, string tittle, IntPtr monitor, Form share)
{
@@ -147,15 +159,15 @@ namespace StgSharp.Graphics
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.windowID);
width, height, tittleBytes, monitor, share.id);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
@@ -180,14 +192,14 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteBuffers(glHandleSet handle)
{
api->glDeleteBuffers((uint)handle.length, (uint*)handle.handle);
api->glDeleteBuffers((uint)handle.length, handle.handle);
handle.Free();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.DeleteVertexArrays(glHandleSet arrays)
{
api->glDeleteVertexArrays((uint)arrays.length, (uint*)arrays.handle);
api->glDeleteVertexArrays((uint)arrays.length, arrays.handle);
arrays.Free();
}
@@ -211,18 +223,22 @@ namespace StgSharp.Graphics
default:
InternalIO.InternalWriteLog(
$"Parameter error in parameter {nameof(type)} method DrawElements. " +
$"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.",
$"{($"Parameter error in parameter {nameof(type)} method DrawElements. ")}{($"Only {typeof(uint).Name},{typeof(ushort).Name},{typeof(byte).Name} types are suporrted.")}",
LogType.Error);
return;
}
api->glDrawElements((uint)mode, count, a, (void*)ptr);
}
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
{
throw new InvalidOperationException();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet((int)count);
glHandleSet h = new glHandleSet(count);
api->glGenBuffers((uint)count, h.handle);
return h;
}
@@ -230,7 +246,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe glHandleSet IglFunc.GenTextures(int count)
{
glHandleSet h = new glHandleSet((int)count);
glHandleSet h = new glHandleSet(count);
api->glGenTextures((uint)count, h.handle);
return h;
}
@@ -256,18 +272,28 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
return InternalIO.glfwWindowShouldClose(form.id) == 0;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
{
byte[] stream = Encoding.UTF8.GetBytes(codeStream);
fixed (byte* streamPtr = stream)
{
api->glShaderSource(shaderHandle.DirectValue, 1, &streamPtr, (void*)0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.MakeContexCurrent(Form form)
{
if (form.windowID == IntPtr.Zero)
if (form.WindowID == IntPtr.Zero)
{
InternalIO.InternalWriteLog($"From {nameof(form)} is not initted.", LogType.Warning);
return;
}
InternalIO.glfwMakeContextCurrent(form.windowID);
InternalIO.glfwMakeContextCurrent(form.id);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -290,11 +316,13 @@ namespace StgSharp.Graphics
return;
}
fixed (void* bufferPtr = bufferArray)
{
api->glBufferData(
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
(uint)bufferType,
(IntPtr)size,
(IntPtr)bufferPtr,
(uint)usage);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -305,6 +333,10 @@ namespace StgSharp.Graphics
api->glEnableVertexAttribArray(index);
}
void IglFunc.SwitchContext()
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.TextureImage2d<T>(int target, int level, uint internalformat, uint width, uint height, uint format, uint type, glHandle pixels)
{
@@ -331,9 +363,8 @@ namespace StgSharp.Graphics
api->glViewport(x, y, width, height);
}
void IglFunc.frameworkHandleEnqueue(System.IntPtr handle, params M128[] param)
{
throw new InvalidOperationException();
}
GLcontext* IglFunc.Context
=> api;
}
}
+65 -37
View File
@@ -1,4 +1,34 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdate.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 StgSharp.Math;
using System;
@@ -15,10 +45,10 @@ namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private GLcontext* api;
private IntPtr SwapBufferPtr = (IntPtr)(delegate*<IntPtr, void>)&InternalIO.glfwSwapBuffers;
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
private FrameOperationBuffer frameOpBuffer;
private glSHandle unupdatedFrame = glSHandle.Alloc(0);
internal GLonUpdate(GLcontext* context)
{
@@ -29,15 +59,19 @@ namespace StgSharp.Graphics
api = context;
}
GLcontext* IglFunc.Context
{
get => api;
}
public FrameOperationBuffer ActivatedOperationBuffer
{
get { return frameOpBuffer; }
set { frameOpBuffer = value; }
get => frameOpBuffer;
set => frameOpBuffer = value;
}
public void GLswapBuffers(Form form)
{
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwSwapBuffers(form.id);
}
void IglFunc.ActiveTexture(uint type)
@@ -77,7 +111,7 @@ namespace StgSharp.Graphics
void IglFunc.BindTexture(uint type, glHandle texture)
{
M128 m = default;
m.Write<uint>(0, (uint)type);
m.Write<uint>(0, type);
m.Write<ulong>(1, (ulong)texture.valuePtr);
frameOpBuffer.ParamEnqueue(m);
frameOpBuffer.MethodEnqueue(BindTexturePtr);
@@ -156,15 +190,15 @@ namespace StgSharp.Graphics
if (share == null)
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, IntPtr.Zero);
width, height, tittleBytes, monitor, (GLFWwindow*)IntPtr.Zero);
}
else
{
windowPtr = InternalIO.glfwCreateWindow(
width, height, tittleBytes, monitor, share.windowID);
width, height, tittleBytes, monitor, share.id);
}
if ((long)windowPtr == -1 || (long)windowPtr == -2)
if (((long)windowPtr == -1) || ((long)windowPtr == -2))
{
throw new Exception("Cannot create window instance!");
}
@@ -229,8 +263,7 @@ namespace StgSharp.Graphics
default:
InternalIO.InternalWriteLog(
$"Parameter error in parameter {type} method DrawElements. " +
$"Only {TypeCode.Byte}, {TypeCode.UInt16}, {TypeCode.UInt32} types are suporrted.",
$"{($"Parameter error in parameter {type} method DrawElements. ")}{($"Only {TypeCode.Byte}, {TypeCode.UInt16}, {TypeCode.UInt32} types are suporrted.")}",
LogType.Error);
return;
}
@@ -239,6 +272,16 @@ namespace StgSharp.Graphics
frameOpBuffer.MethodEnqueue(DrawElementsPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
foreach (M128 item in param)
{
frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
unsafe glHandleSet IglFunc.GenBuffers(int count)
{
glHandleSet h = new glHandleSet(count);
@@ -282,16 +325,7 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool IglFunc.GetWindowShouldClose(Form form)
{
return InternalIO.glfwWindowShouldClose(form.windowID) == 0;
}
public void GLswapBuffers(Form form)
{
if (form.windowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwSwapBuffers(form.windowID);
return InternalIO.glfwWindowShouldClose(form.id) == 0;
}
void IglFunc.LoadShaderSource(glHandle shaderHandle, string codeStream)
@@ -304,11 +338,11 @@ namespace StgSharp.Graphics
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.MakeContexCurrent(Form form)
{
if (form.windowID == IntPtr.Zero)
if (form.WindowID == IntPtr.Zero)
{
return;
}
InternalIO.glfwMakeContextCurrent(form.windowID);
InternalIO.glfwMakeContextCurrent(form.id);
}
void IglFunc.SetBufferData<T>(BufferType bufferType, T bufferData, BufferUsage usage)
@@ -370,14 +404,8 @@ namespace StgSharp.Graphics
frameOpBuffer.MethodEnqueue(ViewPortPtr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
void IglFunc.frameworkHandleEnqueue(IntPtr methodHandle, params M128[] param)
{
foreach (M128 item in param)
{
frameOpBuffer.ParamEnqueue(item);
}
frameOpBuffer.ParamEnqueue(methodHandle);
}
GLcontext* IglFunc.Context
=> api;
}
}
@@ -1,28 +1,49 @@
using StgSharp.Logic;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLonUpdateInternal.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.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Graphics
{
internal unsafe partial class GLonUpdate : IglFunc
{
private IntPtr ActiveTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalActiveTexture;
private IntPtr AttachShaderPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalAttachShader;
private IntPtr BindBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindBuffer;
private IntPtr BindTexturePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindTexture;
private IntPtr BindVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalBindVertexArray;
private IntPtr BufferDataPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetBufferData;
private IntPtr CanUpdatePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalFrameCanUpdate;
private IntPtr ClearColorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearColor;
private IntPtr ClearGraphicErrorPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClearGraphicError;
private IntPtr ClearPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalClear;
@@ -35,7 +56,6 @@ namespace StgSharp.Graphics
private IntPtr DrawElementsPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalDrawElements;
private IntPtr GenBufferPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenBuffers;
private IntPtr GenTexturesPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenTextures;
private IntPtr GenVertexArraysPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGenVertexArrays;
private IntPtr GetUniformLocationPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalGetUniformLocation;
private IntPtr SetVertexArrayPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalSetVertexAttribute;
private IntPtr ShaderSourcePtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&InternalShaderSource;
@@ -147,7 +167,7 @@ namespace StgSharp.Graphics
activatedContext->glDeleteBuffers(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
for (int i = 0; i < m.Read<uint>(2); i++)
{
*((uint*)m.Read<ulong>(0) + i) = 0;
*(((uint*)m.Read<ulong>(0)) + i) = 0;
}
}
@@ -167,13 +187,6 @@ namespace StgSharp.Graphics
activatedContext->glDrawElements(mode, count, type, (void*)ptr);
}
private static void InternalFrameCanUpdate(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr ptr;
frameBuffer.TryDequeue(out ptr);
Interlocked.Add(ref *(int*)ptr, -1);
}
private static void InternalGenBuffers(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
@@ -188,13 +201,6 @@ namespace StgSharp.Graphics
activatedContext->glGenTextures(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGenVertexArrays(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameBuffer.TryDequeue(out m);
activatedContext->glGenVertexArrays(m.Read<uint>(2), (uint*)m.Read<ulong>(0));
}
private static void InternalGetUniformLocation(FrameOperationBuffer frameBuffer, GLcontext* activatedContext)
{
IntPtr programHandle = default, nameHandle = default, targetHandle = default;
@@ -265,14 +271,5 @@ namespace StgSharp.Graphics
activatedContext->glViewport(m.Read<int>(0), m.Read<int>(1), m.Read<uint>(2), m.Read<uint>(3));
}
private void InternalMakeContexCurrent(Form form)
{
throw new NotImplementedException();
}
private void InternalSwitchContext()
{
throw new NotImplementedException();
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLresourceGenrator.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.CompilerServices;
@@ -9,6 +39,7 @@ namespace StgSharp.Graphics
{
public partial class Form
{
/// <summary>
/// Create a set of <see cref="ElementBuffer"/>.
/// </summary>
@@ -20,17 +51,6 @@ namespace StgSharp.Graphics
return new ElementBuffer(count, this.gl);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(int count)
{
return new VertexArray(count, gl);
}
/// <summary>
/// Create a sets of <see cref="Texture"/>
/// </summary>
@@ -42,6 +62,17 @@ namespace StgSharp.Graphics
return new Texture(count, this.GL);
}
/// <summary>
/// Create a set of <see cref="VertexArray"/>.
/// </summary>
/// <param name="count">Amount of VAO to be crated.</param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected VertexArray CreateVertexArray(int count)
{
return new VertexArray(count, gl);
}
/// <summary>
/// Create aset of <see cref="VertexBuffer"/>.
/// </summary>
@@ -52,5 +83,6 @@ namespace StgSharp.Graphics
{
return new VertexBuffer(count, gl);
}
}
}
@@ -1,4 +1,34 @@
using StgSharp;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Shader.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 System;
using System.Collections.Generic;
@@ -10,6 +40,12 @@ namespace StgSharp.Graphics
{
public partial class Form
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
}
/// <summary>
/// Create an instance of <see cref="Shader"/> program
/// </summary>
@@ -20,18 +56,14 @@ namespace StgSharp.Graphics
return new ShaderProgram(GL);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected Shader CreateShader(ShaderType type, int count)
{
return new Shader(this.gl, gl.CreateShaderSet(count, type), type);
}
}
public class Shader
{
private readonly IglFunc GL;
internal readonly glHandleSet handle;
public readonly ShaderType type;
private readonly IglFunc GL;
internal Shader(IglFunc gl, glHandleSet handle, ShaderType usage)
{
@@ -40,17 +72,6 @@ namespace StgSharp.Graphics
type = usage;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
{
if (code == null)
{
throw new ArgumentNullException("Must provide enough code");
}
GL.LoadShaderSource(handle[index], code + '\0');
GL.CompileShader(handle[index]);
}
//TODO:写链接着色器的文档注释
/// <summary>
///
@@ -63,16 +84,29 @@ namespace StgSharp.Graphics
GL.AttachShader(target.handle, handle[index]);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void Compile(int index, string code)
{
if (code == null)
{
throw new ArgumentNullException("Must provide enough code");
}
GL.LoadShaderSource(handle[index], $"{code}\0");
GL.CompileShader(handle[index]);
}
public override string ToString()
{
return $"This is a {type} shader, its shader handles are {handle.ToString()}.";
}
}
public class ShaderProgram
{
internal readonly glHandle handle;
private readonly IglFunc GL;
internal readonly glHandle handle;
/// <summary>
/// Inti a shader with no program attached.
@@ -83,29 +117,6 @@ namespace StgSharp.Graphics
handle = GL.CreateProgram();
}
/// <summary>
/// Link the shader to current context.
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram(GL.Context, handle.Value) == 0)
{
IntPtr logPtr = InternalIO.InternalReadSSCLog();
try
{
byte[] logByte = new byte[512];
Marshal.Copy(logPtr, logByte, 0, 512);
string log = Encoding.UTF8.GetString(logByte);
log = log.Replace("\0", "");
InternalIO.InternalWriteLog(log, LogType.Error);
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
}
}
}
/// <summary>
/// Get a uniform form current shader,
/// the value type of the uniform should be provided.
@@ -145,6 +156,29 @@ namespace StgSharp.Graphics
return new Uniform<T, U, V>(this, name, GL);
}
/// <summary>
/// Link the shader to current context.
/// </summary>
public unsafe void Link()
{
if (InternalIO.InternalLinkShaderProgram(GL.Context, handle.Value) == 0)
{
IntPtr logPtr = InternalIO.InternalReadSSCLog();
try
{
byte[] logByte = new byte[512];
Marshal.Copy(logPtr, logByte, 0, 512);
string log = Encoding.UTF8.GetString(logByte);
log = log.Replace("\0", string.Empty);
InternalIO.InternalWriteLog(log, LogType.Error);
}
catch (Exception ex)
{
InternalIO.InternalWriteLog(ex.Message, LogType.Error);
}
}
}
/// <summary>
/// Let the current context use this shader.
/// </summary>
@@ -153,5 +187,6 @@ namespace StgSharp.Graphics
{
GL.UseProgram(handle);
}
}
}
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 System;
using System.Collections.Generic;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{
public class ShaderGenerator
{
private List<string> codeList;
private List<ShaderFunction> usedShaderFunctions;
@@ -18,19 +49,18 @@ namespace StgSharp.Graphics.GL.ShaderEdit
{
throw new NotImplementedException();
}
}
public class ShaderFunction
{
private string name;
private List<string> codeList;
private List<ShaderParameter> inputList;
private string name;
private ShaderParameter outPut;
public int ParameterCount
{
get { return inputList.Count; }
}
public int ParameterCount => inputList.Count;
public void EmitCall(ShaderFunction function, ShaderParameter outPut, params ShaderParameter[] inputParams)
{
@@ -52,7 +82,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
throw new Exception("Provided parameters does not match function's parameter list.");
}
}
string codeLine = ""; // adding a line like " outvalue = Func(input1, input2,...); "
string codeLine = string.Empty; // adding a line like " outvalue = Func(input1, input2,...); "
if (outPut != ShaderParameter.Void)
{
codeLine += $"{outPut.name} = ";
@@ -65,13 +95,16 @@ namespace StgSharp.Graphics.GL.ShaderEdit
codeLine += ");\n";
codeList.Add(codeLine);
}
}
public class ShaderParameter
{
internal readonly InternalShaderType type;
internal readonly string name;
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)
{
@@ -80,8 +113,6 @@ namespace StgSharp.Graphics.GL.ShaderEdit
isReadOnly = false;
}
public static readonly ShaderParameter Void = new ShaderParameter("", InternalShaderType.Void);
public static bool IsSameType(ShaderParameter param1, ShaderParameter param2)
{
if (param1.type != InternalShaderType.Struct)
@@ -93,6 +124,7 @@ namespace StgSharp.Graphics.GL.ShaderEdit
throw new Exception("Struct is currently not supported.");
}
}
}
public enum InternalShaderType
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Uniform.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;
@@ -11,8 +41,14 @@ namespace StgSharp.Graphics
{
public class Uniform<T> where T : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, IglFunc gl)
@@ -21,18 +57,20 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U>
where T : struct
where U : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(
ShaderProgram program, string name, IglFunc gl)
@@ -41,10 +79,6 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U, V>
@@ -52,8 +86,14 @@ namespace StgSharp.Graphics
where U : struct
where V : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
public unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
@@ -61,10 +101,6 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
public class Uniform<T, U, V, W>
@@ -73,8 +109,14 @@ namespace StgSharp.Graphics
where V : struct
where W : struct
{
internal glSHandle id;
private IglFunc GL;
internal glSHandle id;
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
internal unsafe Uniform(ShaderProgram program, string name, IglFunc gl)
{
@@ -82,14 +124,23 @@ namespace StgSharp.Graphics
id = GL.GetUniformLocation(program.handle, name);
}
internal unsafe Uniform(glSHandle id)
{
this.id = id;
}
}
internal partial class GLonRender : IglFunc
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
unsafe void IglFunc.SetValue(Uniform<float> uniform, float v0)
{
@@ -120,21 +171,11 @@ namespace StgSharp.Graphics
api->glUniform4f(uniform.id.DirectValue, v0, v1, v2, v3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe void SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
api->glUniform1fv(uniform.id.DirectValue, 4, &vec);
}
}
internal unsafe partial class GLonUpdate
{
private IntPtr UniformVal1fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1f;
private IntPtr UniformVal1fvPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1fv;
private IntPtr UniformVal1iPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal1i;
@@ -142,6 +183,53 @@ namespace StgSharp.Graphics
private IntPtr UniformVal3fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal3f;
private IntPtr UniformVal4fPtr = (IntPtr)(delegate*<FrameOperationBuffer, GLcontext*, void>)&UniformVal4f;
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
}
private static unsafe void UniformVal1fv(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default, v = default;
frameOpBuffer.TryDequeue(out m);
frameOpBuffer.TryDequeue(out v);
activatedContext->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&v);
}
private static void UniformVal1i(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
}
private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
}
private static void UniformVal4f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
}
unsafe void IglFunc.SetValue(Uniform<float, float, float> uniform, float f0, float f1, float f2)
{
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr);
@@ -194,55 +282,9 @@ namespace StgSharp.Graphics
unsafe void IglFunc.SetValue(Uniform<Vec4d> uniform, Vec4d vec)
{
Vec4d m = vec;
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(Vec4d*)&m);
frameOpBuffer.ParamEnqueue((IntPtr)uniform.id.valuePtr, (IntPtr)(&m));
frameOpBuffer.MethodEnqueue(UniformVal1fvPtr);
}
private static void UniformVal1f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1f(*(int*)m.Read<ulong>(0), m.Read<uint>(2));
}
private static unsafe void UniformVal1fv(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default, v = default;
frameOpBuffer.TryDequeue(out m);
frameOpBuffer.TryDequeue(out v);
activatedContext->glUniform1fv(*(int*)m.Read<ulong>(0), 4, (Vec4d*)&v);
}
private static void UniformVal1i(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform1i(*(int*)m.Read<ulong>(0), m.Read<int>(2));
}
private static void UniformVal2f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
M128 m = default;
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform2f(*(int*)m.Read<ulong>(0), m.Read<float>(2), m.Read<float>(3));
}
private static void UniformVal3f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform3f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2));
}
private static void UniformVal4f(FrameOperationBuffer frameOpBuffer, GLcontext* activatedContext)
{
IntPtr handle = IntPtr.Zero;
M128 m = default;
frameOpBuffer.TryDequeue(out handle);
frameOpBuffer.TryDequeue(out m);
activatedContext->glUniform4f(*(int*)handle, m.Read<float>(0), m.Read<float>(1), m.Read<float>(2), m.Read<float>(3));
}
}
}
+90 -60
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -67,83 +97,83 @@ namespace StgSharp
[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 = "glfwCreateWindow")] internal static extern unsafe IntPtr glfwCreateWindow(int width, int height, byte[] title, IntPtr monitor, GLFWwindow* share);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwDestroyWindow")] internal static extern unsafe void glfwDestroyWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwWindowShouldClose")] internal static extern unsafe int glfwWindowShouldClose(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(IntPtr window, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowShouldClose")] internal static extern unsafe void glfwSetWindowShouldClose(GLFWwindow* window, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(IntPtr window, byte* title);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowTitle")] internal static extern unsafe void glfwSetWindowTitle(GLFWwindow* window, byte* title);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(IntPtr window, int count, GLFWimage* images);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIcon")] internal static extern unsafe void glfwSetWindowIcon(GLFWwindow* 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 = "glfwGetWindowPos")] internal static extern unsafe void glfwGetWindowPos(GLFWwindow* 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 = "glfwSetWindowPos")] internal static extern unsafe void glfwSetWindowPos(GLFWwindow* 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 = "glfwGetWindowSize")] internal static extern unsafe void glfwGetWindowSize(GLFWwindow* 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 = "glfwSetWindowSizeLimits")] internal static extern unsafe void glfwSetWindowSizeLimits(GLFWwindow* 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 = "glfwSetWindowAspectRatio")] internal static extern unsafe void glfwSetWindowAspectRatio(GLFWwindow* 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 = "glfwSetWindowSize")] internal static extern unsafe void glfwSetWindowSize(GLFWwindow* 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 = "glfwGetFramebufferSize")] internal static extern unsafe void glfwGetFramebufferSize(GLFWwindow* 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 = "glfwGetWindowFrameSize")] internal static extern unsafe void glfwGetWindowFrameSize(GLFWwindow* 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 = "glfwGetWindowContentScale")] internal static extern unsafe void glfwGetWindowContentScale(GLFWwindow* window, float* xscale, float* yscale);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowOpacity")] internal static extern unsafe float glfwGetWindowOpacity(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(IntPtr window, float opacity);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowOpacity")] internal static extern unsafe void glfwSetWindowOpacity(GLFWwindow* window, float opacity);
[DllImport(SSC_libname, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwIconifyWindow")] internal static extern unsafe void glfwIconifyWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRestoreWindow")] internal static extern unsafe void glfwRestoreWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwMaximizeWindow")] internal static extern unsafe void glfwMaximizeWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwShowWindow")] internal static extern unsafe void glfwShowWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwHideWindow")] internal static extern unsafe void glfwHideWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwFocusWindow")] internal static extern unsafe void glfwFocusWindow(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwRequestWindowAttention")] internal static extern unsafe void glfwRequestWindowAttention(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowMonitor")] internal static extern unsafe IntPtr glfwGetWindowMonitor(GLFWwindow* 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 = "glfwSetWindowMonitor")] internal static extern unsafe void glfwSetWindowMonitor(GLFWwindow* 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 = "glfwGetWindowAttrib")] internal static extern unsafe int glfwGetWindowAttrib(GLFWwindow* window, int attrib);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(IntPtr window, int attrib, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowAttrib")] internal static extern unsafe void glfwSetWindowAttrib(GLFWwindow* window, int attrib, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(IntPtr window, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowUserPointer")] internal static extern unsafe void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetWindowUserPointer")] internal static extern unsafe void* glfwGetWindowUserPointer(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(IntPtr window, GLFWwindowposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowPosCallback")] internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(IntPtr window, GLFWwindowsizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowSizeCallback")] internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(IntPtr window, GLFWwindowclosefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowCloseCallback")] internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(IntPtr window, GLFWwindowrefreshfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowRefreshCallback")] internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(IntPtr window, GLFWwindowfocusfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowFocusCallback")] internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(IntPtr window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowIconifyCallback")] internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(IntPtr window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowMaximizeCallback")] internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(GLFWwindow* window, GLFWwindowmaximizefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(IntPtr window, IntPtr callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetFramebufferSizeCallback")] internal static extern unsafe FramebuffersizeHandler glfwSetFramebufferSizeCallback(GLFWwindow* window, IntPtr callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(IntPtr window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetWindowContentScaleCallback")] internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(GLFWwindow* window, GLFWwindowcontentscalefun callback);
[DllImport(SSC_libname, EntryPoint = "glfwPollEvents")] internal static extern unsafe void glfwPollEvents();
@@ -153,9 +183,9 @@ namespace StgSharp
[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 = "glfwGetInputMode")] internal static extern unsafe int glfwGetInputMode(GLFWwindow* window, int mode);
[DllImport(SSC_libname, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(IntPtr window, int mode, int value);
[DllImport(SSC_libname, EntryPoint = "glfwSetInputMode")] internal static extern unsafe void glfwSetInputMode(GLFWwindow* window, int mode, int value);
[DllImport(SSC_libname, EntryPoint = "glfwRawMouseMotionSupported")] internal static extern unsafe int glfwRawMouseMotionSupported();
@@ -163,13 +193,13 @@ namespace StgSharp
[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 = "glfwGetKey")] internal static extern unsafe KeyStatus glfwGetKey(GLFWwindow* window, int key);
[DllImport(SSC_libname, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(IntPtr window, int button);
[DllImport(SSC_libname, EntryPoint = "glfwGetMouseButton")] internal static extern unsafe int glfwGetMouseButton(GLFWwindow* window, int button);
[DllImport(SSC_libname, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(IntPtr window, double* xpos, double* ypos);
[DllImport(SSC_libname, EntryPoint = "glfwGetCursorPos")] internal static extern unsafe void glfwGetCursorPos(GLFWwindow* 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 = "glfwSetCursorPos")] internal static extern unsafe void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
[DllImport(SSC_libname, EntryPoint = "glfwCreateCursor")] internal static extern unsafe GLFWcursor* glfwCreateCursor(GLFWimage* image, int xhot, int yhot);
@@ -177,23 +207,23 @@ namespace StgSharp
[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 = "glfwSetCursor")] internal static extern unsafe void glfwSetCursor(GLFWwindow* window, GLFWcursor* cursor);
[DllImport(SSC_libname, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(IntPtr window, GLFWkeyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetKeyCallback")] internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(IntPtr window, GLFWcharfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharCallback")] internal static extern unsafe GLFWcharfun glfwSetCharCallback(GLFWwindow* window, GLFWcharfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(IntPtr window, GLFWcharmodsfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCharModsCallback")] internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(GLFWwindow* window, GLFWcharmodsfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(IntPtr window, GLFWmousebuttonfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetMouseButtonCallback")] internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(IntPtr window, GLFWcursorposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorPosCallback")] internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(IntPtr window, GLFWcursorenterfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetCursorEnterCallback")] internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(IntPtr window, GLFWscrollfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetScrollCallback")] internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(IntPtr window, GLFWdropfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwSetDropCallback")] internal static extern unsafe GLFWdropfun glfwSetDropCallback(GLFWwindow* window, GLFWdropfun callback);
[DllImport(SSC_libname, EntryPoint = "glfwJoystickPresent")] internal static extern unsafe int glfwJoystickPresent(int jid);
@@ -221,9 +251,9 @@ namespace StgSharp
[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 = "glfwSetClipboardString")] internal static extern unsafe void glfwSetClipboardString(GLFWwindow* window, byte* str);
[DllImport(SSC_libname, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(IntPtr window);
[DllImport(SSC_libname, EntryPoint = "glfwGetClipboardString")] internal static extern unsafe byte* glfwGetClipboardString(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwGetTime")] internal static extern unsafe double glfwGetTime();
@@ -233,11 +263,11 @@ namespace StgSharp
[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 = "glfwMakeContextCurrent")] internal static extern unsafe void glfwMakeContextCurrent(GLFWwindow* 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 = "glfwSwapBuffers")] internal static extern unsafe void glfwSwapBuffers(GLFWwindow* window);
[DllImport(SSC_libname, EntryPoint = "glfwSwapInterval")] internal static extern unsafe void glfwSwapInterval(int interval);
@@ -251,7 +281,7 @@ namespace StgSharp
//[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, IntPtr window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal extern unsafe static VkResult glfwCreateWindowSurface(VkInstance instance, GLFWwindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion api call
}
+211 -25
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiManager.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;
@@ -11,6 +41,7 @@ namespace StgSharp.Graphics
{
public static partial class glManager
{
private const int glExtension = 0x1f03;
private const int glVersion = 0x1f02;
@@ -63,7 +94,7 @@ namespace StgSharp.Graphics
{
if (coreVersion.Contains(branch))
{
coreVersion.Replace(branch, "");
coreVersion.Replace(branch, string.Empty);
}
}
string[] versionSep = coreVersion.Split('.');
@@ -99,7 +130,10 @@ namespace StgSharp.Graphics
}
catch (Exception ex)
{
if (ex.Message != "Final Version") throw;
if (ex.Message != "Final Version")
{
throw;
}
}
IntPtr strPtr = context->glGetString(glExtension);
@@ -763,27 +797,178 @@ namespace StgSharp.Graphics
internal static void CheckCoreVersion(int majorVersion, int minorVersion)
{
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 0)) core10 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 1)) core11 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 2)) core12 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 3)) core13 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 4)) core14 = true; else goto log;
if ((majorVersion >= 1) || (majorVersion == 1 && minorVersion == 5)) core15 = true; else goto log;
if ((majorVersion >= 2) || (majorVersion == 2 && minorVersion == 0)) core20 = true; else goto log;
if ((majorVersion >= 2) || (majorVersion == 2 && minorVersion == 1)) core21 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 0)) core30 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 1)) core31 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 2)) core32 = true; else goto log;
if ((majorVersion >= 3) || (majorVersion == 3 && minorVersion == 3)) core33 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 0)) core40 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 1)) core41 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 2)) core42 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 3)) core43 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 4)) core44 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 5)) core45 = true; else goto log;
if ((majorVersion >= 4) || (majorVersion == 4 && minorVersion == 6)) core46 = true; else goto log;
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 0)))
{
core10 = true;
}
else
{
goto log;
}
log:
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 1)))
{
core11 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 2)))
{
core12 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 3)))
{
core13 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 4)))
{
core14 = true;
}
else
{
goto log;
}
if ((majorVersion >= 1) || ((majorVersion == 1) && (minorVersion == 5)))
{
core15 = true;
}
else
{
goto log;
}
if ((majorVersion >= 2) || ((majorVersion == 2) && (minorVersion == 0)))
{
core20 = true;
}
else
{
goto log;
}
if ((majorVersion >= 2) || ((majorVersion == 2) && (minorVersion == 1)))
{
core21 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 0)))
{
core30 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 1)))
{
core31 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 2)))
{
core32 = true;
}
else
{
goto log;
}
if ((majorVersion >= 3) || ((majorVersion == 3) && (minorVersion == 3)))
{
core33 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 0)))
{
core40 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 1)))
{
core41 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 2)))
{
core42 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 3)))
{
core43 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 4)))
{
core44 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 5)))
{
core45 = true;
}
else
{
goto log;
}
if ((majorVersion >= 4) || ((majorVersion == 4) && (minorVersion == 6)))
{
core46 = true;
}
else
{
goto log;
}
log:
{
InternalIO.InternalWriteLog("Find core OpenGL version.", LogType.Info);
return;
@@ -794,7 +979,7 @@ namespace StgSharp.Graphics
{
if (context.glGetString == null)
{
return "";
return string.Empty;
}
return Marshal.PtrToStringAnsi(
context.glGetString(glExtension));
@@ -812,7 +997,7 @@ namespace StgSharp.Graphics
catch (Exception ex)
{
InternalIO.InternalWriteLog(
$"Failed to convert the api {typeof(T).Name}.\n" + ex.Message, LogType.Warning);
$"{($"Failed to convert the api {typeof(T).Name}.\n")}{ex.Message}", LogType.Warning);
return default;
}
}
@@ -1781,5 +1966,6 @@ namespace StgSharp.Graphics
InternalIO.InternalAppendLog("Successfully load all OpenGL 4.6 APIs");
}
}
}
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="glApiManagerConst.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;
+75 -43
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IglFunc.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.Concurrent;
@@ -8,6 +38,12 @@ namespace StgSharp.Graphics
{
public interface IglFunc
{
internal unsafe GLcontext* Context
{
get;
}
/// <summary>
/// Same function as OpenGL api glActiveTexture
/// </summary>
@@ -86,18 +122,14 @@ namespace StgSharp.Graphics
void ClearGraphicError();
void CompileShader(glHandle shaderhandle);
/// <summary>
/// Same function as OpenGL api, glCreateProgram
/// </summary>
/// <returns>A handle representing a single shader program</returns>
glHandle CreateProgram();
glHandleSet CreateShaderSet(int count, ShaderType type);
void LoadShaderSource(glHandle shaderHandle, string codeStream);
void CompileShader(glHandle shaderhandle);
/// <summary>
/// Same function as OpenGL api, glCreateProgram.
/// Used for creating multiple shader program.
@@ -105,6 +137,8 @@ namespace StgSharp.Graphics
/// <returns>A handle representing all shader programs</returns>
glHandleSet CreateProgram(int count);
glHandleSet CreateShaderSet(int count, ShaderType type);
/// <summary>
/// Creates a form and its associated
/// </summary>
@@ -174,6 +208,8 @@ namespace StgSharp.Graphics
bool GetWindowShouldClose(Form form);
void LoadShaderSource(glHandle shaderHandle, string codeStream);
/// <summary>
/// Make the OpenGL context of a certain <see cref="Form"/> as the activated OpenGL context.
/// </summary>
@@ -184,17 +220,6 @@ namespace StgSharp.Graphics
void SetBufferData<T>(BufferType bufferType, T[] bufferArray, BufferUsage usage) where T : struct, IConvertible;
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
/// <param name="v3">The forth value to be set</param>
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
@@ -203,25 +228,6 @@ namespace StgSharp.Graphics
/// <param name="vec">A <see cref="Vec4d"/> packing four parameters of the uniform </param>
void SetValue(Uniform<float, float, float, float> uniform, Vec4d vec);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
void SetValue(Uniform<float, float> uniform, float v0, float v1);
/// <summary>
/// Set data value to a float <see cref="Uniform{T}"/>,
/// all types of parameters are float.
@@ -246,6 +252,36 @@ namespace StgSharp.Graphics
/// <param name="vec">A <see cref="Vec4d"/> value of the uniform </param>
void SetValue(Uniform<Vec4d> uniform, Vec4d vec);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
void SetValue(Uniform<float, float> uniform, float v0, float v1);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
void SetValue(Uniform<float, float, float> uniform, float v0, float v1, float v2);
/// <summary>
/// Set data value to a float <see cref="Uniform{T,U,V,W}"/>,
/// all types of parameters are float.
/// </summary>
/// <param name="uniform">The <see cref="Uniform{T,U,V,W}"/> target</param>
/// <param name="v0">The first value to be set</param>
/// <param name="v1">The second value to be set</param>
/// <param name="v2">The third value to be set</param>
/// <param name="v3">The forth value to be set</param>
void SetValue(Uniform<float, float, float, float> uniform, float v0, float v1, float v2, float v3);
/// <summary>
/// Set how a shader parameter read data from a VBO.
/// </summary>
@@ -293,13 +329,9 @@ namespace StgSharp.Graphics
/// <param name="height"></param>
void Viewport(int x, int y, uint width, uint height);
internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param);
internal void SwitchContext();
internal unsafe GLcontext* Context
{
get;
}
internal void frameworkHandleEnqueue(IntPtr handle, params M128[] param);
}
}
+49 -13
View File
@@ -1,4 +1,34 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Image.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;
@@ -12,21 +42,10 @@ namespace StgSharp.Graphics
{
public class Image
{
[StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo
{
internal int width;
internal int height;
internal int channel;
internal IntPtr pixelPtr;
}
internal glHandle pixelArrayHandle;
internal ImageInfo info;
public int Width { get => info.width; }
public int Height { get => info.height; }
public int Channel { get => info.channel; }
internal glHandle pixelArrayHandle;
internal Image(ImageInfo information)
{
@@ -40,9 +59,26 @@ namespace StgSharp.Graphics
info = new ImageInfo();
}
public int Channel => info.channel;
public int Height => info.height;
public int Width => info.width;
~Image()
{
Marshal.FreeHGlobal(info.pixelPtr);
}
[StructLayout(LayoutKind.Sequential)]
internal struct ImageInfo
{
internal int width;
internal int height;
internal int channel;
internal IntPtr pixelPtr;
}
}
}
+73 -42
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -14,6 +44,7 @@ namespace StgSharp.Logic
[StructLayout(LayoutKind.Explicit, Size = 8)]
internal struct LogSeperator
{
[FieldOffset(0)] public ulong all;
[FieldOffset(0)] public long all_s;
@@ -28,6 +59,7 @@ namespace StgSharp.Logic
this.high = high;
this.low = low;
}
}
/// <summary>
@@ -38,6 +70,7 @@ namespace StgSharp.Logic
/// <typeparam name="T"></typeparam>
public class DynamicArrayList<T>
{
private List<T[]> arrayIndexList;
private LogSeperator indexpair;
private int lastMain = 0;
@@ -139,10 +172,10 @@ namespace StgSharp.Logic
{
indexpair.all_s = index;
if (
indexpair.low_s > lastSub ||
indexpair.high_s > lastMain ||
indexpair.low_s < 0 ||
indexpair.high_s < 0)
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
@@ -152,10 +185,10 @@ namespace StgSharp.Logic
{
indexpair.all_s = index;
if (
indexpair.low_s > lastSub ||
indexpair.high_s > lastMain ||
indexpair.low_s < 0 ||
indexpair.high_s < 0)
(indexpair.low_s > lastSub) ||
(indexpair.high_s > lastMain) ||
(indexpair.low_s < 0) ||
(indexpair.high_s < 0))
{
throw new IndexOutOfRangeException();
}
@@ -163,30 +196,11 @@ namespace StgSharp.Logic
}
}
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 T this[int index]
{
get
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -195,7 +209,7 @@ namespace StgSharp.Logic
}
set
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -208,7 +222,7 @@ namespace StgSharp.Logic
{
get
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -217,7 +231,7 @@ namespace StgSharp.Logic
}
set
{
if (index + 1 > length || index < 0)
if ((index + 1 > length) || (index < 0))
{
throw new ArgumentOutOfRangeException("index");
}
@@ -231,10 +245,7 @@ namespace StgSharp.Logic
/// <summary>
/// Length of this <see cref="DynamicArrayList{T}"/>
/// </summary>
public int Length
{
get { return length; }
}
public int Length => length;
public int Add(T item)
{
@@ -297,6 +308,25 @@ namespace StgSharp.Logic
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;
@@ -307,7 +337,7 @@ namespace StgSharp.Logic
{
if (i.Equals(item))
{
return index + subindex - 1;
return (index + subindex) - 1;
}
subindex++;
}
@@ -328,11 +358,11 @@ namespace StgSharp.Logic
if (i.Equals(item))
{
list[subindex] = default;
if (subindex == lastSub && index == lastMain)
if ((subindex == lastSub) && (index == lastMain))
{
if (lastSub == 0)
{
lastMain = lastMain == 0 ? 0 : lastMain - 1;
lastMain = (lastMain == 0) ? 0 : (lastMain - 1);
lastSub = arrayIndexList[lastMain].Length - 1;
}
else
@@ -356,7 +386,7 @@ namespace StgSharp.Logic
[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)
if ((index > length) || (index < 0))
{
throw new ArgumentOutOfRangeException(nameof(index));
}
@@ -402,7 +432,7 @@ namespace StgSharp.Logic
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= (int)(32 - mainindex);
indexpair.low >>= 32 - mainindex;
}
private void SeprateIndex(int longIndex)
@@ -415,7 +445,8 @@ namespace StgSharp.Logic
mainindex++;
}
indexpair.high_s = mainindex;
indexpair.low >>= (int)(32 - mainindex);
indexpair.low >>= 32 - mainindex;
}
}
}
+35 -3
View File
@@ -1,4 +1,34 @@
using StgSharp.Entities;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -6,15 +36,17 @@ namespace StgSharp
{
public partial class Control
{
internal Line bottomBoader;
internal Line leftBoader;
internal Line rightBoader;
internal Line topBoader;
internal Line bottomBoader;
public Line BottomBoarder => bottomBoader;
public Line LeftBoarder => leftBoader;
public Line RightBoarder => rightBoader;
public Line TopBoarder => topBoader;
public Line BottomBoarder => bottomBoader;
private void initContainers()
+56 -75
View File
@@ -1,80 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Counter.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.Xml.Serialization;
namespace StgSharp
{
public delegate void TimeSourceProvider(TimeProvider subscriber);
public class TimeProvider
{
private readonly long _spanLength;
private long _spanBegin;
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
public static TimeSourceProvider DefaultProvider
{
get
{
return new(StgSharp.SubscribeTimeProvider);
}
}
public TimeProvider(
long spanLength
)
{
_spanLength = spanLength;
}
internal void CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
}
}
public void SubcsribeToTimeSource(TimeSourceProvider serviceHandler)
{
serviceHandler(this);
}
public static implicit operator uint(TimeProvider provider)
{
return provider.timeSpanCount.Value;
}
}
public class Counter<T> where T : struct, IConvertible, IFormattable, IComparable
{
internal readonly T _defualtValue;
internal readonly T _defualtAddValue;
internal readonly T _defualtSubValue;
internal readonly T _defualtValue;
internal dynamic _value;
public T Value
{
get { return _value; }
set { _value = value; }
}
public T Span
{
get { return _value - _defualtValue; }
}
public T Increament
{
get { return _defualtAddValue; }
}
public T Decreament
{
get { return _defualtSubValue; }
}
public Counter(T defualtValue, T defualtAddValue, T defualtSubValue)
{
var type = Type.GetTypeCode(defualtValue.GetType());
@@ -120,6 +88,18 @@ namespace StgSharp
_defualtSubValue = defualtSubValue;
}
public T Decreament => _defualtSubValue;
public T Increament => _defualtAddValue;
public T Span => _value - _defualtValue;
public T Value
{
get => _value;
set => _value = value;
}
public void Add(T value)
{
_value += value;
@@ -130,11 +110,6 @@ namespace StgSharp
_value += _defualtAddValue;
}
public void Sub(T value)
{
_value -= value;
}
public void QuickSub()
{
_value -= _defualtSubValue;
@@ -145,10 +120,14 @@ namespace StgSharp
_value = _defualtValue;
}
public static Counter<T> operator ++(Counter<T> counter)
public void Sub(T value)
{
counter.QuickAdd();
return counter;
_value -= value;
}
public override string ToString()
{
return Value.ToString();
}
public static Counter<T> operator --(Counter<T> counter)
@@ -157,14 +136,16 @@ namespace StgSharp
return counter;
}
public override string ToString()
public static Counter<T> operator ++(Counter<T> counter)
{
return Value.ToString();
counter.QuickAdd();
return counter;
}
public static implicit operator T(Counter<T> counter)
{
return counter.Value;
}
}
}
+37 -6
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Exception.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;
@@ -11,6 +41,12 @@ namespace StgSharp.Logic
[System.Serializable]
internal class FrameTimeoutException : Exception
{
protected FrameTimeoutException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
internal FrameTimeoutException()
{ }
@@ -22,10 +58,5 @@ namespace StgSharp.Logic
{
}
protected FrameTimeoutException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context)
{
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -13,6 +43,7 @@ namespace StgSharp.Logic
[StructLayout(LayoutKind.Explicit, Size = 2)]
public struct Bool2
{
/// <summary>
/// A <see cref="ushort"/> value.
/// The lower byte is <see cref="bool0"/>,
@@ -33,5 +64,6 @@ namespace StgSharp.Logic
[FieldOffset(1)] public bool bool1;
[FieldOffset(1)] public bool byte1;
}
}
+43 -14
View File
@@ -1,4 +1,34 @@
using StgSharp.Geometries;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Sensor.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;
namespace StgSharp
{
@@ -7,26 +37,30 @@ namespace StgSharp
public class Sensor<T>
{
internal PlainGeometry _boarder;
internal PlainGeometry _target;
internal SensorRuleHandler _rule;
internal PlainGeometry _target;
public PlainGeometry boarder
public PlainGeometry boarder => _boarder;
public SensorRuleHandler Rule
{
get { return _boarder; }
get => _rule;
set => _rule = value;
}
public PlainGeometry target
{
get { return _target; }
set { _target = value; }
get => _target;
set => _target = value;
}
public SensorRuleHandler Rule
public static Sensor<T> operator -(Sensor<T> sensor, SensorRuleHandler rule)
{
get { return _rule; }
set { _rule = value; }
sensor._rule -= rule;
return sensor;
}
public static Sensor<T> operator +(Sensor<T> sensor, SensorRuleHandler rule)
@@ -35,10 +69,5 @@ namespace StgSharp
return sensor;
}
public static Sensor<T> operator -(Sensor<T> sensor, SensorRuleHandler rule)
{
sensor._rule -= rule;
return sensor;
}
}
}
@@ -0,0 +1,88 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeSourceProvider.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 System;
using System.Linq;
using System.Threading;
namespace StgSharpDebug.Logic
{
public abstract class TimeSourceProviderBase
{
private SemaphoreSlim _addSubscriberSemaphore = new SemaphoreSlim(1, 1);
public void AddSubscriber(TimeSpanProvider subscriber)
{
_addSubscriberSemaphore.Wait();
try
{
AddSubscriberUnsynced(subscriber);
}
catch (Exception)
{
throw;
}
finally
{
_addSubscriberSemaphore.Release();
}
}
public void RemoveSubscriber(TimeSpanProvider subscriber)
{
_addSubscriberSemaphore.Wait();
try
{
RemoveSubscriberUnsynced(subscriber);
}
catch (Exception)
{
throw;
}
finally
{
_addSubscriberSemaphore.Release();
}
}
public abstract void StartProvidingTime();
protected abstract void AddSubscriberUnsynced(TimeSpanProvider subscriber);
protected abstract void RemoveSubscriberUnsynced(TimeSpanProvider subscriber);
}
}
@@ -0,0 +1,122 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="TimeSpanProvider.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.Linq;
namespace StgSharp
{
public delegate void TimeSpanRefeshCallback();
/// <summary>
/// A microsecond-accuracy timer. It will refresh every a certain time span.
/// </summary>
public class TimeSpanProvider
{
private readonly int _maxSpanCount;
private TimeSpanRefeshCallback _refeshCallback;
private long _spanBegin;
private readonly long _spanLength;
private bool _subscribed;
private Counter<uint> timeSpanCount = new Counter<uint>(0, 1, 1);
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <parma name="provider"></parma>
public TimeSpanProvider(long spanLength, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
/// <summary>
/// Create a new <see cref="TimeSpanProvider"/> and define the length of time span. Length of a single time span is defined in microseconds.
/// </summary>
/// <param name="spanLength"></param>
/// <parma name="provider"></parma>
public TimeSpanProvider(long spanLength, uint maxSpan, TimeSourceProviderBase provider)
{
_spanLength = spanLength;
provider.AddSubscriber(this);
_subscribed = true;
}
/// <summary>
/// Time source provider provided in <see cref="StgSharp"/> internal framework.
/// </summary>
public static TimeSourceProviderBase DefaultProvider => StgSharpTime.OnlyInstance;
/// <summary>
/// The method this <see cref="TimeSpanProvider"/> will call every time a new time span started.
/// </summary>
public TimeSpanRefeshCallback SpanRefreshCallback
{
get => _refeshCallback;
set => _refeshCallback = value;
}
public void SubcsribeToTimeSource(TimeSourceProviderBase serviceHandler)
{
if (_subscribed)
{
return;
}
_subscribed = true;
serviceHandler.AddSubscriber(this);
}
internal bool CheckTime(long microseconds)
{
if (microseconds - _spanBegin > _spanLength)
{
_spanBegin = microseconds;
timeSpanCount++;
}
if (timeSpanCount > _maxSpanCount)
{
return false;
}
return true;
}
public static implicit operator uint(TimeSpanProvider provider)
{
return provider.timeSpanCount.Value;
}
}
}
+205 -174
View File
@@ -1,4 +1,34 @@
using StgSharp.Graphics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.Graphics;
using StgSharp.Math;
using System;
@@ -16,9 +46,10 @@ namespace StgSharp.Logic
{
internal unsafe class GLparamQueue
{
internal GLcontext* context;
private ConcurrentQueue<M128> paramQueue;
private ConcurrentQueue<glArrayHandle> streamQueue;
internal GLcontext* context;
public GLparamQueue()
{
@@ -47,6 +78,45 @@ namespace StgSharp.Logic
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)
{
@@ -65,6 +135,33 @@ namespace StgSharp.Logic
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)
{
@@ -84,6 +181,16 @@ namespace StgSharp.Logic
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)
{
@@ -95,67 +202,6 @@ namespace StgSharp.Logic
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(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(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)
{
M128 m = default;
m.Write<int>(0, i0);
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(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(int i0, int i1, int i2, int i3)
{
@@ -167,21 +213,6 @@ namespace StgSharp.Logic
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 TryDequeue(out glArrayHandle arrayHandle)
{
@@ -244,6 +275,36 @@ namespace StgSharp.Logic
}
}
[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)
{
@@ -260,6 +321,38 @@ namespace StgSharp.Logic
}
}
[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)
{
@@ -277,6 +370,40 @@ namespace StgSharp.Logic
}
}
[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)
{
@@ -295,37 +422,6 @@ namespace StgSharp.Logic
}
}
[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)
{
@@ -344,71 +440,6 @@ namespace StgSharp.Logic
}
}
[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)
{
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GLfixed.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;
@@ -10,8 +40,10 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 8)]
public struct GLfixed
{
[FieldOffset(0)] public int All;
[FieldOffset(0)] public short Decimals;
[FieldOffset(4)] public short Inertger;
}
}
+31 -1
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cordination.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.Math
{
internal class Cordination
+51 -16
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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;
@@ -19,35 +49,40 @@ 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);
{
return *(((T*)p) + index);
}
}
public override string ToString()
{
return string.Empty;
}
public string ToString(int sample)
{
string str = string.Empty;
for (int i = 0; i < 16; 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
{
fixed (Vector4* p = &vec)
*((T*)(p) + index) = value;
}
public override string ToString()
{
return "";
}
public string ToString(int sample)
{
string str = "";
for (int i = 0; i < 16; i++)
{
str += $"{Convert.ToString(this.Read<byte>(i), sample)} ";
*(((T*)p) + index) = value;
}
return str;
}
#if NET5_0_OR_GREATER
+31 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="MatInterface.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;
+36 -5
View File
@@ -1,20 +1,51 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.Cross.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.Math
{
public static unsafe partial class Vector
{
public static float Cross(Vec2d vec1, Vec2d vec2)
{
return vec1.X * vec2.Y - vec1.Y * vec2.X;
return (vec1.X * vec2.Y) - (vec1.Y * vec2.X);
}
public static vec3d Cross(vec3d vec1, vec3d vec2)
{
return new vec3d(
vec1.Y * vec2.Z - vec1.Z * vec2.Y,
vec1.X * vec2.Z - vec1.Z * vec2.X,
vec1.X * vec2.Y - vec1.Y * vec2.X
(vec1.Y * vec2.Z) - (vec1.Z * vec2.Y),
(vec1.X * vec2.Z) - (vec1.Z * vec2.X),
(vec1.X * vec2.Y) - (vec1.Y * vec2.X)
);
}
}
}
@@ -1,7 +1,38 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetAngle.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.Math
{
public static unsafe partial class Vector
{
public static float GetAngle(Vec2d vec1, Vec2d vec2)
{
return Scaler.ACos(1
@@ -13,7 +44,7 @@
public static float GetAngle(vec3d vec1, vec3d vec2)
{
return Scaler.ACos(
vec1 * vec2
(vec1 * vec2)
/ (vec1.GetLength() * vec2.GetLength())
);
}
@@ -1,21 +1,52 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vector.GetLength.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.Math
{
public static unsafe partial class Vector
{
public static float GetLength(this vec3d vec)
{
return Scaler.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y +
vec.Z * vec.Z
(vec.X * vec.X) +
(vec.Y * vec.Y) +
(vec.Z * vec.Z)
);
}
public static float GetLength(this Vec2d vec)
{
return Scaler.Sqrt(
vec.X * vec.X +
vec.Y * vec.Y
(vec.X * vec.X) +
(vec.Y * vec.Y)
);
}
@@ -1,14 +1,40 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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 unsafe static partial class VectorCalc
public static unsafe partial class VectorCalc
{
public static vec3d To3D(Vec2d vec)
{
return new vec3d(vec.X, vec.Y, 0.0f);
}
public static Vec2d To2D(vec3d vec, CordinatePlain plain)
{
@@ -28,12 +54,17 @@ namespace StgSharp.Math
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);
}
}
+49 -15
View File
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat2.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.CompilerServices;
@@ -8,6 +39,7 @@ namespace StgSharp
{
internal static unsafe partial class InternalIO
{
#region add
[DllImport(InternalIO.SSC_libname, EntryPoint = "add_Mat2",
@@ -16,6 +48,15 @@ namespace StgSharp
internal static extern Mat2* add_mat2(Mat2* left, Mat2* right);
#endregion
#region deinit mat2
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat2",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe void deinit_mat2(Mat2* mat);
#endregion
#region sub
@@ -42,14 +83,6 @@ namespace StgSharp
#endregion
#region deinit mat2
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat2",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe void deinit_mat2(Mat2* mat);
#endregion
}
}
@@ -85,7 +118,7 @@ namespace StgSharp.Math
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool Equals(object? obj)
{
return obj is Mat2 mat && Equals(mat);
return (obj is Mat2 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -95,16 +128,17 @@ namespace StgSharp.Math
colum1.Equals(other.colum1);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat2 left, Mat2 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Mat2 left, Mat2 right)
{
return left.Equals(right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat2 left, Mat2 right)
{
return !(left == right);
}
}
}
+40 -7
View File
@@ -1,4 +1,35 @@
using StgSharp.Math;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat3.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.CompilerServices;
@@ -34,6 +65,7 @@ namespace StgSharp
#endregion
}
}
@@ -66,7 +98,7 @@ namespace StgSharp.Math
public override bool Equals(object? obj)
{
return obj is Mat3 mat && Equals(mat);
return (obj is Mat3 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -77,16 +109,17 @@ namespace StgSharp.Math
colum2.Equals(other.colum2);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat3 left, Mat3 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Mat3 left, Mat3 right)
{
return left.Equals(right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat3 left, Mat3 right)
{
return !(left == right);
}
}
}
+60 -26
View File
@@ -1,5 +1,36 @@
using StgSharp;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat4.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.Math;
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -10,6 +41,26 @@ namespace StgSharp
internal static unsafe partial class InternalIO
{
#region deinit_mat4
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern void deinit_mat4(Mat4* mat);
#endregion
#region det
[DllImport(InternalIO.SSC_libname, EntryPoint = "det_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern unsafe float det_mat4(Mat4* matPtr, Mat4* transpose);
#endregion
#region transpose
[DllImport(InternalIO.SSC_libname, EntryPoint = "transpose4to4",
@@ -27,25 +78,6 @@ namespace StgSharp
#endregion
#region det
[DllImport(InternalIO.SSC_libname, EntryPoint = "det_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe extern float det_mat4(Mat4* matPtr, Mat4* transpose);
#endregion
#region deinit_mat4
[DllImport(InternalIO.SSC_libname, EntryPoint = "deinit_mat4",
CallingConvention = CallingConvention.Cdecl)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static extern void deinit_mat4(Mat4* mat);
#endregion
}
@@ -57,6 +89,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16 * sizeof(float))]
public struct Mat4 : IEquatable<Mat4>, IMat
{
[FieldOffset(0)] internal Vector4 colum0;
[FieldOffset(16)] internal Vector4 colum1;
[FieldOffset(32)] internal Vector4 colum2;
@@ -98,7 +131,7 @@ namespace StgSharp.Math
public override bool Equals(object? obj)
{
return obj is Mat4 mat && Equals(mat);
return (obj is Mat4 mat) && Equals(mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -110,16 +143,17 @@ namespace StgSharp.Math
colum3.Equals(other.colum3);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat4 left, Mat4 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(Mat4 left, Mat4 right)
{
return left.Equals(right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(Mat4 left, Mat4 right)
{
return !(left == right);
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat5.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.Numerics;
using System.Runtime.InteropServices;
@@ -9,10 +39,12 @@ namespace StgSharp.Math.Linear
[StructLayout(LayoutKind.Explicit, Size = 5 * 4 * sizeof(float))]
public struct mat5 : IMat
{
[FieldOffset(0 * 4 * sizeof(float))] internal Vector4 vec0;
[FieldOffset(1 * 4 * sizeof(float))] internal Vector4 vec1;
[FieldOffset(2 * 4 * sizeof(float))] internal Vector4 vec2;
[FieldOffset(3 * 4 * sizeof(float))] internal Vector4 vec3;
[FieldOffset(4 * 4 * sizeof(float))] internal Vector4 vec4;
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="mat6.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.Numerics;
using System.Runtime.InteropServices;
@@ -9,11 +39,13 @@ namespace StgSharp.Math.Linear
[StructLayout(LayoutKind.Sequential)]
public struct mat6 : IMat
{
internal Vector4 vec0;
internal Vector4 vec1;
internal Vector4 vec2;
internal Vector4 vec3;
internal Vector4 vec4;
internal Vector4 vec5;
}
}
+62 -31
View File
@@ -1,12 +1,43 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x2.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;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 2 * 2 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (2 * 2 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix2x2 : IMat
{
[FieldOffset(0)]
internal Mat2 mat;
[FieldOffset(2 * 4 * sizeof(float))]
@@ -14,13 +45,11 @@ namespace StgSharp.Math
[FieldOffset(2 * 2 * 4 * sizeof(float))]
internal bool isTransposed;
public Matrix2x2(
float a00, float a01,
float a10, float a11
internal Matrix2x2(
Mat2 mat
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
this.mat = mat;
}
internal Matrix2x2(
@@ -32,11 +61,13 @@ namespace StgSharp.Math
mat.colum1 = c1;
}
internal Matrix2x2(
Mat2 mat
public Matrix2x2(
float a00, float a01,
float a10, float a11
)
{
this.mat = mat;
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
}
public Matrix2x2 Transpose
@@ -48,6 +79,12 @@ namespace StgSharp.Math
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Det()
{
return (mat.m00 * mat.m11) - (mat.m10 * mat.m01);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal void InternalTranspose()
{
@@ -62,16 +99,6 @@ namespace StgSharp.Math
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix2x2 operator +(Matrix2x2 left, Matrix2x2 right)
{
Mat2* refmat = InternalIO.add_mat2(&left.mat, &right.mat);
Matrix2x2 ret = new Matrix2x2(*refmat);
InternalIO.deinit_mat2(refmat);
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator -(Matrix2x2 left, Matrix2x2 right)
{
@@ -90,15 +117,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator /(Matrix2x2 mat, float value)
{
return new Matrix2x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator *(Matrix2x2 left, Matrix2x2 right)
{
@@ -145,9 +163,22 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Det()
public static Matrix2x2 operator /(Matrix2x2 mat, float value)
{
return mat.m00 * mat.m11 - mat.m10 * mat.m01;
return new Matrix2x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix2x2 operator +(Matrix2x2 left, Matrix2x2 right)
{
Mat2* refmat = InternalIO.add_mat2(&left.mat, &right.mat);
Matrix2x2 ret = new Matrix2x2(*refmat);
InternalIO.deinit_mat2(refmat);
return ret;
}
+79 -45
View File
@@ -1,27 +1,48 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x3.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (3 + 2) * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((3 + 2) * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix2x3
{
[FieldOffset(0)] internal Mat3 mat;
[FieldOffset(3 * 4 * sizeof(float))] internal Mat2 transpose;
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
public Matrix2x3(
float a00,float a01,float a02,
float a10,float a11,float a12
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
mat.colum2 = new Vector4(a02, a12, 0, 0);
}
internal Matrix2x3(
Vector4 c0,
Vector4 c1,
@@ -33,43 +54,53 @@ namespace StgSharp.Math
mat.colum2 = c2;
}
public Matrix2x3(
float a00, float a01, float a02,
float a10, float a11, float a12
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
mat.colum2 = new Vector4(a02, a12, 0, 0);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
@@ -81,24 +112,17 @@ namespace StgSharp.Math
{
if (!isTransposed)
{
fixed(Mat3* source = &this.mat)
fixed(Mat2* target = &this.transpose)
fixed (Mat3* source = &this.mat)
{
InternalIO.Transpose3to2_internal(source, target);
fixed (Mat2* target = &this.transpose)
{
InternalIO.Transpose3to2_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
{
return new Matrix2x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator -(Matrix2x3 left, Matrix2x3 right)
@@ -120,16 +144,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator /(Matrix2x3 mat, float value)
{
return new Matrix2x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator *(Matrix2x3 left, Matrix3x2 right)
{
@@ -175,6 +189,26 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator /(Matrix2x3 mat, float value)
{
return new Matrix2x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x3 operator +(Matrix2x3 left, Matrix2x3 right)
{
return new Matrix2x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
}
+85 -52
View File
@@ -1,13 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix2x4.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (4 + 2) * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((4 + 2) * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix2x4
{
[FieldOffset(0)] internal Mat4 mat;
[FieldOffset(4 * 4 * sizeof(float))] internal Mat2 transpose;
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
@@ -17,18 +48,6 @@ namespace StgSharp.Math
[FieldOffset(32)] public Vec2d Colum2;
[FieldOffset(48)] public Vec2d Colum3;
public Matrix2x4(
float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
mat.colum2 = new Vector4(a02, a12, 0, 0);
mat.colum3 = new Vector4(a03, a13, 0, 0);
}
internal Matrix2x4(
Vector4 c0,
Vector4 c1,
@@ -42,74 +61,84 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
public Matrix2x4(
float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13
)
{
mat.colum0 = new Vector4(a00, a10, 0, 0);
mat.colum1 = new Vector4(a01, a11, 0, 0);
mat.colum2 = new Vector4(a02, a12, 0, 0);
mat.colum3 = new Vector4(a03, a13, 0, 0);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 1 || rowNum < 0)
if ((rowNum > 1) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override string ToString()
{
InternalTranspose();
return $"{($"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}],")}{($"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]")}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat4* source = &this.mat)
fixed (Mat2* target = &this.transpose)
{
InternalIO.Transpose4to2_internal(source, target);
fixed (Mat2* target = &this.transpose)
{
InternalIO.Transpose4to2_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator +(Matrix2x4 left, Matrix2x4 right)
{
return new Matrix2x4(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2,
left.mat.colum3 + right.mat.colum3
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator -(Matrix2x4 left, Matrix2x4 right)
{
@@ -132,17 +161,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator /(Matrix2x4 mat, float value)
{
return new Matrix2x4(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value,
mat.mat.colum3 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x2 operator *(Matrix2x4 left, Matrix4x2 right)
{
@@ -188,11 +206,26 @@ namespace StgSharp.Math
);
}
public override string ToString()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator /(Matrix2x4 mat, float value)
{
InternalTranspose();
return $"[{mat.m00},{mat.m01},{mat.m02},{mat.m03}]," +
$"[{mat.m10},{mat.m11},{mat.m12},{mat.m13}]";
return new Matrix2x4(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value,
mat.mat.colum3 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix2x4 operator +(Matrix2x4 left, Matrix2x4 right)
{
return new Matrix2x4(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2,
left.mat.colum3 + right.mat.colum3
);
}
+80 -46
View File
@@ -1,19 +1,59 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x2.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 5 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (5 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix3x2
{
[FieldOffset(0)] internal Mat2 mat;
[FieldOffset(0)] internal vec3d colum0;
[FieldOffset(4 * 4)] internal vec3d colum1;
[FieldOffset(2 * 4 * sizeof(float))] internal Mat3 transpose;
[FieldOffset(5 * 4 * sizeof(float))] internal bool isTransposed;
internal Matrix3x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public unsafe Matrix3x2(
float a00, float a01,
@@ -30,86 +70,71 @@ namespace StgSharp.Math
#endif
}
internal Matrix3x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public vec3d VerticalVecMultiply(Vec2d vec)
{
return colum0 * vec.X + colum1 * vec.Y;
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public vec3d VerticalVecMultiply(Vec2d vec)
{
return (colum0 * vec.X) + (colum1 * vec.Y);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose2to3_internal(source, target);
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose2to3_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator +(Matrix3x2 left, Matrix3x2 right)
{
return new Matrix3x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator -(Matrix3x2 left, Matrix3x2 right)
{
@@ -128,15 +153,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator /(Matrix3x2 mat, float value)
{
return new Matrix3x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator *(Matrix3x2 left, Matrix2x2 right)
{
@@ -194,6 +210,24 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator /(Matrix3x2 mat, float value)
{
return new Matrix3x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator +(Matrix3x2 left, Matrix3x2 right)
{
return new Matrix3x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1
);
}
}
}
+83 -52
View File
@@ -1,13 +1,44 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x3.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 6 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (6 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix3x3
{
[FieldOffset(0)] internal Mat3 mat;
[FieldOffset(3 * 4 * sizeof(float))] internal Mat3 transpose;
[FieldOffset(6 * 4 * sizeof(float))] internal bool isTransposed;
@@ -15,17 +46,6 @@ namespace StgSharp.Math
[FieldOffset(1 * 4 * sizeof(float))] public vec3d Colum1;
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
public Matrix3x3(
float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22
)
{
mat.colum0 = new Vector4(a00, a10, a20, 0);
mat.colum1 = new Vector4(a01, a11, a21, 0);
mat.colum2 = new Vector4(a02, a12, a22, 0);
}
internal Matrix3x3(
Vector4 c0,
Vector4 c1,
@@ -37,34 +57,45 @@ namespace StgSharp.Math
mat.colum2 = c2;
}
public Matrix3x3(
float a00, float a01, float a02,
float a10, float a11, float a12,
float a20, float a21, float a22
)
{
mat.colum0 = new Vector4(a00, a10, a20, 0);
mat.colum1 = new Vector4(a01, a11, a21, 0);
mat.colum2 = new Vector4(a02, a12, a22, 0);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
InternalIO.InternalWriteLog(
$"Attempt to write unused space in {GetType().Name} {nameof(mat)}",
@@ -74,15 +105,24 @@ namespace StgSharp.Math
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
fixed (Mat3* mat = &this.mat)
{
return InternalIO.det_mat3(mat);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
@@ -96,25 +136,6 @@ namespace StgSharp.Math
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
fixed (Mat3* mat = &this.mat)
{
return InternalIO.det_mat3(mat);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x3 operator +(Matrix3x3 left, Matrix3x3 right)
{
return new Matrix3x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x3 operator -(Matrix3x3 left, Matrix3x3 right)
{
@@ -135,16 +156,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x3 operator /(Matrix3x3 mat, float value)
{
return new Matrix3x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator *(Matrix3x3 left, vec3d right)
{
@@ -213,6 +224,26 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x3 operator /(Matrix3x3 mat, float value)
{
return new Matrix3x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x3 operator +(Matrix3x3 left, Matrix3x3 right)
{
return new Matrix3x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
}
}
+81 -47
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix3x4.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.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -7,9 +37,10 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix3x4
{
[FieldOffset(0)] internal Mat4 mat;
[FieldOffset(4 * 4 * sizeof(float))] internal Mat3 transpose;
[FieldOffset(7 * 4 * sizeof(float))] internal bool isTransposed;
@@ -19,16 +50,9 @@ namespace StgSharp.Math
[FieldOffset(2 * 4 * sizeof(float))] public vec3d Colum2;
[FieldOffset(3 * 4 * sizeof(float))] public vec3d Colum3;
public Matrix3x4(
float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13,
float a20, float a21, float a22, float a23
)
internal Matrix3x4(Mat4 mat)
{
mat.colum0 = new Vector4(a00, a10, a20, 0);
mat.colum0 = new Vector4(a01, a11, a21, 0);
mat.colum0 = new Vector4(a02, a12, a22, 0);
mat.colum0 = new Vector4(a03, a13, a23, 0);
this.mat = mat;
}
internal Matrix3x4(
@@ -44,48 +68,55 @@ namespace StgSharp.Math
mat.colum3 = c3;
}
internal Matrix3x4(Mat4 mat)
public Matrix3x4(
float a00, float a01, float a02, float a03,
float a10, float a11, float a12, float a13,
float a20, float a21, float a22, float a23
)
{
this.mat = mat;
mat.colum0 = new Vector4(a00, a10, a20, 0);
mat.colum0 = new Vector4(a01, a11, a21, 0);
mat.colum0 = new Vector4(a02, a12, a22, 0);
mat.colum0 = new Vector4(a03, a13, a23, 0);
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 2 || rowNum < 0)
if ((rowNum > 2) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
@@ -97,25 +128,17 @@ namespace StgSharp.Math
if (!isTransposed)
{
fixed (Mat4* source = &this.mat)
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose4to3_internal(source, target);
fixed (Mat3* target = &this.transpose)
{
InternalIO.Transpose4to3_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x4 operator +(Matrix3x4 left, Matrix3x4 right)
{
return new Matrix3x4(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2,
left.mat.colum3 + right.mat.colum3
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x4 operator -(Matrix3x4 left, Matrix3x4 right)
{
@@ -138,17 +161,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x4 operator /(Matrix3x4 mat, float value)
{
return new Matrix3x4(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value,
mat.mat.colum3 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x2 operator *(Matrix3x4 left, Matrix4x2 right)
{
@@ -206,6 +218,28 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x4 operator /(Matrix3x4 mat, float value)
{
return new Matrix3x4(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value,
mat.mat.colum3 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix3x4 operator +(Matrix3x4 left, Matrix3x4 right)
{
return new Matrix3x4(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2,
left.mat.colum3 + right.mat.colum3
);
}
+95 -61
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x2.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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -8,13 +38,28 @@ namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = (16 + 8) * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = ((16 + 8) * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x2
{
[FieldOffset(0)] internal Mat2 mat;
[FieldOffset(8 * sizeof(float))] internal Mat4 transpose;
[FieldOffset((16 + 8) * sizeof(float))] internal bool isTransposed;
internal Matrix4x2(Mat2 mat)
{
this.mat = mat;
}
internal Matrix4x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
public Matrix4x2(
float a00, float a01,
@@ -27,71 +72,82 @@ namespace StgSharp.Math
mat.colum1 = new Vector4(a01, a11, a21, a31);
}
internal Matrix4x2(
Vector4 c0,
Vector4 c1
)
{
mat.colum0 = c0;
mat.colum1 = c1;
}
internal Matrix4x2(Mat2 mat)
{
this.mat = mat;
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 1 || columNum < 0)
if ((columNum > 1) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
{
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
{
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0
);
}
@@ -104,24 +160,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
{
return new Matrix4x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator -(Matrix4x2 left, Matrix4x2 right)
{
return new Matrix4x2(
left.mat.colum0 - right.mat.colum0,
left.mat.colum0 - right.mat.colum0
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator *(Matrix4x2 left, Matrix2x2 right)
{
@@ -192,24 +230,20 @@ namespace StgSharp.Math
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
public static Matrix4x2 operator /(Matrix4x2 mat, float value)
{
if (!isTransposed)
{
fixed (Mat2* source = &this.mat)
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose2to4_internal(source, target);
}
isTransposed = true;
}
return new Matrix4x2(
mat.mat.colum0 / value,
mat.mat.colum1 / value
);
}
public override int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x2 operator +(Matrix4x2 left, Matrix4x2 right)
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode()
return new Matrix4x2(
left.mat.colum0 + right.mat.colum0,
left.mat.colum0 + right.mat.colum0
);
}
+100 -65
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x3.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.Numerics;
using System.Runtime.CompilerServices;
@@ -6,9 +36,10 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 7 * 4 * sizeof(float) + sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (7 * 4 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x3 : IEquatable<Matrix4x3>
{
[FieldOffset(0)]
internal Mat3 mat;
@@ -18,6 +49,17 @@ namespace StgSharp.Math
[FieldOffset(7 * 4 * sizeof(float))]
internal bool isTransposed;
internal Matrix4x3(
Vector4 c0,
Vector4 c1,
Vector4 c2
)
{
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public Matrix4x3(
float a00, float a01, float a02,
float a10, float a11, float a12,
@@ -30,94 +72,85 @@ namespace StgSharp.Math
mat.colum2 = new Vector4(a02, a12, a22, a32);
}
internal Matrix4x3(
Vector4 c0,
Vector4 c1,
Vector4 c2
)
{
mat.colum0 = c0;
mat.colum1 = c1;
mat.colum2 = c2;
}
public unsafe float this[int rowNum, int columNum]
{
get
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 2 || columNum < 0)
if ((columNum > 2) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
}
}
public override bool Equals(object? obj)
{
return (obj is Matrix4x3 x) && Equals(x);
}
public bool Equals(Matrix4x3 other)
{
return EqualityComparer<Mat3>.Default.Equals(mat, other.mat);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode()
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat3* source = &this.mat)
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose3to4_internal(source, target);
fixed (Mat4* target = &this.transpose)
{
InternalIO.Transpose3to4_internal(source, target);
}
}
isTransposed = true;
}
}
public override bool Equals(object? obj)
{
return obj is Matrix4x3 x && Equals(x);
}
public bool Equals(Matrix4x3 other)
{
return EqualityComparer<Mat3>.Default.Equals(mat, other.mat);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator +(Matrix4x3 left, Matrix4x3 right)
{
return new Matrix4x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator -(Matrix4x3 left, Matrix4x3 right)
{
@@ -128,11 +161,6 @@ namespace StgSharp.Math
);
}
public static bool operator ==(Matrix4x3 left, Matrix4x3 right)
{
return left.Equals(right);
}
public static bool operator !=(Matrix4x3 left, Matrix4x3 right)
{
return !(left == right);
@@ -148,16 +176,6 @@ namespace StgSharp.Math
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator /(Matrix4x3 mat, float value)
{
return new Matrix4x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x2 operator *(Matrix4x3 left, Matrix3x2 right)
{
@@ -230,13 +248,30 @@ namespace StgSharp.Math
);
}
public override int GetHashCode()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator /(Matrix4x3 mat, float value)
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode()
return new Matrix4x3(
mat.mat.colum0 / value,
mat.mat.colum1 / value,
mat.mat.colum2 / value
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Matrix4x3 operator +(Matrix4x3 left, Matrix4x3 right)
{
return new Matrix4x3(
left.mat.colum0 + right.mat.colum0,
left.mat.colum1 + right.mat.colum1,
left.mat.colum2 + right.mat.colum2
);
}
public static bool operator ==(Matrix4x3 left, Matrix4x3 right)
{
return left.Equals(right);
}
}
}
+151 -120
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="matrix4x4.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.Drawing;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -8,15 +38,34 @@ using System.Runtime.InteropServices;
namespace StgSharp.Math
{
[StructLayout(LayoutKind.Explicit, Size = 2*16*sizeof(float)+sizeof(bool), Pack = 16)]
[StructLayout(LayoutKind.Explicit, Size = (2 * 16 * sizeof(float)) + sizeof(bool), Pack = 16)]
public struct Matrix4x4 : IEquatable<Matrix4x4>
{
[FieldOffset(0)] internal Mat4 mat;
[FieldOffset(64*sizeof(float))] internal Mat4 transpose;
[FieldOffset(2*64*sizeof(float))]internal bool isTransposed;
[FieldOffset(64 * sizeof(float))] internal Mat4 transpose;
[FieldOffset(2 * 64 * sizeof(float))] internal bool isTransposed;
internal Matrix4x4(Mat4 mat)
{
this.mat = mat;
}
internal Matrix4x4(
Vector4 vec0,
Vector4 vec1,
Vector4 vec2,
Vector4 vec3
)
{
mat.colum0 = vec0;
mat.colum1 = vec1;
mat.colum2 = vec2;
mat.colum3 = vec3;
}
public unsafe Matrix4x4(
float a00, float a01, float a02, float a03,
@@ -36,40 +85,40 @@ namespace StgSharp.Math
{
get
{
if (rowNum>3||rowNum<0)
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum>3||columNum<0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00 )
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
return *(float*)pbit;
}
}
set
{
if (rowNum > 3 || rowNum < 0)
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if (columNum > 3 || columNum < 0)
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = (ulong)p
+ (ulong)sizeof(Vector4) * (ulong)rowNum
+ (ulong)sizeof(float) * (ulong)columNum;
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
return *(float*)pbit;
}
}
set
{
if ((rowNum > 3) || (rowNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
if ((columNum > 3) || (columNum < 0))
{
throw new ArgumentOutOfRangeException(nameof(columNum));
}
InternalTranspose();
fixed (float* p = &this.transpose.m00)
{
ulong pbit = ((ulong)p)
+ (((ulong)sizeof(Vector4)) * ((ulong)rowNum))
+ (((ulong)sizeof(float)) * ((ulong)columNum));
*(float*)pbit = value;
}
isTransposed = false;
@@ -78,46 +127,73 @@ namespace StgSharp.Math
}
internal Matrix4x4(
Vector4 vec0,
Vector4 vec1,
Vector4 vec2,
Vector4 vec3
)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
{
mat.colum0 = vec0;
mat.colum1 = vec1;
mat.colum2 = vec2;
mat.colum3 = vec3;
InternalTranspose();
fixed (Mat4* _this = &mat, _trans = &transpose)
{
return InternalIO.det_mat4(_this, _trans);
}
}
internal Matrix4x4(Mat4 mat)
public override bool Equals(object? obj)
{
this.mat = mat;
return (obj is Matrix4x4 x) && Equals(x);
}
public bool Equals(Matrix4x4 other)
{
return mat.Equals(other.mat);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode(),
mat.colum3.GetHashCode()
);
}
public override string ToString()
{
InternalTranspose();
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
internal unsafe void InternalTranspose()
{
return new Matrix4x4(
right.mat.colum0 + left.mat.colum0,
right.mat.colum1 + left.mat.colum1,
right.mat.colum2 + left.mat.colum2,
right.mat.colum3 + left.mat.colum3
);
if (!isTransposed)
{
fixed (Mat4* source = &this.mat, target = &this.transpose)
{
InternalIO.Transpose4to4_internal(source, target);
}
isTransposed = true;
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator -(Matrix4x4 left, Matrix4x4 right)
{
return new Matrix4x4(
right.mat.colum0-left.mat.colum0,
right.mat.colum1-left.mat.colum1,
right.mat.colum2-left.mat.colum2,
right.mat.colum3-left.mat.colum3
right.mat.colum0 - left.mat.colum0,
right.mat.colum1 - left.mat.colum1,
right.mat.colum2 - left.mat.colum2,
right.mat.colum3 - left.mat.colum3
);
}
public static bool operator !=(Matrix4x4 left, Matrix4x4 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe Matrix4x4 operator *(Matrix4x4 mat, float value)
{
@@ -153,21 +229,21 @@ namespace StgSharp.Math
{
left.InternalTranspose();
return new Matrix4x3(
Vector4.Dot(left.transpose.colum0,right.mat.colum0),
Vector4.Dot(left.transpose.colum0,right.mat.colum1),
Vector4.Dot(left.transpose.colum0,right.mat.colum2),
Vector4.Dot(left.transpose.colum0, right.mat.colum0),
Vector4.Dot(left.transpose.colum0, right.mat.colum1),
Vector4.Dot(left.transpose.colum0, right.mat.colum2),
Vector4.Dot(left.transpose.colum1,right.mat.colum0),
Vector4.Dot(left.transpose.colum1,right.mat.colum1),
Vector4.Dot(left.transpose.colum1,right.mat.colum2),
Vector4.Dot(left.transpose.colum1, right.mat.colum0),
Vector4.Dot(left.transpose.colum1, right.mat.colum1),
Vector4.Dot(left.transpose.colum1, right.mat.colum2),
Vector4.Dot(left.transpose.colum2,right.mat.colum0),
Vector4.Dot(left.transpose.colum2,right.mat.colum1),
Vector4.Dot(left.transpose.colum2,right.mat.colum2),
Vector4.Dot(left.transpose.colum3,right.mat.colum0),
Vector4.Dot(left.transpose.colum3,right.mat.colum1),
Vector4.Dot(left.transpose.colum3,right.mat.colum2)
Vector4.Dot(left.transpose.colum2, right.mat.colum0),
Vector4.Dot(left.transpose.colum2, right.mat.colum1),
Vector4.Dot(left.transpose.colum2, right.mat.colum2),
Vector4.Dot(left.transpose.colum3, right.mat.colum0),
Vector4.Dot(left.transpose.colum3, right.mat.colum1),
Vector4.Dot(left.transpose.colum3, right.mat.colum2)
);
}
@@ -199,65 +275,20 @@ namespace StgSharp.Math
);
}
public static bool operator ==(Matrix4x4 left, Matrix4x4 right)
{
return left.Equals(right);
}
public static bool operator !=(Matrix4x4 left, Matrix4x4 right)
{
return !(left == right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe float Det()
public static unsafe Matrix4x4 operator +(Matrix4x4 left, Matrix4x4 right)
{
InternalTranspose();
fixed (Mat4* _this = &mat, _trans = &transpose)
{
return InternalIO.det_mat4(_this,_trans);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal unsafe void InternalTranspose()
{
if (!isTransposed)
{
fixed (Mat4* source = &this.mat, target = &this.transpose)
{
InternalIO.Transpose4to4_internal(source, target);
}
isTransposed = true;
}
}
public override bool Equals(object? obj)
{
return obj is Matrix4x4 x && Equals(x);
}
public bool Equals(Matrix4x4 other)
{
return mat.Equals(other.mat);
}
public override int GetHashCode()
{
return HashCode.Combine(
mat.colum0.GetHashCode(),
mat.colum1.GetHashCode(),
mat.colum2.GetHashCode(),
mat.colum3.GetHashCode()
return new Matrix4x4(
right.mat.colum0 + left.mat.colum0,
right.mat.colum1 + left.mat.colum1,
right.mat.colum2 + left.mat.colum2,
right.mat.colum3 + left.mat.colum3
);
}
public override string ToString()
public static bool operator ==(Matrix4x4 left, Matrix4x4 right)
{
InternalTranspose();
return $"{transpose.colum0}{transpose.colum1}{transpose.colum2}{transpose.colum3}";
return left.Equals(right);
}
}
+49 -25
View File
@@ -1,4 +1,34 @@
using System.Numerics;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="vec2d.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;
using System.Runtime.InteropServices;
@@ -22,30 +52,23 @@ namespace StgSharp.Math
[FieldOffset(0)]
internal Vector2 v;
public Vec2d(float x, float y)
{
v = new Vector2(x, y);
}
internal Vec2d(Vector2 vec)
{
v = vec;
}
public static Vec2d Zero
public Vec2d(float x, float y)
{
get { return new Vec2d(0, 0); }
v = new Vector2(x, y);
}
public static Vec2d Unit
{
get { return new Vec2d(1, 1); }
}
public static Vec2d Unit => new Vec2d(1, 1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator +(Vec2d left, Vec2d right)
public static Vec2d Zero => new Vec2d(0, 0);
public float Cross(Vec2d right)
{
return new Vec2d(left.v + right.v);
return (X * right.Y) - (Y * right.X);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -54,6 +77,11 @@ namespace StgSharp.Math
return new Vec2d(left.v - right.v);
}
public static bool operator !=(Vec2d left, Vec2d right)
{
return !(left == right);
}
public static Vec2d operator *(Vec2d vec, float value)
{
return new Vec2d(vec.v * value);
@@ -64,20 +92,16 @@ namespace StgSharp.Math
return new Vec2d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vec2d operator +(Vec2d left, Vec2d right)
{
return new Vec2d(left.v + right.v);
}
public static bool operator ==(Vec2d left, Vec2d right)
{
return left.v == right.v;
}
public static bool operator !=(Vec2d left, Vec2d right)
{
return !(left == right);
}
public float Cross(Vec2d right)
{
return X * right.Y - Y * right.X;
}
}
}
+125 -88
View File
@@ -1,4 +1,35 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="vec3d.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 System;
using System.Numerics;
using System.Runtime.CompilerServices;
@@ -10,6 +41,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct vec3d : IEquatable<vec3d>
{
[FieldOffset(0)]
internal Vector4 vec;
[FieldOffset(0)]
@@ -19,21 +51,6 @@ namespace StgSharp.Math
[FieldOffset(4)] public float Y;
[FieldOffset(8)] public float Z;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Zero()
{
return new vec3d(0, 0, 0);
}
public vec3d(
float x, float y, float z)
{
#if NET5_0_OR_GREATER
Unsafe.SkipInit(out vec);
#endif
v = new Vector3(x, y, z);
}
internal vec3d(Vector4 vector)
{
vec = vector;
@@ -44,6 +61,25 @@ namespace StgSharp.Math
v = vector;
}
public vec3d(
float x, float y, float z)
{
#if NET5_0_OR_GREATER
Unsafe.SkipInit(out vec);
#endif
v = new Vector3(x, y, z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Cross(vec3d right)
{
return new vec3d(
(this.Y * right.Z) - (this.Z * right.Y),
(this.X * right.Z) - (this.Z * right.X),
(this.X * right.Y) - (this.Y * right.X)
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Dot(vec3d right)
{
@@ -53,75 +89,6 @@ namespace StgSharp.Math
+ vector4.Z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Cross(vec3d right)
{
return new vec3d(
this.Y * right.Z - this.Z * right.Y,
this.X * right.Z - this.Z * right.X,
this.X * right.Y - this.Y * right.X
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator +(vec3d left, vec3d right)
{
return new vec3d(
left.vec + right.vec
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetMaxValue()
{
float ret = X;
ret = ret > Y ? ret : Y;
ret = ret > Z ? ret : Z;
return ret;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator -(vec3d left, vec3d right)
{
return new vec3d(left.v - right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator *(vec3d vec, float value)
{
return new vec3d(vec.v * value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator /(vec3d vec, float value)
{
return new vec3d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator *(vec3d left, vec3d right)
{
return Vector3.Dot(left.v, right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec3d left, vec3d right)
{
return left.v == right.v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(vec3d left, vec3d right)
{
return left.v != right.v;
}
public string ToString(string sample)
{
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
}
public bool Equals(vec3d other)
{
return this.vec == other.vec;
@@ -139,21 +106,91 @@ namespace StgSharp.Math
}
}
public unsafe override int GetHashCode()
public override unsafe int GetHashCode()
{
fixed (float* add = &X)
{
return HashCode.Combine(X, Y, Z, (ulong)add);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetMaxValue()
{
float ret = X;
ret = (ret > Y) ? ret : Y;
ret = (ret > Z) ? ret : Z;
return ret;
}
public override string ToString()
{
return $"[{X},{Y},{Z}]";
}
public string ToString(string sample)
{
return $"[{X.ToString(sample)},{Y.ToString(sample)},{Z.ToString(sample)}]";
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public vec3d Zero()
{
return new vec3d(0, 0, 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator -(vec3d left, vec3d right)
{
return new vec3d(left.v - right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator !=(vec3d left, vec3d right)
{
return left.v != right.v;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator *(vec3d vec, float value)
{
return new vec3d(vec.v * value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static float operator *(vec3d left, vec3d right)
{
return Vector3.Dot(left.v, right.v);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator /(vec3d vec, float value)
{
return new vec3d(vec.v / value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static vec3d operator +(vec3d left, vec3d right)
{
return new vec3d(
left.vec + right.vec
);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool operator ==(vec3d left, vec3d right)
{
return left.v == right.v;
}
}
public static class Vec3d
{
public static vec3d Unit { get => new vec3d(1, 1, 1); }
public static vec3d Zero { get => new vec3d(0, 0, 0); }
public static vec3d Unit => new vec3d(1, 1, 1);
public static vec3d Zero => new vec3d(0, 0, 0);
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using StgSharp.Controlling;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Vec4d.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.Math;
using System;
@@ -11,6 +41,7 @@ namespace StgSharp.Math
[StructLayout(LayoutKind.Explicit, Size = 16, Pack = 16)]
public struct Vec4d
{
[FieldOffset(0)] internal Vector4 vec;
[FieldOffset(0)] internal M128 reg;
@@ -28,5 +59,6 @@ namespace StgSharp.Math
{
return vec.reg;
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ACos.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.CompilerServices;
namespace StgSharp.Math
@@ -75,5 +105,6 @@ namespace StgSharp.Math
return piby2 - v;
*/
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ASin.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.
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
//
//
// some of the code is rewritten from the AMD code:
// https://github.com/amd/aocl-libm-ose/blob/a43e092b03213eb0e129a1cc129900e6e4475778/src/ref/asinf.c
@@ -89,5 +119,6 @@ namespace StgSharp.Math
return sign * v;
*/
}
}
}
+32 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ATan.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.CompilerServices;
namespace StgSharp.Math
@@ -84,5 +114,6 @@ namespace StgSharp.Math
return v;
*/
}
}
}
+33 -1
View File
@@ -1,4 +1,34 @@
using System;
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="BasicOps.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.Globalization;
using System.Runtime.CompilerServices;
@@ -6,6 +36,7 @@ namespace StgSharp.Math
{
public static unsafe partial class Scaler
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static unsafe float Abs(float x)
{
@@ -36,5 +67,6 @@ namespace StgSharp.Math
return CultureInfo.CurrentCulture.TextInfo.ListSeparator;
}
}
}
+34 -3
View File
@@ -1,4 +1,34 @@
namespace StgSharp.Math
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Cos.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.Math
{
public static partial class Scaler
{
@@ -15,8 +45,9 @@
float refer2 = refer * refer;
return -sinData[a] * (0.1570796327f * refer - 6.459640975e-4f * refer * refer2)
+ cosData[a] * (1 - 0.0123370055f * refer2 + 2.536695709e-5f * refer2 * refer2);
return ((-sinData[a]) * ((0.1570796327f * refer) - (6.459640975e-4f * refer * refer2)))
+ (cosData[a] * ((1 - (0.0123370055f * refer2)) + (2.536695709e-5f * refer2 * refer2)));
}
}
}

Some files were not shown because too many files have changed in this diff Show More