summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-07 16:28:14 +0100
committerGitHub <noreply@github.com>2022-01-07 16:28:14 +0100
commitbd91ca027aca787128d913a31ea15870b45f4469 (patch)
tree38556d445f6d6e20fa04e0a1be918b07af15131b /editor
parent07d2dfef7b357adb23727a182e80c55b74799a71 (diff)
parentdf7636b19acc423687f9d785dd7902f94a018f18 (diff)
Merge pull request #50864 from reduz/gen-doc-on-thread
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_help.cpp46
-rw-r--r--editor/editor_help.h9
-rw-r--r--editor/editor_node.cpp2
3 files changed, 52 insertions, 5 deletions
diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp
index 5178f50553..06e3a63f4a 100644
--- a/editor/editor_help.cpp
+++ b/editor/editor_help.cpp
@@ -1724,14 +1724,34 @@ void EditorHelp::_add_text(const String &p_bbcode) {
_add_text_to_rt(p_bbcode, class_desc);
}
-void EditorHelp::generate_doc() {
- doc = memnew(DocTools);
- doc->generate(true);
+Thread EditorHelp::thread;
+
+void EditorHelp::_wait_for_thread() {
+ if (thread.is_started()) {
+ thread.wait_to_finish();
+ }
+}
+
+void EditorHelp::_gen_doc_thread(void *p_udata) {
DocTools compdoc;
compdoc.load_compressed(_doc_data_compressed, _doc_data_compressed_size, _doc_data_uncompressed_size);
doc->merge_from(compdoc); //ensure all is up to date
}
+static bool doc_gen_use_threads = true;
+
+void EditorHelp::generate_doc() {
+ doc = memnew(DocTools);
+ // Not doable on threads unfortunately, since it instantiates all sorts of classes to get default values.
+ doc->generate(true);
+
+ if (doc_gen_use_threads) {
+ thread.start(_gen_doc_thread, nullptr);
+ } else {
+ _gen_doc_thread(nullptr);
+ }
+}
+
void EditorHelp::_toggle_scripts_pressed() {
ScriptEditor::get_singleton()->toggle_scripts_panel();
update_toggle_scripts_button();
@@ -1741,6 +1761,7 @@ void EditorHelp::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY:
case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
+ _wait_for_thread();
_update_doc();
} break;
case NOTIFICATION_THEME_CHANGED: {
@@ -1758,20 +1779,32 @@ void EditorHelp::_notification(int p_what) {
}
void EditorHelp::go_to_help(const String &p_help) {
+ _wait_for_thread();
_help_callback(p_help);
}
void EditorHelp::go_to_class(const String &p_class, int p_scroll) {
+ _wait_for_thread();
_goto_desc(p_class, p_scroll);
}
void EditorHelp::update_doc() {
+ _wait_for_thread();
ERR_FAIL_COND(!doc->class_list.has(edited_class));
ERR_FAIL_COND(!doc->class_list[edited_class].is_script_doc);
_update_doc();
}
+void EditorHelp::cleanup_doc() {
+ _wait_for_thread();
+ if (doc_gen_use_threads) {
+ thread.wait_to_finish();
+ }
+ memdelete(doc);
+}
+
Vector<Pair<String, int>> EditorHelp::get_sections() {
+ _wait_for_thread();
Vector<Pair<String, int>> sections;
for (int i = 0; i < section_line.size(); i++) {
@@ -1781,11 +1814,13 @@ Vector<Pair<String, int>> EditorHelp::get_sections() {
}
void EditorHelp::scroll_to_section(int p_section_index) {
+ _wait_for_thread();
int line = section_line[p_section_index].second;
class_desc->scroll_to_paragraph(line);
}
void EditorHelp::popup_search() {
+ _wait_for_thread();
find_bar->popup_search();
}
@@ -1864,6 +1899,11 @@ EditorHelp::EditorHelp() {
EditorHelp::~EditorHelp() {
}
+DocTools *EditorHelp::get_doc_data() {
+ _wait_for_thread();
+ return doc;
+}
+
void EditorHelpBit::_go_to_help(String p_what) {
EditorNode::get_singleton()->set_visible_editor(EditorNode::EDITOR_SCRIPT);
ScriptEditor::get_singleton()->goto_help(p_what);
diff --git a/editor/editor_help.h b/editor/editor_help.h
index f74c64bb7c..eb879c6d39 100644
--- a/editor/editor_help.h
+++ b/editor/editor_help.h
@@ -31,6 +31,7 @@
#ifndef EDITOR_HELP_H
#define EDITOR_HELP_H
+#include "core/os/thread.h"
#include "editor/code_editor.h"
#include "editor/doc_tools.h"
#include "editor/editor_plugin.h"
@@ -164,13 +165,19 @@ class EditorHelp : public VBoxContainer {
String _fix_constant(const String &p_constant) const;
void _toggle_scripts_pressed();
+ static Thread thread;
+
+ static void _wait_for_thread();
+ static void _gen_doc_thread(void *p_udata);
+
protected:
void _notification(int p_what);
static void _bind_methods();
public:
static void generate_doc();
- static DocTools *get_doc_data() { return doc; }
+ static DocTools *get_doc_data();
+ static void cleanup_doc();
void go_to_help(const String &p_help);
void go_to_class(const String &p_class, int p_scroll = 0);
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index cca8bc1b29..afd5407f37 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -7211,7 +7211,7 @@ EditorNode::~EditorNode() {
EditorTranslationParser::get_singleton()->clean_parsers();
remove_print_handler(&print_handler);
- memdelete(EditorHelp::get_doc_data());
+ EditorHelp::cleanup_doc();
memdelete(editor_selection);
memdelete(editor_plugins_over);
memdelete(editor_plugins_force_over);