From fa825551490ca037edaad47d9063f296dd926206 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:39:08 +0200 Subject: [PATCH 01/46] Add IntX support for JsonWriter. --- Source/Engine/Serialization/JsonWriter.h | 39 ++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Source/Engine/Serialization/JsonWriter.h b/Source/Engine/Serialization/JsonWriter.h index 7182ec69a..df6cb7d2d 100644 --- a/Source/Engine/Serialization/JsonWriter.h +++ b/Source/Engine/Serialization/JsonWriter.h @@ -11,6 +11,9 @@ #include "Engine/Core/Math/Vector2.h" #include "Engine/Core/Math/Vector3.h" #include "Engine/Core/Math/Vector4.h" +#include "Engine/Core/Math/Int2.h" +#include "Engine/Core/Math/Int3.h" +#include "Engine/Core/Math/Int4.h" #include "Engine/Core/Math/Color.h" #include "Engine/Core/Math/Quaternion.h" #include "Engine/Core/Math/Ray.h" @@ -149,6 +152,42 @@ public: EndObject(); } + void Int2(const Int2& value) + { + StartObject(); + JKEY("X"); + Int(value.X); + JKEY("Y"); + Int(value.Y); + EndObject(); + } + + void Int3(const Int3& value) + { + StartObject(); + JKEY("X"); + Int(value.X); + JKEY("Y"); + Int(value.Y); + JKEY("Z"); + Int(value.Z); + EndObject(); + } + + void Int4(const Int4& value) + { + StartObject(); + JKEY("X"); + Int(value.X); + JKEY("Y"); + Int(value.Y); + JKEY("Z"); + Int(value.Z); + JKEY("W"); + Int(value.W); + EndObject(); + } + void Color(const Color& value) { StartObject(); From ca0135724c8091175f1fafc5b02b7bf6594feea8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:41:11 +0200 Subject: [PATCH 02/46] Add Vector4 constructors for IntX. --- Source/Engine/Core/Math/Vector4.cpp | 28 +++++++++++++++++++++++----- Source/Engine/Core/Math/Vector4.h | 14 ++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Source/Engine/Core/Math/Vector4.cpp b/Source/Engine/Core/Math/Vector4.cpp index 34fa27aac..5da725c20 100644 --- a/Source/Engine/Core/Math/Vector4.cpp +++ b/Source/Engine/Core/Math/Vector4.cpp @@ -3,10 +3,12 @@ #include "Vector4.h" #include "Vector2.h" #include "Vector3.h" +#include "Int2.h" +#include "Int3.h" +#include "Int4.h" #include "Color.h" #include "Matrix.h" #include "Rectangle.h" -#include "Int4.h" #include "../Types/String.h" static_assert(sizeof(Vector4) == 16, "Invalid Vector4 type size."); @@ -49,11 +51,27 @@ Vector4::Vector4(const Vector3& xyz, float w) { } +Vector4::Vector4(const Int2& xy, float z, float w) + : X(static_cast(xy.X)) + , Y(static_cast(xy.Y)) + , Z(z) + , W(w) +{ +} + +Vector4::Vector4(const Int3& xyz, float w) + : X(static_cast(xyz.X)) + , Y(static_cast(xyz.Y)) + , Z(static_cast(xyz.Z)) + , W(w) +{ +} + Vector4::Vector4(const Int4& xyzw) - : X((float)xyzw.X) - , Y((float)xyzw.Y) - , Z((float)xyzw.X) - , W((float)xyzw.Y) + : X(static_cast(xyzw.X)) + , Y(static_cast(xyzw.Y)) + , Z(static_cast(xyzw.X)) + , W(static_cast(xyzw.Y)) { } diff --git a/Source/Engine/Core/Math/Vector4.h b/Source/Engine/Core/Math/Vector4.h index c7771aa67..fe25a80bd 100644 --- a/Source/Engine/Core/Math/Vector4.h +++ b/Source/Engine/Core/Math/Vector4.h @@ -13,6 +13,9 @@ struct Color; struct Matrix; struct Rectangle; class String; +struct Int2; +struct Int3; +struct Int4; /// /// Represents a four dimensional mathematical vector. @@ -133,6 +136,17 @@ public: // @param w W component value Vector4(const Vector3& xyz, float w); + // Init + // @param xy X and Y values in the vector + // @param z Z component value + // @param w W component value + explicit Vector4(const Int2& xy, float z, float w); + + // Init + // @param xyz X, Y and Z values in the vector + // @param w W component value + explicit Vector4(const Int3& xyz, float w); + // Init // @param color Int4 value explicit Vector4(const Int4& xyzw); From a746e0c99563023b2e45ff925cae38c8a2b9fc0d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:41:38 +0200 Subject: [PATCH 03/46] Add Vector3 constructor for IntX. --- Source/Engine/Core/Math/Vector3.cpp | 22 +++++++++++++++++++--- Source/Engine/Core/Math/Vector3.h | 11 +++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Math/Vector3.cpp b/Source/Engine/Core/Math/Vector3.cpp index f66bbcbbd..9c8783dad 100644 --- a/Source/Engine/Core/Math/Vector3.cpp +++ b/Source/Engine/Core/Math/Vector3.cpp @@ -6,7 +6,9 @@ #include "Color.h" #include "Quaternion.h" #include "Matrix.h" +#include "Int2.h" #include "Int3.h" +#include "Int4.h" #include "../Types/String.h" static_assert(sizeof(Vector3) == 12, "Invalid Vector3 type size."); @@ -40,10 +42,24 @@ Vector3::Vector3(const Vector2& xy) { } +Vector3::Vector3(const Int2& xy, float z) + : X(static_cast(xy.X)) + , Y(static_cast(xy.Y)) + , Z(static_cast(z)) +{ +} + Vector3::Vector3(const Int3& xyz) - : X((float)xyz.X) - , Y((float)xyz.Y) - , Z((float)xyz.Z) + : X(static_cast(xyz.X)) + , Y(static_cast(xyz.Y)) + , Z(static_cast(xyz.Z)) +{ +} + +Vector3::Vector3(const Int4& xyzw) + : X(static_cast(xyzw.X)) + , Y(static_cast(xyzw.Y)) + , Z(static_cast(xyzw.Z)) { } diff --git a/Source/Engine/Core/Math/Vector3.h b/Source/Engine/Core/Math/Vector3.h index 1f4792e31..d9a1d6036 100644 --- a/Source/Engine/Core/Math/Vector3.h +++ b/Source/Engine/Core/Math/Vector3.h @@ -12,6 +12,8 @@ struct Vector2; struct Vector4; struct Color; class String; +struct Int3; +struct Int4; /// /// Represents a three dimensional mathematical vector. @@ -138,10 +140,19 @@ public: // @param xy Vector3 value explicit Vector3(const Vector2& xy); + // Init + // @param xy Int22 with X and Y components values + // @param z Z component value + explicit Vector3(const Int2& xy, float z); + // Init // @param xyz Int3 value explicit Vector3(const Int3& xyz); + // Init + // @param xyzw Int4 value + explicit Vector3(const Int4& xyzw); + // Init // @param xyz Vector4 value explicit Vector3(const Vector4& xyz); From 42075f7b2a8bc78f7143d52ef47c112f719d3203 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:42:04 +0200 Subject: [PATCH 04/46] Add Vector2 constructors for IntX. --- Source/Engine/Core/Math/Vector2.cpp | 32 +++++++++++++++++++++-------- Source/Engine/Core/Math/Vector2.h | 21 ++++++++++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/Source/Engine/Core/Math/Vector2.cpp b/Source/Engine/Core/Math/Vector2.cpp index c23e79d19..2c6979575 100644 --- a/Source/Engine/Core/Math/Vector2.cpp +++ b/Source/Engine/Core/Math/Vector2.cpp @@ -5,6 +5,8 @@ #include "Vector4.h" #include "Color.h" #include "Int2.h" +#include "Int3.h" +#include "Int4.h" #include "../Types/String.h" static_assert(sizeof(Vector2) == 8, "Invalid Vector2 type size."); @@ -16,21 +18,33 @@ const Vector2 Vector2::UnitY(0, 1); const Vector2 Vector2::Minimum(MIN_float); const Vector2 Vector2::Maximum(MAX_float); -Vector2::Vector2(const Int2& v) - : X((float)v.X) - , Y((float)v.Y) +Vector2::Vector2(const Int2& xy) + : X(static_cast(xy.X)) + , Y(static_cast(xy.Y)) { } -Vector2::Vector2(const Vector3& v) - : X(v.X) - , Y(v.Y) +Vector2::Vector2(const Int3& xyz) + : X(static_cast(xyz.X)) + , Y(static_cast(xyz.Y)) { } -Vector2::Vector2(const Vector4& v) - : X(v.X) - , Y(v.Y) +Vector2::Vector2(const Int4& xyzw) + : X(static_cast(xyzw.X)) + , Y(static_cast(xyzw.Y)) +{ +} + +Vector2::Vector2(const Vector3& xyz) + : X(xyz.X) + , Y(xyz.Y) +{ +} + +Vector2::Vector2(const Vector4& xyzw) + : X(xyzw.X) + , Y(xyzw.Y) { } diff --git a/Source/Engine/Core/Math/Vector2.h b/Source/Engine/Core/Math/Vector2.h index 7a1b1519b..aaea1d73c 100644 --- a/Source/Engine/Core/Math/Vector2.h +++ b/Source/Engine/Core/Math/Vector2.h @@ -8,6 +8,9 @@ struct Vector3; struct Vector4; +struct Int2; +struct Int3; +struct Int4; struct Color; struct Matrix; @@ -85,16 +88,24 @@ public: } // Init - // @param v Vector to use X and Y components - explicit Vector2(const Int2& v); + // @param v Int2 to use X and Y components + explicit Vector2(const Int2& xy); // Init - // @param v Vector to use X and Y components - explicit Vector2(const Vector3& v); + // @param v Int3 to use X and Y components + explicit Vector2(const Int3& xyz); + + // Init + // @param v Int4 to use X and Y components + explicit Vector2(const Int4& xyzw); + + // Init + // @param v Vector3 to use X and Y components + explicit Vector2(const Vector3& xyz); // Init // @param v Vector4 to use X and Y components - explicit Vector2(const Vector4& v); + explicit Vector2(const Vector4& xyzw); // Init // @param color Color value From 3185691077c73510b8834975cf8cb08353fbde9f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:42:40 +0200 Subject: [PATCH 05/46] Add IntX to VariantType. --- Source/Engine/Core/Types/Variant.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Engine/Core/Types/Variant.h b/Source/Engine/Core/Types/Variant.h index 98fd9cf24..9b6ff590f 100644 --- a/Source/Engine/Core/Types/Variant.h +++ b/Source/Engine/Core/Types/Variant.h @@ -54,6 +54,10 @@ API_STRUCT(InBuild) struct FLAXENGINE_API VariantType ManagedObject, Typename, + Int2, + Int3, + Int4, + MAX }; From 1e4c07f94c2cc4bcc9553e70554b94fa82eaab18 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:43:39 +0200 Subject: [PATCH 06/46] Add Variant constructors for IntX. --- Source/Engine/Core/Types/Variant.cpp | 21 +++++++++++++++++++++ Source/Engine/Core/Types/Variant.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index db71c2f77..d12c59c91 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -11,6 +11,9 @@ #include "Engine/Core/Math/Vector2.h" #include "Engine/Core/Math/Vector3.h" #include "Engine/Core/Math/Vector4.h" +#include "Engine/Core/Math/Int2.h" +#include "Engine/Core/Math/Int3.h" +#include "Engine/Core/Math/Int4.h" #include "Engine/Core/Math/Quaternion.h" #include "Engine/Core/Math/Color.h" #include "Engine/Core/Math/Matrix.h" @@ -551,6 +554,24 @@ Variant::Variant(const Vector4& v) *(Vector4*)AsData = v; } +Variant::Variant(const Int2& v) + : Type(VariantType::Int2) +{ + *(Int2*)AsData = v; +} + +Variant::Variant(const Int3& v) + : Type(VariantType::Int3) +{ + *(Int3*)AsData = v; +} + +Variant::Variant(const Int4& v) + : Type(VariantType::Int4) +{ + *(Int4*)AsData = v; +} + Variant::Variant(const Color& v) : Type(VariantType::Color) { diff --git a/Source/Engine/Core/Types/Variant.h b/Source/Engine/Core/Types/Variant.h index 9b6ff590f..ff59c7960 100644 --- a/Source/Engine/Core/Types/Variant.h +++ b/Source/Engine/Core/Types/Variant.h @@ -202,6 +202,9 @@ public: Variant(const Vector2& v); Variant(const Vector3& v); Variant(const Vector4& v); + Variant(const Int2& v); + Variant(const Int3& v); + Variant(const Int4& v); Variant(const Color& v); Variant(const Quaternion& v); Variant(const BoundingSphere& v); From 0f6e204c76fd16efee5e88af4e066487497dd8d8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:44:26 +0200 Subject: [PATCH 07/46] Add Variant operator support for IntX. --- Source/Engine/Core/Types/Variant.cpp | 126 +++++++++++++++++++++++++++ Source/Engine/Core/Types/Variant.h | 3 + 2 files changed, 129 insertions(+) diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index d12c59c91..060d3452f 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -1525,6 +1525,132 @@ Variant::operator Vector4() const } } +Variant::operator Int2() const +{ + switch (Type.Type) + { + case VariantType::Bool: + return Int2((int32)(AsBool ? 1.0f : 0.0f)); + case VariantType::Int: + return Int2((int32)AsInt); + case VariantType::Uint: + return Int2((int32)AsUint); + case VariantType::Int64: + return Int2((int32)AsInt64); + case VariantType::Uint64: + case VariantType::Enum: + return Int2((int32)AsUint64); + case VariantType::Float: + return Int2((int32)AsFloat); + case VariantType::Double: + return Int2((int32)AsDouble); + case VariantType::Pointer: + return Int2((int32)(intptr)AsPointer); + case VariantType::Vector2: + return Int2(*(Vector2*)AsData); + case VariantType::Vector3: + return Int2(*(Vector3*)AsData); + case VariantType::Vector4: + return Int2(*(Vector4*)AsData); + case VariantType::Int2: + return Int2(*(Int2*)AsData); + case VariantType::Int3: + return Int2(*(Int3*)AsData); + case VariantType::Int4: + case VariantType::Color: + return Int2(*(Int4*)AsData); + case VariantType::Structure: + if (StringUtils::Compare(Type.TypeName, Int2::TypeInitializer.GetType().Fullname.Get()) == 0) + return *(Int2*)AsBlob.Data; + default: + return Int3::Zero; + } +} + +Variant::operator Int3() const +{ + switch (Type.Type) + { + case VariantType::Bool: + return Int3((int32)(AsBool ? 1.0f : 0.0f)); + case VariantType::Int: + return Int3((int32)AsInt); + case VariantType::Uint: + return Int3((int32)AsUint); + case VariantType::Int64: + return Int3((int32)AsInt64); + case VariantType::Uint64: + case VariantType::Enum: + return Int3((int32)AsUint64); + case VariantType::Float: + return Int3((int32)AsFloat); + case VariantType::Double: + return Int3((int32)AsDouble); + case VariantType::Pointer: + return Int3((int32)(intptr)AsPointer); + case VariantType::Vector2: + return Int3(*(Vector2*)AsData, 0.0f); + case VariantType::Vector3: + return Int3(*(Vector3*)AsData); + case VariantType::Vector4: + return Int3(*(Vector4*)AsData); + case VariantType::Int2: + return Int3(*(Int2*)AsData, 0.0f); + case VariantType::Int3: + return Int3(*(Int3*)AsData); + case VariantType::Int4: + case VariantType::Color: + return Int3(*(Int4*)AsData); + case VariantType::Structure: + if (StringUtils::Compare(Type.TypeName, Int3::TypeInitializer.GetType().Fullname.Get()) == 0) + return *(Int3*)AsBlob.Data; + default: + return Int3::Zero; + } +} + +Variant::operator Int4() const +{ + switch (Type.Type) + { + case VariantType::Bool: + return Int4((int32)(AsBool ? 1.0f : 0.0f)); + case VariantType::Int: + return Int4((int32)AsInt); + case VariantType::Uint: + return Int4((int32)AsUint); + case VariantType::Int64: + return Int4((int32)AsInt64); + case VariantType::Uint64: + case VariantType::Enum: + return Int4((int32)AsUint64); + case VariantType::Float: + return Int4((int32)AsFloat); + case VariantType::Double: + return Int4((int32)AsDouble); + case VariantType::Pointer: + return Int4((int32)(intptr)AsPointer); + case VariantType::Vector2: + return Int4(*(Vector2*)AsData, 0.0f, 0.0f); + case VariantType::Vector3: + return Int4(*(Vector3*)AsData, 0.0f); + case VariantType::Vector4: + return Int4(*(Vector4*)AsData); + case VariantType::Int2: + return Int4(*(Int2*)AsData, 0.0f, 0.0f); + case VariantType::Int3: + return Int4(*(Int3*)AsData, 0.0f); + case VariantType::Int4: + case VariantType::Color: + return *(Int4*)AsData; + case VariantType::Structure: + if (StringUtils::Compare(Type.TypeName, Int4::TypeInitializer.GetType().Fullname.Get()) == 0) + return *(Int4*)AsBlob.Data; + default: + return Int4::Zero; + } +} + Variant::operator Color() const { switch (Type.Type) diff --git a/Source/Engine/Core/Types/Variant.h b/Source/Engine/Core/Types/Variant.h index ff59c7960..165ad0972 100644 --- a/Source/Engine/Core/Types/Variant.h +++ b/Source/Engine/Core/Types/Variant.h @@ -269,6 +269,9 @@ public: explicit operator Vector2() const; explicit operator Vector3() const; explicit operator Vector4() const; + explicit operator Int2() const; + explicit operator Int3() const; + explicit operator Int4() const; explicit operator Color() const; explicit operator Quaternion() const; explicit operator Guid() const; From 854b2492dd1606801cc82762c28d537ab2b36bc0 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:45:02 +0200 Subject: [PATCH 08/46] Add Variant "As" support for IntX. --- Source/Engine/Core/Types/Variant.cpp | 15 +++++++++++++++ Source/Engine/Core/Types/Variant.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/Source/Engine/Core/Types/Variant.cpp b/Source/Engine/Core/Types/Variant.cpp index 060d3452f..85240c8bf 100644 --- a/Source/Engine/Core/Types/Variant.cpp +++ b/Source/Engine/Core/Types/Variant.cpp @@ -1817,6 +1817,21 @@ const Vector4& Variant::AsVector4() const return *(const Vector4*)AsData; } +const Int2& Variant::AsInt2() const +{ + return *(const Int2*)AsData; +} + +const Int3& Variant::AsInt3() const +{ + return *(const Int3*)AsData; +} + +const Int4& Variant::AsInt4() const +{ + return *(const Int4*)AsData; +} + const Color& Variant::AsColor() const { return *(const Color*)AsData; diff --git a/Source/Engine/Core/Types/Variant.h b/Source/Engine/Core/Types/Variant.h index 165ad0972..ac9af0e79 100644 --- a/Source/Engine/Core/Types/Variant.h +++ b/Source/Engine/Core/Types/Variant.h @@ -285,6 +285,9 @@ public: const Vector2& AsVector2() const; const Vector3& AsVector3() const; const Vector4& AsVector4() const; + const Int2& AsInt2() const; + const Int3& AsInt3() const; + const Int4& AsInt4() const; const Color& AsColor() const; const Quaternion& AsQuaternion() const; From 8661c2af18830eec37988e4d0b4c09438f227486 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:46:28 +0200 Subject: [PATCH 09/46] Convert Int4 to generated type. --- Source/Engine/Core/Math/Int4.cs | 23 +---------------------- Source/Engine/Core/Math/Int4.h | 27 ++++++++++++++++++--------- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/Source/Engine/Core/Math/Int4.cs b/Source/Engine/Core/Math/Int4.cs index 0617f7b71..5328dcc73 100644 --- a/Source/Engine/Core/Math/Int4.cs +++ b/Source/Engine/Core/Math/Int4.cs @@ -12,9 +12,8 @@ namespace FlaxEngine /// Represents a four dimensional mathematical vector (signed integers). /// [Serializable] - [StructLayout(LayoutKind.Sequential, Pack = 4)] [TypeConverter(typeof(TypeConverters.Int4Converter))] - public struct Int4 : IEquatable, IFormattable + partial struct Int4 : IEquatable, IFormattable { private static readonly string _formatString = "X:{0} Y:{1} Z:{2} W:{3}"; @@ -63,26 +62,6 @@ namespace FlaxEngine /// public static readonly Int4 Maximum = new Int4(int.MaxValue); - /// - /// The X component of the vector. - /// - public int X; - - /// - /// The Y component of the vector. - /// - public int Y; - - /// - /// The Z component of the vector. - /// - public int Z; - - /// - /// The W component of the vector. - /// - public int W; - /// /// Initializes a new instance of the struct. /// diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index c8e9eebd8..05b951e62 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -13,25 +13,34 @@ struct Vector4; /// /// Four-components vector (32 bit integer type). /// -API_STRUCT(InBuild) struct FLAXENGINE_API Int4 +API_STRUCT() struct FLAXENGINE_API Int4 { +DECLARE_SCRIPTING_TYPE_MINIMAL(Int4); public: union { struct { - // X component - int32 X; + /// + /// The X component. + /// + API_FIELD() int32 X; - // Y component - int32 Y; + /// + /// The Y component. + /// + API_FIELD() int32 Y; - // Z component - int32 Z; + /// + /// The Z component. + /// + API_FIELD() int32 Z; - // W component - int32 W; + /// + /// The W component. + /// + API_FIELD() int32 W; }; // Raw values From 224937cd097165bb79fee06fb27a59aafee2bf99 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:46:56 +0200 Subject: [PATCH 10/46] Convert Int3 to generated type. --- Source/Engine/Core/Math/Int3.cs | 18 +----------------- Source/Engine/Core/Math/Int3.h | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/Source/Engine/Core/Math/Int3.cs b/Source/Engine/Core/Math/Int3.cs index 93193881a..e0c67bd33 100644 --- a/Source/Engine/Core/Math/Int3.cs +++ b/Source/Engine/Core/Math/Int3.cs @@ -12,9 +12,8 @@ namespace FlaxEngine /// Represents a three dimensional mathematical vector (signed integers). /// [Serializable] - [StructLayout(LayoutKind.Sequential, Pack = 4)] [TypeConverter(typeof(TypeConverters.Int3Converter))] - public struct Int3 : IEquatable, IFormattable + partial struct Int3 : IEquatable, IFormattable { private static readonly string _formatString = "X:{0} Y:{1} Z:{2}"; @@ -58,21 +57,6 @@ namespace FlaxEngine /// public static readonly Int3 Maximum = new Int3(int.MaxValue); - /// - /// The X component of the vector. - /// - public int X; - - /// - /// The Y component of the vector. - /// - public int Y; - - /// - /// The Z component of the vector. - /// - public int Z; - /// /// Initializes a new instance of the struct. /// diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index 6886acc6b..d639ea103 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -13,22 +13,29 @@ struct Vector4; /// /// Three-components vector (32 bit integer type). /// -API_STRUCT(InBuild) struct FLAXENGINE_API Int3 +API_STRUCT() struct FLAXENGINE_API Int3 { +DECLARE_SCRIPTING_TYPE_MINIMAL(Int3); public: union { struct { - // X component - int32 X; + /// + /// The X component. + /// + API_FIELD() int32 X; - // Y component - int32 Y; + /// + /// The Y component. + /// + API_FIELD() int32 Y; - // Y component - int32 Z; + /// + /// The Z component. + /// + API_FIELD() int32 Z; }; // Raw values From d2cc4051ad15c85b18c5c82133edf28fa0ee0d27 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:47:14 +0200 Subject: [PATCH 11/46] Convert Int2 to generated type. --- Source/Engine/Core/Math/Int2.cs | 13 +------------ Source/Engine/Core/Math/Int2.h | 15 ++++++++++----- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/Source/Engine/Core/Math/Int2.cs b/Source/Engine/Core/Math/Int2.cs index 0bf38e95f..a063e1bbf 100644 --- a/Source/Engine/Core/Math/Int2.cs +++ b/Source/Engine/Core/Math/Int2.cs @@ -12,9 +12,8 @@ namespace FlaxEngine /// Represents a two dimensional mathematical vector (signed integers). /// [Serializable] - [StructLayout(LayoutKind.Sequential, Pack = 4)] [TypeConverter(typeof(TypeConverters.Int2Converter))] - public struct Int2 : IEquatable, IFormattable + partial struct Int2 : IEquatable, IFormattable { private static readonly string _formatString = "X:{0} Y:{1}"; @@ -53,16 +52,6 @@ namespace FlaxEngine /// public static readonly Int2 Maximum = new Int2(int.MaxValue); - /// - /// The X component of the vector. - /// - public int X; - - /// - /// The Y component of the vector. - /// - public int Y; - /// /// Initializes a new instance of the struct. /// diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index a6038d1b0..c7bcae257 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -13,19 +13,24 @@ struct Vector4; /// /// Two-components vector (32 bit integer type). /// -API_STRUCT(InBuild) struct FLAXENGINE_API Int2 +API_STRUCT() struct FLAXENGINE_API Int2 { +DECLARE_SCRIPTING_TYPE_MINIMAL(Int2); public: union { struct { - // X component - int32 X; + /// + /// The X component. + /// + API_FIELD() int32 X; - // Y component - int32 Y; + /// + /// The Y component. + /// + API_FIELD() int32 Y; }; // Raw values From 0bb1982bcdb64f894e14db7a44b2485bd7945e04 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:49:18 +0200 Subject: [PATCH 12/46] Delete VectorInt.h. --- Source/Engine/Core/Math/VectorInt.h | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 Source/Engine/Core/Math/VectorInt.h diff --git a/Source/Engine/Core/Math/VectorInt.h b/Source/Engine/Core/Math/VectorInt.h deleted file mode 100644 index d9611d615..000000000 --- a/Source/Engine/Core/Math/VectorInt.h +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. - -#pragma once - -#include "Int2.h" -#include "Int3.h" -#include "Int4.h" From f470a9aaf4dbc8b8af21692855fcb7bd988d39d8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:50:04 +0200 Subject: [PATCH 13/46] Delete unused pre-decl. --- Source/Engine/Core/Math/Int4.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index 05b951e62..82b9facd4 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -6,10 +6,6 @@ #include "Engine/Core/Formatting.h" #include "Engine/Core/Templates.h" -struct Vector2; -struct Vector3; -struct Vector4; - /// /// Four-components vector (32 bit integer type). /// From a04d19d9f7d90b05724805d537257d4926958172 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:50:09 +0200 Subject: [PATCH 14/46] Delete unused pre-decl. --- Source/Engine/Core/Math/Int3.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index d639ea103..302b0c34b 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -6,9 +6,6 @@ #include "Engine/Core/Formatting.h" #include "Engine/Core/Templates.h" -struct Vector2; -struct Vector3; -struct Vector4; /// /// Three-components vector (32 bit integer type). From 6c4ca6c01a6d0090c7b66c5a65eee24654090069 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:50:16 +0200 Subject: [PATCH 15/46] Delete unused pre-decl. --- Source/Engine/Core/Math/Int2.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index c7bcae257..d2ec16623 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -6,10 +6,6 @@ #include "Engine/Core/Formatting.h" #include "Engine/Core/Templates.h" -struct Vector2; -struct Vector3; -struct Vector4; - /// /// Two-components vector (32 bit integer type). /// From 866105631e128add73c042e3273259762fb12926 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:50:59 +0200 Subject: [PATCH 16/46] Add Int4.cpp. --- .../Core/Math/{VectorInt.cpp => Int4.cpp} | 67 +++++++++++-------- 1 file changed, 38 insertions(+), 29 deletions(-) rename Source/Engine/Core/Math/{VectorInt.cpp => Int4.cpp} (56%) diff --git a/Source/Engine/Core/Math/VectorInt.cpp b/Source/Engine/Core/Math/Int4.cpp similarity index 56% rename from Source/Engine/Core/Math/VectorInt.cpp rename to Source/Engine/Core/Math/Int4.cpp index 300343da5..a8f6be236 100644 --- a/Source/Engine/Core/Math/VectorInt.cpp +++ b/Source/Engine/Core/Math/Int4.cpp @@ -1,42 +1,51 @@ // Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. -#include "VectorInt.h" +#include "Int2.h" +#include "Int3.h" +#include "Int4.h" #include "Vector2.h" #include "Vector3.h" #include "Vector4.h" #include "Engine/Core/Types/String.h" -const Int2 Int2::Zero(0); -const Int2 Int2::One(1); - -Int2::Int2(const Vector2& v) - : X(static_cast(v.X)) - , Y(static_cast(v.Y)) -{ -} - -String Int2::ToString() const -{ - return String::Format(TEXT("{}"), *this); -} - -const Int3 Int3::Zero(0); -const Int3 Int3::One(1); - -Int3::Int3(const Vector3& v) - : X(static_cast(v.X)) - , Y(static_cast(v.Y)) - , Z(static_cast(v.Z)) -{ -} - -String Int3::ToString() const -{ - return String::Format(TEXT("{}"), *this); -} +static_assert(sizeof(Int4) == 16, "Invalid Int4 type size."); const Int4 Int4::Zero(0); const Int4 Int4::One(1); +const Int4 Int4::Minimum(MIN_int32); +const Int4 Int4::Maximum(MAX_int32); + +Int4::Int4(const Int2& xy, int32 z, int32 w) + : X(xy.X) + , Y(xy.Y) + , Z(z) + , W(w) +{ +} + +Int4::Int4(const Int3& xyz, int32 w) + : X(xyz.X) + , Y(xyz.Y) + , Z(xyz.Z) + , W(w) +{ +} + +Int4::Int4(const Vector2& v, int32 z, int32 w) + : X(static_cast(v.X)) + , Y(static_cast(v.Y)) + , Z(z) + , W(w) +{ +} + +Int4::Int4(const Vector3& v, int32 w) + : X(static_cast(v.X)) + , Y(static_cast(v.Y)) + , Z(static_cast(v.Z)) + , W(w) +{ +} Int4::Int4(const Vector4& v) : X(static_cast(v.X)) From 048612c65cac8c10f6d6dad656155a10d2c5864a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:51:09 +0200 Subject: [PATCH 17/46] Add Int3.cpp. --- Source/Engine/Core/Math/Int3.cpp | 56 ++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Source/Engine/Core/Math/Int3.cpp diff --git a/Source/Engine/Core/Math/Int3.cpp b/Source/Engine/Core/Math/Int3.cpp new file mode 100644 index 000000000..327437d70 --- /dev/null +++ b/Source/Engine/Core/Math/Int3.cpp @@ -0,0 +1,56 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#include "Int2.h" +#include "Int3.h" +#include "Int4.h" +#include "Vector2.h" +#include "Vector3.h" +#include "Vector4.h" +#include "Engine/Core/Types/String.h" + +static_assert(sizeof(Int3) == 12, "Invalid Int3 type size."); + +const Int3 Int3::Zero(0); +const Int3 Int3::One(1); +const Int3 Int3::Minimum(MIN_int32); +const Int3 Int3::Maximum(MAX_int32); + +Int3::Int3(const Int2& xy, int32 z) + : X(xy.X) + , Y(xy.Y) + , Z(z) +{ +} + +Int3::Int3(const Int4& xyzw) + : X(xyzw.X) + , Y(xyzw.Y) + , Z(xyzw.Z) +{ +} + +Int3::Int3(const Vector2& xy, int32 z) + : X(static_cast(xy.X)) + , Y(static_cast(xy.Y)) + , Z(z) +{ +} + +Int3::Int3(const Vector3& xyz) + : X(static_cast(xyz.X)) + , Y(static_cast(xyz.Y)) + , Z(static_cast(xyz.Z)) +{ +} + +Int3::Int3(const Vector4& xyzw) + : X(static_cast(xyzw.X)) + , Y(static_cast(xyzw.Y)) + , Z(static_cast(xyzw.Z)) +{ +} + +String Int3::ToString() const +{ + return String::Format(TEXT("{}"), *this); +} From efbc7976b0bba192b7bcd50ec1359b1549b6d772 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:51:17 +0200 Subject: [PATCH 18/46] Add Int3.cpp. --- Source/Engine/Core/Math/Int2.cpp | 51 ++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Source/Engine/Core/Math/Int2.cpp diff --git a/Source/Engine/Core/Math/Int2.cpp b/Source/Engine/Core/Math/Int2.cpp new file mode 100644 index 000000000..1293d23ac --- /dev/null +++ b/Source/Engine/Core/Math/Int2.cpp @@ -0,0 +1,51 @@ +// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. + +#include "Int2.h" +#include "Int3.h" +#include "Int4.h" +#include "Vector2.h" +#include "Vector3.h" +#include "Vector4.h" +#include "Engine/Core/Types/String.h" + +static_assert(sizeof(Int2) == 8, "Invalid Int2 type size."); + +const Int2 Int2::Zero(0); +const Int2 Int2::One(1); +const Int2 Int2::Minimum(MIN_int32); +const Int2 Int2::Maximum(MAX_int32); + +Int2::Int2(const Int3& xyz) + : X(xyz.X) + , Y(xyz.Y) +{ +} + +Int2::Int2(const Int4& xyzw) + : X(xyzw.X) + , Y(xyzw.Y) +{ +} + +Int2::Int2(const Vector2& xy) + : X(static_cast(xy.X)) + , Y(static_cast(xy.Y)) +{ +} + +Int2::Int2(const Vector3& xyz) + : X(static_cast(xyz.X)) + , Y(static_cast(xyz.Y)) +{ +} + +Int2::Int2(const Vector4& xyzw) + : X(static_cast(xyzw.X)) + , Y(static_cast(xyzw.Y)) +{ +} + +String Int2::ToString() const +{ + return String::Format(TEXT("{}"), *this); +} From 529beaad08889ccec1ef7a2f801463c991925558 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:51:46 +0200 Subject: [PATCH 19/46] Add Int2 Min/Max support. --- Source/Engine/Core/Math/Int2.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index d2ec16623..c13f3d84c 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -41,6 +41,12 @@ public: // Vector with all components equal 1 static const Int2 One; + // A minimum Int2 + static const Int2 Minimum; + + // A maximum Int2 + static const Int2 Maximum; + public: /// From f8bc124752c37b561a13daec3c567b7e3a2d4e8f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:51:54 +0200 Subject: [PATCH 20/46] Add Int3 Min/Max support. --- Source/Engine/Core/Math/Int3.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index 302b0c34b..308f5fa13 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -47,6 +47,12 @@ public: // Vector with all components equal 1 static const Int3 One; + // A minimum Int3 + static const Int3 Minimum; + + // A maximum Int3 + static const Int3 Maximum; + public: /// From 563ec32f06554992087873a3ce8d4130d1f4e4a3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:52:01 +0200 Subject: [PATCH 21/46] Add Int4 Min/Max support. --- Source/Engine/Core/Math/Int4.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index 82b9facd4..4303e539c 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -51,6 +51,12 @@ public: // Vector with all components equal 1 static const Int4 One; + // A minimum Int4 + static const Int4 Minimum; + + // A maximum Int4 + static const Int4 Maximum; + public: /// From 053d55bf813ab645cb5ab0d38baf74ba90deb6e4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:52:21 +0200 Subject: [PATCH 22/46] Add Int4 constructors. --- Source/Engine/Core/Math/Int4.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index 4303e539c..396fa6e39 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -89,9 +89,31 @@ public: { } + // Init + // @param v Int2 to use X and Y components + // @param z Z component value + // @param w W component value + Int4(const Int2& xy, int32 z, int32 w); + + // Init + // @param v Int3 to use X , Y and Z components + // @param w W component value + Int4(const Int3& xyz, int32 w); + + // Init + // @param v Vector2 to use X and Y components + // @param z Z component value + // @param w W component value + explicit Int4(const Vector2& xy, int32 z, int32 w); + + // Init + // @param v Vector3 to use X , Y and Z components + // @param w W component value + explicit Int4(const Vector3& xyz, int32 w); + // Init // @param v Vector to use X, Y, Z and W components - explicit Int4(const Vector4& v); + explicit Int4(const Vector4& xyzw); public: From 21f1930c2d02c5df53d495466fc98cca0a3178ad Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:52:34 +0200 Subject: [PATCH 23/46] Add Int3 constructors. --- Source/Engine/Core/Math/Int3.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index 308f5fa13..b5f8e0bf3 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -83,9 +83,27 @@ public: } // Init - // @param v Vector to use X, Y and Z components - explicit Int3(const Vector3& v); + // @param v Int2 to use X and Y components + // @param z Z component value + Int3(const Int2& xy, int32 z); + // Init + // @param v Int4 to use X and Y components + Int3(const Int4& xyzw); + + // Init + // @param v Vector2 to use X and Y components + // @param z Z component value + explicit Int3(const Vector2& xy, int32 z); + + // Init + // @param v Vector3 to use X, Y and Z components + explicit Int3(const Vector3& xyz); + + // Init + // @param v Vector4 to use X and Y components + explicit Int3(const Vector4& xyzw); + public: String ToString() const; From 9cf6120b3915670a7d5ad94d79df5dc57a46e33e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:52:42 +0200 Subject: [PATCH 24/46] Add Int2 constructors. --- Source/Engine/Core/Math/Int2.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index c13f3d84c..05861c493 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -74,9 +74,25 @@ public: } // Init - // @param v Vector to use X and Y components - explicit Int2(const Vector2& v); + // @param xyz Int3 to use X and Y components + Int2(const Int3& xyz); + // Init + // @param xyzw Int4 to use X and Y components + Int2(const Int4& xyzw); + + // Init + // @param xy Vector2 to use X and Y components + explicit Int2(const Vector2& xy); + + // Init + // @param xyz Vector3 to use X and Y components + explicit Int2(const Vector3& xyz); + + // Init + // @param xyzw Vector4 to use X and Y components + explicit Int2(const Vector4& xyzw); + public: String ToString() const; From 54786a001a5afe7c05893d795546df62d1c3e1e4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:53:20 +0200 Subject: [PATCH 25/46] Add Int4 operators + funcs. --- Source/Engine/Core/Math/Int4.h | 223 +++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index 396fa6e39..236b34070 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -121,6 +121,229 @@ public: public: + // Arithmetic operators with Int2 + + Int4 operator+(const Int4& b) const + { + return Add(*this, b); + } + + Int4 operator-(const Int4& b) const + { + return Subtract(*this, b); + } + + Int4 operator*(const Int4& b) const + { + return Multiply(*this, b); + } + + Int4 operator/(const Int4& b) const + { + return Divide(*this, b); + } + + Int4 operator-() const + { + return Int4(-X, -Y, -Z, -W); + } + + // op= operators with Int2 + + Int4& operator+=(const Int4& b) + { + *this = Add(*this, b); + return *this; + } + + Int4& operator-=(const Int4& b) + { + *this = Subtract(*this, b); + return *this; + } + + Int4& operator*=(const Int4& b) + { + *this = Multiply(*this, b); + return *this; + } + + Int4& operator/=(const Int4& b) + { + *this = Divide(*this, b); + return *this; + } + + // Arithmetic operators with int32 + + Int4 operator+(int32 b) const + { + return Add(*this, b); + } + + Int4 operator-(int32 b) const + { + return Subtract(*this, b); + } + + Int4 operator*(int32 b) const + { + return Multiply(*this, b); + } + + Int4 operator/(int32 b) const + { + return Divide(*this, b); + } + + // op= operators with int32 + + Int4& operator+=(int32 b) + { + *this = Add(*this, b); + return *this; + } + + Int4& operator-=(int32 b) + { + *this = Subtract(*this, b); + return *this; + } + + Int4& operator*=(int32 b) + { + *this = Multiply(*this, b); + return *this; + } + + Int4& operator/=(int32 b) + { + *this = Divide(*this, b); + return *this; + } + + // Comparison operators + + bool operator==(const Int4& b) const + { + return X == b.X && Y == b.Y; + } + + bool operator!=(const Int4& b) const + { + return X != b.X || Y != b.Y; + } + + bool operator>(const Int4& b) const + { + return X > b.X && Y > b.Y; + } + + bool operator>=(const Int4& b) const + { + return X >= b.X && Y >= b.Y; + } + + bool operator<(const Int4& b) const + { + return X < b.X && Y < b.Y; + } + + bool operator<=(const Int4& b) const + { + return X <= b.X && Y <= b.Y; + } + +public: + + static void Add(const Int4& a, const Int4& b, Int4& result) + { + result.X = a.X + b.X; + result.Y = a.Y + b.Y; + result.Z = a.Z + b.Z; + result.W = a.W + b.W; + } + + static Int4 Add(const Int4& a, const Int4& b) + { + Int4 result; + Add(a, b, result); + return result; + } + + static void Subtract(const Int4& a, const Int4& b, Int4& result) + { + result.X = a.X - b.X; + result.Y = a.Y - b.Y; + result.Z = a.Z - b.Z; + result.W = a.W - b.W; + } + + static Int4 Subtract(const Int4& a, const Int4& b) + { + Int4 result; + Subtract(a, b, result); + return result; + } + + static Int4 Multiply(const Int4& a, const Int4& b) + { + return Int4(a.X * b.X, a.Y * b.Y, a.Z * b.Z, a.W * b.W); + } + + static Int4 Multiply(const Int4& a, int32 b) + { + return Int4(a.X * b, a.Y * b, a.Z * b, a.W * b); + } + + static Int4 Divide(const Int4& a, const Int4& b) + { + return Int4(a.X / b.X, a.Y / b.Y, a.Z / b.Z, a.W / b.W); + } + + static Int4 Divide(const Int4& a, int32 b) + { + return Int4(a.X / b, a.Y / b, a.Z / b, a.Y / b); + } + +public: + + /// + /// Gets a value indicting whether this vector is zero. + /// + /// True if the vector is zero, otherwise false. + bool IsZero() const + { + return X == 0 && Y == 0 && Z == 0 && W == 0; + } + + /// + /// Gets a value indicting whether any vector component is zero. + /// + /// True if a component is zero, otherwise false. + bool IsAnyZero() const + { + return X == 0 || Y == 0 || Z == 0 || W == 0; + } + + /// + /// Gets a value indicting whether this vector is one. + /// + /// True if the vector is one, otherwise false. + bool IsOne() const + { + return X == 1 && Y == 1 && Z == 1 && W == 1; + } + + /// + /// Calculates a vector with values being opposite to values of that vector + /// + /// Negative vector + Int4 GetNegative() const + { + return Int4(-X, -Y, -Z, -W); + } + /// /// Returns average arithmetic of all the components /// From 4b22503ea27e5f19c13804af281dd3f0db5e40f5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:53:39 +0200 Subject: [PATCH 26/46] Add Int3 operators + funcs. --- Source/Engine/Core/Math/Int3.h | 257 +++++++++++++++++++++++++++++++++ 1 file changed, 257 insertions(+) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index b5f8e0bf3..b215ee4ed 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -110,6 +110,263 @@ public: public: + // Arithmetic operators with Int2 + + Int3 operator+(const Int3& b) const + { + return Add(*this, b); + } + + Int3 operator-(const Int3& b) const + { + return Subtract(*this, b); + } + + Int3 operator*(const Int3& b) const + { + return Multiply(*this, b); + } + + Int3 operator/(const Int3& b) const + { + return Divide(*this, b); + } + + Int3 operator-() const + { + return Int3(-X, -Y, -Z); + } + + // op= operators with Int2 + + Int3& operator+=(const Int3& b) + { + *this = Add(*this, b); + return *this; + } + + Int3& operator-=(const Int3& b) + { + *this = Subtract(*this, b); + return *this; + } + + Int3& operator*=(const Int3& b) + { + *this = Multiply(*this, b); + return *this; + } + + Int3& operator/=(const Int3& b) + { + *this = Divide(*this, b); + return *this; + } + + // Arithmetic operators with int32 + + Int3 operator+(int32 b) const + { + return Add(*this, b); + } + + Int3 operator-(int32 b) const + { + return Subtract(*this, b); + } + + Int3 operator*(int32 b) const + { + return Multiply(*this, b); + } + + Int3 operator/(int32 b) const + { + return Divide(*this, b); + } + + // op= operators with int32 + + Int3& operator+=(int32 b) + { + *this = Add(*this, b); + return *this; + } + + Int3& operator-=(int32 b) + { + *this = Subtract(*this, b); + return *this; + } + + Int3& operator*=(int32 b) + { + *this = Multiply(*this, b); + return *this; + } + + Int3& operator/=(int32 b) + { + *this = Divide(*this, b); + return *this; + } + + // Comparison operators + + bool operator==(const Int3& b) const + { + return X == b.X && Y == b.Y; + } + + bool operator!=(const Int3& b) const + { + return X != b.X || Y != b.Y; + } + + bool operator>(const Int3& b) const + { + return X > b.X && Y > b.Y; + } + + bool operator>=(const Int3& b) const + { + return X >= b.X && Y >= b.Y; + } + + bool operator<(const Int3& b) const + { + return X < b.X && Y < b.Y; + } + + bool operator<=(const Int3& b) const + { + return X <= b.X && Y <= b.Y; + } + +public: + + static void Add(const Int3& a, const Int3& b, Int3& result) + { + result.X = a.X + b.X; + result.Y = a.Y + b.Y; + result.Z = a.Z + b.Z; + } + + static Int3 Add(const Int3& a, const Int3& b) + { + Int3 result; + Add(a, b, result); + return result; + } + + static void Subtract(const Int3& a, const Int3& b, Int3& result) + { + result.X = a.X - b.X; + result.Y = a.Y - b.Y; + result.Z = a.Z - b.Z; + } + + static Int3 Subtract(const Int3& a, const Int3& b) + { + Int3 result; + Subtract(a, b, result); + return result; + } + + static Int3 Multiply(const Int3& a, const Int3& b) + { + return Int3(a.X * b.X, a.Y * b.Y, a.Z * b.Z); + } + + static Int3 Multiply(const Int3& a, int32 b) + { + return Int3(a.X * b, a.Y * b, a.Z * b); + } + + static Int3 Divide(const Int3& a, const Int3& b) + { + return Int3(a.X / b.X, a.Y / b.Y, a.Z / b.Z); + } + + static Int3 Divide(const Int3& a, int32 b) + { + return Int3(a.X / b, a.Y / b, a.Z / b); + } + +public: + + /// + /// Gets a value indicting whether this vector is zero. + /// + /// True if the vector is zero, otherwise false. + bool IsZero() const + { + return X == 0 && Y == 0 && Z == 0; + } + + /// + /// Gets a value indicting whether any vector component is zero. + /// + /// True if a component is zero, otherwise false. + bool IsAnyZero() const + { + return X == 0 || Y == 0 || Z == 0; + } + + /// + /// Gets a value indicting whether this vector is one. + /// + /// True if the vector is one, otherwise false. + bool IsOne() const + { + return X == 1 && Y == 1 && Z == 1; + } + + /// + /// Calculates a vector with values being opposite to values of that vector + /// + /// Negative vector + Int3 GetNegative() const + { + return Int3(-X, -Y, -Z); + } + + /// + /// Returns average arithmetic of all the components + /// + /// Average arithmetic of all the components + float AverageArithmetic() const + { + return (X + Y + Z) / 3.0f; + } + + /// + /// Gets sum of all vector components values + /// + /// Sum of X, Y, Z and W + int32 SumValues() const + { + return X + Y + Z; + } + + /// + /// Returns minimum value of all the components + /// + /// Minimum value + int32 MinValue() const + { + return Math::Min(X, Y, Z); + } + + /// + /// Returns maximum value of all the components + /// + /// Maximum value + int32 MaxValue() const + { + return Math::Max(X, Y, Z); + } + // Returns a vector containing the largest components of the specified vectors // @param a The first source vector // @param b The second source vector From 0b1c1b3a8d546c6a891aebd97cf22d123bef8ad9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:54:09 +0200 Subject: [PATCH 27/46] Refactor Int2 operation. --- Source/Engine/Core/Math/Int2.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index 05861c493..682190fa8 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -234,29 +234,29 @@ public: public: - static void Add(const Int2& a, const Int2& b, Int2* result) + static void Add(const Int2& a, const Int2& b, Int2& result) { - result->X = a.X + b.X; - result->Y = a.Y + b.Y; + result.X = a.X + b.X; + result.Y = a.Y + b.Y; } static Int2 Add(const Int2& a, const Int2& b) { Int2 result; - Add(a, b, &result); + Add(a, b, result); return result; } - static void Subtract(const Int2& a, const Int2& b, Int2* result) + static void Subtract(const Int2& a, const Int2& b, Int2& result) { - result->X = a.X - b.X; - result->Y = a.Y - b.Y; + result.X = a.X - b.X; + result.Y = a.Y - b.Y; } static Int2 Subtract(const Int2& a, const Int2& b) { Int2 result; - Subtract(a, b, &result); + Subtract(a, b, result); return result; } From 9d3861ace29de7c46d0b9373731c155bb22c4b2f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:54:20 +0200 Subject: [PATCH 28/46] Add Int2 funcs. --- Source/Engine/Core/Math/Int2.h | 77 +++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index 682190fa8..47875a799 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -280,7 +280,82 @@ public: return Int2(a.X / b, a.Y / b); } - // Creates vector from minimum components of two vectors + /// + /// Gets a value indicting whether this vector is zero. + /// + /// True if the vector is zero, otherwise false. + bool IsZero() const + { + return X == 0 && Y == 0; + } + + /// + /// Gets a value indicting whether any vector component is zero. + /// + /// True if a component is zero, otherwise false. + bool IsAnyZero() const + { + return X == 0 || Y == 0; + } + + /// + /// Gets a value indicting whether this vector is one. + /// + /// True if the vector is one, otherwise false. + bool IsOne() const + { + return X == 1 && Y == 1; + } + + /// + /// Calculates a vector with values being opposite to values of that vector + /// + /// Negative vector + Int2 GetNegative() const + { + return Int2(-X, -Y); + } + + /// + /// Returns average arithmetic of all the components + /// + /// Average arithmetic of all the components + float AverageArithmetic() const + { + return (X + Y) * 0.5f; + } + + /// + /// Gets sum of all vector components values + /// + /// Sum of X, Y, Z and W + int32 SumValues() const + { + return X + Y; + } + + /// + /// Returns minimum value of all the components + /// + /// Minimum value + int32 MinValue() const + { + return Math::Min(X, Y); + } + + /// + /// Returns maximum value of all the components + /// + /// Maximum value + int32 MaxValue() const + { + return Math::Max(X, Y); + } + + + // Returns a vector containing the smallest components of the specified vectors + // @param a The first source vector + // @param b The second source vector static Int2 Min(const Int2& a, const Int2& b) { return Int2(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y); From e912590bc69c503262f689f01b8d34477802242e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:54:35 +0200 Subject: [PATCH 29/46] Add Int2 Min/Max. --- Source/Engine/Core/Math/Int2.h | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Source/Engine/Core/Math/Int2.h b/Source/Engine/Core/Math/Int2.h index 47875a799..236768254 100644 --- a/Source/Engine/Core/Math/Int2.h +++ b/Source/Engine/Core/Math/Int2.h @@ -361,11 +361,31 @@ public: return Int2(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y); } - // Creates vector from maximum components of two vectors + // Returns a vector containing the largest components of the specified vectors + // @param a The first source vector + // @param b The second source vector static Int2 Max(const Int2& a, const Int2& b) { return Int2(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y); } + + // Returns a vector containing the smallest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + // @param result When the method completes, contains an new vector composed of the smallest components of the source vectors + static void Min(const Int2& a, const Int2& b, Int2& result) + { + result = Int2(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y); + } + + // Returns a vector containing the largest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + // @param result When the method completes, contains an new vector composed of the largest components of the source vectors + static void Max(const Int2& a, const Int2& b, Int2& result) + { + result = Int2(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y); + } }; template<> From e9c5ffa73601d760dcf43b325e9451c36229fc5e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:54:55 +0200 Subject: [PATCH 30/46] Add Int3 Min/Max. --- Source/Engine/Core/Math/Int3.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Core/Math/Int3.h b/Source/Engine/Core/Math/Int3.h index b215ee4ed..92311e2b1 100644 --- a/Source/Engine/Core/Math/Int3.h +++ b/Source/Engine/Core/Math/Int3.h @@ -370,7 +370,6 @@ public: // Returns a vector containing the largest components of the specified vectors // @param a The first source vector // @param b The second source vector - // @param result When the method completes, contains an new vector composed of the largest components of the source vectors static Int3 Max(const Int3& a, const Int3& b) { return Int3(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y, a.Z > b.Z ? a.Z : b.Z); @@ -379,7 +378,6 @@ public: // Returns a vector containing the smallest components of the specified vectors // @param a The first source vector // @param b The second source vector - // @param result When the method completes, contains an new vector composed of the smallest components of the source vectors static Int3 Min(const Int3& a, const Int3& b) { return Int3(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y, a.Z < b.Z ? a.Z : b.Z); @@ -389,18 +387,18 @@ public: // @param a The first source vector // @param b The second source vector // @param result When the method completes, contains an new vector composed of the largest components of the source vectors - static void Max(const Int3& a, const Int3& b, Int3* result) + static void Max(const Int3& a, const Int3& b, Int3& result) { - *result = Int3(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y, a.Z > b.Z ? a.Z : b.Z); + result = Int3(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y, a.Z > b.Z ? a.Z : b.Z); } // Returns a vector containing the smallest components of the specified vectors // @param a The first source vector // @param b The second source vector // @param result When the method completes, contains an new vector composed of the smallest components of the source vectors - static void Min(const Int3& a, const Int3& b, Int3* result) + static void Min(const Int3& a, const Int3& b, Int3 result) { - *result = Int3(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y, a.Z < b.Z ? a.Z : b.Z); + result = Int3(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y, a.Z < b.Z ? a.Z : b.Z); } }; From fed5805fcce910bc5f7d00cf962e87e543f84f8a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:55:07 +0200 Subject: [PATCH 31/46] Add Int4 Min/Max. --- Source/Engine/Core/Math/Int4.h | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Source/Engine/Core/Math/Int4.h b/Source/Engine/Core/Math/Int4.h index 236b34070..8c7f148be 100644 --- a/Source/Engine/Core/Math/Int4.h +++ b/Source/Engine/Core/Math/Int4.h @@ -379,6 +379,40 @@ public: { return Math::Max(X, Y, Z, W); } + + // Returns a vector containing the largest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + static Int4 Max(const Int4& a, const Int4& b) + { + return Int4(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y, a.Z > b.Z ? a.Z : b.Z, a.W > b.W ? a.W : b.W); + } + + // Returns a vector containing the smallest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + static Int4 Min(const Int4& a, const Int4& b) + { + return Int4(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y, a.Z < b.Z ? a.Z : b.Z, a.W < b.W ? a.W : b.W); + } + + // Returns a vector containing the largest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + // @param result When the method completes, contains an new vector composed of the largest components of the source vectors + static void Max(const Int4& a, const Int4& b, Int4& result) + { + result = Int4(a.X > b.X ? a.X : b.X, a.Y > b.Y ? a.Y : b.Y, a.Z > b.Z ? a.Z : b.Z, a.W > b.W ? a.W : b.W); + } + + // Returns a vector containing the smallest components of the specified vectors + // @param a The first source vector + // @param b The second source vector + // @param result When the method completes, contains an new vector composed of the smallest components of the source vectors + static void Min(const Int4& a, const Int4& b, Int4& result) + { + result = Int4(a.X < b.X ? a.X : b.X, a.Y < b.Y ? a.Y : b.Y, a.Z < b.Z ? a.Z : b.Z, a.W < b.W ? a.W : b.W); + } }; template<> From 054b2cb9c7049e5015c7b9bcf4ae43b277c1d06f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:55:48 +0200 Subject: [PATCH 32/46] Add C++ Serialization IntX support. Header. --- Source/Engine/Serialization/Serialization.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Source/Engine/Serialization/Serialization.h b/Source/Engine/Serialization/Serialization.h index 29642f850..cfe63c859 100644 --- a/Source/Engine/Serialization/Serialization.h +++ b/Source/Engine/Serialization/Serialization.h @@ -268,6 +268,27 @@ namespace Serialization } FLAXENGINE_API void Deserialize(ISerializable::DeserializeStream& stream, Vector4& v, ISerializeModifier* modifier); + FLAXENGINE_API bool ShouldSerialize(const Int2& v, const void* otherObj); + inline void Serialize(ISerializable::SerializeStream& stream, const Int2& v, const void* otherObj) + { + stream.Int2(v); + } + FLAXENGINE_API void Deserialize(ISerializable::DeserializeStream& stream, Int2& v, ISerializeModifier* modifier); + + FLAXENGINE_API bool ShouldSerialize(const Int3& v, const void* otherObj); + inline void Serialize(ISerializable::SerializeStream& stream, const Int3& v, const void* otherObj) + { + stream.Int3(v); + } + FLAXENGINE_API void Deserialize(ISerializable::DeserializeStream& stream, Int3& v, ISerializeModifier* modifier); + + FLAXENGINE_API bool ShouldSerialize(const Int4& v, const void* otherObj); + inline void Serialize(ISerializable::SerializeStream& stream, const Int4& v, const void* otherObj) + { + stream.Int4(v); + } + FLAXENGINE_API void Deserialize(ISerializable::DeserializeStream& stream, Int4& v, ISerializeModifier* modifier); + FLAXENGINE_API bool ShouldSerialize(const Quaternion& v, const void* otherObj); inline void Serialize(ISerializable::SerializeStream& stream, const Quaternion& v, const void* otherObj) { From e55dd16b723c6ff0de2327871bec83fcc54e3fc6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:56:20 +0200 Subject: [PATCH 33/46] Add IntX support Serialize. --- Source/Engine/Serialization/Serialization.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Engine/Serialization/Serialization.cpp b/Source/Engine/Serialization/Serialization.cpp index 7eb48a22c..2299a9dd3 100644 --- a/Source/Engine/Serialization/Serialization.cpp +++ b/Source/Engine/Serialization/Serialization.cpp @@ -138,6 +138,15 @@ void Serialization::Serialize(ISerializable::SerializeStream& stream, const Vari case VariantType::Vector4: stream.Vector4(*(Vector4*)v.AsData); break; + case VariantType::Int2: + stream.Int2(*(Int2*)v.AsData); + break; + case VariantType::Int3: + stream.Int3(*(Int3*)v.AsData); + break; + case VariantType::Int4: + stream.Int4(*(Int4*)v.AsData); + break; case VariantType::Color: stream.Color(*(Color*)v.AsData); break; From 7a5e5a63e190dee854e1a7b8f35eac2a24c121a4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:56:36 +0200 Subject: [PATCH 34/46] Add IntX support Deserialize. --- Source/Engine/Serialization/Serialization.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Engine/Serialization/Serialization.cpp b/Source/Engine/Serialization/Serialization.cpp index 2299a9dd3..e166c90d2 100644 --- a/Source/Engine/Serialization/Serialization.cpp +++ b/Source/Engine/Serialization/Serialization.cpp @@ -267,6 +267,15 @@ void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Varian case VariantType::Vector4: Deserialize(value, *(Vector4*)v.AsData, modifier); break; + case VariantType::Int2: + Deserialize(value, *(Int2*)v.AsData, modifier); + break; + case VariantType::Int3: + Deserialize(value, *(Int3*)v.AsData, modifier); + break; + case VariantType::Int4: + Deserialize(value, *(Int4*)v.AsData, modifier); + break; case VariantType::Color: Deserialize(value, *(Color*)v.AsData, modifier); break; From 274dde0a7e19d273b2e44cdeb26670fbb8abed0a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:57:05 +0200 Subject: [PATCH 35/46] Add IntX support De/Serialize. --- Source/Engine/Serialization/Serialization.cpp | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Source/Engine/Serialization/Serialization.cpp b/Source/Engine/Serialization/Serialization.cpp index e166c90d2..30cfde962 100644 --- a/Source/Engine/Serialization/Serialization.cpp +++ b/Source/Engine/Serialization/Serialization.cpp @@ -463,6 +463,51 @@ void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Vector v.W = mW != stream.MemberEnd() ? mW->value.GetFloat() : 0.0f; } +bool Serialization::ShouldSerialize(const Int2& v, const void* otherObj) +{ + return !otherObj || !(v == *(Int2*)otherObj); +} + +void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Int2& v, ISerializeModifier* modifier) +{ + const auto mX = SERIALIZE_FIND_MEMBER(stream, "X"); + const auto mY = SERIALIZE_FIND_MEMBER(stream, "Y"); + v.X = mX != stream.MemberEnd() ? mX->value.GetInt() : 0; + v.Y = mY != stream.MemberEnd() ? mY->value.GetInt() : 0; +} + +bool Serialization::ShouldSerialize(const Int3& v, const void* otherObj) +{ + return !otherObj || !(v == *(Int3*)otherObj); +} + +void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Int3& v, ISerializeModifier* modifier) +{ + const auto mX = SERIALIZE_FIND_MEMBER(stream, "X"); + const auto mY = SERIALIZE_FIND_MEMBER(stream, "Y"); + const auto mZ = SERIALIZE_FIND_MEMBER(stream, "Z"); + v.X = mX != stream.MemberEnd() ? mX->value.GetInt() : 0; + v.Y = mY != stream.MemberEnd() ? mY->value.GetInt() : 0; + v.Z = mZ != stream.MemberEnd() ? mZ->value.GetInt() : 0; +} + +bool Serialization::ShouldSerialize(const Int4& v, const void* otherObj) +{ + return !otherObj || !(v == *(Int4*)otherObj); +} + +void Serialization::Deserialize(ISerializable::DeserializeStream& stream, Int4& v, ISerializeModifier* modifier) +{ + const auto mX = SERIALIZE_FIND_MEMBER(stream, "X"); + const auto mY = SERIALIZE_FIND_MEMBER(stream, "Y"); + const auto mZ = SERIALIZE_FIND_MEMBER(stream, "Z"); + const auto mW = SERIALIZE_FIND_MEMBER(stream, "W"); + v.X = mX != stream.MemberEnd() ? mX->value.GetInt() : 0; + v.Y = mY != stream.MemberEnd() ? mY->value.GetInt() : 0; + v.Z = mZ != stream.MemberEnd() ? mZ->value.GetInt() : 0; + v.W = mW != stream.MemberEnd() ? mW->value.GetInt() : 0; +} + bool Serialization::ShouldSerialize(const Quaternion& v, const void* otherObj) { return !otherObj || !Quaternion::NearEqual(v, *(Quaternion*)otherObj, SERIALIZE_EPSILON); From b4b41d677354bfc37e026331573aa96c93172207 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:57:28 +0200 Subject: [PATCH 36/46] Add IntX to VairantType. --- Source/Editor/Utilities/Utils.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index b5c835d70..33810fe5c 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -67,6 +67,10 @@ namespace FlaxEditor.Utilities Dictionary, ManagedObject, Typename, + + Int2, + Int3, + Int4 } /// From f6a6e298e06b99593ff0280ee6fdddf8c3180016 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:57:47 +0200 Subject: [PATCH 37/46] Add ToVariantType support. --- Source/Editor/Utilities/Utils.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 33810fe5c..a9aaa3664 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -450,6 +450,12 @@ namespace FlaxEditor.Utilities variantType = VariantType.Vector3; else if (type == typeof(Vector4)) variantType = VariantType.Vector4; + else if (type == typeof(Int2)) + variantType = VariantType.Int2; + else if (type == typeof(Int3)) + variantType = VariantType.Int3; + else if (type == typeof(Int4)) + variantType = VariantType.Int4; else if (type == typeof(Color)) variantType = VariantType.Color; else if (type == typeof(Guid)) From 3bbeae15f2f83237874261eae2f107c17ee75764 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:58:13 +0200 Subject: [PATCH 38/46] Add ReadCommonValue support. --- Source/Editor/Utilities/Utils.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index a9aaa3664..daa54456e 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -692,6 +692,21 @@ namespace FlaxEditor.Utilities new Vector3(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle())); break; } + case 19: // CommonType::Int2 + { + value = stream.ReadInt2(); + break; + } + case 20: // CommonType::Int3 + { + value = stream.ReadInt3(); + break; + } + case 21: // CommonType::Int4 + { + value = stream.ReadInt4(); + break; + } default: throw new SystemException(); } } From 5b6a0a8d7f870541bca850c30d9492a78ffdfade Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:58:29 +0200 Subject: [PATCH 39/46] Add ReadVariantScriptType support. --- Source/Editor/Utilities/Utils.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index daa54456e..e412b86b6 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -758,6 +758,9 @@ namespace FlaxEditor.Utilities case VariantType.Vector2: return new ScriptType(typeof(Vector2)); case VariantType.Vector3: return new ScriptType(typeof(Vector3)); case VariantType.Vector4: return new ScriptType(typeof(Vector4)); + case VariantType.Int2: return new ScriptType(typeof(Int2)); + case VariantType.Int3: return new ScriptType(typeof(Int3)); + case VariantType.Int4: return new ScriptType(typeof(Int4)); case VariantType.Color: return new ScriptType(typeof(Color)); case VariantType.Guid: return new ScriptType(typeof(Guid)); case VariantType.BoundingBox: return new ScriptType(typeof(BoundingBox)); From b0b6aeccd8f5af31bb94d7c1196f0c44fea552b7 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:58:45 +0200 Subject: [PATCH 40/46] Add ReadVariantType support. --- Source/Editor/Utilities/Utils.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index e412b86b6..da02a975e 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -825,6 +825,9 @@ namespace FlaxEditor.Utilities case VariantType.Vector2: return typeof(Vector2); case VariantType.Vector3: return typeof(Vector3); case VariantType.Vector4: return typeof(Vector4); + case VariantType.Int2: return typeof(Int2); + case VariantType.Int3: return typeof(Int3); + case VariantType.Int4: return typeof(Int4); case VariantType.Color: return typeof(Color); case VariantType.Guid: return typeof(Guid); case VariantType.BoundingBox: return typeof(BoundingBox); From 3f39212b7b2e7892a973a117f999b664a6d8e99a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:59:05 +0200 Subject: [PATCH 41/46] Add ReadVariant support. --- Source/Editor/Utilities/Utils.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index da02a975e..4d4d8adb7 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -925,6 +925,9 @@ namespace FlaxEditor.Utilities case VariantType.Vector2: return stream.ReadVector2(); case VariantType.Vector3: return stream.ReadVector3(); case VariantType.Vector4: return stream.ReadVector4(); + case VariantType.Int2: return stream.ReadInt2(); + case VariantType.Int3: return stream.ReadInt3(); + case VariantType.Int4: return stream.ReadInt4(); case VariantType.Color: return stream.ReadColor(); case VariantType.Guid: return stream.ReadGuid(); case VariantType.BoundingBox: return stream.ReadBoundingBox(); From 3579b869805b822e0bd71897fd37db745b56c91f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:59:19 +0200 Subject: [PATCH 42/46] Add WriteCommonValue support. --- Source/Editor/Utilities/Utils.cs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 4d4d8adb7..ea0bbb843 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1121,6 +1121,21 @@ namespace FlaxEditor.Utilities stream.Write(asRay.Direction.Y); stream.Write(asRay.Direction.Z); } + else if (value is Int2 asInt2) + { + stream.Write((byte)19); + stream.Write(asInt2); + } + else if (value is Int3 asInt3) + { + stream.Write((byte)20); + stream.Write(asInt3); + } + else if (value is Int4 asInt4) + { + stream.Write((byte)21); + stream.Write(asInt4); + } else { throw new NotSupportedException(string.Format("Invalid Common Value type {0}", value != null ? value.GetType().ToString() : "null")); From 4b78551765692af798e9564fcc21092b694d850b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 18:59:38 +0200 Subject: [PATCH 43/46] Add WriteVariant support. --- Source/Editor/Utilities/Utils.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index ea0bbb843..df9121ea2 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1243,6 +1243,15 @@ namespace FlaxEditor.Utilities case VariantType.Vector4: stream.Write((Vector4)value); break; + case VariantType.Int2: + stream.Write((Int2)value); + break; + case VariantType.Int3: + stream.Write((Int3)value); + break; + case VariantType.Int4: + stream.Write((Int4)value); + break; case VariantType.Color: stream.Write((Color)value); break; From 4e86f1c776dcae8d66a0dd3e4bba1fdfcee99609 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 19:00:03 +0200 Subject: [PATCH 44/46] Add WriteVariant support. --- Source/Editor/Utilities/Utils.cs | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index df9121ea2..6c7aa86d7 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -1444,6 +1444,51 @@ namespace FlaxEditor.Utilities stream.WriteEndObject(); break; } + case VariantType.Int2: + { + var asInt2 = (Int2)value; + stream.WriteStartObject(); + + stream.WritePropertyName("X"); + stream.WriteValue(asInt2.X); + stream.WritePropertyName("Y"); + stream.WriteValue(asInt2.Y); + + stream.WriteEndObject(); + break; + } + case VariantType.Int3: + { + var asInt3 = (Int3)value; + stream.WriteStartObject(); + + stream.WritePropertyName("X"); + stream.WriteValue(asInt3.X); + stream.WritePropertyName("Y"); + stream.WriteValue(asInt3.Y); + stream.WritePropertyName("Z"); + stream.WriteValue(asInt3.Z); + + stream.WriteEndObject(); + break; + } + case VariantType.Int4: + { + var asInt4 = (Int4)value; + stream.WriteStartObject(); + + stream.WritePropertyName("X"); + stream.WriteValue(asInt4.X); + stream.WritePropertyName("Y"); + stream.WriteValue(asInt4.Y); + stream.WritePropertyName("Z"); + stream.WriteValue(asInt4.Z); + stream.WritePropertyName("W"); + stream.WriteValue(asInt4.W); + + stream.WriteEndObject(); + break; + } case VariantType.Color: { var asColor = (Color)value; From 8e7ff6f6571999e86254f62b29f5fc87a95dd428 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 19:00:25 +0200 Subject: [PATCH 45/46] Add IntX stream read support. --- Source/Engine/Utilities/Utils.cs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Source/Engine/Utilities/Utils.cs b/Source/Engine/Utilities/Utils.cs index a72b4e676..ba62137cd 100644 --- a/Source/Engine/Utilities/Utils.cs +++ b/Source/Engine/Utilities/Utils.cs @@ -240,6 +240,36 @@ namespace FlaxEngine return new Vector4(stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle(), stream.ReadSingle()); } + /// + /// Reads the Int2 from the binary stream. + /// + /// The stream. + /// The value. + public static Int2 ReadInt2(this BinaryReader stream) + { + return new Int2(stream.ReadInt32(), stream.ReadInt32()); + } + + /// + /// Reads the Int3 from the binary stream. + /// + /// The stream. + /// The value. + public static Int3 ReadInt3(this BinaryReader stream) + { + return new Int3(stream.ReadInt32(), stream.ReadInt32(), stream.ReadInt32()); + } + + /// + /// Reads the Int4 from the binary stream. + /// + /// The stream. + /// The value. + public static Int4 ReadInt4(this BinaryReader stream) + { + return new Int4(stream.ReadInt32(), stream.ReadInt32(), stream.ReadInt32(), stream.ReadInt32()); + } + /// /// Reads the Quaternion from the binary stream. /// From 992f4b230369c1de8a2cdb1664d2413cf75674e1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Perrier Date: Thu, 8 Apr 2021 19:00:40 +0200 Subject: [PATCH 46/46] Add IntX write stream support. --- Source/Engine/Utilities/Utils.cs | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Source/Engine/Utilities/Utils.cs b/Source/Engine/Utilities/Utils.cs index ba62137cd..ab4fdf17b 100644 --- a/Source/Engine/Utilities/Utils.cs +++ b/Source/Engine/Utilities/Utils.cs @@ -392,6 +392,42 @@ namespace FlaxEngine stream.Write(value.W); } + /// + /// Writes the Int2 to the binary stream. + /// + /// The stream. + /// The value to write. + public static void Write(this BinaryWriter stream, Int2 value) + { + stream.Write(value.X); + stream.Write(value.Y); + } + + /// + /// Writes the Int3 to the binary stream. + /// + /// The stream. + /// The value to write. + public static void Write(this BinaryWriter stream, Int3 value) + { + stream.Write(value.X); + stream.Write(value.Y); + stream.Write(value.Z); + } + + /// + /// Writes the Int4 to the binary stream. + /// + /// The stream. + /// The value to write. + public static void Write(this BinaryWriter stream, Int4 value) + { + stream.Write(value.X); + stream.Write(value.Y); + stream.Write(value.Z); + stream.Write(value.W); + } + /// /// Writes the Quaternion to the binary stream. ///