Skip to content

Commit

Permalink
[TextServer, GDExtension] Fix building text servers as GDExtension, e…
Browse files Browse the repository at this point in the history
…xpose new/changed low-level methods to GDExtension API.
  • Loading branch information
bruvzg committed Jun 3, 2024
1 parent 21d526e commit 639466f
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 15 deletions.
8 changes: 6 additions & 2 deletions binding_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
# Special cases.
if class_name == "String":
result.append("\tstatic String utf8(const char *from, int64_t len = -1);")
result.append("\tvoid parse_utf8(const char *from, int64_t len = -1);")
result.append("\tError parse_utf8(const char *from, int64_t len = -1);")
result.append("\tstatic String utf16(const char16_t *from, int64_t len = -1);")
result.append("\tvoid parse_utf16(const char16_t *from, int64_t len = -1);")
result.append("\tError parse_utf16(const char16_t *from, int64_t len = -1, bool default_little_endian = true);")
result.append("\tCharString utf8() const;")
result.append("\tCharString ascii() const;")
result.append("\tChar16String utf16() const;")
Expand Down Expand Up @@ -1601,6 +1601,10 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
if class_name == "XMLParser":
result.append("\tError _open_buffer(const uint8_t *p_buffer, size_t p_size);")

if class_name == "Image":
result.append("\tuint8_t *ptrw();")
result.append("\tconst uint8_t *ptr();")

if class_name == "FileAccess":
result.append("\tuint64_t get_buffer(uint8_t *p_dst, uint64_t p_length) const;")
result.append("\tvoid store_buffer(const uint8_t *p_src, uint64_t p_length);")
Expand Down
88 changes: 79 additions & 9 deletions gdextension/extension_api.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version_major": 4,
"version_minor": 3,
"version_patch": 0,
"version_status": "beta1",
"version_build": "official",
"version_full_name": "Godot Engine v4.3.beta1.official"
"version_status": "beta",
"version_build": "custom_build",
"version_full_name": "Godot Engine v4.3.beta.custom_build"
},
"builtin_class_sizes": [
{
Expand Down Expand Up @@ -20086,6 +20086,24 @@
"is_const": true,
"is_static": false,
"hash": 3918633141
},
{
"name": "recursive_equal",
"return_type": "bool",
"is_vararg": false,
"is_const": true,
"is_static": false,
"hash": 1404404751,
"arguments": [
{
"name": "dictionary",
"type": "Dictionary"
},
{
"name": "recursion_count",
"type": "int"
}
]
}
],
"constructors": [
Expand Down Expand Up @@ -119369,6 +119387,18 @@
"type": "PackedByteArray"
}
},
{
"name": "get_data_size",
"is_const": true,
"is_vararg": false,
"is_static": false,
"is_virtual": false,
"hash": 3905245786,
"return_value": {
"type": "int",
"meta": "int64"
}
},
{
"name": "convert",
"is_const": false,
Expand Down Expand Up @@ -119563,6 +119593,37 @@
}
]
},
{
"name": "create_empty",
"is_const": false,
"is_vararg": false,
"is_static": true,
"is_virtual": false,
"hash": 986942177,
"return_value": {
"type": "Image"
},
"arguments": [
{
"name": "width",
"type": "int",
"meta": "int32"
},
{
"name": "height",
"type": "int",
"meta": "int32"
},
{
"name": "use_mipmaps",
"type": "bool"
},
{
"name": "format",
"type": "enum::Image.Format"
}
]
},
{
"name": "create_from_data",
"is_const": false,
Expand Down Expand Up @@ -256177,7 +256238,7 @@
{
"name": "baseline_offset",
"type": "float",
"meta": "float"
"meta": "double"
}
]
},
Expand All @@ -256190,7 +256251,7 @@
"hash": 866169185,
"return_value": {
"type": "float",
"meta": "float"
"meta": "double"
},
"arguments": [
{
Expand Down Expand Up @@ -259603,7 +259664,8 @@
"arguments": [
{
"name": "unicode",
"type": "int"
"type": "int",
"meta": "uint64"
}
]
},
Expand Down Expand Up @@ -260691,7 +260753,7 @@
{
"name": "baseline_offset",
"type": "float",
"meta": "float"
"meta": "double"
}
]
},
Expand All @@ -260703,7 +260765,7 @@
"is_virtual": true,
"return_value": {
"type": "float",
"meta": "float"
"meta": "double"
},
"arguments": [
{
Expand Down Expand Up @@ -263806,7 +263868,8 @@
"arguments": [
{
"name": "unicode",
"type": "int"
"type": "int",
"meta": "uint64"
}
]
},
Expand Down Expand Up @@ -263985,6 +264048,13 @@
}
]
},
{
"name": "TextServerFallback",
"is_refcounted": true,
"is_instantiable": true,
"inherits": "TextServerExtension",
"api_type": "core"
},
{
"name": "TextServerManager",
"is_refcounted": false,
Expand Down
59 changes: 59 additions & 0 deletions gdextension/gdextension_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -1591,6 +1591,20 @@ typedef void (*GDExtensionInterfaceStringNewWithLatin1CharsAndLen)(GDExtensionUn
*/
typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size);

/**
* @name string_new_with_utf8_chars_and_len2
* @since 4.3
*
* Creates a String from a UTF-8 encoded C string with the given length.
*
* @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a UTF-8 encoded C string.
* @param p_size The number of bytes (not code units).
*
* @return Error code signifying if the operation successful.
*/
typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen2)(GDExtensionUninitializedStringPtr r_dest, const char *p_contents, GDExtensionInt p_size);

