Skip to content

Commit

Permalink
Project Converter 3.x -> 4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Feb 5, 2022
1 parent 69d7d1e commit dbaa796
Show file tree
Hide file tree
Showing 12 changed files with 3,852 additions and 40 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
doc-test: true
bin: "./bin/godot.linuxbsd.opt.tools.64.mono"
build-mono: true
proj-conv: true
artifact: true

- name: Editor with doubles and sanitizers (target=debug, tools=yes, float=64, tests=yes, use_asan=yes, use_ubsan=yes)
Expand Down Expand Up @@ -132,6 +133,17 @@ jobs:
curr="$(pwd)/libvk_swiftshader.so"
sed -i "s|PATH_TO_CHANGE|$curr|" vk_swiftshader_icd.json
# Test 3.x -> 4.0 project converter
- name: Test project converter
if: ${{ matrix.proj-conv }}
run: |
mkdir converter_test
cd converter_test
touch project.godot
../${{ matrix.bin }} --headless --audio-driver Dummy --validate-convert-to-godot40
cd ..
rm converter_test -rf
# Download and extract zip archive with project, folder is renamed to be able to easy change used project
- name: Download test project
if: ${{ matrix.proj-test }}
Expand Down
19 changes: 19 additions & 0 deletions core/core_bind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2146,7 +2146,26 @@ bool ClassDB::is_class_enabled(StringName p_class) const {
return ::ClassDB::is_class_enabled(p_class);
}

Array ClassDB::get_variant_method_list(Variant::Type p_type) const {
List<MethodInfo> methods;
Variant::get_method_list_by_type(&methods, p_type);
Array ret;

for (const MethodInfo &E : methods) {
#ifdef DEBUG_METHODS_ENABLED
ret.push_back(E.operator Dictionary());
#else
Dictionary dict;
dict["name"] = E.name;
ret.push_back(dict);
#endif
}

return ret;
}

void ClassDB::_bind_methods() {
::ClassDB::bind_method(D_METHOD("get_variant_method_list", "type"), &ClassDB::get_variant_method_list);
::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
Expand Down
1 change: 1 addition & 0 deletions core/core_bind.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ class ClassDB : public Object {
bool has_method(StringName p_class, StringName p_method, bool p_no_inheritance = false) const;

Array get_method_list(StringName p_class, bool p_no_inheritance = false) const;
Array get_variant_method_list(Variant::Type p_type) const;

PackedStringArray get_integer_constant_list(const StringName &p_class, bool p_no_inheritance = false) const;
bool has_integer_constant(const StringName &p_class, const StringName &p_name) const;
Expand Down
1 change: 1 addition & 0 deletions core/variant/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ class Variant {
static String get_callable_error_text(const Callable &p_callable, const Variant **p_argptrs, int p_argcount, const Callable::CallError &ce);

//dynamic (includes Object)
static void get_method_list_by_type(List<MethodInfo> *p_list, Variant::Type p_type);
void get_method_list(List<MethodInfo> *p_list) const;
bool has_method(const StringName &p_method) const;

Expand Down
85 changes: 45 additions & 40 deletions core/variant/variant_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,54 +1185,59 @@ uint32_t Variant::get_builtin_method_hash(Variant::Type p_type, const StringName
return hash;
}

void Variant::get_method_list(List<MethodInfo> *p_list) const {
if (type == OBJECT) {
Object *obj = get_validated_object();
if (obj) {
obj->get_method_list(p_list);
}
} else {
for (const StringName &E : builtin_method_names[type]) {
const VariantBuiltInMethodInfo *method = builtin_method_info[type].lookup_ptr(E);
ERR_CONTINUE(!method);

MethodInfo mi;
mi.name = E;

//return type
if (method->has_return_type) {
mi.return_val.type = method->return_type;
if (mi.return_val.type == Variant::NIL) {
mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
}
void Variant::get_method_list_by_type(List<MethodInfo> *p_list, Variant::Type p_type) {
ERR_FAIL_INDEX(p_type, Variant::VARIANT_MAX);
for (const StringName &E : builtin_method_names[p_type]) {
const VariantBuiltInMethodInfo *method = builtin_method_info[p_type].lookup_ptr(E);
ERR_CONTINUE(!method);

if (method->is_const) {
mi.flags |= METHOD_FLAG_CONST;
}
if (method->is_vararg) {
mi.flags |= METHOD_FLAG_VARARG;
}
if (method->is_static) {
mi.flags |= METHOD_FLAG_STATIC;
MethodInfo mi;
mi.name = E;

//return type
if (method->has_return_type) {
mi.return_val.type = method->return_type;
if (mi.return_val.type == Variant::NIL) {
mi.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
for (int i = 0; i < method->argument_count; i++) {
PropertyInfo pi;
}

if (method->is_const) {
mi.flags |= METHOD_FLAG_CONST;
}
if (method->is_vararg) {
mi.flags |= METHOD_FLAG_VARARG;
}
if (method->is_static) {
mi.flags |= METHOD_FLAG_STATIC;
}
for (int i = 0; i < method->argument_count; i++) {
PropertyInfo pi;
#ifdef DEBUG_METHODS_ENABLED
pi.name = method->argument_names[i];
pi.name = method->argument_names[i];
#else
pi.name = "arg" + itos(i + 1);
pi.name = "arg" + itos(i + 1);
#endif
pi.type = method->get_argument_type(i);
if (pi.type == Variant::NIL) {
pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
mi.arguments.push_back(pi);
pi.type = method->get_argument_type(i);
if (pi.type == Variant::NIL) {
pi.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
}
mi.arguments.push_back(pi);
}

mi.default_arguments = method->default_arguments;
p_list->push_back(mi);
}
}

mi.default_arguments = method->default_arguments;
p_list->push_back(mi);
void Variant::get_method_list(List<MethodInfo> *p_list) const {
if (type == OBJECT) {
Object *obj = get_validated_object();
if (obj) {
obj->get_method_list(p_list);
}
} else {
Variant::get_method_list_by_type(p_list, type);
}
}

Expand Down
6 changes: 6 additions & 0 deletions doc/classes/ClassDB.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@
Returns the parent class of [code]class[/code].
</description>
</method>
<method name="get_variant_method_list" qualifiers="const">
<return type="Array" />
<argument index="0" name="type" type="int" enum="Variant.Type" />
<description>
</description>
</method>
<method name="instantiate" qualifiers="const">
<return type="Variant" />
<argument index="0" name="class" type="StringName" />
Expand Down
Loading

0 comments on commit dbaa796

Please sign in to comment.