@@ -51,6 +51,15 @@ class Wrapped {
5151friend void postinitialize_handler (Wrapped *);
5252
5353protected:
54+ #ifdef HOT_RELOAD_ENABLED
55+ struct RecreateInstance {
56+ GDExtensionClassInstancePtr wrapper;
57+ GDExtensionObjectPtr owner;
58+ RecreateInstance *next;
59+ };
60+ inline static RecreateInstance *recreate_instance = nullptr ;
61+ #endif
62+
5463virtual 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.
5564virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks () const = 0;
5665
@@ -104,6 +113,17 @@ void free_c_property_list(GDExtensionPropertyInfo *plist);
104113
105114} // namespace godot
106115
116+ #ifdef HOT_RELOAD_ENABLED
117+ #define _GDCLASS_RECREATE (m_class, m_inherits ) \
118+ m_class *new_instance = (m_class *)memalloc(sizeof (m_class)); \
119+ Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; \
120+ Wrapped::recreate_instance = &recreate_data; \
121+ memnew_placement (new_instance, m_class); \
122+ return new_instance;
123+ #else
124+ #define _GDCLASS_RECREATE (m_class, m_inherits ) return nullptr ;
125+ #endif
126+
107127// Use this on top of your own classes.
108128// Note: the trail of `***` is to keep sane diffs in PRs, because clang-format otherwise moves every `\` which makes
109129// every line of the macro different
@@ -187,6 +207,10 @@ public:
187207return new_object->_owner ; \
188208} \
189209 \
210+ static GDExtensionClassInstancePtr recreate (void *data, GDExtensionObjectPtr obj) { \
211+ _GDCLASS_RECREATE (m_class, m_inherits); \
212+ } \
213+ \
190214static void notification_bind (GDExtensionClassInstancePtr p_instance, int32_t p_what) { \
191215if (p_instance && m_class::_get_notification ()) { \
192216if (m_class::_get_notification () != m_inherits::_get_notification ()) { \
0 commit comments