summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/core_constants.cpp1
-rw-r--r--core/extension/extension_api_dump.cpp2
-rw-r--r--core/extension/gdextension_interface.cpp22
-rw-r--r--core/extension/gdextension_interface.h79
-rw-r--r--core/io/marshalls.cpp94
-rw-r--r--core/io/packed_data_container.cpp1
-rw-r--r--core/io/resource.cpp3
-rw-r--r--core/io/resource_format_binary.cpp61
-rw-r--r--core/math/vector4.cpp6
-rw-r--r--core/math/vector4.h30
-rw-r--r--core/object/script_language.cpp1
-rw-r--r--core/variant/method_ptrcall.h1
-rw-r--r--core/variant/type_info.h1
-rw-r--r--core/variant/typed_array.h2
-rw-r--r--core/variant/variant.cpp83
-rw-r--r--core/variant/variant.h5
-rw-r--r--core/variant/variant_call.cpp24
-rw-r--r--core/variant/variant_construct.cpp5
-rw-r--r--core/variant/variant_construct.h1
-rw-r--r--core/variant/variant_destruct.cpp1
-rw-r--r--core/variant/variant_destruct.h1
-rw-r--r--core/variant/variant_internal.h35
-rw-r--r--core/variant/variant_op.cpp13
-rw-r--r--core/variant/variant_parser.cpp33
-rw-r--r--core/variant/variant_setget.cpp33
-rw-r--r--core/variant/variant_utility.cpp2
26 files changed, 473 insertions, 67 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index aaabbabfd9..5322e39ec0 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -761,6 +761,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR2_ARRAY", Variant::PACKED_VECTOR2_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR3_ARRAY", Variant::PACKED_VECTOR3_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_COLOR_ARRAY", Variant::PACKED_COLOR_ARRAY);
+ BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_PACKED_VECTOR4_ARRAY", Variant::PACKED_VECTOR4_ARRAY);
BIND_CORE_ENUM_CONSTANT_CUSTOM("TYPE_MAX", Variant::VARIANT_MAX);
//comparison
diff --git a/core/extension/extension_api_dump.cpp b/core/extension/extension_api_dump.cpp
index 69be2d2a8f..d7fba74365 100644
--- a/core/extension/extension_api_dump.cpp
+++ b/core/extension/extension_api_dump.cpp
@@ -189,6 +189,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
{ Variant::PACKED_VECTOR2_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::PACKED_VECTOR3_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::PACKED_COLOR_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
+ { Variant::PACKED_VECTOR4_ARRAY, ptrsize_32 * 2, ptrsize_64 * 2, ptrsize_32 * 2, ptrsize_64 * 2 },
{ Variant::VARIANT_MAX, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(float) * 4, sizeof(uint64_t) + sizeof(double) * 4, sizeof(uint64_t) + sizeof(double) * 4 },
};
@@ -230,6 +231,7 @@ Dictionary GDExtensionAPIDump::generate_extension_api(bool p_include_docs) {
static_assert(type_size_array[Variant::PACKED_VECTOR2_ARRAY][sizeof(void *)] == sizeof(PackedVector2Array), "Size of PackedVector2Array mismatch");
static_assert(type_size_array[Variant::PACKED_VECTOR3_ARRAY][sizeof(void *)] == sizeof(PackedVector3Array), "Size of PackedVector3Array mismatch");
static_assert(type_size_array[Variant::PACKED_COLOR_ARRAY][sizeof(void *)] == sizeof(PackedColorArray), "Size of PackedColorArray mismatch");
+ static_assert(type_size_array[Variant::PACKED_VECTOR4_ARRAY][sizeof(void *)] == sizeof(PackedVector4Array), "Size of PackedVector4Array mismatch");
static_assert(type_size_array[Variant::VARIANT_MAX][sizeof(void *)] == sizeof(Variant), "Size of Variant mismatch");
Array core_type_sizes;
diff --git a/core/extension/gdextension_interface.cpp b/core/extension/gdextension_interface.cpp
index 9b4aa98357..98f5cb4d02 100644
--- a/core/extension/gdextension_interface.cpp
+++ b/core/extension/gdextension_interface.cpp
@@ -595,6 +595,8 @@ static GDExtensionVariantFromTypeConstructorFunc gdextension_get_variant_from_ty
return VariantTypeConstructor<PackedVector2Array>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY:
return VariantTypeConstructor<PackedVector3Array>::variant_from_type;
+ case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY:
+ return VariantTypeConstructor<PackedVector4Array>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY:
return VariantTypeConstructor<PackedColorArray>::variant_from_type;
case GDEXTENSION_VARIANT_TYPE_NIL:
@@ -678,6 +680,8 @@ static GDExtensionTypeFromVariantConstructorFunc gdextension_get_variant_to_type
return VariantTypeConstructor<PackedVector2Array>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY:
return VariantTypeConstructor<PackedVector3Array>::type_from_variant;
+ case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY:
+ return VariantTypeConstructor<PackedVector4Array>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY:
return VariantTypeConstructor<PackedColorArray>::type_from_variant;
case GDEXTENSION_VARIANT_TYPE_NIL:
@@ -1116,6 +1120,22 @@ static GDExtensionTypePtr gdextension_packed_vector3_array_operator_index_const(
return (GDExtensionTypePtr)&self->ptr()[p_index];
}
+static GDExtensionTypePtr gdextension_packed_vector4_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
+ PackedVector4Array *self = (PackedVector4Array *)p_self;
+ if (unlikely(p_index < 0 || p_index >= self->size())) {
+ return nullptr;
+ }
+ return (GDExtensionTypePtr)&self->ptrw()[p_index];
+}
+
+static GDExtensionTypePtr gdextension_packed_vector4_array_operator_index_const(GDExtensionConstTypePtr p_self, GDExtensionInt p_index) {
+ const PackedVector4Array *self = (const PackedVector4Array *)p_self;
+ if (unlikely(p_index < 0 || p_index >= self->size())) {
+ return nullptr;
+ }
+ return (GDExtensionTypePtr)&self->ptr()[p_index];
+}
+
static GDExtensionVariantPtr gdextension_array_operator_index(GDExtensionTypePtr p_self, GDExtensionInt p_index) {
Array *self = (Array *)p_self;
if (unlikely(p_index < 0 || p_index >= self->size())) {
@@ -1620,6 +1640,8 @@ void gdextension_setup_interface() {
REGISTER_INTERFACE_FUNC(packed_vector2_array_operator_index_const);
REGISTER_INTERFACE_FUNC(packed_vector3_array_operator_index);
REGISTER_INTERFACE_FUNC(packed_vector3_array_operator_index_const);
+ REGISTER_INTERFACE_FUNC(packed_vector4_array_operator_index);
+ REGISTER_INTERFACE_FUNC(packed_vector4_array_operator_index_const);
REGISTER_INTERFACE_FUNC(array_operator_index);
REGISTER_INTERFACE_FUNC(array_operator_index_const);
REGISTER_INTERFACE_FUNC(array_ref);
diff --git a/core/extension/gdextension_interface.h b/core/extension/gdextension_interface.h
index 00a98af4e2..bfe592cb4e 100644
--- a/core/extension/gdextension_interface.h
+++ b/core/extension/gdextension_interface.h
@@ -96,6 +96,7 @@ typedef enum {
GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR2_ARRAY,
GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY,
GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY,
+ GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY,
GDEXTENSION_VARIANT_TYPE_VARIANT_MAX
} GDExtensionVariantType;
@@ -1964,32 +1965,6 @@ typedef uint8_t *(*GDExtensionInterfacePackedByteArrayOperatorIndex)(GDExtension
typedef const uint8_t *(*GDExtensionInterfacePackedByteArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index);
/**
- * @name packed_color_array_operator_index
- * @since 4.1
- *
- * Gets a pointer to a color in a PackedColorArray.
- *
- * @param p_self A pointer to a PackedColorArray object.
- * @param p_index The index of the Color to get.
- *
- * @return A pointer to the requested Color.
- */
-typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index);
-
-/**
- * @name packed_color_array_operator_index_const
- * @since 4.1
- *
- * Gets a const pointer to a color in a PackedColorArray.
- *
- * @param p_self A const pointer to a const PackedColorArray object.
- * @param p_index The index of the Color to get.
- *
- * @return A const pointer to the requested Color.
- */
-typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index);
-
-/**
* @name packed_float32_array_operator_index
* @since 4.1
*
@@ -2172,6 +2147,58 @@ typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector3ArrayOperatorIndex
typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector3ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index);
/**
+ * @name packed_vector4_array_operator_index
+ * @since 4.3
+ *
+ * Gets a pointer to a Vector4 in a PackedVector4Array.
+ *
+ * @param p_self A pointer to a PackedVector4Array object.
+ * @param p_index The index of the Vector4 to get.
+ *
+ * @return A pointer to the requested Vector4.
+ */
+typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector4ArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index);
+
+/**
+ * @name packed_vector4_array_operator_index_const
+ * @since 4.3
+ *
+ * Gets a const pointer to a Vector4 in a PackedVector4Array.
+ *
+ * @param p_self A const pointer to a PackedVector4Array object.
+ * @param p_index The index of the Vector4 to get.
+ *
+ * @return A const pointer to the requested Vector4.
+ */
+typedef GDExtensionTypePtr (*GDExtensionInterfacePackedVector4ArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index);
+
+/**
+ * @name packed_color_array_operator_index
+ * @since 4.1
+ *
+ * Gets a pointer to a color in a PackedColorArray.
+ *
+ * @param p_self A pointer to a PackedColorArray object.
+ * @param p_index The index of the Color to get.
+ *
+ * @return A pointer to the requested Color.
+ */
+typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndex)(GDExtensionTypePtr p_self, GDExtensionInt p_index);
+
+/**
+ * @name packed_color_array_operator_index_const
+ * @since 4.1
+ *
+ * Gets a const pointer to a color in a PackedColorArray.
+ *
+ * @param p_self A const pointer to a PackedColorArray object.
+ * @param p_index The index of the Color to get.
+ *
+ * @return A const pointer to the requested Color.
+ */
+typedef GDExtensionTypePtr (*GDExtensionInterfacePackedColorArrayOperatorIndexConst)(GDExtensionConstTypePtr p_self, GDExtensionInt p_index);
+
+/**
* @name array_operator_index
* @since 4.1
*
diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp
index 18dbac991c..2cdfacae17 100644
--- a/core/io/marshalls.cpp
+++ b/core/io/marshalls.cpp
@@ -1179,6 +1179,73 @@ Error decode_variant(Variant &r_variant, const uint8_t *p_buffer, int p_len, int
r_variant = carray;
} break;
+
+ case Variant::PACKED_VECTOR4_ARRAY: {
+ ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
+ int32_t count = decode_uint32(buf);
+ buf += 4;
+ len -= 4;
+
+ Vector<Vector4> varray;
+
+ if (header & HEADER_DATA_FLAG_64) {
+ ERR_FAIL_MUL_OF(count, sizeof(double) * 4, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(double) * 4 > (size_t)len, ERR_INVALID_DATA);
+
+ if (r_len) {
+ (*r_len) += 4; // Size of count number.
+ }
+
+ if (count) {
+ varray.resize(count);
+ Vector4 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 0);
+ w[i].y = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 1);
+ w[i].z = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 2);
+ w[i].w = decode_double(buf + i * sizeof(double) * 4 + sizeof(double) * 3);
+ }
+
+ int adv = sizeof(double) * 4 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ len -= adv;
+ buf += adv;
+ }
+ } else {
+ ERR_FAIL_MUL_OF(count, sizeof(float) * 4, ERR_INVALID_DATA);
+ ERR_FAIL_COND_V(count < 0 || count * sizeof(float) * 4 > (size_t)len, ERR_INVALID_DATA);
+
+ if (r_len) {
+ (*r_len) += 4; // Size of count number.
+ }
+
+ if (count) {
+ varray.resize(count);
+ Vector4 *w = varray.ptrw();
+
+ for (int32_t i = 0; i < count; i++) {
+ w[i].x = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 0);
+ w[i].y = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 1);
+ w[i].z = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 2);
+ w[i].w = decode_float(buf + i * sizeof(float) * 4 + sizeof(float) * 3);
+ }
+
+ int adv = sizeof(float) * 4 * count;
+
+ if (r_len) {
+ (*r_len) += adv;
+ }
+ len -= adv;
+ buf += adv;
+ }
+ }
+ r_variant = varray;
+
+ } break;
default: {
ERR_FAIL_V(ERR_BUG);
}
@@ -1263,6 +1330,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
case Variant::VECTOR4:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
+ case Variant::PACKED_VECTOR4_ARRAY:
case Variant::TRANSFORM2D:
case Variant::TRANSFORM3D:
case Variant::PROJECTION:
@@ -1947,6 +2015,32 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo
r_len += 4 * 4 * len;
} break;
+ case Variant::PACKED_VECTOR4_ARRAY: {
+ Vector<Vector4> data = p_variant;
+ int len = data.size();
+
+ if (buf) {
+ encode_uint32(len, buf);
+ buf += 4;
+ }
+
+ r_len += 4;
+
+ if (buf) {
+ for (int i = 0; i < len; i++) {
+ Vector4 v = data.get(i);
+
+ encode_real(v.x, &buf[0]);
+ encode_real(v.y, &buf[sizeof(real_t)]);
+ encode_real(v.z, &buf[sizeof(real_t) * 2]);
+ encode_real(v.w, &buf[sizeof(real_t) * 3]);
+ buf += sizeof(real_t) * 4;
+ }
+ }
+
+ r_len += sizeof(real_t) * 4 * len;
+
+ } break;
default: {
ERR_FAIL_V(ERR_BUG);
}
diff --git a/core/io/packed_data_container.cpp b/core/io/packed_data_container.cpp
index 11b0c69774..b20279c9ac 100644
--- a/core/io/packed_data_container.cpp
+++ b/core/io/packed_data_container.cpp
@@ -244,6 +244,7 @@ uint32_t PackedDataContainer::_pack(const Variant &p_data, Vector<uint8_t> &tmpd
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
case Variant::PACKED_COLOR_ARRAY:
+ case Variant::PACKED_VECTOR4_ARRAY:
case Variant::STRING_NAME:
case Variant::NODE_PATH: {
uint32_t pos = tmpdata.size();
diff --git a/core/io/resource.cpp b/core/io/resource.cpp
index 74f18ceee1..4c3cfeaa58 100644
--- a/core/io/resource.cpp
+++ b/core/io/resource.cpp
@@ -383,7 +383,8 @@ Ref<Resource> Resource::duplicate(bool p_subresources) const {
case Variant::Type::PACKED_FLOAT64_ARRAY:
case Variant::Type::PACKED_STRING_ARRAY:
case Variant::Type::PACKED_VECTOR2_ARRAY:
- case Variant::Type::PACKED_VECTOR3_ARRAY: {
+ case Variant::Type::PACKED_VECTOR3_ARRAY:
+ case Variant::Type::PACKED_VECTOR4_ARRAY: {
r->set(E.name, p.duplicate(p_subresources));
} break;
diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp
index d0a8200546..ab460c5f4c 100644
--- a/core/io/resource_format_binary.cpp
+++ b/core/io/resource_format_binary.cpp
@@ -85,15 +85,17 @@ enum {
VARIANT_VECTOR4 = 50,
VARIANT_VECTOR4I = 51,
VARIANT_PROJECTION = 52,
+ VARIANT_PACKED_VECTOR4_ARRAY = 53,
OBJECT_EMPTY = 0,
OBJECT_EXTERNAL_RESOURCE = 1,
OBJECT_INTERNAL_RESOURCE = 2,
OBJECT_EXTERNAL_RESOURCE_INDEX = 3,
- // Version 2: added 64 bits support for float and int.
- // Version 3: changed nodepath encoding.
- // Version 4: new string ID for ext/subresources, breaks forward compat.
+ // Version 2: Added 64-bit support for float and int.
+ // Version 3: Changed NodePath encoding.
+ // Version 4: New string ID for ext/subresources, breaks forward compat.
// Version 5: Ability to store script class in the header.
- FORMAT_VERSION = 5,
+ // Version 6: Added PackedVector4Array Variant type.
+ FORMAT_VERSION = 6,
FORMAT_VERSION_CAN_RENAME_DEPS = 1,
FORMAT_VERSION_NO_NODEPATH_PROPERTY = 3,
};
@@ -653,6 +655,19 @@ Error ResourceLoaderBinary::parse_variant(Variant &r_v) {
r_v = array;
} break;
+ case VARIANT_PACKED_VECTOR4_ARRAY: {
+ uint32_t len = f->get_32();
+
+ Vector<Vector4> array;
+ array.resize(len);
+ Vector4 *w = array.ptrw();
+ static_assert(sizeof(Vector4) == 4 * sizeof(real_t));
+ const Error err = read_reals(reinterpret_cast<real_t *>(w), f, len * 4);
+ ERR_FAIL_COND_V(err != OK, err);
+
+ r_v = array;
+
+ } break;
default: {
ERR_FAIL_V(ERR_FILE_CORRUPT);
} break;
@@ -1912,33 +1927,33 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
for (int i = 0; i < len; i++) {
save_unicode_string(f, r[i]);
}
-
} break;
- case Variant::PACKED_VECTOR3_ARRAY: {
- f->store_32(VARIANT_PACKED_VECTOR3_ARRAY);
- Vector<Vector3> arr = p_property;
+
+ case Variant::PACKED_VECTOR2_ARRAY: {
+ f->store_32(VARIANT_PACKED_VECTOR2_ARRAY);
+ Vector<Vector2> arr = p_property;
int len = arr.size();
f->store_32(len);
- const Vector3 *r = arr.ptr();
+ const Vector2 *r = arr.ptr();
for (int i = 0; i < len; i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
- f->store_real(r[i].z);
}
-
} break;
- case Variant::PACKED_VECTOR2_ARRAY: {
- f->store_32(VARIANT_PACKED_VECTOR2_ARRAY);
- Vector<Vector2> arr = p_property;
+
+ case Variant::PACKED_VECTOR3_ARRAY: {
+ f->store_32(VARIANT_PACKED_VECTOR3_ARRAY);
+ Vector<Vector3> arr = p_property;
int len = arr.size();
f->store_32(len);
- const Vector2 *r = arr.ptr();
+ const Vector3 *r = arr.ptr();
for (int i = 0; i < len; i++) {
f->store_real(r[i].x);
f->store_real(r[i].y);
+ f->store_real(r[i].z);
}
-
} break;
+
case Variant::PACKED_COLOR_ARRAY: {
f->store_32(VARIANT_PACKED_COLOR_ARRAY);
Vector<Color> arr = p_property;
@@ -1953,6 +1968,20 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref<FileAccess> f, const V
}
} break;
+ case Variant::PACKED_VECTOR4_ARRAY: {
+ f->store_32(VARIANT_PACKED_VECTOR4_ARRAY);
+ Vector<Vector4> arr = p_property;
+ int len = arr.size();
+ f->store_32(len);
+ const Vector4 *r = arr.ptr();
+ for (int i = 0; i < len; i++) {
+ f->store_real(r[i].x);
+ f->store_real(r[i].y);
+ f->store_real(r[i].z);
+ f->store_real(r[i].w);
+ }
+
+ } break;
default: {
ERR_FAIL_MSG("Invalid variant.");
}
diff --git a/core/math/vector4.cpp b/core/math/vector4.cpp
index 555ca6c66c..b6b914f36d 100644
--- a/core/math/vector4.cpp
+++ b/core/math/vector4.cpp
@@ -30,6 +30,8 @@
#include "vector4.h"
+#include "core/math/math_funcs.h"
+#include "core/math/vector4i.h"
#include "core/string/ustring.h"
Vector4::Axis Vector4::min_axis_index() const {
@@ -215,3 +217,7 @@ Vector4::operator String() const {
}
static_assert(sizeof(Vector4) == 4 * sizeof(real_t));
+
+Vector4::operator Vector4i() const {
+ return Vector4i(x, y, z, w);
+}
diff --git a/core/math/vector4.h b/core/math/vector4.h
index 52699c6281..f69b4752bb 100644
--- a/core/math/vector4.h
+++ b/core/math/vector4.h
@@ -32,9 +32,11 @@
#define VECTOR4_H
#include "core/error/error_macros.h"
-#include "core/math/math_funcs.h"
+#include "core/math/math_defs.h"
+#include "core/typedefs.h"
class String;
+struct Vector4i;
struct _NO_DISCARD_ Vector4 {
static const int AXIS_COUNT = 4;
@@ -140,28 +142,14 @@ struct _NO_DISCARD_ Vector4 {
_FORCE_INLINE_ bool operator<=(const Vector4 &p_vec4) const;
operator String() const;
+ operator Vector4i() const;
_FORCE_INLINE_ Vector4() {}
-
- _FORCE_INLINE_ Vector4(real_t p_x, real_t p_y, real_t p_z, real_t p_w) :
- x(p_x),
- y(p_y),
- z(p_z),
- w(p_w) {
- }
-
- Vector4(const Vector4 &p_vec4) :
- x(p_vec4.x),
- y(p_vec4.y),
- z(p_vec4.z),
- w(p_vec4.w) {
- }
-
- void operator=(const Vector4 &p_vec4) {
- x = p_vec4.x;
- y = p_vec4.y;
- z = p_vec4.z;
- w = p_vec4.w;
+ _FORCE_INLINE_ Vector4(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
+ x = p_x;
+ y = p_y;
+ z = p_z;
+ w = p_w;
}
};
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index bd3199ca0a..820296e66d 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -537,6 +537,7 @@ void ScriptLanguage::get_core_type_words(List<String> *p_core_type_words) const
p_core_type_words->push_back("PackedVector2Array");
p_core_type_words->push_back("PackedVector3Array");
p_core_type_words->push_back("PackedColorArray");
+ p_core_type_words->push_back("PackedVector4Array");
}
void ScriptLanguage::frame() {
diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h
index c8d1241d3d..1e10709b12 100644
--- a/core/variant/method_ptrcall.h
+++ b/core/variant/method_ptrcall.h
@@ -152,6 +152,7 @@ MAKE_PTRARG(PackedStringArray);
MAKE_PTRARG(PackedVector2Array);
MAKE_PTRARG(PackedVector3Array);
MAKE_PTRARG(PackedColorArray);
+MAKE_PTRARG(PackedVector4Array);
MAKE_PTRARG_BY_REFERENCE(Variant);
// This is for Object.
diff --git a/core/variant/type_info.h b/core/variant/type_info.h
index 15cb6c9c1a..d51c80eebe 100644
--- a/core/variant/type_info.h
+++ b/core/variant/type_info.h
@@ -142,6 +142,7 @@ MAKE_TYPE_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPE_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPE_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPE_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
+MAKE_TYPE_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)
MAKE_TYPE_INFO(IPAddress, Variant::STRING)
diff --git a/core/variant/typed_array.h b/core/variant/typed_array.h
index 0befd19864..e00947ed1e 100644
--- a/core/variant/typed_array.h
+++ b/core/variant/typed_array.h
@@ -134,6 +134,7 @@ MAKE_TYPED_ARRAY(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPED_ARRAY(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
+MAKE_TYPED_ARRAY(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)
MAKE_TYPED_ARRAY(IPAddress, Variant::STRING)
template <typename T>
@@ -235,6 +236,7 @@ MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
+MAKE_TYPED_ARRAY_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)
MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING)
#undef MAKE_TYPED_ARRAY
diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp
index 37eb16f9b2..3a499a2bcd 100644
--- a/core/variant/variant.cpp
+++ b/core/variant/variant.cpp
@@ -167,6 +167,9 @@ String Variant::get_type_name(Variant::Type p_type) {
case PACKED_COLOR_ARRAY: {
return "PackedColorArray";
}
+ case PACKED_VECTOR4_ARRAY: {
+ return "PackedVector4Array";
+ }
default: {
}
}
@@ -404,6 +407,7 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
PACKED_COLOR_ARRAY,
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
+ PACKED_VECTOR4_ARRAY,
NIL
};
@@ -480,6 +484,14 @@ bool Variant::can_convert(Variant::Type p_type_from, Variant::Type p_type_to) {
valid_types = valid;
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+
+ } break;
default: {
}
}
@@ -738,6 +750,7 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
PACKED_COLOR_ARRAY,
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
+ PACKED_VECTOR4_ARRAY,
NIL
};
@@ -814,6 +827,14 @@ bool Variant::can_convert_strict(Variant::Type p_type_from, Variant::Type p_type
valid_types = valid;
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ static const Type valid[] = {
+ ARRAY,
+ NIL
+ };
+ valid_types = valid;
+
+ } break;
default: {
}
}
@@ -980,6 +1001,9 @@ bool Variant::is_zero() const {
case PACKED_COLOR_ARRAY: {
return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0;
}
+ case PACKED_VECTOR4_ARRAY: {
+ return PackedArrayRef<Vector4>::get_array(_data.packed_array).size() == 0;
+ }
default: {
}
}
@@ -1236,6 +1260,12 @@ void Variant::reference(const Variant &p_variant) {
_data.packed_array = PackedArrayRef<Color>::create();
}
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ _data.packed_array = static_cast<PackedArrayRef<Vector4> *>(p_variant._data.packed_array)->reference();
+ if (!_data.packed_array) {
+ _data.packed_array = PackedArrayRef<Vector4>::create();
+ }
+ } break;
default: {
}
}
@@ -1410,9 +1440,12 @@ void Variant::_clear_internal() {
case PACKED_COLOR_ARRAY: {
PackedArrayRefBase::destroy(_data.packed_array);
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ PackedArrayRefBase::destroy(_data.packed_array);
+ } break;
default: {
// Not needed, there is no point. The following do not allocate memory:
- // VECTOR2, VECTOR3, RECT2, PLANE, QUATERNION, COLOR.
+ // VECTOR2, VECTOR3, VECTOR4, RECT2, PLANE, QUATERNION, COLOR.
}
}
}
@@ -1759,6 +1792,9 @@ String Variant::stringify(int recursion_count) const {
case PACKED_COLOR_ARRAY: {
return stringify_vector(operator PackedColorArray(), recursion_count);
}
+ case PACKED_VECTOR4_ARRAY: {
+ return stringify_vector(operator PackedVector4Array(), recursion_count);
+ }
case PACKED_STRING_ARRAY: {
return stringify_vector(operator PackedStringArray(), recursion_count);
}
@@ -2191,6 +2227,9 @@ inline DA _convert_array_from_variant(const Variant &p_variant) {
case Variant::PACKED_COLOR_ARRAY: {
return _convert_array<DA, PackedColorArray>(p_variant.operator PackedColorArray());
}
+ case Variant::PACKED_VECTOR4_ARRAY: {
+ return _convert_array<DA, PackedVector4Array>(p_variant.operator PackedVector4Array());
+ }
default: {
return DA();
}
@@ -2277,6 +2316,14 @@ Variant::operator PackedColorArray() const {
}
}
+Variant::operator PackedVector4Array() const {
+ if (type == PACKED_VECTOR4_ARRAY) {
+ return static_cast<PackedArrayRef<Vector4> *>(_data.packed_array)->array;
+ } else {
+ return _convert_array_from_variant<PackedVector4Array>(*this);
+ }
+}
+
/* helpers */
Variant::operator Vector<::RID>() const {
@@ -2635,6 +2682,11 @@ Variant::Variant(const PackedColorArray &p_color_array) :
_data.packed_array = PackedArrayRef<Color>::create(p_color_array);
}
+Variant::Variant(const PackedVector4Array &p_vector4_array) :
+ type(PACKED_VECTOR4_ARRAY) {
+ _data.packed_array = PackedArrayRef<Vector4>::create(p_vector4_array);
+}
+
/* helpers */
Variant::Variant(const Vector<::RID> &p_array) :
type(ARRAY) {
@@ -2853,6 +2905,9 @@ void Variant::operator=(const Variant &p_variant) {
case PACKED_COLOR_ARRAY: {
_data.packed_array = PackedArrayRef<Color>::reference_from(_data.packed_array, p_variant._data.packed_array);
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ _data.packed_array = PackedArrayRef<Vector4>::reference_from(_data.packed_array, p_variant._data.packed_array);
+ } break;
default: {
}
}
@@ -3175,6 +3230,25 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
return hash;
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ uint32_t hash = HASH_MURMUR3_SEED;
+ const PackedVector4Array &arr = PackedArrayRef<Vector4>::get_array(_data.packed_array);
+ int len = arr.size();
+
+ if (likely(len)) {
+ const Vector4 *r = arr.ptr();
+
+ for (int i = 0; i < len; i++) {
+ hash = hash_murmur3_one_real(r[i].x, hash);
+ hash = hash_murmur3_one_real(r[i].y, hash);
+ hash = hash_murmur3_one_real(r[i].z, hash);
+ hash = hash_murmur3_one_real(r[i].w, hash);
+ }
+ hash = hash_fmix32(hash);
+ }
+
+ return hash;
+ } break;
default: {
}
}
@@ -3430,6 +3504,10 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Color, hash_compare_color);
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ hash_compare_packed_array(_data.packed_array, p_variant._data.packed_array, Vector4, hash_compare_vector4);
+ } break;
+
default:
bool v;
Variant r;
@@ -3468,7 +3546,8 @@ bool Variant::identity_compare(const Variant &p_variant) const {
case PACKED_STRING_ARRAY:
case PACKED_VECTOR2_ARRAY:
case PACKED_VECTOR3_ARRAY:
- case PACKED_COLOR_ARRAY: {
+ case PACKED_COLOR_ARRAY:
+ case PACKED_VECTOR4_ARRAY: {
return _data.packed_array == p_variant._data.packed_array;
} break;
diff --git a/core/variant/variant.h b/core/variant/variant.h
index 93953c4e0e..821edcfedf 100644
--- a/core/variant/variant.h
+++ b/core/variant/variant.h
@@ -75,6 +75,7 @@ typedef Vector<String> PackedStringArray;
typedef Vector<Vector2> PackedVector2Array;
typedef Vector<Vector3> PackedVector3Array;
typedef Vector<Color> PackedColorArray;
+typedef Vector<Vector4> PackedVector4Array;
class Variant {
public:
@@ -126,6 +127,7 @@ public:
PACKED_VECTOR2_ARRAY,
PACKED_VECTOR3_ARRAY,
PACKED_COLOR_ARRAY,
+ PACKED_VECTOR4_ARRAY,
VARIANT_MAX
};
@@ -297,6 +299,7 @@ private:
true, //PACKED_VECTOR2_ARRAY,
true, //PACKED_VECTOR3_ARRAY,
true, //PACKED_COLOR_ARRAY,
+ true, //PACKED_VECTOR4_ARRAY,
};
if (unlikely(needs_deinit[type])) { // Make it fast for types that don't need deinit.
@@ -409,6 +412,7 @@ public:
operator PackedVector3Array() const;
operator PackedVector2Array() const;
operator PackedColorArray() const;
+ operator PackedVector4Array() const;
operator Vector<::RID>() const;
operator Vector<Plane>() const;
@@ -474,6 +478,7 @@ public:
Variant(const PackedVector2Array &p_vector2_array);
Variant(const PackedVector3Array &p_vector3_array);
Variant(const PackedColorArray &p_color_array);
+ Variant(const PackedVector4Array &p_vector4_array);
Variant(const Vector<::RID> &p_array); // helper
Variant(const Vector<Plane> &p_array); // helper
diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp
index 986b34c662..7012bf698d 100644
--- a/core/variant/variant_call.cpp
+++ b/core/variant/variant_call.cpp
@@ -2568,6 +2568,30 @@ static void _register_variant_builtin_methods() {
bind_method(PackedColorArray, rfind, sarray("value", "from"), varray(-1));
bind_method(PackedColorArray, count, sarray("value"), varray());
+ /* Vector4 Array */
+
+ bind_method(PackedVector4Array, size, sarray(), varray());
+ bind_method(PackedVector4Array, is_empty, sarray(), varray());
+ bind_method(PackedVector4Array, set, sarray("index", "value"), varray());
+ bind_method(PackedVector4Array, push_back, sarray("value"), varray());
+ bind_method(PackedVector4Array, append, sarray("value"), varray());
+ bind_method(PackedVector4Array, append_array, sarray("array"), varray());
+ bind_method(PackedVector4Array, remove_at, sarray("index"), varray());
+ bind_method(PackedVector4Array, insert, sarray("at_index", "value"), varray());
+ bind_method(PackedVector4Array, fill, sarray("value"), varray());
+ bind_methodv(PackedVector4Array, resize, &PackedVector4Array::resize_zeroed, sarray("new_size"), varray());
+ bind_method(PackedVector4Array, clear, sarray(), varray());
+ bind_method(PackedVector4Array, has, sarray("value"), varray());
+ bind_method(PackedVector4Array, reverse, sarray(), varray());
+ bind_method(PackedVector4Array, slice, sarray("begin", "end"), varray(INT_MAX));
+ bind_method(PackedVector4Array, to_byte_array, sarray(), varray());
+ bind_method(PackedVector4Array, sort, sarray(), varray());
+ bind_method(PackedVector4Array, bsearch, sarray("value", "before"), varray(true));
+ bind_method(PackedVector4Array, duplicate, sarray(), varray());
+ bind_method(PackedVector4Array, find, sarray("value", "from"), varray(0));
+ bind_method(PackedVector4Array, rfind, sarray("value", "from"), varray(-1));
+ bind_method(PackedVector4Array, count, sarray("value"), varray());
+
/* Register constants */
int ncc = Color::get_named_color_count();
diff --git a/core/variant/variant_construct.cpp b/core/variant/variant_construct.cpp
index b0ed49be5d..1edae407c2 100644
--- a/core/variant/variant_construct.cpp
+++ b/core/variant/variant_construct.cpp
@@ -211,6 +211,7 @@ void Variant::_register_variant_constructors() {
add_constructor<VariantConstructorToArray<PackedVector2Array>>(sarray("from"));
add_constructor<VariantConstructorToArray<PackedVector3Array>>(sarray("from"));
add_constructor<VariantConstructorToArray<PackedColorArray>>(sarray("from"));
+ add_constructor<VariantConstructorToArray<PackedVector4Array>>(sarray("from"));
add_constructor<VariantConstructNoArgs<PackedByteArray>>(sarray());
add_constructor<VariantConstructor<PackedByteArray, PackedByteArray>>(sarray("from"));
@@ -247,6 +248,10 @@ void Variant::_register_variant_constructors() {
add_constructor<VariantConstructNoArgs<PackedColorArray>>(sarray());
add_constructor<VariantConstructor<PackedColorArray, PackedColorArray>>(sarray("from"));
add_constructor<VariantConstructorFromArray<PackedColorArray>>(sarray("from"));
+
+ add_constructor<VariantConstructNoArgs<PackedVector4Array>>(sarray());
+ add_constructor<VariantConstructor<PackedVector4Array, PackedVector4Array>>(sarray("from"));
+ add_constructor<VariantConstructorFromArray<PackedVector4Array>>(sarray("from"));
}
void Variant::_unregister_variant_constructors() {
diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h
index a93723a910..82995620aa 100644
--- a/core/variant/variant_construct.h
+++ b/core/variant/variant_construct.h
@@ -97,6 +97,7 @@ MAKE_PTRCONSTRUCT(PackedStringArray);
MAKE_PTRCONSTRUCT(PackedVector2Array);
MAKE_PTRCONSTRUCT(PackedVector3Array);
MAKE_PTRCONSTRUCT(PackedColorArray);
+MAKE_PTRCONSTRUCT(PackedVector4Array);
MAKE_PTRCONSTRUCT(Variant);
template <typename T, typename... P>
diff --git a/core/variant/variant_destruct.cpp b/core/variant/variant_destruct.cpp
index c7455d5117..409f4bd07b 100644
--- a/core/variant/variant_destruct.cpp
+++ b/core/variant/variant_destruct.cpp
@@ -56,6 +56,7 @@ void Variant::_register_variant_destructors() {
add_destructor<VariantDestruct<PackedVector2Array>>();
add_destructor<VariantDestruct<PackedVector3Array>>();
add_destructor<VariantDestruct<PackedColorArray>>();
+ add_destructor<VariantDestruct<PackedVector4Array>>();
}
void Variant::_unregister_variant_destructors() {
diff --git a/core/variant/variant_destruct.h b/core/variant/variant_destruct.h
index c496189c6d..d91d99b02e 100644
--- a/core/variant/variant_destruct.h
+++ b/core/variant/variant_destruct.h
@@ -65,6 +65,7 @@ MAKE_PTRDESTRUCT(PackedStringArray);
MAKE_PTRDESTRUCT(PackedVector2Array);
MAKE_PTRDESTRUCT(PackedVector3Array);
MAKE_PTRDESTRUCT(PackedColorArray);
+MAKE_PTRDESTRUCT(PackedVector4Array);
#undef MAKE_PTRDESTRUCT
diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h
index dbd4a6a7ad..ec87081f15 100644
--- a/core/variant/variant_internal.h
+++ b/core/variant/variant_internal.h
@@ -114,6 +114,9 @@ public:
case Variant::PACKED_COLOR_ARRAY:
init_color_array(v);
break;
+ case Variant::PACKED_VECTOR4_ARRAY:
+ init_vector4_array(v);
+ break;
case Variant::OBJECT:
init_object(v);
break;
@@ -205,6 +208,8 @@ public:
_FORCE_INLINE_ static const PackedVector3Array *get_vector3_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector3> *>(v->_data.packed_array)->array; }
_FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
_FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Color> *>(v->_data.packed_array)->array; }
+ _FORCE_INLINE_ static PackedVector4Array *get_vector4_array(Variant *v) { return &static_cast<Variant::PackedArrayRef<Vector4> *>(v->_data.packed_array)->array; }
+ _FORCE_INLINE_ static const PackedVector4Array *get_vector4_array(const Variant *v) { return &static_cast<const Variant::PackedArrayRef<Vector4> *>(v->_data.packed_array)->array; }
_FORCE_INLINE_ static Object **get_object(Variant *v) { return (Object **)&v->_get_obj().obj; }
_FORCE_INLINE_ static const Object **get_object(const Variant *v) { return (const Object **)&v->_get_obj().obj; }
@@ -313,6 +318,10 @@ public:
v->_data.packed_array = Variant::PackedArrayRef<Color>::create(Vector<Color>());
v->type = Variant::PACKED_COLOR_ARRAY;
}
+ _FORCE_INLINE_ static void init_vector4_array(Variant *v) {
+ v->_data.packed_array = Variant::PackedArrayRef<Vector4>::create(Vector<Vector4>());
+ v->type = Variant::PACKED_VECTOR4_ARRAY;
+ }
_FORCE_INLINE_ static void init_object(Variant *v) {
object_assign_null(v);
v->type = Variant::OBJECT;
@@ -417,6 +426,8 @@ public:
return get_vector3_array(v);
case Variant::PACKED_COLOR_ARRAY:
return get_color_array(v);
+ case Variant::PACKED_VECTOR4_ARRAY:
+ return get_vector4_array(v);
case Variant::OBJECT:
return get_object(v);
case Variant::VARIANT_MAX:
@@ -501,6 +512,8 @@ public:
return get_vector3_array(v);
case Variant::PACKED_COLOR_ARRAY:
return get_color_array(v);
+ case Variant::PACKED_VECTOR4_ARRAY:
+ return get_vector4_array(v);
case Variant::OBJECT:
return get_object(v);
case Variant::VARIANT_MAX:
@@ -797,6 +810,12 @@ struct VariantGetInternalPtr<PackedColorArray> {
static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); }
};
+template <>
+struct VariantGetInternalPtr<PackedVector4Array> {
+ static PackedVector4Array *get_ptr(Variant *v) { return VariantInternal::get_vector4_array(v); }
+ static const PackedVector4Array *get_ptr(const Variant *v) { return VariantInternal::get_vector4_array(v); }
+};
+
template <typename T>
struct VariantInternalAccessor {
};
@@ -1058,6 +1077,12 @@ struct VariantInternalAccessor<PackedColorArray> {
};
template <>
+struct VariantInternalAccessor<PackedVector4Array> {
+ static _FORCE_INLINE_ const PackedVector4Array &get(const Variant *v) { return *VariantInternal::get_vector4_array(v); }
+ static _FORCE_INLINE_ void set(Variant *v, const PackedVector4Array &p_value) { *VariantInternal::get_vector4_array(v) = p_value; }
+};
+
+template <>
struct VariantInternalAccessor<Object *> {
static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast<Object *>(*VariantInternal::get_object(v)); }
static _FORCE_INLINE_ void set(Variant *v, const Object *p_value) { VariantInternal::object_assign(v, p_value); }
@@ -1297,6 +1322,11 @@ struct VariantInitializer<PackedColorArray> {
};
template <>
+struct VariantInitializer<PackedVector4Array> {
+ static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector4_array(v); }
+};
+
+template <>
struct VariantInitializer<Object *> {
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); }
};
@@ -1490,6 +1520,11 @@ struct VariantDefaultInitializer<PackedColorArray> {
static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_color_array(v) = PackedColorArray(); }
};
+template <>
+struct VariantDefaultInitializer<PackedVector4Array> {
+ static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector4_array(v) = PackedVector4Array(); }
+};
+
template <typename T>
struct VariantTypeChanger {
static _FORCE_INLINE_ void change(Variant *v) {
diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp
index dcf4b287d1..d2c1cde970 100644
--- a/core/variant/variant_op.cpp
+++ b/core/variant/variant_op.cpp
@@ -274,6 +274,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAppendArray<Vector2>>(Variant::OP_ADD, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorAppendArray<Vector3>>(Variant::OP_ADD, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorAppendArray<Color>>(Variant::OP_ADD, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorAppendArray<Vector4>>(Variant::OP_ADD, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorSub<int64_t, int64_t, int64_t>>(Variant::OP_SUBTRACT, Variant::INT, Variant::INT);
register_op<OperatorEvaluatorSub<double, int64_t, double>>(Variant::OP_SUBTRACT, Variant::INT, Variant::FLOAT);
@@ -480,6 +481,7 @@ void Variant::_register_variant_operators() {
register_string_modulo_op(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY);
register_string_modulo_op(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY);
register_string_modulo_op(PackedColorArray, Variant::PACKED_COLOR_ARRAY);
+ register_string_modulo_op(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorPow<int64_t, int64_t, int64_t>>(Variant::OP_POWER, Variant::INT, Variant::INT);
register_op<OperatorEvaluatorPow<double, int64_t, double>>(Variant::OP_POWER, Variant::INT, Variant::FLOAT);
@@ -561,6 +563,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorEqual<PackedVector2Array, PackedVector2Array>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorEqual<PackedVector3Array, PackedVector3Array>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorEqual<PackedColorArray, PackedColorArray>>(Variant::OP_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorEqual<PackedVector4Array, PackedVector4Array>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::BOOL, Variant::NIL>>(Variant::OP_EQUAL, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::INT, Variant::NIL>>(Variant::OP_EQUAL, Variant::INT, Variant::NIL);
@@ -598,6 +601,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL>>(Variant::OP_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL>>(Variant::OP_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::BOOL>>(Variant::OP_EQUAL, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::INT>>(Variant::OP_EQUAL, Variant::NIL, Variant::INT);
@@ -635,6 +639,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY>>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY>>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY>>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY>>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorAlwaysFalse<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::NIL);
register_op<OperatorEvaluatorNotEqual<bool, bool>>(Variant::OP_NOT_EQUAL, Variant::BOOL, Variant::BOOL);
@@ -680,6 +685,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorNotEqual<PackedVector2Array, PackedVector2Array>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorNotEqual<PackedVector3Array, PackedVector3Array>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorNotEqual<PackedColorArray, PackedColorArray>>(Variant::OP_NOT_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorNotEqual<PackedVector4Array, PackedVector4Array>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::BOOL, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::BOOL, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::INT, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::INT, Variant::NIL);
@@ -717,6 +723,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL>>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::BOOL>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::BOOL);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::INT>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::INT);
@@ -754,6 +761,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY);
register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorAlwaysTrue<Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY>>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorLess<bool, bool>>(Variant::OP_LESS, Variant::BOOL, Variant::BOOL);
register_op<OperatorEvaluatorLess<int64_t, int64_t>>(Variant::OP_LESS, Variant::INT, Variant::INT);
@@ -944,6 +952,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorNot<PackedVector2Array>>(Variant::OP_NOT, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorNot<PackedVector3Array>>(Variant::OP_NOT, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL);
register_op<OperatorEvaluatorNot<PackedColorArray>>(Variant::OP_NOT, Variant::PACKED_COLOR_ARRAY, Variant::NIL);
+ register_op<OperatorEvaluatorNot<PackedVector4Array>>(Variant::OP_NOT, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL);
register_string_op(OperatorEvaluatorInStringFind, Variant::OP_IN);
@@ -986,6 +995,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInDictionaryHas<PackedVector2Array>>(Variant::OP_IN, Variant::PACKED_VECTOR2_ARRAY, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<PackedVector3Array>>(Variant::OP_IN, Variant::PACKED_VECTOR3_ARRAY, Variant::DICTIONARY);
register_op<OperatorEvaluatorInDictionaryHas<PackedColorArray>>(Variant::OP_IN, Variant::PACKED_COLOR_ARRAY, Variant::DICTIONARY);
+ register_op<OperatorEvaluatorInDictionaryHas<PackedVector4Array>>(Variant::OP_IN, Variant::PACKED_VECTOR4_ARRAY, Variant::DICTIONARY);
register_op<OperatorEvaluatorInArrayFindNil>(Variant::OP_IN, Variant::NIL, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<bool, Array>>(Variant::OP_IN, Variant::BOOL, Variant::ARRAY);
@@ -1026,6 +1036,7 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInArrayFind<PackedVector2Array, Array>>(Variant::OP_IN, Variant::PACKED_VECTOR2_ARRAY, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<PackedVector3Array, Array>>(Variant::OP_IN, Variant::PACKED_VECTOR3_ARRAY, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<PackedColorArray, Array>>(Variant::OP_IN, Variant::PACKED_COLOR_ARRAY, Variant::ARRAY);
+ register_op<OperatorEvaluatorInArrayFind<PackedVector4Array, Array>>(Variant::OP_IN, Variant::PACKED_VECTOR4_ARRAY, Variant::ARRAY);
register_op<OperatorEvaluatorInArrayFind<int, PackedByteArray>>(Variant::OP_IN, Variant::INT, Variant::PACKED_BYTE_ARRAY);
register_op<OperatorEvaluatorInArrayFind<float, PackedByteArray>>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_BYTE_ARRAY);
@@ -1047,8 +1058,8 @@ void Variant::_register_variant_operators() {
register_op<OperatorEvaluatorInArrayFind<Vector2, PackedVector2Array>>(Variant::OP_IN, Variant::VECTOR2, Variant::PACKED_VECTOR2_ARRAY);
register_op<OperatorEvaluatorInArrayFind<Vector3, PackedVector3Array>>(Variant::OP_IN, Variant::VECTOR3, Variant::PACKED_VECTOR3_ARRAY);
-
register_op<OperatorEvaluatorInArrayFind<Color, PackedColorArray>>(Variant::OP_IN, Variant::COLOR, Variant::PACKED_COLOR_ARRAY);
+ register_op<OperatorEvaluatorInArrayFind<Vector4, PackedVector4Array>>(Variant::OP_IN, Variant::VECTOR4, Variant::PACKED_VECTOR4_ARRAY);
register_op<OperatorEvaluatorObjectHasPropertyString>(Variant::OP_IN, Variant::STRING, Variant::OBJECT);
register_op<OperatorEvaluatorObjectHasPropertyStringName>(Variant::OP_IN, Variant::STRING_NAME, Variant::OBJECT);
diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp
index 50f8007efa..9a0dd712ed 100644
--- a/core/variant/variant_parser.cpp
+++ b/core/variant/variant_parser.cpp
@@ -1395,6 +1395,24 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
}
value = arr;
+ } else if (id == "PackedVector4Array" || id == "PoolVector4Array" || id == "Vector4Array") {
+ Vector<real_t> args;
+ Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
+ if (err) {
+ return err;
+ }
+
+ Vector<Vector4> arr;
+ {
+ int len = args.size() / 4;
+ arr.resize(len);
+ Vector4 *w = arr.ptrw();
+ for (int i = 0; i < len; i++) {
+ w[i] = Vector4(args[i * 4 + 0], args[i * 4 + 1], args[i * 4 + 2], args[i * 4 + 3]);
+ }
+ }
+
+ value = arr;
} else if (id == "PackedColorArray" || id == "PoolColorArray" || id == "ColorArray") {
Vector<float> args;
Error err = _parse_construct<float>(p_stream, args, line, r_err_str);
@@ -2248,6 +2266,21 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
p_store_string_func(p_store_string_ud, ")");
} break;
+ case Variant::PACKED_VECTOR4_ARRAY: {
+ p_store_string_func(p_store_string_ud, "PackedVector4Array(");
+ Vector<Vector4> data = p_variant;
+ int len = data.size();
+ const Vector4 *ptr = data.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) + ", " + rtos_fix(ptr[i].w));
+ }
+
+ p_store_string_func(p_store_string_ud, ")");
+ } break;
default: {
ERR_PRINT("Unknown variant type");
diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp
index f49e9e54b3..96c52260d9 100644
--- a/core/variant/variant_setget.cpp
+++ b/core/variant/variant_setget.cpp
@@ -856,6 +856,7 @@ INDEXED_SETGET_STRUCT_TYPED(PackedVector2Array, Vector2)
INDEXED_SETGET_STRUCT_TYPED(PackedVector3Array, Vector3)
INDEXED_SETGET_STRUCT_TYPED(PackedStringArray, String)
INDEXED_SETGET_STRUCT_TYPED(PackedColorArray, Color)
+INDEXED_SETGET_STRUCT_TYPED(PackedVector4Array, Vector4)
INDEXED_SETGET_STRUCT_DICT(Dictionary)
@@ -923,6 +924,7 @@ void register_indexed_setters_getters() {
REGISTER_INDEXED_MEMBER(PackedVector3Array);
REGISTER_INDEXED_MEMBER(PackedStringArray);
REGISTER_INDEXED_MEMBER(PackedColorArray);
+ REGISTER_INDEXED_MEMBER(PackedVector4Array);
REGISTER_INDEXED_MEMBER(Array);
REGISTER_INDEXED_MEMBER(Dictionary);
@@ -1498,6 +1500,14 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
return true;
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ const Vector<Vector4> *arr = &PackedArrayRef<Vector4>::get_array(_data.packed_array);
+ if (arr->size() == 0) {
+ return false;
+ }
+ r_iter = 0;
+ return true;
+ } break;
default: {
}
}
@@ -1747,6 +1757,16 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
r_iter = idx;
return true;
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ const Vector<Vector4> *arr = &PackedArrayRef<Vector4>::get_array(_data.packed_array);
+ int idx = r_iter;
+ idx++;
+ if (idx >= arr->size()) {
+ return false;
+ }
+ r_iter = idx;
+ return true;
+ } break;
default: {
}
}
@@ -1921,6 +1941,17 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
#endif
return arr->get(idx);
} break;
+ case PACKED_VECTOR4_ARRAY: {
+ const Vector<Vector4> *arr = &PackedArrayRef<Vector4>::get_array(_data.packed_array);
+ int idx = r_iter;
+#ifdef DEBUG_ENABLED
+ if (idx < 0 || idx >= arr->size()) {
+ r_valid = false;
+ return Variant();
+ }
+#endif
+ return arr->get(idx);
+ } break;
default: {
}
}
@@ -1968,6 +1999,8 @@ Variant Variant::recursive_duplicate(bool p_deep, int recursion_count) const {
return operator Vector<Vector3>().duplicate();
case PACKED_COLOR_ARRAY:
return operator Vector<Color>().duplicate();
+ case PACKED_VECTOR4_ARRAY:
+ return operator Vector<Vector4>().duplicate();
default:
return *this;
}
diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp
index 916ba7aa2f..5522b5ba88 100644
--- a/core/variant/variant_utility.cpp
+++ b/core/variant/variant_utility.cpp
@@ -917,6 +917,8 @@ Variant VariantUtilityFunctions::type_convert(const Variant &p_variant, const Va
return p_variant.operator PackedVector3Array();
case Variant::Type::PACKED_COLOR_ARRAY:
return p_variant.operator PackedColorArray();
+ case Variant::Type::PACKED_VECTOR4_ARRAY:
+ return p_variant.operator PackedVector4Array();
case Variant::Type::VARIANT_MAX:
ERR_PRINT("Invalid type argument to type_convert(), use the TYPE_* constants. Returning the unconverted Variant.");
}