diff options
-rw-r--r-- | editor/connections_dialog.cpp | 31 | ||||
-rw-r--r-- | editor/connections_dialog.h | 1 | ||||
-rw-r--r-- | editor/import/editor_scene_importer_gltf.cpp | 4 | ||||
-rw-r--r-- | editor/plugins/script_text_editor.cpp | 14 | ||||
-rw-r--r-- | modules/assimp/import_utils.h | 2 | ||||
-rw-r--r-- | modules/gdscript/gdscript.cpp | 51 | ||||
-rw-r--r-- | modules/gdscript/gdscript.h | 7 | ||||
-rw-r--r-- | modules/gdscript/gdscript_compiler.cpp | 10 | ||||
-rw-r--r-- | modules/gdscript/gdscript_parser.cpp | 51 |
9 files changed, 133 insertions, 38 deletions
diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 2ef5097345..1853133bc7 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -146,7 +146,7 @@ void ConnectDialog::_tree_node_selected() { return; dst_path = source->get_path_to(current); - get_ok()->set_disabled(false); + _update_ok_enabled(); } /* @@ -210,6 +210,27 @@ void ConnectDialog::_remove_bind() { cdbinds->notify_changed(); } +/* + * Enables or disables the connect button. The connect button is enabled if a + * node is selected and valid in the selected mode. + */ +void ConnectDialog::_update_ok_enabled() { + + Node *target = tree->get_selected(); + + if (target == nullptr) { + get_ok()->set_disabled(true); + return; + } + + if (!advanced->is_pressed() && target->get_script().is_null()) { + get_ok()->set_disabled(true); + return; + } + + get_ok()->set_disabled(false); +} + void ConnectDialog::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { @@ -225,6 +246,7 @@ void ConnectDialog::_bind_methods() { ClassDB::bind_method("_tree_item_activated", &ConnectDialog::_tree_item_activated); ClassDB::bind_method("_add_bind", &ConnectDialog::_add_bind); ClassDB::bind_method("_remove_bind", &ConnectDialog::_remove_bind); + ClassDB::bind_method("_update_ok_enabled", &ConnectDialog::_update_ok_enabled); ADD_SIGNAL(MethodInfo("connected")); } @@ -301,13 +323,12 @@ void ConnectDialog::init(Connection c, bool bEdit) { tree->set_marked(source, true); if (c.target) { - get_ok()->set_disabled(false); set_dst_node(static_cast<Node *>(c.target)); set_dst_method(c.method); - } else { - get_ok()->set_disabled(true); } + _update_ok_enabled(); + bool bDeferred = (c.flags & CONNECT_DEFERRED) == CONNECT_DEFERRED; bool bOneshot = (c.flags & CONNECT_ONESHOT) == CONNECT_ONESHOT; @@ -350,6 +371,8 @@ void ConnectDialog::_advanced_pressed() { error_label->set_visible(!_find_first_script(get_tree()->get_edited_scene_root(), get_tree()->get_edited_scene_root())); } + _update_ok_enabled(); + set_position((get_viewport_rect().size - get_custom_minimum_size()) / 2); } diff --git a/editor/connections_dialog.h b/editor/connections_dialog.h index 4f46e145e1..c30413953a 100644 --- a/editor/connections_dialog.h +++ b/editor/connections_dialog.h @@ -80,6 +80,7 @@ class ConnectDialog : public ConfirmationDialog { void _add_bind(); void _remove_bind(); void _advanced_pressed(); + void _update_ok_enabled(); protected: void _notification(int p_what); diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 7de6db7add..a418915830 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1302,6 +1302,8 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b if (mimetype.findn("png") != -1) { //is a png + ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, ERR_UNAVAILABLE); + const Ref<Image> img = Image::_png_mem_loader_func(data_ptr, data_size); ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); @@ -1316,6 +1318,8 @@ Error EditorSceneImporterGLTF::_parse_images(GLTFState &state, const String &p_b if (mimetype.findn("jpeg") != -1) { //is a jpg + ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, ERR_UNAVAILABLE); + const Ref<Image> img = Image::_jpg_mem_loader_func(data_ptr, data_size); ERR_FAIL_COND_V(img.is_null(), ERR_FILE_CORRUPT); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index f0e4a4bfdc..1432c3fc63 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -691,13 +691,16 @@ void ScriptTextEditor::_update_bookmark_list() { bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { - String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); + // Strip edges to remove spaces or tabs. + // Also replace any tabs by spaces, since we can't print tabs in the menu. + String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).replace("\t", " ").strip_edges(); + // Limit the size of the line if too big. if (line.length() > 50) { line = line.substr(0, 50); } - bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - `" + line + "`"); bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } @@ -841,13 +844,16 @@ void ScriptTextEditor::_update_breakpoint_list() { breakpoints_menu->add_separator(); for (int i = 0; i < breakpoint_list.size(); i++) { - String line = code_editor->get_text_edit()->get_line(breakpoint_list[i]).strip_edges(); + // Strip edges to remove spaces or tabs. + // Also replace any tabs by spaces, since we can't print tabs in the menu. + String line = code_editor->get_text_edit()->get_line(breakpoint_list[i]).replace("\t", " ").strip_edges(); + // Limit the size of the line if too big. if (line.length() > 50) { line = line.substr(0, 50); } - breakpoints_menu->add_item(String::num((int)breakpoint_list[i] + 1) + " - \"" + line + "\""); + breakpoints_menu->add_item(String::num((int)breakpoint_list[i] + 1) + " - `" + line + "`"); breakpoints_menu->set_item_metadata(breakpoints_menu->get_item_count() - 1, breakpoint_list[i]); } } diff --git a/modules/assimp/import_utils.h b/modules/assimp/import_utils.h index f4505249db..c522b01727 100644 --- a/modules/assimp/import_utils.h +++ b/modules/assimp/import_utils.h @@ -355,11 +355,13 @@ public: print_verbose("Open Asset Import: Loading embedded texture " + filename); if (tex->mHeight == 0) { if (tex->CheckFormat("png")) { + ERR_FAIL_COND_V(Image::_png_mem_loader_func == NULL, Ref<Image>()); Ref<Image> img = Image::_png_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); state.path_to_image_cache.insert(p_path, img); return img; } else if (tex->CheckFormat("jpg")) { + ERR_FAIL_COND_V(Image::_jpg_mem_loader_func == NULL, Ref<Image>()); Ref<Image> img = Image::_jpg_mem_loader_func((uint8_t *)tex->pcData, tex->mWidth); ERR_FAIL_COND_V(img.is_null(), Ref<Image>()); state.path_to_image_cache.insert(p_path, img); diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 8abf2ee7ca..8030837cd4 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -915,14 +915,43 @@ GDScript::GDScript() : #endif } +void GDScript::_save_orphaned_subclasses() { + struct ClassRefWithName { + ObjectID id; + String fully_qualified_name; + }; + Vector<ClassRefWithName> weak_subclasses; + // collect subclasses ObjectID and name + for (Map<StringName, Ref<GDScript> >::Element *E = subclasses.front(); E; E = E->next()) { + E->get()->_owner = NULL; //bye, you are no longer owned cause I died + ClassRefWithName subclass; + subclass.id = E->get()->get_instance_id(); + subclass.fully_qualified_name = E->get()->fully_qualified_name; + weak_subclasses.push_back(subclass); + } + + // clear subclasses to allow unused subclasses to be deleted + subclasses.clear(); + // subclasses are also held by constants, clear those as well + constants.clear(); + + // keep orphan subclass only for subclasses that are still in use + for (int i = 0; i < weak_subclasses.size(); i++) { + ClassRefWithName subclass = weak_subclasses[i]; + Object *obj = ObjectDB::get_instance(subclass.id); + if (!obj) + continue; + // subclass is not released + GDScriptLanguage::get_singleton()->add_orphan_subclass(subclass.fully_qualified_name, subclass.id); + } +} + GDScript::~GDScript() { for (Map<StringName, GDScriptFunction *>::Element *E = member_functions.front(); E; E = E->next()) { memdelete(E->get()); } - for (Map<StringName, Ref<GDScript> >::Element *E = subclasses.front(); E; E = E->next()) { - E->get()->_owner = NULL; //bye, you are no longer owned cause I died - } + _save_orphaned_subclasses(); #ifdef DEBUG_ENABLED if (GDScriptLanguage::get_singleton()->lock) { @@ -2176,6 +2205,22 @@ GDScriptLanguage::~GDScriptLanguage() { singleton = NULL; } +void GDScriptLanguage::add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass) { + orphan_subclasses[p_qualified_name] = p_subclass; +} + +Ref<GDScript> GDScriptLanguage::get_orphan_subclass(const String &p_qualified_name) { + Map<String, ObjectID>::Element *orphan_subclass_element = orphan_subclasses.find(p_qualified_name); + if (!orphan_subclass_element) + return Ref<GDScript>(); + ObjectID orphan_subclass = orphan_subclass_element->get(); + Object *obj = ObjectDB::get_instance(orphan_subclass); + orphan_subclasses.erase(orphan_subclass_element); + if (!obj) + return Ref<GDScript>(); + return Ref<GDScript>(Object::cast_to<GDScript>(obj)); +} + /*************** RESOURCE ***************/ RES ResourceFormatLoaderGDScript::load(const String &p_path, const String &p_original_path, Error *r_error) { diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h index 0e2b812a22..4ae52238ce 100644 --- a/modules/gdscript/gdscript.h +++ b/modules/gdscript/gdscript.h @@ -132,6 +132,8 @@ class GDScript : public Script { bool _update_exports(); + void _save_orphaned_subclasses(); + protected: bool _get(const StringName &p_name, Variant &r_ret) const; bool _set(const StringName &p_name, const Variant &p_value); @@ -355,6 +357,8 @@ class GDScriptLanguage : public ScriptLanguage { bool profiling; uint64_t script_frame_time; + Map<String, ObjectID> orphan_subclasses; + public: int calls; @@ -506,6 +510,9 @@ public: virtual bool handles_global_class_type(const String &p_type) const; virtual String get_global_class_name(const String &p_path, String *r_base_type = NULL, String *r_icon_path = NULL) const; + void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass); + Ref<GDScript> get_orphan_subclass(const String &p_qualified_name); + GDScriptLanguage(); ~GDScriptLanguage(); }; diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 711fa54d0b..fba1b992ec 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -2123,15 +2123,21 @@ void GDScriptCompiler::_make_scripts(GDScript *p_script, const GDScriptParser::C StringName name = p_class->subclasses[i]->name; Ref<GDScript> subclass; + String fully_qualified_name = p_script->fully_qualified_name + "::" + name; if (old_subclasses.has(name)) { subclass = old_subclasses[name]; } else { - subclass.instance(); + Ref<GDScript> orphan_subclass = GDScriptLanguage::get_singleton()->get_orphan_subclass(fully_qualified_name); + if (orphan_subclass.is_valid()) { + subclass = orphan_subclass; + } else { + subclass.instance(); + } } subclass->_owner = p_script; - subclass->fully_qualified_name = p_script->fully_qualified_name + "::" + name; + subclass->fully_qualified_name = fully_qualified_name; p_script->subclasses.insert(name, subclass); _make_scripts(subclass.ptr(), p_class->subclasses[i], false); diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index fc2e626795..5c2e7137bf 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4741,10 +4741,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.line = tokenizer->get_token_line(); member.usages = 0; member.rpc_mode = rpc_mode; -#ifdef TOOLS_ENABLED - Variant::CallError ce; - member.default_value = Variant::construct(member._export.type, NULL, 0, ce); -#endif if (current_class->constant_expressions.has(member.identifier)) { _set_error("A constant named \"" + String(member.identifier) + "\" already exists in this class (at line: " + @@ -4797,6 +4793,32 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { } } + if (autoexport && member.data_type.has_type) { + if (member.data_type.kind == DataType::BUILTIN) { + member._export.type = member.data_type.builtin_type; + } else if (member.data_type.kind == DataType::NATIVE) { + if (ClassDB::is_parent_class(member.data_type.native_type, "Resource")) { + member._export.type = Variant::OBJECT; + member._export.hint = PROPERTY_HINT_RESOURCE_TYPE; + member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; + member._export.hint_string = member.data_type.native_type; + member._export.class_name = member.data_type.native_type; + } else { + _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); + return; + } + + } else { + _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); + return; + } + } + +#ifdef TOOLS_ENABLED + Variant::CallError ce; + member.default_value = Variant::construct(member._export.type, NULL, 0, ce); +#endif + if (tokenizer->get_token() == GDScriptTokenizer::TK_OP_ASSIGN) { #ifdef DEBUG_ENABLED @@ -4930,27 +4952,6 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { member.initial_assignment = op; } - if (autoexport && member.data_type.has_type) { - if (member.data_type.kind == DataType::BUILTIN) { - member._export.type = member.data_type.builtin_type; - } else if (member.data_type.kind == DataType::NATIVE) { - if (ClassDB::is_parent_class(member.data_type.native_type, "Resource")) { - member._export.type = Variant::OBJECT; - member._export.hint = PROPERTY_HINT_RESOURCE_TYPE; - member._export.usage |= PROPERTY_USAGE_SCRIPT_VARIABLE; - member._export.hint_string = member.data_type.native_type; - member._export.class_name = member.data_type.native_type; - } else { - _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); - return; - } - - } else { - _set_error("Invalid export type. Only built-in and native resource types can be exported.", member.line); - return; - } - } - if (tokenizer->get_token() == GDScriptTokenizer::TK_PR_SETGET) { tokenizer->advance(); |