Merge pull request #1492 from dsnopek/4.2-cherrypicks-5

Cherry-picks for the godot-cpp 4.2 branch - 5th batch
pull/1524/head
David Snopek 2024-06-14 13:32:50 -05:00 committed by GitHub
commit 9da6ecd144
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 13 deletions

View File

@ -1535,13 +1535,16 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
result.append("\t \\")
for method in class_api["methods"]:
# ClassDBSingleton shouldn't have any static or vararg methods, but if some appear later, lets skip them.
if vararg:
continue
# ClassDBSingleton shouldn't have any static methods, but if some appear later, lets skip them.
if "is_static" in method and method["is_static"]:
continue
method_signature = "\tstatic "
vararg = "is_vararg" in method and method["is_vararg"]
if vararg:
method_signature = "\ttemplate<typename... Args> static "
else:
method_signature = "\tstatic "
return_type = None
if "return_type" in method:
return_type = correct_type(method["return_type"].replace("ClassDBSingleton", "ClassDB"), None, False)
@ -1563,7 +1566,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
method_arguments = method["arguments"]
method_signature += make_function_parameters(
method_arguments, include_default=True, for_builtin=True, is_vararg=False
method_arguments, include_default=True, for_builtin=True, is_vararg=vararg
)
method_signature += ") { \\"
@ -1577,6 +1580,8 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
method_body += f"({return_type})"
method_body += f'ClassDBSingleton::get_singleton()->{method["name"]}('
method_body += ", ".join(map(lambda x: escape_identifier(x["name"]), method_arguments))
if vararg:
method_body += ", args..."
method_body += "); \\"
result.append(method_body)
@ -2224,9 +2229,9 @@ def make_varargs_template(
args_array = f"\tstd::array<Variant, {len(method_arguments)} + sizeof...(Args)> variant_args {{ "
for argument in method_arguments:
if argument["type"] == "Variant":
args_array += argument["name"]
args_array += escape_identifier(argument["name"])
else:
args_array += f'Variant({argument["name"]})'
args_array += f'Variant({escape_identifier(argument["name"])})'
args_array += ", "
args_array += "Variant(args)... };"
@ -2426,6 +2431,7 @@ def correct_default_value(value, type_name):
"null": "nullptr",
'""': "String()",
'&""': "StringName()",
'^""': "NodePath()",
"[]": "Array()",
"{}": "Dictionary()",
"Transform2D(1, 0, 0, 1, 0, 0)": "Transform2D()", # Default transform.
@ -2437,6 +2443,10 @@ def correct_default_value(value, type_name):
return f"{type_name}()"
if value.startswith("Array["):
return f"{{}}"
if value.startswith("&"):
return value[1::]
if value.startswith("^"):
return value[1::]
return value

View File

@ -338,10 +338,10 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p
return bind;
}
#define GDREGISTER_CLASS(m_class) ClassDB::register_class<m_class>();
#define GDREGISTER_VIRTUAL_CLASS(m_class) ClassDB::register_class<m_class>(true);
#define GDREGISTER_ABSTRACT_CLASS(m_class) ClassDB::register_abstract_class<m_class>();
#define GDREGISTER_INTERNAL_CLASS(m_class) ClassDB::register_internal_class<m_class>();
#define GDREGISTER_CLASS(m_class) ::godot::ClassDB::register_class<m_class>();
#define GDREGISTER_VIRTUAL_CLASS(m_class) ::godot::ClassDB::register_class<m_class>(true);
#define GDREGISTER_ABSTRACT_CLASS(m_class) ::godot::ClassDB::register_abstract_class<m_class>();
#define GDREGISTER_INTERNAL_CLASS(m_class) ::godot::ClassDB::register_internal_class<m_class>();
} // namespace godot

View File

@ -388,7 +388,7 @@ void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
{
std::lock_guard<std::mutex> lock(engine_singletons_mutex);
singleton_objects.reserve(engine_singletons.size());
for (const std::pair<StringName, Object *> &pair : engine_singletons) {
for (const std::pair<const StringName, Object *> &pair : engine_singletons) {
singleton_objects.push_back(pair.second);
}
}

View File

@ -75,7 +75,7 @@ MethodInfo::operator Dictionary() const {
dict["name"] = name;
dict["args"] = internal::convert_property_list(arguments);
Array da;
for (int i = 0; i < default_arguments.size(); i++) {
for (size_t i = 0; i < default_arguments.size(); i++) {
da.push_back(default_arguments[i]);
}
dict["default_args"] = da;