Use GDType for GDExtension types as well.

Co-authored-by: David Snopek <dsnopek@gmail.com>
This commit is contained in:
Lukas Tenbrink 2025-10-06 22:35:40 +02:00
parent 2ecefada8d
commit aa33b53e67
6 changed files with 78 additions and 30 deletions

View file

@ -230,6 +230,25 @@ Object::Connection::operator Variant() const {
return d;
}
void ObjectGDExtension::create_gdtype() {
ERR_FAIL_COND(gdtype);
gdtype = memnew(GDType(ClassDB::get_gdtype(parent_class_name), class_name));
}
void ObjectGDExtension::destroy_gdtype() {
ERR_FAIL_COND(!gdtype);
memdelete(const_cast<GDType *>(gdtype));
gdtype = nullptr;
}
ObjectGDExtension::~ObjectGDExtension() {
if (gdtype) {
memdelete(const_cast<GDType *>(gdtype));
}
}
bool Object::Connection::operator<(const Connection &p_conn) const {
if (signal == p_conn.signal) {
return callable < p_conn.callable;
@ -279,6 +298,7 @@ bool Object::_predelete() {
}
_extension = nullptr;
_extension_instance = nullptr;
// _gdtype_ptr = nullptr; // The pointer already set to nullptr above, no need to do it again.
}
#ifdef TOOLS_ENABLED
else if (_instance_bindings != nullptr) {
@ -1379,6 +1399,16 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
return err;
}
void Object::_reset_gdtype() const {
if (_extension) {
// Set to extension's type.
_gdtype_ptr = _extension->gdtype;
} else {
// Reset to internal type.
_gdtype_ptr = &_get_typev();
}
}
void Object::_add_user_signal(const String &p_name, const Array &p_args) {
// this version of add_user_signal is meant to be used from scripts or external apis
// without access to ADD_SIGNAL in bind_methods
@ -1734,7 +1764,7 @@ void Object::initialize_class() {
if (initialized) {
return;
}
_add_class_to_classdb(get_class_static(), StringName());
_add_class_to_classdb(get_gdtype_static(), nullptr);
_bind_methods();
_bind_compatibility_methods();
initialized = true;
@ -1810,8 +1840,8 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
}
}
void Object::_add_class_to_classdb(const StringName &p_class, const StringName &p_inherits) {
ClassDB::_add_class(p_class, p_inherits);
void Object::_add_class_to_classdb(const GDType &p_type, const GDType *p_inherits) {
ClassDB::_add_class(p_type, p_inherits);
}
void Object::_get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
@ -2128,9 +2158,6 @@ const GDType &Object::get_gdtype() const {
}
bool Object::is_class(const String &p_class) const {
if (_extension && _extension->is_class(p_class)) {
return true;
}
for (const StringName &name : get_gdtype().get_name_hierarchy()) {
if (name == p_class) {
return true;
@ -2140,11 +2167,6 @@ bool Object::is_class(const String &p_class) const {
}
const StringName &Object::get_class_name() const {
if (_extension) {
// Can't put inside the unlikely as constructor can run it.
return _extension->class_name;
}
return get_gdtype().get_name();
}
@ -2277,6 +2299,8 @@ void Object::clear_internal_extension() {
}
_extension = nullptr;
_extension_instance = nullptr;
// Reset GDType to internal type.
_gdtype_ptr = &_get_typev();
// Clear the instance bindings.
_instance_binding_mutex.lock();
@ -2305,6 +2329,7 @@ void Object::reset_internal_extension(ObjectGDExtension *p_extension) {
_extension_instance = p_extension->recreate_instance ? p_extension->recreate_instance(p_extension->class_userdata, (GDExtensionObjectPtr)this) : nullptr;
ERR_FAIL_NULL_MSG(_extension_instance, "Unable to recreate GDExtension instance - does this extension support hot reloading?");
_extension = p_extension;
_gdtype_ptr = p_extension->gdtype;
}
}
#endif