Skip to content

Commit 7f5f029

Browse files
committed
Update for GDExtension interface changes in Godot 4.5
1 parent 3afe0d5 commit 7f5f029

File tree

6 files changed

+78
-38
lines changed

6 files changed

+78
-38
lines changed

binding_generator.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,6 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
911911
result.append("\tconst Variant &operator[](int64_t p_index) const;")
912912
result.append("\tVariant &operator[](int64_t p_index);")
913913
result.append("\tvoid set_typed(uint32_t p_type, const StringName &p_class_name, const Variant &p_script);")
914-
result.append("\tvoid _ref(const Array &p_from) const;")
915914
result.append("""
916915
struct Iterator {
917916
_FORCE_INLINE_ Variant &operator*() const;

gdextension/gdextension_interface.h

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,9 @@ typedef struct {
724724

725725
} GDExtensionScriptInstanceInfo3;
726726

727+
typedef void (*GDExtensionWorkerThreadPoolGroupTask)(void *, uint32_t);
728+
typedef void (*GDExtensionWorkerThreadPoolTask)(void *);
729+
727730
/* INITIALIZATION */
728731

729732
typedef enum {
@@ -734,15 +737,18 @@ typedef enum {
734737
GDEXTENSION_MAX_INITIALIZATION_LEVEL,
735738
} GDExtensionInitializationLevel;
736739

740+
typedef void (*GDExtensionInitializeCallback)(void *p_userdata, GDExtensionInitializationLevel p_level);
741+
typedef void (*GDExtensionDeinitializeCallback)(void *p_userdata, GDExtensionInitializationLevel p_level);
742+
737743
typedef struct {
738744
/* Minimum initialization level required.
739745
* If Core or Servers, the extension needs editor or game restart to take effect */
740746
GDExtensionInitializationLevel minimum_initialization_level;
741747
/* Up to the user to supply when initializing */
742748
void *userdata;
743749
/* This function will be called multiple times for each initialization level. */
744-
void (*initialize)(void *userdata, GDExtensionInitializationLevel p_level);
745-
void (*deinitialize)(void *userdata, GDExtensionInitializationLevel p_level);
750+
GDExtensionInitializeCallback initialize;
751+
GDExtensionDeinitializeCallback deinitialize;
746752
} GDExtensionInitialization;
747753

748754
typedef void (*GDExtensionInterfaceFunctionPtr)();
@@ -815,8 +821,12 @@ typedef void (*GDExtensionMainLoopShutdownCallback)();
815821
typedef void (*GDExtensionMainLoopFrameCallback)();
816822

817823
typedef struct {
824+
// Will be called after Godot is started and is fully initialized.
818825
GDExtensionMainLoopStartupCallback startup_func;
826+
// Will be called before Godot is shutdown when it is still fully initialized.
819827
GDExtensionMainLoopShutdownCallback shutdown_func;
828+
// Will be called for each process frame. This will run after all `_process()` methods on Node, and before `ScriptServer::frame()`.
829+
// This is intended to be the equivalent of `ScriptLanguage::frame()` for GDExtension language bindings that don't use the script API.
820830
GDExtensionMainLoopFrameCallback frame_func;
821831
} GDExtensionMainLoopCallbacks;
822832

@@ -1035,7 +1045,7 @@ typedef void (*GDExtensionInterfaceVariantCall)(GDExtensionVariantPtr p_self, GD
10351045
*
10361046
* Calls a static method on a Variant.
10371047
*
1038-
* @param p_self A pointer to the Variant.
1048+
* @param p_type The variant type.
10391049
* @param p_method A pointer to a StringName identifying the method.
10401050
* @param p_args A pointer to a C array of Variant.
10411051
* @param p_argument_count The number of arguments.
@@ -1321,7 +1331,7 @@ typedef GDExtensionVariantType (*GDExtensionInterfaceVariantGetType)(GDExtension
13211331
* @param p_self A pointer to the Variant.
13221332
* @param p_method A pointer to a StringName with the method name.
13231333
*
1324-
* @return
1334+
* @return true if the variant has the given method; otherwise false.
13251335
*/
13261336
typedef GDExtensionBool (*GDExtensionInterfaceVariantHasMethod)(GDExtensionConstVariantPtr p_self, GDExtensionConstStringNamePtr p_method);
13271337

@@ -1334,7 +1344,7 @@ typedef GDExtensionBool (*GDExtensionInterfaceVariantHasMethod)(GDExtensionConst
13341344
* @param p_type The Variant type.
13351345
* @param p_member A pointer to a StringName with the member name.
13361346
*
1337-
* @return
1347+
* @return true if the variant has the given method; otherwise false.
13381348
*/
13391349
typedef GDExtensionBool (*GDExtensionInterfaceVariantHasMember)(GDExtensionVariantType p_type, GDExtensionConstStringNamePtr p_member);
13401350

@@ -1505,7 +1515,7 @@ typedef GDExtensionPtrDestructor (*GDExtensionInterfaceVariantGetPtrDestructor)(
15051515
* Constructs a Variant of the given type, using the first constructor that matches the given arguments.
15061516
*
15071517
* @param p_type The Variant type.
1508-
* @param p_base A pointer to a Variant to store the constructed value.
1518+
* @param r_base A pointer to a Variant to store the constructed value.
15091519
* @param p_args A pointer to a C array of Variant pointers representing the arguments for the constructor.
15101520
* @param p_argument_count The number of arguments to pass to the constructor.
15111521
* @param r_error A pointer the structure which will be updated with error information.
@@ -1728,7 +1738,7 @@ typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf8CharsAndLen2)(GDEx
17281738
*
17291739
* @param r_dest A pointer to a Variant to hold the newly created String.
17301740
* @param p_contents A pointer to a UTF-16 encoded C string.
1731-
* @param p_size The number of characters (not bytes).
1741+
* @param p_char_count The number of characters (not bytes).
17321742
*/
17331743
typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char16_t *p_contents, GDExtensionInt p_char_count);
17341744

@@ -1740,7 +1750,7 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen)(GDExtensionUni
17401750
*
17411751
* @param r_dest A pointer to a Variant to hold the newly created String.
17421752
* @param p_contents A pointer to a UTF-16 encoded C string.
1743-
* @param p_size The number of characters (not bytes).
1753+
* @param p_char_count The number of characters (not bytes).
17441754
* @param p_default_little_endian If true, UTF-16 use little endian.
17451755
*
17461756
* @return Error code signifying if the operation successful.
@@ -1755,7 +1765,7 @@ typedef GDExtensionInt (*GDExtensionInterfaceStringNewWithUtf16CharsAndLen2)(GDE
17551765
*
17561766
* @param r_dest A pointer to a Variant to hold the newly created String.
17571767
* @param p_contents A pointer to a UTF-32 encoded C string.
1758-
* @param p_size The number of characters (not bytes).
1768+
* @param p_char_count The number of characters (not bytes).
17591769
*/
17601770
typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const char32_t *p_contents, GDExtensionInt p_char_count);
17611771

@@ -1767,7 +1777,7 @@ typedef void (*GDExtensionInterfaceStringNewWithUtf32CharsAndLen)(GDExtensionUni
17671777
*
17681778
* @param r_dest A pointer to a Variant to hold the newly created String.
17691779
* @param p_contents A pointer to a wide C string.
1770-
* @param p_size The number of characters (not bytes).
1780+
* @param p_char_count The number of characters (not bytes).
17711781
*/
17721782
typedef void (*GDExtensionInterfaceStringNewWithWideCharsAndLen)(GDExtensionUninitializedStringPtr r_dest, const wchar_t *p_contents, GDExtensionInt p_char_count);
17731783

@@ -2084,6 +2094,7 @@ typedef const uint8_t *(*GDExtensionInterfaceImagePtr)(GDExtensionObjectPtr p_in
20842094
* @param p_instance A pointer to a WorkerThreadPool object.
20852095
* @param p_func A pointer to a function to run in the thread pool.
20862096
* @param p_userdata A pointer to arbitrary data which will be passed to p_func.
2097+
* @param p_elements The number of element needed in the group.
20872098
* @param p_tasks The number of tasks needed in the group.
20882099
* @param p_high_priority Whether or not this is a high priority task.
20892100
* @param p_description A pointer to a String with the task description.
@@ -2092,7 +2103,7 @@ typedef const uint8_t *(*GDExtensionInterfaceImagePtr)(GDExtensionObjectPtr p_in
20922103
*
20932104
* @see WorkerThreadPool::add_group_task()
20942105
*/
2095-
typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask)(GDExtensionObjectPtr p_instance, void (*p_func)(void *, uint32_t), void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
2106+
typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask)(GDExtensionObjectPtr p_instance, GDExtensionWorkerThreadPoolGroupTask p_func, void *p_userdata, int p_elements, int p_tasks, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
20962107

20972108
/**
20982109
* @name worker_thread_pool_add_native_task
@@ -2108,7 +2119,7 @@ typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeGroupTask)(GDExte
21082119
*
21092120
* @return The task ID.
21102121
*/
2111-
typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeTask)(GDExtensionObjectPtr p_instance, void (*p_func)(void *), void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
2122+
typedef int64_t (*GDExtensionInterfaceWorkerThreadPoolAddNativeTask)(GDExtensionObjectPtr p_instance, GDExtensionWorkerThreadPoolTask p_func, void *p_userdata, GDExtensionBool p_high_priority, GDExtensionConstStringPtr p_description);
21122123

21132124
/* INTERFACE: Packed Array */
21142125

@@ -2526,10 +2537,10 @@ typedef GDExtensionObjectPtr (*GDExtensionInterfaceGlobalGetSingleton)(GDExtensi
25262537
* Gets a pointer representing an Object's instance binding.
25272538
*
25282539
* @param p_o A pointer to the Object.
2529-
* @param p_library A token the library received by the GDExtension's entry point function.
2540+
* @param p_token A token the library received by the GDExtension's entry point function.
25302541
* @param p_callbacks A pointer to a GDExtensionInstanceBindingCallbacks struct.
25312542
*
2532-
* @return
2543+
* @return A pointer to the instance binding.
25332544
*/
25342545
typedef void *(*GDExtensionInterfaceObjectGetInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token, const GDExtensionInstanceBindingCallbacks *p_callbacks);
25352546

@@ -2540,7 +2551,7 @@ typedef void *(*GDExtensionInterfaceObjectGetInstanceBinding)(GDExtensionObjectP
25402551
* Sets an Object's instance binding.
25412552
*
25422553
* @param p_o A pointer to the Object.
2543-
* @param p_library A token the library received by the GDExtension's entry point function.
2554+
* @param p_token A token the library received by the GDExtension's entry point function.
25442555
* @param p_binding A pointer to the instance binding.
25452556
* @param p_callbacks A pointer to a GDExtensionInstanceBindingCallbacks struct.
25462557
*/
@@ -2553,7 +2564,7 @@ typedef void (*GDExtensionInterfaceObjectSetInstanceBinding)(GDExtensionObjectPt
25532564
* Free an Object's instance binding.
25542565
*
25552566
* @param p_o A pointer to the Object.
2556-
* @param p_library A token the library received by the GDExtension's entry point function.
2567+
* @param p_token A token the library received by the GDExtension's entry point function.
25572568
*/
25582569
typedef void (*GDExtensionInterfaceObjectFreeInstanceBinding)(GDExtensionObjectPtr p_o, void *p_token);
25592570

@@ -2563,11 +2574,13 @@ typedef void (*GDExtensionInterfaceObjectFreeInstanceBinding)(GDExtensionObjectP
25632574
*
25642575
* Sets an extension class instance on a Object.
25652576
*
2577+
* `p_classname` should be a registered extension class and should extend the `p_o` Object's class.
2578+
*
25662579
* @param p_o A pointer to the Object.
25672580
* @param p_classname A pointer to a StringName with the registered extension class's name.
25682581
* @param p_instance A pointer to the extension class instance.
25692582
*/
2570-
typedef void (*GDExtensionInterfaceObjectSetInstance)(GDExtensionObjectPtr p_o, GDExtensionConstStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance); /* p_classname should be a registered extension class and should extend the p_o object's class. */
2583+
typedef void (*GDExtensionInterfaceObjectSetInstance)(GDExtensionObjectPtr p_o, GDExtensionConstStringNamePtr p_classname, GDExtensionClassInstancePtr p_instance);
25712584

25722585
/**
25732586
* @name object_get_class_name
@@ -2632,7 +2645,7 @@ typedef GDObjectInstanceID (*GDExtensionInterfaceObjectGetInstanceId)(GDExtensio
26322645
* @param p_object A pointer to the Object.
26332646
* @param p_method A pointer to a StringName identifying the method.
26342647
*
2635-
* @returns true if the object has a script and that script has a method with the given name. Returns false if the object has no script.
2648+
* @return true if the object has a script and that script has a method with the given name. Returns false if the object has no script.
26362649
*/
26372650
typedef GDExtensionBool (*GDExtensionInterfaceObjectHasScriptMethod)(GDExtensionConstObjectPtr p_object, GDExtensionConstStringNamePtr p_method);
26382651

@@ -2813,6 +2826,8 @@ typedef void (*GDExtensionInterfaceCallableCustomCreate2)(GDExtensionUninitializ
28132826
*
28142827
* @param p_callable A pointer to a Callable.
28152828
* @param p_token A pointer to an address that uniquely identifies the GDExtension.
2829+
*
2830+
* @return The userdata pointer given when creating this custom Callable.
28162831
*/
28172832
typedef void *(*GDExtensionInterfaceCallableCustomGetUserData)(GDExtensionConstTypePtr p_callable, void *p_token);
28182833

@@ -3068,10 +3083,12 @@ typedef void (*GDExtensionInterfaceClassdbRegisterExtensionClassSignal)(GDExtens
30683083
*
30693084
* Unregisters an extension class in the ClassDB.
30703085
*
3086+
* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first.
3087+
*
30713088
* @param p_library A pointer the library received by the GDExtension's entry point function.
30723089
* @param p_class_name A pointer to a StringName with the class name.
30733090
*/
3074-
typedef void (*GDExtensionInterfaceClassdbUnregisterExtensionClass)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name); /* Unregistering a parent class before a class that inherits it will result in failure. Inheritors must be unregistered first. */
3091+
typedef void (*GDExtensionInterfaceClassdbUnregisterExtensionClass)(GDExtensionClassLibraryPtr p_library, GDExtensionConstStringNamePtr p_class_name);
30753092

30763093
/**
30773094
* @name get_library_path
@@ -3154,7 +3171,7 @@ typedef void (*GDExtensionInterfaceEditorRegisterGetClassesUsedCallback)(GDExten
31543171
* Registers callbacks to be called at different phases of the main loop.
31553172
*
31563173
* @param p_library A pointer the library received by the GDExtension's entry point function.
3157-
* @param p_callback A pointer to the structure that contains the callbacks.
3174+
* @param p_callbacks A pointer to the structure that contains the callbacks.
31583175
*/
31593176
typedef void (*GDExtensionInterfaceRegisterMainLoopCallbacks)(GDExtensionClassLibraryPtr p_library, const GDExtensionMainLoopCallbacks *p_callbacks);
31603177

include/godot_cpp/godot.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ extern "C" GDExtensionInterfaceGetProcAddress gdextension_interface_get_proc_add
4040
extern "C" GDExtensionClassLibraryPtr library;
4141
extern "C" void *token;
4242

43-
extern "C" GDExtensionGodotVersion godot_version;
43+
extern "C" GDExtensionGodotVersion2 godot_version;
4444

4545
// All of the GDExtension interface functions.
46-
extern "C" GDExtensionInterfaceGetGodotVersion gdextension_interface_get_godot_version;
46+
extern "C" GDExtensionInterfaceGetGodotVersion2 gdextension_interface_get_godot_version2;
4747
extern "C" GDExtensionInterfaceMemAlloc gdextension_interface_mem_alloc;
4848
extern "C" GDExtensionInterfaceMemRealloc gdextension_interface_mem_realloc;
4949
extern "C" GDExtensionInterfaceMemFree gdextension_interface_mem_free;
@@ -155,7 +155,6 @@ extern "C" GDExtensionInterfacePackedVector4ArrayOperatorIndex gdextension_inter
155155
extern "C" GDExtensionInterfacePackedVector4ArrayOperatorIndexConst gdextension_interface_packed_vector4_array_operator_index_const;
156156
extern "C" GDExtensionInterfaceArrayOperatorIndex gdextension_interface_array_operator_index;
157157
extern "C" GDExtensionInterfaceArrayOperatorIndexConst gdextension_interface_array_operator_index_const;
158-
extern "C" GDExtensionInterfaceArrayRef gdextension_interface_array_ref;
159158
extern "C" GDExtensionInterfaceArraySetTyped gdextension_interface_array_set_typed;
160159
extern "C" GDExtensionInterfaceDictionaryOperatorIndex gdextension_interface_dictionary_operator_index;
161160
extern "C" GDExtensionInterfaceDictionaryOperatorIndexConst gdextension_interface_dictionary_operator_index_const;
@@ -204,6 +203,7 @@ extern "C" GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8Chars gdextension_inter
204203
extern "C" GDExtensionsInterfaceEditorHelpLoadXmlFromUtf8CharsAndLen gdextension_interface_editor_help_load_xml_from_utf8_chars_and_len;
205204
extern "C" GDExtensionInterfaceImagePtrw gdextension_interface_image_ptrw;
206205
extern "C" GDExtensionInterfaceImagePtr gdextension_interface_image_ptr;
206+
extern "C" GDExtensionInterfaceRegisterMainLoopCallbacks gdextension_interface_register_main_loop_callbacks;
207207

208208
class DocDataRegistration {
209209
public:
@@ -228,6 +228,11 @@ class GDExtensionBinding {
228228
GDExtensionInitializationLevel minimum_initialization_level = GDEXTENSION_INITIALIZATION_CORE;
229229
Callback init_callback = nullptr;
230230
Callback terminate_callback = nullptr;
231+
GDExtensionMainLoopCallbacks main_loop_callbacks = {};
232+
233+
inline bool has_main_loop_callbacks() const {
234+
return main_loop_callbacks.frame_func || main_loop_callbacks.startup_func || main_loop_callbacks.shutdown_func;
235+
}
231236
};
232237

233238
class InitDataList {
@@ -262,6 +267,13 @@ class GDExtensionBinding {
262267
void register_terminator(Callback p_init) const;
263268
void set_minimum_library_initialization_level(ModuleInitializationLevel p_level) const;
264269

270+
// Register a callback that is called after all initialization levels when Godot is fully initialized.
271+
void register_startup_callback(GDExtensionMainLoopStartupCallback p_callback) const;
272+
// Register a callback that is called for every process frame. This will run after all `_process()` methods on Node, and before `ScriptServer::frame()`.
273+
void register_frame_callback(GDExtensionMainLoopFrameCallback p_callback) const;
274+
// Register a callback that is called before Godot is shutdown when it is still fully initialized.
275+
void register_shutdown_callback(GDExtensionMainLoopShutdownCallback p_callback) const;
276+
265277
GDExtensionBool init() const;
266278
};
267279
};

include/godot_cpp/variant/typed_array.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class TypedArray : public Array {
4040
public:
4141
_FORCE_INLINE_ void operator=(const Array &p_array) {
4242
ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type.");
43-
_ref(p_array);
43+
Array::operator=(p_array);
4444
}
4545
_FORCE_INLINE_ TypedArray(const Variant &p_variant) :
4646
TypedArray(Array(p_variant)) {
4747
}
4848
_FORCE_INLINE_ TypedArray(const Array &p_array) {
4949
set_typed(Variant::OBJECT, T::get_class_static(), Variant());
5050
if (is_same_typed(p_array)) {
51-
_ref(p_array);
51+
Array::operator=(p_array);
5252
} else {
5353
assign(p_array);
5454
}
@@ -68,7 +68,7 @@ class TypedArray : public Array {
6868
public: \
6969
_FORCE_INLINE_ void operator=(const Array &p_array) { \
7070
ERR_FAIL_COND_MSG(!is_same_typed(p_array), "Cannot assign an array with a different element type."); \
71-
_ref(p_array); \
71+
Array::operator=(p_array); \
7272
} \
7373
_FORCE_INLINE_ TypedArray(std::initializer_list<Variant> p_init) : \
7474
Array(Array(p_init), m_variant_type, StringName(), Variant()) { \
@@ -79,7 +79,7 @@ class TypedArray : public Array {
7979
_FORCE_INLINE_ TypedArray(const Array &p_array) { \
8080
set_typed(m_variant_type, StringName(), Variant()); \
8181
if (is_same_typed(p_array)) { \
82-
_ref(p_array); \
82+
Array::operator=(p_array); \
8383
} else { \
8484
assign(p_array); \
8585
} \

0 commit comments

Comments
 (0)