From 78922d756a506676e46a8035a8d69abfaf765e06 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Fri, 4 Apr 2025 15:53:35 -0500 Subject: [PATCH] Core: Decouple `GDCLASS` from ClassDB --- core/object/class_db.cpp | 2 +- core/object/class_db.h | 10 +++------- core/object/object.cpp | 10 +++++++++- core/object/object.h | 7 +++++-- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index c09303eaddf..4c4248d86eb 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -840,7 +840,7 @@ use_script: return scr.is_valid() && scr->is_valid() && scr->is_abstract(); } -void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) { +void ClassDB::_add_class(const StringName &p_class, const StringName &p_inherits) { Locker::Lock lock(Locker::STATE_WRITE); const StringName &name = p_class; diff --git a/core/object/class_db.h b/core/object/class_db.h index 1ce62226eff..704af022826 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -78,6 +78,8 @@ MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) { #endif class ClassDB { + friend class Object; + public: enum APIType { API_CORE, @@ -193,7 +195,7 @@ public: static APIType current_api; static HashMap api_hashes_cache; - static void _add_class2(const StringName &p_class, const StringName &p_inherits); + static void _add_class(const StringName &p_class, const StringName &p_inherits); static HashMap> default_values; static HashSet default_values_cached; @@ -221,12 +223,6 @@ private: static bool _can_instantiate(ClassInfo *p_class_info, bool p_exposed_only = true); public: - // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!! - template - static void _add_class() { - _add_class2(T::get_class_static(), T::get_parent_class_static()); - } - template static void register_class(bool p_virtual = false) { Locker::Lock lock(Locker::STATE_WRITE); diff --git a/core/object/object.cpp b/core/object/object.cpp index c4515786399..317b062ebe4 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -1590,7 +1590,7 @@ void Object::initialize_class() { if (initialized) { return; } - ClassDB::_add_class(); + _add_class_to_classdb(get_class_static(), get_parent_class_static()); _bind_methods(); _bind_compatibility_methods(); initialized = true; @@ -1666,6 +1666,14 @@ 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::_get_property_list_from_classdb(const StringName &p_class, List *p_list, bool p_no_inheritance, const Object *p_validator) { + ClassDB::get_property_list(p_class, p_list, p_no_inheritance, p_validator); +} + #ifdef TOOLS_ENABLED void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded, bool p_initializing) { if (!p_initializing) { diff --git a/core/object/object.h b/core/object/object.h index a57a3b71c68..7be354c642a 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -454,7 +454,7 @@ public: return; \ } \ m_inherits::initialize_class(); \ - ::ClassDB::_add_class(); \ + _add_class_to_classdb(get_class_static(), get_parent_class_static()); \ if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \ _bind_methods(); \ } \ @@ -499,7 +499,7 @@ protected: m_inherits::_get_property_listv(p_list, p_reversed); \ } \ p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, get_class_static(), PROPERTY_USAGE_CATEGORY)); \ - ::ClassDB::get_property_list(#m_class, p_list, true, this); \ + _get_property_list_from_classdb(#m_class, p_list, true, this); \ if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \ _get_property_list(p_list); \ } \ @@ -759,6 +759,9 @@ protected: friend class ClassDB; friend class PlaceholderExtensionInstance; + static void _add_class_to_classdb(const StringName &p_class, const StringName &p_inherits); + static void _get_property_list_from_classdb(const StringName &p_class, List *p_list, bool p_no_inheritance, const Object *p_validator); + bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false); #ifdef TOOLS_ENABLED