/**
* @name string_new_with_utf16_chars_and_len
* @since 4.1
Expand All @@ -1603,6 +1617,21 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen)(GDExtensionUnin
*/
typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count);

/**
* @name string_new_with_utf16_chars_and_len2
* @since 4.3
*
* Creates a String from a UTF-16 encoded C string with the given length.
*
* @param r_dest A pointer to a Variant to hold the newly created String.
* @param p_contents A pointer to a UTF-16 encoded C string.
* @param p_size The number of characters (not bytes).
* @param p_default_little_endian If true, UTF-16 use little endian.
*
* @return Error code signifying if the operation successful.
*/
typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen2)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count, GDExtensionBool p_default_little_endian);

/**
* @name string_new_with_utf32_chars_and_len
* @since 4.1
Expand Down Expand Up @@ -1899,6 +1928,36 @@ typedef void (*GDExtensionInterfaceFileAccessStoreBuffer)(GDExtensionObjectPtr p
*/
typedef uint64_t (*GDExtensionInterfaceFileAccessGetBuffer)(GDExtensionConstObjectPtr p_instance, uint8_t *p_dst, uint64_t p_length);

/* INTERFACE: Image Utilities */

/**
* @name image_ptrw
* @since 4.3
*
* Returns writable pointer to internal Image buffer.
*
* @param p_instance A pointer to a Image object.
*
* @return Pointer to internal Image buffer.
*
* @see Image::ptrw()
*/
typedef uint8_t *(*GDExtensionInterfaceImagePtrw)(GDExtensionObjectPtr p_instance);

/**
* @name image_ptr
* @since 4.3
*
* Returns read only pointer to internal Image buffer.
*
* @param p_instance A pointer to a Image object.
*
* @return Pointer to internal Image buffer.
*
* @see Image::ptr()
*/
typedef const uint8_t *(*GDExtensionInterfaceImagePtr)(GDExtensionObjectPtr p_instance);

/* INTERFACE: WorkerThreadPool Utilities */

/**
Expand Down
4 changes: 4 additions & 0 deletions include/godot_cpp/godot.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ extern "C" GDExtensionInterfaceStringNewWithUtf32Chars gdextension_interface_str
extern "C" GDExtensionInterfaceStringNewWithWideChars gdextension_interface_string_new_with_wide_chars;
extern "C" GDExtensionInterfaceStringNewWithLatin1CharsAndLen gdextension_interface_string_new_with_latin1_chars_and_len;
extern "C" GDExtensionInterfaceStringNewWithUtf8CharsAndLen gdextension_interface_string_new_with_utf8_chars_and_len;
extern "C" GDExtensionInterfaceStringNewWithUtf8CharsAndLen2 gdextension_interface_string_new_with_utf8_chars_and_len2;
extern "C" GDExtensionInterfaceStringNewWithUtf16CharsAndLen gdextension_interface_string_new_with_utf16_chars_and_len;
extern "C" GDExtensionInterfaceStringNewWithUtf16CharsAndLen2 gdextension_interface_string_new_with_utf16_chars_and_len2;
extern "C" GDExtensionInterfaceStringNewWithUtf32CharsAndLen gdextension_interface_string_new_with_utf32_chars_and_len;
extern "C" GDExtensionInterfaceStringNewWithWideCharsAndLen gdextension_interface_string_new_with_wide_chars_and_len;
extern "C" GDExtensionInterfaceStringToLatin1Chars gdextension_interface_string_to_latin1_chars;
Expand Down Expand Up @@ -195,6 +197,8 @@ extern "C" GDExtensionInterfaceEditorAddPlugin gdextension_interface_editor_add_
extern "C" GDExtensionInterfaceEditorRemovePlugin gdextension_interface_editor_remove_plugin;
extern "C" GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8Chars gdextension_interface_editor_help_load_xml_from_utf8_chars;
extern "C" GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen gdextension_interface_editor_help_load_xml_from_utf8_chars_and_len;
extern "C" GDExtensionInterfaceImagePtrw gdextension_interface_image_ptrw;
extern "C" GDExtensionInterfaceImagePtr gdextension_interface_image_ptr;

class DocDataRegistration {
public:
Expand Down
9 changes: 9 additions & 0 deletions src/classes/low_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
/**************************************************************************/

#include <godot_cpp/classes/file_access.hpp>
#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/classes/worker_thread_pool.hpp>
#include <godot_cpp/classes/xml_parser.hpp>

