Make extension instances create the corresponding godot object in their constructor

This commit is contained in:
Gilles Roudière
2021-11-30 14:00:13 +01:00
parent 50512f0dee
commit 3fcb8a4d1e
9 changed files with 197 additions and 180 deletions

View File

@@ -158,9 +158,8 @@ void ClassDB::register_class() {
nullptr, // GDNativeExtensionClassUnreference
T::create, // GDNativeExtensionClassCreateInstance create_instance_func; /* this one is mandatory */
T::free, // GDNativeExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
T::set_object_instance, // GDNativeExtensionClassObjectInstance object_instance_func; /* this one is mandatory */
&ClassDB::get_virtual_func, // GDNativeExtensionClassGetVirtual get_virtual_func;
(void *)cl.name, //void *class_userdata;
(void *)cl.name, // void *class_userdata;
};
internal::gdn_interface->classdb_register_extension_class(internal::library, cl.name, cl.parent_name, &class_info);

View File

@@ -68,16 +68,17 @@ public:
static void free_static(void *p_ptr);
};
#define memnew(m_v) \
([&]() { \
if constexpr (std::is_base_of<godot::Object, decltype(m_v)>::value) { \
return godot::internal::Creator<decltype(m_v)>::_new(); \
} else { \
return new ("") m_v; \
} \
}())
_ALWAYS_INLINE_ void postinitialize_handler(void *) {}
#define memnew_placement(m_placement, m_class) (new (m_placement, sizeof(m_class), "") m_class)
template <class T>
_ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
postinitialize_handler(p_obj);
return p_obj;
}
#define memnew(m_class) _post_initialize(new ("") m_class)
#define memnew_placement(m_placement, m_class) _post_initialize(new (m_placement, sizeof(m_class), "") m_class)
template <class T>
void memdelete(T *p_class, typename std::enable_if<!std::is_base_of_v<godot::Wrapped, T>>::type * = 0) {