41
41
#include < godot_cpp/godot.hpp>
42
42
43
43
namespace 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
45
47
class ClassDB ;
46
48
47
49
typedef void GodotObject;
@@ -52,7 +54,15 @@ class Wrapped {
52
54
friend class ClassDB ;
53
55
friend void postinitialize_handler (Wrapped *);
54
56
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
+
55
62
protected:
63
+ bool has_object_instance_binding () const ;
64
+ virtual bool _is_extension_class () const { return false ; }
65
+
56
66
#ifdef HOT_RELOAD_ENABLED
57
67
struct RecreateInstance {
58
68
GDExtensionClassInstancePtr wrapper;
@@ -62,9 +72,6 @@ class Wrapped {
62
72
inline static RecreateInstance *recreate_instance = nullptr ;
63
73
#endif
64
74
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
-
68
75
void _notification (int p_what) {}
69
76
bool _set (const StringName &p_name, const Variant &p_property) { return false ; }
70
77
bool _get (const StringName &p_name, Variant &r_property) const { return false ; }
@@ -95,6 +102,8 @@ class Wrapped {
95
102
virtual ~Wrapped () {}
96
103
97
104
public:
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
+
98
107
static StringName &get_class_static () {
99
108
static StringName string_name = StringName (" Wrapped" );
100
109
return string_name;
@@ -108,6 +117,18 @@ class Wrapped {
108
117
GodotObject *_owner = nullptr ;
109
118
};
110
119
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
+
111
132
_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112
133
}
113
134
@@ -162,15 +183,7 @@ private:
162
183
friend class ::godot::ClassDB; \
163
184
\
164
185
protected: \
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 ; } \
174
187
static void (*_get_bind_methods ())() { \
175
188
return &m_class::_bind_methods; \
176
189
} \
@@ -213,6 +226,11 @@ protected:
213
226
} \
214
227
\
215
228
public: \
229
+ static const ::godot::StringName *_get_extension_class_name () { \
230
+ static ::godot::StringName string_name = get_class_static (); \
231
+ return &string_name; \
232
+ } \
233
+ \
216
234
typedef m_class self_type; \
217
235
\
218
236
static void initialize_class () { \
@@ -383,10 +401,6 @@ private:
383
401
void operator =(const m_class &p_rval) {} \
384
402
\
385
403
protected: \
386
- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387
- return &_gde_binding_callbacks; \
388
- } \
389
- \
390
404
m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391
405
m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392
406
\
0 commit comments