@@ -52,7 +52,17 @@ class Wrapped {
52
52
friend class ClassDB ;
53
53
friend void postinitialize_handler (Wrapped *);
54
54
55
+ template <typename T, std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value, bool >>
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
+
55
63
protected:
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,12 @@ class Wrapped {
108
117
GodotObject *_owner = nullptr ;
109
118
};
110
119
120
+ template <typename T, std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value, bool > = true >
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
+
111
126
_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112
127
}
113
128
@@ -162,15 +177,7 @@ private:
162
177
friend class ::godot::ClassDB; \
163
178
\
164
179
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
- \
180
+ virtual bool _is_extension_class () const override { return true ; } \
174
181
static void (*_get_bind_methods ())() { \
175
182
return &m_class::_bind_methods; \
176
183
} \
@@ -213,6 +220,11 @@ protected:
213
220
} \
214
221
\
215
222
public: \
223
+ static const ::godot::StringName *_get_extension_class_name () { \
224
+ static ::godot::StringName string_name = get_class_static (); \
225
+ return &string_name; \
226
+ } \
227
+ \
216
228
typedef m_class self_type; \
217
229
\
218
230
static void initialize_class () { \
@@ -383,10 +395,6 @@ private:
383
395
void operator =(const m_class &p_rval) {} \
384
396
\
385
397
protected: \
386
- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387
- return &_gde_binding_callbacks; \
388
- } \
389
- \
390
398
m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391
399
m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392
400
\
0 commit comments