feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -35,9 +35,6 @@
#include "core/object/script_language.h"
#include "core/version.h"
#define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
#define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);
#ifdef DEBUG_METHODS_ENABLED
MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount) {
@ -238,13 +235,13 @@ bool ClassDB::_is_parent_class(const StringName &p_class, const StringName &p_in
}
bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
return _is_parent_class(p_class, p_inherits);
}
void ClassDB::get_class_list(List<StringName> *p_classes) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
for (const KeyValue<StringName, ClassInfo> &E : classes) {
p_classes->push_back(E.key);
@ -255,7 +252,7 @@ void ClassDB::get_class_list(List<StringName> *p_classes) {
#ifdef TOOLS_ENABLED
void ClassDB::get_extensions_class_list(List<StringName> *p_classes) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
for (const KeyValue<StringName, ClassInfo> &E : classes) {
if (E.value.api != API_EXTENSION && E.value.api != API_EDITOR_EXTENSION) {
@ -268,7 +265,7 @@ void ClassDB::get_extensions_class_list(List<StringName> *p_classes) {
}
void ClassDB::get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
for (const KeyValue<StringName, ClassInfo> &E : classes) {
if (E.value.api != API_EXTENSION && E.value.api != API_EDITOR_EXTENSION) {
@ -284,28 +281,28 @@ void ClassDB::get_extension_class_list(const Ref<GDExtension> &p_extension, List
}
#endif
void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
OBJTYPE_RLOCK;
void ClassDB::get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes) {
Locker::Lock lock(Locker::STATE_READ);
for (const KeyValue<StringName, ClassInfo> &E : classes) {
if (E.key != p_class && _is_parent_class(E.key, p_class)) {
p_classes->push_back(E.key);
p_classes.push_back(E.key);
}
}
}
void ClassDB::get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
for (const KeyValue<StringName, ClassInfo> &E : classes) {
if (E.key != p_class && _get_parent_class(E.key) == p_class) {
if (E.value.inherits == p_class) {
p_classes->push_back(E.key);
}
}
}
StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
if (!ti) {
@ -315,7 +312,7 @@ StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
}
bool ClassDB::get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *start = classes.getptr(p_class);
if (!start) {
@ -356,13 +353,13 @@ StringName ClassDB::_get_parent_class(const StringName &p_class) {
}
StringName ClassDB::get_parent_class(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
return _get_parent_class(p_class);
}
ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
@ -372,13 +369,13 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
uint32_t ClassDB::get_api_hash(APIType p_api) {
#ifdef DEBUG_METHODS_ENABLED
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
if (api_hashes_cache.has(p_api)) {
return api_hashes_cache[p_api];
}
uint64_t hash = hash_murmur3_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));
uint64_t hash = hash_murmur3_one_64(HashMapHasherDefault::hash(GODOT_VERSION_FULL_CONFIG));
List<StringName> class_list;
for (const KeyValue<StringName, ClassInfo> &E : classes) {
@ -520,12 +517,12 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {
}
bool ClassDB::class_exists(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
return classes.has(p_class);
}
void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
compat_classes[p_class] = p_fallback;
}
@ -536,18 +533,21 @@ StringName ClassDB::get_compatibility_class(const StringName &p_class) {
return StringName();
}
Object *ClassDB::_instantiate_internal(const StringName &p_class, bool p_require_real_class, bool p_notify_postinitialize) {
Object *ClassDB::_instantiate_internal(const StringName &p_class, bool p_require_real_class, bool p_notify_postinitialize, bool p_exposed_only) {
ClassInfo *ti;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ti = classes.getptr(p_class);
if (!_can_instantiate(ti)) {
if (!_can_instantiate(ti, p_exposed_only)) {
if (compat_classes.has(p_class)) {
ti = classes.getptr(compat_classes[p_class]);
}
}
ERR_FAIL_NULL_V_MSG(ti, nullptr, vformat("Cannot get class '%s'.", String(p_class)));
ERR_FAIL_COND_V_MSG(ti->disabled, nullptr, vformat("Class '%s' is disabled.", String(p_class)));
if (p_exposed_only) {
ERR_FAIL_COND_V_MSG(!ti->exposed, nullptr, vformat("Class '%s' isn't exposed.", String(p_class)));
}
ERR_FAIL_NULL_V_MSG(ti->creation_func, nullptr, vformat("Class '%s' or its base class cannot be instantiated.", String(p_class)));
}
@ -599,11 +599,15 @@ Object *ClassDB::_instantiate_internal(const StringName &p_class, bool p_require
}
}
bool ClassDB::_can_instantiate(ClassInfo *p_class_info) {
bool ClassDB::_can_instantiate(ClassInfo *p_class_info, bool p_exposed_only) {
if (!p_class_info) {
return false;
}
if (p_exposed_only && !p_class_info->exposed) {
return false;
}
if (p_class_info->disabled || !p_class_info->creation_func) {
return false;
}
@ -645,7 +649,7 @@ ObjectGDExtension *ClassDB::get_placeholder_extension(const StringName &p_class)
ClassInfo *ti;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ti = classes.getptr(p_class);
if (!_can_instantiate(ti)) {
if (compat_classes.has(p_class)) {
@ -730,7 +734,7 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName &
ERR_FAIL_NULL(p_object);
ClassInfo *ti;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ti = classes.getptr(p_class);
if (!_can_instantiate(ti)) {
if (compat_classes.has(p_class)) {
@ -755,7 +759,7 @@ void ClassDB::set_object_extension_instance(Object *p_object, const StringName &
bool ClassDB::can_instantiate(const StringName &p_class) {
String script_path;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
if (!ti) {
@ -781,7 +785,7 @@ use_script:
bool ClassDB::is_abstract(const StringName &p_class) {
String script_path;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
if (!ti) {
@ -813,7 +817,7 @@ use_script:
bool ClassDB::is_virtual(const StringName &p_class) {
String script_path;
{
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
if (!ti) {
@ -836,8 +840,8 @@ use_script:
return scr.is_valid() && scr->is_valid() && scr->is_abstract();
}
void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
OBJTYPE_WLOCK;
void ClassDB::_add_class(const StringName &p_class, const StringName &p_inherits) {
Locker::Lock lock(Locker::STATE_WRITE);
const StringName &name = p_class;
@ -880,7 +884,7 @@ static MethodInfo info_from_bind(MethodBind *p_method) {
}
void ClassDB::get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -926,7 +930,7 @@ void ClassDB::get_method_list(const StringName &p_class, List<MethodInfo> *p_met
}
void ClassDB::get_method_list_with_compatibility(const StringName &p_class, List<Pair<MethodInfo, uint32_t>> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -986,7 +990,7 @@ void ClassDB::get_method_list_with_compatibility(const StringName &p_class, List
}
bool ClassDB::get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance, bool p_exclude_from_properties) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1036,7 +1040,7 @@ bool ClassDB::get_method_info(const StringName &p_class, const StringName &p_met
}
MethodBind *ClassDB::get_method(const StringName &p_class, const StringName &p_name) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1051,7 +1055,7 @@ MethodBind *ClassDB::get_method(const StringName &p_class, const StringName &p_n
}
Vector<uint32_t> ClassDB::get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1070,7 +1074,7 @@ Vector<uint32_t> ClassDB::get_method_compatibility_hashes(const StringName &p_cl
}
MethodBind *ClassDB::get_method_with_compatibility(const StringName &p_class, const StringName &p_name, uint64_t p_hash, bool *r_method_exists, bool *r_is_deprecated) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1105,7 +1109,7 @@ MethodBind *ClassDB::get_method_with_compatibility(const StringName &p_class, co
}
void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int64_t p_constant, bool p_is_bitfield) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
@ -1142,7 +1146,7 @@ void ClassDB::bind_integer_constant(const StringName &p_class, const StringName
}
void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1167,7 +1171,7 @@ void ClassDB::get_integer_constant_list(const StringName &p_class, List<String>
}
int64_t ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1191,7 +1195,7 @@ int64_t ClassDB::get_integer_constant(const StringName &p_class, const StringNam
}
bool ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1210,7 +1214,7 @@ bool ClassDB::has_integer_constant(const StringName &p_class, const StringName &
}
StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1234,7 +1238,7 @@ StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const S
}
void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1252,7 +1256,7 @@ void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums
}
void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1275,7 +1279,7 @@ void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_
void ClassDB::set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values) {
#ifdef DEBUG_METHODS_ENABLED
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1286,7 +1290,7 @@ void ClassDB::set_method_error_return_values(const StringName &p_class, const St
Vector<Error> ClassDB::get_method_error_return_values(const StringName &p_class, const StringName &p_method) {
#ifdef DEBUG_METHODS_ENABLED
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL_V(type, Vector<Error>());
@ -1301,7 +1305,7 @@ Vector<Error> ClassDB::get_method_error_return_values(const StringName &p_class,
}
bool ClassDB::has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1320,7 +1324,7 @@ bool ClassDB::has_enum(const StringName &p_class, const StringName &p_name, bool
}
bool ClassDB::is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1339,7 +1343,7 @@ bool ClassDB::is_enum_bitfield(const StringName &p_class, const StringName &p_na
}
void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1358,7 +1362,7 @@ void ClassDB::add_signal(const StringName &p_class, const MethodInfo &p_signal)
}
void ClassDB::get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1379,7 +1383,7 @@ void ClassDB::get_signal_list(const StringName &p_class, List<MethodInfo> *p_sig
}
bool ClassDB::has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
@ -1396,7 +1400,7 @@ bool ClassDB::has_signal(const StringName &p_class, const StringName &p_signal,
}
bool ClassDB::get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
while (check) {
@ -1413,7 +1417,7 @@ bool ClassDB::get_signal(const StringName &p_class, const StringName &p_signal,
}
void ClassDB::add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1426,7 +1430,7 @@ void ClassDB::add_property_group(const StringName &p_class, const String &p_name
}
void ClassDB::add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix, int p_indent_depth) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1443,7 +1447,7 @@ void ClassDB::add_property_array_count(const StringName &p_class, const String &
}
void ClassDB::add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1452,9 +1456,9 @@ void ClassDB::add_property_array(const StringName &p_class, const StringName &p_
// NOTE: For implementation simplicity reasons, this method doesn't allow setters to have optional arguments at the end.
void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
lock.read_lock();
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
lock.read_unlock();
ERR_FAIL_NULL(type);
@ -1486,8 +1490,6 @@ void ClassDB::add_property(const StringName &p_class, const PropertyInfo &p_pinf
ERR_FAIL_COND_MSG(type->property_setget.has(p_pinfo.name), vformat("Object '%s' already has property '%s'.", p_class, p_pinfo.name));
#endif
OBJTYPE_WLOCK
type->property_list.push_back(p_pinfo);
type->property_map[p_pinfo.name] = p_pinfo;
#ifdef DEBUG_METHODS_ENABLED
@ -1518,7 +1520,7 @@ void ClassDB::set_property_default_value(const StringName &p_class, const String
void ClassDB::add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property) {
#ifdef TOOLS_ENABLED
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ERR_FAIL_NULL(type);
@ -1534,7 +1536,7 @@ void ClassDB::add_linked_property(const StringName &p_class, const String &p_pro
}
void ClassDB::get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
@ -1577,7 +1579,7 @@ void ClassDB::get_linked_properties_info(const StringName &p_class, const String
}
bool ClassDB::get_property_info(const StringName &p_class, const StringName &p_property, PropertyInfo *r_info, bool p_no_inheritance, const Object *p_validator) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *check = classes.getptr(p_class);
while (check) {
@ -1800,7 +1802,7 @@ bool ClassDB::has_property(const StringName &p_class, const StringName &p_proper
}
void ClassDB::set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ClassInfo *type = classes.getptr(p_class);
ClassInfo *check = type;
ERR_FAIL_NULL(check);
@ -1825,7 +1827,7 @@ bool ClassDB::has_method(const StringName &p_class, const StringName &p_method,
}
int ClassDB::get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid, bool p_no_inheritance) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -1864,7 +1866,7 @@ void ClassDB::_bind_compatibility(ClassInfo *type, MethodBind *p_method) {
}
void ClassDB::_bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
StringName method_name = p_method->get_name();
@ -1933,7 +1935,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_
StringName mdname = StaticCString::create(method_name);
#endif
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ERR_FAIL_NULL_V(p_bind, nullptr);
p_bind->set_name(mdname);
@ -1996,7 +1998,7 @@ MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_
void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual, const Vector<String> &p_arg_names, bool p_object_core) {
ERR_FAIL_COND_MSG(!classes.has(p_class), vformat("Request for nonexistent class '%s'.", p_class));
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
#ifdef DEBUG_METHODS_ENABLED
MethodInfo mi = p_method;
@ -2011,9 +2013,8 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
if (p_arg_names.size() != mi.arguments.size()) {
WARN_PRINT(vformat("Mismatch argument name count for virtual method: '%s::%s'.", String(p_class), p_method.name));
} else {
List<PropertyInfo>::Iterator itr = mi.arguments.begin();
for (int i = 0; i < p_arg_names.size(); ++itr, ++i) {
itr->name = p_arg_names[i];
for (int64_t i = 0; i < p_arg_names.size(); ++i) {
mi.arguments.write[i].name = p_arg_names[i];
}
}
}
@ -2031,7 +2032,7 @@ void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_
void ClassDB::add_virtual_compatibility_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual, const Vector<String> &p_arg_names, bool p_object_core) {
ERR_FAIL_COND_MSG(!classes.has(p_class), vformat("Request for nonexistent class '%s'.", p_class));
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
HashMap<StringName, Vector<uint32_t>> &virtual_methods_compat = classes[p_class].virtual_methods_compat;
@ -2066,7 +2067,7 @@ void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p
}
Vector<uint32_t> ClassDB::get_virtual_method_compatibility_hashes(const StringName &p_class, const StringName &p_name) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *type = classes.getptr(p_class);
@ -2107,14 +2108,14 @@ void ClassDB::add_extension_class_virtual_method(const StringName &p_class, cons
}
void ClassDB::set_class_enabled(const StringName &p_class, bool p_enable) {
OBJTYPE_WLOCK;
Locker::Lock lock(Locker::STATE_WRITE);
ERR_FAIL_COND_MSG(!classes.has(p_class), vformat("Request for nonexistent class '%s'.", p_class));
classes[p_class].disabled = !p_enable;
}
bool ClassDB::is_class_enabled(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
if (!ti || !ti->creation_func) {
@ -2128,7 +2129,7 @@ bool ClassDB::is_class_enabled(const StringName &p_class) {
}
bool ClassDB::is_class_exposed(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_NULL_V_MSG(ti, false, vformat("Cannot get class '%s'.", String(p_class)));
@ -2136,7 +2137,7 @@ bool ClassDB::is_class_exposed(const StringName &p_class) {
}
bool ClassDB::is_class_reloadable(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_NULL_V_MSG(ti, false, vformat("Cannot get class '%s'.", String(p_class)));
@ -2144,7 +2145,7 @@ bool ClassDB::is_class_reloadable(const StringName &p_class) {
}
bool ClassDB::is_class_runtime(const StringName &p_class) {
OBJTYPE_RLOCK;
Locker::Lock lock(Locker::STATE_READ);
ClassInfo *ti = classes.getptr(p_class);
ERR_FAIL_NULL_V_MSG(ti, false, vformat("Cannot get class '%s'.", String(p_class)));
@ -2342,7 +2343,9 @@ uint64_t ClassDB::get_native_struct_size(const StringName &p_name) {
return native_structs[p_name].struct_size;
}
RWLock ClassDB::lock;
Object *ClassDB::_instantiate_allow_unexposed(const StringName &p_class) {
return _instantiate_internal(p_class, false, true, false);
}
void ClassDB::cleanup_defaults() {
default_values.clear();
@ -2379,3 +2382,32 @@ bool ClassDB::is_default_array_arg(const Array &p_array) {
}
//
ClassDB::Locker::Lock::Lock(Locker::State p_state) {
DEV_ASSERT(p_state != STATE_UNLOCKED);
if (p_state == STATE_READ) {
if (Locker::thread_state == STATE_UNLOCKED) {
state = STATE_READ;
Locker::thread_state = STATE_READ;
Locker::lock.read_lock();
}
} else if (p_state == STATE_WRITE) {
if (Locker::thread_state == STATE_UNLOCKED) {
state = STATE_WRITE;
Locker::thread_state = STATE_WRITE;
Locker::lock.write_lock();
} else if (Locker::thread_state == STATE_READ) {
CRASH_NOW_MSG("Lock can't be upgraded from read to write.");
}
}
}
ClassDB::Locker::Lock::~Lock() {
if (state == STATE_READ) {
Locker::lock.read_unlock();
Locker::thread_state = STATE_UNLOCKED;
} else if (state == STATE_WRITE) {
Locker::lock.write_unlock();
Locker::thread_state = STATE_UNLOCKED;
}
}