diff options
Diffstat (limited to 'include/godot_cpp/core')
-rw-r--r-- | include/godot_cpp/core/class_db.hpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index 988277b..6edb324 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -116,9 +116,13 @@ private: static void _register_class(bool p_virtual = false, bool p_exposed = true, bool p_runtime = false); template <typename T> - static GDExtensionObjectPtr _create_instance_func(void *data) { + static GDExtensionObjectPtr _create_instance_func(void *data, GDExtensionBool p_notify_postinitialize) { if constexpr (!std::is_abstract_v<T>) { - T *new_object = memnew(T); + Wrapped::_set_construct_info<T>(); + T *new_object = new ("", "") T; + if (p_notify_postinitialize) { + new_object->_postinitialize(); + } return new_object->_owner; } else { return nullptr; @@ -129,9 +133,11 @@ private: static GDExtensionClassInstancePtr _recreate_instance_func(void *data, GDExtensionObjectPtr obj) { if constexpr (!std::is_abstract_v<T>) { #ifdef HOT_RELOAD_ENABLED +#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL + std::lock_guard<std::recursive_mutex> lk(Wrapped::_constructing_mutex); +#endif + Wrapped::_constructing_recreate_owner = obj; T *new_instance = (T *)memalloc(sizeof(T)); - Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; - Wrapped::recreate_instance = &recreate_data; memnew_placement(new_instance, T); return new_instance; #else @@ -239,7 +245,7 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) { class_register_order.push_back(cl.name); // Register this class with Godot - GDExtensionClassCreationInfo3 class_info = { + GDExtensionClassCreationInfo4 class_info = { p_virtual, // GDExtensionBool is_virtual; is_abstract, // GDExtensionBool is_abstract; p_exposed, // GDExtensionBool is_exposed; @@ -261,11 +267,10 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed, bool p_runtime) { &ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func; nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func; nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func; - nullptr, // GDExtensionClassGetRID get_rid; (void *)&T::get_class_static(), // void *class_userdata; }; - internal::gdextension_interface_classdb_register_extension_class3(internal::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info); + internal::gdextension_interface_classdb_register_extension_class4(internal::library, cl.name._native_ptr(), cl.parent_name._native_ptr(), &class_info); // call bind_methods etc. to register all members of the class T::initialize_class(); |