From 9af3a7a709422673e6b12c0437060397b0b2e572 Mon Sep 17 00:00:00 2001 From: Relintai Date: Fri, 29 Jul 2022 21:18:44 +0200 Subject: [PATCH] Ported sort() for poolVectors from https://github.com/godotengine/godot/commit/7b8b91f505d16f73ace0b22b8aa698ea936970c4 . --- core/pool_vector.h | 13 +++++++++++++ core/variant_call.cpp | 18 ++++++++++++++++++ doc/classes/PoolByteArray.xml | 5 +++++ doc/classes/PoolColorArray.xml | 5 +++++ doc/classes/PoolIntArray.xml | 5 +++++ doc/classes/PoolRealArray.xml | 5 +++++ doc/classes/PoolStringArray.xml | 5 +++++ doc/classes/PoolVector2Array.xml | 5 +++++ doc/classes/PoolVector2iArray.xml | 5 +++++ doc/classes/PoolVector3Array.xml | 5 +++++ doc/classes/PoolVector3iArray.xml | 5 +++++ 11 files changed, 76 insertions(+) diff --git a/core/pool_vector.h b/core/pool_vector.h index ccc3c6fcf..7266933c0 100644 --- a/core/pool_vector.h +++ b/core/pool_vector.h @@ -462,6 +462,7 @@ public: } void invert(); + void sort(); void operator=(const PoolVector &p_pool_vector) { _reference(p_pool_vector); @@ -718,4 +719,16 @@ void PoolVector::invert() { } } +template +void PoolVector::sort() { + int len = size(); + if (len == 0) { + return; + } + + Write w = write(); + SortArray sorter; + sorter.sort(w.ptr(), len); +} + #endif // POOL_VECTOR_H diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 3ae75983d..d91ddfe0f 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -771,6 +771,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolByteArray, count); VCALL_LOCALMEM1R(PoolByteArray, has); VCALL_LOCALMEM0(PoolByteArray, clear); + VCALL_LOCALMEM0(PoolByteArray, sort); VCALL_LOCALMEM0R(PoolIntArray, size); VCALL_LOCALMEM0R(PoolIntArray, empty); @@ -790,6 +791,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolIntArray, count); VCALL_LOCALMEM1R(PoolIntArray, has); VCALL_LOCALMEM0(PoolIntArray, clear); + VCALL_LOCALMEM0(PoolIntArray, sort); VCALL_LOCALMEM0R(PoolRealArray, size); VCALL_LOCALMEM0R(PoolRealArray, empty); @@ -809,6 +811,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolRealArray, count); VCALL_LOCALMEM1R(PoolRealArray, has); VCALL_LOCALMEM0(PoolRealArray, clear); + VCALL_LOCALMEM0(PoolRealArray, sort); VCALL_LOCALMEM0R(PoolStringArray, size); VCALL_LOCALMEM0R(PoolStringArray, empty); @@ -829,6 +832,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolStringArray, count); VCALL_LOCALMEM1R(PoolStringArray, has); VCALL_LOCALMEM0(PoolStringArray, clear); + VCALL_LOCALMEM0(PoolStringArray, sort); VCALL_LOCALMEM0R(PoolVector2Array, size); VCALL_LOCALMEM0R(PoolVector2Array, empty); @@ -848,6 +852,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolVector2Array, count); VCALL_LOCALMEM1R(PoolVector2Array, has); VCALL_LOCALMEM0(PoolVector2Array, clear); + VCALL_LOCALMEM0(PoolVector2Array, sort); VCALL_LOCALMEM0R(PoolVector2iArray, size); VCALL_LOCALMEM0R(PoolVector2iArray, empty); @@ -867,6 +872,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolVector2iArray, count); VCALL_LOCALMEM1R(PoolVector2iArray, has); VCALL_LOCALMEM0(PoolVector2iArray, clear); + VCALL_LOCALMEM0(PoolVector2iArray, sort); VCALL_LOCALMEM0R(PoolVector3Array, size); VCALL_LOCALMEM0R(PoolVector3Array, empty); @@ -886,6 +892,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolVector3Array, count); VCALL_LOCALMEM1R(PoolVector3Array, has); VCALL_LOCALMEM0(PoolVector3Array, clear); + VCALL_LOCALMEM0(PoolVector3Array, sort); VCALL_LOCALMEM0R(PoolVector3iArray, size); VCALL_LOCALMEM0R(PoolVector3iArray, empty); @@ -905,6 +912,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolVector3iArray, count); VCALL_LOCALMEM1R(PoolVector3iArray, has); VCALL_LOCALMEM0(PoolVector3iArray, clear); + VCALL_LOCALMEM0(PoolVector3iArray, sort); VCALL_LOCALMEM0R(PoolColorArray, size); VCALL_LOCALMEM0R(PoolColorArray, empty); @@ -924,6 +932,7 @@ struct _VariantCall { VCALL_LOCALMEM1R(PoolColorArray, count); VCALL_LOCALMEM1R(PoolColorArray, has); VCALL_LOCALMEM0(PoolColorArray, clear); + VCALL_LOCALMEM0(PoolColorArray, sort); #define VCALL_PTR0(m_type, m_method) \ static void _call_##m_type##_##m_method(Variant &r_ret, Variant &p_self, const Variant **p_args) { \ @@ -2303,6 +2312,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_BYTE_ARRAY, INT, PoolByteArray, count, INT, "value", varray()); ADDFUNC1R(POOL_BYTE_ARRAY, BOOL, PoolByteArray, has, INT, "value", varray()); ADDFUNC0(POOL_BYTE_ARRAY, NIL, PoolByteArray, clear, varray()); + ADDFUNC0(POOL_BYTE_ARRAY, NIL, PoolByteArray, sort, varray()); ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_ascii, varray()); ADDFUNC0R(POOL_BYTE_ARRAY, STRING, PoolByteArray, get_string_from_utf8, varray()); @@ -2328,6 +2338,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_INT_ARRAY, INT, PoolIntArray, count, INT, "value", varray()); ADDFUNC1R(POOL_INT_ARRAY, BOOL, PoolIntArray, has, INT, "value", varray()); ADDFUNC0(POOL_INT_ARRAY, NIL, PoolIntArray, clear, varray()); + ADDFUNC0(POOL_INT_ARRAY, NIL, PoolIntArray, sort, varray()); ADDFUNC0R(POOL_REAL_ARRAY, INT, PoolRealArray, size, varray()); ADDFUNC0R(POOL_REAL_ARRAY, BOOL, PoolRealArray, empty, varray()); @@ -2346,6 +2357,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_REAL_ARRAY, INT, PoolRealArray, count, REAL, "value", varray()); ADDFUNC1R(POOL_REAL_ARRAY, BOOL, PoolRealArray, has, REAL, "value", varray()); ADDFUNC0(POOL_REAL_ARRAY, NIL, PoolRealArray, clear, varray()); + ADDFUNC0(POOL_REAL_ARRAY, NIL, PoolRealArray, sort, varray()); ADDFUNC0R(POOL_STRING_ARRAY, INT, PoolStringArray, size, varray()); ADDFUNC0R(POOL_STRING_ARRAY, BOOL, PoolStringArray, empty, varray()); @@ -2365,6 +2377,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_STRING_ARRAY, INT, PoolStringArray, count, STRING, "value", varray()); ADDFUNC1R(POOL_STRING_ARRAY, BOOL, PoolStringArray, has, STRING, "value", varray()); ADDFUNC0(POOL_STRING_ARRAY, NIL, PoolStringArray, clear, varray()); + ADDFUNC0(POOL_STRING_ARRAY, NIL, PoolStringArray, sort, varray()); ADDFUNC0R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, size, varray()); ADDFUNC0R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, empty, varray()); @@ -2383,6 +2396,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_VECTOR2_ARRAY, INT, PoolVector2Array, count, VECTOR2, "value", varray()); ADDFUNC1R(POOL_VECTOR2_ARRAY, BOOL, PoolVector2Array, has, VECTOR2, "value", varray()); ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, clear, varray()); + ADDFUNC0(POOL_VECTOR2_ARRAY, NIL, PoolVector2Array, sort, varray()); ADDFUNC0R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, size, varray()); ADDFUNC0R(POOL_VECTOR2I_ARRAY, BOOL, PoolVector2iArray, empty, varray()); @@ -2401,6 +2415,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_VECTOR2I_ARRAY, INT, PoolVector2iArray, count, VECTOR2I, "value", varray()); ADDFUNC1R(POOL_VECTOR2I_ARRAY, BOOL, PoolVector2iArray, has, VECTOR2I, "value", varray()); ADDFUNC0(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, clear, varray()); + ADDFUNC0(POOL_VECTOR2I_ARRAY, NIL, PoolVector2iArray, sort, varray()); ADDFUNC0R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, size, varray()); ADDFUNC0R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, empty, varray()); @@ -2419,6 +2434,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_VECTOR3_ARRAY, INT, PoolVector3Array, count, VECTOR3, "value", varray()); ADDFUNC1R(POOL_VECTOR3_ARRAY, BOOL, PoolVector3Array, has, VECTOR3, "value", varray()); ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, clear, varray()); + ADDFUNC0(POOL_VECTOR3_ARRAY, NIL, PoolVector3Array, sort, varray()); ADDFUNC0R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, size, varray()); ADDFUNC0R(POOL_VECTOR3I_ARRAY, BOOL, PoolVector3iArray, empty, varray()); @@ -2437,6 +2453,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_VECTOR3I_ARRAY, INT, PoolVector3iArray, count, VECTOR3I, "value", varray()); ADDFUNC1R(POOL_VECTOR3I_ARRAY, BOOL, PoolVector3iArray, has, VECTOR3I, "value", varray()); ADDFUNC0(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, clear, varray()); + ADDFUNC0(POOL_VECTOR3I_ARRAY, NIL, PoolVector3iArray, sort, varray()); ADDFUNC0R(POOL_COLOR_ARRAY, INT, PoolColorArray, size, varray()); ADDFUNC0R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, empty, varray()); @@ -2455,6 +2472,7 @@ void register_variant_methods() { ADDFUNC1R(POOL_COLOR_ARRAY, INT, PoolColorArray, count, COLOR, "value", varray()); ADDFUNC1R(POOL_COLOR_ARRAY, BOOL, PoolColorArray, has, COLOR, "value", varray()); ADDFUNC0(POOL_COLOR_ARRAY, NIL, PoolColorArray, clear, varray()); + ADDFUNC0(POOL_COLOR_ARRAY, NIL, PoolColorArray, sort, varray()); //pointerbased diff --git a/doc/classes/PoolByteArray.xml b/doc/classes/PoolByteArray.xml index 4c32f9ba5..9aad6dcf4 100644 --- a/doc/classes/PoolByteArray.xml +++ b/doc/classes/PoolByteArray.xml @@ -178,6 +178,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolColorArray.xml b/doc/classes/PoolColorArray.xml index 27face4b6..3b40ec7a7 100644 --- a/doc/classes/PoolColorArray.xml +++ b/doc/classes/PoolColorArray.xml @@ -129,6 +129,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolIntArray.xml b/doc/classes/PoolIntArray.xml index e66e6d91d..cf12c1a4e 100644 --- a/doc/classes/PoolIntArray.xml +++ b/doc/classes/PoolIntArray.xml @@ -131,6 +131,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolRealArray.xml b/doc/classes/PoolRealArray.xml index 8c1746d3b..481c5b549 100644 --- a/doc/classes/PoolRealArray.xml +++ b/doc/classes/PoolRealArray.xml @@ -131,6 +131,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolStringArray.xml b/doc/classes/PoolStringArray.xml index 98887cffa..d780699d5 100644 --- a/doc/classes/PoolStringArray.xml +++ b/doc/classes/PoolStringArray.xml @@ -137,6 +137,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolVector2Array.xml b/doc/classes/PoolVector2Array.xml index 43647f4ef..b0003da0b 100644 --- a/doc/classes/PoolVector2Array.xml +++ b/doc/classes/PoolVector2Array.xml @@ -130,6 +130,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolVector2iArray.xml b/doc/classes/PoolVector2iArray.xml index bedd97df4..efea6c5c5 100644 --- a/doc/classes/PoolVector2iArray.xml +++ b/doc/classes/PoolVector2iArray.xml @@ -65,6 +65,11 @@ + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolVector3Array.xml b/doc/classes/PoolVector3Array.xml index 62379ebcc..17de8d94f 100644 --- a/doc/classes/PoolVector3Array.xml +++ b/doc/classes/PoolVector3Array.xml @@ -129,6 +129,11 @@ Returns the number of elements in the array. + + + Sorts the elements of the array in ascending order. + + diff --git a/doc/classes/PoolVector3iArray.xml b/doc/classes/PoolVector3iArray.xml index 90dd32ff0..ad5abf663 100644 --- a/doc/classes/PoolVector3iArray.xml +++ b/doc/classes/PoolVector3iArray.xml @@ -65,6 +65,11 @@ + + + Sorts the elements of the array in ascending order. + +