Added Vector2i, Vector3i, Rect2i, PoolVector2i, PoolVector3i, Vector<Vector2i>, Vector<Vector3i> classes as core variant binds. GDScript still need to be updated to be able to use them.

This commit is contained in:
Relintai 2022-03-21 14:01:31 +01:00
parent 34547120dd
commit 527cfb88aa
14 changed files with 1888 additions and 148 deletions

View File

@ -642,26 +642,31 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL", Variant::REAL);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING", Variant::STRING);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2", Variant::VECTOR2); // 5
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I", Variant::VECTOR2I);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2", Variant::RECT2);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RECT2I", Variant::RECT2I);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3", Variant::VECTOR3);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I", Variant::VECTOR3I); //10
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM2D", Variant::TRANSFORM2D);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_PLANE", Variant::PLANE);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT); // 10
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_QUAT", Variant::QUAT);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_AABB", Variant::AABB);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_BASIS", Variant::BASIS); //15
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_TRANSFORM", Variant::TRANSFORM);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR", Variant::COLOR);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH); // 15
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_NODE_PATH", Variant::NODE_PATH);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RID", Variant::_RID);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_OBJECT", Variant::OBJECT);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY); // 20
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_OBJECT", Variant::OBJECT); // 20
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_DICTIONARY", Variant::DICTIONARY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_ARRAY", Variant::ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_RAW_ARRAY", Variant::POOL_BYTE_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_INT_ARRAY", Variant::POOL_INT_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL_ARRAY", Variant::POOL_REAL_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_REAL_ARRAY", Variant::POOL_REAL_ARRAY); //25
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_STRING_ARRAY", Variant::POOL_STRING_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::POOL_VECTOR2_ARRAY); // 25
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2_ARRAY", Variant::POOL_VECTOR2_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR2I_ARRAY", Variant::POOL_VECTOR2I_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3_ARRAY", Variant::POOL_VECTOR3_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_VECTOR3I_ARRAY", Variant::POOL_VECTOR3I_ARRAY); //30
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_COLOR_ARRAY", Variant::POOL_COLOR_ARRAY);
BIND_GLOBAL_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX);

View File

@ -32,6 +32,7 @@
#include "core/math/quat.h"
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
class _NO_DISCARD_CLASS_ Basis {
public:
@ -151,6 +152,10 @@ public:
_FORCE_INLINE_ Vector3 xform(const Vector3 &p_vector) const;
_FORCE_INLINE_ Vector3 xform_inv(const Vector3 &p_vector) const;
_FORCE_INLINE_ Vector3i xform(const Vector3i &p_vector) const;
_FORCE_INLINE_ Vector3i xform_inv(const Vector3i &p_vector) const;
_FORCE_INLINE_ void operator*=(const Basis &p_matrix);
_FORCE_INLINE_ Basis operator*(const Basis &p_matrix) const;
_FORCE_INLINE_ void operator+=(const Basis &p_matrix);
@ -328,6 +333,20 @@ Vector3 Basis::xform(const Vector3 &p_vector) const {
elements[2].dot(p_vector));
}
Vector3i Basis::xform_inv(const Vector3i &p_vector) const {
return Vector3i(
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z),
(elements[0][1] * p_vector.x) + (elements[1][1] * p_vector.y) + (elements[2][1] * p_vector.z),
(elements[0][2] * p_vector.x) + (elements[1][2] * p_vector.y) + (elements[2][2] * p_vector.z));
}
Vector3i Basis::xform(const Vector3i &p_vector) const {
return Vector3i(
elements[0].dot(p_vector),
elements[1].dot(p_vector),
elements[2].dot(p_vector));
}
Vector3 Basis::xform_inv(const Vector3 &p_vector) const {
return Vector3(
(elements[0][0] * p_vector.x) + (elements[1][0] * p_vector.y) + (elements[2][0] * p_vector.z),

View File

@ -34,6 +34,7 @@
#include "core/math/basis.h"
#include "core/math/plane.h"
#include "core/pool_vector.h"
#include "core/math/vector3i.h"
class _NO_DISCARD_CLASS_ Transform {
public:
@ -75,15 +76,19 @@ public:
bool operator!=(const Transform &p_transform) const;
_FORCE_INLINE_ Vector3 xform(const Vector3 &p_vector) const;
_FORCE_INLINE_ Vector3i xform(const Vector3i &p_vector) const;
_FORCE_INLINE_ AABB xform(const AABB &p_aabb) const;
_FORCE_INLINE_ PoolVector<Vector3> xform(const PoolVector<Vector3> &p_array) const;
_FORCE_INLINE_ PoolVector<Vector3i> xform(const PoolVector<Vector3i> &p_array) const;
// NOTE: These are UNSAFE with non-uniform scaling, and will produce incorrect results.
// They use the transpose.
// For safe inverse transforms, xform by the affine_inverse.
_FORCE_INLINE_ Vector3 xform_inv(const Vector3 &p_vector) const;
_FORCE_INLINE_ Vector3i xform_inv(const Vector3i &p_vector) const;
_FORCE_INLINE_ AABB xform_inv(const AABB &p_aabb) const;
_FORCE_INLINE_ PoolVector<Vector3> xform_inv(const PoolVector<Vector3> &p_array) const;
_FORCE_INLINE_ PoolVector<Vector3i> xform_inv(const PoolVector<Vector3i> &p_array) const;
// Safe with non-uniform scaling (uses affine_inverse).
_FORCE_INLINE_ Plane xform(const Plane &p_plane) const;
@ -135,6 +140,25 @@ _FORCE_INLINE_ Vector3 Transform::xform_inv(const Vector3 &p_vector) const {
(basis.elements[0][2] * v.x) + (basis.elements[1][2] * v.y) + (basis.elements[2][2] * v.z));
}
_FORCE_INLINE_ Vector3i Transform::xform(const Vector3i &p_vector) const {
return Vector3i(
basis[0].dot(p_vector) + origin.x,
basis[1].dot(p_vector) + origin.y,
basis[2].dot(p_vector) + origin.z);
}
_FORCE_INLINE_ Vector3i Transform::xform_inv(const Vector3i &p_vector) const {
Vector3i v = p_vector;
v.x -= origin.x;
v.y -= origin.y;
v.z -= origin.z;
return Vector3i(
(basis.elements[0][0] * v.x) + (basis.elements[1][0] * v.y) + (basis.elements[2][0] * v.z),
(basis.elements[0][1] * v.x) + (basis.elements[1][1] * v.y) + (basis.elements[2][1] * v.z),
(basis.elements[0][2] * v.x) + (basis.elements[1][2] * v.y) + (basis.elements[2][2] * v.z));
}
// Neither the plane regular xform or xform_inv are particularly efficient,
// as they do a basis inverse. For xforming a large number
// of planes it is better to pre-calculate the inverse transpose basis once
@ -213,6 +237,19 @@ PoolVector<Vector3> Transform::xform(const PoolVector<Vector3> &p_array) const {
return array;
}
PoolVector<Vector3i> Transform::xform(const PoolVector<Vector3i> &p_array) const {
PoolVector<Vector3i> array;
array.resize(p_array.size());
PoolVector<Vector3i>::Read r = p_array.read();
PoolVector<Vector3i>::Write w = array.write();
for (int i = 0; i < p_array.size(); ++i) {
w[i] = xform(r[i]);
}
return array;
}
PoolVector<Vector3> Transform::xform_inv(const PoolVector<Vector3> &p_array) const {
PoolVector<Vector3> array;
array.resize(p_array.size());
@ -226,6 +263,19 @@ PoolVector<Vector3> Transform::xform_inv(const PoolVector<Vector3> &p_array) con
return array;
}
PoolVector<Vector3i> Transform::xform_inv(const PoolVector<Vector3i> &p_array) const {
PoolVector<Vector3i> array;
array.resize(p_array.size());
PoolVector<Vector3i>::Read r = p_array.read();
PoolVector<Vector3i>::Write w = array.write();
for (int i = 0; i < p_array.size(); ++i) {
w[i] = xform_inv(r[i]);
}
return array;
}
_FORCE_INLINE_ Plane Transform::xform_fast(const Plane &p_plane, const Basis &p_basis_inverse_transpose) const {
// Transform a single point on the plane.
Vector3 point = p_plane.normal * p_plane.d;

View File

@ -31,7 +31,7 @@
/*************************************************************************/
#include "core/math/rect2.h" // also includes vector2, math_funcs, and ustring
#include "core/math/rect2i.h" // also includes vector2, math_funcs, and ustring
#include "core/math/rect2i.h" // also includes vector2i, math_funcs, and ustring
#include "core/pool_vector.h"
struct _NO_DISCARD_CLASS_ Transform2D {
@ -110,10 +110,19 @@ struct _NO_DISCARD_CLASS_ Transform2D {
_FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2 &p_vec) const;
_FORCE_INLINE_ Vector2 xform(const Vector2 &p_vec) const;
_FORCE_INLINE_ Vector2 xform_inv(const Vector2 &p_vec) const;
_FORCE_INLINE_ Rect2 xform(const Rect2 &p_rect) const;
_FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_rect) const;
_FORCE_INLINE_ Vector2i basis_xform(const Vector2i &p_vec) const;
_FORCE_INLINE_ Vector2i basis_xform_inv(const Vector2i &p_vec) const;
_FORCE_INLINE_ Vector2i xform(const Vector2i &p_vec) const;
_FORCE_INLINE_ Vector2i xform_inv(const Vector2i &p_vec) const;
_FORCE_INLINE_ PoolVector<Vector2> xform(const PoolVector<Vector2> &p_array) const;
_FORCE_INLINE_ PoolVector<Vector2> xform_inv(const PoolVector<Vector2> &p_array) const;
_FORCE_INLINE_ PoolVector<Vector2i> xform(const PoolVector<Vector2i> &p_array) const;
_FORCE_INLINE_ PoolVector<Vector2i> xform_inv(const PoolVector<Vector2i> &p_array) const;
operator String() const;
@ -195,6 +204,32 @@ Rect2 Transform2D::xform_inv(const Rect2 &p_rect) const {
return new_rect;
}
Vector2i Transform2D::basis_xform(const Vector2i &p_vec) const {
return Vector2i(
tdotx(p_vec),
tdoty(p_vec));
}
Vector2i Transform2D::basis_xform_inv(const Vector2i &p_vec) const {
return Vector2i(
elements[0].dot(p_vec),
elements[1].dot(p_vec));
}
Vector2i Transform2D::xform(const Vector2i &p_vec) const {
return Vector2i(
tdotx(p_vec),
tdoty(p_vec)) +
elements[2];
}
Vector2i Transform2D::xform_inv(const Vector2i &p_vec) const {
Vector2i v = p_vec - elements[2];
return Vector2i(
elements[0].dot(v),
elements[1].dot(v));
}
PoolVector<Vector2> Transform2D::xform(const PoolVector<Vector2> &p_array) const {
PoolVector<Vector2> array;
array.resize(p_array.size());
@ -221,4 +256,30 @@ PoolVector<Vector2> Transform2D::xform_inv(const PoolVector<Vector2> &p_array) c
return array;
}
PoolVector<Vector2i> Transform2D::xform(const PoolVector<Vector2i> &p_array) const {
PoolVector<Vector2i> array;
array.resize(p_array.size());
PoolVector<Vector2i>::Read r = p_array.read();
PoolVector<Vector2i>::Write w = array.write();
for (int i = 0; i < p_array.size(); ++i) {
w[i] = xform(r[i]);
}
return array;
}
PoolVector<Vector2i> Transform2D::xform_inv(const PoolVector<Vector2i> &p_array) const {
PoolVector<Vector2i> array;
array.resize(p_array.size());
PoolVector<Vector2i>::Read r = p_array.read();
PoolVector<Vector2i>::Write w = array.write();
for (int i = 0; i < p_array.size(); ++i) {
w[i] = xform_inv(r[i]);
}
return array;
}
#endif // TRANSFORM_2D_H

View File

@ -66,6 +66,9 @@ struct _NO_DISCARD_CLASS_ Vector2i {
return coord[p_idx];
}
_FORCE_INLINE_ static Vector2i linear_interpolate(const Vector2i &p_a, const Vector2i &p_b, real_t p_weight);
_FORCE_INLINE_ Vector2i linear_interpolate(const Vector2i &p_to, real_t p_weight) const;
Vector2i operator+(const Vector2i &p_v) const;
void operator+=(const Vector2i &p_v);
Vector2i operator-(const Vector2i &p_v) const;
@ -84,6 +87,8 @@ struct _NO_DISCARD_CLASS_ Vector2i {
Vector2i operator-() const;
bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }
bool operator>(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y > p_vec2.y) : (x > p_vec2.x); }
bool operator<=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y <= p_vec2.y) : (x < p_vec2.x); }
bool operator>=(const Vector2 &p_vec2) const { return x == p_vec2.x ? (y >= p_vec2.y) : (x > p_vec2.x); }
bool operator==(const Vector2i &p_vec2) const;
bool operator!=(const Vector2i &p_vec2) const;
@ -109,6 +114,24 @@ struct _NO_DISCARD_CLASS_ Vector2i {
}
};
Vector2i Vector2i::linear_interpolate(const Vector2i &p_a, const Vector2i &p_b, real_t p_weight) {
Vector2i res = p_a;
res.x += (p_weight * (p_b.x - p_a.x));
res.y += (p_weight * (p_b.y - p_a.y));
return res;
}
Vector2i Vector2i::linear_interpolate(const Vector2i &p_to, real_t p_weight) const {
Vector2 res = *this;
res.x += (p_weight * (p_to.x - x));
res.y += (p_weight * (p_to.y - y));
return res;
}
typedef Vector2i Size2i;
typedef Vector2i Point2i;

