feat: modules moved and engine moved to submodule
This commit is contained in:
parent
dfb5e645cd
commit
c33d2130cc
5136 changed files with 225275 additions and 64485 deletions
|
|
@ -45,6 +45,10 @@ struct ArrayPrivate {
|
|||
Vector<Variant> array;
|
||||
Variant *read_only = nullptr; // If enabled, a pointer is used to a temporary value that is used to return read-only values.
|
||||
ContainerTypeValidate typed;
|
||||
|
||||
ArrayPrivate() {}
|
||||
ArrayPrivate(std::initializer_list<Variant> p_init) :
|
||||
array(p_init) {}
|
||||
};
|
||||
|
||||
void Array::_ref(const Array &p_from) const {
|
||||
|
|
@ -88,11 +92,11 @@ Array::Iterator Array::end() {
|
|||
}
|
||||
|
||||
Array::ConstIterator Array::begin() const {
|
||||
return ConstIterator(_p->array.ptr(), _p->read_only);
|
||||
return ConstIterator(_p->array.ptr());
|
||||
}
|
||||
|
||||
Array::ConstIterator Array::end() const {
|
||||
return ConstIterator(_p->array.ptr() + _p->array.size(), _p->read_only);
|
||||
return ConstIterator(_p->array.ptr() + _p->array.size());
|
||||
}
|
||||
|
||||
Variant &Array::operator[](int p_idx) {
|
||||
|
|
@ -104,10 +108,6 @@ Variant &Array::operator[](int p_idx) {
|
|||
}
|
||||
|
||||
const Variant &Array::operator[](int p_idx) const {
|
||||
if (unlikely(_p->read_only)) {
|
||||
*_p->read_only = _p->array[p_idx];
|
||||
return *_p->read_only;
|
||||
}
|
||||
return _p->array[p_idx];
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ void Array::push_back(const Variant &p_value) {
|
|||
ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state.");
|
||||
Variant value = p_value;
|
||||
ERR_FAIL_COND(!_p->typed.validate(value, "push_back"));
|
||||
_p->array.push_back(value);
|
||||
_p->array.push_back(std::move(value));
|
||||
}
|
||||
|
||||
void Array::append_array(const Array &p_array) {
|
||||
|
|
@ -312,14 +312,22 @@ Error Array::insert(int p_pos, const Variant &p_value) {
|
|||
ERR_FAIL_COND_V_MSG(_p->read_only, ERR_LOCKED, "Array is in read-only state.");
|
||||
Variant value = p_value;
|
||||
ERR_FAIL_COND_V(!_p->typed.validate(value, "insert"), ERR_INVALID_PARAMETER);
|
||||
return _p->array.insert(p_pos, value);
|
||||
|
||||
if (p_pos < 0) {
|
||||
// Relative offset from the end.
|
||||
p_pos = _p->array.size() + p_pos;
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX_V_MSG(p_pos, _p->array.size(), ERR_INVALID_PARAMETER, vformat("The calculated index %d is out of bounds (the array has %d elements). Leaving the array untouched.", p_pos, _p->array.size()));
|
||||
|
||||
return _p->array.insert(p_pos, std::move(value));
|
||||
}
|
||||
|
||||
void Array::fill(const Variant &p_value) {
|
||||
ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state.");
|
||||
Variant value = p_value;
|
||||
ERR_FAIL_COND(!_p->typed.validate(value, "fill"));
|
||||
_p->array.fill(value);
|
||||
_p->array.fill(std::move(value));
|
||||
}
|
||||
|
||||
void Array::erase(const Variant &p_value) {
|
||||
|
|
@ -345,7 +353,7 @@ Variant Array::pick_random() const {
|
|||
}
|
||||
|
||||
int Array::find(const Variant &p_value, int p_from) const {
|
||||
if (_p->array.size() == 0) {
|
||||
if (_p->array.is_empty()) {
|
||||
return -1;
|
||||
}
|
||||
Variant value = p_value;
|
||||
|
|
@ -396,7 +404,7 @@ int Array::find_custom(const Callable &p_callable, int p_from) const {
|
|||
}
|
||||
|
||||
int Array::rfind(const Variant &p_value, int p_from) const {
|
||||
if (_p->array.size() == 0) {
|
||||
if (_p->array.is_empty()) {
|
||||
return -1;
|
||||
}
|
||||
Variant value = p_value;
|
||||
|
|
@ -421,7 +429,7 @@ int Array::rfind(const Variant &p_value, int p_from) const {
|
|||
}
|
||||
|
||||
int Array::rfind_custom(const Callable &p_callable, int p_from) const {
|
||||
if (_p->array.size() == 0) {
|
||||
if (_p->array.is_empty()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
@ -458,7 +466,7 @@ int Array::rfind_custom(const Callable &p_callable, int p_from) const {
|
|||
int Array::count(const Variant &p_value) const {
|
||||
Variant value = p_value;
|
||||
ERR_FAIL_COND_V(!_p->typed.validate(value, "count"), 0);
|
||||
if (_p->array.size() == 0) {
|
||||
if (_p->array.is_empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -481,6 +489,14 @@ bool Array::has(const Variant &p_value) const {
|
|||
|
||||
void Array::remove_at(int p_pos) {
|
||||
ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state.");
|
||||
|
||||
if (p_pos < 0) {
|
||||
// Relative offset from the end.
|
||||
p_pos = _p->array.size() + p_pos;
|
||||
}
|
||||
|
||||
ERR_FAIL_INDEX_MSG(p_pos, _p->array.size(), vformat("The calculated index %d is out of bounds (the array has %d elements). Leaving the array untouched.", p_pos, _p->array.size()));
|
||||
|
||||
_p->array.remove_at(p_pos);
|
||||
}
|
||||
|
||||
|
|
@ -489,7 +505,7 @@ void Array::set(int p_idx, const Variant &p_value) {
|
|||
Variant value = p_value;
|
||||
ERR_FAIL_COND(!_p->typed.validate(value, "set"));
|
||||
|
||||
operator[](p_idx) = value;
|
||||
_p->array.write[p_idx] = std::move(value);
|
||||
}
|
||||
|
||||
const Variant &Array::get(int p_idx) const {
|
||||
|
|
@ -707,9 +723,7 @@ void Array::shuffle() {
|
|||
Variant *data = _p->array.ptrw();
|
||||
for (int i = n - 1; i >= 1; i--) {
|
||||
const int j = Math::rand() % (i + 1);
|
||||
const Variant tmp = data[j];
|
||||
data[j] = data[i];
|
||||
data[i] = tmp;
|
||||
SWAP(data[i], data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -736,7 +750,7 @@ void Array::push_front(const Variant &p_value) {
|
|||
ERR_FAIL_COND_MSG(_p->read_only, "Array is in read-only state.");
|
||||
Variant value = p_value;
|
||||
ERR_FAIL_COND(!_p->typed.validate(value, "push_front"));
|
||||
_p->array.insert(0, value);
|
||||
_p->array.insert(0, std::move(value));
|
||||
}
|
||||
|
||||
Variant Array::pop_back() {
|
||||
|
|
@ -913,6 +927,12 @@ Array::Array(const Array &p_from) {
|
|||
_ref(p_from);
|
||||
}
|
||||
|
||||
Array::Array(std::initializer_list<Variant> p_init) {
|
||||
_p = memnew(ArrayPrivate);
|
||||
_p->refcount.init();
|
||||
_p->array = Vector<Variant>(p_init);
|
||||
}
|
||||
|
||||
Array::Array() {
|
||||
_p = memnew(ArrayPrivate);
|
||||
_p->refcount.init();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue