diff options
-rw-r--r-- | core/class_db.h | 4 | ||||
-rw-r--r-- | core/method_bind.h | 10 | ||||
-rw-r--r-- | core/object.cpp | 10 | ||||
-rw-r--r-- | core/undo_redo.cpp | 4 | ||||
-rw-r--r-- | core/vector.h | 10 | ||||
-rw-r--r-- | doc/classes/Object.xml | 6 | ||||
-rw-r--r-- | doc/classes/UndoRedo.xml | 4 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.h | 3 | ||||
-rw-r--r-- | modules/mono/glue/gd_glue.cpp | 96 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.cpp | 84 | ||||
-rw-r--r-- | modules/mono/mono_gd/gd_mono_marshal.h | 6 | ||||
-rw-r--r-- | scene/2d/visibility_notifier_2d.cpp | 2 | ||||
-rw-r--r-- | scene/3d/camera.cpp | 3 | ||||
-rw-r--r-- | scene/3d/visibility_notifier.cpp | 1 |
14 files changed, 183 insertions, 60 deletions
diff --git a/core/class_db.h b/core/class_db.h index 4129a74147..490deb7873 100644 --- a/core/class_db.h +++ b/core/class_db.h @@ -294,11 +294,11 @@ public: } template <class M> - static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>()) { + static MethodBind *bind_vararg_method(uint32_t p_flags, StringName p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) { GLOBAL_LOCK_FUNCTION; - MethodBind *bind = create_vararg_method_bind(p_method, p_info); + MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant); ERR_FAIL_COND_V(!bind, NULL); bind->set_name(p_name); diff --git a/core/method_bind.h b/core/method_bind.h index 754d9f70e6..1860d227f7 100644 --- a/core/method_bind.h +++ b/core/method_bind.h @@ -344,7 +344,7 @@ public: return (instance->*call_method)(p_args, p_arg_count, r_error); } - void set_method_info(const MethodInfo &p_info) { + void set_method_info(const MethodInfo &p_info, bool p_return_nil_is_variant) { set_argument_count(p_info.arguments.size()); #ifdef DEBUG_METHODS_ENABLED @@ -364,7 +364,9 @@ public: } argument_types = at; arguments = p_info; - arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + if (p_return_nil_is_variant) { + arguments.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; + } #endif } @@ -387,11 +389,11 @@ public: }; template <class T> -MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Variant::CallError &), const MethodInfo &p_info) { +MethodBind *create_vararg_method_bind(Variant (T::*p_method)(const Variant **, int, Variant::CallError &), const MethodInfo &p_info, bool p_return_nil_is_variant) { MethodBindVarArg<T> *a = memnew((MethodBindVarArg<T>)); a->set_method(p_method); - a->set_method_info(p_info); + a->set_method_info(p_info, p_return_nil_is_variant); return a; } diff --git a/core/object.cpp b/core/object.cpp index 57fd730f7f..35ccc38d4e 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -1517,9 +1517,11 @@ void Object::_disconnect(const StringName &p_signal, Object *p_to_object, const ERR_FAIL_NULL(p_to_object); Signal *s = signal_map.getptr(p_signal); - ERR_FAIL_COND_MSG(!s, "Nonexistent signal: " + p_signal + "."); + ERR_FAIL_COND_MSG(!s, vformat("Nonexistent signal '%s' in %s.", p_signal, to_string())); - ERR_FAIL_COND_MSG(s->lock > 0, "Attempt to disconnect signal '" + p_signal + "' while in emission callback. Use CONNECT_DEFERRED (to be able to safely disconnect) or CONNECT_ONESHOT (for automatic disconnection) as connection flags."); + ERR_FAIL_COND_MSG(s->lock > 0, + vformat("Attempt to disconnect %s signal '%s' while in emission callback '%s' (in target %s). Use CONNECT_DEFERRED (to be able to safely disconnect) or CONNECT_ONESHOT (for automatic disconnection) as connection flags.", + to_string(), p_signal, p_to_method, p_to_object->to_string())); Signal::Target target(p_to_object->get_instance_id(), p_to_method); @@ -1686,7 +1688,7 @@ void Object::_bind_methods() { mi.name = "emit_signal"; mi.arguments.push_back(PropertyInfo(Variant::STRING, "signal")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "emit_signal", &Object::_emit_signal, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "emit_signal", &Object::_emit_signal, mi, varray(), false); } { @@ -1702,7 +1704,7 @@ void Object::_bind_methods() { mi.name = "call_deferred"; mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_deferred", &Object::_call_deferred_bind, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_deferred", &Object::_call_deferred_bind, mi, varray(), false); } ClassDB::bind_method(D_METHOD("set_deferred", "property", "value"), &Object::set_deferred); diff --git a/core/undo_redo.cpp b/core/undo_redo.cpp index 98a9db5d3b..5d1144e1f5 100644 --- a/core/undo_redo.cpp +++ b/core/undo_redo.cpp @@ -520,7 +520,7 @@ void UndoRedo::_bind_methods() { mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_do_method", &UndoRedo::_add_do_method, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_do_method", &UndoRedo::_add_do_method, mi, varray(), false); } { @@ -529,7 +529,7 @@ void UndoRedo::_bind_methods() { mi.arguments.push_back(PropertyInfo(Variant::OBJECT, "object")); mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); - ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_undo_method", &UndoRedo::_add_undo_method, mi); + ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "add_undo_method", &UndoRedo::_add_undo_method, mi, varray(), false); } ClassDB::bind_method(D_METHOD("add_do_property", "object", "property", "value"), &UndoRedo::add_do_property); diff --git a/core/vector.h b/core/vector.h index 7bf83d4cff..44add2c4d7 100644 --- a/core/vector.h +++ b/core/vector.h @@ -63,7 +63,7 @@ private: CowData<T> _cowdata; public: - bool push_back(const T &p_elem); + bool push_back(T p_elem); void remove(int p_index) { _cowdata.remove(p_index); } void erase(const T &p_val) { @@ -83,10 +83,10 @@ public: _FORCE_INLINE_ int size() const { return _cowdata.size(); } Error resize(int p_size) { return _cowdata.resize(p_size); } _FORCE_INLINE_ const T &operator[](int p_index) const { return _cowdata.get(p_index); } - Error insert(int p_pos, const T &p_val) { return _cowdata.insert(p_pos, p_val); } + Error insert(int p_pos, T p_val) { return _cowdata.insert(p_pos, p_val); } int find(const T &p_val, int p_from = 0) const { return _cowdata.find(p_val, p_from); } - void append_array(const Vector<T> &p_other); + void append_array(Vector<T> p_other); template <class C> void sort_custom() { @@ -136,7 +136,7 @@ void Vector<T>::invert() { } template <class T> -void Vector<T>::append_array(const Vector<T> &p_other) { +void Vector<T>::append_array(Vector<T> p_other) { const int ds = p_other.size(); if (ds == 0) return; @@ -147,7 +147,7 @@ void Vector<T>::append_array(const Vector<T> &p_other) { } template <class T> -bool Vector<T>::push_back(const T &p_elem) { +bool Vector<T>::push_back(T p_elem) { Error err = resize(size() + 1); ERR_FAIL_COND_V(err, true); diff --git a/doc/classes/Object.xml b/doc/classes/Object.xml index 1e5b8669fd..1d7e5f8080 100644 --- a/doc/classes/Object.xml +++ b/doc/classes/Object.xml @@ -99,12 +99,12 @@ </description> </method> <method name="call_deferred" qualifiers="vararg"> - <return type="Variant"> + <return type="void"> </return> <argument index="0" name="method" type="String"> </argument> <description> - Calls the [code]method[/code] on the object during idle time and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example: + Calls the [code]method[/code] on the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example: [codeblock] call_deferred("set", "position", Vector2(42.0, 0.0)) [/codeblock] @@ -178,7 +178,7 @@ </description> </method> <method name="emit_signal" qualifiers="vararg"> - <return type="Variant"> + <return type="void"> </return> <argument index="0" name="signal" type="String"> </argument> diff --git a/doc/classes/UndoRedo.xml b/doc/classes/UndoRedo.xml index 7834719af6..52ff7ef38b 100644 --- a/doc/classes/UndoRedo.xml +++ b/doc/classes/UndoRedo.xml @@ -32,7 +32,7 @@ </tutorials> <methods> <method name="add_do_method" qualifiers="vararg"> - <return type="Variant"> + <return type="void"> </return> <argument index="0" name="object" type="Object"> </argument> @@ -65,7 +65,7 @@ </description> </method> <method name="add_undo_method" qualifiers="vararg"> - <return type="Variant"> + <return type="void"> </return> <argument index="0" name="object" type="Object"> </argument> diff --git a/editor/import/editor_scene_importer_gltf.h b/editor/import/editor_scene_importer_gltf.h index 579d4037b7..4a91b99aa7 100644 --- a/editor/import/editor_scene_importer_gltf.h +++ b/editor/import/editor_scene_importer_gltf.h @@ -172,7 +172,10 @@ class EditorSceneImporterGLTF : public EditorSceneImporter { min = 0; max = 0; sparse_count = 0; + sparse_indices_buffer_view = 0; sparse_indices_byte_offset = 0; + sparse_indices_component_type = 0; + sparse_values_buffer_view = 0; sparse_values_byte_offset = 0; } }; diff --git a/modules/mono/glue/gd_glue.cpp b/modules/mono/glue/gd_glue.cpp index 041d29c7bf..9bea625450 100644 --- a/modules/mono/glue/gd_glue.cpp +++ b/modules/mono/glue/gd_glue.cpp @@ -71,48 +71,114 @@ MonoObject *godot_icall_GD_instance_from_id(uint64_t p_instance_id) { } void godot_icall_GD_print(MonoArray *p_what) { - Array what = GDMonoMarshal::mono_array_to_Array(p_what); String str; - for (int i = 0; i < what.size(); i++) - str += what[i].operator String(); + int length = mono_array_length(p_what); + + for (int i = 0; i < length; i++) { + MonoObject *elem = mono_array_get(p_what, MonoObject *, i); + + MonoException *exc = NULL; + String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc); + + if (exc) { + GDMonoUtils::set_pending_exception(exc); + return; + } + + str += elem_str; + } + print_line(str); } void godot_icall_GD_printerr(MonoArray *p_what) { - Array what = GDMonoMarshal::mono_array_to_Array(p_what); + String str; - for (int i = 0; i < what.size(); i++) - str += what[i].operator String(); + int length = mono_array_length(p_what); + + for (int i = 0; i < length; i++) { + MonoObject *elem = mono_array_get(p_what, MonoObject *, i); + + MonoException *exc = NULL; + String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc); + + if (exc) { + GDMonoUtils::set_pending_exception(exc); + return; + } + + str += elem_str; + } + print_error(str); } void godot_icall_GD_printraw(MonoArray *p_what) { - Array what = GDMonoMarshal::mono_array_to_Array(p_what); String str; - for (int i = 0; i < what.size(); i++) - str += what[i].operator String(); + int length = mono_array_length(p_what); + + for (int i = 0; i < length; i++) { + MonoObject *elem = mono_array_get(p_what, MonoObject *, i); + + MonoException *exc = NULL; + String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc); + + if (exc) { + GDMonoUtils::set_pending_exception(exc); + return; + } + + str += elem_str; + } + OS::get_singleton()->print("%s", str.utf8().get_data()); } void godot_icall_GD_prints(MonoArray *p_what) { - Array what = GDMonoMarshal::mono_array_to_Array(p_what); String str; - for (int i = 0; i < what.size(); i++) { + int length = mono_array_length(p_what); + + for (int i = 0; i < length; i++) { + MonoObject *elem = mono_array_get(p_what, MonoObject *, i); + + MonoException *exc = NULL; + String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc); + + if (exc) { + GDMonoUtils::set_pending_exception(exc); + return; + } + if (i) str += " "; - str += what[i].operator String(); + + str += elem_str; } + print_line(str); } void godot_icall_GD_printt(MonoArray *p_what) { - Array what = GDMonoMarshal::mono_array_to_Array(p_what); String str; - for (int i = 0; i < what.size(); i++) { + int length = mono_array_length(p_what); + + for (int i = 0; i < length; i++) { + MonoObject *elem = mono_array_get(p_what, MonoObject *, i); + + MonoException *exc = NULL; + String elem_str = GDMonoMarshal::mono_object_to_variant_string(elem, &exc); + + if (exc) { + GDMonoUtils::set_pending_exception(exc); + return; + } + if (i) str += "\t"; - str += what[i].operator String(); + + str += elem_str; } + print_line(str); } diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp index 24fcd27bbb..b81c20348d 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.cpp +++ b/modules/mono/mono_gd/gd_mono_marshal.cpp @@ -700,15 +700,11 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty p_type.type_class->get_name() + "' Encoding: " + itos(p_type.type_encoding) + "."); } -Variant mono_object_to_variant(MonoObject *p_obj) { - if (!p_obj) - return Variant(); +Variant mono_object_to_variant_impl(MonoObject *p_obj, const ManagedType &p_type, bool p_fail_with_err = true) { - ManagedType type = ManagedType::from_class(mono_object_get_class(p_obj)); - - ERR_FAIL_COND_V(!type.type_class, Variant()); + ERR_FAIL_COND_V(!p_type.type_class, Variant()); - switch (type.type_encoding) { + switch (p_type.type_encoding) { case MONO_TYPE_BOOLEAN: return (bool)unbox<MonoBoolean>(p_obj); @@ -745,7 +741,7 @@ Variant mono_object_to_variant(MonoObject *p_obj) { } break; case MONO_TYPE_VALUETYPE: { - GDMonoClass *vtclass = type.type_class; + GDMonoClass *vtclass = p_type.type_class; if (vtclass == CACHED_CLASS(Vector2)) return MARSHALLED_IN(Vector2, (GDMonoMarshal::M_Vector2 *)mono_object_unbox(p_obj)); @@ -783,7 +779,7 @@ Variant mono_object_to_variant(MonoObject *p_obj) { case MONO_TYPE_ARRAY: case MONO_TYPE_SZARRAY: { - MonoArrayType *array_type = mono_type_get_array_type(type.type_class->get_mono_type()); + MonoArrayType *array_type = mono_type_get_array_type(p_type.type_class->get_mono_type()); if (array_type->eklass == CACHED_CLASS_RAW(MonoObject)) return mono_array_to_Array((MonoArray *)p_obj); @@ -809,11 +805,15 @@ Variant mono_object_to_variant(MonoObject *p_obj) { if (array_type->eklass == CACHED_CLASS_RAW(Color)) return mono_array_to_PoolColorArray((MonoArray *)p_obj); - ERR_FAIL_V_MSG(Variant(), "Attempted to convert a managed array of unmarshallable element type to Variant."); + if (p_fail_with_err) { + ERR_FAIL_V_MSG(Variant(), "Attempted to convert a managed array of unmarshallable element type to Variant."); + } else { + return Variant(); + } } break; case MONO_TYPE_CLASS: { - GDMonoClass *type_class = type.type_class; + GDMonoClass *type_class = p_type.type_class; // GodotObject if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) { @@ -871,18 +871,18 @@ Variant mono_object_to_variant(MonoObject *p_obj) { } break; case MONO_TYPE_GENERICINST: { - MonoReflectionType *reftype = mono_type_get_object(mono_domain_get(), type.type_class->get_mono_type()); + MonoReflectionType *reftype = mono_type_get_object(mono_domain_get(), p_type.type_class->get_mono_type()); if (GDMonoUtils::Marshal::type_is_generic_dictionary(reftype)) { MonoException *exc = NULL; - MonoObject *ret = type.type_class->get_method("GetPtr")->invoke(p_obj, &exc); + MonoObject *ret = p_type.type_class->get_method("GetPtr")->invoke(p_obj, &exc); UNHANDLED_EXCEPTION(exc); return *unbox<Dictionary *>(ret); } if (GDMonoUtils::Marshal::type_is_generic_array(reftype)) { MonoException *exc = NULL; - MonoObject *ret = type.type_class->get_method("GetPtr")->invoke(p_obj, &exc); + MonoObject *ret = p_type.type_class->get_method("GetPtr")->invoke(p_obj, &exc); UNHANDLED_EXCEPTION(exc); return *unbox<Array *>(ret); } @@ -893,7 +893,7 @@ Variant mono_object_to_variant(MonoObject *p_obj) { return GDMonoUtils::Marshal::generic_idictionary_to_dictionary(p_obj); } - if (type.type_class->implements_interface(CACHED_CLASS(System_Collections_IDictionary))) { + if (p_type.type_class->implements_interface(CACHED_CLASS(System_Collections_IDictionary))) { return GDMonoUtils::Marshal::idictionary_to_dictionary(p_obj); } @@ -901,14 +901,62 @@ Variant mono_object_to_variant(MonoObject *p_obj) { return GDMonoUtils::Marshal::enumerable_to_array(p_obj); } - if (type.type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) { + if (p_type.type_class->implements_interface(CACHED_CLASS(System_Collections_IEnumerable))) { return GDMonoUtils::Marshal::enumerable_to_array(p_obj); } } break; } - ERR_FAIL_V_MSG(Variant(), "Attempted to convert an unmarshallable managed type to Variant. Name: '" + - type.type_class->get_name() + "' Encoding: " + itos(type.type_encoding) + "."); + if (p_fail_with_err) { + ERR_FAIL_V_MSG(Variant(), "Attempted to convert an unmarshallable managed type to Variant. Name: '" + + p_type.type_class->get_name() + "' Encoding: " + itos(p_type.type_encoding) + "."); + } else { + return Variant(); + } +} + +Variant mono_object_to_variant(MonoObject *p_obj) { + if (!p_obj) + return Variant(); + + ManagedType type = ManagedType::from_class(mono_object_get_class(p_obj)); + + return mono_object_to_variant_impl(p_obj, type); +} + +Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) { + if (!p_obj) + return Variant(); + + return mono_object_to_variant_impl(p_obj, p_type); +} + +Variant mono_object_to_variant_no_err(MonoObject *p_obj, const ManagedType &p_type) { + if (!p_obj) + return Variant(); + + return mono_object_to_variant_impl(p_obj, p_type, /* fail_with_err: */ false); +} + +String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc) { + ManagedType type = ManagedType::from_class(mono_object_get_class(p_obj)); + Variant var = GDMonoMarshal::mono_object_to_variant_no_err(p_obj, type); + + if (var.get_type() == Variant::NIL && p_obj != NULL) { + // Cannot convert MonoObject* to Variant; fallback to 'ToString()'. + MonoException *exc = NULL; + MonoString *mono_str = GDMonoUtils::object_to_string(p_obj, &exc); + + if (exc) { + if (r_exc) + *r_exc = exc; + return String(); + } + + return GDMonoMarshal::mono_string_to_godot(mono_str); + } else { + return var.operator String(); + } } MonoArray *Array_to_mono_array(const Array &p_array) { diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h index d0665f7c0d..e662e7814e 100644 --- a/modules/mono/mono_gd/gd_mono_marshal.h +++ b/modules/mono/mono_gd/gd_mono_marshal.h @@ -115,6 +115,12 @@ _FORCE_INLINE_ MonoObject *variant_to_mono_object(const Variant &p_var, const Ma } Variant mono_object_to_variant(MonoObject *p_obj); +Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type); +Variant mono_object_to_variant_no_err(MonoObject *p_obj, const ManagedType &p_type); + +/// Tries to convert the MonoObject* to Variant and then convert the Variant to String. +/// If the MonoObject* cannot be converted to Variant, then 'ToString()' is called instead. +String mono_object_to_variant_string(MonoObject *p_obj, MonoException **r_exc); // Array diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index 8138f96aa6..223e57f39f 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -319,8 +319,6 @@ void VisibilityEnabler2D::_node_removed(Node *p_node) { if (!visible) _change_node_state(p_node, true); - //changed to one shot, not needed - //p_node->disconnect(SceneStringNames::get_singleton()->exit_scene,this,"_node_removed"); nodes.erase(p_node); } diff --git a/scene/3d/camera.cpp b/scene/3d/camera.cpp index bbc81afe3d..289dc0ba07 100644 --- a/scene/3d/camera.cpp +++ b/scene/3d/camera.cpp @@ -390,10 +390,9 @@ Vector3 Camera::project_position(const Point2 &p_point, float p_z_depth) const { ERR_FAIL_COND_V_MSG(!is_inside_tree(), Vector3(), "Camera is not inside scene."); - if (p_z_depth == 0) { + if (p_z_depth == 0 && mode != PROJECTION_ORTHOGONAL) { return get_global_transform().origin; } - Size2 viewport_size = get_viewport()->get_visible_rect().size; CameraMatrix cm; diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index 14c4d306d1..510442dc1c 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -240,7 +240,6 @@ void VisibilityEnabler::_node_removed(Node *p_node) { if (!visible) _change_node_state(p_node, true); - p_node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); nodes.erase(p_node); } |