Skip to content

Commit e298f43

Browse files
authored
Merge pull request #1569 from dsnopek/4.3-cherrypicks-1
Cherry-picks for the godot-cpp 4.3 branch - 1st batch
2 parents fbbf9ec + 1ac33c9 commit e298f43

File tree

7 files changed

+83
-19
lines changed

7 files changed

+83
-19
lines changed

binding_generator.py

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,14 +852,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
852852

853853
if "operators" in builtin_api:
854854
for operator in builtin_api["operators"]:
855-
if operator["name"] not in ["in", "xor"]:
855+
if is_valid_cpp_operator(operator["name"]):
856856
if "right_type" in operator:
857857
result.append(
858-
f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;'
858+
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;'
859859
)
860860
else:
861861
result.append(
862-
f'\t{correct_type(operator["return_type"])} operator{operator["name"].replace("unary", "")}() const;'
862+
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;'
863863
)
864864

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

12921292
if "operators" in builtin_api:
12931293
for operator in builtin_api["operators"]:
1294-
if operator["name"] not in ["in", "xor"]:
1294+
if is_valid_cpp_operator(operator["name"]):
12951295
if "right_type" in operator:
12961296
result.append(
1297-
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{'
1297+
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{'
12981298
)
12991299
(encode, arg_name) = get_encoded_arg("other", operator["right_type"], None)
13001300
result += encode
@@ -1304,7 +1304,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
13041304
result.append("}")
13051305
else:
13061306
result.append(
1307-
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"].replace("unary", "")}() const {{'
1307+
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{'
13081308
)
13091309
result.append(
13101310
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):
27192719
if meta is not None:
27202720
if "int" in meta:
27212721
return f"{meta}_t"
2722-
elif meta in type_conversion:
2723-
return type_conversion[type_name]
2722+
elif "char" in meta:
2723+
return f"{meta}_t"
27242724
else:
27252725
return meta
27262726
if type_name in type_conversion:
@@ -2832,6 +2832,38 @@ def get_operator_id_name(op):
28322832
return op_id_map[op]
28332833

28342834

2835+
def get_operator_cpp_name(op):
2836+
op_cpp_map = {
2837+
"==": "==",
2838+
"!=": "!=",
2839+
"<": "<",
2840+
"<=": "<=",
2841+
">": ">",
2842+
">=": ">=",
2843+
"+": "+",
2844+
"-": "-",
2845+
"*": "*",
2846+
"/": "/",
2847+
"unary-": "-",
2848+
"unary+": "+",
2849+
"%": "%",
2850+
"<<": "<<",
2851+
">>": ">>",
2852+
"&": "&",
2853+
"|": "|",
2854+
"^": "^",
2855+
"~": "~",
2856+
"and": "&&",
2857+
"or": "||",
2858+
"not": "!",
2859+
}
2860+
return op_cpp_map[op]
2861+
2862+
2863+
def is_valid_cpp_operator(op):
2864+
return op not in ["**", "xor", "in"]
2865+
2866+
28352867
def get_default_value_for_type(type_name):
28362868
if type_name == "int":
28372869
return "0"

include/godot_cpp/core/type_info.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,17 @@ MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE)
397397
MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL)
398398
MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY)
399399
MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY)
400+
MAKE_TYPED_ARRAY_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY)
401+
MAKE_TYPED_ARRAY_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY)
402+
MAKE_TYPED_ARRAY_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY)
403+
MAKE_TYPED_ARRAY_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY)
404+
MAKE_TYPED_ARRAY_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY)
405+
MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
406+
MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
407+
MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
408+
MAKE_TYPED_ARRAY_INFO(PackedVector4Array, Variant::PACKED_VECTOR4_ARRAY)
409+
MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
400410
/*
401-
MAKE_TYPED_ARRAY_INFO(Vector<uint8_t>, Variant::PACKED_BYTE_ARRAY)
402-
MAKE_TYPED_ARRAY_INFO(Vector<int32_t>, Variant::PACKED_INT32_ARRAY)
403-
MAKE_TYPED_ARRAY_INFO(Vector<int64_t>, Variant::PACKED_INT64_ARRAY)
404-
MAKE_TYPED_ARRAY_INFO(Vector<float>, Variant::PACKED_FLOAT32_ARRAY)
405-
MAKE_TYPED_ARRAY_INFO(Vector<double>, Variant::PACKED_FLOAT64_ARRAY)
406-
MAKE_TYPED_ARRAY_INFO(Vector<String>, Variant::PACKED_STRING_ARRAY)
407-
MAKE_TYPED_ARRAY_INFO(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY)
408-
MAKE_TYPED_ARRAY_INFO(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY)
409-
MAKE_TYPED_ARRAY_INFO(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
410411
MAKE_TYPED_ARRAY_INFO(IPAddress, Variant::STRING)
411412
*/
412413

