From 867d073b98344b848c96012418912a7e72841a31 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 13 Feb 2020 16:03:10 -0300 Subject: [PATCH] Changed logic and optimized ObjectID in ObjectDB and Variant, removed RefPtr. --- core/io/marshalls.cpp | 12 +- core/io/resource_format_binary.cpp | 2 +- core/io/resource_loader.cpp | 2 +- core/io/resource_saver.cpp | 2 +- core/object.cpp | 197 +++++++++++------- core/object.h | 80 ++++--- core/object_id.h | 1 + core/os/main_loop.cpp | 4 +- core/ref_ptr.cpp | 103 --------- core/ref_ptr.h | 62 ------ core/reference.cpp | 3 +- core/reference.h | 106 +++------- core/resource.h | 1 - core/type_info.h | 18 -- core/variant.cpp | 127 ++++++++--- core/variant.h | 14 +- core/variant_call.cpp | 22 +- core/variant_op.cpp | 66 +++--- editor/editor_autoload_settings.cpp | 2 +- editor/editor_data.cpp | 4 +- editor/editor_node.cpp | 2 +- editor/import/resource_importer_scene.cpp | 2 +- .../animation_blend_tree_editor_plugin.cpp | 2 +- editor/plugins/script_editor_plugin.cpp | 2 +- .../plugins/version_control_editor_plugin.cpp | 2 +- .../plugins/visual_shader_editor_plugin.cpp | 4 +- editor/property_editor.cpp | 26 ++- editor/scene_tree_dock.cpp | 4 +- editor/scene_tree_editor.cpp | 5 +- editor/script_create_dialog.cpp | 2 +- editor/script_editor_debugger.cpp | 2 +- main/main.cpp | 2 +- modules/gdnative/gdnative/gdnative.cpp | 4 - modules/gdnative/gdnative/variant.cpp | 2 +- modules/gdnative/gdnative_api.json | 7 - modules/gdnative/include/gdnative/gdnative.h | 4 +- modules/gdscript/gdscript.cpp | 9 +- modules/gdscript/gdscript.h | 1 + modules/gdscript/gdscript_function.cpp | 62 ++++-- modules/gdscript/gdscript_function.h | 8 +- modules/gdscript/gdscript_functions.cpp | 4 +- modules/mono/csharp_script.cpp | 6 +- modules/mono/mono_gd/gd_mono_internals.cpp | 2 +- .../visual_script/visual_script_editor.cpp | 4 +- modules/visual_script/visual_script_editor.h | 2 +- scene/animation/animation_player.cpp | 2 +- scene/animation/tween.cpp | 11 - scene/debugger/script_debugger_remote.cpp | 2 +- scene/gui/rich_text_label.cpp | 2 +- scene/resources/font.cpp | 2 +- scene/resources/resource_format_text.cpp | 2 +- 51 files changed, 446 insertions(+), 573 deletions(-) delete mode 100644 core/ref_ptr.cpp delete mode 100644 core/ref_ptr.h diff --git a/core/io/marshalls.cpp b/core/io/marshalls.cpp index fdce9db2a09..17edc4982cf 100644 --- a/core/io/marshalls.cpp +++ b/core/io/marshalls.cpp @@ -802,10 +802,10 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } } break; case Variant::OBJECT: { -#ifdef DEBUG_ENABLED + // Test for potential wrong values sent by the debugger when it breaks. - Object *obj = p_variant; - if (!obj || !ObjectDB::instance_validate(obj)) { + Object *obj = p_variant.get_validated_object(); + if (!obj) { // Object is invalid, send a NULL instead. if (buf) { encode_uint32(Variant::NIL, buf); @@ -813,7 +813,7 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo r_len += 4; return OK; } -#endif // DEBUG_ENABLED + if (!p_full_objects) { flags |= ENCODE_FLAG_OBJECT_AS_ID; } @@ -1127,9 +1127,9 @@ Error encode_variant(const Variant &p_variant, uint8_t *r_buffer, int &r_len, bo } else { if (buf) { - Object *obj = p_variant; + Object *obj = p_variant.get_validated_object(); ObjectID id; - if (obj && ObjectDB::instance_validate(obj)) { + if (obj) { id = obj->get_instance_id(); } diff --git a/core/io/resource_format_binary.cpp b/core/io/resource_format_binary.cpp index 4a2bea31825..02ae5788fc0 100644 --- a/core/io/resource_format_binary.cpp +++ b/core/io/resource_format_binary.cpp @@ -1573,7 +1573,7 @@ void ResourceFormatSaverBinaryInstance::_find_resources(const Variant &p_variant switch (p_variant.get_type()) { case Variant::OBJECT: { - RES res = p_variant.operator RefPtr(); + RES res = p_variant; if (res.is_null() || external_resources.has(res)) return; diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 0ee6478fa27..6877f816e1a 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -955,7 +955,7 @@ bool ResourceLoader::add_custom_resource_format_loader(String script_path) { ERR_FAIL_COND_V_MSG(obj == NULL, false, "Cannot instance script as custom resource loader, expected 'ResourceFormatLoader' inheritance, got: " + String(ibt) + "."); ResourceFormatLoader *crl = Object::cast_to(obj); - crl->set_script(s.get_ref_ptr()); + crl->set_script(s); ResourceLoader::add_resource_format_loader(crl); return true; diff --git a/core/io/resource_saver.cpp b/core/io/resource_saver.cpp index b468685e4d4..685d21107fa 100644 --- a/core/io/resource_saver.cpp +++ b/core/io/resource_saver.cpp @@ -221,7 +221,7 @@ bool ResourceSaver::add_custom_resource_format_saver(String script_path) { ERR_FAIL_COND_V_MSG(obj == NULL, false, "Cannot instance script as custom resource saver, expected 'ResourceFormatSaver' inheritance, got: " + String(ibt) + "."); ResourceFormatSaver *crl = Object::cast_to(obj); - crl->set_script(s.get_ref_ptr()); + crl->set_script(s); ResourceSaver::add_resource_format_saver(crl); return true; diff --git a/core/object.cpp b/core/object.cpp index dc1dc2c41f6..9a5cfe5c221 100644 --- a/core/object.cpp +++ b/core/object.cpp @@ -968,7 +968,7 @@ void Object::cancel_delete() { _predelete_ok = true; } -void Object::set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_instance) { +void Object::set_script_and_instance(const Variant &p_script, ScriptInstance *p_instance) { //this function is not meant to be used in any of these ways ERR_FAIL_COND(p_script.is_null()); @@ -979,7 +979,7 @@ void Object::set_script_and_instance(const RefPtr &p_script, ScriptInstance *p_i script_instance = p_instance; } -void Object::set_script(const RefPtr &p_script) { +void Object::set_script(const Variant &p_script) { if (script == p_script) return; @@ -990,7 +990,7 @@ void Object::set_script(const RefPtr &p_script) { } script = p_script; - Ref