Add fill method to Arrays and PackedArrays
This commit is contained in:
parent
e271dba9cb
commit
efd27a63c1
@ -66,6 +66,7 @@ private:
|
|||||||
public:
|
public:
|
||||||
bool push_back(T p_elem);
|
bool push_back(T p_elem);
|
||||||
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
|
_FORCE_INLINE_ bool append(const T &p_elem) { return push_back(p_elem); } //alias
|
||||||
|
void fill(T p_elem);
|
||||||
|
|
||||||
void remove(int p_index) { _cowdata.remove(p_index); }
|
void remove(int p_index) { _cowdata.remove(p_index); }
|
||||||
void erase(const T &p_val) {
|
void erase(const T &p_val) {
|
||||||
@ -223,4 +224,12 @@ bool Vector<T>::push_back(T p_elem) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void Vector<T>::fill(T p_elem) {
|
||||||
|
T *p = ptrw();
|
||||||
|
for (int i = 0; i < size(); i++) {
|
||||||
|
p[i] = p_elem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endif // VECTOR_H
|
#endif // VECTOR_H
|
||||||
|
@ -208,6 +208,11 @@ void Array::insert(int p_pos, const Variant &p_value) {
|
|||||||
_p->array.insert(p_pos, p_value);
|
_p->array.insert(p_pos, p_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Array::fill(const Variant &p_value) {
|
||||||
|
ERR_FAIL_COND(!_p->typed.validate(p_value, "fill"));
|
||||||
|
_p->array.fill(p_value);
|
||||||
|
}
|
||||||
|
|
||||||
void Array::erase(const Variant &p_value) {
|
void Array::erase(const Variant &p_value) {
|
||||||
ERR_FAIL_COND(!_p->typed.validate(p_value, "erase"));
|
ERR_FAIL_COND(!_p->typed.validate(p_value, "erase"));
|
||||||
_p->array.erase(p_value);
|
_p->array.erase(p_value);
|
||||||
|
@ -74,6 +74,7 @@ public:
|
|||||||
|
|
||||||
void insert(int p_pos, const Variant &p_value);
|
void insert(int p_pos, const Variant &p_value);
|
||||||
void remove(int p_pos);
|
void remove(int p_pos);
|
||||||
|
void fill(const Variant &p_value);
|
||||||
|
|
||||||
Variant front() const;
|
Variant front() const;
|
||||||
Variant back() const;
|
Variant back() const;
|
||||||
|
@ -1647,6 +1647,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(Array, resize, sarray("size"), varray());
|
bind_method(Array, resize, sarray("size"), varray());
|
||||||
bind_method(Array, insert, sarray("position", "value"), varray());
|
bind_method(Array, insert, sarray("position", "value"), varray());
|
||||||
bind_method(Array, remove, sarray("position"), varray());
|
bind_method(Array, remove, sarray("position"), varray());
|
||||||
|
bind_method(Array, fill, sarray("value"), varray());
|
||||||
bind_method(Array, erase, sarray("value"), varray());
|
bind_method(Array, erase, sarray("value"), varray());
|
||||||
bind_method(Array, front, sarray(), varray());
|
bind_method(Array, front, sarray(), varray());
|
||||||
bind_method(Array, back, sarray(), varray());
|
bind_method(Array, back, sarray(), varray());
|
||||||
@ -1677,6 +1678,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedByteArray, append_array, sarray("array"), varray());
|
bind_method(PackedByteArray, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedByteArray, remove, sarray("index"), varray());
|
bind_method(PackedByteArray, remove, sarray("index"), varray());
|
||||||
bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedByteArray, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedByteArray, fill, sarray("value"), varray());
|
||||||
bind_method(PackedByteArray, resize, sarray("new_size"), varray());
|
bind_method(PackedByteArray, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedByteArray, has, sarray("value"), varray());
|
bind_method(PackedByteArray, has, sarray("value"), varray());
|
||||||
bind_method(PackedByteArray, reverse, sarray(), varray());
|
bind_method(PackedByteArray, reverse, sarray(), varray());
|
||||||
@ -1731,6 +1733,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedInt32Array, append_array, sarray("array"), varray());
|
bind_method(PackedInt32Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedInt32Array, remove, sarray("index"), varray());
|
bind_method(PackedInt32Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedInt32Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedInt32Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedInt32Array, resize, sarray("new_size"), varray());
|
bind_method(PackedInt32Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedInt32Array, has, sarray("value"), varray());
|
bind_method(PackedInt32Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedInt32Array, reverse, sarray(), varray());
|
bind_method(PackedInt32Array, reverse, sarray(), varray());
|
||||||
@ -1749,6 +1752,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedInt64Array, append_array, sarray("array"), varray());
|
bind_method(PackedInt64Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedInt64Array, remove, sarray("index"), varray());
|
bind_method(PackedInt64Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedInt64Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedInt64Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedInt64Array, resize, sarray("new_size"), varray());
|
bind_method(PackedInt64Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedInt64Array, has, sarray("value"), varray());
|
bind_method(PackedInt64Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedInt64Array, reverse, sarray(), varray());
|
bind_method(PackedInt64Array, reverse, sarray(), varray());
|
||||||
@ -1767,6 +1771,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
|
bind_method(PackedFloat32Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedFloat32Array, remove, sarray("index"), varray());
|
bind_method(PackedFloat32Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedFloat32Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedFloat32Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedFloat32Array, resize, sarray("new_size"), varray());
|
bind_method(PackedFloat32Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedFloat32Array, has, sarray("value"), varray());
|
bind_method(PackedFloat32Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedFloat32Array, reverse, sarray(), varray());
|
bind_method(PackedFloat32Array, reverse, sarray(), varray());
|
||||||
@ -1785,6 +1790,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
|
bind_method(PackedFloat64Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedFloat64Array, remove, sarray("index"), varray());
|
bind_method(PackedFloat64Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedFloat64Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedFloat64Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedFloat64Array, resize, sarray("new_size"), varray());
|
bind_method(PackedFloat64Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedFloat64Array, has, sarray("value"), varray());
|
bind_method(PackedFloat64Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedFloat64Array, reverse, sarray(), varray());
|
bind_method(PackedFloat64Array, reverse, sarray(), varray());
|
||||||
@ -1803,6 +1809,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedStringArray, append_array, sarray("array"), varray());
|
bind_method(PackedStringArray, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedStringArray, remove, sarray("index"), varray());
|
bind_method(PackedStringArray, remove, sarray("index"), varray());
|
||||||
bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedStringArray, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedStringArray, fill, sarray("value"), varray());
|
||||||
bind_method(PackedStringArray, resize, sarray("new_size"), varray());
|
bind_method(PackedStringArray, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedStringArray, has, sarray("value"), varray());
|
bind_method(PackedStringArray, has, sarray("value"), varray());
|
||||||
bind_method(PackedStringArray, reverse, sarray(), varray());
|
bind_method(PackedStringArray, reverse, sarray(), varray());
|
||||||
@ -1821,6 +1828,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedVector2Array, append_array, sarray("array"), varray());
|
bind_method(PackedVector2Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedVector2Array, remove, sarray("index"), varray());
|
bind_method(PackedVector2Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedVector2Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedVector2Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
|
bind_method(PackedVector2Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedVector2Array, has, sarray("value"), varray());
|
bind_method(PackedVector2Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedVector2Array, reverse, sarray(), varray());
|
bind_method(PackedVector2Array, reverse, sarray(), varray());
|
||||||
@ -1839,6 +1847,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedVector3Array, append_array, sarray("array"), varray());
|
bind_method(PackedVector3Array, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedVector3Array, remove, sarray("index"), varray());
|
bind_method(PackedVector3Array, remove, sarray("index"), varray());
|
||||||
bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedVector3Array, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedVector3Array, fill, sarray("value"), varray());
|
||||||
bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
|
bind_method(PackedVector3Array, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedVector3Array, has, sarray("value"), varray());
|
bind_method(PackedVector3Array, has, sarray("value"), varray());
|
||||||
bind_method(PackedVector3Array, reverse, sarray(), varray());
|
bind_method(PackedVector3Array, reverse, sarray(), varray());
|
||||||
@ -1857,6 +1866,7 @@ static void _register_variant_builtin_methods() {
|
|||||||
bind_method(PackedColorArray, append_array, sarray("array"), varray());
|
bind_method(PackedColorArray, append_array, sarray("array"), varray());
|
||||||
bind_method(PackedColorArray, remove, sarray("index"), varray());
|
bind_method(PackedColorArray, remove, sarray("index"), varray());
|
||||||
bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
|
bind_method(PackedColorArray, insert, sarray("at_index", "value"), varray());
|
||||||
|
bind_method(PackedColorArray, fill, sarray("value"), varray());
|
||||||
bind_method(PackedColorArray, resize, sarray("new_size"), varray());
|
bind_method(PackedColorArray, resize, sarray("new_size"), varray());
|
||||||
bind_method(PackedColorArray, has, sarray("value"), varray());
|
bind_method(PackedColorArray, has, sarray("value"), varray());
|
||||||
bind_method(PackedColorArray, reverse, sarray(), varray());
|
bind_method(PackedColorArray, reverse, sarray(), varray());
|
||||||
|
@ -237,6 +237,27 @@
|
|||||||
[b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
|
[b]Note:[/b] On large arrays, this method will be slower if the removed element is close to the beginning of the array (index 0). This is because all elements placed after the removed element have to be reindexed.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="Variant">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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:
|
||||||
|
[codeblocks]
|
||||||
|
[gdscript]
|
||||||
|
var array = []
|
||||||
|
array.resize(10)
|
||||||
|
array.fill(0) # Initialize the 10 elements to 0.
|
||||||
|
[/gdscript]
|
||||||
|
[csharp]
|
||||||
|
var array = new Godot.Collections.Array{};
|
||||||
|
array.Resize(10);
|
||||||
|
array.Fill(0); // Initialize the 10 elements to 0.
|
||||||
|
[/csharp]
|
||||||
|
[/codeblocks]
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="find" qualifiers="const">
|
<method name="find" qualifiers="const">
|
||||||
<return type="int">
|
<return type="int">
|
||||||
</return>
|
</return>
|
||||||
|
@ -322,6 +322,15 @@
|
|||||||
<description>
|
<description>
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="get_string_from_ascii" qualifiers="const">
|
<method name="get_string_from_ascii" qualifiers="const">
|
||||||
<return type="String">
|
<return type="String">
|
||||||
</return>
|
</return>
|
||||||
|
@ -59,6 +59,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="Color">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="float">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="float">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="int">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="String">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -60,6 +60,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="Vector2">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
@ -59,6 +59,15 @@
|
|||||||
Creates a copy of the array, and returns it.
|
Creates a copy of the array, and returns it.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
|
<method name="fill">
|
||||||
|
<return type="void">
|
||||||
|
</return>
|
||||||
|
<argument index="0" name="value" type="Vector3">
|
||||||
|
</argument>
|
||||||
|
<description>
|
||||||
|
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.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="has">
|
<method name="has">
|
||||||
<return type="bool">
|
<return type="bool">
|
||||||
</return>
|
</return>
|
||||||
|
Loading…
Reference in New Issue
Block a user