Skip to content

Commit 78594a0

Browse files
[Serialization] WIP;
1 parent 9060f8b commit 78594a0

File tree

12 files changed

+1111
-759
lines changed

12 files changed

+1111
-759
lines changed

Engine/Core/Math/Vector3Int.cs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System.Runtime.InteropServices;
2+
using System;
3+
using MessagePack;
4+
5+
namespace Staple;
6+
7+
/// <summary>
8+
/// 3D Vector that uses ints instead of floats
9+
/// </summary>
10+
[Serializable]
11+
[StructLayout(LayoutKind.Sequential, Pack = 0)]
12+
[MessagePackObject]
13+
public struct Vector3Int
14+
{
15+
[Key(0)]
16+
public int X;
17+
18+
[Key(1)]
19+
public int Y;
20+
21+
[Key(2)]
22+
public int Z;
23+
24+
public Vector3Int()
25+
{
26+
}
27+
28+
public Vector3Int(int X, int Y, int Z)
29+
{
30+
this.X = X;
31+
this.Y = Y;
32+
this.Z = Z;
33+
}
34+
35+
[IgnoreMember]
36+
public static readonly Vector3Int Zero = new();
37+
38+
[IgnoreMember]
39+
public static readonly Vector3Int One = new(1, 1, 1);
40+
41+
public static Vector3Int operator +(Vector3Int a, Vector3Int b) => new(a.X + b.X, a.Y + b.Y, a.Z + b.Z);
42+
43+
public static Vector3Int operator -(Vector3Int a, Vector3Int b) => new(a.X - b.X, a.Y - b.Y, a.Z - b.Z);
44+
45+
public static Vector3Int operator *(Vector3Int a, Vector3Int b) => new(a.X * b.X, a.Y * b.Y, a.Z * b.Z);
46+
47+
public static Vector3Int operator *(Vector3Int a, int b) => new(a.X * b, a.Y * b, a.Z * b);
48+
49+
public static Vector3Int operator *(Vector3Int a, float b) => new((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b));
50+
51+
public static Vector3Int operator /(Vector3Int a, Vector3Int b) => new(a.X / b.X, a.Y / b.Y, a.Z / b.Z);
52+
53+
public static Vector3Int operator /(Vector3Int a, int b) => new(a.X / b, a.Y / b, a.Z / b);
54+
55+
public static Vector3Int operator /(Vector3Int a, float b) => new((int)(a.X / b), (int)(a.Y / b), (int)(a.Z / b));
56+
57+
public static bool operator ==(Vector3Int a, Vector3Int b) => a.X == b.X && a.Y == b.Y && a.Z == b.Z;
58+
59+
public static bool operator !=(Vector3Int a, Vector3Int b) => a.X != b.X || a.Y != b.Y || a.Z != b.Z;
60+
61+
public override readonly int GetHashCode()
62+
{
63+
return HashCode.Combine(X, Y, Z);
64+
}
65+
66+
public override readonly bool Equals(object obj)
67+
{
68+
if (obj == null || obj is not Vector3Int v)
69+
{
70+
return false;
71+
}
72+
73+
return X == v.X && Y == v.Y && Z == v.Z;
74+
}
75+
76+
public override readonly string ToString()
77+
{
78+
return $"({X}, {Y}, {Z})";
79+
}
80+
}

Engine/Core/Math/Vector4Int.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Runtime.InteropServices;
2+
using System;
3+
using MessagePack;
4+
5+
namespace Staple;
6+
7+
/// <summary>
8+
/// 3D Vector that uses ints instead of floats
9+
/// </summary>
10+
[Serializable]
11+
[StructLayout(LayoutKind.Sequential, Pack = 0)]
12+
[MessagePackObject]
13+
public struct Vector4Int
14+
{
15+
[Key(0)]
16+
public int X;
17+
18+
[Key(1)]
19+
public int Y;
20+
21+
[Key(2)]
22+
public int Z;
23+
24+
[Key(3)]
25+
public int W;
26+
27+
public Vector4Int()
28+
{
29+
}
30+
31+
public Vector4Int(int X, int Y, int Z, int W)
32+
{
33+
this.X = X;
34+
this.Y = Y;
35+
this.Z = Z;
36+
this.W = W;
37+
}
38+
39+
[IgnoreMember]
40+
public static readonly Vector4Int Zero = new();
41+
42+
[IgnoreMember]
43+
public static readonly Vector4Int One = new(1, 1, 1, 1);
44+
45+
public static Vector4Int operator +(Vector4Int a, Vector4Int b) => new(a.X + b.X, a.Y + b.Y, a.Z + b.Z, a.W + b.W);
46+
47+
public static Vector4Int operator -(Vector4Int a, Vector4Int b) => new(a.X - b.X, a.Y - b.Y, a.Z - b.Z, a.W - b.W);
48+
49+
public static Vector4Int operator *(Vector4Int a, Vector4Int b) => new(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W);
50+
51+
public static Vector4Int operator *(Vector4Int a, int b) => new(a.X * b, a.Y * b, a.Z * b, a.W * b);
52+
53+
public static Vector4Int operator *(Vector4Int a, float b) => new((int)(a.X * b), (int)(a.Y * b), (int)(a.Z * b), (int)(a.W * b));
54+
55+
public static Vector4Int operator /(Vector4Int a, Vector4Int b) => new(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W);
56+
57+
public static Vector4Int operator /(Vector4Int a, int b) => new(a.X / b, a.Y / b, a.Z / b, a.W / b);
58+
59+
public static Vector4Int operator /(Vector4Int a, float b) => new((int)(a.X / b), (int)(a.Y / b), (int)(a.Z / b), (int)(a.W / b));
60+
61+
public static bool operator ==(Vector4Int a, Vector4Int b) => a.X == b.X && a.Y == b.Y && a.Z == b.Z && a.W == b.W;
62+
63+
public static bool operator !=(Vector4Int a, Vector4Int b) => a.X != b.X || a.Y != b.Y || a.Z != b.Z || a.W != b.W;
64+
65+
public override readonly int GetHashCode()
66+
{
67+
return HashCode.Combine(X, Y, Z, W);
68+
}
69+
70+
public override readonly bool Equals(object obj)
71+
{
72+
if (obj == null || obj is not Vector4Int v)
73+
{
74+
return false;
75+
}
76+
77+
return X == v.X && Y == v.Y && Z == v.Z && W == v.W;
78+
}
79+
80+
public override readonly string ToString()
81+
{
82+
return $"({X}, {Y}, {Z}, {W})";
83+
}
84+
}

0 commit comments

Comments
 (0)