diff options
Diffstat (limited to 'include/godot_cpp/classes/wrapped.hpp')
-rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 0ffd783..0c02d15 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -40,6 +40,14 @@ #include <godot_cpp/godot.hpp> +#if defined(MACOS_ENABLED) && defined(HOT_RELOAD_ENABLED) +#include <mutex> +#define _GODOT_CPP_AVOID_THREAD_LOCAL +#define _GODOT_CPP_THREAD_LOCAL +#else +#define _GODOT_CPP_THREAD_LOCAL thread_local +#endif + namespace godot { class ClassDB; @@ -58,8 +66,16 @@ class Wrapped { template <typename T, std::enable_if_t<std::is_base_of<::godot::Wrapped, T>::value, bool>> friend _ALWAYS_INLINE_ void _pre_initialize(); - thread_local static const StringName *_constructing_extension_class_name; - thread_local static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks; +#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL + static std::recursive_mutex _constructing_mutex; +#endif + + _GODOT_CPP_THREAD_LOCAL static const StringName *_constructing_extension_class_name; + _GODOT_CPP_THREAD_LOCAL static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks; + +#ifdef HOT_RELOAD_ENABLED + _GODOT_CPP_THREAD_LOCAL static GDExtensionObjectPtr _constructing_recreate_owner; +#endif template <typename T> _ALWAYS_INLINE_ static void _set_construct_info() { @@ -71,15 +87,6 @@ protected: virtual bool _is_extension_class() const { return false; } static const StringName *_get_extension_class_name(); // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned. -#ifdef HOT_RELOAD_ENABLED - struct RecreateInstance { - GDExtensionClassInstancePtr wrapper; - GDExtensionObjectPtr owner; - RecreateInstance *next; - }; - inline static RecreateInstance *recreate_instance = nullptr; -#endif - void _notification(int p_what) {} bool _set(const StringName &p_name, const Variant &p_property) { return false; } bool _get(const StringName &p_name, Variant &r_property) const { return false; } @@ -104,7 +111,6 @@ protected: ::godot::List<::godot::PropertyInfo> plist_owned; void _postinitialize(); - virtual void _notificationv(int32_t p_what, bool p_reversed = false) {} Wrapped(const StringName p_godot_class); Wrapped(GodotObject *p_godot_object); @@ -126,6 +132,9 @@ public: template <typename T, std::enable_if_t<std::is_base_of<::godot::Wrapped, T>::value, bool>> _ALWAYS_INLINE_ void _pre_initialize() { +#ifdef _GODOT_CPP_AVOID_THREAD_LOCAL + Wrapped::_constructing_mutex.lock(); +#endif Wrapped::_set_construct_info<T>(); } @@ -250,7 +259,7 @@ public: } \ \ static const ::godot::StringName &get_class_static() { \ - static const ::godot::StringName string_name = ::godot::StringName(#m_class); \ + static const ::godot::StringName string_name = ::godot::StringName(U## #m_class); \ return string_name; \ } \ \ @@ -398,11 +407,6 @@ public: _gde_binding_reference_callback, \ }; \ \ -protected: \ - virtual void _notificationv(int32_t p_what, bool p_reversed = false) override { \ - m_class::notification_bind(this, p_what, p_reversed); \ - } \ - \ private: // Don't use this for your classes, use GDCLASS() instead. |