View File

@ -79,6 +79,8 @@ struct _NO_DISCARD_CLASS_ Vector3i {
_FORCE_INLINE_ Vector3i sign() const;
Vector3i clamp(const Vector3i &p_min, const Vector3i &p_max) const;
_FORCE_INLINE_ Vector3i linear_interpolate(const Vector3i &p_to, real_t p_weight) const;
/* Operators */
_FORCE_INLINE_ Vector3i &operator+=(const Vector3i &p_v);
@ -135,6 +137,13 @@ Vector3i Vector3i::sign() const {
return Vector3i(SGN(x), SGN(y), SGN(z));
}
Vector3i Vector3i::linear_interpolate(const Vector3i &p_to, real_t p_weight) const {
return Vector3i(
x + (p_weight * (p_to.x - x)),
y + (p_weight * (p_to.y - y)),
z + (p_weight * (p_to.z - z)));
}
/* Operators */
Vector3i &Vector3i::operator+=(const Vector3i &p_v) {

View File

@ -165,6 +165,9 @@ struct VariantObjectClassChecker<Control *> {
// some helpers
VARIANT_ENUM_CAST(Vector3::Axis);
VARIANT_ENUM_CAST(Vector3i::Axis);
VARIANT_ENUM_CAST(Vector2::Axis);
VARIANT_ENUM_CAST(Vector2i::Axis);
VARIANT_ENUM_CAST(Error);
VARIANT_ENUM_CAST(Margin);

View File

@ -114,8 +114,11 @@ MAKE_PTRARG(double);
MAKE_PTRARG(String);
MAKE_PTRARG(Vector2);
MAKE_PTRARG(Vector2i);
MAKE_PTRARG(Rect2);
MAKE_PTRARG(Rect2i);
MAKE_PTRARG_BY_REFERENCE(Vector3);
MAKE_PTRARG_BY_REFERENCE(Vector3i);
MAKE_PTRARG(Transform2D);
MAKE_PTRARG_BY_REFERENCE(Plane);
MAKE_PTRARG(Quat);
@ -132,7 +135,9 @@ MAKE_PTRARG(PoolIntArray);
MAKE_PTRARG(PoolRealArray);
MAKE_PTRARG(PoolStringArray);
MAKE_PTRARG(PoolVector2Array);
MAKE_PTRARG(PoolVector2iArray);
MAKE_PTRARG(PoolVector3Array);
MAKE_PTRARG(PoolVector3iArray);
MAKE_PTRARG(PoolColorArray);
MAKE_PTRARG_BY_REFERENCE(Variant);
@ -256,7 +261,9 @@ MAKE_VECARG(uint8_t);
MAKE_VECARG(int);
MAKE_VECARG(float);
MAKE_VECARG(Vector2);
MAKE_VECARG(Vector2i);
MAKE_VECARG(Vector3);
MAKE_VECARG(Vector3i);
MAKE_VECARG(Color);
MAKE_VECARG_ALT(String, StringName);

View File

@ -137,8 +137,11 @@ MAKE_TYPE_INFO_WITH_META(double, Variant::REAL, GodotTypeInfo::METADATA_REAL_IS_
MAKE_TYPE_INFO(String, Variant::STRING)
MAKE_TYPE_INFO(Vector2, Variant::VECTOR2)
MAKE_TYPE_INFO(Vector2i, Variant::VECTOR2I)
MAKE_TYPE_INFO(Rect2, Variant::RECT2)
MAKE_TYPE_INFO(Rect2i, Variant::RECT2I)
MAKE_TYPE_INFO(Vector3, Variant::VECTOR3)
MAKE_TYPE_INFO(Vector3i, Variant::VECTOR3I)
MAKE_TYPE_INFO(Transform2D, Variant::TRANSFORM2D)
MAKE_TYPE_INFO(Plane, Variant::PLANE)
MAKE_TYPE_INFO(Quat, Variant::QUAT)
@ -155,7 +158,9 @@ MAKE_TYPE_INFO(PoolIntArray, Variant::POOL_INT_ARRAY)
MAKE_TYPE_INFO(PoolRealArray, Variant::POOL_REAL_ARRAY)
MAKE_TYPE_INFO(PoolStringArray, Variant::POOL_STRING_ARRAY)
MAKE_TYPE_INFO(PoolVector2Array, Variant::POOL_VECTOR2_ARRAY)
MAKE_TYPE_INFO(PoolVector2iArray, Variant::POOL_VECTOR2I_ARRAY)
MAKE_TYPE_INFO(PoolVector3Array, Variant::POOL_VECTOR3_ARRAY)
MAKE_TYPE_INFO(PoolVector3iArray, Variant::POOL_VECTOR3I_ARRAY)
MAKE_TYPE_INFO(PoolColorArray, Variant::POOL_COLOR_ARRAY)
MAKE_TYPE_INFO(StringName, Variant::STRING)
@ -224,7 +229,9 @@ MAKE_TEMPLATE_TYPE_INFO(Vector, int, Variant::POOL_INT_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, float, Variant::POOL_REAL_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, String, Variant::POOL_STRING_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Vector2, Variant::POOL_VECTOR2_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Vector2i, Variant::POOL_VECTOR2I_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Vector3, Variant::POOL_VECTOR3_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Vector3i, Variant::POOL_VECTOR3I_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Color, Variant::POOL_COLOR_ARRAY)
MAKE_TEMPLATE_TYPE_INFO(Vector, Variant, Variant::ARRAY)

View File

@ -66,15 +66,24 @@ String Variant::get_type_name(Variant::Type p_type) {
case VECTOR2: {
return "Vector2";
} break;
case VECTOR2I: {
return "Vector2i";
} break;
case RECT2: {
return "Rect2";
} break;
case RECT2I: {
return "Rect2i";
} break;
case TRANSFORM2D: {
return "Transform2D";
} break;
case VECTOR3: {
return "Vector3";
} break;
case VECTOR3I: {
return "Vector3i";
} break;
case PLANE: {
return "Plane";
@ -143,10 +152,18 @@ String Variant::get_type_name(Variant::Type p_type) {
case POOL_VECTOR2_ARRAY: {
return "PoolVector2Array";
} break;
case POOL_VECTOR2I_ARRAY: {
return "PoolVector2iArray";
} break;
case POOL_VECTOR3_ARRAY: {
return "PoolVector3Array";
} break;
case POOL_VECTOR3I_ARRAY: {
return "PoolVector3iArray";
} break;
case POOL_COLOR_ARRAY: {
return "PoolColorArray";
@ -215,6 +232,60 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
invalid_types = invalid;
} break;
case VECTOR2: {
static const Type valid[] = {
VECTOR2I,
NIL
};
valid_types = valid;
} break;
case VECTOR2I: {
static const Type valid[] = {
VECTOR2,
NIL
};
valid_types = valid;
} break;
case RECT2: {
static const Type valid[] = {
RECT2I,
NIL
};
valid_types = valid;
} break;
case RECT2I: {
static const Type valid[] = {
RECT2,
NIL
};
valid_types = valid;
} break;
case VECTOR3: {
static const Type valid[] = {
VECTOR3I,
NIL
};
valid_types = valid;
} break;
case VECTOR3I: {
static const Type valid[] = {
VECTOR3,
NIL
};
valid_types = valid;
} break;
case TRANSFORM2D: {
static const Type valid[] = {
TRANSFORM,
@ -296,7 +367,9 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
POOL_REAL_ARRAY,
POOL_COLOR_ARRAY,
POOL_VECTOR2_ARRAY,
POOL_VECTOR2I_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_VECTOR3I_ARRAY,
NIL
};
@ -340,6 +413,14 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
};
valid_types = valid;
} break;
case POOL_VECTOR2I_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
case POOL_VECTOR3_ARRAY: {
static const Type valid[] = {
@ -348,6 +429,14 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
};
valid_types = valid;
} break;
case POOL_VECTOR3I_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
case POOL_COLOR_ARRAY: {
static const Type valid[] = {
@ -441,6 +530,60 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
case VECTOR2: {
static const Type valid[] = {
VECTOR2I,
NIL
};
valid_types = valid;
} break;
case VECTOR2I: {
static const Type valid[] = {
VECTOR2,
NIL
};
valid_types = valid;
} break;
case RECT2: {
static const Type valid[] = {
RECT2I,
NIL
};
valid_types = valid;
} break;
case RECT2I: {
static const Type valid[] = {
RECT2,
NIL
};
valid_types = valid;
} break;
case VECTOR3: {
static const Type valid[] = {
VECTOR3I,
NIL
};
valid_types = valid;
} break;
case VECTOR3I: {
static const Type valid[] = {
VECTOR3,
NIL
};
valid_types = valid;
} break;
case TRANSFORM2D: {
static const Type valid[] = {
TRANSFORM,
@ -522,7 +665,9 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
POOL_REAL_ARRAY,
POOL_COLOR_ARRAY,
POOL_VECTOR2_ARRAY,
POOL_VECTOR2I_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_VECTOR3I_ARRAY,
NIL
};
@ -566,6 +711,14 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
};
valid_types = valid;
} break;
case POOL_VECTOR2I_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
case POOL_VECTOR3_ARRAY: {
static const Type valid[] = {
@ -574,6 +727,14 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
};
valid_types = valid;
} break;
case POOL_VECTOR3I_ARRAY: {
static const Type valid[] = {
ARRAY,
NIL
};
valid_types = valid;
} break;
case POOL_COLOR_ARRAY: {
static const Type valid[] = {
@ -689,10 +850,18 @@ bool Variant::is_zero() const {
case VECTOR2: {
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2();
} break;
case VECTOR2I: {
return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i();
} break;
case RECT2: {
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2();
} break;
case RECT2I: {
return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i();
} break;
case TRANSFORM2D: {
return *_data._transform2d == Transform2D();
@ -701,6 +870,10 @@ bool Variant::is_zero() const {
case VECTOR3: {
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3();
} break;
case VECTOR3I: {
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i();
} break;
case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane();
@ -771,10 +944,18 @@ bool Variant::is_zero() const {
case POOL_VECTOR2_ARRAY: {
return reinterpret_cast<const PoolVector<Vector2> *>(_data._mem)->size() == 0;
} break;
case POOL_VECTOR2I_ARRAY: {
return reinterpret_cast<const PoolVector<Vector2i> *>(_data._mem)->size() == 0;
} break;
case POOL_VECTOR3_ARRAY: {
return reinterpret_cast<const PoolVector<Vector3> *>(_data._mem)->size() == 0;
} break;
case POOL_VECTOR3I_ARRAY: {
return reinterpret_cast<const PoolVector<Vector3i> *>(_data._mem)->size() == 0;
} break;
case POOL_COLOR_ARRAY: {
return reinterpret_cast<const PoolVector<Color> *>(_data._mem)->size() == 0;
@ -808,14 +989,26 @@ bool Variant::is_one() const {
case VECTOR2: {
return *reinterpret_cast<const Vector2 *>(_data._mem) == Vector2(1, 1);
} break;
case VECTOR2I: {
return *reinterpret_cast<const Vector2i *>(_data._mem) == Vector2i(1, 1);
} break;
case RECT2: {
return *reinterpret_cast<const Rect2 *>(_data._mem) == Rect2(1, 1, 1, 1);
} break;
case RECT2I: {
return *reinterpret_cast<const Rect2i *>(_data._mem) == Rect2i(1, 1, 1, 1);
} break;
case VECTOR3: {
return *reinterpret_cast<const Vector3 *>(_data._mem) == Vector3(1, 1, 1);
} break;
case VECTOR3I: {
return *reinterpret_cast<const Vector3i *>(_data._mem) == Vector3i(1, 1, 1);
} break;
case PLANE: {
return *reinterpret_cast<const Plane *>(_data._mem) == Plane(1, 1, 1, 1);
@ -886,15 +1079,24 @@ void Variant::reference(const Variant &p_variant) {
case VECTOR2: {
memnew_placement(_data._mem, Vector2(*reinterpret_cast<const Vector2 *>(p_variant._data._mem)));
} break;
case VECTOR2I: {
memnew_placement(_data._mem, Vector2i(*reinterpret_cast<const Vector2i *>(p_variant._data._mem)));
} break;
case RECT2: {
memnew_placement(_data._mem, Rect2(*reinterpret_cast<const Rect2 *>(p_variant._data._mem)));
} break;
case RECT2I: {
memnew_placement(_data._mem, Rect2i(*reinterpret_cast<const Rect2i *>(p_variant._data._mem)));
} break;
case TRANSFORM2D: {
_data._transform2d = memnew(Transform2D(*p_variant._data._transform2d));
} break;
case VECTOR3: {
memnew_placement(_data._mem, Vector3(*reinterpret_cast<const Vector3 *>(p_variant._data._mem)));
} break;
case VECTOR3I: {
memnew_placement(_data._mem, Vector3i(*reinterpret_cast<const Vector3i *>(p_variant._data._mem)));
} break;
case PLANE: {
memnew_placement(_data._mem, Plane(*reinterpret_cast<const Plane *>(p_variant._data._mem)));
} break;
@ -961,10 +1163,18 @@ void Variant::reference(const Variant &p_variant) {
case POOL_VECTOR2_ARRAY: {
memnew_placement(_data._mem, PoolVector<Vector2>(*reinterpret_cast<const PoolVector<Vector2> *>(p_variant._data._mem)));
} break;
case POOL_VECTOR2I_ARRAY: {
memnew_placement(_data._mem, PoolVector<Vector2i>(*reinterpret_cast<const PoolVector<Vector2i> *>(p_variant._data._mem)));
} break;
case POOL_VECTOR3_ARRAY: {
memnew_placement(_data._mem, PoolVector<Vector3>(*reinterpret_cast<const PoolVector<Vector3> *>(p_variant._data._mem)));
} break;
case POOL_VECTOR3I_ARRAY: {
memnew_placement(_data._mem, PoolVector<Vector3i>(*reinterpret_cast<const PoolVector<Vector3i> *>(p_variant._data._mem)));
} break;
case POOL_COLOR_ARRAY: {
memnew_placement(_data._mem, PoolVector<Color>(*reinterpret_cast<const PoolVector<Color> *>(p_variant._data._mem)));
@ -991,12 +1201,21 @@ void Variant::zero() {
case VECTOR2:
*reinterpret_cast<Vector2 *>(this->_data._mem) = Vector2();
break;
case VECTOR2I:
*reinterpret_cast<Vector2i *>(this->_data._mem) = Vector2i();
break;
case RECT2:
*reinterpret_cast<Rect2 *>(this->_data._mem) = Rect2();
break;
case RECT2I:
*reinterpret_cast<Rect2i *>(this->_data._mem) = Rect2i();
break;
case VECTOR3:
*reinterpret_cast<Vector3 *>(this->_data._mem) = Vector3();
break;
case VECTOR3I:
*reinterpret_cast<Vector3i *>(this->_data._mem) = Vector3i();
break;
case PLANE:
*reinterpret_cast<Plane *>(this->_data._mem) = Plane();
break;
@ -1020,11 +1239,14 @@ void Variant::clear() {
/*
// no point, they don't allocate memory
VECTOR3,
VECTOR3i,
PLANE,
QUAT,
COLOR,
VECTOR2,
RECT2
VECTOR2I,
RECT2,
RECT2I
*/
case TRANSFORM2D: {
memdelete(_data._transform2d);
@ -1078,9 +1300,15 @@ void Variant::clear() {
case POOL_VECTOR2_ARRAY: {
reinterpret_cast<PoolVector<Vector2> *>(_data._mem)->~PoolVector<Vector2>();
} break;
case POOL_VECTOR2I_ARRAY: {
reinterpret_cast<PoolVector<Vector2i> *>(_data._mem)->~PoolVector<Vector2i>();
} break;
case POOL_VECTOR3_ARRAY: {
reinterpret_cast<PoolVector<Vector3> *>(_data._mem)->~PoolVector<Vector3>();
} break;
case POOL_VECTOR3I_ARRAY: {
reinterpret_cast<PoolVector<Vector3i> *>(_data._mem)->~PoolVector<Vector3i>();
} break;
case POOL_COLOR_ARRAY: {
reinterpret_cast<PoolVector<Color> *>(_data._mem)->~PoolVector<Color>();
} break;
@ -1381,14 +1609,20 @@ String Variant::stringify(List<const void *> &stack) const {
return *reinterpret_cast<const String *>(_data._mem);
case VECTOR2:
return "(" + operator Vector2() + ")";
case VECTOR2I:
return "(" + operator Vector2i() + ")";
case RECT2:
return "(" + operator Rect2() + ")";
case RECT2I:
return "(" + operator Rect2i() + ")";
case TRANSFORM2D: {
Transform2D mat32 = operator Transform2D();
return "(" + Variant(mat32.elements[0]).operator String() + ", " + Variant(mat32.elements[1]).operator String() + ", " + Variant(mat32.elements[2]).operator String() + ")";
} break;
case VECTOR3:
return "(" + operator Vector3() + ")";
case VECTOR3I:
return "(" + operator Vector3i() + ")";
case PLANE:
return operator Plane();
//case QUAT:
@ -1465,9 +1699,15 @@ String Variant::stringify(List<const void *> &stack) const {
case POOL_VECTOR2_ARRAY: {
return stringify_vector(operator PoolVector<Vector2>(), stack);
} break;
case POOL_VECTOR2I_ARRAY: {
return stringify_vector(operator PoolVector<Vector2i>(), stack);
} break;
case POOL_VECTOR3_ARRAY: {
return stringify_vector(operator PoolVector<Vector3>(), stack);
} break;
case POOL_VECTOR3I_ARRAY: {
return stringify_vector(operator PoolVector<Vector3i>(), stack);
} break;
case POOL_COLOR_ARRAY: {
return stringify_vector(operator PoolVector<Color>(), stack);
} break;
@ -1516,29 +1756,75 @@ String Variant::stringify(List<const void *> &stack) const {
Variant::operator Vector2() const {
if (type == VECTOR2) {
return *reinterpret_cast<const Vector2 *>(_data._mem);
} else if (type == VECTOR2I) {
return Vector2(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y);
} else if (type == VECTOR3) {
return Vector2(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
} else if (type == VECTOR3I) {
return Vector2(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
} else {
return Vector2();
}
}
Variant::operator Vector2i() const {
if (type == VECTOR2I) {
return *reinterpret_cast<const Vector2i *>(_data._mem);
} else if (type == VECTOR2) {
return Vector2i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y);
} else if (type == VECTOR3) {
return Vector2i(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y);
} else if (type == VECTOR3I) {
return Vector2i(reinterpret_cast<const Vector3i *>(_data._mem)->x, reinterpret_cast<const Vector3i *>(_data._mem)->y);
} else {
return Vector2i();
}
}
Variant::operator Rect2() const {
if (type == RECT2) {
return *reinterpret_cast<const Rect2 *>(_data._mem);
} else if (type == RECT2I) {
return Rect2(*reinterpret_cast<const Rect2i *>(_data._mem));
} else {
return Rect2();
}
}
Variant::operator Rect2i() const {
if (type == RECT2I) {
return *reinterpret_cast<const Rect2i *>(_data._mem);
} else if (type == RECT2) {
return Rect2i(*reinterpret_cast<const Rect2 *>(_data._mem));
} else {
return Rect2i();
}
}
Variant::operator Vector3() const {
if (type == VECTOR3) {
return *reinterpret_cast<const Vector3 *>(_data._mem);
} else if (type == VECTOR3I) {
return Vector3(*reinterpret_cast<const Vector3i *>(_data._mem));
} else if (type == VECTOR2) {
return Vector3(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
} else if (type == VECTOR2I) {
return Vector3(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
} else {
return Vector3();
}
}
Variant::operator Vector3i() const {
if (type == VECTOR3I) {
return *reinterpret_cast<const Vector3i *>(_data._mem);
} else if (type == VECTOR3) {
return Vector3i(reinterpret_cast<const Vector3 *>(_data._mem)->x, reinterpret_cast<const Vector3 *>(_data._mem)->y, reinterpret_cast<const Vector3 *>(_data._mem)->z);
} else if (type == VECTOR2) {
return Vector3i(reinterpret_cast<const Vector2 *>(_data._mem)->x, reinterpret_cast<const Vector2 *>(_data._mem)->y, 0.0);
} else if (type == VECTOR2I) {
return Vector3i(reinterpret_cast<const Vector2i *>(_data._mem)->x, reinterpret_cast<const Vector2i *>(_data._mem)->y, 0.0);
} else {
return Vector3i();
}
}
Variant::operator Plane() const {
if (type == PLANE) {
return *reinterpret_cast<const Plane *>(_data._mem);
@ -1740,9 +2026,15 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
case Variant::POOL_VECTOR2_ARRAY: {
return _convert_array<DA, PoolVector<Vector2>>(p_variant.operator PoolVector<Vector2>());
}
case Variant::POOL_VECTOR2I_ARRAY: {
return _convert_array<DA, PoolVector<Vector2i>>(p_variant.operator PoolVector<Vector2i>());
}
case Variant::POOL_VECTOR3_ARRAY: {
return _convert_array<DA, PoolVector<Vector3>>(p_variant.operator PoolVector<Vector3>());
}
case Variant::POOL_VECTOR3I_ARRAY: {
return _convert_array<DA, PoolVector<Vector3i>>(p_variant.operator PoolVector<Vector3i>());
}
case Variant::POOL_COLOR_ARRAY: {
return _convert_array<DA, PoolVector<Color>>(p_variant.operator PoolVector<Color>());
}
@ -1796,6 +2088,13 @@ Variant::operator PoolVector<Vector3>() const {
return _convert_array_from_variant<PoolVector<Vector3>>(*this);
}
}
Variant::operator PoolVector<Vector3i>() const {
if (type == POOL_VECTOR3I_ARRAY) {
return *reinterpret_cast<const PoolVector<Vector3i> *>(_data._mem);
} else {
return _convert_array_from_variant<PoolVector<Vector3i>>(*this);
}
}
Variant::operator PoolVector<Vector2>() const {
if (type == POOL_VECTOR2_ARRAY) {
return *reinterpret_cast<const PoolVector<Vector2> *>(_data._mem);
@ -1803,7 +2102,13 @@ Variant::operator PoolVector<Vector2>() const {
return _convert_array_from_variant<PoolVector<Vector2>>(*this);
}
}
Variant::operator PoolVector<Vector2i>() const {
if (type == POOL_VECTOR2I_ARRAY) {
return *reinterpret_cast<const PoolVector<Vector2i> *>(_data._mem);
} else {
return _convert_array_from_variant<PoolVector<Vector2i>>(*this);
}
}
Variant::operator PoolVector<Color>() const {
if (type == POOL_COLOR_ARRAY) {
return *reinterpret_cast<const PoolVector<Color> *>(_data._mem);
@ -1824,22 +2129,6 @@ Variant::operator Vector<RID>() const {
return rids;
}
Variant::operator Vector<Vector2>() const {
PoolVector<Vector2> from = operator PoolVector<Vector2>();
Vector<Vector2> to;
int len = from.size();
if (len == 0) {
return Vector<Vector2>();
}
to.resize(len);
PoolVector<Vector2>::Read r = from.read();
Vector2 *w = to.ptrw();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
return to;
}
Variant::operator PoolVector<Plane>() const {
Array va = operator Array();
PoolVector<Plane> planes;
@ -1957,6 +2246,37 @@ Variant::operator Vector<StringName>() const {
return to;
}
Variant::operator Vector<Vector2>() const {
PoolVector<Vector2> from = operator PoolVector<Vector2>();
Vector<Vector2> to;
int len = from.size();
if (len == 0) {
return Vector<Vector2>();
}
to.resize(len);
PoolVector<Vector2>::Read r = from.read();
Vector2 *w = to.ptrw();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
return to;
}
Variant::operator Vector<Vector2i>() const {
PoolVector<Vector2i> from = operator PoolVector<Vector2i>();
Vector<Vector2i> to;
int len = from.size();
if (len == 0) {
return Vector<Vector2i>();
}
to.resize(len);
PoolVector<Vector2i>::Read r = from.read();
Vector2i *w = to.ptrw();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
return to;
}
Variant::operator Vector<Vector3>() const {
PoolVector<Vector3> from = operator PoolVector<Vector3>();
Vector<Vector3> to;
@ -1972,6 +2292,21 @@ Variant::operator Vector<Vector3>() const {
}
return to;
}
Variant::operator Vector<Vector3i>() const {
PoolVector<Vector3i> from = operator PoolVector<Vector3i>();
Vector<Vector3i> to;
int len = from.size();
if (len == 0) {
return Vector<Vector3i>();
}
to.resize(len);
PoolVector<Vector3i>::Read r = from.read();
Vector3i *w = to.ptrw();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
return to;
}
Variant::operator Vector<Color>() const {
PoolVector<Color> from = operator PoolVector<Color>();
Vector<Color> to;
@ -2097,14 +2432,26 @@ Variant::Variant(const Vector3 &p_vector3) {
type = VECTOR3;
memnew_placement(_data._mem, Vector3(p_vector3));
}
Variant::Variant(const Vector3i &p_vector3) {
type = VECTOR3I;
memnew_placement(_data._mem, Vector3i(p_vector3));
}
Variant::Variant(const Vector2 &p_vector2) {
type = VECTOR2;
memnew_placement(_data._mem, Vector2(p_vector2));
}
Variant::Variant(const Vector2i &p_vector2) {
type = VECTOR2I;
memnew_placement(_data._mem, Vector2i(p_vector2));
}
Variant::Variant(const Rect2 &p_rect2) {
type = RECT2;
memnew_placement(_data._mem, Rect2(p_rect2));
}
Variant::Variant(const Rect2i &p_rect2) {
type = RECT2I;
memnew_placement(_data._mem, Rect2i(p_rect2));
}
Variant::Variant(const Plane &p_plane) {
type = PLANE;
@ -2215,22 +2562,6 @@ Variant::Variant(const Vector<RID> &p_array) {
}
}
Variant::Variant(const Vector<Vector2> &p_array) {
type = NIL;
PoolVector<Vector2> v;
int len = p_array.size();
if (len > 0) {
v.resize(len);
PoolVector<Vector2>::Write w = v.write();
const Vector2 *r = p_array.ptr();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
}
*this = v;
}
Variant::Variant(const PoolVector<uint8_t> &p_raw_array) {
type = POOL_BYTE_ARRAY;
memnew_placement(_data._mem, PoolVector<uint8_t>(p_raw_array));
@ -2247,15 +2578,23 @@ Variant::Variant(const PoolVector<String> &p_string_array) {
type = POOL_STRING_ARRAY;
memnew_placement(_data._mem, PoolVector<String>(p_string_array));
}
Variant::Variant(const PoolVector<Vector3> &p_vector3_array) {
type = POOL_VECTOR3_ARRAY;
memnew_placement(_data._mem, PoolVector<Vector3>(p_vector3_array));
}
Variant::Variant(const PoolVector<Vector2> &p_vector2_array) {
type = POOL_VECTOR2_ARRAY;
memnew_placement(_data._mem, PoolVector<Vector2>(p_vector2_array));
}
Variant::Variant(const PoolVector<Vector2i> &p_vector2_array) {
type = POOL_VECTOR2I_ARRAY;
memnew_placement(_data._mem, PoolVector<Vector2i>(p_vector2_array));
}
Variant::Variant(const PoolVector<Vector3> &p_vector3_array) {
type = POOL_VECTOR3_ARRAY;
memnew_placement(_data._mem, PoolVector<Vector3>(p_vector3_array));
}
Variant::Variant(const PoolVector<Vector3i> &p_vector3_array) {
type = POOL_VECTOR3I_ARRAY;
memnew_placement(_data._mem, PoolVector<Vector3i>(p_vector3_array));
}
Variant::Variant(const PoolVector<Color> &p_color_array) {
type = POOL_COLOR_ARRAY;
memnew_placement(_data._mem, PoolVector<Color>(p_color_array));
@ -2350,6 +2689,37 @@ Variant::Variant(const Vector<StringName> &p_array) {
*this = v;
}
Variant::Variant(const Vector<Vector2> &p_array) {
type = NIL;
PoolVector<Vector2> v;
int len = p_array.size();
if (len > 0) {
v.resize(len);
PoolVector<Vector2>::Write w = v.write();
const Vector2 *r = p_array.ptr();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
}
*this = v;
}
Variant::Variant(const Vector<Vector2i> &p_array) {
type = NIL;
PoolVector<Vector2i> v;
int len = p_array.size();
if (len > 0) {
v.resize(len);
PoolVector<Vector2i>::Write w = v.write();
const Vector2i *r = p_array.ptr();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
}
*this = v;
}
Variant::Variant(const Vector<Vector3> &p_array) {
type = NIL;
PoolVector<Vector3> v;
@ -2365,6 +2735,21 @@ Variant::Variant(const Vector<Vector3> &p_array) {
}
*this = v;
}
Variant::Variant(const Vector<Vector3i> &p_array) {
type = NIL;
PoolVector<Vector3i> v;
int len = p_array.size();
if (len > 0) {
v.resize(len);
PoolVector<Vector3i>::Write w = v.write();
const Vector3i *r = p_array.ptr();
for (int i = 0; i < len; i++) {
w[i] = r[i];
}
}
*this = v;
}
Variant::Variant(const Vector<Color> &p_array) {
type = NIL;
@ -2410,15 +2795,24 @@ void Variant::operator=(const Variant &p_variant) {
case VECTOR2: {
*reinterpret_cast<Vector2 *>(_data._mem) = *reinterpret_cast<const Vector2 *>(p_variant._data._mem);
} break;
case VECTOR2I: {
*reinterpret_cast<Vector2i *>(_data._mem) = *reinterpret_cast<const Vector2i *>(p_variant._data._mem);
} break;
case RECT2: {
*reinterpret_cast<Rect2 *>(_data._mem) = *reinterpret_cast<const Rect2 *>(p_variant._data._mem);
} break;
case RECT2I: {
*reinterpret_cast<Rect2i *>(_data._mem) = *reinterpret_cast<const Rect2i *>(p_variant._data._mem);
} break;
case TRANSFORM2D: {
*_data._transform2d = *(p_variant._data._transform2d);
} break;
case VECTOR3: {
*reinterpret_cast<Vector3 *>(_data._mem) = *reinterpret_cast<const Vector3 *>(p_variant._data._mem);
} break;
case VECTOR3I: {
*reinterpret_cast<Vector3i *>(_data._mem) = *reinterpret_cast<const Vector3i *>(p_variant._data._mem);
} break;
case PLANE: {
*reinterpret_cast<Plane *>(_data._mem) = *reinterpret_cast<const Plane *>(p_variant._data._mem);
} break;
@ -2480,9 +2874,15 @@ void Variant::operator=(const Variant &p_variant) {
case POOL_VECTOR2_ARRAY: {
*reinterpret_cast<PoolVector<Vector2> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector2> *>(p_variant._data._mem);
} break;
case POOL_VECTOR2I_ARRAY: {
*reinterpret_cast<PoolVector<Vector2i> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector2i> *>(p_variant._data._mem);
} break;
case POOL_VECTOR3_ARRAY: {
*reinterpret_cast<PoolVector<Vector3> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector3> *>(p_variant._data._mem);
} break;
case POOL_VECTOR3I_ARRAY: {
*reinterpret_cast<PoolVector<Vector3i> *>(_data._mem) = *reinterpret_cast<const PoolVector<Vector3i> *>(p_variant._data._mem);
} break;
case POOL_COLOR_ARRAY: {
*reinterpret_cast<PoolVector<Color> *>(_data._mem) = *reinterpret_cast<const PoolVector<Color> *>(p_variant._data._mem);
} break;
@ -2530,12 +2930,22 @@ uint32_t Variant::hash() const {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->x);
return hash_djb2_one_float(reinterpret_cast<const Vector2 *>(_data._mem)->y, hash);
} break;
case VECTOR2I: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector2i *>(_data._mem)->x);
return hash_djb2_one_float(reinterpret_cast<const Vector2i *>(_data._mem)->y, hash);
} break;
case RECT2: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.x);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.x, hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2 *>(_data._mem)->size.y, hash);
} break;
case RECT2I: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Rect2i *>(_data._mem)->position.x);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2i *>(_data._mem)->position.y, hash);
hash = hash_djb2_one_float(reinterpret_cast<const Rect2i *>(_data._mem)->size.x, hash);
return hash_djb2_one_float(reinterpret_cast<const Rect2i *>(_data._mem)->size.y, hash);
} break;
case TRANSFORM2D: {
uint32_t hash = 5831;
for (int i = 0; i < 3; i++) {
@ -2551,6 +2961,11 @@ uint32_t Variant::hash() const {
hash = hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->y, hash);
return hash_djb2_one_float(reinterpret_cast<const Vector3 *>(_data._mem)->z, hash);
} break;
case VECTOR3I: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Vector3i *>(_data._mem)->x);
hash = hash_djb2_one_float(reinterpret_cast<const Vector3i *>(_data._mem)->y, hash);
return hash_djb2_one_float(reinterpret_cast<const Vector3i *>(_data._mem)->z, hash);
} break;
case PLANE: {
uint32_t hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.x);
hash = hash_djb2_one_float(reinterpret_cast<const Plane *>(_data._mem)->normal.y, hash);
@ -2695,6 +3110,22 @@ uint32_t Variant::hash() const {
return hash;
} break;
case POOL_VECTOR2I_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Vector2i> &arr = *reinterpret_cast<const PoolVector<Vector2i> *>(_data._mem);
int len = arr.size();
if (likely(len)) {
PoolVector<Vector2i>::Read r = arr.read();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_float(r[i].x, hash);
hash = hash_djb2_one_float(r[i].y, hash);
}
}
return hash;
} break;
case POOL_VECTOR3_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Vector3> &arr = *reinterpret_cast<const PoolVector<Vector3> *>(_data._mem);
@ -2712,6 +3143,23 @@ uint32_t Variant::hash() const {
return hash;
} break;
case POOL_VECTOR3I_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Vector3i> &arr = *reinterpret_cast<const PoolVector<Vector3i> *>(_data._mem);
int len = arr.size();
if (likely(len)) {
PoolVector<Vector3i>::Read r = arr.read();
for (int i = 0; i < len; i++) {
hash = hash_djb2_one_float(r[i].x, hash);
hash = hash_djb2_one_float(r[i].y, hash);
hash = hash_djb2_one_float(r[i].z, hash);
}
}
return hash;
} break;
case POOL_COLOR_ARRAY: {
uint32_t hash = 5831;
const PoolVector<Color> &arr = *reinterpret_cast<const PoolVector<Color> *>(_data._mem);
@ -2744,11 +3192,20 @@ uint32_t Variant::hash() const {
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
(hash_compare_scalar((p_lhs).y, (p_rhs).y))
#define hash_compare_vector2i(p_lhs, p_rhs) \
(((p_lhs).x == (p_rhs).x)) && \
(((p_lhs).y == (p_rhs).y))
#define hash_compare_vector3(p_lhs, p_rhs) \
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
(hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
(hash_compare_scalar((p_lhs).z, (p_rhs).z))
#define hash_compare_vector3i(p_lhs, p_rhs) \
(((p_lhs).x == (p_rhs).x)) && \
(((p_lhs).y == (p_rhs).y)) && \
(((p_lhs).z == (p_rhs).z))
#define hash_compare_quat(p_lhs, p_rhs) \
(hash_compare_scalar((p_lhs).x, (p_rhs).x)) && \
(hash_compare_scalar((p_lhs).y, (p_rhs).y)) && \
@ -2803,6 +3260,13 @@ bool Variant::hash_compare(const Variant &p_variant) const {
return hash_compare_vector2(*l, *r);
} break;
case VECTOR2I: {
const Vector2i *l = reinterpret_cast<const Vector2i *>(_data._mem);
const Vector2i *r = reinterpret_cast<const Vector2i *>(p_variant._data._mem);
return hash_compare_vector2i(*l, *r);
} break;
case RECT2: {
const Rect2 *l = reinterpret_cast<const Rect2 *>(_data._mem);
const Rect2 *r = reinterpret_cast<const Rect2 *>(p_variant._data._mem);
@ -2811,6 +3275,14 @@ bool Variant::hash_compare(const Variant &p_variant) const {
(hash_compare_vector2(l->size, r->size));
} break;
case RECT2I: {
const Rect2i *l = reinterpret_cast<const Rect2i *>(_data._mem);
const Rect2i *r = reinterpret_cast<const Rect2i *>(p_variant._data._mem);
return (hash_compare_vector2i(l->position, r->position)) &&
(hash_compare_vector2i(l->size, r->size));
} break;
case TRANSFORM2D: {
Transform2D *l = _data._transform2d;
Transform2D *r = p_variant._data._transform2d;
@ -2831,6 +3303,13 @@ bool Variant::hash_compare(const Variant &p_variant) const {
return hash_compare_vector3(*l, *r);
} break;
case VECTOR3I: {
const Vector3i *l = reinterpret_cast<const Vector3i *>(_data._mem);
const Vector3i *r = reinterpret_cast<const Vector3i *>(p_variant._data._mem);
return hash_compare_vector3i(*l, *r);
} break;
case PLANE: {
const Plane *l = reinterpret_cast<const Plane *>(_data._mem);
const Plane *r = reinterpret_cast<const Plane *>(p_variant._data._mem);
@ -2913,10 +3392,18 @@ bool Variant::hash_compare(const Variant &p_variant) const {
hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2, hash_compare_vector2);
} break;
case POOL_VECTOR2I_ARRAY: {
hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector2i, hash_compare_vector2i);
} break;
case POOL_VECTOR3_ARRAY: {
hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3, hash_compare_vector3);
} break;
case POOL_VECTOR3I_ARRAY: {
hash_compare_pool_array(_data._mem, p_variant._data._mem, Vector3i, hash_compare_vector3i);
} break;
case POOL_COLOR_ARRAY: {
hash_compare_pool_array(_data._mem, p_variant._data._mem, Color, hash_compare_color);
} break;

View File

@ -42,6 +42,7 @@
#include "core/math/transform.h"
#include "core/math/transform_2d.h"
#include "core/math/vector3.h"
#include "core/math/vector3i.h"
#include "core/node_path.h"
#include "core/object_id.h"
#include "core/pool_vector.h"
@ -62,7 +63,9 @@ typedef PoolVector<int> PoolIntArray;
typedef PoolVector<real_t> PoolRealArray;
typedef PoolVector<String> PoolStringArray;
typedef PoolVector<Vector2> PoolVector2Array;
typedef PoolVector<Vector2i> PoolVector2iArray;
typedef PoolVector<Vector3> PoolVector3Array;
typedef PoolVector<Vector3i> PoolVector3iArray;
typedef PoolVector<Color> PoolColorArray;
// Temporary workaround until c++11 alignas()
@ -95,33 +98,38 @@ public:
// math types
VECTOR2, // 5
VECTOR2I,
RECT2,
RECT2I,
VECTOR3,
VECTOR3I, //10
TRANSFORM2D,
PLANE,
QUAT, // 10
QUAT,
AABB,
BASIS,
BASIS, //15
TRANSFORM,
// misc types
COLOR,
NODE_PATH, // 15
NODE_PATH,
_RID,
OBJECT,
OBJECT, //20
DICTIONARY,
ARRAY,
// arrays
POOL_BYTE_ARRAY, // 20
POOL_BYTE_ARRAY,
POOL_INT_ARRAY,
POOL_REAL_ARRAY,
POOL_REAL_ARRAY, //25
POOL_STRING_ARRAY,
POOL_VECTOR2_ARRAY,
POOL_VECTOR3_ARRAY, // 25
POOL_VECTOR2I_ARRAY,
POOL_VECTOR3_ARRAY,
POOL_VECTOR3I_ARRAY, //30
POOL_COLOR_ARRAY,
VARIANT_MAX
VARIANT_MAX // 32
};
@ -201,8 +209,11 @@ public:
operator String() const;
operator StringName() const;
operator Vector2() const;
operator Vector2i() const;
operator Rect2() const;
operator Rect2i() const;
operator Vector3() const;
operator Vector3i() const;
operator Plane() const;
operator ::AABB() const;
operator Quat() const;
@ -226,7 +237,10 @@ public:
operator PoolVector<int>() const;
operator PoolVector<real_t>() const;
operator PoolVector<String>() const;
operator PoolVector<Vector2>() const;
operator PoolVector<Vector2i>() const;
operator PoolVector<Vector3>() const;
operator PoolVector<Vector3i>() const;
operator PoolVector<Color>() const;
operator PoolVector<Plane>() const;
operator PoolVector<Face3>() const;
@ -238,10 +252,12 @@ public:
operator Vector<String>() const;
operator Vector<StringName>() const;
operator Vector<Vector3>() const;
operator Vector<Vector3i>() const;
operator Vector<Color>() const;
operator Vector<RID>() const;
operator Vector<Vector2>() const;
operator PoolVector<Vector2>() const;
operator Vector<Vector2i>() const;
operator Vector<Plane>() const;
// some core type enums to convert to
@ -271,8 +287,11 @@ public:
Variant(const char *const p_cstring);
Variant(const CharType *p_wstring);
Variant(const Vector2 &p_vector2);
Variant(const Vector2i &p_vector2);
Variant(const Rect2 &p_rect2);
Variant(const Rect2i &p_rect2);
Variant(const Vector3 &p_vector3);
Variant(const Vector3i &p_vector3);
Variant(const Plane &p_plane);
Variant(const ::AABB &p_aabb);
Variant(const Quat &p_quat);
@ -293,8 +312,11 @@ public:
Variant(const PoolVector<real_t> &p_real_array);
Variant(const PoolVector<String> &p_string_array);
Variant(const PoolVector<Vector3> &p_vector3_array);
Variant(const PoolVector<Vector3i> &p_vector3_array);
Variant(const PoolVector<Color> &p_color_array);
Variant(const PoolVector<Face3> &p_face_array);
Variant(const PoolVector<Vector2> &p_vector2_array); // helper
Variant(const PoolVector<Vector2i> &p_vector2_array); // helper
Variant(const Vector<Variant> &p_array);
Variant(const Vector<uint8_t> &p_array);
@ -303,11 +325,12 @@ public:
Variant(const Vector<String> &p_array);
Variant(const Vector<StringName> &p_array);
Variant(const Vector<Vector3> &p_array);
Variant(const Vector<Vector3i> &p_array);
Variant(const Vector<Color> &p_array);
Variant(const Vector<Plane> &p_array); // helper
Variant(const Vector<RID> &p_array); // helper
Variant(const Vector<Vector2> &p_array); // helper
Variant(const PoolVector<Vector2> &p_vector2_array); // helper
Variant(const Vector<Vector2i> &p_array); // helper
Variant(const IP_Address &p_address);

View File

@ -413,6 +413,8 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector2, limit_length);
VCALL_LOCALMEM0R(Vector2, sign);
VCALL_LOCALMEM2R(Vector2i, linear_interpolate);
VCALL_LOCALMEM0R(Rect2, get_area);
VCALL_LOCALMEM0R(Rect2, get_center);
VCALL_LOCALMEM0R(Rect2, has_no_area);
@ -428,6 +430,19 @@ struct _VariantCall {
VCALL_LOCALMEM4R(Rect2, grow_individual);
VCALL_LOCALMEM0R(Rect2, abs);
VCALL_LOCALMEM0R(Rect2i, get_area);
VCALL_LOCALMEM0R(Rect2i, get_center);
VCALL_LOCALMEM0R(Rect2i, has_no_area);
VCALL_LOCALMEM1R(Rect2i, has_point);
VCALL_LOCALMEM1R(Rect2i, intersects);
VCALL_LOCALMEM1R(Rect2i, encloses);
VCALL_LOCALMEM1R(Rect2i, clip);
VCALL_LOCALMEM1R(Rect2i, merge);
VCALL_LOCALMEM1R(Rect2i, expand);
VCALL_LOCALMEM1R(Rect2i, grow);
VCALL_LOCALMEM2R(Rect2i, grow_margin);
VCALL_LOCALMEM4R(Rect2i, grow_individual);
VCALL_LOCALMEM0R(Vector3, min_axis);
VCALL_LOCALMEM0R(Vector3, max_axis);
VCALL_LOCALMEM1R(Vector3, distance_to);
@ -464,6 +479,14 @@ struct _VariantCall {
VCALL_LOCALMEM1R(Vector3, limit_length);
VCALL_LOCALMEM0R(Vector3, sign);
VCALL_LOCALMEM0R(Vector3i, min_axis_index);
VCALL_LOCALMEM0R(Vector3i, max_axis_index);
VCALL_LOCALMEM0R(Vector3i, length);
VCALL_LOCALMEM0R(Vector3i, length_squared);
VCALL_LOCALMEM2R(Vector3i, linear_interpolate);
VCALL_LOCALMEM0R(Vector3i, abs);
VCALL_LOCALMEM0R(Vector3i, sign);
VCALL_LOCALMEM0R(Plane, normalized);
VCALL_LOCALMEM0R(Plane, center);
VCALL_LOCALMEM0R(Plane, get_any_point);
@ -749,6 +772,18 @@ struct _VariantCall {
VCALL_LOCALMEM1(PoolVector2Array, append_array);
VCALL_LOCALMEM0(PoolVector2Array, invert);
VCALL_LOCALMEM0R(PoolVector2iArray, size);
VCALL_LOCALMEM0R(PoolVector2iArray, empty);
VCALL_LOCALMEM2(PoolVector2iArray, set);
VCALL_LOCALMEM1R(PoolVector2iArray, get);
VCALL_LOCALMEM1(PoolVector2iArray, push_back);
VCALL_LOCALMEM1(PoolVector2iArray, resize);
VCALL_LOCALMEM2R(PoolVector2iArray, insert);
VCALL_LOCALMEM1(PoolVector2iArray, remove);
VCALL_LOCALMEM1(PoolVector2iArray, append);
VCALL_LOCALMEM1(PoolVector2iArray, append_array);
VCALL_LOCALMEM0(PoolVector2iArray, invert);
VCALL_LOCALMEM0R(PoolVector3Array, size);
VCALL_LOCALMEM0R(PoolVector3Array, empty);
VCALL_LOCALMEM2(PoolVector3Array, set);
@ -761,6 +796,18 @@ struct _VariantCall {
VCALL_LOCALMEM1(PoolVector3Array, append_array);
VCALL_LOCALMEM0(PoolVector3Array, invert);
VCALL_LOCALMEM0R(PoolVector3iArray, size);
VCALL_LOCALMEM0R(PoolVector3iArray, empty);
VCALL_LOCALMEM2(PoolVector3iArray, set);
VCALL_LOCALMEM1R(PoolVector3iArray, get);
VCALL_LOCALMEM1(PoolVector3iArray, push_back);
VCALL_LOCALMEM1(PoolVector3iArray, resize);
VCALL_LOCALMEM2R(PoolVector3iArray, insert);
VCALL_LOCALMEM1(PoolVector3iArray, remove);
VCALL_LOCALMEM1(PoolVector3iArray, append);
VCALL_LOCALMEM1(PoolVector3iArray, append_array);
VCALL_LOCALMEM0(PoolVector3iArray, invert);
VCALL_LOCALMEM0R(PoolColorArray, size);
VCALL_LOCALMEM0R(PoolColorArray, empty);
VCALL_LOCALMEM2(PoolColorArray, set);
@ -839,12 +886,21 @@ struct _VariantCall {
case Variant::VECTOR2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2());
return;
case Variant::VECTOR2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Vector2i());
return;
case Variant::RECT2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2());
return;
case Variant::RECT2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator Rect2i());
return;
case Variant::POOL_VECTOR2_ARRAY:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator PoolVector2Array());
return;
case Variant::POOL_VECTOR2I_ARRAY:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform(p_args[0]->operator PoolVector2iArray());
return;
default:
r_ret = Variant();
}
@ -855,12 +911,21 @@ struct _VariantCall {
case Variant::VECTOR2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2());
return;
case Variant::VECTOR2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector2i());
return;
case Variant::RECT2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2());
return;
case Variant::RECT2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Rect2i());
return;
case Variant::POOL_VECTOR2_ARRAY:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator PoolVector2Array());
return;
case Variant::POOL_VECTOR2I_ARRAY:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->xform_inv(p_args[0]->operator PoolVector2iArray());
return;
default:
r_ret = Variant();
}
@ -871,6 +936,9 @@ struct _VariantCall {
case Variant::VECTOR2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2());
return;
case Variant::VECTOR2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform(p_args[0]->operator Vector2i());
return;
default:
r_ret = Variant();
}
@ -881,6 +949,9 @@ struct _VariantCall {
case Variant::VECTOR2:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2());
return;
case Variant::VECTOR2I:
r_ret = reinterpret_cast<Transform2D *>(p_self._data._ptr)->basis_xform_inv(p_args[0]->operator Vector2i());
return;
default:
r_ret = Variant();
}
@ -908,14 +979,38 @@ struct _VariantCall {
VCALL_PTR1R(Basis, tdotx);
VCALL_PTR1R(Basis, tdoty);
VCALL_PTR1R(Basis, tdotz);
VCALL_PTR1R(Basis, xform);
VCALL_PTR1R(Basis, xform_inv);
VCALL_PTR0R(Basis, get_orthogonal_index);
VCALL_PTR0R(Basis, orthonormalized);
VCALL_PTR2R(Basis, slerp);
VCALL_PTR2R(Basis, is_equal_approx);
VCALL_PTR0R(Basis, get_rotation_quat);
static void _call_Basis_xform(Variant &r_ret, Variant &p_self, const Variant **p_args) {
switch (p_args[0]->type) {
case Variant::VECTOR3:
r_ret = reinterpret_cast<Basis *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3());
return;
case Variant::VECTOR3I:
r_ret = reinterpret_cast<Basis *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3i());
return;
default:
r_ret = Variant();
}
}
static void _call_Basis_xform_inv(Variant &r_ret, Variant &p_self, const Variant **p_args) {
switch (p_args[0]->type) {
case Variant::VECTOR3:
r_ret = reinterpret_cast<Basis *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3());
return;
case Variant::VECTOR3I:
r_ret = reinterpret_cast<Basis *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3i());
return;
default:
r_ret = Variant();
}
}
VCALL_PTR0R(Transform, inverse);
VCALL_PTR0R(Transform, affine_inverse);
VCALL_PTR2R(Transform, rotated);
@ -931,6 +1026,9 @@ struct _VariantCall {
case Variant::VECTOR3:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3());
return;
case Variant::VECTOR3I:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Vector3i());
return;
case Variant::PLANE:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator Plane());
return;
@ -940,6 +1038,9 @@ struct _VariantCall {
case Variant::POOL_VECTOR3_ARRAY:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::PoolVector3Array());
return;
case Variant::POOL_VECTOR3I_ARRAY:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform(p_args[0]->operator ::PoolVector3iArray());
return;
default:
r_ret = Variant();
}
@ -950,6 +1051,9 @@ struct _VariantCall {
case Variant::VECTOR3:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3());
return;
case Variant::VECTOR3I:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Vector3i());
return;
case Variant::PLANE:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator Plane());
return;
@ -959,6 +1063,9 @@ struct _VariantCall {
case Variant::POOL_VECTOR3_ARRAY:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::PoolVector3Array());
return;
case Variant::POOL_VECTOR3I_ARRAY:
r_ret = reinterpret_cast<Transform *>(p_self._data._ptr)->xform_inv(p_args[0]->operator ::PoolVector3iArray());
return;
default:
r_ret = Variant();
}
@ -989,6 +1096,10 @@ struct _VariantCall {
r_ret = Vector2(*p_args[0], *p_args[1]);
}
static void Vector2i_init1(Variant &r_ret, const Variant **p_args) {
r_ret = Vector2i(*p_args[0], *p_args[1]);
}
static void Rect2_init1(Variant &r_ret, const Variant **p_args) {
r_ret = Rect2(*p_args[0], *p_args[1]);
}
@ -997,6 +1108,14 @@ struct _VariantCall {
r_ret = Rect2(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Rect2i_init1(Variant &r_ret, const Variant **p_args) {
r_ret = Rect2i(*p_args[0], *p_args[1]);
}
static void Rect2i_init2(Variant &r_ret, const Variant **p_args) {
r_ret = Rect2i(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
static void Transform2D_init2(Variant &r_ret, const Variant **p_args) {
Transform2D m(*p_args[0], *p_args[1]);
r_ret = m;
@ -1014,6 +1133,10 @@ struct _VariantCall {
r_ret = Vector3(*p_args[0], *p_args[1], *p_args[2]);
}
static void Vector3i_init1(Variant &r_ret, const Variant **p_args) {
r_ret = Vector3i(*p_args[0], *p_args[1], *p_args[2]);
}
static void Plane_init1(Variant &r_ret, const Variant **p_args) {
r_ret = Plane(*p_args[0], *p_args[1], *p_args[2], *p_args[3]);
}
@ -1231,10 +1354,16 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
// math types
case VECTOR2:
return Vector2(); // 5
case VECTOR2I:
return Vector2i();
case RECT2:
return Rect2();
case RECT2I:
return Rect2i();
case VECTOR3:
return Vector3();
case VECTOR3I:
return Vector3i();
case TRANSFORM2D:
return Transform2D();
case PLANE:
@ -1270,9 +1399,13 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
case POOL_STRING_ARRAY:
return PoolStringArray();
case POOL_VECTOR2_ARRAY:
return PoolVector2Array(); // 25
return PoolVector2Array();
case POOL_VECTOR2I_ARRAY:
return PoolVector2iArray();
case POOL_VECTOR3_ARRAY:
return PoolVector3Array();
case POOL_VECTOR3I_ARRAY:
return PoolVector3iArray();
case POOL_COLOR_ARRAY:
return PoolColorArray();
default:
@ -1303,10 +1436,19 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
case VECTOR2: {
return Vector2(*p_args[0]);
}
case VECTOR2I: {
//TODO Don't cast like this
return Vector2i(Vector2(*p_args[0]));
}
case RECT2:
return (Rect2(*p_args[0]));
case RECT2I:
//TODO Don't cast like this
return (Rect2i(Rect2(*p_args[0])));
case VECTOR3:
return (Vector3(*p_args[0]));
case VECTOR3I:
return (Vector3i(*p_args[0]));
case TRANSFORM2D:
return (Transform2D(p_args[0]->operator Transform2D()));
case PLANE:
@ -1344,9 +1486,13 @@ Variant Variant::construct(const Variant::Type p_type, const Variant **p_args, i
case POOL_STRING_ARRAY:
return (PoolStringArray(*p_args[0]));
case POOL_VECTOR2_ARRAY:
return (PoolVector2Array(*p_args[0])); // 25
return (PoolVector2Array(*p_args[0]));
case POOL_VECTOR2I_ARRAY:
return (PoolVector2iArray(*p_args[0]));
case POOL_VECTOR3_ARRAY:
return (PoolVector3Array(*p_args[0]));
case POOL_VECTOR3I_ARRAY:
return (PoolVector3iArray(*p_args[0]));
case POOL_COLOR_ARRAY:
return (PoolColorArray(*p_args[0]));
default:
@ -1772,6 +1918,8 @@ void register_variant_methods() {
ADDFUNC1R(VECTOR2, VECTOR2, Vector2, limit_length, REAL, "length", varray(1.0));
ADDFUNC0R(VECTOR2, VECTOR2, Vector2, sign, varray());
ADDFUNC2R(VECTOR2I, VECTOR2I, Vector2i, linear_interpolate, VECTOR2, "to", REAL, "weight", varray());
ADDFUNC0R(RECT2, REAL, Rect2, get_area, varray());
ADDFUNC0R(RECT2, VECTOR2, Rect2, get_center, varray());
ADDFUNC0R(RECT2, BOOL, Rect2, has_no_area, varray());
@ -1787,6 +1935,35 @@ void register_variant_methods() {
ADDFUNC4R(RECT2, RECT2, Rect2, grow_individual, REAL, "left", REAL, "top", REAL, "right", REAL, " bottom", varray());
ADDFUNC0R(RECT2, RECT2, Rect2, abs, varray());
ADDFUNC0R(RECT2I, INT, Rect2i, get_area, varray());
ADDFUNC0R(RECT2I, VECTOR2I, Rect2i, get_center, varray());
ADDFUNC0R(RECT2I, BOOL, Rect2i, has_no_area, varray());
ADDFUNC1R(RECT2I, BOOL, Rect2i, has_point, VECTOR2, "point", varray());
ADDFUNC1R(RECT2I, BOOL, Rect2i, intersects, RECT2I, "b", varray());
ADDFUNC1R(RECT2I, BOOL, Rect2i, encloses, RECT2I, "b", varray());
ADDFUNC1R(RECT2I, RECT2I, Rect2i, clip, RECT2I, "b", varray());
ADDFUNC1R(RECT2I, RECT2I, Rect2i, merge, RECT2I, "b", varray());
ADDFUNC1R(RECT2I, RECT2I, Rect2i, expand, VECTOR2I, "to", varray());
ADDFUNC1R(RECT2I, RECT2I, Rect2i, grow, INT, "by", varray());
ADDFUNC2R(RECT2I, RECT2I, Rect2i, grow_margin, INT, "margin", INT, "by", varray());
ADDFUNC4R(RECT2I, RECT2I, Rect2i, grow_individual, INT, "left", INT, "top", INT, "right", INT, " bottom", varray());
/*
int get_area() const;
_FORCE_INLINE_ Vector2i get_center() const;
_FORCE_INLINE_ bool has_no_area() const;
bool has_point(const Point2 &p_point) const;
inline bool intersects(const Rect2i &p_rect) const;
inline bool encloses(const Rect2i &p_rect) const;
inline Rect2i clip(const Rect2i &p_rect) const;
inline Rect2i merge(const Rect2i &p_rect) const;
_FORCE_INLINE_ Rect2i expand(const Vector2i &p_vector) const;
inline void expand_to(const Point2i &p_vector);
Rect2i grow(int p_by) const;
inline Rect2i grow_margin(Margin p_margin, int p_amount) const;
inline Rect2i grow_individual(int p_left, int p_top, int p_right, int p_bottom) const;
*/
ADDFUNC0R(VECTOR3, INT, Vector3, min_axis, varray());
ADDFUNC0R(VECTOR3, INT, Vector3, max_axis, varray());
ADDFUNC1R(VECTOR3, REAL, Vector3, angle_to, VECTOR3, "to", varray());
@ -1823,6 +2000,25 @@ void register_variant_methods() {
ADDFUNC1R(VECTOR3, VECTOR3, Vector3, limit_length, REAL, "length", varray(1.0));
ADDFUNC0R(VECTOR3, VECTOR3, Vector3, sign, varray());
ADDFUNC0R(VECTOR3I, INT, Vector3i, min_axis_index, varray());
ADDFUNC0R(VECTOR3I, INT, Vector3i, max_axis_index, varray());
ADDFUNC0R(VECTOR3I, REAL, Vector3, length, varray());
ADDFUNC0R(VECTOR3I, REAL, Vector3, length_squared, varray());
ADDFUNC2R(VECTOR3I, VECTOR3I, Vector3, linear_interpolate, VECTOR3I, "to", REAL, "weight", varray());
/*
Vector3i::Axis min_axis_index() const;
Vector3i::Axis max_axis_index() const;
_FORCE_INLINE_ int64_t length_squared() const;
_FORCE_INLINE_ double length() const;
//_FORCE_INLINE_ void zero();
_FORCE_INLINE_ Vector3i abs() const;
_FORCE_INLINE_ Vector3i sign() const;
Vector3i clamp(const Vector3i &p_min, const Vector3i &p_max) const;
_FORCE_INLINE_ Vector3i linear_interpolate(const Vector3i &p_to, real_t p_weight) const;
*/
ADDFUNC0R(PLANE, PLANE, Plane, normalized, varray());
ADDFUNC0R(PLANE, VECTOR3, Plane, center, varray());
ADDFUNC0R(PLANE, VECTOR3, Plane, get_any_point, varray());
@ -1989,6 +2185,17 @@ void register_variant_methods() {
ADDFUNC1(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, resize, INT, "idx", varray());
ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, invert, varray());
ADDFUNC0R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, size, varray());
ADDFUNC0R(POOL_VECTOR2I_ARRAY, BOOL, PoolVector2iArray, empty, varray());
ADDFUNC2(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, set, INT, "idx", VECTOR2I, "vector2i", varray());
ADDFUNC1(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, push_back, VECTOR2I, "vector2i", varray());
ADDFUNC1(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, append, VECTOR2I, "vector2i", varray());
ADDFUNC1(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, append_array, POOL_VECTOR2I_ARRAY, "array", varray());
ADDFUNC1(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, remove, INT, "idx", varray());
ADDFUNC2R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, insert, INT, "idx", VECTOR2I, "vector2i", varray());
ADDFUNC1(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, resize, INT, "idx", varray());
ADDFUNC0(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, invert, varray());
ADDFUNC0R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, size, varray());
ADDFUNC0R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, empty, varray());
ADDFUNC2(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, set, INT, "idx", VECTOR3, "vector3", varray());
@ -2000,6 +2207,17 @@ void register_variant_methods() {
ADDFUNC1(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, resize, INT, "idx", varray());
ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, invert, varray());
ADDFUNC0R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, size, varray());
ADDFUNC0R(POOL_VECTOR3I_ARRAY, BOOL, PoolVector3iArray, empty, varray());
ADDFUNC2(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, set, INT, "idx", VECTOR3I, "vector3i", varray());
ADDFUNC1(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, push_back, VECTOR3I, "vector3i", varray());
ADDFUNC1(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, append, VECTOR3I, "vector3i", varray());
ADDFUNC1(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, append_array, POOL_VECTOR3I_ARRAY, "array", varray());
ADDFUNC1(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, remove, INT, "idx", varray());
ADDFUNC2R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, insert, INT, "idx", VECTOR3I, "vector3i", varray());
ADDFUNC1(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, resize, INT, "idx", varray());
ADDFUNC0(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, invert, varray());
ADDFUNC0R(POOL_COLOR_ARRAY, INT, PoolColorArray, size, varray());
ADDFUNC0R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, empty, varray());
ADDFUNC2(POOL_COLOR_ARRAY, NIL, PoolColorArray, set, INT, "idx", COLOR, "color", varray());
@ -2088,6 +2306,8 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Vector2_init1, Variant::VECTOR2, "x", Variant::REAL, "y", Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Vector2i_init1, Variant::VECTOR2I, "x", Variant::INT, "y", Variant::INT);
_VariantCall::add_constructor(_VariantCall::Rect2_init1, Variant::RECT2, "position", Variant::VECTOR2, "size", Variant::VECTOR2);
_VariantCall::add_constructor(_VariantCall::Rect2_init2, Variant::RECT2, "x", Variant::REAL, "y", Variant::REAL, "width", Variant::REAL, "height", Variant::REAL);
@ -2096,6 +2316,8 @@ void register_variant_methods() {
_VariantCall::add_constructor(_VariantCall::Vector3_init1, Variant::VECTOR3, "x", Variant::REAL, "y", Variant::REAL, "z", Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Vector3i_init1, Variant::VECTOR3I, "x", Variant::INT, "y", Variant::INT, "z", Variant::INT);
_VariantCall::add_constructor(_VariantCall::Plane_init1, Variant::PLANE, "a", Variant::REAL, "b", Variant::REAL, "c", Variant::REAL, "d", Variant::REAL);
_VariantCall::add_constructor(_VariantCall::Plane_init2, Variant::PLANE, "v1", Variant::VECTOR3, "v2", Variant::VECTOR3, "v3", Variant::VECTOR3);
_VariantCall::add_constructor(_VariantCall::Plane_init3, Variant::PLANE, "normal", Variant::VECTOR3, "d", Variant::REAL);
@ -2136,6 +2358,19 @@ void register_variant_methods() {
_VariantCall::add_variant_constant(Variant::VECTOR3, "FORWARD", Vector3(0, 0, -1));
_VariantCall::add_variant_constant(Variant::VECTOR3, "BACK", Vector3(0, 0, 1));
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_X", Vector3i::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Y", Vector3i::AXIS_Y);
_VariantCall::add_constant(Variant::VECTOR3I, "AXIS_Z", Vector3i::AXIS_Z);
_VariantCall::add_variant_constant(Variant::VECTOR3I, "ZERO", Vector3i(0, 0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "ONE", Vector3i(1, 1, 1));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "LEFT", Vector3i(-1, 0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "RIGHT", Vector3i(1, 0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "UP", Vector3i(0, 1, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "DOWN", Vector3i(0, -1, 0));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "FORWARD", Vector3i(0, 0, -1));
_VariantCall::add_variant_constant(Variant::VECTOR3I, "BACK", Vector3i(0, 0, 1));
_VariantCall::add_constant(Variant::VECTOR2, "AXIS_X", Vector2::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR2, "AXIS_Y", Vector2::AXIS_Y);
@ -2147,6 +2382,16 @@ void register_variant_methods() {
_VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
_VariantCall::add_variant_constant(Variant::VECTOR2, "DOWN", Vector2(0, 1));
_VariantCall::add_constant(Variant::VECTOR2I, "AXIS_X", Vector2i::AXIS_X);
_VariantCall::add_constant(Variant::VECTOR2I, "AXIS_Y", Vector2i::AXIS_Y);
_VariantCall::add_variant_constant(Variant::VECTOR2I, "ZERO", Vector2i(0, 0));
_VariantCall::add_variant_constant(Variant::VECTOR2I, "ONE", Vector2i(1, 1));
_VariantCall::add_variant_constant(Variant::VECTOR2I, "LEFT", Vector2i(-1, 0));
_VariantCall::add_variant_constant(Variant::VECTOR2I, "RIGHT", Vector2i(1, 0));
_VariantCall::add_variant_constant(Variant::VECTOR2I, "UP", Vector2i(0, -1));
_VariantCall::add_variant_constant(Variant::VECTOR2I, "DOWN", Vector2i(0, 1));
_VariantCall::add_variant_constant(Variant::TRANSFORM2D, "IDENTITY", Transform2D());
_VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_X", Transform2D(-1, 0, 0, 1, 0, 0));
_VariantCall::add_variant_constant(Variant::TRANSFORM2D, "FLIP_Y", Transform2D(1, 0, 0, -1, 0, 0));

File diff suppressed because it is too large Load Diff

View File

@ -528,6 +528,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = Vector2(args[0], args[1]);
} else if (id == "Vector2i") {
Vector<int> args;
Error err = _parse_construct<int>(p_stream, args, line, r_err_str);
if (err) {
return err;
}
if (args.size() != 2) {
r_err_str = "Expected 2 arguments for constructor";
return ERR_PARSE_ERROR;
}
value = Vector2i(args[0], args[1]);
} else if (id == "Rect2") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@ -541,6 +554,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = Rect2(args[0], args[1], args[2], args[3]);
} else if (id == "Rect2i") {
Vector<int> args;
Error err = _parse_construct<int>(p_stream, args, line, r_err_str);
if (err) {
return err;
}
if (args.size() != 4) {
r_err_str = "Expected 4 arguments for constructor";
return ERR_PARSE_ERROR;
}
value = Rect2i(args[0], args[1], args[2], args[3]);
} else if (id == "Vector3") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@ -554,6 +580,19 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = Vector3(args[0], args[1], args[2]);
} else if (id == "Vector3i") {
Vector<int> args;
Error err = _parse_construct<int>(p_stream, args, line, r_err_str);
if (err) {
return err;
}
if (args.size() != 3) {
r_err_str = "Expected 3 arguments for constructor";
return ERR_PARSE_ERROR;
}
value = Vector3i(args[0], args[1], args[2]);
} else if (id == "Transform2D" || id == "Matrix32") { //compatibility
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@ -1144,6 +1183,25 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = arr;
} else if (id == "PoolVector2iArray" || id == "Vector2iArray") {
Vector<int> args;
Error err = _parse_construct<int>(p_stream, args, line, r_err_str);
if (err) {
return err;
}
PoolVector<Vector2i> arr;
{
int len = args.size() / 2;
arr.resize(len);
PoolVector<Vector2i>::Write w = arr.write();
for (int i = 0; i < len; i++) {
w[i] = Vector2i(args[i * 2 + 0], args[i * 2 + 1]);
}
}
value = arr;
} else if (id == "PoolVector3Array" || id == "Vector3Array") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@ -1163,6 +1221,25 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
value = arr;
} else if (id == "PoolVector3iArray" || id == "Vector3iArray") {
Vector<int> args;
Error err = _parse_construct<int>(p_stream, args, line, r_err_str);
if (err) {
return err;
}
PoolVector<Vector3i> arr;
{
int len = args.size() / 3;
arr.resize(len);
PoolVector<Vector3i>::Write w = arr.write();
for (int i = 0; i < len; i++) {
w[i] = Vector3i(args[i * 3 + 0], args[i * 3 + 1], args[i * 3 + 2]);
}
}
value = arr;
} else if (id == "PoolColorArray" || id == "ColorArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@ -1566,15 +1643,28 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
Vector2 v = p_variant;
p_store_string_func(p_store_string_ud, "Vector2( " + rtos_fix(v.x) + ", " + rtos_fix(v.y) + " )");
} break;
case Variant::VECTOR2I: {
Vector2i v = p_variant;
p_store_string_func(p_store_string_ud, "Vector2i( " + rtos_fix(v.x) + ", " + rtos_fix(v.y) + " )");
} break;
case Variant::RECT2: {
Rect2 aabb = p_variant;
p_store_string_func(p_store_string_ud, "Rect2( " + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + " )");
} break;
case Variant::RECT2I: {
Rect2i aabb = p_variant;
p_store_string_func(p_store_string_ud, "Rect2i( " + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + " )");
} break;
case Variant::VECTOR3: {
Vector3 v = p_variant;
p_store_string_func(p_store_string_ud, "Vector3( " + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ", " + rtos_fix(v.z) + " )");
} break;
case Variant::VECTOR3I: {
Vector3i v = p_variant;
p_store_string_func(p_store_string_ud, "Vector3i( " + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ", " + rtos_fix(v.z) + " )");
} break;
case Variant::PLANE: {
Plane p = p_variant;
p_store_string_func(p_store_string_ud, "Plane( " + rtos_fix(p.normal.x) + ", " + rtos_fix(p.normal.y) + ", " + rtos_fix(p.normal.z) + ", " + rtos_fix(p.d) + " )");
@ -1839,6 +1929,23 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, " )");
} break;
case Variant::POOL_VECTOR2I_ARRAY: {
p_store_string_func(p_store_string_ud, "PoolVector2iArray( ");
PoolVector<Vector2i> data = p_variant;
int len = data.size();
PoolVector<Vector2i>::Read r = data.read();
const Vector2i *ptr = r.ptr();
for (int i = 0; i < len; i++) {
if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
}
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y));
}
p_store_string_func(p_store_string_ud, " )");
} break;
case Variant::POOL_VECTOR3_ARRAY: {
p_store_string_func(p_store_string_ud, "PoolVector3Array( ");
@ -1856,6 +1963,23 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, " )");
} break;
case Variant::POOL_VECTOR3I_ARRAY: {
p_store_string_func(p_store_string_ud, "PoolVector3iArray( ");
PoolVector<Vector3i> data = p_variant;
int len = data.size();
PoolVector<Vector3i>::Read r = data.read();
const Vector3i *ptr = r.ptr();
for (int i = 0; i < len; i++) {
if (i > 0) {
p_store_string_func(p_store_string_ud, ", ");
}
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y) + ", " + rtos_fix(ptr[i].z));
}
p_store_string_func(p_store_string_ud, " )");
} break;
case Variant::POOL_COLOR_ARRAY: {
p_store_string_func(p_store_string_ud, "PoolColorArray( ");