Merge pull request #1572 from dsnopek/4.1-cherrypicks-13

Cherry-picks for the godot-cpp 4.1 branch - 13th batch
4.1
David Snopek 2024-09-11 17:15:09 -05:00 committed by GitHub
commit 4d5d707d60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 138 additions and 55 deletions

View File

@ -1,5 +1,5 @@
name: Setup Godot build cache name: Restore Godot build cache
description: Setup Godot build cache. description: Restore Godot build cache.
inputs: inputs:
cache-name: cache-name:
description: The cache base name (job name by default). description: The cache base name (job name by default).
@ -10,9 +10,8 @@ inputs:
runs: runs:
using: "composite" using: "composite"
steps: steps:
# Upload cache on completion and check it out now - name: Restore .scons_cache directory
- name: Load .scons_cache directory uses: actions/cache/restore@v3
uses: actions/cache@v3
with: with:
path: ${{inputs.scons-cache}} path: ${{inputs.scons-cache}}
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}} key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}

View File

@ -0,0 +1,17 @@
name: Save Godot build cache
description: Save Godot build cache.
inputs:
cache-name:
description: The cache base name (job name by default).
default: "${{github.job}}"
scons-cache:
description: The SCons cache path.
default: "${{github.workspace}}/.scons-cache/"
runs:
using: "composite"
steps:
- name: Save SCons cache directory
uses: actions/cache/save@v4
with:
path: ${{inputs.scons-cache}}
key: ${{inputs.cache-name}}-${{env.GODOT_BASE_BRANCH}}-${{github.ref}}-${{github.sha}}

View File

@ -99,8 +99,8 @@ jobs:
with: with:
submodules: recursive submodules: recursive
- name: Setup Godot build cache - name: Restore Godot build cache
uses: ./.github/actions/godot-cache uses: ./.github/actions/godot-cache-restore
with: with:
cache-name: ${{ matrix.cache-name }} cache-name: ${{ matrix.cache-name }}
continue-on-error: true continue-on-error: true
@ -153,6 +153,12 @@ jobs:
cd test cd test
scons platform=${{ matrix.platform }} verbose=yes target=template_release ${{ matrix.flags }} scons platform=${{ matrix.platform }} verbose=yes target=template_release ${{ matrix.flags }}
- name: Save Godot build cache
uses: ./.github/actions/godot-cache-save
with:
cache-name: ${{ matrix.cache-name }}
continue-on-error: true
- name: Download latest Godot artifacts - name: Download latest Godot artifacts
uses: dsnopek/action-download-artifact@1322f74e2dac9feed2ee76a32d9ae1ca3b4cf4e9 uses: dsnopek/action-download-artifact@1322f74e2dac9feed2ee76a32d9ae1ca3b4cf4e9
if: ${{ matrix.run-tests && env.GODOT_TEST_VERSION == 'master' }} if: ${{ matrix.run-tests && env.GODOT_TEST_VERSION == 'master' }}

View File

