Skip to content

Cherry-picks for the godot-cpp 4.3 branch - 1st batch #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 40 additions & 8 deletions binding_generator.py
Original file line number Diff line number Diff line change
@@ -852,14 +852,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl

if "operators" in builtin_api:
for operator in builtin_api["operators"]:
if operator["name"] not in ["in", "xor"]:
if is_valid_cpp_operator(operator["name"]):
if "right_type" in operator:
result.append(
f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;'
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;'
)
else:
result.append(
f'\t{correct_type(operator["return_type"])} operator{operator["name"].replace("unary", "")}() const;'
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;'
)

# Copy assignment.
@@ -1291,10 +1291,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl

if "operators" in builtin_api:
for operator in builtin_api["operators"]:
if operator["name"] not in ["in", "xor"]:
if is_valid_cpp_operator(operator["name"]):
if "right_type" in operator:
result.append(
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{'
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{'
)
(encode, arg_name) = get_encoded_arg("other", operator["right_type"], None)
result += encode
@@ -1304,7 +1304,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
result.append("}")
else:
result.append(
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"].replace("unary", "")}() const {{'
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{'
)
result.append(
f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr)nullptr);'
@@ -2719,8 +2719,8 @@ def correct_type(type_name, meta=None, use_alias=True):
if meta is not None:
if "int" in meta:
return f"{meta}_t"
elif meta in type_conversion:
return type_conversion[type_name]
elif "char" in meta:
return f"{meta}_t"
else:
return meta
if type_name in type_conversion:
@@ -2832,6 +2832,38 @@ def get_operator_id_name(op):
return op_id_map[op]


def get_operator_cpp_name(op):
op_cpp_map = {
"==": "==",
"!=": "!=",
"<": "<",
"<=": "<=",
">": ">",
">=": ">=",
"+": "+",
"-": "-",
"*": "*",
"/": "/",
"unary-": "-",
"unary+": "+",
"%": "%",
"<<": "<<",
">>": ">>",
"&": "&",
"|": "|",
"^": "^",
"~": "~",
"and": "&&",
"or": "||",
"not": "!",
}
return op_cpp_map[op]


def is_valid_cpp_operator(op):
return op not in ["**", "xor", "in"]


def get_default_value_for_type(type_name):
if type_name == "int":
return "0"
19 changes: 10 additions & 9 deletions include/godot_cpp/core/type_info.hpp
Original file line number Diff line number Diff line change
@@ -397,16 +397,17 @@ MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE)
MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL)
MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY)
MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)
MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
/*
MAKE_TYPED_ARRAY_INFO(Vector<uint8_t>, Variant::PACKED_BYTE_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<int32_t>, Variant::PACKED_INT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<int64_t>, Variant::PACKED_INT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<float>, Variant::PACKED_FLOAT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<double>, Variant::PACKED_FLOAT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<String>, Variant::PACKED_STRING_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING)
*/

2 changes: 1 addition & 1 deletion include/godot_cpp/templates/safe_refcount.hpp
Original file line number Diff line number Diff line change
@@ -132,7 +132,7 @@ class SafeNumeric {
}
}

_ALWAYS_INLINE_ explicit SafeNumeric<T>(T p_value = static_cast<T>(0)) {
_ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast<T>(0)) {
set(p_value);
}
};
6 changes: 6 additions & 0 deletions test/project/main.gd
Original file line number Diff line number Diff line change
@@ -270,6 +270,12 @@ func _ready():
assert_equal(example_child.get_value1(), 11)
assert_equal(example_child.get_value2(), 22)

# Test that the extension's library path is absolute and valid.
var library_path = Example.test_library_path()
assert_equal(library_path.begins_with("res://"), false)
assert_equal(library_path, ProjectSettings.globalize_path(library_path))
assert_equal(FileAccess.file_exists(library_path), true)

exit_with_status()

func _on_Example_custom_signal(signal_name, value):
22 changes: 22 additions & 0 deletions test/src/example.cpp
Original file line number Diff line number Diff line change
@@ -204,6 +204,7 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility);
ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &Example::test_string_is_forty_two);
ClassDB::bind_method(D_METHOD("test_string_resize"), &Example::test_string_resize);
ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &Example::test_typed_array_of_packed);
ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops);
ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list);

@@ -248,6 +249,8 @@ void Example::_bind_methods() {
ClassDB::bind_static_method("Example", D_METHOD("test_static", "a", "b"), &Example::test_static);
ClassDB::bind_static_method("Example", D_METHOD("test_static2"), &Example::test_static2);

ClassDB::bind_static_method("Example", D_METHOD("test_library_path"), &Example::test_library_path);

{
MethodInfo mi;
mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument"));
@@ -424,6 +427,19 @@ String Example::test_string_resize(String p_string) const {
return p_string;
}

TypedArray<PackedInt32Array> Example::test_typed_array_of_packed() const {
TypedArray<PackedInt32Array> arr;
PackedInt32Array packed_arr1;
packed_arr1.push_back(1);
packed_arr1.push_back(2);
arr.push_back(packed_arr1);
PackedInt32Array packed_arr2;
packed_arr2.push_back(3);
packed_arr2.push_back(4);
arr.push_back(packed_arr2);
return arr;
}

int Example::test_vector_ops() const {
PackedInt32Array arr;
arr.push_back(10);
@@ -695,6 +711,12 @@ String Example::test_use_engine_singleton() const {
return OS::get_singleton()->get_name();
}

String Example::test_library_path() {
String library_path;
internal::gdextension_interface_get_library_path(internal::library, library_path._native_ptr());
return library_path;
}

void ExampleRuntime::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_prop_value", "value"), &ExampleRuntime::set_prop_value);
ClassDB::bind_method(D_METHOD("get_prop_value"), &ExampleRuntime::get_prop_value);
3 changes: 3 additions & 0 deletions test/src/example.h
Original file line number Diff line number Diff line change
@@ -134,6 +134,7 @@ class Example : public Control {
String test_str_utility() const;
bool test_string_is_forty_two(const String &p_str) const;
String test_string_resize(String p_original) const;
TypedArray<PackedInt32Array> test_typed_array_of_packed() const;
int test_vector_ops() const;
int test_vector_init_list() const;

@@ -194,6 +195,8 @@ class Example : public Control {
GDVIRTUAL1(_do_something_virtual_with_control, Control *);

String test_use_engine_singleton() const;

static String test_library_path();
};

VARIANT_ENUM_CAST(Example::Constants);
2 changes: 1 addition & 1 deletion tools/web.py
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ def generate(env):
env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])

# Build as side module (shared library).
env.Append(CPPFLAGS=["-sSIDE_MODULE=1"])
env.Append(CCFLAGS=["-sSIDE_MODULE=1"])
env.Append(LINKFLAGS=["-sSIDE_MODULE=1"])

# Force wasm longjmp mode.