From 2d56e092765affde1904e76fe912329db0e9eab6 Mon Sep 17 00:00:00 2001 From: Jordan Schidlowsky Date: Thu, 17 Dec 2020 14:26:05 -0600 Subject: [PATCH] packed*arrays are pass by ref now. support duplicate and update documentation --- core/templates/vector.h | 4 ++++ core/variant/variant_call.cpp | 9 +++++++++ core/variant/variant_setget.cpp | 18 ++++++++++++++++++ doc/classes/PackedByteArray.xml | 8 +++++++- doc/classes/PackedColorArray.xml | 8 +++++++- doc/classes/PackedFloat32Array.xml | 8 +++++++- doc/classes/PackedFloat64Array.xml | 8 +++++++- doc/classes/PackedInt32Array.xml | 8 +++++++- doc/classes/PackedInt64Array.xml | 8 +++++++- doc/classes/PackedStringArray.xml | 8 +++++++- doc/classes/PackedVector2Array.xml | 8 +++++++- doc/classes/PackedVector3Array.xml | 8 +++++++- 12 files changed, 94 insertions(+), 9 deletions(-) diff --git a/core/templates/vector.h b/core/templates/vector.h index 9d45f7c30a1..7420384bf71 100644 --- a/core/templates/vector.h +++ b/core/templates/vector.h @@ -112,6 +112,10 @@ public: sort_custom<_DefaultComparator>(); } + Vector duplicate() { + return *this; + } + void ordered_insert(const T &p_val) { int i; for (i = 0; i < _cowdata.size(); i++) { diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index d588c838090..0a1af591a1f 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1316,6 +1316,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedByteArray, invert, sarray(), varray()); bind_method(PackedByteArray, subarray, sarray("from", "to"), varray()); bind_method(PackedByteArray, sort, sarray(), varray()); + bind_method(PackedByteArray, duplicate, sarray(), varray()); bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray()); bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray()); @@ -1342,6 +1343,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt32Array, to_byte_array, sarray(), varray()); bind_method(PackedInt32Array, sort, sarray(), varray()); + bind_method(PackedInt32Array, duplicate, sarray(), varray()); /* Int64 Array */ @@ -1359,6 +1361,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedInt64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedInt64Array, to_byte_array, sarray(), varray()); bind_method(PackedInt64Array, sort, sarray(), varray()); + bind_method(PackedInt64Array, duplicate, sarray(), varray()); /* Float32 Array */ @@ -1376,6 +1379,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat32Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat32Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat32Array, sort, sarray(), varray()); + bind_method(PackedFloat32Array, duplicate, sarray(), varray()); /* Float64 Array */ @@ -1393,6 +1397,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedFloat64Array, subarray, sarray("from", "to"), varray()); bind_method(PackedFloat64Array, to_byte_array, sarray(), varray()); bind_method(PackedFloat64Array, sort, sarray(), varray()); + bind_method(PackedFloat64Array, duplicate, sarray(), varray()); /* String Array */ @@ -1410,6 +1415,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedStringArray, subarray, sarray("from", "to"), varray()); bind_method(PackedStringArray, to_byte_array, sarray(), varray()); bind_method(PackedStringArray, sort, sarray(), varray()); + bind_method(PackedStringArray, duplicate, sarray(), varray()); /* Vector2 Array */ @@ -1427,6 +1433,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector2Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector2Array, to_byte_array, sarray(), varray()); bind_method(PackedVector2Array, sort, sarray(), varray()); + bind_method(PackedVector2Array, duplicate, sarray(), varray()); /* Vector3 Array */ @@ -1444,6 +1451,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedVector3Array, subarray, sarray("from", "to"), varray()); bind_method(PackedVector3Array, to_byte_array, sarray(), varray()); bind_method(PackedVector3Array, sort, sarray(), varray()); + bind_method(PackedVector3Array, duplicate, sarray(), varray()); /* Color Array */ @@ -1461,6 +1469,7 @@ static void _register_variant_builtin_methods() { bind_method(PackedColorArray, subarray, sarray("from", "to"), varray()); bind_method(PackedColorArray, to_byte_array, sarray(), varray()); bind_method(PackedColorArray, sort, sarray(), varray()); + bind_method(PackedColorArray, duplicate, sarray(), varray()); /* Register constants */ diff --git a/core/variant/variant_setget.cpp b/core/variant/variant_setget.cpp index cee7465205d..28cf8ef967b 100644 --- a/core/variant/variant_setget.cpp +++ b/core/variant/variant_setget.cpp @@ -2023,6 +2023,24 @@ Variant Variant::duplicate(bool deep) const { return operator Dictionary().duplicate(deep); case ARRAY: return operator Array().duplicate(deep); + case PACKED_BYTE_ARRAY: + return operator Vector().duplicate(); + case PACKED_INT32_ARRAY: + return operator Vector().duplicate(); + case PACKED_INT64_ARRAY: + return operator Vector().duplicate(); + case PACKED_FLOAT32_ARRAY: + return operator Vector().duplicate(); + case PACKED_FLOAT64_ARRAY: + return operator Vector().duplicate(); + case PACKED_STRING_ARRAY: + return operator Vector().duplicate(); + case PACKED_VECTOR2_ARRAY: + return operator Vector().duplicate(); + case PACKED_VECTOR3_ARRAY: + return operator Vector().duplicate(); + case PACKED_COLOR_ARRAY: + return operator Vector().duplicate(); default: return *this; } diff --git a/doc/classes/PackedByteArray.xml b/doc/classes/PackedByteArray.xml index 91d066260be..0cef26df796 100644 --- a/doc/classes/PackedByteArray.xml +++ b/doc/classes/PackedByteArray.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold bytes. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. @@ -86,6 +85,13 @@ GZIP has a maximal compression ratio of 1032:1, meaning it's very possible for a small compressed payload to decompress to a potentially very large output. To guard against this, you may provide a maximum size this function is allowed to allocate in bytes via [code]max_output_size[/code]. Passing -1 will allow for unbounded output. If any positive value is passed, and the decompression exceeds that amount in bytes, then an error will be returned. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedColorArray.xml b/doc/classes/PackedColorArray.xml index 3065d169459..b45e2cbe2eb 100644 --- a/doc/classes/PackedColorArray.xml +++ b/doc/classes/PackedColorArray.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold [Color]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. @@ -53,6 +52,13 @@ Appends a [PackedColorArray] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedFloat32Array.xml b/doc/classes/PackedFloat32Array.xml index ab9594d2e38..d6825dbcd7c 100644 --- a/doc/classes/PackedFloat32Array.xml +++ b/doc/classes/PackedFloat32Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold 32-bit floating-point values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. If you need to pack 64-bit floats tightly, see [PackedFloat64Array]. @@ -54,6 +53,13 @@ Appends a [PackedFloat32Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedFloat64Array.xml b/doc/classes/PackedFloat64Array.xml index 3088aee483b..9b6df93cf5c 100644 --- a/doc/classes/PackedFloat64Array.xml +++ b/doc/classes/PackedFloat64Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold 64-bit floating-point values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. If you only need to pack 32-bit floats tightly, see [PackedFloat32Array] for a more memory-friendly alternative. @@ -54,6 +53,13 @@ Appends a [PackedFloat64Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedInt32Array.xml b/doc/classes/PackedInt32Array.xml index eded545de89..7923b268a4c 100644 --- a/doc/classes/PackedInt32Array.xml +++ b/doc/classes/PackedInt32Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold 32-bit integer values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. [b]Note:[/b] This type stores signed 32-bit integers, which means it can take values in the interval [code][-2^31, 2^31 - 1][/code], i.e. [code][-2147483648, 2147483647][/code]. Exceeding those bounds will wrap around. In comparison, [int] uses signed 64-bit integers which can hold much larger values. If you need to pack 64-bit integers tightly, see [PackedInt64Array]. @@ -54,6 +53,13 @@ Appends a [PackedInt32Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedInt64Array.xml b/doc/classes/PackedInt64Array.xml index 83731b10230..f7e91284109 100644 --- a/doc/classes/PackedInt64Array.xml +++ b/doc/classes/PackedInt64Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold 64-bit integer values. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. [b]Note:[/b] This type stores signed 64-bit integers, which means it can take values in the interval [code][-2^63, 2^63 - 1][/code], i.e. [code][-9223372036854775808, 9223372036854775807][/code]. Exceeding those bounds will wrap around. If you only need to pack 32-bit integers tightly, see [PackedInt32Array] for a more memory-friendly alternative. @@ -54,6 +53,13 @@ Appends a [PackedInt64Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedStringArray.xml b/doc/classes/PackedStringArray.xml index c71f5ffa7e8..1ae0d55177b 100644 --- a/doc/classes/PackedStringArray.xml +++ b/doc/classes/PackedStringArray.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold [String]s. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. https://godotengine.org/asset-library/asset/677 @@ -54,6 +53,13 @@ Appends a [PackedStringArray] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedVector2Array.xml b/doc/classes/PackedVector2Array.xml index 5f68d9256d0..9ab3a03edb9 100644 --- a/doc/classes/PackedVector2Array.xml +++ b/doc/classes/PackedVector2Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold [Vector2]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. https://godotengine.org/asset-library/asset/519 @@ -54,6 +53,13 @@ Appends a [PackedVector2Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + + diff --git a/doc/classes/PackedVector3Array.xml b/doc/classes/PackedVector3Array.xml index e681e1deb74..80787547ac0 100644 --- a/doc/classes/PackedVector3Array.xml +++ b/doc/classes/PackedVector3Array.xml @@ -5,7 +5,6 @@ An [Array] specifically designed to hold [Vector3]. Packs data tightly, so it saves memory for large array sizes. - [b]Note:[/b] This type is passed by value and not by reference. @@ -53,6 +52,13 @@ Appends a [PackedVector3Array] at the end of this array. + + + + + Creates a copy of the array, and returns it. + +