Expand All @@ -55,4 +56,12 @@ WorkerThreadPool::GroupID WorkerThreadPool::add_native_group_task(void (*p_func)
return (GroupID)internal::gdextension_interface_worker_thread_pool_add_native_group_task(_owner, p_func, p_userdata, p_elements, p_tasks, p_high_priority, (GDExtensionConstStringPtr)&p_description);
}

uint8_t *Image::ptrw() {
return internal::gdextension_interface_image_ptrw(_owner);
}

const uint8_t *Image::ptr() {
return internal::gdextension_interface_image_ptr(_owner);
}

} // namespace godot
8 changes: 8 additions & 0 deletions src/godot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ GDExtensionInterfaceStringNewWithUtf32Chars gdextension_interface_string_new_wit
GDExtensionInterfaceStringNewWithWideChars gdextension_interface_string_new_with_wide_chars = nullptr;
GDExtensionInterfaceStringNewWithLatin1CharsAndLen gdextension_interface_string_new_with_latin1_chars_and_len = nullptr;
GDExtensionInterfaceStringNewWithUtf8CharsAndLen gdextension_interface_string_new_with_utf8_chars_and_len = nullptr;
GDExtensionInterfaceStringNewWithUtf8CharsAndLen2 gdextension_interface_string_new_with_utf8_chars_and_len2 = nullptr;
GDExtensionInterfaceStringNewWithUtf16CharsAndLen gdextension_interface_string_new_with_utf16_chars_and_len = nullptr;
GDExtensionInterfaceStringNewWithUtf16CharsAndLen2 gdextension_interface_string_new_with_utf16_chars_and_len2 = nullptr;
GDExtensionInterfaceStringNewWithUtf32CharsAndLen gdextension_interface_string_new_with_utf32_chars_and_len = nullptr;
GDExtensionInterfaceStringNewWithWideCharsAndLen gdextension_interface_string_new_with_wide_chars_and_len = nullptr;
GDExtensionInterfaceStringToLatin1Chars gdextension_interface_string_to_latin1_chars = nullptr;
Expand Down Expand Up @@ -201,6 +203,8 @@ GDExtensionInterfaceEditorAddPlugin gdextension_interface_editor_add_plugin = nu
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;
GDExtensionInterfaceImagePtrw gdextension_interface_image_ptrw = nullptr;
GDExtensionInterfaceImagePtr gdextension_interface_image_ptr = nullptr;

struct DocData {
const char *hash = nullptr;
Expand Down Expand Up @@ -389,7 +393,9 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
LOAD_PROC_ADDRESS(string_new_with_wide_chars, GDExtensionInterfaceStringNewWithWideChars);
LOAD_PROC_ADDRESS(string_new_with_latin1_chars_and_len, GDExtensionInterfaceStringNewWithLatin1CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf8_chars_and_len, GDExtensionInterfaceStringNewWithUtf8CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf8_chars_and_len2, GDExtensionInterfaceStringNewWithUtf8CharsAndLen2);
LOAD_PROC_ADDRESS(string_new_with_utf16_chars_and_len, GDExtensionInterfaceStringNewWithUtf16CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_utf16_chars_and_len2, GDExtensionInterfaceStringNewWithUtf16CharsAndLen2);
LOAD_PROC_ADDRESS(string_new_with_utf32_chars_and_len, GDExtensionInterfaceStringNewWithUtf32CharsAndLen);
LOAD_PROC_ADDRESS(string_new_with_wide_chars_and_len, GDExtensionInterfaceStringNewWithWideCharsAndLen);
LOAD_PROC_ADDRESS(string_to_latin1_chars, GDExtensionInterfaceStringToLatin1Chars);
Expand Down Expand Up @@ -476,6 +482,8 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
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);
LOAD_PROC_ADDRESS(image_ptrw, GDExtensionInterfaceImagePtrw);
LOAD_PROC_ADDRESS(image_ptr, GDExtensionInterfaceImagePtr);

r_initialization->initialize = initialize_level;
r_initialization->deinitialize = deinitialize_level;
Expand Down
8 changes: 4 additions & 4 deletions src/variant/char_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ String String::utf8(const char *from, int64_t len) {
return ret;
}

void String::parse_utf8(const char *from, int64_t len) {
internal::gdextension_interface_string_new_with_utf8_chars_and_len(_native_ptr(), from, len);
Error String::parse_utf8(const char *from, int64_t len) {
return (Error)internal::gdextension_interface_string_new_with_utf8_chars_and_len2(_native_ptr(), from, len);
}

String String::utf16(const char16_t *from, int64_t len) {
Expand All @@ -188,8 +188,8 @@ String String::utf16(const char16_t *from, int64_t len) {
return ret;
}

void String::parse_utf16(const char16_t *from, int64_t len) {
internal::gdextension_interface_string_new_with_utf16_chars_and_len(_native_ptr(), from, len);
Error String::parse_utf16(const char16_t *from, int64_t len, bool default_little_endian) {
return (Error)internal::gdextension_interface_string_new_with_utf16_chars_and_len2(_native_ptr(), from, len, default_little_endian);
}

String String::num_real(double p_num, bool p_trailing) {
Expand Down

0 comments on commit 639466f

Please sign in to comment.