Browse Source

Simplify ResourceLoader error callbacks

Pedro J. Estébanez 2 years ago
parent
commit
7537a0521f
4 changed files with 15 additions and 29 deletions
  1. 0 3
      core/io/resource_loader.cpp
  2. 6 8
      core/io/resource_loader.h
  3. 5 12
      editor/editor_node.cpp
  4. 4 6
      editor/editor_node.h

+ 0 - 3
core/io/resource_loader.cpp

@@ -1136,10 +1136,7 @@ void ResourceLoader::initialize() {}
 void ResourceLoader::finalize() {}
 void ResourceLoader::finalize() {}
 
 
 ResourceLoadErrorNotify ResourceLoader::err_notify = nullptr;
 ResourceLoadErrorNotify ResourceLoader::err_notify = nullptr;
-void *ResourceLoader::err_notify_ud = nullptr;
-
 DependencyErrorNotify ResourceLoader::dep_err_notify = nullptr;
 DependencyErrorNotify ResourceLoader::dep_err_notify = nullptr;
-void *ResourceLoader::dep_err_notify_ud = nullptr;
 
 
 bool ResourceLoader::create_missing_resources_if_class_unavailable = false;
 bool ResourceLoader::create_missing_resources_if_class_unavailable = false;
 bool ResourceLoader::abort_on_missing_resource = true;
 bool ResourceLoader::abort_on_missing_resource = true;

+ 6 - 8
core/io/resource_loader.h

@@ -89,8 +89,8 @@ public:
 
 
 VARIANT_ENUM_CAST(ResourceFormatLoader::CacheMode)
 VARIANT_ENUM_CAST(ResourceFormatLoader::CacheMode)
 
 
-typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text);
-typedef void (*DependencyErrorNotify)(void *p_ud, const String &p_loading, const String &p_which, const String &p_type);
+typedef void (*ResourceLoadErrorNotify)(const String &p_text);
+typedef void (*DependencyErrorNotify)(const String &p_loading, const String &p_which, const String &p_type);
 
 
 typedef Error (*ResourceLoaderImport)(const String &p_path);
 typedef Error (*ResourceLoaderImport)(const String &p_path);
 typedef void (*ResourceLoadedCallback)(Ref<Resource> p_resource, const String &p_path);
 typedef void (*ResourceLoadedCallback)(Ref<Resource> p_resource, const String &p_path);
@@ -220,22 +220,20 @@ public:
 
 
 	static void notify_load_error(const String &p_err) {
 	static void notify_load_error(const String &p_err) {
 		if (err_notify) {
 		if (err_notify) {
-			err_notify(err_notify_ud, p_err);
+			err_notify(p_err);
 		}
 		}
 	}
 	}
-	static void set_error_notify_func(void *p_ud, ResourceLoadErrorNotify p_err_notify) {
+	static void set_error_notify_func(ResourceLoadErrorNotify p_err_notify) {
 		err_notify = p_err_notify;
 		err_notify = p_err_notify;
-		err_notify_ud = p_ud;
 	}
 	}
 
 
 	static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
 	static void notify_dependency_error(const String &p_path, const String &p_dependency, const String &p_type) {
 		if (dep_err_notify) {
 		if (dep_err_notify) {
-			dep_err_notify(dep_err_notify_ud, p_path, p_dependency, p_type);
+			dep_err_notify(p_path, p_dependency, p_type);
 		}
 		}
 	}
 	}
-	static void set_dependency_error_notify_func(void *p_ud, DependencyErrorNotify p_err_notify) {
+	static void set_dependency_error_notify_func(DependencyErrorNotify p_err_notify) {
 		dep_err_notify = p_err_notify;
 		dep_err_notify = p_err_notify;
-		dep_err_notify_ud = p_ud;
 	}
 	}
 
 
 	static void set_abort_on_missing_resources(bool p_abort) { abort_on_missing_resource = p_abort; }
 	static void set_abort_on_missing_resources(bool p_abort) { abort_on_missing_resource = p_abort; }

+ 5 - 12
editor/editor_node.cpp

@@ -4115,16 +4115,9 @@ void EditorNode::notify_all_debug_sessions_exited() {
 }
 }
 
 
 void EditorNode::add_io_error(const String &p_error) {
 void EditorNode::add_io_error(const String &p_error) {
-	_load_error_notify(singleton, p_error);
-}
-
-void EditorNode::_load_error_notify(void *p_ud, const String &p_text) {
-	EditorNode *en = static_cast<EditorNode *>(p_ud);
-	if (en && en->load_error_dialog) {
-		en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
-		en->load_errors->add_text(p_text + "\n");
-		en->load_error_dialog->attach_and_popup_centered_ratio(0.5);
-	}
+	singleton->load_errors->add_image(singleton->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons")));
+	singleton->load_errors->add_text(p_error + "\n");
+	singleton->load_error_dialog->attach_and_popup_centered_ratio(0.5);
 }
 }
 
 
 bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
 bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const {
@@ -6731,8 +6724,8 @@ EditorNode::EditorNode() {
 	}
 	}
 
 
 	ResourceLoader::set_abort_on_missing_resources(false);
 	ResourceLoader::set_abort_on_missing_resources(false);
-	ResourceLoader::set_error_notify_func(this, _load_error_notify);
-	ResourceLoader::set_dependency_error_notify_func(this, _dependency_error_report);
+	ResourceLoader::set_error_notify_func(&EditorNode::add_io_error);
+	ResourceLoader::set_dependency_error_notify_func(&EditorNode::_dependency_error_report);
 
 
 	{
 	{
 		// Register importers at the beginning, so dialogs are created with the right extensions.
 		// Register importers at the beginning, so dialogs are created with the right extensions.

+ 4 - 6
editor/editor_node.h

@@ -504,12 +504,11 @@ private:
 	static int plugin_init_callback_count;
 	static int plugin_init_callback_count;
 	static Vector<EditorNodeInitCallback> _init_callbacks;
 	static Vector<EditorNodeInitCallback> _init_callbacks;
 
 
-	static void _dependency_error_report(void *ud, const String &p_path, const String &p_dep, const String &p_type) {
-		EditorNode *en = static_cast<EditorNode *>(ud);
-		if (!en->dependency_errors.has(p_path)) {
-			en->dependency_errors[p_path] = HashSet<String>();
+	static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
+		if (!singleton->dependency_errors.has(p_path)) {
+			singleton->dependency_errors[p_path] = HashSet<String>();
 		}
 		}
-		en->dependency_errors[p_path].insert(p_dep + "::" + p_type);
+		singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
 	}
 	}
 
 
 	static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
 	static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
@@ -518,7 +517,6 @@ private:
 	static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
 	static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
 	static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
 	static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
 
 
-	static void _load_error_notify(void *p_ud, const String &p_text);
 	static void _file_access_close_error_notify(const String &p_str);
 	static void _file_access_close_error_notify(const String &p_str);
 
 
 	static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
 	static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);