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();
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
#pragma once
|
||||
|
||||
#include "core/typedefs.h"
|
||||
|
||||
#include <climits>
|
||||
#include <initializer_list>
|
||||
|
||||
class Callable;
|
||||
class StringName;
|
||||
|
|
@ -57,21 +57,19 @@ public:
|
|||
_FORCE_INLINE_ bool operator==(const ConstIterator &p_other) const { return element_ptr == p_other.element_ptr; }
|
||||
_FORCE_INLINE_ bool operator!=(const ConstIterator &p_other) const { return element_ptr != p_other.element_ptr; }
|
||||
|
||||
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr, Variant *p_read_only = nullptr) :
|
||||
element_ptr(p_element_ptr), read_only(p_read_only) {}
|
||||
_FORCE_INLINE_ ConstIterator(const Variant *p_element_ptr) :
|
||||
element_ptr(p_element_ptr) {}
|
||||
_FORCE_INLINE_ ConstIterator() {}
|
||||
_FORCE_INLINE_ ConstIterator(const ConstIterator &p_other) :
|
||||
element_ptr(p_other.element_ptr), read_only(p_other.read_only) {}
|
||||
element_ptr(p_other.element_ptr) {}
|
||||
|
||||
_FORCE_INLINE_ ConstIterator &operator=(const ConstIterator &p_other) {
|
||||
element_ptr = p_other.element_ptr;
|
||||
read_only = p_other.read_only;
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
const Variant *element_ptr = nullptr;
|
||||
Variant *read_only = nullptr;
|
||||
};
|
||||
|
||||
struct Iterator {
|
||||
|
|
@ -97,7 +95,7 @@ public:
|
|||
}
|
||||
|
||||
operator ConstIterator() const {
|
||||
return ConstIterator(element_ptr, read_only);
|
||||
return ConstIterator(element_ptr);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
@ -204,8 +202,7 @@ public:
|
|||
|
||||
Array(const Array &p_base, uint32_t p_type, const StringName &p_class_name, const Variant &p_script);
|
||||
Array(const Array &p_from);
|
||||
Array(std::initializer_list<Variant> p_init);
|
||||
Array();
|
||||
~Array();
|
||||
};
|
||||
|
||||
#endif // ARRAY_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef BINDER_COMMON_H
|
||||
#define BINDER_COMMON_H
|
||||
#pragma once
|
||||
|
||||
#include "core/input/input_enums.h"
|
||||
#include "core/object/object.h"
|
||||
|
|
@ -82,73 +81,8 @@ struct VariantCaster<const T &> {
|
|||
}
|
||||
};
|
||||
|
||||
#define VARIANT_ENUM_CAST(m_enum) \
|
||||
MAKE_ENUM_TYPE_INFO(m_enum) \
|
||||
template <> \
|
||||
struct VariantCaster<m_enum> { \
|
||||
static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \
|
||||
return (m_enum)p_variant.operator int64_t(); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<m_enum> { \
|
||||
_FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \
|
||||
return m_enum(*reinterpret_cast<const int64_t *>(p_ptr)); \
|
||||
} \
|
||||
typedef int64_t EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \
|
||||
*(int64_t *)p_ptr = (int64_t)p_val; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct ZeroInitializer<m_enum> { \
|
||||
static void initialize(m_enum &value) { \
|
||||
value = (m_enum)0; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct VariantInternalAccessor<m_enum> { \
|
||||
static _FORCE_INLINE_ m_enum get(const Variant *v) { \
|
||||
return m_enum(*VariantInternal::get_int(v)); \
|
||||
} \
|
||||
static _FORCE_INLINE_ void set(Variant *v, m_enum p_value) { \
|
||||
*VariantInternal::get_int(v) = (int64_t)p_value; \
|
||||
} \
|
||||
};
|
||||
|
||||
#define VARIANT_BITFIELD_CAST(m_enum) \
|
||||
MAKE_BITFIELD_TYPE_INFO(m_enum) \
|
||||
template <> \
|
||||
struct VariantCaster<BitField<m_enum>> { \
|
||||
static _FORCE_INLINE_ BitField<m_enum> cast(const Variant &p_variant) { \
|
||||
return BitField<m_enum>(p_variant.operator int64_t()); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<BitField<m_enum>> { \
|
||||
_FORCE_INLINE_ static BitField<m_enum> convert(const void *p_ptr) { \
|
||||
return BitField<m_enum>(*reinterpret_cast<const int64_t *>(p_ptr)); \
|
||||
} \
|
||||
typedef int64_t EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(BitField<m_enum> p_val, const void *p_ptr) { \
|
||||
*(int64_t *)p_ptr = p_val; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct ZeroInitializer<BitField<m_enum>> { \
|
||||
static void initialize(BitField<m_enum> &value) { \
|
||||
value = 0; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct VariantInternalAccessor<BitField<m_enum>> { \
|
||||
static _FORCE_INLINE_ BitField<m_enum> get(const Variant *v) { \
|
||||
return BitField<m_enum>(*VariantInternal::get_int(v)); \
|
||||
} \
|
||||
static _FORCE_INLINE_ void set(Variant *v, BitField<m_enum> p_value) { \
|
||||
*VariantInternal::get_int(v) = p_value.operator int64_t(); \
|
||||
} \
|
||||
};
|
||||
#define VARIANT_ENUM_CAST(m_enum) MAKE_ENUM_TYPE_INFO(m_enum)
|
||||
#define VARIANT_BITFIELD_CAST(m_enum) MAKE_BITFIELD_TYPE_INFO(m_enum)
|
||||
|
||||
// Object enum casts must go here
|
||||
VARIANT_ENUM_CAST(Object::ConnectFlags);
|
||||
|
|
@ -189,32 +123,6 @@ VARIANT_ENUM_CAST(Key);
|
|||
VARIANT_BITFIELD_CAST(KeyModifierMask);
|
||||
VARIANT_ENUM_CAST(KeyLocation);
|
||||
|
||||
static inline Key &operator|=(Key &a, BitField<KeyModifierMask> b) {
|
||||
a = static_cast<Key>(static_cast<int>(a) | static_cast<int>(b.operator int64_t()));
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline Key &operator&=(Key &a, BitField<KeyModifierMask> b) {
|
||||
a = static_cast<Key>(static_cast<int>(a) & static_cast<int>(b.operator int64_t()));
|
||||
return a;
|
||||
}
|
||||
|
||||
static inline Key operator|(Key a, BitField<KeyModifierMask> b) {
|
||||
return (Key)((int)a | (int)b.operator int64_t());
|
||||
}
|
||||
|
||||
static inline Key operator&(Key a, BitField<KeyModifierMask> b) {
|
||||
return (Key)((int)a & (int)b.operator int64_t());
|
||||
}
|
||||
|
||||
static inline Key operator+(BitField<KeyModifierMask> a, Key b) {
|
||||
return (Key)((int)a.operator int64_t() + (int)b);
|
||||
}
|
||||
|
||||
static inline Key operator|(BitField<KeyModifierMask> a, Key b) {
|
||||
return (Key)((int)a.operator int64_t() | (int)b);
|
||||
}
|
||||
|
||||
template <>
|
||||
struct VariantCaster<char32_t> {
|
||||
static _FORCE_INLINE_ char32_t cast(const Variant &p_variant) {
|
||||
|
|
@ -690,10 +598,7 @@ void call_with_validated_object_instance_args_static_retc(T *base, R (*p_method)
|
|||
|
||||
// GCC raises "parameter 'p_args' set but not used" when P = {},
|
||||
// it's not clever enough to treat other P values as making this branch valid.
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
|
||||
#endif
|
||||
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wunused-but-set-parameter")
|
||||
|
||||
template <typename Q>
|
||||
void call_get_argument_type_helper(int p_arg, int &index, Variant::Type &type) {
|
||||
|
|
@ -1034,8 +939,4 @@ void call_with_variant_args_static_dv(void (*p_method)(P...), const Variant **p_
|
|||
call_with_variant_args_static(p_method, args, r_error, BuildIndexSequence<sizeof...(P)>{});
|
||||
}
|
||||
|
||||
#if defined(__GNUC__) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#endif // BINDER_COMMON_H
|
||||
GODOT_GCC_WARNING_POP
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ int Callable::get_argument_count(bool *r_is_valid) const {
|
|||
if (is_custom()) {
|
||||
bool valid = false;
|
||||
return custom->get_argument_count(r_is_valid ? *r_is_valid : valid);
|
||||
} else if (!is_null()) {
|
||||
} else if (is_valid()) {
|
||||
return get_object()->get_method_argument_count(method, r_is_valid);
|
||||
} else {
|
||||
if (r_is_valid) {
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CALLABLE_H
|
||||
#define CALLABLE_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/object_id.h"
|
||||
#include "core/string/string_name.h"
|
||||
|
|
@ -136,6 +135,10 @@ public:
|
|||
~Callable();
|
||||
};
|
||||
|
||||
// Zero-constructing Callable initializes method and object to 0 (and thus empty).
|
||||
template <>
|
||||
struct is_zero_constructible<Callable> : std::true_type {};
|
||||
|
||||
class CallableCustom {
|
||||
friend class Callable;
|
||||
SafeRefCount ref_count;
|
||||
|
|
@ -201,10 +204,12 @@ public:
|
|||
Signal() {}
|
||||
};
|
||||
|
||||
// Zero-constructing Signal initializes name and object to 0 (and thus empty).
|
||||
template <>
|
||||
struct is_zero_constructible<Signal> : std::true_type {};
|
||||
|
||||
struct CallableComparator {
|
||||
const Callable &func;
|
||||
|
||||
bool operator()(const Variant &p_l, const Variant &p_r) const;
|
||||
};
|
||||
|
||||
#endif // CALLABLE_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CALLABLE_BIND_H
|
||||
#define CALLABLE_BIND_H
|
||||
#pragma once
|
||||
|
||||
#include "core/variant/callable.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
|
@ -94,5 +93,3 @@ public:
|
|||
CallableCustomUnbind(const Callable &p_callable, int p_argcount);
|
||||
virtual ~CallableCustomUnbind();
|
||||
};
|
||||
|
||||
#endif // CALLABLE_BIND_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef CONTAINER_TYPE_VALIDATE_H
|
||||
#define CONTAINER_TYPE_VALIDATE_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/script_language.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
|
@ -148,5 +147,3 @@ struct ContainerTypeValidate {
|
|||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CONTAINER_TYPE_VALIDATE_H
|
||||
|
|
|
|||
|
|
@ -49,14 +49,22 @@ struct DictionaryPrivate {
|
|||
Variant *typed_fallback = nullptr; // Allows a typed dictionary to return dummy values when attempting an invalid access.
|
||||
};
|
||||
|
||||
void Dictionary::get_key_list(List<Variant> *p_keys) const {
|
||||
if (_p->variant_map.is_empty()) {
|
||||
return;
|
||||
}
|
||||
Dictionary::ConstIterator Dictionary::begin() const {
|
||||
return _p->variant_map.begin();
|
||||
}
|
||||
|
||||
Dictionary::ConstIterator Dictionary::end() const {
|
||||
return _p->variant_map.end();
|
||||
}
|
||||
|
||||
LocalVector<Variant> Dictionary::get_key_list() const {
|
||||
LocalVector<Variant> keys;
|
||||
|
||||
keys.reserve(_p->variant_map.size());
|
||||
for (const KeyValue<Variant, Variant> &E : _p->variant_map) {
|
||||
p_keys->push_back(E.key);
|
||||
keys.push_back(E.key);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
Variant Dictionary::get_key_at_index(int p_index) const {
|
||||
|
|
@ -101,10 +109,12 @@ Variant &Dictionary::operator[](const Variant &p_key) {
|
|||
}
|
||||
return *_p->read_only;
|
||||
} else {
|
||||
if (unlikely(!_p->variant_map.has(key))) {
|
||||
VariantInternal::initialize(&_p->variant_map[key], _p->typed_value.type);
|
||||
const uint32_t old_size = _p->variant_map.size();
|
||||
Variant &value = _p->variant_map[key];
|
||||
if (_p->variant_map.size() > old_size) {
|
||||
VariantInternal::initialize(&value, _p->typed_value.type);
|
||||
}
|
||||
return _p->variant_map[key];
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -208,7 +218,7 @@ bool Dictionary::is_empty() const {
|
|||
bool Dictionary::has(const Variant &p_key) const {
|
||||
Variant key = p_key;
|
||||
ERR_FAIL_COND_V(!_p->typed_key.validate(key, "use 'has'"), false);
|
||||
return _p->variant_map.has(p_key);
|
||||
return _p->variant_map.has(key);
|
||||
}
|
||||
|
||||
bool Dictionary::has_all(const Array &p_keys) const {
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
#pragma once
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/list.h"
|
||||
#include "core/templates/hash_map.h"
|
||||
#include "core/templates/local_vector.h"
|
||||
#include "core/templates/pair.h"
|
||||
#include "core/variant/array.h"
|
||||
|
||||
|
|
@ -40,6 +40,8 @@ class Variant;
|
|||
|
||||
struct ContainerType;
|
||||
struct DictionaryPrivate;
|
||||
struct StringLikeVariantComparator;
|
||||
struct VariantHasher;
|
||||
|
||||
class Dictionary {
|
||||
mutable DictionaryPrivate *_p;
|
||||
|
|
@ -48,7 +50,12 @@ class Dictionary {
|
|||
void _unref() const;
|
||||
|
||||
public:
|
||||
void get_key_list(List<Variant> *p_keys) const;
|
||||
using ConstIterator = HashMap<Variant, Variant, VariantHasher, StringLikeVariantComparator>::ConstIterator;
|
||||
|
||||
ConstIterator begin() const;
|
||||
ConstIterator end() const;
|
||||
|
||||
LocalVector<Variant> get_key_list() const;
|
||||
Variant get_key_at_index(int p_index) const;
|
||||
Variant get_value_at_index(int p_index) const;
|
||||
|
||||
|
|
@ -123,5 +130,3 @@ public:
|
|||
Dictionary();
|
||||
~Dictionary();
|
||||
};
|
||||
|
||||
#endif // DICTIONARY_H
|
||||
|
|
|
|||
|
|
@ -28,15 +28,18 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef METHOD_PTRCALL_H
|
||||
#define METHOD_PTRCALL_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/object_id.h"
|
||||
#include "core/templates/simple_type.h"
|
||||
#include "core/typedefs.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct PtrToArg;
|
||||
|
||||
template <typename T>
|
||||
struct PtrToArg {};
|
||||
struct PtrToArg<T, std::enable_if_t<!std::is_same_v<T, GetSimpleTypeT<T>>>> : PtrToArg<GetSimpleTypeT<T>> {};
|
||||
|
||||
#define MAKE_PTRARG(m_type) \
|
||||
template <> \
|
||||
|
|
@ -48,17 +51,7 @@ struct PtrToArg {};
|
|||
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
||||
*((m_type *)p_ptr) = p_val; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const m_type &> { \
|
||||
_FORCE_INLINE_ static const m_type &convert(const void *p_ptr) { \
|
||||
return *reinterpret_cast<const m_type *>(p_ptr); \
|
||||
} \
|
||||
typedef m_type EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
||||
*((m_type *)p_ptr) = p_val; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_PTRARGCONV(m_type, m_conv) \
|
||||
template <> \
|
||||
|
|
@ -70,17 +63,7 @@ struct PtrToArg {};
|
|||
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
||||
*((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const m_type &> { \
|
||||
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
||||
return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \
|
||||
} \
|
||||
typedef m_conv EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
||||
*((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_PTRARG_BY_REFERENCE(m_type) \
|
||||
template <> \
|
||||
|
|
@ -92,17 +75,19 @@ struct PtrToArg {};
|
|||
_FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \
|
||||
*((m_type *)p_ptr) = p_val; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const m_type &> { \
|
||||
_FORCE_INLINE_ static const m_type &convert(const void *p_ptr) { \
|
||||
return *reinterpret_cast<const m_type *>(p_ptr); \
|
||||
} \
|
||||
typedef m_type EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(const m_type &p_val, void *p_ptr) { \
|
||||
*((m_type *)p_ptr) = p_val; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_PTRARGCONV_CONDITIONAL(m_type, m_conv, m_conditional) \
|
||||
template <typename T> \
|
||||
struct PtrToArg<m_type, std::enable_if_t<m_conditional>> { \
|
||||
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
||||
return static_cast<m_type>(*reinterpret_cast<const m_conv *>(p_ptr)); \
|
||||
} \
|
||||
typedef m_conv EncodeT; \
|
||||
_FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \
|
||||
*((m_conv *)p_ptr) = static_cast<m_conv>(p_val); \
|
||||
} \
|
||||
};
|
||||
|
||||
MAKE_PTRARGCONV(bool, uint8_t);
|
||||
// Integer types.
|
||||
|
|
@ -155,6 +140,9 @@ MAKE_PTRARG(PackedColorArray);
|
|||
MAKE_PTRARG(PackedVector4Array);
|
||||
MAKE_PTRARG_BY_REFERENCE(Variant);
|
||||
|
||||
MAKE_PTRARGCONV_CONDITIONAL(T, int64_t, std::is_enum_v<T>);
|
||||
MAKE_PTRARGCONV_CONDITIONAL(BitField<T>, int64_t, std::is_enum_v<T>);
|
||||
|
||||
// This is for Object.
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -222,23 +210,7 @@ struct PtrToArg<ObjectID> {
|
|||
} \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const Vector<m_type> &> { \
|
||||
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
||||
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
||||
Vector<m_type> ret; \
|
||||
int len = dvs->size(); \
|
||||
ret.resize(len); \
|
||||
{ \
|
||||
const m_type *r = dvs->ptr(); \
|
||||
for (int i = 0; i < len; i++) { \
|
||||
ret.write[i] = r[i]; \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
// No EncodeT because direct pointer conversion not possible.
|
||||
#define MAKE_VECARG_ALT(m_type, m_type_alt) \
|
||||
|
|
@ -268,23 +240,7 @@ struct PtrToArg<ObjectID> {
|
|||
} \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const Vector<m_type_alt> &> { \
|
||||
_FORCE_INLINE_ static Vector<m_type_alt> convert(const void *p_ptr) { \
|
||||
const Vector<m_type> *dvs = reinterpret_cast<const Vector<m_type> *>(p_ptr); \
|
||||
Vector<m_type_alt> ret; \
|
||||
int len = dvs->size(); \
|
||||
ret.resize(len); \
|
||||
{ \
|
||||
const m_type *r = dvs->ptr(); \
|
||||
for (int i = 0; i < len; i++) { \
|
||||
ret.write[i] = r[i]; \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
MAKE_VECARG_ALT(String, StringName);
|
||||
|
||||
|
|
@ -312,20 +268,7 @@ MAKE_VECARG_ALT(String, StringName);
|
|||
(*arr)[i] = p_vec[i]; \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const Vector<m_type> &> { \
|
||||
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
||||
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
||||
Vector<m_type> ret; \
|
||||
int len = arr->size(); \
|
||||
ret.resize(len); \
|
||||
for (int i = 0; i < len; i++) { \
|
||||
ret.write[i] = (*arr)[i]; \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
MAKE_VECARR(Variant);
|
||||
MAKE_VECARR(RID);
|
||||
|
|
@ -359,23 +302,7 @@ MAKE_VECARR(Plane);
|
|||
} \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct PtrToArg<const Vector<m_type> &> { \
|
||||
_FORCE_INLINE_ static Vector<m_type> convert(const void *p_ptr) { \
|
||||
const Array *arr = reinterpret_cast<const Array *>(p_ptr); \
|
||||
Vector<m_type> ret; \
|
||||
int len = arr->size(); \
|
||||
ret.resize(len); \
|
||||
{ \
|
||||
m_type *w = ret.ptrw(); \
|
||||
for (int i = 0; i < len; i++) { \
|
||||
w[i] = (*arr)[i]; \
|
||||
} \
|
||||
} \
|
||||
return ret; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
// Special case for IPAddress.
|
||||
|
||||
|
|
@ -391,15 +318,7 @@ MAKE_VECARR(Plane);
|
|||
String *arr = reinterpret_cast<String *>(p_ptr); \
|
||||
*arr = p_vec; \
|
||||
} \
|
||||
}; \
|
||||
\
|
||||
template <> \
|
||||
struct PtrToArg<const m_type &> { \
|
||||
_FORCE_INLINE_ static m_type convert(const void *p_ptr) { \
|
||||
m_type s = *reinterpret_cast<const String *>(p_ptr); \
|
||||
return s; \
|
||||
} \
|
||||
}
|
||||
};
|
||||
|
||||
MAKE_STRINGCONV_BY_REFERENCE(IPAddress);
|
||||
|
||||
|
|
@ -437,26 +356,3 @@ struct PtrToArg<Vector<Face3>> {
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
// No EncodeT because direct pointer conversion not possible.
|
||||
template <>
|
||||
struct PtrToArg<const Vector<Face3> &> {
|
||||
_FORCE_INLINE_ static Vector<Face3> convert(const void *p_ptr) {
|
||||
const Vector<Vector3> *dvs = reinterpret_cast<const Vector<Vector3> *>(p_ptr);
|
||||
Vector<Face3> ret;
|
||||
int len = dvs->size() / 3;
|
||||
ret.resize(len);
|
||||
{
|
||||
const Vector3 *r = dvs->ptr();
|
||||
Face3 *w = ret.ptrw();
|
||||
for (int i = 0; i < len; i++) {
|
||||
w[i].vertex[0] = r[i * 3 + 0];
|
||||
w[i].vertex[1] = r[i * 3 + 1];
|
||||
w[i].vertex[2] = r[i * 3 + 2];
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // METHOD_PTRCALL_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef NATIVE_PTR_H
|
||||
#define NATIVE_PTR_H
|
||||
#pragma once
|
||||
|
||||
#include "core/math/audio_frame.h"
|
||||
#include "core/variant/method_ptrcall.h"
|
||||
|
|
@ -176,5 +175,3 @@ GDVIRTUAL_NATIVE_PTR(int64_t)
|
|||
GDVIRTUAL_NATIVE_PTR(uint64_t)
|
||||
GDVIRTUAL_NATIVE_PTR(float)
|
||||
GDVIRTUAL_NATIVE_PTR(double)
|
||||
|
||||
#endif // NATIVE_PTR_H
|
||||
|
|
|
|||
|
|
@ -28,9 +28,9 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TYPE_INFO_H
|
||||
#define TYPE_INFO_H
|
||||
#pragma once
|
||||
|
||||
#include "core/templates/simple_type.h"
|
||||
#include "core/typedefs.h"
|
||||
|
||||
#include <type_traits>
|
||||
|
|
@ -61,6 +61,9 @@ enum Metadata {
|
|||
template <typename T, typename = void>
|
||||
struct GetTypeInfo;
|
||||
|
||||
template <typename T>
|
||||
struct GetTypeInfo<T, std::enable_if_t<!std::is_same_v<T, GetSimpleTypeT<T>>>> : GetTypeInfo<GetSimpleTypeT<T>> {};
|
||||
|
||||
#define MAKE_TYPE_INFO(m_type, m_var_type) \
|
||||
template <> \
|
||||
struct GetTypeInfo<m_type> { \
|
||||
|
|
@ -69,14 +72,6 @@ struct GetTypeInfo;
|
|||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<const m_type &> { \
|
||||
static const Variant::Type VARIANT_TYPE = m_var_type; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define MAKE_TYPE_INFO_WITH_META(m_type, m_var_type, m_metadata) \
|
||||
|
|
@ -87,14 +82,6 @@ struct GetTypeInfo;
|
|||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<const m_type &> { \
|
||||
static const Variant::Type VARIANT_TYPE = m_var_type; \
|
||||
static const GodotTypeInfo::Metadata METADATA = m_metadata; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
};
|
||||
|
||||
MAKE_TYPE_INFO(bool, Variant::BOOL)
|
||||
|
|
@ -168,15 +155,6 @@ struct GetTypeInfo<Variant> {
|
|||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct GetTypeInfo<const Variant &> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::NIL;
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
|
||||
static inline PropertyInfo get_class_info() {
|
||||
return PropertyInfo(Variant::NIL, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_NIL_IS_VARIANT);
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_TEMPLATE_TYPE_INFO(m_template, m_type, m_var_type) \
|
||||
template <> \
|
||||
struct GetTypeInfo<m_template<m_type>> { \
|
||||
|
|
@ -185,14 +163,6 @@ struct GetTypeInfo<const Variant &> {
|
|||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<const m_template<m_type> &> { \
|
||||
static const Variant::Type VARIANT_TYPE = m_var_type; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(VARIANT_TYPE, String()); \
|
||||
} \
|
||||
};
|
||||
|
||||
MAKE_TEMPLATE_TYPE_INFO(Vector, Variant, Variant::ARRAY)
|
||||
|
|
@ -210,8 +180,8 @@ struct GetTypeInfo<T *, std::enable_if_t<std::is_base_of_v<Object, T>>> {
|
|||
}
|
||||
};
|
||||
|
||||
namespace godot {
|
||||
namespace details {
|
||||
namespace GodotTypeInfo {
|
||||
namespace Internal {
|
||||
inline String enum_qualified_name_to_class_info_name(const String &p_qualified_name) {
|
||||
Vector<String> parts = p_qualified_name.split("::", false);
|
||||
if (parts.size() <= 2) {
|
||||
|
|
@ -220,124 +190,57 @@ inline String enum_qualified_name_to_class_info_name(const String &p_qualified_n
|
|||
// Contains namespace. We only want the class and enum names.
|
||||
return parts[parts.size() - 2] + "." + parts[parts.size() - 1];
|
||||
}
|
||||
} // namespace details
|
||||
} // namespace godot
|
||||
} // namespace Internal
|
||||
} // namespace GodotTypeInfo
|
||||
|
||||
#define TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_impl) \
|
||||
#define MAKE_ENUM_TYPE_INFO(m_enum) \
|
||||
template <> \
|
||||
struct GetTypeInfo<m_impl> { \
|
||||
struct GetTypeInfo<m_enum> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_ENUM, \
|
||||
godot::details::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
GodotTypeInfo::Internal::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define MAKE_ENUM_TYPE_INFO(m_enum) \
|
||||
TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_enum) \
|
||||
TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_enum const) \
|
||||
TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_enum &) \
|
||||
TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, const m_enum &)
|
||||
|
||||
template <typename T>
|
||||
inline StringName __constant_get_enum_name(T param, const String &p_constant) {
|
||||
if constexpr (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
|
||||
ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant);
|
||||
}
|
||||
return GetTypeInfo<T>::get_class_info().class_name;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class BitField {
|
||||
int64_t value = 0;
|
||||
|
||||
public:
|
||||
_FORCE_INLINE_ BitField<T> &set_flag(T p_flag) {
|
||||
value |= (int64_t)p_flag;
|
||||
return *this;
|
||||
}
|
||||
_FORCE_INLINE_ bool has_flag(T p_flag) const { return value & (int64_t)p_flag; }
|
||||
_FORCE_INLINE_ bool is_empty() const { return value == 0; }
|
||||
_FORCE_INLINE_ void clear_flag(T p_flag) { value &= ~(int64_t)p_flag; }
|
||||
_FORCE_INLINE_ void clear() { value = 0; }
|
||||
_FORCE_INLINE_ constexpr BitField() = default;
|
||||
_FORCE_INLINE_ constexpr BitField(int64_t p_value) { value = p_value; }
|
||||
_FORCE_INLINE_ constexpr BitField(T p_value) { value = (int64_t)p_value; }
|
||||
_FORCE_INLINE_ operator int64_t() const { return value; }
|
||||
_FORCE_INLINE_ operator Variant() const { return value; }
|
||||
_FORCE_INLINE_ BitField<T> operator^(const BitField<T> &p_b) const { return BitField<T>(value ^ p_b.value); }
|
||||
};
|
||||
|
||||
#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_impl) \
|
||||
#define MAKE_BITFIELD_TYPE_INFO(m_enum) \
|
||||
template <> \
|
||||
struct GetTypeInfo<m_impl> { \
|
||||
struct GetTypeInfo<m_enum> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
||||
godot::details::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
GodotTypeInfo::Internal::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<BitField<m_impl>> { \
|
||||
struct GetTypeInfo<BitField<m_enum>> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::INT; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::INT, String(), PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_CLASS_IS_BITFIELD, \
|
||||
godot::details::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
GodotTypeInfo::Internal::enum_qualified_name_to_class_info_name(String(#m_enum))); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define MAKE_BITFIELD_TYPE_INFO(m_enum) \
|
||||
TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_enum) \
|
||||
TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_enum const) \
|
||||
TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_enum &) \
|
||||
TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, const m_enum &)
|
||||
|
||||
template <typename T>
|
||||
inline StringName __constant_get_bitfield_name(T param, const String &p_constant) {
|
||||
if (GetTypeInfo<T>::VARIANT_TYPE == Variant::NIL) {
|
||||
ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's bitfield: " + p_constant);
|
||||
}
|
||||
return GetTypeInfo<BitField<T>>::get_class_info().class_name;
|
||||
}
|
||||
#define CLASS_INFO(m_type) (GetTypeInfo<m_type *>::get_class_info())
|
||||
|
||||
// No initialization by default, except for scalar types.
|
||||
template <typename T>
|
||||
struct ZeroInitializer {
|
||||
static void initialize(T &value) {} //no initialization by default
|
||||
static void initialize(T &value) {
|
||||
if constexpr (std::is_scalar_v<T>) {
|
||||
value = {};
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct ZeroInitializer<bool> {
|
||||
static void initialize(bool &value) { value = false; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct ZeroInitializer<T *> {
|
||||
static void initialize(T *&value) { value = nullptr; }
|
||||
};
|
||||
|
||||
#define ZERO_INITIALIZER_NUMBER(m_type) \
|
||||
template <> \
|
||||
struct ZeroInitializer<m_type> { \
|
||||
static void initialize(m_type &value) { \
|
||||
value = 0; \
|
||||
} \
|
||||
};
|
||||
|
||||
ZERO_INITIALIZER_NUMBER(uint8_t)
|
||||
ZERO_INITIALIZER_NUMBER(int8_t)
|
||||
ZERO_INITIALIZER_NUMBER(uint16_t)
|
||||
ZERO_INITIALIZER_NUMBER(int16_t)
|
||||
ZERO_INITIALIZER_NUMBER(uint32_t)
|
||||
ZERO_INITIALIZER_NUMBER(int32_t)
|
||||
ZERO_INITIALIZER_NUMBER(uint64_t)
|
||||
ZERO_INITIALIZER_NUMBER(int64_t)
|
||||
ZERO_INITIALIZER_NUMBER(char16_t)
|
||||
ZERO_INITIALIZER_NUMBER(char32_t)
|
||||
ZERO_INITIALIZER_NUMBER(float)
|
||||
ZERO_INITIALIZER_NUMBER(double)
|
||||
|
||||
#endif // TYPE_INFO_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TYPED_ARRAY_H
|
||||
#define TYPED_ARRAY_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/object.h"
|
||||
#include "core/variant/array.h"
|
||||
|
|
@ -56,6 +55,8 @@ public:
|
|||
assign(p_array);
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ TypedArray(std::initializer_list<Variant> p_init) :
|
||||
TypedArray(Array(p_init)) {}
|
||||
_FORCE_INLINE_ TypedArray() {
|
||||
set_typed(Variant::OBJECT, T::get_class_static(), Variant());
|
||||
}
|
||||
|
|
@ -82,6 +83,9 @@ struct VariantInternalAccessor<const TypedArray<T> &> {
|
|||
ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type."); \
|
||||
_ref(p_array); \
|
||||
} \
|
||||
_FORCE_INLINE_ TypedArray(std::initializer_list<Variant> p_init) : \
|
||||
Array(Array(p_init), m_variant_type, StringName(), Variant()) { \
|
||||
} \
|
||||
_FORCE_INLINE_ TypedArray(const Variant &p_variant) : \
|
||||
TypedArray(Array(p_variant)) { \
|
||||
} \
|
||||
|
|
@ -158,14 +162,6 @@ struct PtrToArg<TypedArray<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct PtrToArg<const TypedArray<T> &> {
|
||||
typedef Array EncodeT;
|
||||
_FORCE_INLINE_ static TypedArray<T> convert(const void *p_ptr) {
|
||||
return TypedArray<T>(*reinterpret_cast<const Array *>(p_ptr));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct GetTypeInfo<TypedArray<T>> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::ARRAY;
|
||||
|
|
@ -175,15 +171,6 @@ struct GetTypeInfo<TypedArray<T>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct GetTypeInfo<const TypedArray<T> &> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::ARRAY;
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
|
||||
static inline PropertyInfo get_class_info() {
|
||||
return PropertyInfo(Variant::ARRAY, String(), PROPERTY_HINT_ARRAY_TYPE, T::get_class_static());
|
||||
}
|
||||
};
|
||||
|
||||
#define MAKE_TYPED_ARRAY_INFO(m_type, m_variant_type) \
|
||||
template <> \
|
||||
struct GetTypeInfo<TypedArray<m_type>> { \
|
||||
|
|
@ -192,14 +179,6 @@ struct GetTypeInfo<const TypedArray<T> &> {
|
|||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::ARRAY, String(), PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type)); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<const TypedArray<m_type> &> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::ARRAY; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::ARRAY, String(), PROPERTY_HINT_ARRAY_TYPE, Variant::get_type_name(m_variant_type)); \
|
||||
} \
|
||||
};
|
||||
|
||||
MAKE_TYPED_ARRAY_INFO(bool, Variant::BOOL)
|
||||
|
|
@ -251,5 +230,3 @@ MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING)
|
|||
|
||||
#undef MAKE_TYPED_ARRAY
|
||||
#undef MAKE_TYPED_ARRAY_INFO
|
||||
|
||||
#endif // TYPED_ARRAY_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef TYPED_DICTIONARY_H
|
||||
#define TYPED_DICTIONARY_H
|
||||
#pragma once
|
||||
|
||||
#include "core/object/object.h"
|
||||
#include "core/variant/binder_common.h"
|
||||
|
|
@ -92,15 +91,6 @@ struct PtrToArg<TypedDictionary<K, V>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct PtrToArg<const TypedDictionary<K, V> &> {
|
||||
typedef Dictionary EncodeT;
|
||||
_FORCE_INLINE_ static TypedDictionary<K, V>
|
||||
convert(const void *p_ptr) {
|
||||
return TypedDictionary<K, V>(*reinterpret_cast<const Dictionary *>(p_ptr));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct GetTypeInfo<TypedDictionary<K, V>> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY;
|
||||
|
|
@ -110,15 +100,6 @@ struct GetTypeInfo<TypedDictionary<K, V>> {
|
|||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
struct GetTypeInfo<const TypedDictionary<K, V> &> {
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY;
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE;
|
||||
static inline PropertyInfo get_class_info() {
|
||||
return PropertyInfo(Variant::DICTIONARY, String(), PROPERTY_HINT_DICTIONARY_TYPE, vformat("%s;%s", K::get_class_static(), V::get_class_static()));
|
||||
}
|
||||
};
|
||||
|
||||
// Specialization for the rest of the Variant types.
|
||||
|
||||
#define MAKE_TYPED_DICTIONARY_WITH_OBJECT(m_type, m_variant_type) \
|
||||
|
|
@ -161,15 +142,6 @@ struct GetTypeInfo<const TypedDictionary<K, V> &> {
|
|||
} \
|
||||
}; \
|
||||
template <typename T> \
|
||||
struct GetTypeInfo<const TypedDictionary<T, m_type> &> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::DICTIONARY, String(), PROPERTY_HINT_DICTIONARY_TYPE, \
|
||||
vformat("%s;%s", T::get_class_static(), m_variant_type == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type))); \
|
||||
} \
|
||||
}; \
|
||||
template <typename T> \
|
||||
class TypedDictionary<m_type, T> : public Dictionary { \
|
||||
public: \
|
||||
_FORCE_INLINE_ void operator=(const Dictionary &p_dictionary) { \
|
||||
|
|
@ -190,18 +162,16 @@ struct GetTypeInfo<const TypedDictionary<K, V> &> {
|
|||
_FORCE_INLINE_ TypedDictionary() { \
|
||||
set_typed(m_variant_type, StringName(), Variant(), Variant::OBJECT, T::get_class_static(), Variant()); \
|
||||
} \
|
||||
}; \
|
||||
template <typename T> \
|
||||
struct GetTypeInfo<TypedDictionary<m_type, T>> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::DICTIONARY, String(), PROPERTY_HINT_DICTIONARY_TYPE, \
|
||||
vformat("%s;%s", m_variant_type == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type), T::get_class_static())); \
|
||||
_FORCE_INLINE_ TypedDictionary(std::initializer_list<KeyValue<m_type, T>> p_init) : \
|
||||
Dictionary() { \
|
||||
set_typed(m_variant_type, StringName(), Variant(), Variant::OBJECT, std::remove_pointer<T>::type::get_class_static(), Variant()); \
|
||||
for (const KeyValue<m_type, T> &E : p_init) { \
|
||||
operator[](E.key) = E.value; \
|
||||
} \
|
||||
} \
|
||||
}; \
|
||||
template <typename T> \
|
||||
struct GetTypeInfo<const TypedDictionary<m_type, T> &> { \
|
||||
struct GetTypeInfo<TypedDictionary<m_type, T>> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
|
|
@ -249,16 +219,6 @@ struct GetTypeInfo<const TypedDictionary<K, V> &> {
|
|||
vformat("%s;%s", m_variant_type_key == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type_key), \
|
||||
m_variant_type_value == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type_value))); \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
struct GetTypeInfo<const TypedDictionary<m_type_key, m_type_value> &> { \
|
||||
static const Variant::Type VARIANT_TYPE = Variant::DICTIONARY; \
|
||||
static const GodotTypeInfo::Metadata METADATA = GodotTypeInfo::METADATA_NONE; \
|
||||
static inline PropertyInfo get_class_info() { \
|
||||
return PropertyInfo(Variant::DICTIONARY, String(), PROPERTY_HINT_DICTIONARY_TYPE, \
|
||||
vformat("%s;%s", m_variant_type_key == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type_key), \
|
||||
m_variant_type_value == Variant::NIL ? "Variant" : Variant::get_type_name(m_variant_type_value))); \
|
||||
} \
|
||||
};
|
||||
|
||||
#define MAKE_TYPED_DICTIONARY_NIL(m_type, m_variant_type) \
|
||||
|
|
@ -360,5 +320,3 @@ MAKE_TYPED_DICTIONARY(IPAddress, Variant::STRING)
|
|||
#undef MAKE_TYPED_DICTIONARY_NIL
|
||||
#undef MAKE_TYPED_DICTIONARY_EXPANDED
|
||||
#undef MAKE_TYPED_DICTIONARY_WITH_OBJECT
|
||||
|
||||
#endif // TYPED_DICTIONARY_H
|
||||
|
|
|
|||
|
|
@ -984,34 +984,34 @@ bool Variant::is_zero() const {
|
|||
|
||||
// Arrays.
|
||||
case PACKED_BYTE_ARRAY: {
|
||||
return PackedArrayRef<uint8_t>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<uint8_t>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_INT32_ARRAY: {
|
||||
return PackedArrayRef<int32_t>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<int32_t>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_INT64_ARRAY: {
|
||||
return PackedArrayRef<int64_t>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<int64_t>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_FLOAT32_ARRAY: {
|
||||
return PackedArrayRef<float>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<float>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_FLOAT64_ARRAY: {
|
||||
return PackedArrayRef<double>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<double>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_STRING_ARRAY: {
|
||||
return PackedArrayRef<String>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<String>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_VECTOR2_ARRAY: {
|
||||
return PackedArrayRef<Vector2>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<Vector2>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_VECTOR3_ARRAY: {
|
||||
return PackedArrayRef<Vector3>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<Vector3>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_COLOR_ARRAY: {
|
||||
return PackedArrayRef<Color>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<Color>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
case PACKED_VECTOR4_ARRAY: {
|
||||
return PackedArrayRef<Vector4>::get_array(_data.packed_array).size() == 0;
|
||||
return PackedArrayRef<Vector4>::get_array(_data.packed_array).is_empty();
|
||||
}
|
||||
default: {
|
||||
}
|
||||
|
|
@ -1654,15 +1654,13 @@ String Variant::stringify(int recursion_count) const {
|
|||
// Add leading and trailing space to Dictionary printing. This distinguishes it
|
||||
// from array printing on fonts that have similar-looking {} and [] characters.
|
||||
String str("{ ");
|
||||
List<Variant> keys;
|
||||
d.get_key_list(&keys);
|
||||
|
||||
Vector<_VariantStrPair> pairs;
|
||||
|
||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
||||
for (const KeyValue<Variant, Variant> &kv : d) {
|
||||
_VariantStrPair sp;
|
||||
sp.key = stringify_variant_clean(E->get(), recursion_count);
|
||||
sp.value = stringify_variant_clean(d[E->get()], recursion_count);
|
||||
sp.key = stringify_variant_clean(kv.key, recursion_count);
|
||||
sp.value = stringify_variant_clean(kv.value, recursion_count);
|
||||
|
||||
pairs.push_back(sp);
|
||||
}
|
||||
|
|
@ -2296,14 +2294,6 @@ Variant::operator Vector<StringName>() const {
|
|||
return to;
|
||||
}
|
||||
|
||||
Variant::operator Side() const {
|
||||
return (Side) operator int();
|
||||
}
|
||||
|
||||
Variant::operator Orientation() const {
|
||||
return (Orientation) operator int();
|
||||
}
|
||||
|
||||
Variant::operator IPAddress() const {
|
||||
if (type == PACKED_FLOAT32_ARRAY || type == PACKED_INT32_ARRAY || type == PACKED_FLOAT64_ARRAY || type == PACKED_INT64_ARRAY || type == PACKED_BYTE_ARRAY) {
|
||||
Vector<int> addr = operator Vector<int>();
|
||||
|
|
@ -2531,6 +2521,11 @@ Variant::Variant(const Dictionary &p_dictionary) :
|
|||
static_assert(sizeof(Dictionary) <= sizeof(_data._mem));
|
||||
}
|
||||
|
||||
Variant::Variant(std::initializer_list<Variant> p_init) :
|
||||
type(ARRAY) {
|
||||
memnew_placement(_data._mem, Array(p_init));
|
||||
}
|
||||
|
||||
Variant::Variant(const Array &p_array) :
|
||||
type(ARRAY) {
|
||||
memnew_placement(_data._mem, Array(p_array));
|
||||
|
|
@ -3139,32 +3134,20 @@ uint32_t Variant::recursive_hash(int recursion_count) const {
|
|||
#define hash_compare_scalar(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar_base(p_lhs, p_rhs, true))
|
||||
|
||||
#define hash_compare_vector2(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y))
|
||||
#define hash_compare_vector2(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_vector3(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z))
|
||||
#define hash_compare_vector3(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_vector4(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z) && \
|
||||
hash_compare_scalar((p_lhs).w, (p_rhs).w))
|
||||
#define hash_compare_vector4(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_quaternion(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).x, (p_rhs).x) && \
|
||||
hash_compare_scalar((p_lhs).y, (p_rhs).y) && \
|
||||
hash_compare_scalar((p_lhs).z, (p_rhs).z) && \
|
||||
hash_compare_scalar((p_lhs).w, (p_rhs).w))
|
||||
#define hash_compare_quaternion(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_color(p_lhs, p_rhs) \
|
||||
(hash_compare_scalar((p_lhs).r, (p_rhs).r) && \
|
||||
hash_compare_scalar((p_lhs).g, (p_rhs).g) && \
|
||||
hash_compare_scalar((p_lhs).b, (p_rhs).b) && \
|
||||
hash_compare_scalar((p_lhs).a, (p_rhs).a))
|
||||
#define hash_compare_color(p_lhs, p_rhs) \
|
||||
(p_lhs).is_same(p_rhs)
|
||||
|
||||
#define hash_compare_packed_array(p_lhs, p_rhs, p_type, p_compare_func) \
|
||||
const Vector<p_type> &l = PackedArrayRef<p_type>::get_array(p_lhs); \
|
||||
|
|
@ -3235,13 +3218,7 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
Transform2D *l = _data._transform2d;
|
||||
Transform2D *r = p_variant._data._transform2d;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector2(l->columns[i], r->columns[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case VECTOR3: {
|
||||
|
|
@ -3273,17 +3250,14 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
const Plane *l = reinterpret_cast<const Plane *>(_data._mem);
|
||||
const Plane *r = reinterpret_cast<const Plane *>(p_variant._data._mem);
|
||||
|
||||
return hash_compare_vector3(l->normal, r->normal) &&
|
||||
hash_compare_scalar(l->d, r->d);
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case AABB: {
|
||||
const ::AABB *l = _data._aabb;
|
||||
const ::AABB *r = p_variant._data._aabb;
|
||||
|
||||
return hash_compare_vector3(l->position, r->position) &&
|
||||
hash_compare_vector3(l->size, r->size);
|
||||
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case QUATERNION: {
|
||||
|
|
@ -3297,38 +3271,20 @@ bool Variant::hash_compare(const Variant &p_variant, int recursion_count, bool s
|
|||
const Basis *l = _data._basis;
|
||||
const Basis *r = p_variant._data._basis;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector3(l->rows[i], r->rows[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case TRANSFORM3D: {
|
||||
const Transform3D *l = _data._transform3d;
|
||||
const Transform3D *r = p_variant._data._transform3d;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (!hash_compare_vector3(l->basis.rows[i], r->basis.rows[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return hash_compare_vector3(l->origin, r->origin);
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
case PROJECTION: {
|
||||
const Projection *l = _data._projection;
|
||||
const Projection *r = p_variant._data._projection;
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
if (!hash_compare_vector4(l->columns[i], r->columns[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return l->is_same(*r);
|
||||
} break;
|
||||
|
||||
case COLOR: {
|
||||
|
|
@ -3447,6 +3403,26 @@ bool StringLikeVariantComparator::compare(const Variant &p_lhs, const Variant &p
|
|||
return false;
|
||||
}
|
||||
|
||||
bool StringLikeVariantOrder::compare(const Variant &p_lhs, const Variant &p_rhs) {
|
||||
if (p_lhs.get_type() == Variant::STRING) {
|
||||
const String &lhs = *VariantInternal::get_string(&p_lhs);
|
||||
if (p_rhs.get_type() == Variant::STRING) {
|
||||
return StringName::AlphCompare::compare(lhs, *VariantInternal::get_string(&p_rhs));
|
||||
} else if (p_rhs.get_type() == Variant::STRING_NAME) {
|
||||
return StringName::AlphCompare::compare(lhs, *VariantInternal::get_string_name(&p_rhs));
|
||||
}
|
||||
} else if (p_lhs.get_type() == Variant::STRING_NAME) {
|
||||
const StringName &lhs = *VariantInternal::get_string_name(&p_lhs);
|
||||
if (p_rhs.get_type() == Variant::STRING) {
|
||||
return StringName::AlphCompare::compare(lhs, *VariantInternal::get_string(&p_rhs));
|
||||
} else if (p_rhs.get_type() == Variant::STRING_NAME) {
|
||||
return StringName::AlphCompare::compare(lhs, *VariantInternal::get_string_name(&p_rhs));
|
||||
}
|
||||
}
|
||||
|
||||
return p_lhs < p_rhs;
|
||||
}
|
||||
|
||||
bool Variant::is_ref_counted() const {
|
||||
return type == OBJECT && _get_obj().id.is_ref_counted();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_H
|
||||
#define VARIANT_H
|
||||
#pragma once
|
||||
|
||||
#include "core/core_string_names.h"
|
||||
#include "core/input/input_enums.h"
|
||||
|
|
@ -55,6 +54,8 @@
|
|||
#include "core/os/keyboard.h"
|
||||
#include "core/string/node_path.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/templates/bit_field.h"
|
||||
#include "core/templates/list.h"
|
||||
#include "core/templates/paged_allocator.h"
|
||||
#include "core/templates/rid.h"
|
||||
#include "core/variant/array.h"
|
||||
|
|
@ -66,6 +67,8 @@ class RefCounted;
|
|||
|
||||
template <typename T>
|
||||
class Ref;
|
||||
template <typename T>
|
||||
class BitField;
|
||||
|
||||
struct PropertyInfo;
|
||||
struct MethodInfo;
|
||||
|
|
@ -479,12 +482,13 @@ public:
|
|||
operator Vector<Variant>() const;
|
||||
operator Vector<StringName>() const;
|
||||
|
||||
// some core type enums to convert to
|
||||
operator Side() const;
|
||||
operator Orientation() const;
|
||||
|
||||
operator IPAddress() const;
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
_FORCE_INLINE_ operator T() const { return static_cast<T>(operator int64_t()); }
|
||||
template <typename T>
|
||||
_FORCE_INLINE_ operator BitField<T>() const { return static_cast<T>(operator uint64_t()); }
|
||||
|
||||
Object *get_validated_object() const;
|
||||
Object *get_validated_object_with_check(bool &r_previously_freed) const;
|
||||
|
||||
|
|
@ -527,6 +531,7 @@ public:
|
|||
Variant(const Signal &p_signal);
|
||||
Variant(const Dictionary &p_dictionary);
|
||||
|
||||
Variant(std::initializer_list<Variant> p_init);
|
||||
Variant(const Array &p_array);
|
||||
Variant(const PackedByteArray &p_byte_array);
|
||||
Variant(const PackedInt32Array &p_int32_array);
|
||||
|
|
@ -547,22 +552,12 @@ public:
|
|||
|
||||
Variant(const IPAddress &p_address);
|
||||
|
||||
#define VARIANT_ENUM_CLASS_CONSTRUCTOR(m_enum) \
|
||||
Variant(m_enum p_value) : \
|
||||
type(INT) { \
|
||||
_data._int = (int64_t)p_value; \
|
||||
}
|
||||
|
||||
// Only enum classes that need to be bound need this to be defined.
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(EulerOrder)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyAxis)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(Key)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(KeyLocation)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(MIDIMessage)
|
||||
VARIANT_ENUM_CLASS_CONSTRUCTOR(MouseButton)
|
||||
|
||||
#undef VARIANT_ENUM_CLASS_CONSTRUCTOR
|
||||
template <typename T, std::enable_if_t<std::is_enum_v<T>, int> = 0>
|
||||
_FORCE_INLINE_ Variant(T p_enum) :
|
||||
Variant(static_cast<int64_t>(p_enum)) {}
|
||||
template <typename T>
|
||||
_FORCE_INLINE_ Variant(BitField<T> p_bitfield) :
|
||||
Variant(static_cast<uint64_t>(p_bitfield)) {}
|
||||
|
||||
// If this changes the table in variant_op must be updated
|
||||
enum Operator {
|
||||
|
|
@ -910,12 +905,7 @@ struct StringLikeVariantComparator {
|
|||
};
|
||||
|
||||
struct StringLikeVariantOrder {
|
||||
static _ALWAYS_INLINE_ bool compare(const Variant &p_lhs, const Variant &p_rhs) {
|
||||
if (p_lhs.is_string() && p_rhs.is_string()) {
|
||||
return p_lhs.operator String() < p_rhs.operator String();
|
||||
}
|
||||
return p_lhs < p_rhs;
|
||||
}
|
||||
static bool compare(const Variant &p_lhs, const Variant &p_rhs);
|
||||
|
||||
_ALWAYS_INLINE_ bool operator()(const Variant &p_lhs, const Variant &p_rhs) const {
|
||||
return compare(p_lhs, p_rhs);
|
||||
|
|
@ -998,18 +988,10 @@ Array::Iterator &Array::Iterator::operator--() {
|
|||
}
|
||||
|
||||
const Variant &Array::ConstIterator::operator*() const {
|
||||
if (unlikely(read_only)) {
|
||||
*read_only = *element_ptr;
|
||||
return *read_only;
|
||||
}
|
||||
return *element_ptr;
|
||||
}
|
||||
|
||||
const Variant *Array::ConstIterator::operator->() const {
|
||||
if (unlikely(read_only)) {
|
||||
*read_only = *element_ptr;
|
||||
return read_only;
|
||||
}
|
||||
return element_ptr;
|
||||
}
|
||||
|
||||
|
|
@ -1023,4 +1005,6 @@ Array::ConstIterator &Array::ConstIterator::operator--() {
|
|||
return *this;
|
||||
}
|
||||
|
||||
#endif // VARIANT_H
|
||||
// Zero-constructing Variant results in NULL.
|
||||
template <>
|
||||
struct is_zero_constructible<Variant> : std::true_type {};
|
||||
|
|
|
|||
|
|
@ -694,11 +694,62 @@ struct _VariantCall {
|
|||
return s;
|
||||
}
|
||||
|
||||
static void func_PackedByteArray_bswap16(PackedByteArray *p_instance, int64_t p_offset, int64_t p_count) {
|
||||
size_t sz = p_instance->size();
|
||||
if (sz == 0 || p_count == 0) {
|
||||
return;
|
||||
}
|
||||
ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(sz) - 2);
|
||||
if (p_count < 0) {
|
||||
p_count = floor((sz - p_offset) / 2);
|
||||
}
|
||||
ERR_FAIL_COND(p_count > floor((sz - p_offset) / 2));
|
||||
|
||||
uint16_t *w = (uint16_t *)(p_instance->ptrw() + p_offset);
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
w[i] = BSWAP16(w[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void func_PackedByteArray_bswap32(PackedByteArray *p_instance, int64_t p_offset, int64_t p_count) {
|
||||
size_t sz = p_instance->size();
|
||||
if (sz == 0 || p_count == 0) {
|
||||
return;
|
||||
}
|
||||
ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(sz) - 4);
|
||||
if (p_count < 0) {
|
||||
p_count = floor((sz - p_offset) / 4);
|
||||
}
|
||||
ERR_FAIL_COND(p_count > floor((sz - p_offset) / 4));
|
||||
|
||||
uint32_t *w = (uint32_t *)(p_instance->ptrw() + p_offset);
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
w[i] = BSWAP32(w[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static void func_PackedByteArray_bswap64(PackedByteArray *p_instance, int64_t p_offset, int64_t p_count) {
|
||||
size_t sz = p_instance->size();
|
||||
if (sz == 0 || p_count == 0) {
|
||||
return;
|
||||
}
|
||||
ERR_FAIL_COND(p_offset < 0 || p_offset > int64_t(sz) - 8);
|
||||
if (p_count < 0) {
|
||||
p_count = floor((sz - p_offset) / 8);
|
||||
}
|
||||
ERR_FAIL_COND(p_count > floor((sz - p_offset) / 8));
|
||||
|
||||
uint64_t *w = (uint64_t *)(p_instance->ptrw() + p_offset);
|
||||
for (int64_t i = 0; i < p_count; i++) {
|
||||
w[i] = BSWAP64(w[i]);
|
||||
}
|
||||
}
|
||||
|
||||
static String func_PackedByteArray_get_string_from_utf8(PackedByteArray *p_instance) {
|
||||
String s;
|
||||
if (p_instance->size() > 0) {
|
||||
const uint8_t *r = p_instance->ptr();
|
||||
s.parse_utf8((const char *)r, p_instance->size());
|
||||
s.append_utf8((const char *)r, p_instance->size());
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
@ -707,7 +758,7 @@ struct _VariantCall {
|
|||
String s;
|
||||
if (p_instance->size() > 0) {
|
||||
const uint8_t *r = p_instance->ptr();
|
||||
s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
|
||||
s.append_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
@ -716,7 +767,7 @@ struct _VariantCall {
|
|||
String s;
|
||||
if (p_instance->size() > 0) {
|
||||
const uint8_t *r = p_instance->ptr();
|
||||
s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
|
||||
s.append_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t))));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
|
@ -726,14 +777,22 @@ struct _VariantCall {
|
|||
if (p_instance->size() > 0) {
|
||||
const uint8_t *r = p_instance->ptr();
|
||||
#ifdef WINDOWS_ENABLED
|
||||
s.parse_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
|
||||
s.append_utf16((const char16_t *)r, floor((double)p_instance->size() / (double)sizeof(char16_t)));
|
||||
#else
|
||||
s = String((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t)));
|
||||
s.append_utf32(Span((const char32_t *)r, floor((double)p_instance->size() / (double)sizeof(char32_t))));
|
||||
#endif
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static String func_PackedByteArray_get_string_from_multibyte_char(PackedByteArray *p_instance, const String &p_encoding) {
|
||||
String s;
|
||||
if (p_instance->size() > 0) {
|
||||
s = OS::get_singleton()->multibyte_to_string(p_encoding, *p_instance);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static PackedByteArray func_PackedByteArray_compress(PackedByteArray *p_instance, int p_mode) {
|
||||
PackedByteArray compressed;
|
||||
|
||||
|
|
@ -1731,6 +1790,10 @@ static void _register_variant_builtin_methods_string() {
|
|||
bind_string_method(format, sarray("values", "placeholder"), varray("{_}"));
|
||||
bind_string_methodv(replace, static_cast<String (String::*)(const String &, const String &) const>(&String::replace), sarray("what", "forwhat"), varray());
|
||||
bind_string_methodv(replacen, static_cast<String (String::*)(const String &, const String &) const>(&String::replacen), sarray("what", "forwhat"), varray());
|
||||
bind_string_method(replace_char, sarray("key", "with"), varray());
|
||||
bind_string_methodv(replace_chars, static_cast<String (String::*)(const String &, char32_t) const>(&String::replace_chars), sarray("keys", "with"), varray());
|
||||
bind_string_method(remove_char, sarray("what"), varray());
|
||||
bind_string_methodv(remove_chars, static_cast<String (String::*)(const String &) const>(&String::remove_chars), sarray("chars"), varray());
|
||||
bind_string_method(repeat, sarray("count"), varray());
|
||||
bind_string_method(reverse, sarray(), varray());
|
||||
bind_string_method(insert, sarray("position", "what"), varray());
|
||||
|
|
@ -1739,6 +1802,7 @@ static void _register_variant_builtin_methods_string() {
|
|||
bind_string_method(to_camel_case, sarray(), varray());
|
||||
bind_string_method(to_pascal_case, sarray(), varray());
|
||||
bind_string_method(to_snake_case, sarray(), varray());
|
||||
bind_string_method(to_kebab_case, sarray(), varray());
|
||||
bind_string_methodv(split, static_cast<Vector<String> (String::*)(const String &, bool, int) const>(&String::split), sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0));
|
||||
bind_string_methodv(rsplit, static_cast<Vector<String> (String::*)(const String &, bool, int) const>(&String::rsplit), sarray("delimiter", "allow_empty", "maxsplit"), varray("", true, 0));
|
||||
bind_string_method(split_floats, sarray("delimiter", "allow_empty"), varray(true));
|
||||
|
|
@ -1780,6 +1844,7 @@ static void _register_variant_builtin_methods_string() {
|
|||
bind_string_method(xml_unescape, sarray(), varray());
|
||||
bind_string_method(uri_encode, sarray(), varray());
|
||||
bind_string_method(uri_decode, sarray(), varray());
|
||||
bind_string_method(uri_file_decode, sarray(), varray());
|
||||
bind_string_method(c_escape, sarray(), varray());
|
||||
bind_string_method(c_unescape, sarray(), varray());
|
||||
bind_string_method(json_escape, sarray(), varray());
|
||||
|
|
@ -1813,8 +1878,9 @@ static void _register_variant_builtin_methods_string() {
|
|||
bind_string_method(to_utf8_buffer, sarray(), varray());
|
||||
bind_string_method(to_utf16_buffer, sarray(), varray());
|
||||
bind_string_method(to_utf32_buffer, sarray(), varray());
|
||||
bind_string_method(hex_decode, sarray(), varray());
|
||||
bind_string_method(to_wchar_buffer, sarray(), varray());
|
||||
bind_string_method(to_multibyte_char_buffer, sarray("encoding"), varray(String()));
|
||||
bind_string_method(hex_decode, sarray(), varray());
|
||||
|
||||
bind_static_method(String, num_scientific, sarray("number"), varray());
|
||||
bind_static_method(String, num, sarray("number", "decimals"), varray(-1));
|
||||
|
|
@ -2449,12 +2515,14 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedByteArray, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedByteArray, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedByteArray, count, sarray("value"), varray());
|
||||
bind_method(PackedByteArray, erase, sarray("value"), varray());
|
||||
|
||||
bind_function(PackedByteArray, get_string_from_ascii, _VariantCall::func_PackedByteArray_get_string_from_ascii, sarray(), varray());
|
||||
bind_function(PackedByteArray, get_string_from_utf8, _VariantCall::func_PackedByteArray_get_string_from_utf8, sarray(), varray());
|
||||
bind_function(PackedByteArray, get_string_from_utf16, _VariantCall::func_PackedByteArray_get_string_from_utf16, sarray(), varray());
|
||||
bind_function(PackedByteArray, get_string_from_utf32, _VariantCall::func_PackedByteArray_get_string_from_utf32, sarray(), varray());
|
||||
bind_function(PackedByteArray, get_string_from_wchar, _VariantCall::func_PackedByteArray_get_string_from_wchar, sarray(), varray());
|
||||
bind_function(PackedByteArray, get_string_from_multibyte_char, _VariantCall::func_PackedByteArray_get_string_from_multibyte_char, sarray("encoding"), varray(String()));
|
||||
bind_function(PackedByteArray, hex_encode, _VariantCall::func_PackedByteArray_hex_encode, sarray(), varray());
|
||||
bind_function(PackedByteArray, compress, _VariantCall::func_PackedByteArray_compress, sarray("compression_mode"), varray(0));
|
||||
bind_function(PackedByteArray, decompress, _VariantCall::func_PackedByteArray_decompress, sarray("buffer_size", "compression_mode"), varray(0));
|
||||
|
|
@ -2480,6 +2548,10 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_function(PackedByteArray, to_float32_array, _VariantCall::func_PackedByteArray_decode_float_array, sarray(), varray());
|
||||
bind_function(PackedByteArray, to_float64_array, _VariantCall::func_PackedByteArray_decode_double_array, sarray(), varray());
|
||||
|
||||
bind_functionnc(PackedByteArray, bswap16, _VariantCall::func_PackedByteArray_bswap16, sarray("offset", "count"), varray(0, -1));
|
||||
bind_functionnc(PackedByteArray, bswap32, _VariantCall::func_PackedByteArray_bswap32, sarray("offset", "count"), varray(0, -1));
|
||||
bind_functionnc(PackedByteArray, bswap64, _VariantCall::func_PackedByteArray_bswap64, sarray("offset", "count"), varray(0, -1));
|
||||
|
||||
bind_functionnc(PackedByteArray, encode_u8, _VariantCall::func_PackedByteArray_encode_u8, sarray("byte_offset", "value"), varray());
|
||||
bind_functionnc(PackedByteArray, encode_s8, _VariantCall::func_PackedByteArray_encode_s8, sarray("byte_offset", "value"), varray());
|
||||
bind_functionnc(PackedByteArray, encode_u16, _VariantCall::func_PackedByteArray_encode_u16, sarray("byte_offset", "value"), varray());
|
||||
|
|
@ -2515,6 +2587,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedInt32Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedInt32Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedInt32Array, count, sarray("value"), varray());
|
||||
bind_method(PackedInt32Array, erase, sarray("value"), varray());
|
||||
|
||||
/* Int64 Array */
|
||||
|
||||
|
|
@ -2538,6 +2611,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedInt64Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedInt64Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedInt64Array, count, sarray("value"), varray());
|
||||
bind_method(PackedInt64Array, erase, sarray("value"), varray());
|
||||
|
||||
/* Float32 Array */
|
||||
|
||||
|
|
@ -2561,6 +2635,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedFloat32Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedFloat32Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedFloat32Array, count, sarray("value"), varray());
|
||||
bind_method(PackedFloat32Array, erase, sarray("value"), varray());
|
||||
|
||||
/* Float64 Array */
|
||||
|
||||
|
|
@ -2584,6 +2659,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedFloat64Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedFloat64Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedFloat64Array, count, sarray("value"), varray());
|
||||
bind_method(PackedFloat64Array, erase, sarray("value"), varray());
|
||||
|
||||
/* String Array */
|
||||
|
||||
|
|
@ -2607,6 +2683,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedStringArray, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedStringArray, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedStringArray, count, sarray("value"), varray());
|
||||
bind_method(PackedStringArray, erase, sarray("value"), varray());
|
||||
|
||||
/* Vector2 Array */
|
||||
|
||||
|
|
@ -2630,6 +2707,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedVector2Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedVector2Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedVector2Array, count, sarray("value"), varray());
|
||||
bind_method(PackedVector2Array, erase, sarray("value"), varray());
|
||||
|
||||
/* Vector3 Array */
|
||||
|
||||
|
|
@ -2653,6 +2731,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedVector3Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedVector3Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedVector3Array, count, sarray("value"), varray());
|
||||
bind_method(PackedVector3Array, erase, sarray("value"), varray());
|
||||
|
||||
/* Color Array */
|
||||
|
||||
|
|
@ -2676,6 +2755,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedColorArray, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedColorArray, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedColorArray, count, sarray("value"), varray());
|
||||
bind_method(PackedColorArray, erase, sarray("value"), varray());
|
||||
|
||||
/* Vector4 Array */
|
||||
|
||||
|
|
@ -2699,6 +2779,7 @@ static void _register_variant_builtin_methods_array() {
|
|||
bind_method(PackedVector4Array, find, sarray("value", "from"), varray(0));
|
||||
bind_method(PackedVector4Array, rfind, sarray("value", "from"), varray(-1));
|
||||
bind_method(PackedVector4Array, count, sarray("value"), varray());
|
||||
bind_method(PackedVector4Array, erase, sarray("value"), varray());
|
||||
}
|
||||
|
||||
static void _register_variant_builtin_constants() {
|
||||
|
|
@ -2715,7 +2796,7 @@ static void _register_variant_builtin_constants() {
|
|||
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "ZERO", Vector3(0, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "ONE", Vector3(1, 1, 1));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(INFINITY, INFINITY, INFINITY));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "INF", Vector3(Math::INF, Math::INF, Math::INF));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "LEFT", Vector3(-1, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "RIGHT", Vector3(1, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR3, "UP", Vector3(0, 1, 0));
|
||||
|
|
@ -2737,7 +2818,7 @@ static void _register_variant_builtin_constants() {
|
|||
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR4, "ZERO", Vector4(0, 0, 0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR4, "ONE", Vector4(1, 1, 1, 1));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR4, "INF", Vector4(INFINITY, INFINITY, INFINITY, INFINITY));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR4, "INF", Vector4(Math::INF, Math::INF, Math::INF, Math::INF));
|
||||
|
||||
_VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_X", Vector3i::AXIS_X);
|
||||
_VariantCall::add_enum_constant(Variant::VECTOR3I, "Axis", "AXIS_Y", Vector3i::AXIS_Y);
|
||||
|
|
@ -2772,7 +2853,7 @@ static void _register_variant_builtin_constants() {
|
|||
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "ZERO", Vector2(0, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "ONE", Vector2(1, 1));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(INFINITY, INFINITY));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "INF", Vector2(Math::INF, Math::INF));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "LEFT", Vector2(-1, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "RIGHT", Vector2(1, 0));
|
||||
_VariantCall::add_variant_constant(Variant::VECTOR2, "UP", Vector2(0, -1));
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_CALLABLE_H
|
||||
#define VARIANT_CALLABLE_H
|
||||
#pragma once
|
||||
|
||||
#include "core/variant/callable.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
|
@ -55,5 +54,3 @@ public:
|
|||
|
||||
VariantCallable(const Variant &p_variant, const StringName &p_method);
|
||||
};
|
||||
|
||||
#endif // VARIANT_CALLABLE_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_CONSTRUCT_H
|
||||
#define VARIANT_CONSTRUCT_H
|
||||
#pragma once
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
|
|
@ -813,5 +812,3 @@ public:
|
|||
return Variant::OBJECT;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // VARIANT_CONSTRUCT_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_DESTRUCT_H
|
||||
#define VARIANT_DESTRUCT_H
|
||||
#pragma once
|
||||
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
|
|
@ -68,5 +67,3 @@ MAKE_PTRDESTRUCT(PackedColorArray);
|
|||
MAKE_PTRDESTRUCT(PackedVector4Array);
|
||||
|
||||
#undef MAKE_PTRDESTRUCT
|
||||
|
||||
#endif // VARIANT_DESTRUCT_H
|
||||
|
|
|
|||
|
|
@ -28,11 +28,12 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_INTERNAL_H
|
||||
#define VARIANT_INTERNAL_H
|
||||
#pragma once
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
#include "core/templates/simple_type.h"
|
||||
|
||||
// For use when you want to access the internal pointer of a Variant directly.
|
||||
// Use with caution. You need to be sure that the type is correct.
|
||||
|
||||
|
|
@ -528,9 +529,11 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct VariantGetInternalPtr;
|
||||
|
||||
template <typename T>
|
||||
struct VariantGetInternalPtr {
|
||||
};
|
||||
struct VariantGetInternalPtr<T, std::enable_if_t<!std::is_same_v<T, GetSimpleTypeT<T>>>> : VariantGetInternalPtr<GetSimpleTypeT<T>> {};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<bool> {
|
||||
|
|
@ -538,56 +541,14 @@ struct VariantGetInternalPtr<bool> {
|
|||
static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<int8_t> {
|
||||
template <typename T>
|
||||
struct VariantGetInternalPtr<T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<uint8_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<int16_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<uint16_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<int32_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<uint32_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<int64_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<uint64_t> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<char32_t> {
|
||||
template <typename T>
|
||||
struct VariantGetInternalPtr<BitField<T>, std::enable_if_t<std::is_enum_v<T>>> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
|
@ -598,12 +559,6 @@ struct VariantGetInternalPtr<ObjectID> {
|
|||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<Error> {
|
||||
static int64_t *get_ptr(Variant *v) { return VariantInternal::get_int(v); }
|
||||
static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantGetInternalPtr<float> {
|
||||
static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); }
|
||||
|
|
@ -821,9 +776,11 @@ struct VariantGetInternalPtr<PackedVector4Array> {
|
|||
static const PackedVector4Array *get_ptr(const Variant *v) { return VariantInternal::get_vector4_array(v); }
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct VariantInternalAccessor;
|
||||
|
||||
template <typename T>
|
||||
struct VariantInternalAccessor {
|
||||
};
|
||||
struct VariantInternalAccessor<T, std::enable_if_t<!std::is_same_v<T, GetSimpleTypeT<T>>>> : VariantInternalAccessor<GetSimpleTypeT<T>> {};
|
||||
|
||||
template <>
|
||||
struct VariantInternalAccessor<bool> {
|
||||
|
|
@ -831,26 +788,17 @@ struct VariantInternalAccessor<bool> {
|
|||
static _FORCE_INLINE_ void set(Variant *v, bool p_value) { *VariantInternal::get_bool(v) = p_value; }
|
||||
};
|
||||
|
||||
#define VARIANT_ACCESSOR_NUMBER(m_type) \
|
||||
template <> \
|
||||
struct VariantInternalAccessor<m_type> { \
|
||||
static _FORCE_INLINE_ m_type get(const Variant *v) { \
|
||||
return (m_type) * VariantInternal::get_int(v); \
|
||||
} \
|
||||
static _FORCE_INLINE_ void set(Variant *v, m_type p_value) { \
|
||||
*VariantInternal::get_int(v) = p_value; \
|
||||
} \
|
||||
};
|
||||
template <typename T>
|
||||
struct VariantInternalAccessor<T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>> {
|
||||
static _FORCE_INLINE_ T get(const Variant *v) { return static_cast<T>(*VariantInternal::get_int(v)); }
|
||||
static _FORCE_INLINE_ void set(Variant *v, T p_value) { *VariantInternal::get_int(v) = static_cast<int64_t>(p_value); }
|
||||
};
|
||||
|
||||
VARIANT_ACCESSOR_NUMBER(int8_t)
|
||||
VARIANT_ACCESSOR_NUMBER(uint8_t)
|
||||
VARIANT_ACCESSOR_NUMBER(int16_t)
|
||||
VARIANT_ACCESSOR_NUMBER(uint16_t)
|
||||
VARIANT_ACCESSOR_NUMBER(int32_t)
|
||||
VARIANT_ACCESSOR_NUMBER(uint32_t)
|
||||
VARIANT_ACCESSOR_NUMBER(int64_t)
|
||||
VARIANT_ACCESSOR_NUMBER(uint64_t)
|
||||
VARIANT_ACCESSOR_NUMBER(char32_t)
|
||||
template <typename T>
|
||||
struct VariantInternalAccessor<BitField<T>, std::enable_if_t<std::is_enum_v<T>>> {
|
||||
static _FORCE_INLINE_ BitField<T> get(const Variant *v) { return BitField<T>(static_cast<T>(*VariantInternal::get_int(v))); }
|
||||
static _FORCE_INLINE_ void set(Variant *v, BitField<T> p_value) { *VariantInternal::get_int(v) = static_cast<int64_t>(p_value); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInternalAccessor<ObjectID> {
|
||||
|
|
@ -1127,47 +1075,7 @@ struct VariantInternalAccessor<Vector<Variant>> {
|
|||
|
||||
template <typename T>
|
||||
struct VariantInitializer {
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<bool> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<bool>(v); }
|
||||
};
|
||||
|
||||
#define INITIALIZER_INT(m_type) \
|
||||
template <> \
|
||||
struct VariantInitializer<m_type> { \
|
||||
static _FORCE_INLINE_ void init(Variant *v) { \
|
||||
VariantInternal::init_generic<int64_t>(v); \
|
||||
} \
|
||||
};
|
||||
|
||||
INITIALIZER_INT(uint8_t)
|
||||
INITIALIZER_INT(int8_t)
|
||||
INITIALIZER_INT(uint16_t)
|
||||
INITIALIZER_INT(int16_t)
|
||||
INITIALIZER_INT(uint32_t)
|
||||
INITIALIZER_INT(int32_t)
|
||||
INITIALIZER_INT(uint64_t)
|
||||
INITIALIZER_INT(int64_t)
|
||||
INITIALIZER_INT(char32_t)
|
||||
INITIALIZER_INT(Error)
|
||||
INITIALIZER_INT(ObjectID)
|
||||
INITIALIZER_INT(Vector2::Axis)
|
||||
INITIALIZER_INT(Vector2i::Axis)
|
||||
INITIALIZER_INT(Vector3::Axis)
|
||||
INITIALIZER_INT(Vector3i::Axis)
|
||||
INITIALIZER_INT(Vector4::Axis)
|
||||
INITIALIZER_INT(Vector4i::Axis)
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<double> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<float> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<double>(v); }
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<T>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
|
|
@ -1175,59 +1083,11 @@ struct VariantInitializer<String> {
|
|||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Vector2> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Vector2i> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector2i>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Rect2> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Rect2i> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Rect2i>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Vector3> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Vector3i> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector3i>(v); }
|
||||
};
|
||||
template <>
|
||||
struct VariantInitializer<Vector4> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Vector4i> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Vector4i>(v); }
|
||||
};
|
||||
template <>
|
||||
struct VariantInitializer<Transform2D> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Plane> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Plane>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Quaternion> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Quaternion>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<AABB> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_aabb(v); }
|
||||
|
|
@ -1242,16 +1102,12 @@ template <>
|
|||
struct VariantInitializer<Transform3D> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform3d(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Projection> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_projection(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Color> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<Color>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<StringName> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_name(v); }
|
||||
|
|
@ -1262,11 +1118,6 @@ struct VariantInitializer<NodePath> {
|
|||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_node_path(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<::RID> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic<::RID>(v); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantInitializer<Callable> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_callable(v); }
|
||||
|
|
@ -1342,17 +1193,24 @@ struct VariantInitializer<Object *> {
|
|||
static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); }
|
||||
};
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct VariantDefaultInitializer;
|
||||
|
||||
template <typename T>
|
||||
struct VariantDefaultInitializer {
|
||||
};
|
||||
struct VariantDefaultInitializer<T, std::enable_if_t<!std::is_same_v<T, GetSimpleTypeT<T>>>> : VariantDefaultInitializer<GetSimpleTypeT<T>> {};
|
||||
|
||||
template <>
|
||||
struct VariantDefaultInitializer<bool> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_bool(v) = false; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct VariantDefaultInitializer<int64_t> {
|
||||
template <typename T>
|
||||
struct VariantDefaultInitializer<T, std::enable_if_t<std::is_integral_v<T> || std::is_enum_v<T>>> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int(v) = 0; }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct VariantDefaultInitializer<BitField<T>, std::enable_if_t<std::is_enum_v<T>>> {
|
||||
static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int(v) = 0; }
|
||||
};
|
||||
|
||||
|
|
@ -1590,5 +1448,3 @@ struct VariantTypeConstructor {
|
|||
memnew_placement(r_value, T(*reinterpret_cast<Variant *>(p_variant)));
|
||||
}
|
||||
};
|
||||
|
||||
#endif // VARIANT_INTERNAL_H
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_OP_H
|
||||
#define VARIANT_OP_H
|
||||
#pragma once
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
|
|
@ -908,9 +907,7 @@ template <typename S>
|
|||
class OperatorEvaluatorStringFormat<S, void> {
|
||||
public:
|
||||
_FORCE_INLINE_ static String do_mod(const String &s, bool *r_valid) {
|
||||
Array values;
|
||||
values.push_back(Variant());
|
||||
|
||||
Array values = { Variant() };
|
||||
String a = s.sprintf(values, r_valid);
|
||||
if (r_valid) {
|
||||
*r_valid = !*r_valid;
|
||||
|
|
@ -967,8 +964,7 @@ template <typename S>
|
|||
class OperatorEvaluatorStringFormat<S, Object> {
|
||||
public:
|
||||
_FORCE_INLINE_ static String do_mod(const String &s, const Object *p_object, bool *r_valid) {
|
||||
Array values;
|
||||
values.push_back(p_object);
|
||||
Array values = { p_object };
|
||||
String a = s.sprintf(values, r_valid);
|
||||
if (r_valid) {
|
||||
*r_valid = !*r_valid;
|
||||
|
|
@ -998,8 +994,7 @@ template <typename S, typename T>
|
|||
class OperatorEvaluatorStringFormat {
|
||||
public:
|
||||
_FORCE_INLINE_ static String do_mod(const String &s, const T &p_value, bool *r_valid) {
|
||||
Array values;
|
||||
values.push_back(p_value);
|
||||
Array values = { p_value };
|
||||
String a = s.sprintf(values, r_valid);
|
||||
if (r_valid) {
|
||||
*r_valid = !*r_valid;
|
||||
|
|
@ -1558,5 +1553,3 @@ public:
|
|||
}
|
||||
static Variant::Type get_return_type() { return Variant::BOOL; }
|
||||
};
|
||||
|
||||
#endif // VARIANT_OP_H
|
||||
|
|
|
|||
|
|
@ -147,11 +147,12 @@ const char *VariantParser::tk_name[TK_MAX] = {
|
|||
|
||||
static double stor_fix(const String &p_str) {
|
||||
if (p_str == "inf") {
|
||||
return INFINITY;
|
||||
} else if (p_str == "inf_neg") {
|
||||
return -INFINITY;
|
||||
return Math::INF;
|
||||
} else if (p_str == "-inf" || p_str == "inf_neg") {
|
||||
// inf_neg kept for compatibility.
|
||||
return -Math::INF;
|
||||
} else if (p_str == "nan") {
|
||||
return NAN;
|
||||
return Math::NaN;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -395,7 +396,10 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
}
|
||||
|
||||
if (p_stream->is_utf8()) {
|
||||
str.parse_utf8(str.ascii(true).get_data());
|
||||
// Re-interpret the string we built as ascii.
|
||||
CharString string_as_ascii = str.ascii(true);
|
||||
str.clear();
|
||||
str.append_utf8(string_as_ascii);
|
||||
}
|
||||
if (string_name) {
|
||||
r_token.type = TK_STRING_NAME;
|
||||
|
|
@ -411,11 +415,13 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
if (cchar <= 32) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (cchar == '-' || (cchar >= '0' && cchar <= '9')) {
|
||||
StringBuffer<> token_text;
|
||||
if (cchar == '-') {
|
||||
token_text += '-';
|
||||
cchar = p_stream->get_char();
|
||||
}
|
||||
if (cchar >= '0' && cchar <= '9') {
|
||||
//a number
|
||||
|
||||
StringBuffer<> num;
|
||||
#define READING_SIGN 0
|
||||
#define READING_INT 1
|
||||
#define READING_DEC 2
|
||||
|
|
@ -423,11 +429,6 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
#define READING_DONE 4
|
||||
int reading = READING_INT;
|
||||
|
||||
if (cchar == '-') {
|
||||
num += '-';
|
||||
cchar = p_stream->get_char();
|
||||
}
|
||||
|
||||
char32_t c = cchar;
|
||||
bool exp_sign = false;
|
||||
bool exp_beg = false;
|
||||
|
|
@ -474,7 +475,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
if (reading == READING_DONE) {
|
||||
break;
|
||||
}
|
||||
num += c;
|
||||
token_text += c;
|
||||
c = p_stream->get_char();
|
||||
}
|
||||
|
||||
|
|
@ -483,17 +484,16 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
r_token.type = TK_NUMBER;
|
||||
|
||||
if (is_float) {
|
||||
r_token.value = num.as_double();
|
||||
r_token.value = token_text.as_double();
|
||||
} else {
|
||||
r_token.value = num.as_int();
|
||||
r_token.value = token_text.as_int();
|
||||
}
|
||||
return OK;
|
||||
} else if (is_ascii_alphabet_char(cchar) || is_underscore(cchar)) {
|
||||
StringBuffer<> id;
|
||||
bool first = true;
|
||||
|
||||
while (is_ascii_alphabet_char(cchar) || is_underscore(cchar) || (!first && is_digit(cchar))) {
|
||||
id += cchar;
|
||||
token_text += cchar;
|
||||
cchar = p_stream->get_char();
|
||||
first = false;
|
||||
}
|
||||
|
|
@ -501,7 +501,7 @@ Error VariantParser::get_token(Stream *p_stream, Token &r_token, int &line, Stri
|
|||
p_stream->saved = cchar;
|
||||
|
||||
r_token.type = TK_IDENTIFIER;
|
||||
r_token.value = id.as_string();
|
||||
r_token.value = token_text.as_string();
|
||||
return OK;
|
||||
} else {
|
||||
r_err_str = "Unexpected character";
|
||||
|
|
@ -698,11 +698,12 @@ Error VariantParser::parse_value(Token &token, Variant &value, Stream *p_stream,
|
|||
} else if (id == "null" || id == "nil") {
|
||||
value = Variant();
|
||||
} else if (id == "inf") {
|
||||
value = INFINITY;
|
||||
} else if (id == "inf_neg") {
|
||||
value = -INFINITY;
|
||||
value = Math::INF;
|
||||
} else if (id == "-inf" || id == "inf_neg") {
|
||||
// inf_neg kept for compatibility.
|
||||
value = -Math::INF;
|
||||
} else if (id == "nan") {
|
||||
value = NAN;
|
||||
value = Math::NaN;
|
||||
} else if (id == "Vector2") {
|
||||
Vector<real_t> args;
|
||||
Error err = _parse_construct<real_t>(p_stream, args, line, r_err_str);
|
||||
|
|
@ -1736,7 +1737,8 @@ Error VariantParser::_parse_tag(Token &token, Stream *p_stream, int &line, Strin
|
|||
}
|
||||
cs += c;
|
||||
}
|
||||
r_tag.name.parse_utf8(cs.get_data(), cs.length());
|
||||
r_tag.name.clear();
|
||||
r_tag.name.append_utf8(cs.get_data(), cs.length());
|
||||
} else {
|
||||
while (true) {
|
||||
char32_t c = p_stream->get_char();
|
||||
|
|
@ -1932,7 +1934,7 @@ Error VariantParser::parse(Stream *p_stream, Variant &r_ret, String &r_err_str,
|
|||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static String rtos_fix(double p_value) {
|
||||
static String rtos_fix(double p_value, bool p_compat) {
|
||||
if (p_value == 0.0) {
|
||||
return "0"; //avoid negative zero (-0) being written, which may annoy git, svn, etc. for changes when they don't exist.
|
||||
} else if (isnan(p_value)) {
|
||||
|
|
@ -1940,8 +1942,10 @@ static String rtos_fix(double p_value) {
|
|||
} else if (isinf(p_value)) {
|
||||
if (p_value > 0) {
|
||||
return "inf";
|
||||
} else {
|
||||
} else if (p_compat) {
|
||||
return "inf_neg";
|
||||
} else {
|
||||
return "-inf";
|
||||
}
|
||||
} else {
|
||||
return rtoss(p_value);
|
||||
|
|
@ -1960,8 +1964,8 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
p_store_string_func(p_store_string_ud, itos(p_variant.operator int64_t()));
|
||||
} break;
|
||||
case Variant::FLOAT: {
|
||||
String s = rtos_fix(p_variant.operator double());
|
||||
if (s != "inf" && s != "inf_neg" && s != "nan") {
|
||||
String s = rtos_fix(p_variant.operator double(), p_compat);
|
||||
if (s != "inf" && s != "-inf" && s != "nan") {
|
||||
if (!s.contains_char('.') && !s.contains_char('e') && !s.contains_char('E')) {
|
||||
s += ".0";
|
||||
}
|
||||
|
|
@ -1977,7 +1981,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
// Math types.
|
||||
case Variant::VECTOR2: {
|
||||
Vector2 v = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Vector2(" + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Vector2(" + rtos_fix(v.x, p_compat) + ", " + rtos_fix(v.y, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::VECTOR2I: {
|
||||
Vector2i v = p_variant;
|
||||
|
|
@ -1985,7 +1989,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
case Variant::RECT2: {
|
||||
Rect2 aabb = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Rect2(" + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Rect2(" + rtos_fix(aabb.position.x, p_compat) + ", " + rtos_fix(aabb.position.y, p_compat) + ", " + rtos_fix(aabb.size.x, p_compat) + ", " + rtos_fix(aabb.size.y, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::RECT2I: {
|
||||
Rect2i aabb = p_variant;
|
||||
|
|
@ -1993,7 +1997,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
case Variant::VECTOR3: {
|
||||
Vector3 v = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Vector3(" + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ", " + rtos_fix(v.z) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Vector3(" + rtos_fix(v.x, p_compat) + ", " + rtos_fix(v.y, p_compat) + ", " + rtos_fix(v.z, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::VECTOR3I: {
|
||||
Vector3i v = p_variant;
|
||||
|
|
@ -2001,7 +2005,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
case Variant::VECTOR4: {
|
||||
Vector4 v = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Vector4(" + rtos_fix(v.x) + ", " + rtos_fix(v.y) + ", " + rtos_fix(v.z) + ", " + rtos_fix(v.w) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Vector4(" + rtos_fix(v.x, p_compat) + ", " + rtos_fix(v.y, p_compat) + ", " + rtos_fix(v.z, p_compat) + ", " + rtos_fix(v.w, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::VECTOR4I: {
|
||||
Vector4i v = p_variant;
|
||||
|
|
@ -2009,15 +2013,15 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
} break;
|
||||
case Variant::PLANE: {
|
||||
Plane p = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Plane(" + rtos_fix(p.normal.x) + ", " + rtos_fix(p.normal.y) + ", " + rtos_fix(p.normal.z) + ", " + rtos_fix(p.d) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Plane(" + rtos_fix(p.normal.x, p_compat) + ", " + rtos_fix(p.normal.y, p_compat) + ", " + rtos_fix(p.normal.z, p_compat) + ", " + rtos_fix(p.d, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::AABB: {
|
||||
AABB aabb = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "AABB(" + rtos_fix(aabb.position.x) + ", " + rtos_fix(aabb.position.y) + ", " + rtos_fix(aabb.position.z) + ", " + rtos_fix(aabb.size.x) + ", " + rtos_fix(aabb.size.y) + ", " + rtos_fix(aabb.size.z) + ")");
|
||||
p_store_string_func(p_store_string_ud, "AABB(" + rtos_fix(aabb.position.x, p_compat) + ", " + rtos_fix(aabb.position.y, p_compat) + ", " + rtos_fix(aabb.position.z, p_compat) + ", " + rtos_fix(aabb.size.x, p_compat) + ", " + rtos_fix(aabb.size.y, p_compat) + ", " + rtos_fix(aabb.size.z, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::QUATERNION: {
|
||||
Quaternion quaternion = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Quaternion(" + rtos_fix(quaternion.x) + ", " + rtos_fix(quaternion.y) + ", " + rtos_fix(quaternion.z) + ", " + rtos_fix(quaternion.w) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Quaternion(" + rtos_fix(quaternion.x, p_compat) + ", " + rtos_fix(quaternion.y, p_compat) + ", " + rtos_fix(quaternion.z, p_compat) + ", " + rtos_fix(quaternion.w, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::TRANSFORM2D: {
|
||||
String s = "Transform2D(";
|
||||
|
|
@ -2027,7 +2031,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i != 0 || j != 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += rtos_fix(m3.columns[i][j]);
|
||||
s += rtos_fix(m3.columns[i][j], p_compat);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2041,7 +2045,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i != 0 || j != 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += rtos_fix(m3.rows[i][j]);
|
||||
s += rtos_fix(m3.rows[i][j], p_compat);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2056,11 +2060,11 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i != 0 || j != 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += rtos_fix(m3.rows[i][j]);
|
||||
s += rtos_fix(m3.rows[i][j], p_compat);
|
||||
}
|
||||
}
|
||||
|
||||
s = s + ", " + rtos_fix(t.origin.x) + ", " + rtos_fix(t.origin.y) + ", " + rtos_fix(t.origin.z);
|
||||
s = s + ", " + rtos_fix(t.origin.x, p_compat) + ", " + rtos_fix(t.origin.y, p_compat) + ", " + rtos_fix(t.origin.z, p_compat);
|
||||
|
||||
p_store_string_func(p_store_string_ud, s + ")");
|
||||
} break;
|
||||
|
|
@ -2072,7 +2076,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i != 0 || j != 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += rtos_fix(t.columns[i][j]);
|
||||
s += rtos_fix(t.columns[i][j], p_compat);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2082,7 +2086,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
// Misc types.
|
||||
case Variant::COLOR: {
|
||||
Color c = p_variant;
|
||||
p_store_string_func(p_store_string_ud, "Color(" + rtos_fix(c.r) + ", " + rtos_fix(c.g) + ", " + rtos_fix(c.b) + ", " + rtos_fix(c.a) + ")");
|
||||
p_store_string_func(p_store_string_ud, "Color(" + rtos_fix(c.r, p_compat) + ", " + rtos_fix(c.g, p_compat) + ", " + rtos_fix(c.b, p_compat) + ", " + rtos_fix(c.a, p_compat) + ")");
|
||||
} break;
|
||||
case Variant::STRING_NAME: {
|
||||
String str = p_variant;
|
||||
|
|
@ -2244,8 +2248,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
ERR_PRINT("Max recursion reached");
|
||||
p_store_string_func(p_store_string_ud, "{}");
|
||||
} else {
|
||||
List<Variant> keys;
|
||||
dict.get_key_list(&keys);
|
||||
LocalVector<Variant> keys = dict.get_key_list();
|
||||
keys.sort_custom<StringLikeVariantOrder>();
|
||||
|
||||
if (keys.is_empty()) {
|
||||
|
|
@ -2256,11 +2259,12 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
|
||||
p_store_string_func(p_store_string_ud, "{\n");
|
||||
|
||||
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
||||
write(E->get(), p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||
for (uint32_t i = 0; i < keys.size(); i++) {
|
||||
const Variant &key = keys[i];
|
||||
write(key, p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||
p_store_string_func(p_store_string_ud, ": ");
|
||||
write(dict[E->get()], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||
if (E->next()) {
|
||||
write(dict[key], p_store_string_func, p_store_string_ud, p_encode_res_func, p_encode_res_ud, p_recursion_count, p_compat);
|
||||
if (i + 1 < keys.size()) {
|
||||
p_store_string_func(p_store_string_ud, ",\n");
|
||||
} else {
|
||||
p_store_string_func(p_store_string_ud, "\n");
|
||||
|
|
@ -2397,7 +2401,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i]));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i], p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
@ -2412,7 +2416,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i]));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i], p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
@ -2442,7 +2446,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x, p_compat) + ", " + rtos_fix(ptr[i].y, p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
@ -2457,7 +2461,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y) + ", " + rtos_fix(ptr[i].z));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x, p_compat) + ", " + rtos_fix(ptr[i].y, p_compat) + ", " + rtos_fix(ptr[i].z, p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
@ -2472,7 +2476,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].r) + ", " + rtos_fix(ptr[i].g) + ", " + rtos_fix(ptr[i].b) + ", " + rtos_fix(ptr[i].a));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].r, p_compat) + ", " + rtos_fix(ptr[i].g, p_compat) + ", " + rtos_fix(ptr[i].b, p_compat) + ", " + rtos_fix(ptr[i].a, p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
@ -2487,7 +2491,7 @@ Error VariantWriter::write(const Variant &p_variant, StoreStringFunc p_store_str
|
|||
if (i > 0) {
|
||||
p_store_string_func(p_store_string_ud, ", ");
|
||||
}
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x) + ", " + rtos_fix(ptr[i].y) + ", " + rtos_fix(ptr[i].z) + ", " + rtos_fix(ptr[i].w));
|
||||
p_store_string_func(p_store_string_ud, rtos_fix(ptr[i].x, p_compat) + ", " + rtos_fix(ptr[i].y, p_compat) + ", " + rtos_fix(ptr[i].z, p_compat) + ", " + rtos_fix(ptr[i].w, p_compat));
|
||||
}
|
||||
|
||||
p_store_string_func(p_store_string_ud, ")");
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_PARSER_H
|
||||
#define VARIANT_PARSER_H
|
||||
#pragma once
|
||||
|
||||
#include "core/io/file_access.h"
|
||||
#include "core/io/resource.h"
|
||||
|
|
@ -164,5 +163,3 @@ public:
|
|||
static Error write(const Variant &p_variant, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud, int p_recursion_count = 0, bool p_compat = true);
|
||||
static Error write_to_string(const Variant &p_variant, String &r_string, EncodeResourceFunc p_encode_res_func = nullptr, void *p_encode_res_ud = nullptr, bool p_compat = true);
|
||||
};
|
||||
|
||||
#endif // VARIANT_PARSER_H
|
||||
|
|
|
|||
|
|
@ -768,8 +768,7 @@ struct VariantIndexedSetGet_String {
|
|||
*oob = true;
|
||||
return;
|
||||
}
|
||||
char32_t result = (*VariantGetInternalPtr<String>::get_ptr(base))[index];
|
||||
*value = String(&result, 1);
|
||||
*value = String::chr((*VariantGetInternalPtr<String>::get_ptr(base))[index]);
|
||||
*oob = false;
|
||||
}
|
||||
static void ptr_get(const void *base, int64_t index, void *member) {
|
||||
|
|
@ -779,8 +778,7 @@ struct VariantIndexedSetGet_String {
|
|||
index += v.length();
|
||||
}
|
||||
OOB_TEST(index, v.length());
|
||||
char32_t c = v[index];
|
||||
PtrToArg<String>::encode(String(&c, 1), member);
|
||||
PtrToArg<String>::encode(String::chr(v[index]), member);
|
||||
}
|
||||
static void set(Variant *base, int64_t index, const Variant *value, bool *valid, bool *oob) {
|
||||
if (value->get_type() != Variant::STRING) {
|
||||
|
|
@ -1288,11 +1286,9 @@ Variant Variant::get(const Variant &p_index, bool *r_valid, VariantGetError *err
|
|||
void Variant::get_property_list(List<PropertyInfo> *p_list) const {
|
||||
if (type == DICTIONARY) {
|
||||
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
||||
List<Variant> keys;
|
||||
dic->get_key_list(&keys);
|
||||
for (const Variant &E : keys) {
|
||||
if (E.is_string()) {
|
||||
p_list->push_back(PropertyInfo(dic->get_valid(E).get_type(), E));
|
||||
for (const KeyValue<Variant, Variant> &kv : *dic) {
|
||||
if (kv.key.is_string()) {
|
||||
p_list->push_back(PropertyInfo(dic->get_valid(kv.key).get_type(), kv.key));
|
||||
}
|
||||
}
|
||||
} else if (type == OBJECT) {
|
||||
|
|
@ -1383,8 +1379,7 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
|
|||
#endif
|
||||
Callable::CallError ce;
|
||||
ce.error = Callable::CallError::CALL_OK;
|
||||
Array ref;
|
||||
ref.push_back(r_iter);
|
||||
Array ref = { r_iter };
|
||||
Variant vref = ref;
|
||||
const Variant *refp[] = { &vref };
|
||||
Variant ret = _get_obj().obj->callp(CoreStringName(_iter_init), refp, 1, ce);
|
||||
|
|
@ -1618,8 +1613,7 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
|
|||
#endif
|
||||
Callable::CallError ce;
|
||||
ce.error = Callable::CallError::CALL_OK;
|
||||
Array ref;
|
||||
ref.push_back(r_iter);
|
||||
Array ref = { r_iter };
|
||||
Variant vref = ref;
|
||||
const Variant *refp[] = { &vref };
|
||||
Variant ret = _get_obj().obj->callp(CoreStringName(_iter_next), refp, 1, ce);
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_SETGET_H
|
||||
#define VARIANT_SETGET_H
|
||||
#pragma once
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
|
|
@ -359,5 +358,3 @@ SETGET_NUMBER_STRUCT_FUNC(Color, double, v, set_v, get_v)
|
|||
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_h, set_ok_hsl_h, get_ok_hsl_h)
|
||||
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_s, set_ok_hsl_s, get_ok_hsl_s)
|
||||
SETGET_NUMBER_STRUCT_FUNC(Color, double, ok_hsl_l, set_ok_hsl_l, get_ok_hsl_l)
|
||||
|
||||
#endif // VARIANT_SETGET_H
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ Variant VariantUtilityFunctions::abs(const Variant &x, Callable::CallError &r_er
|
|||
r_error.error = Callable::CallError::CALL_OK;
|
||||
switch (x.get_type()) {
|
||||
case Variant::INT: {
|
||||
return ABS(VariantInternalAccessor<int64_t>::get(&x));
|
||||
return Math::abs(VariantInternalAccessor<int64_t>::get(&x));
|
||||
} break;
|
||||
case Variant::FLOAT: {
|
||||
return Math::absd(VariantInternalAccessor<double>::get(&x));
|
||||
|
|
@ -281,7 +281,7 @@ double VariantUtilityFunctions::absf(double x) {
|
|||
}
|
||||
|
||||
int64_t VariantUtilityFunctions::absi(int64_t x) {
|
||||
return ABS(x);
|
||||
return Math::abs(x);
|
||||
}
|
||||
|
||||
Variant VariantUtilityFunctions::sign(const Variant &x, Callable::CallError &r_error) {
|
||||
|
|
@ -1678,7 +1678,7 @@ template <typename T>
|
|||
static void register_utility_function(const String &p_name, const Vector<String> &argnames) {
|
||||
String name = p_name;
|
||||
if (name.begins_with("_")) {
|
||||
name = name.substr(1, name.length() - 1);
|
||||
name = name.substr(1);
|
||||
}
|
||||
StringName sname = name;
|
||||
ERR_FAIL_COND(utility_function_table.has(sname));
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@
|
|||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/**************************************************************************/
|
||||
|
||||
#ifndef VARIANT_UTILITY_H
|
||||
#define VARIANT_UTILITY_H
|
||||
#pragma once
|
||||
|
||||
#include "variant.h"
|
||||
|
||||
|
|
@ -154,5 +153,3 @@ struct VariantUtilityFunctions {
|
|||
static RID rid_from_int64(uint64_t p_base);
|
||||
static bool is_same(const Variant &p_a, const Variant &p_b);
|
||||
};
|
||||
|
||||
#endif // VARIANT_UTILITY_H
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue