diff options
Diffstat (limited to 'include/godot_cpp/classes/wrapped.hpp')
-rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 91e29eb..2bbffc0 100644 --- a/include/godot_cpp/classes/wrapped.hpp +++ b/include/godot_cpp/classes/wrapped.hpp @@ -51,6 +51,15 @@ class Wrapped { friend void postinitialize_handler(Wrapped *); protected: +#ifdef HOT_RELOAD_ENABLED + struct RecreateInstance { + GDExtensionClassInstancePtr wrapper; + GDExtensionObjectPtr owner; + RecreateInstance *next; + }; + inline static RecreateInstance *recreate_instance = nullptr; +#endif + 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. virtual const GDExtensionInstanceBindingCallbacks *_get_bindings_callbacks() const = 0; @@ -102,10 +111,37 @@ namespace internal { GDExtensionPropertyInfo *create_c_property_list(const ::godot::List<::godot::PropertyInfo> &plist_cpp, uint32_t *r_size); void free_c_property_list(GDExtensionPropertyInfo *plist); +typedef void (*EngineClassRegistrationCallback)(); +void add_engine_class_registration_callback(EngineClassRegistrationCallback p_callback); +void register_engine_class(const StringName &p_name, const GDExtensionInstanceBindingCallbacks *p_callbacks); +void register_engine_classes(); + +template <class T> +struct EngineClassRegistration { + EngineClassRegistration() { + add_engine_class_registration_callback(&EngineClassRegistration<T>::callback); + } + + static void callback() { + register_engine_class(T::get_class_static(), &T::_gde_binding_callbacks); + } +}; + } // namespace internal } // namespace godot +#ifdef HOT_RELOAD_ENABLED +#define _GDCLASS_RECREATE(m_class, m_inherits) \ + m_class *new_instance = (m_class *)memalloc(sizeof(m_class)); \ + Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; \ + Wrapped::recreate_instance = &recreate_data; \ + memnew_placement(new_instance, m_class); \ + return new_instance; +#else +#define _GDCLASS_RECREATE(m_class, m_inherits) return nullptr; +#endif + // Use this on top of your own classes. // Note: the trail of `***` is to keep sane diffs in PRs, because clang-format otherwise moves every `\` which makes // every line of the macro different @@ -193,6 +229,10 @@ public: return new_object->_owner; \ } \ \ + static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \ + _GDCLASS_RECREATE(m_class, m_inherits); \ + } \ + \ static void notification_bind(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) { \ if (p_instance && m_class::_get_notification()) { \ if (m_class::_get_notification() != m_inherits::_get_notification()) { \ @@ -328,6 +368,7 @@ public: // Don't use this for your classes, use GDCLASS() instead. #define GDEXTENSION_CLASS_ALIAS(m_class, m_alias_for, m_inherits) \ private: \ + inline static ::godot::internal::EngineClassRegistration<m_class> _gde_engine_class_registration_helper; \ void operator=(const m_class &p_rval) {} \ \ protected: \ |