Skip to content

Commit 2e7f551

Browse files
authored
Merge pull request #1491 from dsnopek/4.1-cherrypicks-11
Cherry-picks for the godot-cpp 4.1 branch - 11th batch
2 parents 32becf6 + 5880be0 commit 2e7f551

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

.github/workflows/ci.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on: [push, pull_request]
44
env:
55
# Only used for the cache key. Increment version to force clean build.
66
GODOT_BASE_BRANCH: master
7+
# Used to select the version of Godot to run the tests with.
8+
GODOT_TEST_VERSION: 4.1.4-stable
79

810
concurrency:
911
group: ci-${{github.actor}}-${{github.head_ref || github.run_number}}-${{github.ref}}
@@ -153,7 +155,7 @@ jobs:
153155
154156
- name: Download latest Godot artifacts
155157
uses: dsnopek/action-download-artifact@1322f74e2dac9feed2ee76a32d9ae1ca3b4cf4e9
156-
if: ${{ matrix.run-tests }}
158+
if: ${{ matrix.run-tests && env.GODOT_TEST_VERSION == 'master' }}
157159
with:
158160
repo: godotengine/godot
159161
branch: master
@@ -166,15 +168,28 @@ jobs:
166168
ensure_latest: true
167169
path: godot-artifacts
168170

171+
- name: Prepare Godot artifacts for testing
172+
if: ${{ matrix.run-tests && env.GODOT_TEST_VERSION == 'master' }}
173+
run: |
174+
chmod +x ./godot-artifacts/godot.linuxbsd.editor.x86_64.mono
175+
echo "GODOT=$(pwd)/godot-artifacts/godot.linuxbsd.editor.x86_64.mono" >> $GITHUB_ENV
176+
177+
- name: Download requested Godot version for testing
178+
if: ${{ matrix.run-tests && env.GODOT_TEST_VERSION != 'master' }}
179+
run: |
180+
wget "https://github.com/godotengine/godot-builds/releases/download/${GODOT_TEST_VERSION}/Godot_v${GODOT_TEST_VERSION}_linux.x86_64.zip" -O Godot.zip
181+
unzip -a Godot.zip
182+
chmod +x "Godot_v${GODOT_TEST_VERSION}_linux.x86_64"
183+
echo "GODOT=$(pwd)/Godot_v${GODOT_TEST_VERSION}_linux.x86_64" >> $GITHUB_ENV
184+
169185
- name: Run tests
170186
if: ${{ matrix.run-tests }}
171187
run: |
172-
chmod +x ./godot-artifacts/godot.linuxbsd.editor.x86_64.mono
173-
./godot-artifacts/godot.linuxbsd.editor.x86_64.mono --headless --version
188+
$GODOT --headless --version
174189
cd test
175190
# Need to run the editor so .godot is generated... but it crashes! Ignore that :-)
176-
(cd project && (timeout 10 ../../godot-artifacts/godot.linuxbsd.editor.x86_64.mono --editor --headless --quit >/dev/null 2>&1 || true))
177-
GODOT=../godot-artifacts/godot.linuxbsd.editor.x86_64.mono ./run-tests.sh
191+
(cd project && (timeout 30 $GODOT --editor --headless --quit >/dev/null 2>&1 || true))
192+
./run-tests.sh
178193
179194
- name: Upload artifact
180195
uses: actions/upload-artifact@v3

binding_generator.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,13 +1470,16 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
14701470
result.append("\t \\")
14711471

14721472
for method in class_api["methods"]:
1473-
# ClassDBSingleton shouldn't have any static or vararg methods, but if some appear later, lets skip them.
1474-
if vararg:
1475-
continue
1473+
# ClassDBSingleton shouldn't have any static methods, but if some appear later, lets skip them.
14761474
if "is_static" in method and method["is_static"]:
14771475
continue
14781476

1479-
method_signature = "\tstatic "
1477+
vararg = "is_vararg" in method and method["is_vararg"]
1478+
if vararg:
1479+
method_signature = "\ttemplate<typename... Args> static "
1480+
else:
1481+
method_signature = "\tstatic "
1482+
14801483
return_type = None
14811484
if "return_type" in method:
14821485
return_type = correct_type(method["return_type"].replace("ClassDBSingleton", "ClassDB"), None, False)
@@ -1498,7 +1501,7 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
14981501
method_arguments = method["arguments"]
14991502

15001503
method_signature += make_function_parameters(
1501-
method_arguments, include_default=True, for_builtin=True, is_vararg=False
1504+
method_arguments, include_default=True, for_builtin=True, is_vararg=vararg
15021505
)
15031506

15041507
method_signature += ") { \\"
@@ -1512,6 +1515,8 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
15121515
method_body += f"({return_type})"
15131516
method_body += f'ClassDBSingleton::get_singleton()->{method["name"]}('
15141517
method_body += ", ".join(map(lambda x: escape_identifier(x["name"]), method_arguments))
1518+
if vararg:
1519+
method_body += ", args..."
15151520
method_body += "); \\"
15161521

