diff options
Diffstat (limited to 'core/variant')
-rw-r--r-- | core/variant/binder_common.h | 2 | ||||
-rw-r--r-- | core/variant/variant.h | 17 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 8 |
3 files changed, 22 insertions, 5 deletions
diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index f06d767cf5..98be62391f 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -80,7 +80,7 @@ struct VariantCaster<const T &> { } \ typedef int64_t EncodeT; \ _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ - *(int64_t *)p_ptr = p_val; \ + *(int64_t *)p_ptr = (int64_t)p_val; \ } \ }; diff --git a/core/variant/variant.h b/core/variant/variant.h index 8ce5e7dcd2..230ed33c0c 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -31,6 +31,7 @@ #ifndef VARIANT_H #define VARIANT_H +#include "core/input/input_enums.h" #include "core/io/ip_address.h" #include "core/math/aabb.h" #include "core/math/basis.h" @@ -43,6 +44,7 @@ #include "core/math/vector3.h" #include "core/math/vector3i.h" #include "core/object/object_id.h" +#include "core/os/keyboard.h" #include "core/string/node_path.h" #include "core/string/ustring.h" #include "core/templates/rid.h" @@ -430,6 +432,21 @@ public: Variant(const IPAddress &p_address); +#define VARIANT_ENUM_CLASS_CONSTRUCTOR(m_enum) \ + Variant(const 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(JoyAxis) + VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton) + VARIANT_ENUM_CLASS_CONSTRUCTOR(Key) + VARIANT_ENUM_CLASS_CONSTRUCTOR(MIDIMessage) + VARIANT_ENUM_CLASS_CONSTRUCTOR(MouseButton) + +#undef VARIANT_ENUM_CLASS_CONSTRUCTOR + // If this changes the table in variant_op must be updated enum Operator { //comparison diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index e89bdd4faa..83fa4bde69 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -151,10 +151,10 @@ struct VariantUtilityFunctions { r_error.error = Callable::CallError::CALL_OK; switch (x.get_type()) { case Variant::INT: { - return SGN(VariantInternalAccessor<int64_t>::get(&x)); + return SIGN(VariantInternalAccessor<int64_t>::get(&x)); } break; case Variant::FLOAT: { - return SGN(VariantInternalAccessor<double>::get(&x)); + return SIGN(VariantInternalAccessor<double>::get(&x)); } break; case Variant::VECTOR2: { return VariantInternalAccessor<Vector2>::get(&x).sign(); @@ -176,11 +176,11 @@ struct VariantUtilityFunctions { } static inline double signf(double x) { - return SGN(x); + return SIGN(x); } static inline int64_t signi(int64_t x) { - return SGN(x); + return SIGN(x); } static inline double pow(double x, double y) { |