From 99a936fa50d3321b2cd8ed670d00fe005cca3bc8 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 1 Jan 2025 11:25:10 -0600 Subject: [PATCH] Core: Natively convert enum/BitField with Variant --- core/variant/binder_common.h | 69 +---------- core/variant/method_ptrcall.h | 29 ++++- core/variant/type_info.h | 111 +++++------------ core/variant/variant.cpp | 8 -- core/variant/variant.h | 33 ++--- core/variant/variant_internal.h | 212 +++++--------------------------- 6 files changed, 105 insertions(+), 357 deletions(-) diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index b6810930cca1..ce10de419597 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -82,73 +82,8 @@ struct VariantCaster { } }; -#define VARIANT_ENUM_CAST(m_enum) \ - MAKE_ENUM_TYPE_INFO(m_enum) \ - template <> \ - struct VariantCaster { \ - static _FORCE_INLINE_ m_enum cast(const Variant &p_variant) { \ - return (m_enum)p_variant.operator int64_t(); \ - } \ - }; \ - template <> \ - struct PtrToArg { \ - _FORCE_INLINE_ static m_enum convert(const void *p_ptr) { \ - return m_enum(*reinterpret_cast(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 { \ - static void initialize(m_enum &value) { \ - value = (m_enum)0; \ - } \ - }; \ - template <> \ - struct VariantInternalAccessor { \ - 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> { \ - static _FORCE_INLINE_ BitField cast(const Variant &p_variant) { \ - return BitField(p_variant.operator int64_t()); \ - } \ - }; \ - template <> \ - struct PtrToArg> { \ - _FORCE_INLINE_ static BitField convert(const void *p_ptr) { \ - return BitField(*reinterpret_cast(p_ptr)); \ - } \ - typedef int64_t EncodeT; \ - _FORCE_INLINE_ static void encode(BitField p_val, const void *p_ptr) { \ - *(int64_t *)p_ptr = p_val; \ - } \ - }; \ - template <> \ - struct ZeroInitializer> { \ - static void initialize(BitField &value) { \ - value = 0; \ - } \ - }; \ - template <> \ - struct VariantInternalAccessor> { \ - static _FORCE_INLINE_ BitField get(const Variant *v) { \ - return BitField(*VariantInternal::get_int(v)); \ - } \ - static _FORCE_INLINE_ void set(Variant *v, BitField p_value) { \ - *VariantInternal::get_int(v) = p_value.operator int64_t(); \ - } \ - }; +#define VARIANT_ENUM_CAST(m_enum) SET_QUALIFIED_NAME(m_enum) +#define VARIANT_BITFIELD_CAST(m_enum) SET_QUALIFIED_NAME(m_enum) // Object enum casts must go here VARIANT_ENUM_CAST(Object::ConnectFlags); diff --git a/core/variant/method_ptrcall.h b/core/variant/method_ptrcall.h index 540dcc4a4d91..6d3d8cc6b22c 100644 --- a/core/variant/method_ptrcall.h +++ b/core/variant/method_ptrcall.h @@ -35,8 +35,8 @@ #include "core/typedefs.h" #include "core/variant/variant.h" -template -struct PtrToArg {}; +template +struct PtrToArg; #define MAKE_PTRARG(m_type) \ template <> \ @@ -104,6 +104,28 @@ struct PtrToArg {}; } \ } +#define MAKE_PTRARGCONV_CONDITIONAL(m_type, m_conv, m_conditional) \ + template \ + struct PtrToArg> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return static_cast(*reinterpret_cast(p_ptr)); \ + } \ + typedef m_conv EncodeT; \ + _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ + *((m_conv *)p_ptr) = static_cast(p_val); \ + } \ + }; \ + template \ + struct PtrToArg> { \ + _FORCE_INLINE_ static m_type convert(const void *p_ptr) { \ + return static_cast(*reinterpret_cast(p_ptr)); \ + } \ + typedef m_conv EncodeT; \ + _FORCE_INLINE_ static void encode(m_type p_val, void *p_ptr) { \ + *((m_conv *)p_ptr) = static_cast(p_val); \ + } \ + } + MAKE_PTRARGCONV(bool, uint8_t); // Integer types. MAKE_PTRARGCONV(uint8_t, int64_t); @@ -155,6 +177,9 @@ MAKE_PTRARG(PackedColorArray); MAKE_PTRARG(PackedVector4Array); MAKE_PTRARG_BY_REFERENCE(Variant); +MAKE_PTRARGCONV_CONDITIONAL(T, int64_t, std::is_enum_v); +MAKE_PTRARGCONV_CONDITIONAL(BitField, int64_t, std::is_enum_v); + // This is for Object. template diff --git a/core/variant/type_info.h b/core/variant/type_info.h index c05f6b0be0c8..5b5913dfcee5 100644 --- a/core/variant/type_info.h +++ b/core/variant/type_info.h @@ -31,6 +31,7 @@ #ifndef TYPE_INFO_H #define TYPE_INFO_H +#include "core/templates/simple_type.h" // IWYU pragma: keep // Used in macros. #include "core/typedefs.h" #include @@ -220,31 +221,31 @@ 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]; } + +template +struct GetQualifiedName; + } // namespace details } // namespace godot -#define TEMPL_MAKE_ENUM_TYPE_INFO(m_enum, m_impl) \ - template <> \ - struct GetTypeInfo { \ - 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))); \ - } \ +#define SET_QUALIFIED_NAME(m_enum) \ + template <> \ + struct godot::details::GetQualifiedName { \ + static inline String value = 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 +struct GetTypeInfo>> { + 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::GetQualifiedName>::value); + } +}; template inline StringName __constant_get_enum_name(T param, const String &p_constant) { - if constexpr (GetTypeInfo::VARIANT_TYPE == Variant::NIL) { - ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's enum: " + p_constant); - } return GetTypeInfo::get_class_info().class_name; } @@ -265,79 +266,33 @@ class BitField { _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 operator^(const BitField &p_b) const { return BitField(value ^ p_b.value); } }; -#define TEMPL_MAKE_BITFIELD_TYPE_INFO(m_enum, m_impl) \ - template <> \ - struct GetTypeInfo { \ - 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))); \ - } \ - }; \ - template <> \ - struct GetTypeInfo> { \ - 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))); \ - } \ - }; - -#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 +struct GetTypeInfo, std::enable_if_t>> { + 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::GetQualifiedName>::value); + } +}; template inline StringName __constant_get_bitfield_name(T param, const String &p_constant) { - if (GetTypeInfo::VARIANT_TYPE == Variant::NIL) { - ERR_PRINT("Missing VARIANT_ENUM_CAST for constant's bitfield: " + p_constant); - } return GetTypeInfo>::get_class_info().class_name; } #define CLASS_INFO(m_type) (GetTypeInfo::get_class_info()) +// No initialization by default, except for scalar types. template struct ZeroInitializer { - static void initialize(T &value) {} //no initialization by default -}; - -template <> -struct ZeroInitializer { - static void initialize(bool &value) { value = false; } -}; - -template -struct ZeroInitializer { - static void initialize(T *&value) { value = nullptr; } + static void initialize(T &value) { + if constexpr (std::is_scalar_v) { + value = {}; + } + } }; -#define ZERO_INITIALIZER_NUMBER(m_type) \ - template <> \ - struct ZeroInitializer { \ - 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 diff --git a/core/variant/variant.cpp b/core/variant/variant.cpp index f092905a3ab0..c1e5928f339c 100644 --- a/core/variant/variant.cpp +++ b/core/variant/variant.cpp @@ -2436,14 +2436,6 @@ Variant::operator Vector() 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 addr = operator Vector(); diff --git a/core/variant/variant.h b/core/variant/variant.h index ede1535e0c1c..57c0b27e6392 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -66,6 +66,8 @@ class RefCounted; template class Ref; +template +class BitField; struct PropertyInfo; struct MethodInfo; @@ -441,12 +443,13 @@ class Variant { operator Vector() const; operator Vector() const; - // some core type enums to convert to - operator Side() const; - operator Orientation() const; - operator IPAddress() const; + template , int> = 0> + _FORCE_INLINE_ operator T() const { return static_cast(operator int64_t()); } + template , int> = 0> + _FORCE_INLINE_ operator BitField() const { return static_cast(operator int64_t()); } + Object *get_validated_object() const; Object *get_validated_object_with_check(bool &r_previously_freed) const; @@ -509,22 +512,12 @@ class Variant { 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 , int> = 0> + _FORCE_INLINE_ Variant(T p_enum) : + Variant(static_cast(p_enum)) {} + template , int> = 0> + _FORCE_INLINE_ Variant(BitField p_bitfield) : + Variant(static_cast(p_bitfield)) {} // If this changes the table in variant_op must be updated enum Operator { diff --git a/core/variant/variant_internal.h b/core/variant/variant_internal.h index 9a40dcec84af..beb4a89bd0aa 100644 --- a/core/variant/variant_internal.h +++ b/core/variant/variant_internal.h @@ -528,9 +528,8 @@ class VariantInternal { } }; -template -struct VariantGetInternalPtr { -}; +template +struct VariantGetInternalPtr; template <> struct VariantGetInternalPtr { @@ -538,56 +537,14 @@ struct VariantGetInternalPtr { static const bool *get_ptr(const Variant *v) { return VariantInternal::get_bool(v); } }; -template <> -struct VariantGetInternalPtr { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { +template +struct VariantGetInternalPtr && !std::is_same_v) || std::is_enum_v>> { 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 { +template +struct VariantGetInternalPtr, std::enable_if_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 +555,6 @@ struct VariantGetInternalPtr { static const int64_t *get_ptr(const Variant *v) { return VariantInternal::get_int(v); } }; -template <> -struct VariantGetInternalPtr { - 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 { static double *get_ptr(Variant *v) { return VariantInternal::get_float(v); } @@ -821,9 +772,8 @@ struct VariantGetInternalPtr { static const PackedVector4Array *get_ptr(const Variant *v) { return VariantInternal::get_vector4_array(v); } }; -template -struct VariantInternalAccessor { -}; +template +struct VariantInternalAccessor; template <> struct VariantInternalAccessor { @@ -831,26 +781,17 @@ struct VariantInternalAccessor { 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 { \ - 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; \ - } \ - }; - -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 +struct VariantInternalAccessor && !std::is_same_v) || std::is_enum_v>> { + static _FORCE_INLINE_ T get(const Variant *v) { return static_cast(*VariantInternal::get_int(v)); } + static _FORCE_INLINE_ void set(Variant *v, T p_value) { *VariantInternal::get_int(v) = static_cast(p_value); } +}; + +template +struct VariantInternalAccessor, std::enable_if_t>> { + static _FORCE_INLINE_ BitField get(const Variant *v) { return BitField(static_cast(*VariantInternal::get_int(v))); } + static _FORCE_INLINE_ void set(Variant *v, BitField p_value) { *VariantInternal::get_int(v) = static_cast(p_value); } +}; template <> struct VariantInternalAccessor { @@ -1127,47 +1068,7 @@ struct VariantInternalAccessor> { template struct VariantInitializer { -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -#define INITIALIZER_INT(m_type) \ - template <> \ - struct VariantInitializer { \ - static _FORCE_INLINE_ void init(Variant *v) { \ - VariantInternal::init_generic(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 { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } + static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } }; template <> @@ -1175,59 +1076,11 @@ struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string(v); } }; -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform2d(v); } }; -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_aabb(v); } @@ -1242,16 +1095,12 @@ template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_transform3d(v); } }; + template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_projection(v); } }; -template <> -struct VariantInitializer { - static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_generic(v); } -}; - template <> struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_string_name(v); } @@ -1262,11 +1111,6 @@ struct VariantInitializer { 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 { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_callable(v); } @@ -1342,17 +1186,21 @@ struct VariantInitializer { static _FORCE_INLINE_ void init(Variant *v) { VariantInternal::init_object(v); } }; -template -struct VariantDefaultInitializer { -}; +template +struct VariantDefaultInitializer; template <> struct VariantDefaultInitializer { static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_bool(v) = false; } }; -template <> -struct VariantDefaultInitializer { +template +struct VariantDefaultInitializer && !std::is_same_v) || std::is_enum_v>> { + static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int(v) = 0; } +}; + +template +struct VariantDefaultInitializer, std::enable_if_t>> { static _FORCE_INLINE_ void init(Variant *v) { *VariantInternal::get_int(v) = 0; } };