15171522
result.append(method_body)
@@ -2126,9 +2131,9 @@ def make_varargs_template(function_data, static=False):
21262131
args_array = f"\t\tstd::array<Variant, {len(method_arguments)} + sizeof...(Args)> variant_args {{ "
21272132
for argument in method_arguments:
21282133
if argument["type"] == "Variant":
2129-
args_array += argument["name"]
2134+
args_array += escape_identifier(argument["name"])
21302135
else:
2131-
args_array += f'Variant({argument["name"]})'
2136+
args_array += f'Variant({escape_identifier(argument["name"])})'
21322137
args_array += ", "
21332138

21342139
args_array += "Variant(args)... };"
@@ -2305,6 +2310,7 @@ def correct_default_value(value, type_name):
23052310
"null": "nullptr",
23062311
'""': "String()",
23072312
'&""': "StringName()",
2313+
'^""': "NodePath()",
23082314
"[]": "Array()",
23092315
"{}": "Dictionary()",
23102316
"Transform2D(1, 0, 0, 1, 0, 0)": "Transform2D()", # Default transform.
@@ -2316,6 +2322,10 @@ def correct_default_value(value, type_name):
23162322
return f"{type_name}()"
23172323
if value.startswith("Array["):
23182324
return f"{{}}"
2325+
if value.startswith("&"):
2326+
return value[1::]
2327+
if value.startswith("^"):
2328+
return value[1::]
23192329
return value
23202330

23212331

include/godot_cpp/core/class_db.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ MethodBind *ClassDB::bind_vararg_method(uint32_t p_flags, StringName p_name, M p
286286
return bind;
287287
}
288288

289-
#define GDREGISTER_CLASS(m_class) ClassDB::register_class<m_class>();
290-
#define GDREGISTER_VIRTUAL_CLASS(m_class) ClassDB::register_class<m_class>(true);
291-
#define GDREGISTER_ABSTRACT_CLASS(m_class) ClassDB::register_abstract_class<m_class>();
289+
#define GDREGISTER_CLASS(m_class) ::godot::ClassDB::register_class<m_class>();
290+
#define GDREGISTER_VIRTUAL_CLASS(m_class) ::godot::ClassDB::register_class<m_class>(true);
291+
#define GDREGISTER_ABSTRACT_CLASS(m_class) ::godot::ClassDB::register_abstract_class<m_class>();
292292

293293
} // namespace godot
294294

src/core/class_db.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ void ClassDB::initialize(GDExtensionInitializationLevel p_level) {
360360
}
361361

362362
void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
363+
std::set<StringName> to_erase;
363364
for (std::vector<StringName>::reverse_iterator i = class_register_order.rbegin(); i != class_register_order.rend(); ++i) {
364365
const StringName &name = *i;
365366
const ClassInfo &cl = classes[name];
@@ -370,9 +371,20 @@ void ClassDB::deinitialize(GDExtensionInitializationLevel p_level) {
370371

371372
internal::gdextension_interface_classdb_unregister_extension_class(internal::library, name._native_ptr());
372373

373-
for (auto method : cl.method_map) {
374+
for (const std::pair<const StringName, MethodBind *> &method : cl.method_map) {
374375
memdelete(method.second);
375376
}
377+
378+
classes.erase(name);
379+
to_erase.insert(name);
380+
}
381+
382+
{
383+
// The following is equivalent to c++20 `std::erase_if(class_register_order, [&](const StringName& name){ return to_erase.contains(name); });`
384+
std::vector<StringName>::iterator it = std::remove_if(class_register_order.begin(), class_register_order.end(), [&](const StringName &p_name) {
385+
return to_erase.count(p_name) > 0;
386+
});
387+
class_register_order.erase(it, class_register_order.end());
376388
}
377389
}
378390

src/core/object.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ MethodInfo::operator Dictionary() const {
7575
dict["name"] = name;
7676
dict["args"] = internal::convert_property_list(arguments);
7777
Array da;
78-
for (int i = 0; i < default_arguments.size(); i++) {
78+
for (size_t i = 0; i < default_arguments.size(); i++) {
7979
da.push_back(default_arguments[i]);
8080
}
8181
dict["default_args"] = da;

tools/common_compiler_flags.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ def generate(env):
3939
elif env.get("is_msvc", False):
4040
env.Append(CXXFLAGS=["/EHsc"])
4141

42+
if not env.get("is_msvc", False):
43+
if env["symbols_visibility"] == "visible":
44+
env.Append(CCFLAGS=["-fvisibility=default"])
45+
env.Append(LINKFLAGS=["-fvisibility=default"])
46+
elif env["symbols_visibility"] == "hidden":
47+
env.Append(CCFLAGS=["-fvisibility=hidden"])
48+
env.Append(LINKFLAGS=["-fvisibility=hidden"])
49+
4250
# Set optimize and debug_symbols flags.
4351
# "custom" means do nothing and let users set their own optimization flags.
4452
if env.get("is_msvc", False):

tools/godotcpp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,15 @@ def options(opts, env):
291291
)
292292
)
293293

294+
opts.Add(
295+
EnumVariable(
296+
key="symbols_visibility",
297+
help="Symbols visibility on GNU platforms. Use 'auto' to apply the default value.",
298+
default=env.get("symbols_visibility", "hidden"),
299+
allowed_values=["auto", "visible", "hidden"],
300+
)
301+
)
302+
294303
opts.Add(
295304
EnumVariable(
296305
"optimize",

0 commit comments

Comments
 (0)