include/godot_cpp/templates/safe_refcount.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class SafeNumeric {
132132
}
133133
}
134134

135-
_ALWAYS_INLINE_ explicit SafeNumeric<T>(T p_value = static_cast<T>(0)) {
135+
_ALWAYS_INLINE_ explicit SafeNumeric(T p_value = static_cast<T>(0)) {
136136
set(p_value);
137137
}
138138
};

test/project/main.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,12 @@ func _ready():
270270
assert_equal(example_child.get_value1(), 11)
271271
assert_equal(example_child.get_value2(), 22)
272272

273+
# Test that the extension's library path is absolute and valid.
274+
var library_path = Example.test_library_path()
275+
assert_equal(library_path.begins_with("res://"), false)
276+
assert_equal(library_path, ProjectSettings.globalize_path(library_path))
277+
assert_equal(FileAccess.file_exists(library_path), true)
278+
273279
exit_with_status()
274280

275281
func _on_Example_custom_signal(signal_name, value):

test/src/example.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void Example::_bind_methods() {
204204
ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility);
205205
ClassDB::bind_method(D_METHOD("test_string_is_forty_two"), &Example::test_string_is_forty_two);
206206
ClassDB::bind_method(D_METHOD("test_string_resize"), &Example::test_string_resize);
207+
ClassDB::bind_method(D_METHOD("test_typed_array_of_packed"), &Example::test_typed_array_of_packed);
207208
ClassDB::bind_method(D_METHOD("test_vector_ops"), &Example::test_vector_ops);
208209
ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list);
209210

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

252+
ClassDB::bind_static_method("Example", D_METHOD("test_library_path"), &Example::test_library_path);
253+
251254
{
252255
MethodInfo mi;
253256
mi.arguments.push_back(PropertyInfo(Variant::STRING, "some_argument"));
@@ -424,6 +427,19 @@ String Example::test_string_resize(String p_string) const {
424427
return p_string;
425428
}
426429

430+
TypedArray<PackedInt32Array> Example::test_typed_array_of_packed() const {
431+
TypedArray<PackedInt32Array> arr;
432+
PackedInt32Array packed_arr1;
433+
packed_arr1.push_back(1);
434+
packed_arr1.push_back(2);
435+
arr.push_back(packed_arr1);
436+
PackedInt32Array packed_arr2;
437+
packed_arr2.push_back(3);
438+
packed_arr2.push_back(4);
439+
arr.push_back(packed_arr2);
440+
return arr;
441+
}
442+
427443
int Example::test_vector_ops() const {
428444
PackedInt32Array arr;
429445
arr.push_back(10);
@@ -695,6 +711,12 @@ String Example::test_use_engine_singleton() const {
695711
return OS::get_singleton()->get_name();
696712
}
697713

714+
String Example::test_library_path() {
715+
String library_path;
716+
internal::gdextension_interface_get_library_path(internal::library, library_path._native_ptr());
717+
return library_path;
718+
}
719+
698720
void ExampleRuntime::_bind_methods() {
699721
ClassDB::bind_method(D_METHOD("set_prop_value", "value"), &ExampleRuntime::set_prop_value);
700722
ClassDB::bind_method(D_METHOD("get_prop_value"), &ExampleRuntime::get_prop_value);

test/src/example.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class Example : public Control {
134134
String test_str_utility() const;
135135
bool test_string_is_forty_two(const String &p_str) const;
136136
String test_string_resize(String p_original) const;
137+
TypedArray<PackedInt32Array> test_typed_array_of_packed() const;
137138
int test_vector_ops() const;
138139
int test_vector_init_list() const;
139140

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

196197
String test_use_engine_singleton() const;
198+
199+
static String test_library_path();
197200
};
198201

199202
VARIANT_ENUM_CAST(Example::Constants);

tools/web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def generate(env):
3939
env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])
4040

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

4545
# Force wasm longjmp mode.

0 commit comments

Comments
 (0)