diff --git a/core/core_constants.cpp b/core/core_constants.cpp index aaabbabfd9e7..5322e39ec0de 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 69be2d2a8f69..d7fba7436521 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 9b4aa983572d..98f5cb4d0258 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::variant_from_type; case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY: return VariantTypeConstructor::variant_from_type; + case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY: + return VariantTypeConstructor::variant_from_type; case GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY: return VariantTypeConstructor::variant_from_type; case GDEXTENSION_VARIANT_TYPE_NIL: @@ -678,6 +680,8 @@ static GDExtensionTypeFromVariantConstructorFunc gdextension_get_variant_to_type return VariantTypeConstructor::type_from_variant; case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR3_ARRAY: return VariantTypeConstructor::type_from_variant; + case GDEXTENSION_VARIANT_TYPE_PACKED_VECTOR4_ARRAY: + return VariantTypeConstructor::type_from_variant; case GDEXTENSION_VARIANT_TYPE_PACKED_COLOR_ARRAY: return VariantTypeConstructor::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 00a98af4e2d7..bfe592cb4e7b 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; @@ -1963,32 +1964,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 @@ -2171,6 +2146,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 18dbac991cbb..2cdfacae1751 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -1178,6 +1178,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 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: @@ -1946,6 +2014,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 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 11b0c697748e..b20279c9ace2 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 &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 74f18ceee197..4c3cfeaa5869 100644 --- a/core/io/resource.cpp +++ b/core/io/resource.cpp @@ -383,7 +383,8 @@ Ref 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 d0a820054608..ab460c5f4c57 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 array; + array.resize(len); + Vector4 *w = array.ptrw(); + static_assert(sizeof(Vector4) == 4 * sizeof(real_t)); + const Error err = read_reals(reinterpret_cast(w), f, len * 4); + ERR_FAIL_COND_V(err != OK, err); + + r_v = array; + + } break; default: { ERR_FAIL_V(ERR_FILE_CORRUPT); } break; @@ -1912,8 +1927,20 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const V for (int i = 0; i < len; i++) { save_unicode_string(f, r[i]); } - } break; + + case Variant::PACKED_VECTOR2_ARRAY: { + f->store_32(VARIANT_PACKED_VECTOR2_ARRAY); + Vector arr = p_property; + int len = arr.size(); + f->store_32(len); + const Vector2 *r = arr.ptr(); + for (int i = 0; i < len; i++) { + f->store_real(r[i].x); + f->store_real(r[i].y); + } + } break; + case Variant::PACKED_VECTOR3_ARRAY: { f->store_32(VARIANT_PACKED_VECTOR3_ARRAY); Vector arr = p_property; @@ -1925,20 +1952,8 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const V 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 arr = p_property; - int len = arr.size(); - f->store_32(len); - const Vector2 *r = arr.ptr(); - for (int i = 0; i < len; i++) { - f->store_real(r[i].x); - f->store_real(r[i].y); - } - } break; case Variant::PACKED_COLOR_ARRAY: { f->store_32(VARIANT_PACKED_COLOR_ARRAY); Vector arr = p_property; @@ -1952,6 +1967,20 @@ void ResourceFormatSaverBinaryInstance::write_variant(Ref f, const V f->store_float(r[i].a); } + } break; + case Variant::PACKED_VECTOR4_ARRAY: { + f->store_32(VARIANT_PACKED_VECTOR4_ARRAY); + Vector 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 555ca6c66cf6..b6b914f36dab 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 52699c6281a6..f69b4752bbf7 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 bd3199ca0af5..820296e66d03 100644 --- a/core/object/script_language.cpp +++ b/core/object/script_language.cpp @@ -537,6 +537,7 @@ void ScriptLanguage::get_core_type_words(List *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 c8d1241d3d1b..1e10709b12bd 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 15cb6c9c1aac..d51c80eebe98 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 0befd198648e..e00947ed1e77 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 @@ -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 37eb16f9b2d0..3a499a2bcd3a 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 }; @@ -479,6 +483,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 }; @@ -813,6 +826,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::get_array(_data.packed_array).size() == 0; } + case PACKED_VECTOR4_ARRAY: { + return PackedArrayRef::get_array(_data.packed_array).size() == 0; + } default: { } } @@ -1236,6 +1260,12 @@ void Variant::reference(const Variant &p_variant) { _data.packed_array = PackedArrayRef::create(); } } break; + case PACKED_VECTOR4_ARRAY: { + _data.packed_array = static_cast *>(p_variant._data.packed_array)->reference(); + if (!_data.packed_array) { + _data.packed_array = PackedArrayRef::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(p_variant.operator PackedColorArray()); } + case Variant::PACKED_VECTOR4_ARRAY: { + return _convert_array(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 *>(_data.packed_array)->array; + } else { + return _convert_array_from_variant(*this); + } +} + /* helpers */ Variant::operator Vector<::RID>() const { @@ -2635,6 +2682,11 @@ Variant::Variant(const PackedColorArray &p_color_array) : _data.packed_array = PackedArrayRef::create(p_color_array); } +Variant::Variant(const PackedVector4Array &p_vector4_array) : + type(PACKED_VECTOR4_ARRAY) { + _data.packed_array = PackedArrayRef::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::reference_from(_data.packed_array, p_variant._data.packed_array); } break; + case PACKED_VECTOR4_ARRAY: { + _data.packed_array = PackedArrayRef::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::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 93953c4e0e18..821edcfedf41 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -75,6 +75,7 @@ typedef Vector PackedStringArray; typedef Vector PackedVector2Array; typedef Vector PackedVector3Array; typedef Vector PackedColorArray; +typedef Vector 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() 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 &p_array); // helper diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index 986b34c662e7..7012bf698d1f 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 b0ed49be5d10..1edae407c249 100644 --- a/core/variant/variant_construct.cpp +++ b/core/variant/variant_construct.cpp @@ -211,6 +211,7 @@ void Variant::_register_variant_constructors() { add_constructor>(sarray("from")); add_constructor>(sarray("from")); add_constructor>(sarray("from")); + add_constructor>(sarray("from")); add_constructor>(sarray()); add_constructor>(sarray("from")); @@ -247,6 +248,10 @@ void Variant::_register_variant_constructors() { add_constructor>(sarray()); add_constructor>(sarray("from")); add_constructor>(sarray("from")); + + add_constructor>(sarray()); + add_constructor>(sarray("from")); + add_constructor>(sarray("from")); } void Variant::_unregister_variant_constructors() { diff --git a/core/variant/variant_construct.h b/core/variant/variant_construct.h index a93723a910f3..82995620aa7e 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 diff --git a/core/variant/variant_destruct.cpp b/core/variant/variant_destruct.cpp index c7455d5117c6..409f4bd07bbb 100644 --- a/core/variant/variant_destruct.cpp +++ b/core/variant/variant_destruct.cpp @@ -56,6 +56,7 @@ void Variant::_register_variant_destructors() { add_destructor>(); add_destructor>(); add_destructor>(); + add_destructor>(); } void Variant::_unregister_variant_destructors() { diff --git a/core/variant/variant_destruct.h b/core/variant/variant_destruct.h index c496189c6de3..d91d99b02e4c 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 dbd4a6a7ad92..ec87081f1504 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 *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static PackedColorArray *get_color_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } _FORCE_INLINE_ static const PackedColorArray *get_color_array(const Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } + _FORCE_INLINE_ static PackedVector4Array *get_vector4_array(Variant *v) { return &static_cast *>(v->_data.packed_array)->array; } + _FORCE_INLINE_ static const PackedVector4Array *get_vector4_array(const Variant *v) { return &static_cast *>(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::create(Vector()); v->type = Variant::PACKED_COLOR_ARRAY; } + _FORCE_INLINE_ static void init_vector4_array(Variant *v) { + v->_data.packed_array = Variant::PackedArrayRef::create(Vector()); + 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 { static const PackedColorArray *get_ptr(const Variant *v) { return VariantInternal::get_color_array(v); } }; +template <> +struct VariantGetInternalPtr { + 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 struct VariantInternalAccessor { }; @@ -1057,6 +1076,12 @@ struct VariantInternalAccessor { static _FORCE_INLINE_ void set(Variant *v, const PackedColorArray &p_value) { *VariantInternal::get_color_array(v) = p_value; } }; +template <> +struct VariantInternalAccessor { + 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 { static _FORCE_INLINE_ Object *get(const Variant *v) { return const_cast(*VariantInternal::get_object(v)); } @@ -1296,6 +1321,11 @@ struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_color_array(v); } }; +template <> +struct VariantInitializer { + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_vector4_array(v); } +}; + template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); } @@ -1490,6 +1520,11 @@ struct VariantDefaultInitializer { static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_color_array(v) = PackedColorArray(); } }; +template <> +struct VariantDefaultInitializer { + static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_vector4_array(v) = PackedVector4Array(); } +}; + template struct VariantTypeChanger { static _FORCE_INLINE_ void change(Variant *v) { diff --git a/core/variant/variant_op.cpp b/core/variant/variant_op.cpp index dcf4b287d1e3..d2c1cde970fb 100644 --- a/core/variant/variant_op.cpp +++ b/core/variant/variant_op.cpp @@ -274,6 +274,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_ADD, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_ADD, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY); register_op>(Variant::OP_ADD, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_ADD, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY); register_op>(Variant::OP_SUBTRACT, Variant::INT, Variant::INT); register_op>(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>(Variant::OP_POWER, Variant::INT, Variant::INT); register_op>(Variant::OP_POWER, Variant::INT, Variant::FLOAT); @@ -561,6 +563,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY); register_op>(Variant::OP_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY); register_op>(Variant::OP_EQUAL, Variant::BOOL, Variant::NIL); register_op>(Variant::OP_EQUAL, Variant::INT, Variant::NIL); @@ -598,6 +601,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL); register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL); register_op>(Variant::OP_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL); + register_op>(Variant::OP_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL); register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::BOOL); register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::INT); @@ -635,6 +639,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY); register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::NIL); register_op>(Variant::OP_NOT_EQUAL, Variant::BOOL, Variant::BOOL); @@ -680,6 +685,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::PACKED_VECTOR3_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::PACKED_VECTOR4_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::BOOL, Variant::NIL); register_op>(Variant::OP_NOT_EQUAL, Variant::INT, Variant::NIL); @@ -717,6 +723,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL); register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL); register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_COLOR_ARRAY, Variant::NIL); + register_op>(Variant::OP_NOT_EQUAL, Variant::PACKED_VECTOR4_ARRAY, Variant::NIL); register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::BOOL); register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::INT); @@ -754,6 +761,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR3_ARRAY); register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_NOT_EQUAL, Variant::NIL, Variant::PACKED_VECTOR4_ARRAY); register_op>(Variant::OP_LESS, Variant::BOOL, Variant::BOOL); register_op>(Variant::OP_LESS, Variant::INT, Variant::INT); @@ -944,6 +952,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_NOT, Variant::PACKED_VECTOR2_ARRAY, Variant::NIL); register_op>(Variant::OP_NOT, Variant::PACKED_VECTOR3_ARRAY, Variant::NIL); register_op>(Variant::OP_NOT, Variant::PACKED_COLOR_ARRAY, Variant::NIL); + register_op>(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>(Variant::OP_IN, Variant::PACKED_VECTOR2_ARRAY, Variant::DICTIONARY); register_op>(Variant::OP_IN, Variant::PACKED_VECTOR3_ARRAY, Variant::DICTIONARY); register_op>(Variant::OP_IN, Variant::PACKED_COLOR_ARRAY, Variant::DICTIONARY); + register_op>(Variant::OP_IN, Variant::PACKED_VECTOR4_ARRAY, Variant::DICTIONARY); register_op(Variant::OP_IN, Variant::NIL, Variant::ARRAY); register_op>(Variant::OP_IN, Variant::BOOL, Variant::ARRAY); @@ -1026,6 +1036,7 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_IN, Variant::PACKED_VECTOR2_ARRAY, Variant::ARRAY); register_op>(Variant::OP_IN, Variant::PACKED_VECTOR3_ARRAY, Variant::ARRAY); register_op>(Variant::OP_IN, Variant::PACKED_COLOR_ARRAY, Variant::ARRAY); + register_op>(Variant::OP_IN, Variant::PACKED_VECTOR4_ARRAY, Variant::ARRAY); register_op>(Variant::OP_IN, Variant::INT, Variant::PACKED_BYTE_ARRAY); register_op>(Variant::OP_IN, Variant::FLOAT, Variant::PACKED_BYTE_ARRAY); @@ -1047,8 +1058,8 @@ void Variant::_register_variant_operators() { register_op>(Variant::OP_IN, Variant::VECTOR2, Variant::PACKED_VECTOR2_ARRAY); register_op>(Variant::OP_IN, Variant::VECTOR3, Variant::PACKED_VECTOR3_ARRAY); - register_op>(Variant::OP_IN, Variant::COLOR, Variant::PACKED_COLOR_ARRAY); + register_op>(Variant::OP_IN, Variant::VECTOR4, Variant::PACKED_VECTOR4_ARRAY); register_op(Variant::OP_IN, Variant::STRING, Variant::OBJECT); register_op(Variant::OP_IN, Variant::STRING_NAME, Variant::OBJECT); diff --git a/core/variant/variant_parser.cpp b/core/variant/variant_parser.cpp index 50f8007efae5..9a0dd712edc6 100644 --- a/core/variant/variant_parser.cpp +++ b/core/variant/variant_parser.cpp @@ -1394,6 +1394,24 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream, } } + value = arr; + } else if (id == "PackedVector4Array" || id == "PoolVector4Array" || id == "Vector4Array") { + Vector args; + Error err = _parse_construct(p_stream, args, line, r_err_str); + if (err) { + return err; + } + + Vector 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 args; @@ -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 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 f49e9e54b342..96c52260d9da 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 *arr = &PackedArrayRef::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 *arr = &PackedArrayRef::get_array(_data.packed_array); + int idx = r_iter; + idx++; + if (idx >= arr->size()) { + return false; + } + r_iter = idx; + return true; + } break; default: { } } @@ -1918,6 +1938,17 @@ Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { r_valid = false; return Variant(); } +#endif + return arr->get(idx); + } break; + case PACKED_VECTOR4_ARRAY: { + const Vector *arr = &PackedArrayRef::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; @@ -1968,6 +1999,8 @@ Variant Variant::recursive_duplicate(bool p_deep, int recursion_count) const { return operator Vector().duplicate(); case PACKED_COLOR_ARRAY: return operator Vector().duplicate(); + case PACKED_VECTOR4_ARRAY: + return operator Vector().duplicate(); default: return *this; } diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 916ba7aa2f60..5522b5ba8811 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."); } diff --git a/doc/classes/@GlobalScope.xml b/doc/classes/@GlobalScope.xml index f2a6517a0cb6..26bf5151358e 100644 --- a/doc/classes/@GlobalScope.xml +++ b/doc/classes/@GlobalScope.xml @@ -604,7 +604,7 @@ is_same(arr_a, arr_b) # false [/codeblock] These are [Variant] value types: [code]null[/code], [bool], [int], [float], [String], [StringName], [Vector2], [Vector2i], [Vector3], [Vector3i], [Vector4], [Vector4i], [Rect2], [Rect2i], [Transform2D], [Transform3D], [Plane], [Quaternion], [AABB], [Basis], [Projection], [Color], [NodePath], [RID], [Callable] and [Signal]. - These are [Variant] reference types: [Object], [Dictionary], [Array], [PackedByteArray], [PackedInt32Array], [PackedInt64Array], [PackedFloat32Array], [PackedFloat64Array], [PackedStringArray], [PackedVector2Array], [PackedVector3Array] and [PackedColorArray]. + These are [Variant] reference types: [Object], [Dictionary], [Array], [PackedByteArray], [PackedInt32Array], [PackedInt64Array], [PackedFloat32Array], [PackedFloat64Array], [PackedStringArray], [PackedVector2Array], [PackedVector3Array], [PackedVector4Array], and [PackedColorArray]. @@ -3169,7 +3169,10 @@ Variable is of type [PackedColorArray]. - + + Variable is of type [PackedVector4Array]. + + Represents the size of the [enum Variant.Type] enum. diff --git a/doc/classes/Array.xml b/doc/classes/Array.xml index a72ac6053620..326b71c58825 100644 --- a/doc/classes/Array.xml +++ b/doc/classes/Array.xml @@ -154,6 +154,13 @@ Constructs an array from a [PackedVector3Array]. + + + + + Constructs an array from a [PackedVector4Array]. + + diff --git a/doc/classes/PackedVector4Array.xml b/doc/classes/PackedVector4Array.xml new file mode 100644 index 000000000000..fd0cfeb74bd2 --- /dev/null +++ b/doc/classes/PackedVector4Array.xml @@ -0,0 +1,225 @@ + + + + A packed array of [Vector4]s. + + + An array specifically designed to hold [Vector4]. Packs data tightly, so it saves memory for large array sizes. + [b]Note:[/b] Packed arrays are always passed by reference. To get a copy of an array that can be modified independently of the original array, use [method duplicate]. This is [i]not[/i] the case for built-in properties and methods. The returned packed array of these are a copies, and changing it will [i]not[/i] affect the original value. To update a built-in property you need to modify the returned array, and then assign it to the property again. + + + + + + + + Constructs an empty [PackedVector4Array]. + + + + + + + Constructs a [PackedVector4Array] as a copy of the given [PackedVector4Array]. + + + + + + + Constructs a new [PackedVector4Array]. Optionally, you can pass in a generic [Array] that will be converted. + [b]Note:[/b] When initializing a [PackedVector4Array] with elements, it must be initialized with an [Array] of [Vector4] values: + [codeblock] + var array = PackedVector4Array([Vector4(12, 34, 56, 78), Vector4(90, 12, 34, 56)]) + [/codeblock] + + + + + + + + + Appends an element at the end of the array (alias of [method push_back]). + + + + + + + Appends a [PackedVector4Array] at the end of this array. + + + + + + + + Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a [param before] specifier can be passed. If [code]false[/code], the returned index comes after all existing entries of the value in the array. + [b]Note:[/b] Calling [method bsearch] on an unsorted array results in unexpected behavior. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + Clears the array. This is equivalent to using [method resize] with a size of [code]0[/code]. + + + + + + + Returns the number of times an element is in the array. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + Creates a copy of the array, and returns it. + + + + + + + Assigns the given value to all elements in the array. This can typically be used together with [method resize] to create an array with a given size and initialized elements. + + + + + + + + Searches the array for a value and returns its index or [code]-1[/code] if not found. Optionally, the initial search index can be passed. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + + Returns [code]true[/code] if the array contains [param value]. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + + + Inserts a new element at a given position in the array. The position must be valid, or at the end of the array ([code]idx == size()[/code]). + + + + + + Returns [code]true[/code] if the array is empty. + + + + + + + Inserts a [Vector4] at the end. + + + + + + + Removes an element from the array by index. + + + + + + + Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. + + + + + + Reverses the order of the elements in the array. + + + + + + + + Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + + + Changes the [Vector4] at the given index. + + + + + + Returns the number of elements in the array. + + + + + + + + Returns the slice of the [PackedVector4Array], from [param begin] (inclusive) to [param end] (exclusive), as a new [PackedVector4Array]. + The absolute value of [param begin] and [param end] will be clamped to the array size, so the default value for [param end] makes it slice to the size of the array by default (i.e. [code]arr.slice(1)[/code] is a shorthand for [code]arr.slice(1, arr.size())[/code]). + If either [param begin] or [param end] are negative, they will be relative to the end of the array (i.e. [code]arr.slice(0, -2)[/code] is a shorthand for [code]arr.slice(0, arr.size() - 2)[/code]). + + + + + + Sorts the elements of the array in ascending order. + [b]Note:[/b] Vectors with [constant @GDScript.NAN] elements don't behave the same as other vectors. Therefore, the results from this method may not be accurate if NaNs are included. + + + + + + Returns a [PackedByteArray] with each vector encoded as bytes. + + + + + + + + + Returns [code]true[/code] if contents of the arrays differ. + + + + + + + Returns a new [PackedVector4Array] with contents of [param right] added at the end of this array. For better performance, consider using [method append_array] instead. + + + + + + + Returns [code]true[/code] if contents of both arrays are the same, i.e. they have all equal [Vector4]s at the corresponding indices. + + + + + + + Returns the [Vector4] at index [param index]. Negative indices can be used to access the elements starting from the end. Using index out of array's bounds will result in an error. + + + + diff --git a/doc/tools/make_rst.py b/doc/tools/make_rst.py index d7230db6a684..0b722757f964 100755 --- a/doc/tools/make_rst.py +++ b/doc/tools/make_rst.py @@ -143,6 +143,7 @@ CLASSES_WITH_CSHARP_DIFFERENCES: List[str] = [ "PackedStringArray", "PackedVector2Array", "PackedVector3Array", + "PackedVector4Array", "Variant", ] @@ -156,6 +157,7 @@ PACKED_ARRAY_TYPES: List[str] = [ "PackedStringArray", "PackedVector2Array", "PackedVector3Array", + "PackedVector4Array", ] diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 86fe9dd1fb50..88e0878bd4d6 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -5075,7 +5075,8 @@ void AnimationTrackEditor::_fetch_value_track_options(const NodePath &p_path, An case Variant::PACKED_FLOAT64_ARRAY: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: - case Variant::PACKED_COLOR_ARRAY: { + case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: { *r_update_mode = Animation::UPDATE_CONTINUOUS; } break; default: { diff --git a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp index 74d749792925..c86ca7aaad53 100644 --- a/editor/debugger/debug_adapter/debug_adapter_protocol.cpp +++ b/editor/debugger/debug_adapter/debug_adapter_protocol.cpp @@ -649,6 +649,28 @@ int DebugAdapterProtocol::parse_variant(const Variant &p_var) { variable_list.insert(id, arr); return id; } + case Variant::PACKED_VECTOR4_ARRAY: { + int id = variable_id++; + PackedVector4Array array = p_var; + DAP::Variable size; + size.name = "size"; + size.type = Variant::get_type_name(Variant::INT); + size.value = itos(array.size()); + + Array arr; + arr.push_back(size.to_json()); + + for (int i = 0; i < array.size(); i++) { + DAP::Variable var; + var.name = itos(i); + var.type = Variant::get_type_name(Variant::VECTOR4); + var.value = array[i]; + var.variablesReference = parse_variant(array[i]); + arr.push_back(var.to_json()); + } + variable_list.insert(id, arr); + return id; + } default: // Simple atomic stuff, or too complex to be manipulated return 0; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 63c2ebe3d978..d0ad0e8b1150 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -93,6 +93,7 @@ const Vector classes_with_csharp_differences = { "PackedStringArray", "PackedVector2Array", "PackedVector3Array", + "PackedVector4Array", "Variant", }; #endif @@ -107,6 +108,7 @@ const Vector packed_array_types = { "PackedStringArray", "PackedVector2Array", "PackedVector3Array", + "PackedVector4Array", }; // TODO: this is sometimes used directly as doc->something, other times as EditorHelp::get_doc_data(), which is thread-safe. diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index f34994a10d7f..9cb5fcc18cc1 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -3911,6 +3911,11 @@ EditorProperty *EditorInspectorDefaultPlugin::get_editor_for_property(Object *p_ editor->setup(Variant::PACKED_COLOR_ARRAY, p_hint_text); return editor; } break; + case Variant::PACKED_VECTOR4_ARRAY: { + EditorPropertyArray *editor = memnew(EditorPropertyArray); + editor->setup(Variant::PACKED_VECTOR4_ARRAY, p_hint_text); + return editor; + } break; default: { } } diff --git a/editor/icons/PackedVector4Array.svg b/editor/icons/PackedVector4Array.svg new file mode 100644 index 000000000000..3b550c6005d7 --- /dev/null +++ b/editor/icons/PackedVector4Array.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index d7af751f956d..fceda52a3eab 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -162,7 +162,8 @@ void PropertySelector::_update_search() { search_options->get_editor_theme_icon(SNAME("PackedStringArray")), search_options->get_editor_theme_icon(SNAME("PackedVector2Array")), search_options->get_editor_theme_icon(SNAME("PackedVector3Array")), - search_options->get_editor_theme_icon(SNAME("PackedColorArray")) + search_options->get_editor_theme_icon(SNAME("PackedColorArray")), + search_options->get_editor_theme_icon(SNAME("PackedVector4Array")), }; static_assert((sizeof(type_icons) / sizeof(type_icons[0])) == Variant::VARIANT_MAX, "Number of type icons doesn't match the number of Variant types."); diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index ec20811385f0..279be65f0348 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -3030,6 +3030,7 @@ void GDScriptAnalyzer::reduce_call(GDScriptParser::CallNode *p_call, bool p_is_a case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: safe_to_fold = false; break; default: @@ -4425,7 +4426,6 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri switch (base_type.builtin_type) { // Expect int or real as index. case Variant::PACKED_BYTE_ARRAY: - case Variant::PACKED_COLOR_ARRAY: case Variant::PACKED_FLOAT32_ARRAY: case Variant::PACKED_FLOAT64_ARRAY: case Variant::PACKED_INT32_ARRAY: @@ -4433,6 +4433,8 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri case Variant::PACKED_STRING_ARRAY: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: + case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::ARRAY: case Variant::STRING: error = index_type.builtin_type != Variant::INT && index_type.builtin_type != Variant::FLOAT; @@ -4531,10 +4533,6 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri case Variant::QUATERNION: result_type.builtin_type = Variant::FLOAT; break; - // Return Color. - case Variant::PACKED_COLOR_ARRAY: - result_type.builtin_type = Variant::COLOR; - break; // Return String. case Variant::PACKED_STRING_ARRAY: case Variant::STRING: @@ -4556,6 +4554,14 @@ void GDScriptAnalyzer::reduce_subscript(GDScriptParser::SubscriptNode *p_subscri case Variant::BASIS: result_type.builtin_type = Variant::VECTOR3; break; + // Return Color. + case Variant::PACKED_COLOR_ARRAY: + result_type.builtin_type = Variant::COLOR; + break; + // Return Vector4. + case Variant::PACKED_VECTOR4_ARRAY: + result_type.builtin_type = Variant::VECTOR4; + break; // Depends on the index. case Variant::TRANSFORM3D: case Variant::PROJECTION: diff --git a/modules/gdscript/gdscript_byte_codegen.cpp b/modules/gdscript/gdscript_byte_codegen.cpp index 5a50bd86487b..4cda3d303753 100644 --- a/modules/gdscript/gdscript_byte_codegen.cpp +++ b/modules/gdscript/gdscript_byte_codegen.cpp @@ -109,6 +109,7 @@ uint32_t GDScriptByteCodeGenerator::add_temporary(const GDScriptDataType &p_type case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::VARIANT_MAX: // Arrays, dictionaries, and objects are reference counted, so we don't use the pool for them. temp_type = Variant::NIL; @@ -543,6 +544,9 @@ void GDScriptByteCodeGenerator::write_type_adjust(const Address &p_target, Varia case Variant::PACKED_COLOR_ARRAY: append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_COLOR_ARRAY); break; + case Variant::PACKED_VECTOR4_ARRAY: + append_opcode(GDScriptFunction::OPCODE_TYPE_ADJUST_PACKED_VECTOR4_ARRAY); + break; case Variant::NIL: case Variant::VARIANT_MAX: return; @@ -1573,6 +1577,10 @@ void GDScriptByteCodeGenerator::write_for(const Address &p_variable, bool p_use_ begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY; iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_COLOR_ARRAY; break; + case Variant::PACKED_VECTOR4_ARRAY: + begin_opcode = GDScriptFunction::OPCODE_ITERATE_BEGIN_PACKED_VECTOR4_ARRAY; + iterate_opcode = GDScriptFunction::OPCODE_ITERATE_PACKED_VECTOR4_ARRAY; + break; default: break; } diff --git a/modules/gdscript/gdscript_disassembler.cpp b/modules/gdscript/gdscript_disassembler.cpp index 8dd04c76dd78..03310450780e 100644 --- a/modules/gdscript/gdscript_disassembler.cpp +++ b/modules/gdscript/gdscript_disassembler.cpp @@ -1046,6 +1046,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { m_macro(PACKED_VECTOR2_ARRAY); \ m_macro(PACKED_VECTOR3_ARRAY); \ m_macro(PACKED_COLOR_ARRAY); \ + m_macro(PACKED_VECTOR4_ARRAY); \ m_macro(OBJECT) case OPCODE_ITERATE_BEGIN: { @@ -1150,6 +1151,7 @@ void GDScriptFunction::disassemble(const Vector &p_code_lines) const { DISASSEMBLE_TYPE_ADJUST(PACKED_VECTOR2_ARRAY); DISASSEMBLE_TYPE_ADJUST(PACKED_VECTOR3_ARRAY); DISASSEMBLE_TYPE_ADJUST(PACKED_COLOR_ARRAY); + DISASSEMBLE_TYPE_ADJUST(PACKED_VECTOR4_ARRAY); case OPCODE_ASSERT: { text += "assert ("; diff --git a/modules/gdscript/gdscript_function.h b/modules/gdscript/gdscript_function.h index 430b96115bdb..759e92d68ce5 100644 --- a/modules/gdscript/gdscript_function.h +++ b/modules/gdscript/gdscript_function.h @@ -301,6 +301,7 @@ public: OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY, OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY, OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY, + OPCODE_ITERATE_BEGIN_PACKED_VECTOR4_ARRAY, OPCODE_ITERATE_BEGIN_OBJECT, OPCODE_ITERATE, OPCODE_ITERATE_INT, @@ -321,6 +322,7 @@ public: OPCODE_ITERATE_PACKED_VECTOR2_ARRAY, OPCODE_ITERATE_PACKED_VECTOR3_ARRAY, OPCODE_ITERATE_PACKED_COLOR_ARRAY, + OPCODE_ITERATE_PACKED_VECTOR4_ARRAY, OPCODE_ITERATE_OBJECT, OPCODE_STORE_GLOBAL, OPCODE_STORE_NAMED_GLOBAL, @@ -361,6 +363,7 @@ public: OPCODE_TYPE_ADJUST_PACKED_VECTOR2_ARRAY, OPCODE_TYPE_ADJUST_PACKED_VECTOR3_ARRAY, OPCODE_TYPE_ADJUST_PACKED_COLOR_ARRAY, + OPCODE_TYPE_ADJUST_PACKED_VECTOR4_ARRAY, OPCODE_ASSERT, OPCODE_BREAKPOINT, OPCODE_LINE, diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 9799c6e610ec..634d4fc86709 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4129,6 +4129,9 @@ static String _get_annotation_error_string(const StringName &p_annotation_name, case Variant::COLOR: types.push_back("PackedColorArray"); break; + case Variant::VECTOR4: + types.push_back("PackedVector4Array"); + break; default: break; } @@ -4827,6 +4830,8 @@ static Variant::Type _variant_type_to_typed_array_element_type(Variant::Type p_t return Variant::VECTOR3; case Variant::PACKED_COLOR_ARRAY: return Variant::COLOR; + case Variant::PACKED_VECTOR4_ARRAY: + return Variant::VECTOR4; default: return Variant::NIL; } diff --git a/modules/gdscript/gdscript_utility_functions.cpp b/modules/gdscript/gdscript_utility_functions.cpp index e5b0f55df8ae..f0816650b983 100644 --- a/modules/gdscript/gdscript_utility_functions.cpp +++ b/modules/gdscript/gdscript_utility_functions.cpp @@ -519,6 +519,10 @@ struct GDScriptUtilityFunctionsDefinitions { Vector d = *p_args[0]; *r_ret = d.size(); } break; + case Variant::PACKED_VECTOR4_ARRAY: { + Vector d = *p_args[0]; + *r_ret = d.size(); + } break; default: { r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; diff --git a/modules/gdscript/gdscript_vm.cpp b/modules/gdscript/gdscript_vm.cpp index 4e76965889f3..11bd1d224a86 100644 --- a/modules/gdscript/gdscript_vm.cpp +++ b/modules/gdscript/gdscript_vm.cpp @@ -208,6 +208,7 @@ void (*type_init_function_table[])(Variant *) = { &VariantInitializer::init, // PACKED_VECTOR2_ARRAY. &VariantInitializer::init, // PACKED_VECTOR3_ARRAY. &VariantInitializer::init, // PACKED_COLOR_ARRAY. + &VariantInitializer::init, // PACKED_VECTOR4_ARRAY. }; #if defined(__GNUC__) @@ -298,6 +299,7 @@ void (*type_init_function_table[])(Variant *) = { &&OPCODE_ITERATE_BEGIN_PACKED_VECTOR2_ARRAY, \ &&OPCODE_ITERATE_BEGIN_PACKED_VECTOR3_ARRAY, \ &&OPCODE_ITERATE_BEGIN_PACKED_COLOR_ARRAY, \ + &&OPCODE_ITERATE_BEGIN_PACKED_VECTOR4_ARRAY, \ &&OPCODE_ITERATE_BEGIN_OBJECT, \ &&OPCODE_ITERATE, \ &&OPCODE_ITERATE_INT, \ @@ -318,6 +320,7 @@ void (*type_init_function_table[])(Variant *) = { &&OPCODE_ITERATE_PACKED_VECTOR2_ARRAY, \ &&OPCODE_ITERATE_PACKED_VECTOR3_ARRAY, \ &&OPCODE_ITERATE_PACKED_COLOR_ARRAY, \ + &&OPCODE_ITERATE_PACKED_VECTOR4_ARRAY, \ &&OPCODE_ITERATE_OBJECT, \ &&OPCODE_STORE_GLOBAL, \ &&OPCODE_STORE_NAMED_GLOBAL, \ @@ -358,6 +361,7 @@ void (*type_init_function_table[])(Variant *) = { &&OPCODE_TYPE_ADJUST_PACKED_VECTOR2_ARRAY, \ &&OPCODE_TYPE_ADJUST_PACKED_VECTOR3_ARRAY, \ &&OPCODE_TYPE_ADJUST_PACKED_COLOR_ARRAY, \ + &&OPCODE_TYPE_ADJUST_PACKED_VECTOR4_ARRAY, \ &&OPCODE_ASSERT, \ &&OPCODE_BREAKPOINT, \ &&OPCODE_LINE, \ @@ -430,6 +434,7 @@ void (*type_init_function_table[])(Variant *) = { #define OP_GET_PACKED_VECTOR2_ARRAY get_vector2_array #define OP_GET_PACKED_VECTOR3_ARRAY get_vector3_array #define OP_GET_PACKED_COLOR_ARRAY get_color_array +#define OP_GET_PACKED_VECTOR4_ARRAY get_vector4_array #define OP_GET_TRANSFORM3D get_transform #define OP_GET_TRANSFORM2D get_transform2d #define OP_GET_PROJECTION get_projection @@ -3059,6 +3064,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_ITERATE_BEGIN_PACKED_ARRAY(VECTOR2, Vector2, get_vector2_array, VECTOR2, Vector2, get_vector2); OPCODE_ITERATE_BEGIN_PACKED_ARRAY(VECTOR3, Vector3, get_vector3_array, VECTOR3, Vector3, get_vector3); OPCODE_ITERATE_BEGIN_PACKED_ARRAY(COLOR, Color, get_color_array, COLOR, Color, get_color); + OPCODE_ITERATE_BEGIN_PACKED_ARRAY(VECTOR4, Vector4, get_vector4_array, VECTOR4, Vector4, get_vector4); OPCODE(OPCODE_ITERATE_BEGIN_OBJECT) { CHECK_SPACE(4); @@ -3394,6 +3400,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_ITERATE_PACKED_ARRAY(VECTOR2, Vector2, get_vector2_array, get_vector2); OPCODE_ITERATE_PACKED_ARRAY(VECTOR3, Vector3, get_vector3_array, get_vector3); OPCODE_ITERATE_PACKED_ARRAY(COLOR, Color, get_color_array, get_color); + OPCODE_ITERATE_PACKED_ARRAY(VECTOR4, Vector4, get_vector4_array, get_vector4); OPCODE(OPCODE_ITERATE_OBJECT) { CHECK_SPACE(4); @@ -3525,6 +3532,7 @@ Variant GDScriptFunction::call(GDScriptInstance *p_instance, const Variant **p_a OPCODE_TYPE_ADJUST(PACKED_VECTOR2_ARRAY, PackedVector2Array); OPCODE_TYPE_ADJUST(PACKED_VECTOR3_ARRAY, PackedVector3Array); OPCODE_TYPE_ADJUST(PACKED_COLOR_ARRAY, PackedColorArray); + OPCODE_TYPE_ADJUST(PACKED_VECTOR4_ARRAY, PackedVector4Array); OPCODE(OPCODE_ASSERT) { CHECK_SPACE(3); diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd index 73d0f9096c67..18675e5725f4 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd @@ -345,3 +345,12 @@ func test(): prints(x and true) prints(x or false) prints(x or true) + + # TYPE_PACKED_VECTOR4_ARRAY + x = PackedVector4Array([Vector4.ONE]) + prints("TYPE_PACKED_VECTOR4_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out index e2945c910aed..47f9d7548bd6 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out @@ -227,3 +227,9 @@ false true true true +TYPE_PACKED_VECTOR4_ARRAY +false +false +true +true +true diff --git a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd index ddfb186aa48c..0d97135a7b8f 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd @@ -63,6 +63,7 @@ var temp_packed_float64_array: PackedFloat64Array var temp_packed_color_array: PackedColorArray var temp_packed_vector2_array: PackedVector2Array var temp_packed_vector3_array: PackedVector3Array +var temp_packed_vector4_array: PackedVector4Array @export var test_weak_packed_byte_array = temp_packed_byte_array @export var test_weak_packed_int32_array = temp_packed_int32_array @@ -72,6 +73,7 @@ var temp_packed_vector3_array: PackedVector3Array @export var test_weak_packed_color_array = temp_packed_color_array @export var test_weak_packed_vector2_array = temp_packed_vector2_array @export var test_weak_packed_vector3_array = temp_packed_vector3_array +@export var test_weak_packed_vector4_array = temp_packed_vector4_array @export_range(1, 10) var test_range_weak_packed_byte_array = temp_packed_byte_array @export_range(1, 10) var test_range_weak_packed_int32_array = temp_packed_int32_array diff --git a/modules/gdscript/tests/scripts/parser/features/export_arrays.out b/modules/gdscript/tests/scripts/parser/features/export_arrays.out index 00e75fcc4364..acbf389645e8 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_arrays.out +++ b/modules/gdscript/tests/scripts/parser/features/export_arrays.out @@ -123,6 +123,8 @@ var test_weak_packed_vector2_array: PackedVector2Array hint=TYPE_STRING hint_string="Vector2:Vector2" usage=DEFAULT|SCRIPT_VARIABLE var test_weak_packed_vector3_array: PackedVector3Array hint=TYPE_STRING hint_string="Vector3:Vector3" usage=DEFAULT|SCRIPT_VARIABLE +var test_weak_packed_vector4_array: PackedVector4Array + hint=TYPE_STRING hint_string="Vector4:Vector4" usage=DEFAULT|SCRIPT_VARIABLE var test_range_weak_packed_byte_array: PackedByteArray hint=TYPE_STRING hint_string="int/RANGE:1,10" usage=DEFAULT|SCRIPT_VARIABLE var test_range_weak_packed_int32_array: PackedInt32Array diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd index 809d0d28a9fd..5d8dafc4a1fd 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd @@ -140,3 +140,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(value == null) + + # PackedVector4Array + value = PackedVector4Array() + print(value == null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out index 27423ab8e7a8..e0e222eccc99 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out @@ -34,3 +34,4 @@ false false false false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd index f46afb0f18c2..88286ede0338 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd @@ -140,3 +140,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(value != null) + + # PackedVector4Array + value = PackedVector4Array() + print(value != null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out index a11c47854a17..f6e72aedd56f 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out @@ -34,3 +34,4 @@ true true true true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd index 7649062fdaa8..6ca1b3e490ae 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd @@ -136,3 +136,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(null == value) + + # PackedVector4Array + value = PackedVector4Array() + print(null == value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out index 639f6027b96a..27423ab8e7a8 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out @@ -33,3 +33,4 @@ false false false false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd index 8d5f9df1b82c..d7addfa3909c 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd @@ -136,3 +136,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(null != value) + + # PackedVector4Array + value = PackedVector4Array() + print(null != value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out index d1e332afbaae..a11c47854a17 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out @@ -33,3 +33,4 @@ true true true true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.gd b/modules/gdscript/tests/scripts/runtime/features/stringify.gd index 0dbb252b0e3f..8579baf8766d 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.gd +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.gd @@ -40,3 +40,4 @@ func test(): print(PackedVector2Array([Vector2.ONE, Vector2.ZERO])) print(PackedVector3Array([Vector3.ONE, Vector3.ZERO])) print(PackedColorArray([Color.RED, Color.BLUE, Color.GREEN])) + print(PackedVector4Array([Vector4.ONE, Vector4.ZERO])) diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.out b/modules/gdscript/tests/scripts/runtime/features/stringify.out index 1f33de00ccee..7833b6e213a8 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.out +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.out @@ -32,3 +32,4 @@ Node::[signal]property_list_changed [(1, 1), (0, 0)] [(1, 1, 1), (0, 0, 0)] [(1, 0, 0, 1), (0, 0, 1, 1), (0, 1, 0, 1)] +[(1, 1, 1, 1), (0, 0, 0, 0)] diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs index 834beaa1311c..4cf6a9f431e5 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/GodotEnums.cs @@ -44,7 +44,8 @@ namespace Godot.SourceGenerators PackedVector2Array = 35, PackedVector3Array = 36, PackedColorArray = 37, - Max = 38 + PackedVector4Array = 38, + Max = 39 } internal enum PropertyHint diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs index be6af117ebaf..bfb735e72ff2 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalType.cs @@ -51,6 +51,7 @@ namespace Godot.SourceGenerators StringArray, Vector2Array, Vector3Array, + Vector4Array, ColorArray, GodotObjectOrDerivedArray, SystemArrayOfStringName, diff --git a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs index 0258f53062fa..d27283295052 100644 --- a/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs +++ b/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/MarshalUtils.cs @@ -66,6 +66,7 @@ namespace Godot.SourceGenerators MarshalType.StringArray => VariantType.PackedStringArray, MarshalType.Vector2Array => VariantType.PackedVector2Array, MarshalType.Vector3Array => VariantType.PackedVector3Array, + MarshalType.Vector4Array => VariantType.PackedVector4Array, MarshalType.ColorArray => VariantType.PackedColorArray, MarshalType.GodotObjectOrDerivedArray => VariantType.Array, MarshalType.SystemArrayOfStringName => VariantType.Array, @@ -190,6 +191,8 @@ namespace Godot.SourceGenerators return MarshalType.Vector2Array; case { Name: "Vector3" }: return MarshalType.Vector3Array; + case { Name: "Vector4" }: + return MarshalType.Vector4Array; case { Name: "Color" }: return MarshalType.ColorArray; case { Name: "StringName" }: diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp index e1ce41edd5e2..db86693a5808 100644 --- a/modules/mono/editor/bindings_generator.cpp +++ b/modules/mono/editor/bindings_generator.cpp @@ -330,6 +330,8 @@ String BindingsGenerator::bbcode_to_text(const String &p_bbcode, const TypeInter output.append("'" BINDINGS_NAMESPACE ".Vector3[]'"); } else if (tag == "PackedColorArray") { output.append("'" BINDINGS_NAMESPACE ".Color[]'"); + } else if (tag == "PackedVector4Array") { + output.append("'" BINDINGS_NAMESPACE ".Vector4[]'"); } else { const TypeInterface *target_itype = _get_type_or_null(TypeReference(tag)); @@ -646,6 +648,8 @@ String BindingsGenerator::bbcode_to_xml(const String &p_bbcode, const TypeInterf xml_output.append("[]"); } else if (tag == "PackedColorArray") { xml_output.append("[]"); + } else if (tag == "PackedVector4Array") { + xml_output.append("[]"); } else { const TypeInterface *target_itype = _get_type_or_null(TypeReference(tag)); @@ -3516,6 +3520,7 @@ bool BindingsGenerator::_arg_default_value_is_assignable_to_type(const Variant & case Variant::PACKED_STRING_ARRAY: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::PACKED_COLOR_ARRAY: case Variant::CALLABLE: case Variant::SIGNAL: @@ -4246,6 +4251,7 @@ bool BindingsGenerator::_arg_default_value_from_variant(const Variant &p_val, Ar case Variant::PACKED_STRING_ARRAY: case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::PACKED_COLOR_ARRAY: r_iarg.default_argument = "Array.Empty<%s>()"; r_iarg.def_param_mode = ArgumentInterface::NULLABLE_REF; @@ -4585,6 +4591,7 @@ void BindingsGenerator::_populate_builtin_type_interfaces() { INSERT_ARRAY(PackedColorArray, godot_packed_color_array, Color); INSERT_ARRAY(PackedVector2Array, godot_packed_vector2_array, Vector2); INSERT_ARRAY(PackedVector3Array, godot_packed_vector3_array, Vector3); + INSERT_ARRAY(PackedVector4Array, godot_packed_vector4_array, Vector4); #undef INSERT_ARRAY diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h index a397dcb02667..556d287af4ef 100644 --- a/modules/mono/editor/bindings_generator.h +++ b/modules/mono/editor/bindings_generator.h @@ -705,7 +705,7 @@ class BindingsGenerator { StringName type_Vector4i = StaticCString::create("Vector4i"); // Object not included as it must be checked for all derived classes - static constexpr int nullable_types_count = 18; + static constexpr int nullable_types_count = 19; StringName nullable_types[nullable_types_count] = { type_String, type_StringName, @@ -727,6 +727,7 @@ class BindingsGenerator { StaticCString::create(_STR(PackedVector2Array)), StaticCString::create(_STR(PackedVector3Array)), StaticCString::create(_STR(PackedColorArray)), + StaticCString::create(_STR(PackedVector4Array)), }; bool is_nullable_type(const StringName &p_type) const { diff --git a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs index f3f6759e1de4..08e293afcc27 100644 --- a/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs +++ b/modules/mono/glue/GodotSharp/Godot.SourceGenerators.Internal/UnmanagedCallbacksGenerator.cs @@ -468,6 +468,7 @@ using Godot.NativeInterop; "Godot.NativeInterop.godot_packed_string_array", "Godot.NativeInterop.godot_packed_vector2_array", "Godot.NativeInterop.godot_packed_vector3_array", + "Godot.NativeInterop.godot_packed_vector4_array", "Godot.NativeInterop.godot_packed_color_array", }; } diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/CustomUnsafe.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/CustomUnsafe.cs index afef20a7f227..171cf86edb1d 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/CustomUnsafe.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/CustomUnsafe.cs @@ -295,6 +295,22 @@ public static class CustomUnsafe public static unsafe ref godot_packed_vector3_array AsRef(in godot_packed_vector3_array source) => ref *ReadOnlyRefAsPointer(in source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe godot_packed_vector4_array* AsPointer(ref godot_packed_vector4_array value) + => value.GetUnsafeAddress(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe godot_packed_vector4_array* ReadOnlyRefAsPointer(in godot_packed_vector4_array value) + => value.GetUnsafeAddress(); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe ref godot_packed_vector4_array AsRef(godot_packed_vector4_array* source) + => ref *source; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static unsafe ref godot_packed_vector4_array AsRef(in godot_packed_vector4_array source) + => ref *ReadOnlyRefAsPointer(in source); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static unsafe godot_packed_color_array* AsPointer(ref godot_packed_color_array value) => value.GetUnsafeAddress(); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs index a019dd351372..7e5c01d0f883 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/InteropStructs.cs @@ -1134,6 +1134,39 @@ namespace Godot.NativeInterop } [StructLayout(LayoutKind.Sequential)] + // ReSharper disable once InconsistentNaming + public ref struct godot_packed_vector4_array + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal readonly unsafe godot_packed_vector4_array* GetUnsafeAddress() + => (godot_packed_vector4_array*)Unsafe.AsPointer(ref Unsafe.AsRef(in _writeProxy)); + + private IntPtr _writeProxy; + private unsafe Vector4* _ptr; + + public unsafe void Dispose() + { + if (_ptr == null) + return; + NativeFuncs.godotsharp_packed_vector4_array_destroy(ref this); + _ptr = null; + } + + public readonly unsafe Vector4* Buffer + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _ptr; + } + + public readonly unsafe int Size + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get => _ptr != null ? (int)(*((ulong*)_ptr - 1)) : 0; + } + } + + [StructLayout(LayoutKind.Sequential)] + // ReSharper disable once InconsistentNaming public ref struct godot_packed_color_array { [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs index 9f7fa53e24eb..15b7ce7c73f4 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/Marshaling.cs @@ -133,6 +133,9 @@ namespace Godot.NativeInterop if (type == typeof(Vector3[])) return Variant.Type.PackedVector3Array; + if (type == typeof(Vector4[])) + return Variant.Type.PackedVector4Array; + if (type == typeof(Color[])) return Variant.Type.PackedColorArray; @@ -574,6 +577,30 @@ namespace Godot.NativeInterop return NativeFuncs.godotsharp_packed_vector3_array_new_mem_copy(src, p_array.Length); } + // PackedVector4Array + + public static unsafe Vector4[] ConvertNativePackedVector4ArrayToSystemArray(godot_packed_vector4_array p_array) + { + Vector4* buffer = p_array.Buffer; + int size = p_array.Size; + if (size == 0) + return Array.Empty(); + int sizeInBytes = size * sizeof(Vector4); + var array = new Vector4[size]; + fixed (Vector4* dest = array) + Buffer.MemoryCopy(buffer, dest, sizeInBytes, sizeInBytes); + return array; + } + + public static unsafe godot_packed_vector4_array ConvertSystemArrayToNativePackedVector4Array( + Span p_array) + { + if (p_array.IsEmpty) + return new godot_packed_vector4_array(); + fixed (Vector4* src = p_array) + return NativeFuncs.godotsharp_packed_vector4_array_new_mem_copy(src, p_array.Length); + } + // PackedColorArray public static unsafe Color[] ConvertNativePackedColorArrayToSystemArray(godot_packed_color_array p_array) diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs index fef21fae468d..c4fd639ccedd 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/NativeFuncs.cs @@ -144,6 +144,9 @@ namespace Godot.NativeInterop public static partial godot_packed_vector3_array godotsharp_packed_vector3_array_new_mem_copy(Vector3* p_src, int p_length); + public static partial godot_packed_vector4_array godotsharp_packed_vector4_array_new_mem_copy(Vector4* p_src, + int p_length); + public static partial godot_packed_color_array godotsharp_packed_color_array_new_mem_copy(Color* p_src, int p_length); @@ -224,6 +227,9 @@ namespace Godot.NativeInterop public static partial void godotsharp_variant_new_packed_vector3_array(out godot_variant r_dest, in godot_packed_vector3_array p_pv3a); + public static partial void godotsharp_variant_new_packed_vector4_array(out godot_variant r_dest, + in godot_packed_vector4_array p_pv4a); + public static partial void godotsharp_variant_new_packed_color_array(out godot_variant r_dest, in godot_packed_color_array p_pca); @@ -302,6 +308,9 @@ namespace Godot.NativeInterop public static partial godot_packed_vector3_array godotsharp_variant_as_packed_vector3_array( in godot_variant p_self); + public static partial godot_packed_vector4_array godotsharp_variant_as_packed_vector4_array( + in godot_variant p_self); + public static partial godot_packed_color_array godotsharp_variant_as_packed_color_array(in godot_variant p_self); public static partial godot_bool godotsharp_variant_equals(in godot_variant p_a, in godot_variant p_b); @@ -352,6 +361,8 @@ namespace Godot.NativeInterop public static partial void godotsharp_packed_vector3_array_destroy(ref godot_packed_vector3_array p_self); + public static partial void godotsharp_packed_vector4_array_destroy(ref godot_packed_vector4_array p_self); + public static partial void godotsharp_packed_color_array_destroy(ref godot_packed_color_array p_self); public static partial void godotsharp_variant_destroy(ref godot_variant p_self); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs index 94609984ac02..dc151e2c3eee 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.cs @@ -165,6 +165,12 @@ namespace Godot.NativeInterop return ret; } + public static godot_variant CreateFromPackedVector4Array(in godot_packed_vector4_array from) + { + NativeFuncs.godotsharp_variant_new_packed_vector4_array(out godot_variant ret, from); + return ret; + } + public static godot_variant CreateFromPackedColorArray(in godot_packed_color_array from) { NativeFuncs.godotsharp_variant_new_packed_color_array(out godot_variant ret, from); @@ -227,6 +233,13 @@ namespace Godot.NativeInterop return CreateFromPackedVector3Array(nativePackedArray); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static godot_variant CreateFromPackedVector4Array(Span from) + { + using var nativePackedArray = Marshaling.ConvertSystemArrayToNativePackedVector4Array(from); + return CreateFromPackedVector4Array(nativePackedArray); + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static godot_variant CreateFromPackedColorArray(Span from) { @@ -605,6 +618,12 @@ namespace Godot.NativeInterop return Marshaling.ConvertNativePackedVector3ArrayToSystemArray(packedArray); } + public static Vector4[] ConvertAsPackedVector4ArrayToSystemArray(in godot_variant p_var) + { + using var packedArray = NativeFuncs.godotsharp_variant_as_packed_vector4_array(p_var); + return Marshaling.ConvertNativePackedVector4ArrayToSystemArray(packedArray); + } + public static Color[] ConvertAsPackedColorArrayToSystemArray(in godot_variant p_var) { using var packedArray = NativeFuncs.godotsharp_variant_as_packed_color_array(p_var); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs index d8f7214c2fc9..2897cc4199e6 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/NativeInterop/VariantUtils.generic.cs @@ -155,6 +155,9 @@ public partial class VariantUtils if (typeof(T) == typeof(Vector3[])) return CreateFromPackedVector3Array(UnsafeAs(from)); + if (typeof(T) == typeof(Vector4[])) + return CreateFromPackedVector4Array(UnsafeAs(from)); + if (typeof(T) == typeof(Color[])) return CreateFromPackedColorArray(UnsafeAs(from)); @@ -343,6 +346,9 @@ public partial class VariantUtils if (typeof(T) == typeof(Vector3[])) return UnsafeAsT(ConvertAsPackedVector3ArrayToSystemArray(variant)); + if (typeof(T) == typeof(Vector4[])) + return UnsafeAsT(ConvertAsPackedVector4ArrayToSystemArray(variant)); + if (typeof(T) == typeof(Color[])) return UnsafeAsT(ConvertAsPackedColorArrayToSystemArray(variant)); diff --git a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs index c2d3050adcb0..b40f524859db 100644 --- a/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs +++ b/modules/mono/glue/GodotSharp/GodotSharp/Core/Variant.cs @@ -149,6 +149,7 @@ public partial struct Variant : IDisposable Type.PackedStringArray => AsStringArray(), Type.PackedVector2Array => AsVector2Array(), Type.PackedVector3Array => AsVector3Array(), + Type.PackedVector4Array => AsVector4Array(), Type.PackedColorArray => AsColorArray(), Type.Nil => null, Type.Max or _ => @@ -319,6 +320,10 @@ public partial struct Variant : IDisposable public Vector3[] AsVector3Array() => VariantUtils.ConvertAsPackedVector3ArrayToSystemArray((godot_variant)NativeVar); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Vector4[] AsVector4Array() => + VariantUtils.ConvertAsPackedVector4ArrayToSystemArray((godot_variant)NativeVar); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public Color[] AsColorArray() => VariantUtils.ConvertAsPackedColorArrayToSystemArray((godot_variant)NativeVar); @@ -491,6 +496,9 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Vector3[](Variant from) => from.AsVector3Array(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static explicit operator Vector4[](Variant from) => from.AsVector4Array(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static explicit operator Color[](Variant from) => from.AsColorArray(); @@ -641,6 +649,9 @@ public partial struct Variant : IDisposable [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Variant CreateFrom(Span from) => from; + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static Variant CreateFrom(Span from) => from; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Variant CreateFrom(Span from) => from; @@ -840,6 +851,10 @@ public partial struct Variant : IDisposable public static implicit operator Variant(Vector3[] from) => (Variant)from.AsSpan(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Vector4[] from) => + (Variant)from.AsSpan(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Variant(Color[] from) => (Variant)from.AsSpan(); @@ -892,6 +907,10 @@ public partial struct Variant : IDisposable public static implicit operator Variant(Span from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromPackedVector3Array(from)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static implicit operator Variant(Span from) => + CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromPackedVector4Array(from)); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static implicit operator Variant(Span from) => CreateTakingOwnershipOfDisposableValue(VariantUtils.CreateFromPackedColorArray(from)); diff --git a/modules/mono/glue/runtime_interop.cpp b/modules/mono/glue/runtime_interop.cpp index 4bb324c0eef9..1af462dafd2e 100644 --- a/modules/mono/glue/runtime_interop.cpp +++ b/modules/mono/glue/runtime_interop.cpp @@ -461,6 +461,16 @@ godot_packed_array godotsharp_packed_vector3_array_new_mem_copy(const Vector3 *p return ret; } +godot_packed_array godotsharp_packed_vector4_array_new_mem_copy(const Vector4 *p_src, int32_t p_length) { + godot_packed_array ret; + memnew_placement(&ret, PackedVector4Array); + PackedVector4Array *array = reinterpret_cast(&ret); + array->resize(p_length); + Vector4 *dst = array->ptrw(); + memcpy(dst, p_src, p_length * sizeof(Vector4)); + return ret; +} + godot_packed_array godotsharp_packed_color_array_new_mem_copy(const Color *p_src, int32_t p_length) { godot_packed_array ret; memnew_placement(&ret, PackedColorArray); @@ -646,6 +656,10 @@ void godotsharp_variant_new_packed_vector3_array(godot_variant *r_dest, const Pa memnew_placement(r_dest, Variant(*p_pv3a)); } +void godotsharp_variant_new_packed_vector4_array(godot_variant *r_dest, const PackedVector4Array *p_pv4a) { + memnew_placement(r_dest, Variant(*p_pv4a)); +} + void godotsharp_variant_new_packed_color_array(godot_variant *r_dest, const PackedColorArray *p_pca) { memnew_placement(r_dest, Variant(*p_pca)); } @@ -886,6 +900,13 @@ godot_packed_array godotsharp_variant_as_packed_vector3_array(const Variant *p_s return raw_dest; } +godot_packed_array godotsharp_variant_as_packed_vector4_array(const Variant *p_self) { + godot_packed_array raw_dest; + PackedVector4Array *dest = (PackedVector4Array *)&raw_dest; + memnew_placement(dest, PackedVector4Array(p_self->operator PackedVector4Array())); + return raw_dest; +} + godot_packed_array godotsharp_variant_as_packed_color_array(const Variant *p_self) { godot_packed_array raw_dest; PackedColorArray *dest = (PackedColorArray *)&raw_dest; @@ -974,6 +995,10 @@ void godotsharp_packed_vector3_array_destroy(PackedVector3Array *p_self) { p_self->~PackedVector3Array(); } +void godotsharp_packed_vector4_array_destroy(PackedVector4Array *p_self) { + p_self->~PackedVector4Array(); +} + void godotsharp_packed_color_array_destroy(PackedColorArray *p_self) { p_self->~PackedColorArray(); } @@ -1456,6 +1481,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_packed_float64_array_new_mem_copy, (void *)godotsharp_packed_vector2_array_new_mem_copy, (void *)godotsharp_packed_vector3_array_new_mem_copy, + (void *)godotsharp_packed_vector4_array_new_mem_copy, (void *)godotsharp_packed_color_array_new_mem_copy, (void *)godotsharp_packed_string_array_add, (void *)godotsharp_callable_new_with_delegate, @@ -1484,6 +1510,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_variant_new_packed_string_array, (void *)godotsharp_variant_new_packed_vector2_array, (void *)godotsharp_variant_new_packed_vector3_array, + (void *)godotsharp_variant_new_packed_vector4_array, (void *)godotsharp_variant_new_packed_color_array, (void *)godotsharp_variant_as_bool, (void *)godotsharp_variant_as_int, @@ -1520,6 +1547,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_variant_as_packed_string_array, (void *)godotsharp_variant_as_packed_vector2_array, (void *)godotsharp_variant_as_packed_vector3_array, + (void *)godotsharp_variant_as_packed_vector4_array, (void *)godotsharp_variant_as_packed_color_array, (void *)godotsharp_variant_equals, (void *)godotsharp_string_new_with_utf16_chars, @@ -1538,6 +1566,7 @@ static const void *unmanaged_callbacks[]{ (void *)godotsharp_packed_string_array_destroy, (void *)godotsharp_packed_vector2_array_destroy, (void *)godotsharp_packed_vector3_array_destroy, + (void *)godotsharp_packed_vector4_array_destroy, (void *)godotsharp_packed_color_array_destroy, (void *)godotsharp_variant_destroy, (void *)godotsharp_string_destroy, diff --git a/modules/multiplayer/editor/replication_editor.cpp b/modules/multiplayer/editor/replication_editor.cpp index 8453a4147372..73e53a6a07e2 100644 --- a/modules/multiplayer/editor/replication_editor.cpp +++ b/modules/multiplayer/editor/replication_editor.cpp @@ -234,7 +234,8 @@ ReplicationEditor::ReplicationEditor() { Variant::PACKED_STRING_ARRAY, Variant::PACKED_VECTOR2_ARRAY, Variant::PACKED_VECTOR3_ARRAY, - Variant::PACKED_COLOR_ARRAY + Variant::PACKED_COLOR_ARRAY, + Variant::PACKED_VECTOR4_ARRAY, }; prop_selector->set_type_filter(types); prop_selector->connect("selected", callable_mp(this, &ReplicationEditor::_pick_node_property_selected)); diff --git a/platform/windows/godot.natvis b/platform/windows/godot.natvis index d049ed9a3df6..e0d3cfe13a1e 100644 --- a/platform/windows/godot.natvis +++ b/platform/windows/godot.natvis @@ -29,7 +29,7 @@ - + _p && _p->variant_map.head_element ? _p->variant_map.num_elements : 0 @@ -38,7 +38,7 @@ _p ? _p->variant_map.head_element : nullptr next (*this),view(MapHelper) - + @@ -186,6 +186,7 @@ {reinterpret_cast<const Variant::PackedArrayRef<Vector2>*>(_data.packed_array)->array} {reinterpret_cast<const Variant::PackedArrayRef<Vector3>*>(_data.packed_array)->array} {reinterpret_cast<const Variant::PackedArrayRef<Color>*>(_data.packed_array)->array} + {reinterpret_cast<const Variant::PackedArrayRef<Vector4>*>(_data.packed_array)->array} [INVALID] ((String *)(_data._mem))->_cowdata._ptr,s32 @@ -214,12 +215,13 @@ reinterpret_cast<const Variant::PackedArrayRef<unsigned char>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<int>*>(_data.packed_array)->array *reinterpret_cast<PackedInt64Array *>(&_data.packed_array[1]) - reinterpret_cast<const Variant::PackedArrayRef<float>*>(_data.packed_array)->array + reinterpret_cast<const Variant::PackedArrayRef<float>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<double>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<String>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<Vector2>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<Vector3>*>(_data.packed_array)->array reinterpret_cast<const Variant::PackedArrayRef<Color>*>(_data.packed_array)->array + reinterpret_cast<const Variant::PackedArrayRef<Vector4>*>(_data.packed_array)->array diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp index f70a00a9f6ac..2e27ac9198e3 100644 --- a/scene/resources/resource_format_text.cpp +++ b/scene/resources/resource_format_text.cpp @@ -37,11 +37,12 @@ #include "core/object/script_language.h" #include "core/version.h" -// Version 2: changed names for Basis, AABB, Vectors, etc. -// Version 3: new string ID for ext/subresources, breaks forward compat. -// Version 4: PackedByteArray is now stored as base64 encoded. -#define FORMAT_VERSION_COMPAT 3 +// Version 2: Changed names for Basis, AABB, Vectors, etc. +// Version 3: New string ID for ext/subresources, breaks forward compat. +// Version 4: PackedByteArray can be base64 encoded, and PackedVector4Array was added. #define FORMAT_VERSION 4 +// For compat, save as version 3 if not using PackedVector4Array or no big PackedByteArray. +#define FORMAT_VERSION_COMPAT 3 #define BINARY_FORMAT_VERSION 4 @@ -1979,6 +1980,9 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, use_compat = false; } } break; + case Variant::PACKED_VECTOR4_ARRAY: { + use_compat = false; + } break; default: { } } diff --git a/servers/rendering/storage/variant_converters.h b/servers/rendering/storage/variant_converters.h index 7dbdb0f5176a..cee663e878f3 100644 --- a/servers/rendering/storage/variant_converters.h +++ b/servers/rendering/storage/variant_converters.h @@ -239,7 +239,8 @@ inline bool is_convertible_array(Variant::Type type) { return type == Variant::ARRAY || type == Variant::PACKED_VECTOR2_ARRAY || type == Variant::PACKED_VECTOR3_ARRAY || - type == Variant::PACKED_COLOR_ARRAY; + type == Variant::PACKED_COLOR_ARRAY || + type == Variant::PACKED_VECTOR4_ARRAY; } template diff --git a/tests/core/object/test_class_db.h b/tests/core/object/test_class_db.h index 5f7de11c7179..5623c1d495ea 100644 --- a/tests/core/object/test_class_db.h +++ b/tests/core/object/test_class_db.h @@ -141,7 +141,7 @@ struct NamesCache { StringName vector3_type = StaticCString::create("Vector3"); // Object not included as it must be checked for all derived classes - static constexpr int nullable_types_count = 17; + static constexpr int nullable_types_count = 18; StringName nullable_types[nullable_types_count] = { string_type, string_name_type, @@ -161,6 +161,7 @@ struct NamesCache { StaticCString::create(_STR(PackedVector2Array)), StaticCString::create(_STR(PackedVector3Array)), StaticCString::create(_STR(PackedColorArray)), + StaticCString::create(_STR(PackedVector4Array)), }; bool is_nullable_type(const StringName &p_type) const { @@ -258,6 +259,7 @@ bool arg_default_value_is_assignable_to_type(const Context &p_context, const Var case Variant::PACKED_VECTOR2_ARRAY: case Variant::PACKED_VECTOR3_ARRAY: case Variant::PACKED_COLOR_ARRAY: + case Variant::PACKED_VECTOR4_ARRAY: case Variant::CALLABLE: case Variant::SIGNAL: return p_arg_type.name == Variant::get_type_name(p_val.get_type()); diff --git a/tests/core/variant/test_variant.h b/tests/core/variant/test_variant.h index 54ca06c6c426..be615975f889 100644 --- a/tests/core/variant/test_variant.h +++ b/tests/core/variant/test_variant.h @@ -2034,6 +2034,10 @@ TEST_CASE("[Variant] Identity comparison") { CHECK(packed_color_array.identity_compare(packed_color_array)); CHECK_FALSE(packed_color_array.identity_compare(PackedColorArray())); + Variant packed_vector4_array = PackedVector4Array(); + CHECK(packed_vector4_array.identity_compare(packed_vector4_array)); + CHECK_FALSE(packed_vector4_array.identity_compare(PackedVector4Array())); + Variant packed_float32_array = PackedFloat32Array(); CHECK(packed_float32_array.identity_compare(packed_float32_array)); CHECK_FALSE(packed_float32_array.identity_compare(PackedFloat32Array())); diff --git a/tests/test_macros.h b/tests/test_macros.h index 927884dcedf3..25e48c1e059a 100644 --- a/tests/test_macros.h +++ b/tests/test_macros.h @@ -119,6 +119,7 @@ DOCTEST_STRINGIFY_VARIANT(PackedStringArray); DOCTEST_STRINGIFY_VARIANT(PackedVector2Array); DOCTEST_STRINGIFY_VARIANT(PackedVector3Array); DOCTEST_STRINGIFY_VARIANT(PackedColorArray); +DOCTEST_STRINGIFY_VARIANT(PackedVector4Array); // Register test commands to be launched from the command-line. // For instance: REGISTER_TEST_COMMAND("gdscript-parser" &test_parser_func). diff --git a/tests/test_validate_testing.h b/tests/test_validate_testing.h index 4673d42b5a27..f2e3bf3bb451 100644 --- a/tests/test_validate_testing.h +++ b/tests/test_validate_testing.h @@ -181,6 +181,13 @@ TEST_SUITE("Validate tests") { color_arr.push_back(Color(2, 2, 2)); INFO(color_arr); + PackedVector4Array vec4_arr; + vec4_arr.push_back(Vector4(0, 0, 0, 0)); + vec4_arr.push_back(Vector4(1, 1, 1, 1)); + vec4_arr.push_back(Vector4(2, 2, 2, 2)); + vec4_arr.push_back(Vector4(3, 3, 3, 3)); + INFO(vec4_arr); + // doctest string concatenation. CHECK_MESSAGE(true, var, " ", vec2, " ", rect2, " ", color); }