@ -671,14 +671,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
if "operators" in builtin_api: if "operators" in builtin_api:
for operator in builtin_api["operators"]: 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: if "right_type" in operator:
result.append( 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: else:
result.append( 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. # Copy assignment.
@ -1110,10 +1110,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
if "operators" in builtin_api: if "operators" in builtin_api:
for operator in builtin_api["operators"]: 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: if "right_type" in operator:
result.append( 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) (encode, arg_name) = get_encoded_arg("other", operator["right_type"], None)
result += encode result += encode
@ -1123,7 +1123,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
result.append("}") result.append("}")
else: else:
result.append( 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( 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);' 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);'
@ -2451,8 +2451,6 @@ def correct_type(type_name, meta=None, use_alias=True):
if meta is not None: if meta is not None:
if "int" in meta: if "int" in meta:
return f"{meta}_t" return f"{meta}_t"
elif meta in type_conversion:
return type_conversion[type_name]
else: else:
return meta return meta
if type_name in type_conversion: if type_name in type_conversion:
@ -2564,6 +2562,38 @@ def get_operator_id_name(op):
return op_id_map[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): def get_default_value_for_type(type_name):
if type_name == "int": if type_name == "int":
return "0" return "0"

View File

@ -120,7 +120,7 @@ struct EngineClassRegistration {
#define GDCLASS(m_class, m_inherits) \ #define GDCLASS(m_class, m_inherits) \
private: \ private: \
void operator=(const m_class &p_rval) {} \ void operator=(const m_class & /*p_rval*/) {} \
friend class ::godot::ClassDB; \ friend class ::godot::ClassDB; \
\ \
protected: \ protected: \
@ -212,23 +212,27 @@ public:
} \ } \
\ \
static GDExtensionBool set_bind(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value) { \ static GDExtensionBool set_bind(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value) { \
if (p_instance && m_class::_get_set()) { \ if (p_instance) { \
if (m_inherits::set_bind(p_instance, p_name, p_value)) { \
return true; \
} \
if (m_class::_get_set() != m_inherits::_get_set()) { \ if (m_class::_get_set() != m_inherits::_get_set()) { \
m_class *cls = reinterpret_cast<m_class *>(p_instance); \ m_class *cls = reinterpret_cast<m_class *>(p_instance); \
return cls->_set(*reinterpret_cast<const ::godot::StringName *>(p_name), *reinterpret_cast<const ::godot::Variant *>(p_value)); \ return cls->_set(*reinterpret_cast<const ::godot::StringName *>(p_name), *reinterpret_cast<const ::godot::Variant *>(p_value)); \
} \ } \
return m_inherits::set_bind(p_instance, p_name, p_value); \
} \ } \
return false; \ return false; \
} \ } \
\ \
static GDExtensionBool get_bind(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret) { \ static GDExtensionBool get_bind(GDExtensionClassInstancePtr p_instance, GDExtensionConstStringNamePtr p_name, GDExtensionVariantPtr r_ret) { \
if (p_instance && m_class::_get_get()) { \ if (p_instance) { \
if (m_inherits::get_bind(p_instance, p_name, r_ret)) { \
return true; \
} \
if (m_class::_get_get() != m_inherits::_get_get()) { \ if (m_class::_get_get() != m_inherits::_get_get()) { \
m_class *cls = reinterpret_cast<m_class *>(p_instance); \ m_class *cls = reinterpret_cast<m_class *>(p_instance); \
return cls->_get(*reinterpret_cast<const ::godot::StringName *>(p_name), *reinterpret_cast<::godot::Variant *>(r_ret)); \ return cls->_get(*reinterpret_cast<const ::godot::StringName *>(p_name), *reinterpret_cast<::godot::Variant *>(r_ret)); \
} \ } \
return m_inherits::get_bind(p_instance, p_name, r_ret); \
} \ } \
return false; \ return false; \
} \ } \
@ -304,7 +308,7 @@ public:
} \ } \
} \ } \
\ \
static void free(void *data, GDExtensionClassInstancePtr ptr) { \ static void free(void * /*data*/, GDExtensionClassInstancePtr ptr) { \
if (ptr) { \ if (ptr) { \
m_class *cls = reinterpret_cast<m_class *>(ptr); \ m_class *cls = reinterpret_cast<m_class *>(ptr); \
cls->~m_class(); \ cls->~m_class(); \
@ -312,14 +316,14 @@ public:
} \ } \
} \ } \
\ \
static void *_gde_binding_create_callback(void *p_token, void *p_instance) { \ static void *_gde_binding_create_callback(void * /*p_token*/, void * /*p_instance*/) { \
return nullptr; \ return nullptr; \
} \ } \
\ \
static void _gde_binding_free_callback(void *p_token, void *p_instance, void *p_binding) { \ static void _gde_binding_free_callback(void * /*p_token*/, void * /*p_instance*/, void * /*p_binding*/) { \
} \ } \
\ \
static GDExtensionBool _gde_binding_reference_callback(void *p_token, void *p_instance, GDExtensionBool p_reference) { \ static GDExtensionBool _gde_binding_reference_callback(void * /*p_token*/, void * /*p_instance*/, GDExtensionBool /*p_reference*/) { \
return true; \ return true; \
} \ } \
\ \

