Skip to content

Commit

Permalink
Allow EditorImportPlugin to override can_import_threaded()
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Jan 9, 2024
1 parent 631d1e3 commit acac31b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/classes/EditorImportPlugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@
<link title="Import plugins">$DOCS_URL/tutorials/plugins/editor/import_plugins.html</link>
</tutorials>
<methods>
<method name="_can_import_threaded" qualifiers="virtual const">
<return type="bool" />
<description>
Tells whether this importer can be run in parallel on threads, or, on the contrary, it's only safe for the editor to call it from the main thread, for one file at a time.
If this method is not overridden, it will return [code]true[/code] by default (i.e., safe for parallel importing).
</description>
</method>
<method name="_get_import_options" qualifiers="virtual const">
<return type="Dictionary[]" />
<param index="0" name="path" type="String" />
Expand Down
10 changes: 10 additions & 0 deletions editor/import/editor_import_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa
ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on.");
}

bool EditorImportPlugin::can_import_threaded() const {
bool ret = false;
if (GDVIRTUAL_CALL(_can_import_threaded, ret)) {
return ret;
} else {
return ResourceImporter::can_import_threaded();
}
}

Error EditorImportPlugin::_append_import_external_resource(const String &p_file, const Dictionary &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters) {
HashMap<StringName, Variant> options;
List<Variant> keys;
Expand Down Expand Up @@ -213,5 +222,6 @@ void EditorImportPlugin::_bind_methods() {
GDVIRTUAL_BIND(_get_import_order)
GDVIRTUAL_BIND(_get_option_visibility, "path", "option_name", "options")
GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files");
GDVIRTUAL_BIND(_can_import_threaded);
ClassDB::bind_method(D_METHOD("append_import_external_resource", "path", "custom_options", "custom_importer", "generator_parameters"), &EditorImportPlugin::_append_import_external_resource, DEFVAL(Dictionary()), DEFVAL(String()), DEFVAL(Variant()));
}
2 changes: 2 additions & 0 deletions editor/import/editor_import_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class EditorImportPlugin : public ResourceImporter {
GDVIRTUAL0RC(int, _get_import_order)
GDVIRTUAL3RC(bool, _get_option_visibility, String, StringName, Dictionary)
GDVIRTUAL5RC(Error, _import, String, String, Dictionary, TypedArray<String>, TypedArray<String>)
GDVIRTUAL0RC(bool, _can_import_threaded)

Error _append_import_external_resource(const String &p_file, const Dictionary &p_custom_options = Dictionary(), const String &p_custom_importer = String(), Variant p_generator_parameters = Variant());

Expand All @@ -69,6 +70,7 @@ class EditorImportPlugin : public ResourceImporter {
virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset) const override;
virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;
virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata = nullptr) override;
virtual bool can_import_threaded() const override;
Error append_import_external_resource(const String &p_file, const HashMap<StringName, Variant> &p_custom_options = HashMap<StringName, Variant>(), const String &p_custom_importer = String(), Variant p_generator_parameters = Variant());
};

Expand Down

0 comments on commit acac31b

Please sign in to comment.