diff options
Diffstat (limited to 'src/classes/wrapped.cpp')
-rw-r--r-- | src/classes/wrapped.cpp | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/classes/wrapped.cpp b/src/classes/wrapped.cpp index ffca4f9..e729ba0 100644 --- a/src/classes/wrapped.cpp +++ b/src/classes/wrapped.cpp @@ -39,41 +39,43 @@ #include <godot_cpp/core/class_db.hpp> namespace godot { -thread_local const StringName *Wrapped::_constructing_extension_class_name = nullptr; -thread_local const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr; + +#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL +std::recursive_mutex Wrapped::_constructing_mutex; +#endif + +_GODOT_CPP_THREAD_LOCAL const StringName *Wrapped::_constructing_extension_class_name = nullptr; +_GODOT_CPP_THREAD_LOCAL const GDExtensionInstanceBindingCallbacks *Wrapped::_constructing_class_binding_callbacks = nullptr; + +#ifdef HOT_RELOAD_ENABLED +_GODOT_CPP_THREAD_LOCAL GDExtensionObjectPtr Wrapped::_constructing_recreate_owner = nullptr; +#endif const StringName *Wrapped::_get_extension_class_name() { return nullptr; } void Wrapped::_postinitialize() { - // Only send NOTIFICATION_POSTINITIALIZE for extension classes. - if (_is_extension_class()) { - _notificationv(Object::NOTIFICATION_POSTINITIALIZE); +#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL + Wrapped::_constructing_mutex.unlock(); +#endif + + Object *obj = dynamic_cast<Object *>(this); + if (obj) { + obj->notification(Object::NOTIFICATION_POSTINITIALIZE); } } Wrapped::Wrapped(const StringName p_godot_class) { #ifdef HOT_RELOAD_ENABLED - if (unlikely(Wrapped::recreate_instance)) { - RecreateInstance *recreate_data = Wrapped::recreate_instance; - RecreateInstance *previous = nullptr; - while (recreate_data) { - if (recreate_data->wrapper == this) { - _owner = recreate_data->owner; - if (previous) { - previous->next = recreate_data->next; - } else { - Wrapped::recreate_instance = recreate_data->next; - } - return; - } - previous = recreate_data; - recreate_data = recreate_data->next; - } - } + if (unlikely(Wrapped::_constructing_recreate_owner)) { + _owner = Wrapped::_constructing_recreate_owner; + Wrapped::_constructing_recreate_owner = nullptr; + } else #endif - _owner = godot::internal::gdextension_interface_classdb_construct_object(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr())); + { + _owner = godot::internal::gdextension_interface_classdb_construct_object2(reinterpret_cast<GDExtensionConstStringNamePtr>(p_godot_class._native_ptr())); + } if (_constructing_extension_class_name) { godot::internal::gdextension_interface_object_set_instance(_owner, reinterpret_cast<GDExtensionConstStringNamePtr>(_constructing_extension_class_name), this); |