diff options
author | David Snopek <dsnopek@gmail.com> | 2024-01-25 08:54:58 -0600 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2024-05-07 11:08:18 -0500 |
commit | a434850069212b2d2dbe70fd82c4e5774b739040 (patch) | |
tree | dc624f2af43e2033fb7304e879f5d8348feac7d8 /src/godot.cpp | |
parent | 54fe2f9891525891a52c47ffbd190d15c38cccab (diff) | |
download | redot-cpp-a434850069212b2d2dbe70fd82c4e5774b739040.tar.gz |
Allow submitting documentation to the Godot editor
Diffstat (limited to 'src/godot.cpp')
-rw-r--r-- | src/godot.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/godot.cpp b/src/godot.cpp index 8a031be..01977de 100644 --- a/src/godot.cpp +++ b/src/godot.cpp @@ -196,6 +196,38 @@ GDExtensionInterfaceClassdbUnregisterExtensionClass gdextension_interface_classd GDExtensionInterfaceGetLibraryPath gdextension_interface_get_library_path = nullptr; GDExtensionInterfaceEditorAddPlugin gdextension_interface_editor_add_plugin = nullptr; GDExtensionInterfaceEditorRemovePlugin gdextension_interface_editor_remove_plugin = nullptr; +GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8Chars gdextension_interface_editor_help_load_xml_from_utf8_chars = nullptr; +GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen gdextension_interface_editor_help_load_xml_from_utf8_chars_and_len = nullptr; + +struct DocData { + const char *hash = nullptr; + int uncompressed_size = 0; + int compressed_size = 0; + const unsigned char *data = nullptr; + + inline bool is_valid() const { + return hash != nullptr && uncompressed_size > 0 && compressed_size > 0 && data != nullptr; + } + + void load_data() const; +}; + +static DocData &get_doc_data() { + static DocData doc_data; + return doc_data; +} + +DocDataRegistration::DocDataRegistration(const char *p_hash, int p_uncompressed_size, int p_compressed_size, const unsigned char *p_data) { + DocData &doc_data = get_doc_data(); + if (doc_data.is_valid()) { + printf("ERROR: Attempting to register documentation data when we already have some - discarding.\n"); + return; + } + doc_data.hash = p_hash; + doc_data.uncompressed_size = p_uncompressed_size; + doc_data.compressed_size = p_compressed_size; + doc_data.data = p_data; +} } // namespace internal @@ -436,6 +468,8 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge LOAD_PROC_ADDRESS(get_library_path, GDExtensionInterfaceGetLibraryPath); LOAD_PROC_ADDRESS(editor_add_plugin, GDExtensionInterfaceEditorAddPlugin); LOAD_PROC_ADDRESS(editor_remove_plugin, GDExtensionInterfaceEditorRemovePlugin); + LOAD_PROC_ADDRESS(editor_help_load_xml_from_utf8_chars, GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8Chars); + LOAD_PROC_ADDRESS(editor_help_load_xml_from_utf8_chars_and_len, GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen); r_initialization->initialize = initialize_level; r_initialization->deinitialize = deinitialize_level; @@ -465,6 +499,13 @@ void GDExtensionBinding::initialize_level(void *p_userdata, GDExtensionInitializ ClassDB::initialize(p_level); } level_initialized[p_level]++; + + if ((ModuleInitializationLevel)p_level == MODULE_INITIALIZATION_LEVEL_EDITOR) { + const internal::DocData &doc_data = internal::get_doc_data(); + if (doc_data.is_valid()) { + doc_data.load_data(); + } + } } void GDExtensionBinding::deinitialize_level(void *p_userdata, GDExtensionInitializationLevel p_level) { @@ -531,4 +572,15 @@ GDExtensionBool GDExtensionBinding::InitObject::init() const { return GDExtensionBinding::init(get_proc_address, library, init_data, initialization); } +void internal::DocData::load_data() const { + PackedByteArray compressed; + compressed.resize(compressed_size); + memcpy(compressed.ptrw(), data, compressed_size); + + // FileAccess::COMPRESSION_DEFLATE = 1 + PackedByteArray decompressed = compressed.decompress(uncompressed_size, 1); + + internal::gdextension_interface_editor_help_load_xml_from_utf8_chars_and_len(reinterpret_cast<const char *>(decompressed.ptr()), uncompressed_size); +} + } // namespace godot |