Skip to content

Commit

Permalink
Added StructLayout to evrything
Browse files Browse the repository at this point in the history
  • Loading branch information
Tornado-Technology committed Jul 10, 2024
1 parent 735f943 commit 815f414
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Hypercube.Client/Graphics/Vertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public readonly struct Vertex
private static readonly Color DefaultColor = Color.White;

public readonly Vector3 Position;
public readonly Vector2 UVCoords;
public readonly Color Color;
public readonly Vector2 UVCoords;

public Vertex(Vector3 position, Vector2 uvCoords, Color color)
{
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared.Math/Color.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Globalization;
using System.Runtime.InteropServices;
using Hypercube.Shared.Math.Vector;

namespace Hypercube.Shared.Math;

[StructLayout(LayoutKind.Sequential)]
public readonly struct Color
{
public static readonly Color White = new(1f, 1f, 1f);
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared.Math/Matrix/Matrix3X3.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Hypercube.Shared.Math.Vector;

namespace Hypercube.Shared.Math.Matrix;

[StructLayout(LayoutKind.Sequential)]
public struct Matrix3X3(Vector3 x, Vector3 y, Vector3 z)
{
private const int IndexRaw0 = 0;
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared.Math/Matrix/Matrix4X4.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Hypercube.Shared.Math.Box;
using Hypercube.Shared.Math.Vector;

namespace Hypercube.Shared.Math.Matrix;

[StructLayout(LayoutKind.Sequential)]
public partial struct Matrix4X4(Vector4 x, Vector4 y, Vector4 z, Vector4 w) : IEquatable<Matrix4X4>
{
public static Matrix4X4 Zero => new(Vector4.Zero);
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared.Math/Vector/Vector2.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Hypercube.Shared.Math.Vector;

[StructLayout(LayoutKind.Sequential)]
public readonly partial struct Vector2(float x, float y) : IEquatable<Vector2>
{
public static readonly Vector2 Zero = new(0, 0);
Expand Down
8 changes: 6 additions & 2 deletions Hypercube.Shared.Math/Vector/Vector2Int.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Hypercube.Shared.Math.Vector;
using System.Runtime.InteropServices;

namespace Hypercube.Shared.Math.Vector;

[StructLayout(LayoutKind.Sequential)]
public readonly partial struct Vector2Int(int x, int y)
{
public static readonly Vector2Int Zero = new(0, 0);
Expand All @@ -11,7 +14,8 @@ public readonly partial struct Vector2Int(int x, int y)

public readonly int X = x;

Check warning on line 15 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int x' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 15 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int x' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 15 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int x' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 15 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int x' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.
public readonly int Y = y;

Check warning on line 16 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 16 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 16 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 16 in Hypercube.Shared.Math/Vector/Vector2Int.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'int y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.
public readonly float Ratio = x / (float)y;

public float Ratio => x / (float)y;

public static Vector2Int operator +(Vector2Int a, Vector2Int b)
{
Expand Down
17 changes: 14 additions & 3 deletions Hypercube.Shared.Math/Vector/Vector3.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace Hypercube.Shared.Math.Vector;

[StructLayout(LayoutKind.Sequential)]
public readonly partial struct Vector3(float x, float y, float z)
{
public static readonly Vector3 Zero = new(0, 0, 0);
Expand All @@ -20,9 +22,18 @@ public readonly partial struct Vector3(float x, float y, float z)
public readonly float Y = y;

Check warning on line 22 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 22 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 22 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 22 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float y' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.
public readonly float Z = z;

Check warning on line 23 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float z' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

Check warning on line 23 in Hypercube.Shared.Math/Vector/Vector3.cs

View workflow job for this annotation

GitHub Actions / Windows Build

Parameter 'float z' is captured into the state of the enclosing type and its value is also used to initialize a field, property, or event.

public float Length => (float)System.Math.Sqrt(X * X + Y * Y + Z * Z);
public Vector3 Normalized => this / Length;

public float Length
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => MathF.Sqrt(X * X + Y * Y + Z * Z);
}

public Vector3 Normalized
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => this / Length;
}

public Vector3(float value) : this(value, value, value)
{
}
Expand Down
2 changes: 2 additions & 0 deletions Hypercube.Shared.Math/Vector/Vector4.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using Hypercube.Shared.Math.Extensions;

namespace Hypercube.Shared.Math.Vector;

[StructLayout(LayoutKind.Sequential)]
public readonly partial struct Vector4(float x, float y, float z, float w) : IEquatable<Vector4>
{
public static readonly Vector4 Zero = new(0, 0, 0, 0);
Expand Down

0 comments on commit 815f414

Please sign in to comment.