diff options
Diffstat (limited to 'modules/mono/mono_gd/gd_mono_marshal.cpp')
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.cpp | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index b5419952de..b64915109f 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -41,11 +41,11 @@ namespace GDMonoMarshal { return mono_value_box(mono_domain_get(), CACHED_CLASS_RAW(m_t), raw); \ } -#define RETURN_UNBOXED_STRUCT(m_t, m_var_in) \ - { \ - float *raw = UNBOX_FLOAT_PTR(m_var_in); \ - MARSHALLED_IN(m_t, raw, ret); \ - return ret; \ +#define RETURN_UNBOXED_STRUCT(m_t, m_var_in) \ + { \ + float *raw = (float *)mono_object_unbox(m_var_in); \ + MARSHALLED_IN(m_t, raw, ret); \ + return ret; \ } Variant::Type managed_to_variant_type(const ManagedType &p_type) { @@ -453,30 +453,30 @@ Variant mono_object_to_variant(MonoObject *p_obj) { Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { switch (p_type.type_encoding) { case MONO_TYPE_BOOLEAN: - return (bool)UNBOX_BOOLEAN(p_obj); + return (bool)unbox<MonoBoolean>(p_obj); case MONO_TYPE_I1: - return UNBOX_INT8(p_obj); + return unbox<int8_t>(p_obj); case MONO_TYPE_I2: - return UNBOX_INT16(p_obj); + return unbox<int16_t>(p_obj); case MONO_TYPE_I4: - return UNBOX_INT32(p_obj); + return unbox<int32_t>(p_obj); case MONO_TYPE_I8: - return UNBOX_INT64(p_obj); + return unbox<int64_t>(p_obj); case MONO_TYPE_U1: - return UNBOX_UINT8(p_obj); + return unbox<uint8_t>(p_obj); case MONO_TYPE_U2: - return UNBOX_UINT16(p_obj); + return unbox<uint16_t>(p_obj); case MONO_TYPE_U4: - return UNBOX_UINT32(p_obj); + return unbox<uint32_t>(p_obj); case MONO_TYPE_U8: - return UNBOX_UINT64(p_obj); + return unbox<uint64_t>(p_obj); case MONO_TYPE_R4: - return UNBOX_FLOAT(p_obj); + return unbox<float>(p_obj); case MONO_TYPE_R8: - return UNBOX_DOUBLE(p_obj); + return unbox<double>(p_obj); case MONO_TYPE_STRING: { String str = mono_string_to_godot((MonoString *)p_obj); @@ -554,29 +554,18 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { // GodotObject if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) { - GDMonoField *ptr_field = CACHED_FIELD(GodotObject, ptr); - - ERR_FAIL_NULL_V(ptr_field, Variant()); - - void *ptr_to_unmanaged = UNBOX_PTR(ptr_field->get_value(p_obj)); - - if (!ptr_to_unmanaged) // IntPtr.Zero - return Variant(); - - Object *object_ptr = static_cast<Object *>(ptr_to_unmanaged); - - if (!object_ptr) - return Variant(); - - return object_ptr; + Object *ptr = unbox<Object *>(CACHED_FIELD(GodotObject, ptr)->get_value(p_obj)); + return ptr ? Variant(ptr) : Variant(); } if (CACHED_CLASS(NodePath) == type_class) { - return UNBOX_PTR(CACHED_FIELD(NodePath, ptr)->get_value(p_obj)); + NodePath *ptr = unbox<NodePath *>(CACHED_FIELD(NodePath, ptr)->get_value(p_obj)); + return ptr ? Variant(*ptr) : Variant(); } if (CACHED_CLASS(RID) == type_class) { - return UNBOX_PTR(CACHED_FIELD(RID, ptr)->get_value(p_obj)); + RID *ptr = unbox<RID *>(CACHED_FIELD(RID, ptr)->get_value(p_obj)); + return ptr ? Variant(*ptr) : Variant(); } } break; |