From e55b73db0f804da7da29b55f9caaba72046747e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 8 Dec 2021 20:58:26 +0100 Subject: [PATCH] Renamed Int-Vector and added swizzle --- GlitchyEngine/src/Math/IntExtension.bf | 6 +- GlitchyEngine/src/Math/Vectors/Int2.bf | 162 +++++++++++++ GlitchyEngine/src/Math/Vectors/Int3.bf | 206 ++++++++++++++++ GlitchyEngine/src/Math/Vectors/Int32_2.bf | 162 ------------- GlitchyEngine/src/Math/Vectors/Int32_3.bf | 206 ---------------- GlitchyEngine/src/Math/Vectors/Int32_4.bf | 234 ------------------- GlitchyEngine/src/Math/Vectors/Int4.bf | 234 +++++++++++++++++++ GlitchyEngine/src/Renderer/BufferVariable.bf | 12 +- GlitchyEngine/src/Renderer/Material.bf | 6 +- GlitchyEngine/src/Renderer/Text/Font.bf | 12 +- 10 files changed, 620 insertions(+), 620 deletions(-) create mode 100644 GlitchyEngine/src/Math/Vectors/Int2.bf create mode 100644 GlitchyEngine/src/Math/Vectors/Int3.bf delete mode 100644 GlitchyEngine/src/Math/Vectors/Int32_2.bf delete mode 100644 GlitchyEngine/src/Math/Vectors/Int32_3.bf delete mode 100644 GlitchyEngine/src/Math/Vectors/Int32_4.bf create mode 100644 GlitchyEngine/src/Math/Vectors/Int4.bf diff --git a/GlitchyEngine/src/Math/IntExtension.bf b/GlitchyEngine/src/Math/IntExtension.bf index 508c8fa..0bab554 100644 --- a/GlitchyEngine/src/Math/IntExtension.bf +++ b/GlitchyEngine/src/Math/IntExtension.bf @@ -13,12 +13,12 @@ namespace System } [Inline] - public Int32_2 XX => Int32_2((int32)this); + public Int2 XX => Int2((int32)this); [Inline] - public Int32_3 XXX => Int32_3((int32)this); + public Int3 XXX => Int3((int32)this); [Inline] - public Int32_4 XXXX => Int32_4((int32)this); + public Int4 XXXX => Int4((int32)this); } } diff --git a/GlitchyEngine/src/Math/Vectors/Int2.bf b/GlitchyEngine/src/Math/Vectors/Int2.bf new file mode 100644 index 0000000..7bd04de --- /dev/null +++ b/GlitchyEngine/src/Math/Vectors/Int2.bf @@ -0,0 +1,162 @@ +#pragma warning disable 4204 + +using System; +using System.Diagnostics; + +namespace GlitchyEngine.Math +{ + /** + * A Vector with two components of type int32. + */ + [SwizzleVector(2, "Int")] + public struct Int2 : IHashable + { + public const Int2 Zero = .(0, 0); + public const Int2 UnitX = .(1, 0); + public const Int2 UnitY = .(0, 1); + public const Int2 One = .(1, 1); + + public int32 X, Y; + + public this() => this = default; + + public this(int32 value) + { + X = value; + Y = value; + } + + public this(int value) + { + X = (.)value; + Y = (.)value; + } + + public this(int32 x, int32 y) + { + X = x; + Y = y; + } + + public this(int x, int y) + { + X = (.)x; + Y = (.)y; + } + + public ref int32 this[int index] + { + [Inline] + get + { +#if DEBUG + if(index < 0 || index >= 2) + Internal.ThrowIndexOutOfRange(1); +#endif + + return ref (&X)[index]; + } + } + + public int32 MagnitudeSquared() => X * X + Y * Y; + + public float Magnitude() => Math.Sqrt(X * X + Y * Y); + + public Int2 Abs() => .(Math.Abs(X), Math.Abs(Y)); + + // + // Assignment operators + // + + public void operator +=(Int2 value) mut + { + X += value.X; + Y += value.Y; + } + + public void operator +=(int32 value) mut + { + X += value; + Y += value; + } + + public void operator -=(Int2 value) mut + { + X -= value.X; + Y -= value.Y; + } + + public void operator -=(int32 value) mut + { + X -= value; + Y -= value; + } + + public void operator *=(Int2 value) mut + { + X *= value.X; + Y *= value.Y; + } + + public void operator *=(int32 value) mut + { + X *= value; + Y *= value; + } + + public void operator /=(Int2 value) mut + { + X /= value.X; + Y /= value.Y; + } + + public void operator /=(int32 value) mut + { + X /= value; + Y /= value; + } + + // Operators + + public static Int2 operator +(Int2 value) => value; + public static Int2 operator +(Int2 left, Int2 right) => .(left.X + right.X, left.Y + right.Y); + public static Int2 operator +(Int2 left, int32 right) => .(left.X + right, left.Y + right); + public static Int2 operator +(int32 left, Int2 right) => .(left + right.X, left + right.Y); + + public static Int2 operator -(Int2 value) => .(-value.X, -value.Y); + public static Int2 operator -(Int2 left, Int2 right) => .(left.X - right.X, left.Y - right.Y); + public static Int2 operator -(Int2 left, int32 right) => .(left.X - right, left.Y - right); + public static Int2 operator -(int32 left, Int2 right) => .(left - right.X, left - right.Y); + + public static Int2 operator *(Int2 left, Int2 right) => .(left.X * right.X, left.Y * right.Y); + public static Int2 operator *(Int2 left, int32 right) => .(left.X * right, left.Y * right); + public static Int2 operator *(int32 left, Int2 right) => .(left * right.X, left * right.Y); + + public static Int2 operator /(Int2 left, Int2 right) => .(left.X / right.X, left.Y / right.Y); + public static Int2 operator /(Int2 left, int32 right) => .(left.X / right, left.Y / right); + public static Int2 operator /(int32 left, Int2 right) => .(left / right.X, left / right.Y); + + public static Int2 operator %(Int2 left, Int2 right) => .(left.X % right.X, left.Y % right.Y); + public static Int2 operator %(Int2 left, int32 right) => .(left.X % right, left.Y % right); + public static Int2 operator %(int32 left, Int2 right) => .(left % right.X, left % right.Y); + + public static bool operator ==(Int2 left, Int2 right) => left.X == right.X && left.Y == right.Y; + public static bool operator ==(Int2 left, int32 right) => left.X == right && left.Y == right; + public static bool operator ==(int32 left, Int2 right) => left == right.X && left == right.Y; + + public static bool operator !=(Int2 left, Int2 right) => left.X != right.X || left.Y != right.Y; + public static bool operator !=(Int2 left, int32 right) => left.X != right || left.Y != right; + public static bool operator !=(int32 left, Int2 right) => left != right.X || left != right.Y; + + public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y}"); + + public static explicit operator Vector2(Int2 point) => .(point.X, point.Y); + + public static explicit operator Int2(Vector2 point) => .((int32)point.X, (int32)point.Y); + + public int GetHashCode() + { + return (X * 39) ^ Y; + } + } +} diff --git a/GlitchyEngine/src/Math/Vectors/Int3.bf b/GlitchyEngine/src/Math/Vectors/Int3.bf new file mode 100644 index 0000000..0e7db10 --- /dev/null +++ b/GlitchyEngine/src/Math/Vectors/Int3.bf @@ -0,0 +1,206 @@ +#pragma warning disable 4204 + +using System; +using System.Diagnostics; + +namespace GlitchyEngine.Math +{ + /** + * A Vector with three components of type int32. + */ + [SwizzleVector(3, "Int")] + public struct Int3 : IHashable + { + public const Int3 Zero = .(0, 0, 0); + public const Int3 UnitX = .(1, 0, 0); + public const Int3 UnitY = .(0, 1, 0); + public const Int3 UnitZ = .(0, 0, 1); + public const Int3 One = .(1, 1, 1); + + public int32 X, Y, Z; + + public this() => this = default; + + public this(int32 value) + { + X = value; + Y = value; + Z = value; + } + + public this(int value) + { + X = (.)value; + Y = (.)value; + Z = (.)value; + } + + public this(int32 x, int32 y, int32 z) + { + X = x; + Y = y; + Z = z; + } + + public this(Int2 xy, int32 z) + { + X = xy.X; + Y = xy.Y; + Z = z; + } + + public this(int32 x, Int2 yz) + { + X = x; + Y = yz.X; + Z = yz.Y; + } + + public this(int x, int y, int z) + { + X = (.)x; + Y = (.)y; + Z = (.)z; + } + + public this(Int2 xy, int z) + { + X = xy.X; + Y = xy.Y; + Z = (.)z; + } + + public this(int x, Int2 yz) + { + X = (.)x; + Y = yz.X; + Z = yz.Y; + } + + public ref int32 this[int index] + { + [Inline] + get + { +#if DEBUG + if(index < 0 || index >= 3) + Internal.ThrowIndexOutOfRange(1); +#endif + + return ref (&X)[index]; + } + } + + public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z; + + public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z); + + public Int3 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z)); + + // + // Assignment operators + // + + public void operator +=(Int3 value) mut + { + X += value.X; + Y += value.Y; + Z += value.Z; + } + + public void operator +=(int32 value) mut + { + X += value; + Y += value; + Z += value; + } + + public void operator -=(Int3 value) mut + { + X -= value.X; + Y -= value.Y; + Z -= value.Z; + } + + public void operator -=(int32 value) mut + { + X -= value; + Y -= value; + Z -= value; + } + + public void operator *=(Int3 value) mut + { + X *= value.X; + Y *= value.Y; + Z *= value.Z; + } + + public void operator *=(int32 value) mut + { + X *= value; + Y *= value; + Z *= value; + } + + public void operator /=(Int3 value) mut + { + X /= value.X; + Y /= value.Y; + Z /= value.Z; + } + + public void operator /=(int32 value) mut + { + X /= value; + Y /= value; + Z /= value; + } + + // Operators + + public static Int3 operator +(Int3 value) => value; + public static Int3 operator +(Int3 left, Int3 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z); + public static Int3 operator +(Int3 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right); + public static Int3 operator +(int32 left, Int3 right) => .(left + right.X, left + right.Y, left + right.Z); + + public static Int3 operator -(Int3 value) => .(-value.X, -value.Y, -value.Z); + public static Int3 operator -(Int3 left, Int3 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z); + public static Int3 operator -(Int3 left, int32 right) => .(left.X - right, left.Y - right, left.Z- right); + public static Int3 operator -(int32 left, Int3 right) => .(left - right.X, left - right.Y, left - right.Z); + + public static Int3 operator *(Int3 left, Int3 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z); + public static Int3 operator *(Int3 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right); + public static Int3 operator *(int32 left, Int3 right) => .(left * right.X, left * right.Y, left * right.Z); + + public static Int3 operator /(Int3 left, Int3 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z); + public static Int3 operator /(Int3 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right); + public static Int3 operator /(int32 left, Int3 right) => .(left / right.X, left / right.Y, left / right.Z); + + public static Int3 operator %(Int3 left, Int3 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z); + public static Int3 operator %(Int3 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right); + public static Int3 operator %(int32 left, Int3 right) => .(left % right.X, left % right.Y, left % right.Z); + + public static bool operator ==(Int3 left, Int3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z; + public static bool operator ==(Int3 left, int32 right) => left.X == right && left.Y == right && left.Z == right; + public static bool operator ==(int32 left, Int3 right) => left == right.X && left == right.Y && left == right.Z; + + public static bool operator !=(Int3 left, Int3 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z; + public static bool operator !=(Int3 left, int32 right) => left.X != right || left.Y != right || left.Z != right; + public static bool operator !=(int32 left, Int3 right) => left != right.X || left != right.Y || left != right.Z; + + public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z}"); + + public static explicit operator Vector3(Int3 point) => .(point.X, point.Y, point.Z); + + public static explicit operator Int3(Vector3 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z); + + [Inline] + public static explicit operator Int2(in Int3 point) => *(Int2*)&point; + + public int GetHashCode() + { + return (((X * 39) ^ Y) * 39) ^ Z; + } + } +} diff --git a/GlitchyEngine/src/Math/Vectors/Int32_2.bf b/GlitchyEngine/src/Math/Vectors/Int32_2.bf deleted file mode 100644 index a407d93..0000000 --- a/GlitchyEngine/src/Math/Vectors/Int32_2.bf +++ /dev/null @@ -1,162 +0,0 @@ -#pragma warning disable 4204 - -using System; -using System.Diagnostics; - -namespace GlitchyEngine.Math -{ - /** - * A Vector with two components of type int32. - */ - //[SwizzleVector(2, "Int32_")] - public struct Int32_2 : IHashable - { - public const Int32_2 Zero = .(0, 0); - public const Int32_2 UnitX = .(1, 0); - public const Int32_2 UnitY = .(0, 1); - public const Int32_2 One = .(1, 1); - - public int32 X, Y; - - public this() => this = default; - - public this(int32 value) - { - X = value; - Y = value; - } - - public this(int value) - { - X = (.)value; - Y = (.)value; - } - - public this(int32 x, int32 y) - { - X = x; - Y = y; - } - - public this(int x, int y) - { - X = (.)x; - Y = (.)y; - } - - public ref int32 this[int index] - { - [Inline] - get - { -#if DEBUG - if(index < 0 || index >= 2) - Internal.ThrowIndexOutOfRange(1); -#endif - - return ref (&X)[index]; - } - } - - public int32 MagnitudeSquared() => X * X + Y * Y; - - public float Magnitude() => Math.Sqrt(X * X + Y * Y); - - public Int32_2 Abs() => .(Math.Abs(X), Math.Abs(Y)); - - // - // Assignment operators - // - - public void operator +=(Int32_2 value) mut - { - X += value.X; - Y += value.Y; - } - - public void operator +=(int32 value) mut - { - X += value; - Y += value; - } - - public void operator -=(Int32_2 value) mut - { - X -= value.X; - Y -= value.Y; - } - - public void operator -=(int32 value) mut - { - X -= value; - Y -= value; - } - - public void operator *=(Int32_2 value) mut - { - X *= value.X; - Y *= value.Y; - } - - public void operator *=(int32 value) mut - { - X *= value; - Y *= value; - } - - public void operator /=(Int32_2 value) mut - { - X /= value.X; - Y /= value.Y; - } - - public void operator /=(int32 value) mut - { - X /= value; - Y /= value; - } - - // Operators - - public static Int32_2 operator +(Int32_2 value) => value; - public static Int32_2 operator +(Int32_2 left, Int32_2 right) => .(left.X + right.X, left.Y + right.Y); - public static Int32_2 operator +(Int32_2 left, int32 right) => .(left.X + right, left.Y + right); - public static Int32_2 operator +(int32 left, Int32_2 right) => .(left + right.X, left + right.Y); - - public static Int32_2 operator -(Int32_2 value) => .(-value.X, -value.Y); - public static Int32_2 operator -(Int32_2 left, Int32_2 right) => .(left.X - right.X, left.Y - right.Y); - public static Int32_2 operator -(Int32_2 left, int32 right) => .(left.X - right, left.Y - right); - public static Int32_2 operator -(int32 left, Int32_2 right) => .(left - right.X, left - right.Y); - - public static Int32_2 operator *(Int32_2 left, Int32_2 right) => .(left.X * right.X, left.Y * right.Y); - public static Int32_2 operator *(Int32_2 left, int32 right) => .(left.X * right, left.Y * right); - public static Int32_2 operator *(int32 left, Int32_2 right) => .(left * right.X, left * right.Y); - - public static Int32_2 operator /(Int32_2 left, Int32_2 right) => .(left.X / right.X, left.Y / right.Y); - public static Int32_2 operator /(Int32_2 left, int32 right) => .(left.X / right, left.Y / right); - public static Int32_2 operator /(int32 left, Int32_2 right) => .(left / right.X, left / right.Y); - - public static Int32_2 operator %(Int32_2 left, Int32_2 right) => .(left.X % right.X, left.Y % right.Y); - public static Int32_2 operator %(Int32_2 left, int32 right) => .(left.X % right, left.Y % right); - public static Int32_2 operator %(int32 left, Int32_2 right) => .(left % right.X, left % right.Y); - - public static bool operator ==(Int32_2 left, Int32_2 right) => left.X == right.X && left.Y == right.Y; - public static bool operator ==(Int32_2 left, int32 right) => left.X == right && left.Y == right; - public static bool operator ==(int32 left, Int32_2 right) => left == right.X && left == right.Y; - - public static bool operator !=(Int32_2 left, Int32_2 right) => left.X != right.X || left.Y != right.Y; - public static bool operator !=(Int32_2 left, int32 right) => left.X != right || left.Y != right; - public static bool operator !=(int32 left, Int32_2 right) => left != right.X || left != right.Y; - - public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y}"); - - public static explicit operator Vector2(Int32_2 point) => .(point.X, point.Y); - - public static explicit operator Int32_2(Vector2 point) => .((int32)point.X, (int32)point.Y); - - public int GetHashCode() - { - return (X * 39) ^ Y; - } - } -} diff --git a/GlitchyEngine/src/Math/Vectors/Int32_3.bf b/GlitchyEngine/src/Math/Vectors/Int32_3.bf deleted file mode 100644 index 519530c..0000000 --- a/GlitchyEngine/src/Math/Vectors/Int32_3.bf +++ /dev/null @@ -1,206 +0,0 @@ -#pragma warning disable 4204 - -using System; -using System.Diagnostics; - -namespace GlitchyEngine.Math -{ - /** - * A Vector with three components of type int32. - */ - //[SwizzleVector(3, "Int32_")] - public struct Int32_3 : IHashable - { - public const Int32_3 Zero = .(0, 0, 0); - public const Int32_3 UnitX = .(1, 0, 0); - public const Int32_3 UnitY = .(0, 1, 0); - public const Int32_3 UnitZ = .(0, 0, 1); - public const Int32_3 One = .(1, 1, 1); - - public int32 X, Y, Z; - - public this() => this = default; - - public this(int32 value) - { - X = value; - Y = value; - Z = value; - } - - public this(int value) - { - X = (.)value; - Y = (.)value; - Z = (.)value; - } - - public this(int32 x, int32 y, int32 z) - { - X = x; - Y = y; - Z = z; - } - - public this(Int32_2 xy, int32 z) - { - X = xy.X; - Y = xy.Y; - Z = z; - } - - public this(int32 x, Int32_2 yz) - { - X = x; - Y = yz.X; - Z = yz.Y; - } - - public this(int x, int y, int z) - { - X = (.)x; - Y = (.)y; - Z = (.)z; - } - - public this(Int32_2 xy, int z) - { - X = xy.X; - Y = xy.Y; - Z = (.)z; - } - - public this(int x, Int32_2 yz) - { - X = (.)x; - Y = yz.X; - Z = yz.Y; - } - - public ref int32 this[int index] - { - [Inline] - get - { -#if DEBUG - if(index < 0 || index >= 3) - Internal.ThrowIndexOutOfRange(1); -#endif - - return ref (&X)[index]; - } - } - - public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z; - - public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z); - - public Int32_3 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z)); - - // - // Assignment operators - // - - public void operator +=(Int32_3 value) mut - { - X += value.X; - Y += value.Y; - Z += value.Z; - } - - public void operator +=(int32 value) mut - { - X += value; - Y += value; - Z += value; - } - - public void operator -=(Int32_3 value) mut - { - X -= value.X; - Y -= value.Y; - Z -= value.Z; - } - - public void operator -=(int32 value) mut - { - X -= value; - Y -= value; - Z -= value; - } - - public void operator *=(Int32_3 value) mut - { - X *= value.X; - Y *= value.Y; - Z *= value.Z; - } - - public void operator *=(int32 value) mut - { - X *= value; - Y *= value; - Z *= value; - } - - public void operator /=(Int32_3 value) mut - { - X /= value.X; - Y /= value.Y; - Z /= value.Z; - } - - public void operator /=(int32 value) mut - { - X /= value; - Y /= value; - Z /= value; - } - - // Operators - - public static Int32_3 operator +(Int32_3 value) => value; - public static Int32_3 operator +(Int32_3 left, Int32_3 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z); - public static Int32_3 operator +(Int32_3 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right); - public static Int32_3 operator +(int32 left, Int32_3 right) => .(left + right.X, left + right.Y, left + right.Z); - - public static Int32_3 operator -(Int32_3 value) => .(-value.X, -value.Y, -value.Z); - public static Int32_3 operator -(Int32_3 left, Int32_3 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z); - public static Int32_3 operator -(Int32_3 left, int32 right) => .(left.X - right, left.Y - right, left.Z- right); - public static Int32_3 operator -(int32 left, Int32_3 right) => .(left - right.X, left - right.Y, left - right.Z); - - public static Int32_3 operator *(Int32_3 left, Int32_3 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z); - public static Int32_3 operator *(Int32_3 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right); - public static Int32_3 operator *(int32 left, Int32_3 right) => .(left * right.X, left * right.Y, left * right.Z); - - public static Int32_3 operator /(Int32_3 left, Int32_3 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z); - public static Int32_3 operator /(Int32_3 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right); - public static Int32_3 operator /(int32 left, Int32_3 right) => .(left / right.X, left / right.Y, left / right.Z); - - public static Int32_3 operator %(Int32_3 left, Int32_3 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z); - public static Int32_3 operator %(Int32_3 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right); - public static Int32_3 operator %(int32 left, Int32_3 right) => .(left % right.X, left % right.Y, left % right.Z); - - public static bool operator ==(Int32_3 left, Int32_3 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z; - public static bool operator ==(Int32_3 left, int32 right) => left.X == right && left.Y == right && left.Z == right; - public static bool operator ==(int32 left, Int32_3 right) => left == right.X && left == right.Y && left == right.Z; - - public static bool operator !=(Int32_3 left, Int32_3 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z; - public static bool operator !=(Int32_3 left, int32 right) => left.X != right || left.Y != right || left.Z != right; - public static bool operator !=(int32 left, Int32_3 right) => left != right.X || left != right.Y || left != right.Z; - - public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z}"); - - public static explicit operator Vector3(Int32_3 point) => .(point.X, point.Y, point.Z); - - public static explicit operator Int32_3(Vector3 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z); - - [Inline] - public static explicit operator Int32_2(in Int32_3 point) => *(Int32_2*)&point; - - public int GetHashCode() - { - return (((X * 39) ^ Y) * 39) ^ Z; - } - } -} diff --git a/GlitchyEngine/src/Math/Vectors/Int32_4.bf b/GlitchyEngine/src/Math/Vectors/Int32_4.bf deleted file mode 100644 index a2009c6..0000000 --- a/GlitchyEngine/src/Math/Vectors/Int32_4.bf +++ /dev/null @@ -1,234 +0,0 @@ -#pragma warning disable 4204 - -using System; -using System.Diagnostics; - -namespace GlitchyEngine.Math -{ - /** - * A Vector with four components of type int32. - */ - //[SwizzleVector(4, "Int32_")] - public struct Int32_4 : IHashable - { - public const Int32_4 Zero = .(0, 0, 0, 0); - public const Int32_4 UnitX = .(1, 0, 0, 0); - public const Int32_4 UnitY = .(0, 1, 0, 0); - public const Int32_4 UnitZ = .(0, 0, 1, 0); - public const Int32_4 UnitW = .(0, 0, 0, 1); - public const Int32_4 One = .(1, 1, 1, 1); - - public int32 X, Y, Z, W; - - public this() => this = default; - - public this(int32 value) - { - X = value; - Y = value; - Z = value; - W = value; - } - - public this(int value) - { - X = (.)value; - Y = (.)value; - Z = (.)value; - W = (.)value; - } - - public this(int32 x, int32 y, int32 z, int32 w) - { - X = x; - Y = y; - Z = z; - W = w; - } - - public this(Int32_2 xy, int32 z, int32 w) - { - X = xy.X; - Y = xy.Y; - Z = z; - W = w; - } - - public this(int32 x, Int32_2 yz, int32 w) - { - X = x; - Y = yz.X; - Z = yz.Y; - W = w; - } - - public this(int32 x, int32 y, Int32_2 zw) - { - X = x; - Y = y; - Z = zw.X; - W = zw.Y; - } - - public this(Int32_2 xy, Int32_2 zw) - { - X = xy.X; - Y = xy.Y; - Z = zw.X; - W = zw.Y; - } - - public this(Int32_3 xyz, int32 w) - { - X = xyz.X; - Y = xyz.Y; - Z = xyz.Z; - W = w; - } - - public this(int32 x, Int32_3 yzw) - { - X = x; - Y = yzw.X; - Z = yzw.Y; - W = yzw.Z; - } - - public ref int32 this[int index] - { - [Inline] - get - { -#if DEBUG - if(index < 0 || index >= 3) - Internal.ThrowIndexOutOfRange(1); -#endif - - return ref (&X)[index]; - } - } - - public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z + W * W; - - public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z + W * W); - - public Int32_4 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z), Math.Abs(W)); - - // - // Assignment operators - // - - public void operator +=(Int32_4 value) mut - { - X += value.X; - Y += value.Y; - Z += value.Z; - W += value.W; - } - - public void operator +=(int32 value) mut - { - X += value; - Y += value; - Z += value; - W += value; - } - - public void operator -=(Int32_4 value) mut - { - X -= value.X; - Y -= value.Y; - Z -= value.Z; - W -= value.W; - } - - public void operator -=(int32 value) mut - { - X -= value; - Y -= value; - Z -= value; - W -= value; - } - - public void operator *=(Int32_4 value) mut - { - X *= value.X; - Y *= value.Y; - Z *= value.Z; - W *= value.W; - } - - public void operator *=(int32 value) mut - { - X *= value; - Y *= value; - Z *= value; - W *= value; - } - - public void operator /=(Int32_4 value) mut - { - X /= value.X; - Y /= value.Y; - Z /= value.Z; - W /= value.W; - } - - public void operator /=(int32 value) mut - { - X /= value; - Y /= value; - Z /= value; - W /= value; - } - - // Operators - - public static Int32_4 operator +(Int32_4 value) => value; - public static Int32_4 operator +(Int32_4 left, Int32_4 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); - public static Int32_4 operator +(Int32_4 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right, left.W + right); - public static Int32_4 operator +(int32 left, Int32_4 right) => .(left + right.X, left + right.Y, left + right.Z, left + right.W); - - public static Int32_4 operator -(Int32_4 value) => .(-value.X, -value.Y, -value.Z, -value.W); - public static Int32_4 operator -(Int32_4 left, Int32_4 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); - public static Int32_4 operator -(Int32_4 left, int32 right) => .(left.X - right, left.Y - right, left.Z - right, left.W - right); - public static Int32_4 operator -(int32 left, Int32_4 right) => .(left - right.X, left - right.Y, left - right.Z, left - right.W); - - public static Int32_4 operator *(Int32_4 left, Int32_4 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); - public static Int32_4 operator *(Int32_4 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right, left.W * right); - public static Int32_4 operator *(int32 left, Int32_4 right) => .(left * right.X, left * right.Y, left * right.Z, left * right.W); - - public static Int32_4 operator /(Int32_4 left, Int32_4 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); - public static Int32_4 operator /(Int32_4 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right, left.W / right); - public static Int32_4 operator /(int32 left, Int32_4 right) => .(left / right.X, left / right.Y, left / right.Z, left / right.W); - - public static Int32_4 operator %(Int32_4 left, Int32_4 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z, left.W % right.W); - public static Int32_4 operator %(Int32_4 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right, left.W % right); - public static Int32_4 operator %(int32 left, Int32_4 right) => .(left % right.X, left % right.Y, left % right.Z, left % right.W); - - public static bool operator ==(Int32_4 left, Int32_4 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W; - public static bool operator ==(Int32_4 left, int32 right) => left.X == right && left.Y == right && left.Z == right && left.W == right; - public static bool operator ==(int32 left, Int32_4 right) => left == right.X && left == right.Y && left == right.Z && left == right.W; - - public static bool operator !=(Int32_4 left, Int32_4 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W; - public static bool operator !=(Int32_4 left, int32 right) => left.X != right || left.Y != right || left.Z != right || left.W != right; - public static bool operator !=(int32 left, Int32_4 right) => left != right.X || left != right.Y || left != right.Z || left != right.W; - - public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z} W:{W}"); - - public static explicit operator Vector4(Int32_4 point) => .(point.X, point.Y, point.Z, point.W); - - public static explicit operator Int32_4(Vector4 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z, (int32)point.W); - - [Inline] - public static explicit operator Int32_2(in Int32_4 point) => *(Int32_2*)&point; - - [Inline] - public static explicit operator Int32_3(in Int32_4 point) => *(Int32_3*)&point; - - public int GetHashCode() - { - return (((((X * 39) ^ Y) * 39) ^ Z) * 39) ^ W; - } - } -} diff --git a/GlitchyEngine/src/Math/Vectors/Int4.bf b/GlitchyEngine/src/Math/Vectors/Int4.bf new file mode 100644 index 0000000..3f0dc6d --- /dev/null +++ b/GlitchyEngine/src/Math/Vectors/Int4.bf @@ -0,0 +1,234 @@ +#pragma warning disable 4204 + +using System; +using System.Diagnostics; + +namespace GlitchyEngine.Math +{ + /** + * A Vector with four components of type int32. + */ + [SwizzleVector(4, "Int")] + public struct Int4 : IHashable + { + public const Int4 Zero = .(0, 0, 0, 0); + public const Int4 UnitX = .(1, 0, 0, 0); + public const Int4 UnitY = .(0, 1, 0, 0); + public const Int4 UnitZ = .(0, 0, 1, 0); + public const Int4 UnitW = .(0, 0, 0, 1); + public const Int4 One = .(1, 1, 1, 1); + + public int32 X, Y, Z, W; + + public this() => this = default; + + public this(int32 value) + { + X = value; + Y = value; + Z = value; + W = value; + } + + public this(int value) + { + X = (.)value; + Y = (.)value; + Z = (.)value; + W = (.)value; + } + + public this(int32 x, int32 y, int32 z, int32 w) + { + X = x; + Y = y; + Z = z; + W = w; + } + + public this(Int2 xy, int32 z, int32 w) + { + X = xy.X; + Y = xy.Y; + Z = z; + W = w; + } + + public this(int32 x, Int2 yz, int32 w) + { + X = x; + Y = yz.X; + Z = yz.Y; + W = w; + } + + public this(int32 x, int32 y, Int2 zw) + { + X = x; + Y = y; + Z = zw.X; + W = zw.Y; + } + + public this(Int2 xy, Int2 zw) + { + X = xy.X; + Y = xy.Y; + Z = zw.X; + W = zw.Y; + } + + public this(Int3 xyz, int32 w) + { + X = xyz.X; + Y = xyz.Y; + Z = xyz.Z; + W = w; + } + + public this(int32 x, Int3 yzw) + { + X = x; + Y = yzw.X; + Z = yzw.Y; + W = yzw.Z; + } + + public ref int32 this[int index] + { + [Inline] + get + { +#if DEBUG + if(index < 0 || index >= 3) + Internal.ThrowIndexOutOfRange(1); +#endif + + return ref (&X)[index]; + } + } + + public int32 MagnitudeSquared() => X * X + Y * Y + Z * Z + W * W; + + public float Magnitude() => Math.Sqrt(X * X + Y * Y + Z * Z + W * W); + + public Int4 Abs() => .(Math.Abs(X), Math.Abs(Y), Math.Abs(Z), Math.Abs(W)); + + // + // Assignment operators + // + + public void operator +=(Int4 value) mut + { + X += value.X; + Y += value.Y; + Z += value.Z; + W += value.W; + } + + public void operator +=(int32 value) mut + { + X += value; + Y += value; + Z += value; + W += value; + } + + public void operator -=(Int4 value) mut + { + X -= value.X; + Y -= value.Y; + Z -= value.Z; + W -= value.W; + } + + public void operator -=(int32 value) mut + { + X -= value; + Y -= value; + Z -= value; + W -= value; + } + + public void operator *=(Int4 value) mut + { + X *= value.X; + Y *= value.Y; + Z *= value.Z; + W *= value.W; + } + + public void operator *=(int32 value) mut + { + X *= value; + Y *= value; + Z *= value; + W *= value; + } + + public void operator /=(Int4 value) mut + { + X /= value.X; + Y /= value.Y; + Z /= value.Z; + W /= value.W; + } + + public void operator /=(int32 value) mut + { + X /= value; + Y /= value; + Z /= value; + W /= value; + } + + // Operators + + public static Int4 operator +(Int4 value) => value; + public static Int4 operator +(Int4 left, Int4 right) => .(left.X + right.X, left.Y + right.Y, left.Z + right.Z, left.W + right.W); + public static Int4 operator +(Int4 left, int32 right) => .(left.X + right, left.Y + right, left.Z + right, left.W + right); + public static Int4 operator +(int32 left, Int4 right) => .(left + right.X, left + right.Y, left + right.Z, left + right.W); + + public static Int4 operator -(Int4 value) => .(-value.X, -value.Y, -value.Z, -value.W); + public static Int4 operator -(Int4 left, Int4 right) => .(left.X - right.X, left.Y - right.Y, left.Z - right.Z, left.W - right.W); + public static Int4 operator -(Int4 left, int32 right) => .(left.X - right, left.Y - right, left.Z - right, left.W - right); + public static Int4 operator -(int32 left, Int4 right) => .(left - right.X, left - right.Y, left - right.Z, left - right.W); + + public static Int4 operator *(Int4 left, Int4 right) => .(left.X * right.X, left.Y * right.Y, left.Z * right.Z, left.W * right.W); + public static Int4 operator *(Int4 left, int32 right) => .(left.X * right, left.Y * right, left.Z * right, left.W * right); + public static Int4 operator *(int32 left, Int4 right) => .(left * right.X, left * right.Y, left * right.Z, left * right.W); + + public static Int4 operator /(Int4 left, Int4 right) => .(left.X / right.X, left.Y / right.Y, left.Z / right.Z, left.W / right.W); + public static Int4 operator /(Int4 left, int32 right) => .(left.X / right, left.Y / right, left.Z / right, left.W / right); + public static Int4 operator /(int32 left, Int4 right) => .(left / right.X, left / right.Y, left / right.Z, left / right.W); + + public static Int4 operator %(Int4 left, Int4 right) => .(left.X % right.X, left.Y % right.Y, left.Z % right.Z, left.W % right.W); + public static Int4 operator %(Int4 left, int32 right) => .(left.X % right, left.Y % right, left.Z % right, left.W % right); + public static Int4 operator %(int32 left, Int4 right) => .(left % right.X, left % right.Y, left % right.Z, left % right.W); + + public static bool operator ==(Int4 left, Int4 right) => left.X == right.X && left.Y == right.Y && left.Z == right.Z && left.W == right.W; + public static bool operator ==(Int4 left, int32 right) => left.X == right && left.Y == right && left.Z == right && left.W == right; + public static bool operator ==(int32 left, Int4 right) => left == right.X && left == right.Y && left == right.Z && left == right.W; + + public static bool operator !=(Int4 left, Int4 right) => left.X != right.X || left.Y != right.Y || left.Z != right.Z || left.W != right.W; + public static bool operator !=(Int4 left, int32 right) => left.X != right || left.Y != right || left.Z != right || left.W != right; + public static bool operator !=(int32 left, Int4 right) => left != right.X || left != right.Y || left != right.Z || left != right.W; + + public override void ToString(String strBuffer) => strBuffer.AppendF($"X:{X} Y:{Y} Z:{Z} W:{W}"); + + public static explicit operator Vector4(Int4 point) => .(point.X, point.Y, point.Z, point.W); + + public static explicit operator Int4(Vector4 point) => .((int32)point.X, (int32)point.Y, (int32)point.Z, (int32)point.W); + + [Inline] + public static explicit operator Int2(in Int4 point) => *(Int2*)&point; + + [Inline] + public static explicit operator Int3(in Int4 point) => *(Int3*)&point; + + public int GetHashCode() + { + return (((((X * 39) ^ Y) * 39) ^ Z) * 39) ^ W; + } + } +} diff --git a/GlitchyEngine/src/Renderer/BufferVariable.bf b/GlitchyEngine/src/Renderer/BufferVariable.bf index f68a9bd..e453dfc 100644 --- a/GlitchyEngine/src/Renderer/BufferVariable.bf +++ b/GlitchyEngine/src/Renderer/BufferVariable.bf @@ -82,11 +82,11 @@ namespace GlitchyEngine.Renderer case typeof(int32): EnsureTypeMatch(1, 1, .Int); - case typeof(Int32_2): + case typeof(Int2): EnsureTypeMatch(1, 2, .Int); - case typeof(Int32_3): + case typeof(Int3): EnsureTypeMatch(1, 3, .Int); - case typeof(Int32_4): + case typeof(Int4): EnsureTypeMatch(1, 4, .Int); case typeof(Matrix4x3): @@ -127,9 +127,9 @@ namespace GlitchyEngine.Renderer public void SetData(Vector4 value) => SetData(value); public void SetData(int32 value) => SetData(value); - public void SetData(Int32_2 value) => SetData(value); - public void SetData(Int32_3 value) => SetData(value); - public void SetData(Int32_4 value) => SetData(value); + public void SetData(Int2 value) => SetData(value); + public void SetData(Int3 value) => SetData(value); + public void SetData(Int4 value) => SetData(value); public void SetData(ColorRGB value) => SetData(value); public void SetData(ColorRGBA value) => SetData(value); diff --git a/GlitchyEngine/src/Renderer/Material.bf b/GlitchyEngine/src/Renderer/Material.bf index 01e3ff7..96b5131 100644 --- a/GlitchyEngine/src/Renderer/Material.bf +++ b/GlitchyEngine/src/Renderer/Material.bf @@ -124,9 +124,9 @@ namespace GlitchyEngine.Renderer public void SetVariable(String name, Vector4 value) => SetVariable(name, value); public void SetVariable(String name, int32 value) => SetVariable(name, value); - public void SetVariable(String name, Int32_2 value) => SetVariable(name, value); - public void SetVariable(String name, Int32_3 value) => SetVariable(name, value); - public void SetVariable(String name, Int32_4 value) => SetVariable(name, value); + public void SetVariable(String name, Int2 value) => SetVariable(name, value); + public void SetVariable(String name, Int3 value) => SetVariable(name, value); + public void SetVariable(String name, Int4 value) => SetVariable(name, value); public void SetVariable(String name, Color value) => SetVariable(name, value); public void SetVariable(String name, ColorRGB value) => SetVariable(name, value); diff --git a/GlitchyEngine/src/Renderer/Text/Font.bf b/GlitchyEngine/src/Renderer/Text/Font.bf index adc572a..a79c5f6 100644 --- a/GlitchyEngine/src/Renderer/Text/Font.bf +++ b/GlitchyEngine/src/Renderer/Text/Font.bf @@ -18,7 +18,7 @@ namespace GlitchyEngine.Renderer.Text public FT_UInt GlyphIndex; // TODO: Consider using floats - public Int32_3 MapCoord; + public Int3 MapCoord; public int32 Width, Height; public double TranslationX, TranslationY; @@ -45,10 +45,10 @@ namespace GlitchyEngine.Renderer.Text private int32 _faceIndex; private bool _hasColor; - private Int32_3 _penPos; + private Int3 _penPos; private int32 _lastRowHeight; internal Texture2D _atlas ~ _?.ReleaseRef(); - private Int32_3 _atlasSize; + private Int3 _atlasSize; private Dictionary _glyphs = new .() ~ DeleteDictionaryAndValues!(_); GlyphDescriptor _missingGlyph; @@ -215,12 +215,12 @@ namespace GlitchyEngine.Renderer.Text UpdateAtlas(); } - Int32_3 PrepareAtlas() + Int3 PrepareAtlas() { const uint32 maxRes = 16384; // D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION const uint32 maxArray = 2048; // D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION - ref Int32_3 pen = ref _penPos; + ref Int3 pen = ref _penPos; ref int32 rowHeight = ref _lastRowHeight; int32 atlasWidth = _atlasSize.X; @@ -298,7 +298,7 @@ namespace GlitchyEngine.Renderer.Text void DrawAtlas() { - Int32_3 oldAtlasSize = _atlasSize; + Int3 oldAtlasSize = _atlasSize; _atlasSize = PrepareAtlas(); if(_atlasSize != oldAtlasSize)