diff options
author | David Snopek <dsnopek@gmail.com> | 2023-08-04 11:02:57 -0500 |
---|---|---|
committer | David Snopek <dsnopek@gmail.com> | 2023-09-25 22:13:33 -0500 |
commit | df849651d9d71e3b901fe386a6752aec368c7206 (patch) | |
tree | fc6e5fabafb682aeba91c124d7c4beebb5c9c4ef /include/godot_cpp | |
parent | c44c3d5ebf9826214efc971f0cbe047789af2575 (diff) | |
download | redot-cpp-df849651d9d71e3b901fe386a6752aec368c7206.tar.gz |
Changes necessary for hot reload to work
Diffstat (limited to 'include/godot_cpp')
-rw-r--r-- | include/godot_cpp/classes/wrapped.hpp | 24 | ||||
-rw-r--r-- | include/godot_cpp/core/class_db.hpp | 1 |
2 files changed, 25 insertions, 0 deletions
diff --git a/include/godot_cpp/classes/wrapped.hpp b/include/godot_cpp/classes/wrapped.hpp index 91e29eb..879346b 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; @@ -106,6 +115,17 @@ void free_c_property_list(GDExtensionPropertyInfo *plist); } // 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 +213,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()) { \ diff --git a/include/godot_cpp/core/class_db.hpp b/include/godot_cpp/core/class_db.hpp index c974fa4..ef18c6e 100644 --- a/include/godot_cpp/core/class_db.hpp +++ b/include/godot_cpp/core/class_db.hpp @@ -201,6 +201,7 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed) { nullptr, // GDExtensionClassUnreference unreference_func; T::create, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */ T::free, // GDExtensionClassFreeInstance free_instance_func; /* this one is mandatory */ + T::recreate, // GDExtensionClassRecreateInstance recreate_instance_func; &ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func; nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func; nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func; |