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,15 @@ 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+ bool has_object_instance_binding () const ;
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,18 @@ class Wrapped {
108117 GodotObject *_owner = nullptr ;
109118};
110119
120+ namespace internal {
121+ _ALWAYS_INLINE_ void _set_construct_info (const StringName *p_extension_class_name, const GDExtensionInstanceBindingCallbacks *p_binding_callbacks) {
122+ Wrapped::_constructing_extension_class_name = p_extension_class_name;
123+ Wrapped::_constructing_class_binding_callbacks = p_binding_callbacks;
124+ }
125+ } // namespace internal
126+
127+ template <typename T, std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value, bool > = true >
128+ _ALWAYS_INLINE_ void _pre_initialize () {
129+ internal::_set_construct_info (T::_get_extension_class_name (), &T::_gde_binding_callbacks);
130+ }
131+
111132_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112133}
113134
@@ -162,15 +183,7 @@ private:
162183 friend class ::godot::ClassDB; \
163184 \
164185protected: \
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- \
186+ virtual bool _is_extension_class () const override { return true ; } \
174187 static void (*_get_bind_methods ())() { \
175188 return &m_class::_bind_methods; \
176189 } \
@@ -213,6 +226,11 @@ protected:
213226 } \
214227 \
215228public: \
229+ static const ::godot::StringName *_get_extension_class_name () { \
230+ static ::godot::StringName string_name = get_class_static (); \
231+ return &string_name; \
232+ } \
233+ \
216234 typedef m_class self_type; \
217235 \
218236 static void initialize_class () { \
@@ -383,10 +401,6 @@ private:
383401 void operator =(const m_class &p_rval) {} \
384402 \
385403protected: \
386- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387- return &_gde_binding_callbacks; \
388- } \
389- \
390404 m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391405 m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392406 \
0 commit comments