Skip to content

Commit 78922d7

Browse files
committed
Core: Decouple GDCLASS from ClassDB
1 parent 27b2ba6 commit 78922d7

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

core/object/class_db.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ bool ClassDB::is_virtual(const StringName &p_class) {
840840
return scr.is_valid() && scr->is_valid() && scr->is_abstract();
841841
}
842842

843-
void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
843+
void ClassDB::_add_class(const StringName &p_class, const StringName &p_inherits) {
844844
Locker::Lock lock(Locker::STATE_WRITE);
845845

846846
const StringName &name = p_class;

core/object/class_db.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
7878
#endif
7979

8080
class ClassDB {
81+
friend class Object;
82+
8183
public:
8284
enum APIType {
8385
API_CORE,
@@ -193,7 +195,7 @@ class ClassDB {
193195
static APIType current_api;
194196
static HashMap<APIType, uint32_t> api_hashes_cache;
195197

196-
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
198+
static void _add_class(const StringName &p_class, const StringName &p_inherits);
197199

198200
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
199201
static HashSet<StringName> default_values_cached;
@@ -221,12 +223,6 @@ class ClassDB {
221223
static bool _can_instantiate(ClassInfo *p_class_info, bool p_exposed_only = true);
222224

223225
public:
224-
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
225-
template <typename T>
226-
static void _add_class() {
227-
_add_class2(T::get_class_static(), T::get_parent_class_static());
228-
}
229-
230226
template <typename T>
231227
static void register_class(bool p_virtual = false) {
232228
Locker::Lock lock(Locker::STATE_WRITE);

core/object/object.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ void Object::initialize_class() {
15901590
if (initialized) {
15911591
return;
15921592
}
1593-
ClassDB::_add_class<Object>();
1593+
_add_class_to_classdb(get_class_static(), get_parent_class_static());
15941594
_bind_methods();
15951595
_bind_compatibility_methods();
15961596
initialized = true;
@@ -1666,6 +1666,14 @@ void Object::_clear_internal_resource_paths(const Variant &p_var) {
16661666
}
16671667
}
16681668

1669+
void Object::_add_class_to_classdb(const StringName &p_class, const StringName &p_inherits) {
1670+
ClassDB::_add_class(p_class, p_inherits);
1671+
}
1672+
1673+
void Object::_get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
1674+
ClassDB::get_property_list(p_class, p_list, p_no_inheritance, p_validator);
1675+
}
1676+
16691677
#ifdef TOOLS_ENABLED
16701678
void Object::editor_set_section_unfold(const String &p_section, bool p_unfolded, bool p_initializing) {
16711679
if (!p_initializing) {

core/object/object.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public:
454454
return; \
455455
} \
456456
m_inherits::initialize_class(); \
457-
::ClassDB::_add_class<m_class>(); \
457+
_add_class_to_classdb(get_class_static(), get_parent_class_static()); \
458458
if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
459459
_bind_methods(); \
460460
} \
@@ -499,7 +499,7 @@ protected:
499499
m_inherits::_get_property_listv(p_list, p_reversed); \
500500
} \
501501
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, get_class_static(), PROPERTY_USAGE_CATEGORY)); \
502-
::ClassDB::get_property_list(#m_class, p_list, true, this); \
502+
_get_property_list_from_classdb(#m_class, p_list, true, this); \
503503
if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
504504
_get_property_list(p_list); \
505505
} \
@@ -759,6 +759,9 @@ class Object {
759759
friend class ClassDB;
760760
friend class PlaceholderExtensionInstance;
761761

762+
static void _add_class_to_classdb(const StringName &p_class, const StringName &p_inherits);
763+
static void _get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator);
764+
762765
bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false);
763766

764767
#ifdef TOOLS_ENABLED

0 commit comments

Comments
 (0)