Merge pull request #1569 from dsnopek/4.3-cherrypicks-1

Cherry-picks for the godot-cpp 4.3 branch - 1st batch
pull/1041/head
David Snopek 2024-09-11 17:17:24 -05:00 committed by GitHub
commit e298f430b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 83 additions and 19 deletions

View File

@ -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"

View File

@ -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)
*/

View File

@ -132,7 +132,7 @@ public:
}
}
_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);
}
};

View File

@ -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):

View File

@ -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);

View File

@ -134,6 +134,7 @@ public:
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 @@ public:
GDVIRTUAL1(_do_something_virtual_with_control, Control *);
String test_use_engine_singleton() const;
static String test_library_path();
};
VARIANT_ENUM_CAST(Example::Constants);

View File

@ -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.