4141#include < godot_cpp/godot.hpp>
4242
4343namespace godot {
44-
44+ namespace internal {
45+ _ALWAYS_INLINE_ void _set_construct_info (const StringName *p_extension_class_name, const GDExtensionInstanceBindingCallbacks *p_binding_callbacks);
46+ } // namespace internal
4547class ClassDB ;
4648
4749typedef void GodotObject;
@@ -52,7 +54,14 @@ class Wrapped {
5254 friend class ClassDB ;
5355 friend void postinitialize_handler (Wrapped *);
5456
57+ friend _ALWAYS_INLINE_ void internal::_set_construct_info (const StringName *p_extension_class_name, const GDExtensionInstanceBindingCallbacks *p_binding_callbacks);
58+
59+ thread_local static const StringName *_constructing_extension_class_name;
60+ thread_local static const GDExtensionInstanceBindingCallbacks *_constructing_class_binding_callbacks;
61+
5562protected:
63+ virtual bool _is_extension_class () const { return false ; }
64+
5665#ifdef HOT_RELOAD_ENABLED
5766 struct RecreateInstance {
5867 GDExtensionClassInstancePtr wrapper;
@@ -62,9 +71,6 @@ class Wrapped {
6271 inline static RecreateInstance *recreate_instance = nullptr ;
6372#endif
6473
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-
6874 void _notification (int p_what) {}
6975 bool _set (const StringName &p_name, const Variant &p_property) { return false ; }
7076 bool _get (const StringName &p_name, Variant &r_property) const { return false ; }
@@ -95,6 +101,8 @@ class Wrapped {
95101 virtual ~Wrapped () {}
96102
97103public:
104+ 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.
105+
98106 static StringName &get_class_static () {
99107 static StringName string_name = StringName (" Wrapped" );
100108 return string_name;
@@ -108,6 +116,18 @@ class Wrapped {
108116 GodotObject *_owner = nullptr ;
109117};
110118
119+ namespace internal {
120+ _ALWAYS_INLINE_ void _set_construct_info (const StringName *p_extension_class_name, const GDExtensionInstanceBindingCallbacks *p_binding_callbacks) {
121+ Wrapped::_constructing_extension_class_name = p_extension_class_name;
122+ Wrapped::_constructing_class_binding_callbacks = p_binding_callbacks;
123+ }
124+ } // namespace internal
125+
126+ template <typename T, std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value, bool > = true >
127+ _ALWAYS_INLINE_ void _pre_initialize () {
128+ internal::_set_construct_info (T::_get_extension_class_name (), &T::_gde_binding_callbacks);
129+ }
130+
111131_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112132}
113133
@@ -162,15 +182,7 @@ private:
162182 friend class ::godot::ClassDB; \
163183 \
164184protected: \
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- \
185+ virtual bool _is_extension_class () const override { return true ; } \
174186 static void (*_get_bind_methods ())() { \
175187 return &m_class::_bind_methods; \
176188 } \
@@ -213,6 +225,11 @@ protected:
213225 } \
214226 \
215227public: \
228+ static const ::godot::StringName *_get_extension_class_name () { \
229+ const ::godot::StringName &string_name = get_class_static (); \
230+ return &string_name; \
231+ } \
232+ \
216233 typedef m_class self_type; \
217234 \
218235 static void initialize_class () { \
@@ -383,10 +400,6 @@ private:
383400 void operator =(const m_class &p_rval) {} \
384401 \
385402protected: \
386- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387- return &_gde_binding_callbacks; \
388- } \
389- \
390403 m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391404 m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392405 \
0 commit comments