@@ -52,7 +52,17 @@ class Wrapped {
5252 friend class ClassDB ;
5353 friend void postinitialize_handler (Wrapped *);
5454
55+ template <typename T, typename std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value> *_dummy>
56+ friend _ALWAYS_INLINE_ void _pre_initialize ();
57+
58+ thread_local static const StringName *constructing_extension_class_name;
59+ thread_local static const GDExtensionInstanceBindingCallbacks *constructing_extension_class_binds_callbacks;
60+
61+ void _initialize ();
62+
5563protected:
64+ virtual bool _is_extension_class () const { return false ; }
65+
5666#ifdef HOT_RELOAD_ENABLED
5767 struct RecreateInstance {
5868 GDExtensionClassInstancePtr wrapper;
@@ -62,9 +72,6 @@ class Wrapped {
6272 inline static RecreateInstance *recreate_instance = nullptr ;
6373#endif
6474
65- virtual const StringName *_get_extension_class_name () const ; // This is needed to retrieve the class name before the godot object has its _extension and _extension_instance members assigned.
66- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const = 0;
67-
6875 void _notification (int p_what) {}
6976 bool _set (const StringName &p_name, const Variant &p_property) { return false ; }
7077 bool _get (const StringName &p_name, Variant &r_property) const { return false ; }
@@ -95,6 +102,8 @@ class Wrapped {
95102 virtual ~Wrapped () {}
96103
97104public:
105+ 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.
106+
98107 static StringName &get_class_static () {
99108 static StringName string_name = StringName (" Wrapped" );
100109 return string_name;
@@ -108,6 +117,12 @@ class Wrapped {
108117 GodotObject *_owner = nullptr ;
109118};
110119
120+ template <typename T, typename std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value> *_dummy>
121+ _ALWAYS_INLINE_ void _pre_initialize () {
122+ Wrapped::constructing_extension_class_name = T::_get_extension_class_name ();
123+ Wrapped::constructing_extension_class_binds_callbacks = &T::_gde_binding_callbacks;
124+ }
125+
111126_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112127}
113128
@@ -162,15 +177,7 @@ private:
162177 friend class ::godot::ClassDB; \
163178 \
164179protected: \
165- virtual const ::godot::StringName *_get_extension_class_name () const override { \
166- static ::godot::StringName string_name = get_class_static (); \
167- return &string_name; \
168- } \
169- \
170- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
171- return &_gde_binding_callbacks; \
172- } \
173- \
180+ virtual bool _is_extension_class () const override { return true ; } \
174181 static void (*_get_bind_methods ())() { \
175182 return &m_class::_bind_methods; \
176183 } \
@@ -213,6 +220,11 @@ protected:
213220 } \
214221 \
215222public: \
223+ static const ::godot::StringName *_get_extension_class_name () { \
224+ static ::godot::StringName string_name = get_class_static (); \
225+ return &string_name; \
226+ } \
227+ \
216228 typedef m_class self_type; \
217229 \
218230 static void initialize_class () { \
@@ -383,10 +395,6 @@ private:
383395 void operator =(const m_class &p_rval) {} \
384396 \
385397protected: \
386- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387- return &_gde_binding_callbacks; \
388- } \
389- \
390398 m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391399 m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392400 \
0 commit comments