Skip to content

Commit

Permalink
add pop_back method to Packed*Array
Browse files Browse the repository at this point in the history
  • Loading branch information
bend-n committed Oct 9, 2023
1 parent 6916349 commit 18e9218
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/templates/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ class Vector {
bool push_back(T p_elem);
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
void fill(T p_elem);

T pop_back() {
ERR_FAIL_COND_V(_cowdata.is_empty(), T());
T tmp = _cowdata.get(_cowdata.size() - 1);
_cowdata.resize(_cowdata.size() - 1);
return tmp;
}
void remove_at(int p_index) { _cowdata.remove_at(p_index); }
_FORCE_INLINE_ bool erase(const T &p_val) {
int idx = find(p_val);
Expand Down
9 changes: 9 additions & 0 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedByteArray, is_empty, sarray(), varray());
bind_method(PackedByteArray, set, sarray("index", "value"), varray());
bind_method(PackedByteArray, push_back, sarray("value"), varray());
bind_method(PackedByteArray, pop_back, sarray(), varray());
bind_method(PackedByteArray, append, sarray("value"), varray());
bind_method(PackedByteArray, append_array, sarray("array"), varray());
bind_method(PackedByteArray, remove_at, sarray("index"), varray());
Expand Down Expand Up @@ -2318,6 +2319,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt32Array, is_empty, sarray(), varray());
bind_method(PackedInt32Array, set, sarray("index", "value"), varray());
bind_method(PackedInt32Array, push_back, sarray("value"), varray());
bind_method(PackedInt32Array, pop_back, sarray(), varray());
bind_method(PackedInt32Array, append, sarray("value"), varray());
bind_method(PackedInt32Array, append_array, sarray("array"), varray());
bind_method(PackedInt32Array, remove_at, sarray("index"), varray());
Expand All @@ -2342,6 +2344,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedInt64Array, is_empty, sarray(), varray());
bind_method(PackedInt64Array, set, sarray("index", "value"), varray());
bind_method(PackedInt64Array, push_back, sarray("value"), varray());
bind_method(PackedInt64Array, pop_back, sarray(), varray());
bind_method(PackedInt64Array, append, sarray("value"), varray());
bind_method(PackedInt64Array, append_array, sarray("array"), varray());
bind_method(PackedInt64Array, remove_at, sarray("index"), varray());
Expand All @@ -2366,6 +2369,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat32Array, is_empty, sarray(), varray());
bind_method(PackedFloat32Array, set, sarray("index", "value"), varray());
bind_method(PackedFloat32Array, push_back, sarray("value"), varray());
bind_method(PackedFloat32Array, pop_back, sarray(), varray());
bind_method(PackedFloat32Array, append, sarray("value"), varray());
bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
bind_method(PackedFloat32Array, remove_at, sarray("index"), varray());
Expand All @@ -2390,6 +2394,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedFloat64Array, is_empty, sarray(), varray());
bind_method(PackedFloat64Array, set, sarray("index", "value"), varray());
bind_method(PackedFloat64Array, push_back, sarray("value"), varray());
bind_method(PackedFloat64Array, pop_back, sarray(), varray());
bind_method(PackedFloat64Array, append, sarray("value"), varray());
bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
bind_method(PackedFloat64Array, remove_at, sarray("index"), varray());
Expand All @@ -2414,6 +2419,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedStringArray, is_empty, sarray(), varray());
bind_method(PackedStringArray, set, sarray("index", "value"), varray());
bind_method(PackedStringArray, push_back, sarray("value"), varray());
bind_method(PackedStringArray, pop_back, sarray(), varray());
bind_method(PackedStringArray, append, sarray("value"), varray());
bind_method(PackedStringArray, append_array, sarray("array"), varray());
bind_method(PackedStringArray, remove_at, sarray("index"), varray());
Expand All @@ -2438,6 +2444,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector2Array, is_empty, sarray(), varray());
bind_method(PackedVector2Array, set, sarray("index", "value"), varray());
bind_method(PackedVector2Array, push_back, sarray("value"), varray());
bind_method(PackedVector2Array, pop_back, sarray(), varray());
bind_method(PackedVector2Array, append, sarray("value"), varray());
bind_method(PackedVector2Array, append_array, sarray("array"), varray());
bind_method(PackedVector2Array, remove_at, sarray("index"), varray());
Expand All @@ -2462,6 +2469,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedVector3Array, is_empty, sarray(), varray());
bind_method(PackedVector3Array, set, sarray("index", "value"), varray());
bind_method(PackedVector3Array, push_back, sarray("value"), varray());
bind_method(PackedVector3Array, pop_back, sarray(), varray());
bind_method(PackedVector3Array, append, sarray("value"), varray());
bind_method(PackedVector3Array, append_array, sarray("array"), varray());
bind_method(PackedVector3Array, remove_at, sarray("index"), varray());
Expand All @@ -2486,6 +2494,7 @@ static void _register_variant_builtin_methods() {
bind_method(PackedColorArray, is_empty, sarray(), varray());
bind_method(PackedColorArray, set, sarray("index", "value"), varray());
bind_method(PackedColorArray, push_back, sarray("value"), varray());
bind_method(PackedColorArray, pop_back, sarray(), varray());
bind_method(PackedColorArray, append, sarray("value"), varray());
bind_method(PackedColorArray, append_array, sarray("array"), varray());
bind_method(PackedColorArray, remove_at, sarray("index"), varray());
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedByteArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="int" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="int" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedColorArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="Color" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="Color" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedFloat32Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="float" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="float" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedFloat64Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="float" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="float" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedInt32Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="int" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="int" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedInt64Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
Inserts a new integer at a given position in the array. The position must be valid, or at the end of the array ([code]idx == size()[/code]).
</description>
</method>
<method name="pop_back">
<return type="int" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="is_empty" qualifiers="const">
<return type="bool" />
<description>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedStringArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="String" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="String" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedVector2Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="Vector2" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="Vector2" />
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/PackedVector3Array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@
Returns [code]true[/code] if the array is empty.
</description>
</method>
<method name="pop_back">
<return type="Vector3" />
<description>
Removes and returns the last element of the array.
</description>
</method>
<method name="push_back">
<return type="bool" />
<param index="0" name="value" type="Vector3" />
Expand Down

0 comments on commit 18e9218

Please sign in to comment.