View File

@ -393,17 +393,15 @@ MAKE_TYPED_ARRAY_INFO(Callable, Variant::CALLABLE)
MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL) MAKE_TYPED_ARRAY_INFO(Signal, Variant::SIGNAL)
MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY) MAKE_TYPED_ARRAY_INFO(Dictionary, Variant::DICTIONARY)
MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY) MAKE_TYPED_ARRAY_INFO(Array, Variant::ARRAY)
/* MAKE_TYPED_ARRAY_INFO(PackedByteArray, Variant::PACKED_BYTE_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<uint8_t>, Variant::PACKED_BYTE_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedInt32Array, Variant::PACKED_INT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<int32_t>, Variant::PACKED_INT32_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedInt64Array, Variant::PACKED_INT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<int64_t>, Variant::PACKED_INT64_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedFloat32Array, Variant::PACKED_FLOAT32_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<float>, Variant::PACKED_FLOAT32_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedFloat64Array, Variant::PACKED_FLOAT64_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<double>, Variant::PACKED_FLOAT64_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedStringArray, Variant::PACKED_STRING_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<String>, Variant::PACKED_STRING_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedVector2Array, Variant::PACKED_VECTOR2_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Vector2>, Variant::PACKED_VECTOR2_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedVector3Array, Variant::PACKED_VECTOR3_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Vector3>, Variant::PACKED_VECTOR3_ARRAY) MAKE_TYPED_ARRAY_INFO(PackedColorArray, Variant::PACKED_COLOR_ARRAY)
MAKE_TYPED_ARRAY_INFO(Vector<Color>, Variant::PACKED_COLOR_ARRAY)
*/
#define CLASS_INFO(m_type) (GetTypeInfo<m_type *>::get_class_info()) #define CLASS_INFO(m_type) (GetTypeInfo<m_type *>::get_class_info())

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); set(p_value);
} }
}; };

View File

@ -21,5 +21,17 @@ android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so"
android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so" android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so"
android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so" android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so"
android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so" android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so"
web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm" ios.debug = "res://bin/libgdexample.ios.template_debug.xcframework"
web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm" ios.release = "res://bin/libgdexample.ios.template_release.xcframework"
web.debug.threads.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm"
web.release.threads.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm"
web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.nothreads.wasm"
web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.nothreads.wasm"
[dependencies]
ios.debug = {
"res://bin/libgodot-cpp.ios.template_debug.xcframework": ""
}
ios.release = {
"res://bin/libgodot-cpp.ios.template_release.xcframework": ""
}

View File

