-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add sort and has methods to PackedArrays #32144
Conversation
Perhaps rename |
@Xrayez Thanks for pointing it out, but it might make more sense to rename |
850a58a
to
0904f5f
Compare
That's a separate discussion, but if you want this change in 3.2, consistency is more important than potential future changes. Both Array and Dictionary use |
This PR really overcomplicated things, simply
|
Just a note: |
c2e10d7
to
4d92976
Compare
4d92976
to
3f258ca
Compare
f354233
to
5d00b10
Compare
5d00b10
to
2f81c6a
Compare
Because of the removal of PoolArrays, I basically had to recreate this PR from scratch. Fortunately, it was super simple. Since Since this PR is so simple and I need it for another PR, this should probably be merged soon-ish. |
2f81c6a
to
86ab103
Compare
Updated again, now compatible with Packed(Int32/Int64/Float32/Float64)Arrays. |
core/vector.h
Outdated
bool has(const T &p_val) { | ||
for (int i = 0; i < size(); i++) { | ||
if (get(i) == p_val) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array::has()
relies on find()
, which is also implemented for Vector
/CowData
. Maybe it would be faster than this? (Didn't try.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure which is faster, but they both look similar, and it would be simpler and better for consistency with Array to use find, so I changed it to find.
@@ -2182,6 +2216,8 @@ void register_variant_methods() { | |||
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, remove, INT, "idx", varray()); | |||
ADDFUNC2R(PACKED_COLOR_ARRAY, INT, PackedColorArray, insert, INT, "idx", COLOR, "color", varray()); | |||
ADDFUNC1(PACKED_COLOR_ARRAY, NIL, PackedColorArray, resize, INT, "idx", varray()); | |||
ADDFUNC1R(PACKED_COLOR_ARRAY, BOOL, PackedColorArray, has, COLOR, "value", varray()); | |||
ADDFUNC0(PACKED_COLOR_ARRAY, NIL, PackedColorArray, sort, varray()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since PackedVectors are code types new methods should be added to the GDNative API as well: gdnative_api.json, packed_arrays.cpp, packed_arrays.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info, done.
Thanks! |
Is it possible to remake this pull request for the |
I made this before 3.2 was released, but Akien gave it the 4.0 milestone. |
Yes, because it was made during feature freeze, and so wouldn't be merged during the stage/RC stage for 3.2. A PR gets the milestone matching the version which will be in development when it's meant to be merged in |
This is a backport from 4.0 to 3.x that adds 'sort' and 'has' methods to the following types: - PoolByteArray - PoolIntArray - PoolRealArray - PoolStringArray - PoolVector2Array - PoolVector3Array - PoolColorArray For all the types above, the methods 'sort' and 'has' have been exposed to the GDNative API (v. 1.3) Since the method 'has' was already implemented in GDScript before, in this commit it has been only exposed to GDNative API. The classes documentation is updated. The method 'sort' uses the exisging class "Sorter". Pooled arrays in 4.0 are rewritten, that's why this backport is not completely indentical to the original PR made for 4.0 (see godotengine#32144).
This is a backport from 4.0 to 3.x that adds 'sort' and 'has' methods to the following types: - PoolByteArray - PoolIntArray - PoolRealArray - PoolStringArray - PoolVector2Array - PoolVector3Array - PoolColorArray For all the types above, the methods 'sort' and 'has' have been exposed to the GDNative API (v. 1.3) Since the method 'has' was already implemented in GDScript before, in this commit it has been only exposed to GDNative API. The classes documentation is updated. The method 'sort' uses the exisging class "Sorter". Pooled arrays in 4.0 are rewritten, that's why this backport is not completely indentical to the original PR made for 4.0 (see godotengine#32144).
This PR adds two methods, for sorting using Godot's built-in sorting system, and for checking if it contains a specific value.
The methods are added for
PackedByteArray
,PackedColorArray
,PackedInt32Array
,PackedInt64Array
,PackedFloat32Array
,PackedFloat64Array
,PackedStringArray
,PackedVector2Array
, andPackedVector3Array
. I've exposed the methods to Variant and GDScript, but I also need this functionality internally for #31171