@@ -230,6 +230,25 @@ Object::Connection::operator Variant() const {
230230 return d;
231231}
232232
233+ void ObjectGDExtension::create_gdtype () {
234+ ERR_FAIL_COND (gdtype);
235+
236+ gdtype = memnew (GDType (ClassDB::get_gdtype (parent_class_name), class_name));
237+ }
238+
239+ void ObjectGDExtension::destroy_gdtype () {
240+ ERR_FAIL_COND (!gdtype);
241+
242+ memdelete (const_cast <GDType *>(gdtype));
243+ gdtype = nullptr ;
244+ }
245+
246+ ObjectGDExtension::~ObjectGDExtension () {
247+ if (gdtype) {
248+ memdelete (const_cast <GDType *>(gdtype));
249+ }
250+ }
251+
233252bool Object::Connection::operator <(const Connection &p_conn) const {
234253 if (signal == p_conn.signal ) {
235254 return callable < p_conn.callable ;
@@ -279,6 +298,7 @@ bool Object::_predelete() {
279298 }
280299 _extension = nullptr ;
281300 _extension_instance = nullptr ;
301+ // _gdtype_ptr = nullptr; // The pointer already set to nullptr above, no need to do it again.
282302 }
283303#ifdef TOOLS_ENABLED
284304 else if (_instance_bindings != nullptr ) {
@@ -1379,6 +1399,16 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
13791399 return err;
13801400}
13811401
1402+ void Object::_reset_gdtype () const {
1403+ if (_extension) {
1404+ // Set to extension's type.
1405+ _gdtype_ptr = _extension->gdtype ;
1406+ } else {
1407+ // Reset to internal type.
1408+ _gdtype_ptr = &_get_typev ();
1409+ }
1410+ }
1411+
13821412void Object::_add_user_signal (const String &p_name, const Array &p_args) {
13831413 // this version of add_user_signal is meant to be used from scripts or external apis
13841414 // without access to ADD_SIGNAL in bind_methods
@@ -1734,7 +1764,7 @@ void Object::initialize_class() {
17341764 if (initialized) {
17351765 return ;
17361766 }
1737- _add_class_to_classdb (get_class_static (), StringName () );
1767+ _add_class_to_classdb (get_gdtype_static (), nullptr );
17381768 _bind_methods ();
17391769 _bind_compatibility_methods ();
17401770 initialized = true ;
@@ -1810,8 +1840,8 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
18101840 }
18111841}
18121842
1813- void Object::_add_class_to_classdb (const StringName &p_class , const StringName & p_inherits) {
1814- ClassDB::_add_class (p_class , p_inherits);
1843+ void Object::_add_class_to_classdb (const GDType &p_type , const GDType * p_inherits) {
1844+ ClassDB::_add_class (p_type , p_inherits);
18151845}
18161846
18171847void 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 {
21282158}
21292159
21302160bool Object::is_class (const String &p_class) const {
2131- if (_extension && _extension->is_class (p_class)) {
2132- return true ;
2133- }
21342161 for (const StringName &name : get_gdtype ().get_name_hierarchy ()) {
21352162 if (name == p_class) {
21362163 return true ;
@@ -2140,11 +2167,6 @@ bool Object::is_class(const String &p_class) const {
21402167}
21412168
21422169const StringName &Object::get_class_name () const {
2143- if (_extension) {
2144- // Can't put inside the unlikely as constructor can run it.
2145- return _extension->class_name ;
2146- }
2147-
21482170 return get_gdtype ().get_name ();
21492171}
21502172
@@ -2277,6 +2299,8 @@ void Object::clear_internal_extension() {
22772299 }
22782300 _extension = nullptr ;
22792301 _extension_instance = nullptr ;
2302+ // Reset GDType to internal type.
2303+ _gdtype_ptr = &_get_typev ();
22802304
22812305 // Clear the instance bindings.
22822306 _instance_binding_mutex.lock ();
@@ -2305,6 +2329,7 @@ void Object::reset_internal_extension(ObjectGDExtension *p_extension) {
23052329 _extension_instance = p_extension->recreate_instance ? p_extension->recreate_instance (p_extension->class_userdata , (GDExtensionObjectPtr)this ) : nullptr ;
23062330 ERR_FAIL_NULL_MSG (_extension_instance, " Unable to recreate GDExtension instance - does this extension support hot reloading?" );
23072331 _extension = p_extension;
2332+ _gdtype_ptr = p_extension->gdtype ;
23082333 }
23092334}
23102335#endif
0 commit comments