@ -147,6 +147,7 @@ void Example::_bind_methods() {
ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops); ClassDB::bind_method(D_METHOD("test_string_ops"), &Example::test_string_ops);
ClassDB::bind_method(D_METHOD("test_str_utility"), &Example::test_str_utility); 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_is_forty_two"), &Example::test_string_is_forty_two);
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_ops"), &Example::test_vector_ops);
ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list); ClassDB::bind_method(D_METHOD("test_vector_init_list"), &Example::test_vector_init_list);
@ -327,6 +328,19 @@ bool Example::test_string_is_forty_two(const String &p_string) const {
return strcmp(p_string.utf8().ptr(), "forty two") == 0; return strcmp(p_string.utf8().ptr(), "forty two") == 0;
} }
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 { int Example::test_vector_ops() const {
PackedInt32Array arr; PackedInt32Array arr;
arr.push_back(10); arr.push_back(10);

View File

@ -126,6 +126,7 @@ public:
String test_string_ops() const; String test_string_ops() const;
String test_str_utility() const; String test_str_utility() const;
bool test_string_is_forty_two(const String &p_str) const; bool test_string_is_forty_two(const String &p_str) const;
TypedArray<PackedInt32Array> test_typed_array_of_packed() const;
int test_vector_ops() const; int test_vector_ops() const;
int test_vector_init_list() const; int test_vector_init_list() const;

View File

@ -267,6 +267,8 @@ def options(opts, env):
) )
) )
opts.Add(BoolVariable(key="threads", help="Enable threading support", default=env.get("threads", True)))
# compiledb # compiledb
opts.Add( opts.Add(
BoolVariable( BoolVariable(
@ -396,6 +398,9 @@ def generate(env):
tool.generate(env) tool.generate(env)
if env["threads"]:
env.Append(CPPDEFINES=["THREADS_ENABLED"])
if env.editor_build: if env.editor_build:
env.Append(CPPDEFINES=["TOOLS_ENABLED"]) env.Append(CPPDEFINES=["TOOLS_ENABLED"])
@ -436,6 +441,8 @@ def generate(env):
suffix += "." + env["arch"] suffix += "." + env["arch"]
if env["ios_simulator"]: if env["ios_simulator"]:
suffix += ".simulator" suffix += ".simulator"
if not env["threads"]:
suffix += ".nothreads"
env["suffix"] = suffix # Exposed when included from another project env["suffix"] = suffix # Exposed when included from another project
env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"] env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]

View File

@ -1,3 +1,4 @@
import codecs
import os import os
import subprocess import subprocess
import sys import sys
@ -5,17 +6,6 @@ import sys
import common_compiler_flags import common_compiler_flags
from SCons.Variables import BoolVariable from SCons.Variables import BoolVariable
if sys.version_info < (3,):
def decode_utf8(x):
return x
else:
import codecs
def decode_utf8(x):
return codecs.utf_8_decode(x)[0]
def has_ios_osxcross(): def has_ios_osxcross():
return "OSXCROSS_IOS" in os.environ return "OSXCROSS_IOS" in os.environ
@ -53,9 +43,9 @@ def generate(env):
if sys.platform == "darwin": if sys.platform == "darwin":
if env["IOS_SDK_PATH"] == "": if env["IOS_SDK_PATH"] == "":
try: try:
env["IOS_SDK_PATH"] = decode_utf8( env["IOS_SDK_PATH"] = codecs.utf_8_decode(
subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-path"]).strip() subprocess.check_output(["xcrun", "--sdk", sdk_name, "--show-sdk-path"]).strip()
) )[0]
except (subprocess.CalledProcessError, OSError): except (subprocess.CalledProcessError, OSError):
raise ValueError( raise ValueError(
"Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name) "Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name)

View File

@ -34,12 +34,17 @@ def generate(env):
env["SHLIBSUFFIX"] = ".wasm" env["SHLIBSUFFIX"] = ".wasm"
# Thread support (via SharedArrayBuffer). # Thread support (via SharedArrayBuffer).
env.Append(CCFLAGS=["-s", "USE_PTHREADS=1"]) if env["threads"]:
env.Append(LINKFLAGS=["-s", "USE_PTHREADS=1"]) env.Append(CCFLAGS=["-sUSE_PTHREADS=1"])
env.Append(LINKFLAGS=["-sUSE_PTHREADS=1"])
# Build as side module (shared library). # Build as side module (shared library).
env.Append(CPPFLAGS=["-s", "SIDE_MODULE=1"]) env.Append(CCFLAGS=["-sSIDE_MODULE=1"])
env.Append(LINKFLAGS=["-s", "SIDE_MODULE=1"]) env.Append(LINKFLAGS=["-sSIDE_MODULE=1"])
# Force wasm longjmp mode.
env.Append(CCFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
env.Append(LINKFLAGS=["-sSUPPORT_LONGJMP='wasm'"])
env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"]) env.Append(CPPDEFINES=["WEB_ENABLED", "UNIX_ENABLED"])