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,16 @@ 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
+
62
+ void _initialize ();
63
+
55
64
protected:
65
+ virtual bool _is_extension_class () const { return false ; }
66
+
56
67
#ifdef HOT_RELOAD_ENABLED
57
68
struct RecreateInstance {
58
69
GDExtensionClassInstancePtr wrapper;
@@ -62,9 +73,6 @@ class Wrapped {
62
73
inline static RecreateInstance *recreate_instance = nullptr ;
63
74
#endif
64
75
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
76
void _notification (int p_what) {}
69
77
bool _set (const StringName &p_name, const Variant &p_property) { return false ; }
70
78
bool _get (const StringName &p_name, Variant &r_property) const { return false ; }
@@ -95,6 +103,8 @@ class Wrapped {
95
103
virtual ~Wrapped () {}
96
104
97
105
public:
106
+ 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.
107
+
98
108
static StringName &get_class_static () {
99
109
static StringName string_name = StringName (" Wrapped" );
100
110
return string_name;
@@ -108,6 +118,18 @@ class Wrapped {
108
118
GodotObject *_owner = nullptr ;
109
119
};
110
120
121
+ namespace internal {
122
+ _ALWAYS_INLINE_ void _set_construct_info (const StringName *p_extension_class_name, const GDExtensionInstanceBindingCallbacks *p_binding_callbacks) {
123
+ Wrapped::_constructing_extension_class_name = p_extension_class_name;
124
+ Wrapped::_constructing_class_binding_callbacks = p_binding_callbacks;
125
+ }
126
+ } // namespace internal
127
+
128
+ template <typename T, typename std::enable_if_t <std::is_base_of<::godot::Wrapped, T>::value> *_dummy>
129
+ _ALWAYS_INLINE_ void _pre_initialize () {
130
+ internal::_set_construct_info (T::_get_extension_class_name (), &T::_gde_binding_callbacks);
131
+ }
132
+
111
133
_FORCE_INLINE_ void snarray_add_str (Vector<StringName> &arr) {
112
134
}
113
135
@@ -162,15 +184,7 @@ private:
162
184
friend class ::godot::ClassDB; \
163
185
\
164
186
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
- \
187
+ virtual bool _is_extension_class () const override { return true ; } \
174
188
static void (*_get_bind_methods ())() { \
175
189
return &m_class::_bind_methods; \
176
190
} \
@@ -213,6 +227,11 @@ protected:
213
227
} \
214
228
\
215
229
public: \
230
+ static const ::godot::StringName *_get_extension_class_name () { \
231
+ static ::godot::StringName string_name = get_class_static (); \
232
+ return &string_name; \
233
+ } \
234
+ \
216
235
typedef m_class self_type; \
217
236
\
218
237
static void initialize_class () { \
@@ -383,10 +402,6 @@ private:
383
402
void operator =(const m_class &p_rval) {} \
384
403
\
385
404
protected: \
386
- virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const override { \
387
- return &_gde_binding_callbacks; \
388
- } \
389
- \
390
405
m_class (const char *p_godot_class) : m_inherits(p_godot_class) {} \
391
406
m_class (GodotObject *p_godot_object) : m_inherits(p_godot_object) {} \
392
407
\
0 commit comments