Skip to content

Commit 9609216

Browse files
committed
Upgrade to gdptrs.gdptr_classdb_register_extension_class4() for registering extensions
1 parent eab16c9 commit 9609216

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

scripts/gdextension_cython_preprocessor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def __cinit__(self):
109109
{spec.class_name + "." + spec.cinit_instance_hook + "()" if spec.cinit_instance_hook is not None else ""}
110110
111111
@staticmethod
112-
cdef GDExtensionObjectPtr __godot_extension_create_instance(void* p_class_userdata) noexcept with gil:
112+
cdef GDExtensionObjectPtr __godot_extension_create_instance(void* p_class_userdata, GDExtensionBool p_notify_postinitialize) noexcept with gil:
113+
# TODO: use `p_notify_postinitialize` ?
113114
# print("[DEBUG] {spec.class_name}.__godot_extension_create_instance()")
114115
cdef {spec.class_name} obj = {spec.class_name}()
115116
# Note `Py_INCREF(obj)` has already been done during `__cinit__`
@@ -189,8 +190,9 @@ def __godot_extension_register_class():
189190
# TODO: cache virtual methods name to avoid pystr to gd_string_name_t conversions
190191
code += """
191192
@staticmethod
192-
cdef GDExtensionClassCallVirtual __godot_extension_get_virtual(void *p_class_userdata, GDExtensionConstStringNamePtr p_name) noexcept with gil:
193+
cdef GDExtensionClassCallVirtual __godot_extension_get_virtual(void *p_class_userdata, GDExtensionConstStringNamePtr p_name, uint32_t p_hash) noexcept with gil:
193194
# TODO: We should handle inheritance here by looking into parent class until we reach a Godot class
195+
# TODO: use `p_hash` ?
194196
cdef gd_string_t gd_candidate_name
195197
"""
196198
code += f"""

src/godot/hazmat/extension_class.pxd

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ cdef inline void _extension_class_to_string(GDExtensionClassInstancePtr p_instan
5050
cdef inline void register_extension_class_creation(
5151
bytes class_name,
5252
bytes parent_class_name,
53-
GDExtensionClassCreateInstance create_instance_func,
53+
GDExtensionClassCreateInstance2 create_instance_func,
5454
GDExtensionClassFreeInstance free_instance_func,
55-
GDExtensionClassGetVirtual get_virtual_func,
55+
GDExtensionClassGetVirtual2 get_virtual_func,
5656
bint is_virtual,
5757
bint is_abstract,
5858
bint is_exposed,
@@ -65,14 +65,18 @@ cdef inline void register_extension_class_creation(
6565
cdef list specs_list = _get_extension_gc_protector()
6666
specs_list.append(spec)
6767

68-
cdef GDExtensionClassCreationInfo2 info
68+
cdef GDExtensionClassCreationInfo4 info
6969
info.is_virtual = is_virtual
7070
info.is_abstract = is_abstract
7171
info.is_exposed = is_exposed
72+
# info.is_runtime = is_runtime # GDExtensionBool
73+
info.is_runtime = False
74+
# info.icon_path = icon_path # GDExtensionConstStringPtr
75+
info.icon_path = NULL
7276
info.set_func = NULL # GDExtensionClassSet
7377
info.get_func = NULL # GDExtensionClassGet
7478
info.get_property_list_func = NULL # GDExtensionClassGetPropertyList
75-
info.free_property_list_func = NULL # GDExtensionClassFreePropertyList
79+
info.free_property_list_func = NULL # GDExtensionClassFreePropertyList2
7680
info.property_can_revert_func = NULL # GDExtensionClassPropertyCanRevert
7781
info.property_get_revert_func = NULL # GDExtensionClassPropertyGetRevert
7882
info.validate_property_func = NULL # GDExtensionClassValidateProperty
@@ -91,17 +95,16 @@ cdef inline void register_extension_class_creation(
9195
# Returning `NULL` from this function signals to Godot that the virtual function is not overridden.
9296
# Data returned from this function should be managed by the extension and must be valid until the extension is deinitialized.
9397
# You should supply either `get_virtual_func`, or `get_virtual_call_data_func` with `call_virtual_with_data_func`.
94-
info.get_virtual_call_data_func = NULL # GDExtensionClassGetVirtualCallData
98+
info.get_virtual_call_data_func = NULL # GDExtensionClassGetVirtualCallData2
9599
# Used to call virtual functions when `get_virtual_call_data_func` is not null.
96100
info.call_virtual_with_data_func = NULL # GDExtensionClassCallVirtualWithData
97-
info.get_rid_func = NULL # GDExtensionClassGetRID
98101
# Don't increment refcount given we rely on gc protector
99102
info.class_userdata = <void*>spec # void*
100103

101104
cdef gd_string_name_t gdname = gd_string_name_from_utf8_and_len(<char*>class_name, len(class_name))
102105
cdef gd_string_name_t gdname_parent = gd_string_name_from_utf8_and_len(<char*>parent_class_name, len(parent_class_name))
103106
# TODO: correct me once https://github.com/godotengine/godot/pull/67121 is merged
104-
gdptrs.gdptr_classdb_register_extension_class2(
107+
gdptrs.gdptr_classdb_register_extension_class4(
105108
gdptrs.gdptr_library,
106109
&gdname,
107110
&gdname_parent,

0 commit comments

Comments
 (0)