From 3475ad69b38e2784cdadae13ead7eeb7c9b61be7 Mon Sep 17 00:00:00 2001 From: Ivorius Date: Wed, 29 Dec 2021 15:02:38 +0100 Subject: [PATCH 01/18] In CMakeLists, use the new FindPython3 instead of FindPython --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 801b36207..bb7900c86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,20 +115,20 @@ else() endif() # Generate source from the bindings file -find_package(PythonInterp 3.4 REQUIRED) # pathlib should be present +find_package(Python3 3.4 REQUIRED) # pathlib should be present if(GENERATE_TEMPLATE_GET_NODE) set(GENERATE_BINDING_PARAMETERS "True") else() set(GENERATE_BINDING_PARAMETERS "False") endif() -execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_CUSTOM_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)" +execute_process(COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.print_file_list(\"${GODOT_CUSTOM_API_FILE}\", \"${CMAKE_CURRENT_BINARY_DIR}\", headers=True, sources=True)" WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GENERATED_FILES_LIST ) add_custom_command(OUTPUT ${GENERATED_FILES_LIST} - COMMAND "${PYTHON_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${CMAKE_CURRENT_BINARY_DIR}\")" + COMMAND "${Python3_EXECUTABLE}" "-c" "import binding_generator; binding_generator.generate_bindings(\"${GODOT_CUSTOM_API_FILE}\", \"${GENERATE_BINDING_PARAMETERS}\", \"${CMAKE_CURRENT_BINARY_DIR}\")" VERBATIM WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} MAIN_DEPENDENCY ${GODOT_CUSTOM_API_FILE} From 2ce688d2ad217a3aae298a8e80fd41778fe618bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 23 Jan 2022 23:28:40 +0100 Subject: [PATCH 02/18] headers: Sync with upstream commit 31a7ddb (4.0-alpha1) --- godot-headers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot-headers b/godot-headers index c9fe81be4..3978d90e8 160000 --- a/godot-headers +++ b/godot-headers @@ -1 +1 @@ -Subproject commit c9fe81be49d1fd1b9b0bdcc34632192babfccec5 +Subproject commit 3978d90e8910e74e812055af602dc20607727e35 From 4e2411ad98089235eb90ac427354031b8aab70cc Mon Sep 17 00:00:00 2001 From: Bastiaan Olij Date: Thu, 27 Jan 2022 09:56:46 +1100 Subject: [PATCH 03/18] headers: Sync with upstream commit 9f5c18c --- godot-headers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot-headers b/godot-headers index 3978d90e8..7306075c4 160000 --- a/godot-headers +++ b/godot-headers @@ -1 +1 @@ -Subproject commit 3978d90e8910e74e812055af602dc20607727e35 +Subproject commit 7306075c40ed8f6ab71ef62a62c6267ed18fb49a From 31eddf9e8714f56aac552f00cf27c2aeccc41ed6 Mon Sep 17 00:00:00 2001 From: Patrick Exner Date: Sat, 29 Jan 2022 16:56:31 +0100 Subject: [PATCH 04/18] Update README file for macos support --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c49a915ba..59a807953 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,12 @@ entry_symbol = "example_library_init" [libraries] -linux.64 = "bin/x11/libgdexample.so" -windows.64 = "bin/win64/libgdexample.dll" +linux.64.debug = "bin/libgdexample.linux.debug.64.so" +linux.64.release = "bin/libgdexample.linux.release.64.so" +windows.64.debug = "bin/libgdexample.windows.debug.64.dll" +windows.64.release = "bin/libgdexample.windows.release.64.dll" +macos.debug = "bin/libgdexample.debug.framework" +macos.release = "bin/libgdexample.release.framework" ``` The `entry_symbol` is the name of the function that initializes your library. It should be similar to following layout: From 24c94e4af0399f7a1f39738942a0b24adde39db6 Mon Sep 17 00:00:00 2001 From: Zhehang Ding Date: Mon, 7 Feb 2022 00:31:48 -0800 Subject: [PATCH 05/18] Add missing Vector3::operator Vector3i --- src/variant/vector3.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/variant/vector3.cpp b/src/variant/vector3.cpp index 5c12c75bc..6cfb92af7 100644 --- a/src/variant/vector3.cpp +++ b/src/variant/vector3.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace godot { @@ -121,4 +122,8 @@ Vector3::operator String() const { return (String::num(x, 5) + ", " + String::num(y, 5) + ", " + String::num(z, 5)); } +Vector3::operator Vector3i() const { + return Vector3i(x, y, z); +} + } // namespace godot From df0e28fe43ae40efe13df1dacc8f2fc617cc1e4c Mon Sep 17 00:00:00 2001 From: Zhehang Ding Date: Mon, 7 Feb 2022 01:21:36 -0800 Subject: [PATCH 06/18] Add missing Vector2::operator Vector2i() --- include/godot_cpp/variant/vector2.hpp | 1 + src/variant/vector2.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index f7ae8b065..56a2c958a 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -151,6 +151,7 @@ class Vector2 { real_t aspect() const { return width / height; } operator String() const; + operator Vector2i() const; inline Vector2() {} inline Vector2(real_t p_x, real_t p_y) { diff --git a/src/variant/vector2.cpp b/src/variant/vector2.cpp index 3cc9fda52..7ba09102c 100644 --- a/src/variant/vector2.cpp +++ b/src/variant/vector2.cpp @@ -31,6 +31,7 @@ #include #include #include +#include namespace godot { @@ -38,6 +39,10 @@ Vector2::operator String() const { return String::num(x, 5) + ", " + String::num(y, 5); } +Vector2::operator Vector2i() const { + return Vector2i(x, y); +} + real_t Vector2::angle() const { return Math::atan2(y, x); } From 75b180d2cd54cbbcc2268247f671cd8257d16d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 9 Feb 2022 16:46:48 +0100 Subject: [PATCH 07/18] headers: Sync with upstream commit 79077e6 (4.0-alpha2) --- godot-headers | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/godot-headers b/godot-headers index 7306075c4..ac7e75bb2 160000 --- a/godot-headers +++ b/godot-headers @@ -1 +1 @@ -Subproject commit 7306075c40ed8f6ab71ef62a62c6267ed18fb49a +Subproject commit ac7e75bb2844ceea5844a821276989ab33ef0774 From cf3fcab6b4fcd0a5d76296b9fd8d3973e253ab80 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Wed, 29 Sep 2021 23:00:24 +0200 Subject: [PATCH 08/18] Always require C++17. Shuold fix other platforms. --- SConstruct | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index d56d0495c..f77f6f81e 100644 --- a/SConstruct +++ b/SConstruct @@ -165,6 +165,13 @@ if host_platform == "windows" and env["platform"] != "android": opts.Update(env) +# Require C++17 +if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]: + # MSVC + env.Append(CCFLAGS=["/std:c++17"]) +else: + env.Append(CCFLAGS=["-std=c++17"]) + if env["target"] == "debug": env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"]) @@ -172,7 +179,7 @@ if env["platform"] == "linux" or env["platform"] == "freebsd": if env["use_llvm"]: env["CXX"] = "clang++" - env.Append(CCFLAGS=["-fPIC", "-std=c++17", "-Wwrite-strings"]) + env.Append(CCFLAGS=["-fPIC", "-Wwrite-strings"]) env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"]) if env["target"] == "debug": @@ -201,8 +208,6 @@ elif env["platform"] == "osx": env.Append(LINKFLAGS=["-arch", env["macos_arch"]]) env.Append(CCFLAGS=["-arch", env["macos_arch"]]) - env.Append(CCFLAGS=["-std=c++17"]) - if env["macos_deployment_target"] != "default": env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]]) env.Append(LINKFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]]) @@ -246,7 +251,7 @@ elif env["platform"] == "ios": env["AR"] = compiler_path + "ar" env["RANLIB"] = compiler_path + "ranlib" - env.Append(CCFLAGS=["-std=c++17", "-arch", env["ios_arch"], "-isysroot", sdk_path]) + env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path]) env.Append( LINKFLAGS=[ "-arch", @@ -292,14 +297,16 @@ elif env["platform"] == "windows": # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff. env = Environment(ENV=os.environ, tools=["mingw"]) opts.Update(env) - # env = env.Clone(tools=['mingw']) + + # Still need to use C++17. + env.Append(CCFLAGS=["-std=c++17"]) env["SPAWN"] = mySpawn # Native or cross-compilation using MinGW if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env["use_mingw"]: # These options are for a release build even using target=debug - env.Append(CCFLAGS=["-O3", "-std=c++17", "-Wwrite-strings"]) + env.Append(CCFLAGS=["-O3", "-Wwrite-strings"]) env.Append( LINKFLAGS=[ "--static", From dcc52f4321ee143257858adefaf4cb55f63733a3 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 30 Sep 2021 04:29:42 +0200 Subject: [PATCH 09/18] Library SCons boilerplate to build projects. Works by executing project `SConstruct`s file in a cloned env (a bit like Godot does for modules) so you don't have to worry about platform and toolchain setup. Convert the project test file to work as submodule, add it to CI Run with: ``` scons build_projects=test,/path/to/other/project ``` --- .github/workflows/ci.yml | 4 ++ SConstruct | 34 ++++++--- test/SConstruct | 148 +-------------------------------------- 3 files changed, 32 insertions(+), 154 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fce6c2d4f..af76eedc2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,6 +152,10 @@ jobs: # cd test # scons target=release use_mingw=yes -j $env:NUMBER_OF_PROCESSORS + - name: Build test + run: | + scons platform=${{ matrix.platform }} target=release ${{ matrix.flags }} -j2 build_projects=test + - name: Upload artifact uses: actions/upload-artifact@v2 with: diff --git a/SConstruct b/SConstruct index f77f6f81e..3105daf5f 100644 --- a/SConstruct +++ b/SConstruct @@ -144,6 +144,9 @@ opts.Add( ) opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True)) +opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) +opts.Add("build_projects", "List of projects to build (comma-separated list of paths).", "") + opts.Update(env) Help(opts.GenerateHelpText(env)) @@ -250,14 +253,13 @@ elif env["platform"] == "ios": env["CXX"] = compiler_path + "clang++" env["AR"] = compiler_path + "ar" env["RANLIB"] = compiler_path + "ranlib" + env["SHLIBSUFFIX"] = ".dylib" env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path]) env.Append( LINKFLAGS=[ "-arch", env["ios_arch"], - "-framework", - "Cocoa", "-Wl,-undefined,dynamic_lookup", "-isysroot", sdk_path, @@ -300,8 +302,13 @@ elif env["platform"] == "windows": # Still need to use C++17. env.Append(CCFLAGS=["-std=c++17"]) + # Don't want lib prefixes + env["IMPLIBPREFIX"] = "" + env["SHLIBPREFIX"] = "" + # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other). env["SPAWN"] = mySpawn + env.Replace(ARFLAGS=["q"]) # Native or cross-compilation using MinGW if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env["use_mingw"]: @@ -321,9 +328,10 @@ elif env["platform"] == "android": # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff. env = Environment(ENV=os.environ, tools=["mingw"]) opts.Update(env) - # env = env.Clone(tools=['mingw']) + # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other). env["SPAWN"] = mySpawn + env.Replace(ARFLAGS=["q"]) # Verify NDK root if not "ANDROID_NDK_ROOT" in env: @@ -389,11 +397,13 @@ elif env["platform"] == "android": env["CC"] = toolchain + "/bin/clang" env["CXX"] = toolchain + "/bin/clang++" env["AR"] = toolchain + "/bin/" + arch_info["tool_path"] + "-ar" + env["SHLIBSUFFIX"] = ".so" env.Append( CCFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"], "-fPIC"] ) # , '-fPIE', '-fno-addrsig', '-Oz']) env.Append(CCFLAGS=arch_info["ccflags"]) + env.Append(LINKFLAGS=["--target=" + arch_info["target"] + env["android_api_level"], "-march=" + arch_info["march"]]) if env["target"] == "debug": env.Append(CCFLAGS=["-Og", "-g"]) @@ -481,8 +491,16 @@ elif env["platform"] == "javascript": elif env["platform"] == "osx": arch_suffix = env["macos_arch"] -library = env.StaticLibrary( - target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]), - source=sources, -) -Default(library) +library = None +env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["OBJSUFFIX"]) +library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]) + +if env["build_library"]: + library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) + Default(library) + +env["SHLIBSUFFIX"] = "{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["SHLIBSUFFIX"]) +env.Append(CPPPATH=[env.Dir(f) for f in ["gen/include", "include", "godot-headers"]]) +env.Append(LIBPATH=[env.Dir("bin")]) +env.Append(LIBS=library_name) +Return("env") diff --git a/test/SConstruct b/test/SConstruct index 0bd80acc3..b2ddba186 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -2,79 +2,7 @@ import os import sys -# default values, adapt them to your setup -default_library_name = "libgdexample" -default_target_path = "demo/bin/" - -# Local dependency paths, adapt them to your setup -cpp_bindings_path = "../" -# cpp_bindings_path = "godot-cpp/" -godot_headers_path = cpp_bindings_path + "godot-headers/" -cpp_library = "libgodot-cpp" - -# Try to detect the host platform automatically. -# This is used if no `platform` argument is passed -if sys.platform.startswith("linux"): - host_platform = "linux" -elif sys.platform.startswith("freebsd"): - host_platform = "freebsd" -elif sys.platform == "darwin": - host_platform = "osx" -elif sys.platform == "win32" or sys.platform == "msys": - host_platform = "windows" -else: - raise ValueError("Could not detect platform automatically, please specify with " "platform=") - -env = Environment(ENV=os.environ) - -opts = Variables([], ARGUMENTS) - -# Define our options -opts.Add(EnumVariable("target", "Compilation target", "debug", allowed_values=("debug", "release"), ignorecase=2)) -opts.Add( - EnumVariable( - "platform", - "Compilation platform", - host_platform, - # We'll need to support these in due times - # allowed_values=("linux", "freebsd", "osx", "windows", "android", "ios", "javascript"), - allowed_values=("linux", "windows", "osx"), - ignorecase=2, - ) -) -opts.Add(EnumVariable("bits", "Target platform bits", "64", ("32", "64"))) -opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no")) -opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"])) -opts.Add(PathVariable("target_path", "The path where the lib is installed.", default_target_path, PathVariable.PathAccept)) -opts.Add(PathVariable("target_name", "The library name.", default_library_name, PathVariable.PathAccept)) - -# only support 64 at this time.. -bits = 64 - -# Updates the environment with the option variables. -opts.Update(env) -# Generates help for the -h scons option. -Help(opts.GenerateHelpText(env)) - -# This makes sure to keep the session environment variables on Windows. -# This way, you can run SCons in a Visual Studio 2017 prompt and it will find -# all the required tools -if host_platform == "windows" and env["platform"] != "android": - if env["bits"] == "64": - env = Environment(TARGET_ARCH="amd64") - elif env["bits"] == "32": - env = Environment(TARGET_ARCH="x86") - - opts.Update(env) - -# Process some arguments -if env["use_llvm"]: - env["CC"] = "clang" - env["CXX"] = "clang++" - -if env["platform"] == "": - print("No valid target platform selected.") - quit() +env = SConscript("../SConstruct") # For the reference: # - CCFLAGS are compilation flags shared between C and C++ @@ -84,82 +12,10 @@ if env["platform"] == "": # - CPPDEFINES are for pre-processor defines # - LINKFLAGS are for linking flags -if env["target"] == "debug": - env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"]) - -# Check our platform specifics -if env["platform"] == "osx": - env["target_path"] += "{}.{}.framework/".format(env["target_name"], env["target"]) - cpp_library += ".osx" - - if env["bits"] == "32": - raise ValueError("Only 64-bit builds are supported for the macOS target.") - - if env["macos_arch"] == "universal": - env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) - env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) - else: - env.Append(LINKFLAGS=["-arch", env["macos_arch"]]) - env.Append(CCFLAGS=["-arch", env["macos_arch"]]) - - env.Append(CXXFLAGS=["-std=c++17"]) - if env["target"] == "debug": - env.Append(CCFLAGS=["-g", "-O2"]) - else: - env.Append(CCFLAGS=["-g", "-O3"]) - - arch_suffix = env["macos_arch"] - -elif env["platform"] in ("x11", "linux"): - cpp_library += ".linux" - env.Append(CCFLAGS=["-fPIC"]) - env.Append(CXXFLAGS=["-std=c++17"]) - if env["target"] == "debug": - env.Append(CCFLAGS=["-g3", "-Og"]) - else: - env.Append(CCFLAGS=["-g", "-O3"]) - - arch_suffix = str(bits) -elif env["platform"] == "windows": - cpp_library += ".windows" - # This makes sure to keep the session environment variables on windows, - # that way you can run scons in a vs 2017 prompt and it will find all the required tools - env.Append(ENV=os.environ) - - env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"]) - env.Append(CCFLAGS=["-W3", "-GR"]) - env.Append(CXXFLAGS=["-std:c++17"]) - if env["target"] == "debug": - env.Append(CPPDEFINES=["_DEBUG"]) - env.Append(CCFLAGS=["-EHsc", "-MDd", "-ZI", "-FS"]) - env.Append(LINKFLAGS=["-DEBUG"]) - else: - env.Append(CPPDEFINES=["NDEBUG"]) - env.Append(CCFLAGS=["-O2", "-EHsc", "-MD"]) - - if not(env["use_llvm"]): - env.Append(CPPDEFINES=["TYPED_METHOD_BIND"]) - - arch_suffix = str(bits) - -# suffix our godot-cpp library -cpp_library += "." + env["target"] + "." + arch_suffix - -# make sure our binding library is properly includes -env.Append(CPPPATH=[".", godot_headers_path, cpp_bindings_path + "include/", cpp_bindings_path + "gen/include/"]) -env.Append(LIBPATH=[cpp_bindings_path + "bin/"]) -env.Append(LIBS=[cpp_library]) - # tweak this if you want to use different folders, or more folders, to store your source code in. env.Append(CPPPATH=["src/"]) sources = Glob("src/*.cpp") -if env["platform"] == "osx": - target_name = "{}.{}".format(env["target_name"], env["target"]) -else: - target_name = "{}.{}.{}.{}".format(env["target_name"], env["platform"], env["target"], arch_suffix) - -print(target_name) -library = env.SharedLibrary(target=env["target_path"] + target_name, source=sources) +library = env.SharedLibrary("demo/bin/libgdexample" + env["SHLIBSUFFIX"], source=sources) Default(library) From 90b7d056eee8fd589b42b329b712958577bc889e Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 10 Feb 2022 01:21:04 +0100 Subject: [PATCH 10/18] [CI] Use matrix for builds. --- .github/workflows/ci.yml | 185 +++++++++++++++------------------------ 1 file changed, 71 insertions(+), 114 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af76eedc2..f252fc888 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,9 +2,52 @@ name: Continuous integration on: [push, pull_request] jobs: - linux: - name: Build (Linux, GCC) - runs-on: ubuntu-18.04 + build: + name: ${{ matrix.name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - name: 🐧 Linux (GCC) + os: ubuntu-18.04 + platform: linux + artifact-name: godot-cpp-linux-glibc2.27-x86_64-release + artifact-path: bin/libgodot-cpp.linux.release.64.a + + - name: 🏁 Windows (x86_64, MSVC) + os: windows-2019 + platform: windows + artifact-name: godot-cpp-windows-msvc2019-x86_64-release + artifact-path: bin/libgodot-cpp.windows.release.64.lib + + - name: 🏁 Windows (x86_64, MinGW) + os: windows-2019 + platform: windows + artifact-name: godot-cpp-linux-mingw-x86_64-release + artifact-path: bin/libgodot-cpp.windows.release.64.a + flags: use_mingw=yes + + - name: 🍎 macOS (universal) + os: macos-11 + platform: osx + artifact-name: godot-cpp-macos-universal-release + artifact-path: bin/libgodot-cpp.osx.release.universal.a + flags: macos_arch=universal + + - name: 🤖 Android (arm64) + os: ubuntu-18.04 + platform: android + artifact-name: godot-cpp-android-arm64-release + artifact-path: bin/libgodot-cpp.android.release.arm64v8.a + flags: android_arch=arm64v8 + + - name: 🍏 iOS (arm64) + os: macos-11 + platform: ios + artifact-name: godot-cpp-ios-arm64-release + artifact-path: bin/libgodot-cpp.ios.release.arm64.a + steps: - name: Checkout uses: actions/checkout@v2 @@ -16,26 +59,44 @@ jobs: with: python-version: '3.x' - - name: Install dependencies + - name: Linux dependencies + if: ${{ matrix.platform == 'linux' }} run: | sudo apt-get update -qq sudo apt-get install -qqq build-essential pkg-config + + - name: Install scons + run: | python -m pip install scons - - name: Build godot-cpp + - name: Windows GCC dependency + if: ${{ matrix.platform == 'windows' }} + # Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1"). + run: | + Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh') + scoop install gcc + g++ --version + gcc --version + + - name: Build godot-cpp (debug) + run: | + scons platform=${{ matrix.platform }} target=debug generate_bindings=yes ${{ matrix.flags }} -j2 + + - name: Build test without rebuilding godot-cpp (debug) run: | - scons target=release generate_bindings=yes -j $(nproc) + cd test + scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no -j2 - - name: Build test project + - name: Build test and godot-cpp (release) run: | cd test - scons target=release -j $(nproc) + scons platform=${{ matrix.platform }} target=release ${{ matrix.flags }} -j2 - name: Upload artifact uses: actions/upload-artifact@v2 with: - name: godot-cpp-linux-glibc2.27-x86_64-release - path: bin/libgodot-cpp.linux.release.64.a + name: ${{ matrix.artifact-name }} + path: ${{ matrix.artifact-path }} if-no-files-found: error linux-cmake: @@ -86,110 +147,6 @@ jobs: cd test && cmake -DCMAKE_BUILD_TYPE=Release -GNinja . cmake --build . -j $(nproc) - windows-msvc: - name: Build (Windows, MSVC) - runs-on: windows-2019 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Set up Python (for SCons) - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install scons - - - name: Build godot-cpp - run: | - scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS - - - name: Build test project - run: | - cd test - scons target=release -j $env:NUMBER_OF_PROCESSORS - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: godot-cpp-windows-msvc2019-x86_64-release - path: bin/libgodot-cpp.windows.release.64.lib - if-no-files-found: error - - windows-mingw: - name: Build (Windows, MinGW) - runs-on: windows-2019 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Set up Python (for SCons) - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install scons - - - name: Build godot-cpp - # Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1"). - run: | - Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh') - scoop install gcc - g++ --version - gcc --version - scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS - - #- name: Build test project (TODO currently not supported, leaving uncommented as a reminder to fix this) - # run: | - # cd test - # scons target=release use_mingw=yes -j $env:NUMBER_OF_PROCESSORS - - - name: Build test - run: | - scons platform=${{ matrix.platform }} target=release ${{ matrix.flags }} -j2 build_projects=test - - - name: Upload artifact - uses: actions/upload-artifact@v2 - with: - name: godot-cpp-linux-mingw-x86_64-release - path: bin/libgodot-cpp.windows.release.64.a - if-no-files-found: error - - macos: - name: Build (macOS, Clang, universal / x86_64 + arm64) - runs-on: macos-11 - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - submodules: recursive - - - name: Set up Python (for SCons) - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - - name: Install dependencies - run: | - python -m pip install scons - - - name: Build godot-cpp - run: | - scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu) - - - name: Build test project - run: | - cd test - scons target=release -j $(sysctl -n hw.logicalcpu) - static-checks: name: Static Checks (clang-format) runs-on: ubuntu-20.04 From f5172016b80549bd107850c0845ff208a5b7f3a2 Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 10 Feb 2022 05:38:54 +0100 Subject: [PATCH 11/18] [Build] Fix exposed suffix, remove unused option. --- SConstruct | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SConstruct b/SConstruct index 3105daf5f..35c19a92e 100644 --- a/SConstruct +++ b/SConstruct @@ -145,7 +145,6 @@ opts.Add( opts.Add(BoolVariable("generate_template_get_node", "Generate a template version of the Node class's get_node.", True)) opts.Add(BoolVariable("build_library", "Build the godot-cpp library.", True)) -opts.Add("build_projects", "List of projects to build (comma-separated list of paths).", "") opts.Update(env) Help(opts.GenerateHelpText(env)) @@ -236,7 +235,6 @@ elif env["platform"] == "ios": if env["ios_simulator"]: sdk_name = "iphonesimulator" env.Append(CCFLAGS=["-mios-simulator-version-min=10.0"]) - env["LIBSUFFIX"] = ".simulator" + env["LIBSUFFIX"] else: sdk_name = "iphoneos" env.Append(CCFLAGS=["-miphoneos-version-min=10.0"]) @@ -486,6 +484,8 @@ if env["platform"] == "android": arch_suffix = env["android_arch"] elif env["platform"] == "ios": arch_suffix = env["ios_arch"] + if env["ios_simulator"]: + arch_suffix += ".simulator" elif env["platform"] == "javascript": arch_suffix = "wasm" elif env["platform"] == "osx": @@ -499,7 +499,7 @@ if env["build_library"]: library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) Default(library) -env["SHLIBSUFFIX"] = "{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["SHLIBSUFFIX"]) +env["SHLIBSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["SHLIBSUFFIX"]) env.Append(CPPPATH=[env.Dir(f) for f in ["gen/include", "include", "godot-headers"]]) env.Append(LIBPATH=[env.Dir("bin")]) env.Append(LIBS=library_name) From b6b64bcd7080b0abce8f454b11446dab6b0f30ae Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 10 Feb 2022 16:18:22 +0200 Subject: [PATCH 12/18] [macOS] Restore demo library output names. --- SConstruct | 43 ++++++++++--------- test/SConstruct | 5 ++- .../Resources/Info.plist | 2 +- .../Resources/Info.plist | 2 +- test/demo/example.gdextension | 4 +- 5 files changed, 30 insertions(+), 26 deletions(-) rename test/demo/bin/{libgdexample.debug.framework => libgdexample.osx.debug.framework}/Resources/Info.plist (94%) rename test/demo/bin/{libgdexample.release.framework => libgdexample.osx.release.framework}/Resources/Info.plist (94%) diff --git a/SConstruct b/SConstruct index 35c19a92e..d748f63aa 100644 --- a/SConstruct +++ b/SConstruct @@ -125,7 +125,7 @@ opts.Add(EnumVariable("android_arch", "Target Android architecture", "armv7", [" opts.Add("macos_deployment_target", "macOS deployment target", "default") opts.Add("macos_sdk_path", "macOS SDK path", "") opts.Add(EnumVariable("macos_arch", "Target macOS architecture", "universal", ["universal", "x86_64", "arm64"])) -opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["armv7", "arm64", "x86_64"])) +opts.Add(EnumVariable("ios_arch", "Target iOS architecture", "arm64", ["universal", "arm64", "x86_64"])) opts.Add(BoolVariable("ios_simulator", "Target iOS Simulator", False)) opts.Add( "IPHONEPATH", @@ -253,17 +253,19 @@ elif env["platform"] == "ios": env["RANLIB"] = compiler_path + "ranlib" env["SHLIBSUFFIX"] = ".dylib" - env.Append(CCFLAGS=["-arch", env["ios_arch"], "-isysroot", sdk_path]) - env.Append( - LINKFLAGS=[ - "-arch", - env["ios_arch"], - "-Wl,-undefined,dynamic_lookup", - "-isysroot", - sdk_path, - "-F" + sdk_path, - ] - ) + if env["ios_arch"] == "universal": + if env["ios_simulator"]: + env.Append(LINKFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + env.Append(CCFLAGS=["-arch", "x86_64", "-arch", "arm64"]) + else: + env.Append(LINKFLAGS=["-arch", "arm64"]) + env.Append(CCFLAGS=["-arch", "arm64"]) + else: + env.Append(LINKFLAGS=["-arch", env["ios_arch"]]) + env.Append(CCFLAGS=["-arch", env["ios_arch"]]) + + env.Append(CCFLAGS=["-isysroot", sdk_path]) + env.Append(LINKFLAGS=["-isysroot", sdk_path, "-F" + sdk_path,]) if env["target"] == "debug": env.Append(CCFLAGS=["-Og", "-g"]) @@ -479,27 +481,26 @@ add_sources(sources, "src/variant", "cpp") add_sources(sources, "gen/src/variant", "cpp") add_sources(sources, "gen/src/classes", "cpp") -arch_suffix = env["bits"] +env["arch_suffix"] = env["bits"] if env["platform"] == "android": - arch_suffix = env["android_arch"] + env["arch_suffix"] = env["android_arch"] elif env["platform"] == "ios": - arch_suffix = env["ios_arch"] + env["arch_suffix"] = env["ios_arch"] if env["ios_simulator"]: - arch_suffix += ".simulator" + env["arch_suffix"] += ".simulator" elif env["platform"] == "javascript": - arch_suffix = "wasm" + env["arch_suffix"] = "wasm" elif env["platform"] == "osx": - arch_suffix = env["macos_arch"] + env["arch_suffix"] = env["macos_arch"] library = None -env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["OBJSUFFIX"]) -library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]) +env["OBJSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["OBJSUFFIX"]) +library_name = "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["LIBSUFFIX"]) if env["build_library"]: library = env.StaticLibrary(target=env.File("bin/%s" % library_name), source=sources) Default(library) -env["SHLIBSUFFIX"] = ".{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["SHLIBSUFFIX"]) env.Append(CPPPATH=[env.Dir(f) for f in ["gen/include", "include", "godot-headers"]]) env.Append(LIBPATH=[env.Dir("bin")]) env.Append(LIBS=library_name) diff --git a/test/SConstruct b/test/SConstruct index b2ddba186..6f700f472 100644 --- a/test/SConstruct +++ b/test/SConstruct @@ -16,6 +16,9 @@ env = SConscript("../SConstruct") env.Append(CPPPATH=["src/"]) sources = Glob("src/*.cpp") -library = env.SharedLibrary("demo/bin/libgdexample" + env["SHLIBSUFFIX"], source=sources) +if env["platform"] == "osx": + library = env.SharedLibrary("demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(env["platform"], env["target"], env["platform"], env["target"]), source=sources) +else: + library = env.SharedLibrary("demo/bin/libgdexample.{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"]), source=sources) Default(library) diff --git a/test/demo/bin/libgdexample.debug.framework/Resources/Info.plist b/test/demo/bin/libgdexample.osx.debug.framework/Resources/Info.plist similarity index 94% rename from test/demo/bin/libgdexample.debug.framework/Resources/Info.plist rename to test/demo/bin/libgdexample.osx.debug.framework/Resources/Info.plist index 0395b3767..d3e521b1d 100644 --- a/test/demo/bin/libgdexample.debug.framework/Resources/Info.plist +++ b/test/demo/bin/libgdexample.osx.debug.framework/Resources/Info.plist @@ -9,7 +9,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - libgdexample.debug + libgdexample.osx.debug CFBundlePackageType FMWK CFBundleShortVersionString diff --git a/test/demo/bin/libgdexample.release.framework/Resources/Info.plist b/test/demo/bin/libgdexample.osx.release.framework/Resources/Info.plist similarity index 94% rename from test/demo/bin/libgdexample.release.framework/Resources/Info.plist rename to test/demo/bin/libgdexample.osx.release.framework/Resources/Info.plist index 827d8639d..bda7622f6 100644 --- a/test/demo/bin/libgdexample.release.framework/Resources/Info.plist +++ b/test/demo/bin/libgdexample.osx.release.framework/Resources/Info.plist @@ -9,7 +9,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - libgdexample.release + libgdexample.osx.release CFBundlePackageType FMWK CFBundleShortVersionString diff --git a/test/demo/example.gdextension b/test/demo/example.gdextension index a654bde51..a963bdc7e 100644 --- a/test/demo/example.gdextension +++ b/test/demo/example.gdextension @@ -8,5 +8,5 @@ linux.64.debug = "bin/libgdexample.linux.debug.64.so" linux.64.release = "bin/libgdexample.linux.release.64.so" windows.64.debug = "bin/libgdexample.windows.debug.64.dll" windows.64.release = "bin/libgdexample.windows.release.64.dll" -macos.debug = "bin/libgdexample.debug.framework" -macos.release = "bin/libgdexample.release.framework" +macos.debug = "bin/libgdexample.osx.debug.framework" +macos.release = "bin/libgdexample.osx.release.framework" From bf8fc4c53d07cf8ac4d8343364899c197076fbc2 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 9 Feb 2022 12:36:22 +0200 Subject: [PATCH 13/18] Add `ptr()` / `ptrw()` to the arrays, add missing `String` methods, add missing `CharString` method implementations. --- binding_generator.py | 10 +- include/godot_cpp/variant/aabb.hpp | 10 +- include/godot_cpp/variant/basis.hpp | 6 +- include/godot_cpp/variant/char_string.hpp | 12 ++ include/godot_cpp/variant/color.hpp | 8 +- include/godot_cpp/variant/plane.hpp | 8 +- include/godot_cpp/variant/quaternion.hpp | 6 +- include/godot_cpp/variant/rect2.hpp | 16 +- include/godot_cpp/variant/rect2i.hpp | 8 +- include/godot_cpp/variant/transform2d.hpp | 6 +- include/godot_cpp/variant/transform3d.hpp | 6 +- include/godot_cpp/variant/variant.hpp | 2 +- include/godot_cpp/variant/vector2.hpp | 6 +- include/godot_cpp/variant/vector2i.hpp | 6 +- include/godot_cpp/variant/vector3.hpp | 6 +- include/godot_cpp/variant/vector3i.hpp | 6 +- src/core/method_bind.cpp | 2 +- src/variant/char_string.cpp | 140 +++++++++++++-- src/variant/packed_arrays.cpp | 72 ++++++++ src/variant/variant.cpp | 202 +++++++++++----------- 20 files changed, 380 insertions(+), 158 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index 753d67994..ff59ce749 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -246,7 +246,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append(f"\tstatic constexpr size_t {snake_class_name}_SIZE = {size};") result.append(f"\tuint8_t opaque[{snake_class_name}_SIZE] = {{}};") result.append( - f"\t_FORCE_INLINE_ GDNativeTypePtr ptr() const {{ return const_cast(&opaque); }}" + f"\t_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const {{ return const_cast(&opaque); }}" ) result.append("") @@ -378,6 +378,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl # Special cases. if class_name == "String": + result.append("\tstatic String utf8(const char *from, int len = -1);") + result.append("\tvoid parse_utf8(const char *from, int len = -1);") + result.append("\tstatic String utf16(const char16_t *from, int len = -1);") + result.append("\tvoid parse_utf16(const char16_t *from, int len = -1);") result.append("\tCharString utf8() const;") result.append("\tCharString ascii() const;") result.append("\tChar16String utf16() const;") @@ -426,6 +430,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append("bool operator!=(const char32_t *p_str) const;") result.append(f"\tconst char32_t &operator[](int p_index) const;") result.append(f"\tchar32_t &operator[](int p_index);") + result.append(f"\tconst char32_t *ptr() const;") + result.append(f"\tchar32_t *ptrw();") if class_name == "Array": result.append("\ttemplate ") @@ -443,6 +449,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl return_type = "float" result.append(f"\tconst " + return_type + f" &operator[](int p_index) const;") result.append(f"\t" + return_type + f" &operator[](int p_index);") + result.append(f"\tconst " + return_type + f" *ptr() const;") + result.append(f"\t" + return_type + f" *ptrw();") if class_name == "Array": result.append(f"\tconst Variant &operator[](int p_index) const;") diff --git a/include/godot_cpp/variant/aabb.hpp b/include/godot_cpp/variant/aabb.hpp index f654aae1a..2cfcc2abb 100644 --- a/include/godot_cpp/variant/aabb.hpp +++ b/include/godot_cpp/variant/aabb.hpp @@ -44,9 +44,11 @@ namespace godot { class AABB { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Vector3 position; Vector3 size; @@ -73,8 +75,8 @@ class AABB { inline bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this AABB merge(const AABB &p_with) const; - void merge_with(const AABB &p_aabb); ///merge with another AABB - AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs + void merge_with(const AABB &p_aabb); /// merge with another AABB + AABB intersection(const AABB &p_aabb) const; /// get box where two intersect, empty if no intersection occurs bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const; bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const; inline bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const; diff --git a/include/godot_cpp/variant/basis.hpp b/include/godot_cpp/variant/basis.hpp index 5dfa95ec7..8f49c7ace 100644 --- a/include/godot_cpp/variant/basis.hpp +++ b/include/godot_cpp/variant/basis.hpp @@ -38,9 +38,11 @@ namespace godot { class Basis { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Vector3 elements[3] = { Vector3(1, 0, 0), Vector3(0, 1, 0), diff --git a/include/godot_cpp/variant/char_string.hpp b/include/godot_cpp/variant/char_string.hpp index 3ba894865..469a8e3ce 100644 --- a/include/godot_cpp/variant/char_string.hpp +++ b/include/godot_cpp/variant/char_string.hpp @@ -48,6 +48,9 @@ class CharString { int length() const; const char *get_data() const; + CharString(CharString &&p_str); + void operator=(CharString &&p_str); + CharString() {} ~CharString(); }; @@ -63,6 +66,9 @@ class Char16String { int length() const; const char16_t *get_data() const; + Char16String(Char16String &&p_str); + void operator=(Char16String &&p_str); + Char16String() {} ~Char16String(); }; @@ -78,6 +84,9 @@ class Char32String { int length() const; const char32_t *get_data() const; + Char32String(Char32String &&p_str); + void operator=(Char32String &&p_str); + Char32String() {} ~Char32String(); }; @@ -93,6 +102,9 @@ class CharWideString { int length() const; const wchar_t *get_data() const; + CharWideString(CharWideString &&p_str); + void operator=(CharWideString &&p_str); + CharWideString() {} ~CharWideString(); }; diff --git a/include/godot_cpp/variant/color.hpp b/include/godot_cpp/variant/color.hpp index d8948d12d..df768338e 100644 --- a/include/godot_cpp/variant/color.hpp +++ b/include/godot_cpp/variant/color.hpp @@ -38,9 +38,11 @@ namespace godot { class String; class Color { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: union { struct { float r; @@ -198,7 +200,7 @@ class Color { static Color from_hsv(float p_h, float p_s, float p_v, float p_a); static Color from_rgbe9995(uint32_t p_rgbe); - inline bool operator<(const Color &p_color) const; //used in set keys + inline bool operator<(const Color &p_color) const; // used in set keys operator String() const; // For the binder. diff --git a/include/godot_cpp/variant/plane.hpp b/include/godot_cpp/variant/plane.hpp index aa7ccae87..4527e9eed 100644 --- a/include/godot_cpp/variant/plane.hpp +++ b/include/godot_cpp/variant/plane.hpp @@ -38,14 +38,16 @@ namespace godot { class Plane { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Vector3 normal; real_t d = 0; void set_normal(const Vector3 &p_normal); - inline Vector3 get_normal() const { return normal; }; ///Point is coplanar, CMP_EPSILON for precision + inline Vector3 get_normal() const { return normal; }; /// Point is coplanar, CMP_EPSILON for precision void normalize(); Plane normalized() const; diff --git a/include/godot_cpp/variant/quaternion.hpp b/include/godot_cpp/variant/quaternion.hpp index e87862cd4..dd7319dc1 100644 --- a/include/godot_cpp/variant/quaternion.hpp +++ b/include/godot_cpp/variant/quaternion.hpp @@ -37,9 +37,11 @@ namespace godot { class Quaternion { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: union { struct { real_t x; diff --git a/include/godot_cpp/variant/rect2.hpp b/include/godot_cpp/variant/rect2.hpp index e5a25ca56..f696bca90 100644 --- a/include/godot_cpp/variant/rect2.hpp +++ b/include/godot_cpp/variant/rect2.hpp @@ -40,9 +40,11 @@ namespace godot { class Transform2D; class Rect2 { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Point2 position; Size2 size; @@ -161,7 +163,7 @@ class Rect2 { new_rect.size.x = Math::max(p_rect.position.x + p_rect.size.x, position.x + size.x); new_rect.size.y = Math::max(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.position; //make relative again + new_rect.size = new_rect.size - new_rect.position; // make relative again return new_rect; } @@ -225,7 +227,7 @@ class Rect2 { return r; } - inline void expand_to(const Vector2 &p_vector) { //in place function for speed + inline void expand_to(const Vector2 &p_vector) { // in place function for speed Vector2 begin = position; Vector2 end = position + size; @@ -279,7 +281,7 @@ class Rect2 { continue; } - //check inside + // check inside Vector2 tg = r.orthogonal(); float s = tg.dot(center) - tg.dot(a); if (s < 0.0) { @@ -288,7 +290,7 @@ class Rect2 { side_minus++; } - //check ray box + // check ray box r /= l; Vector2 ir((real_t)1.0 / r.x, (real_t)1.0 / r.y); @@ -309,7 +311,7 @@ class Rect2 { } if (side_plus * side_minus == 0) { - return true; //all inside + return true; // all inside } else { return false; } diff --git a/include/godot_cpp/variant/rect2i.hpp b/include/godot_cpp/variant/rect2i.hpp index f9d023fc0..9d82668b0 100644 --- a/include/godot_cpp/variant/rect2i.hpp +++ b/include/godot_cpp/variant/rect2i.hpp @@ -37,9 +37,11 @@ namespace godot { class Rect2i { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Point2i position; Size2i size; @@ -107,7 +109,7 @@ class Rect2i { new_rect.size.x = Math::max(p_rect.position.x + p_rect.size.x, position.x + size.x); new_rect.size.y = Math::max(p_rect.position.y + p_rect.size.y, position.y + size.y); - new_rect.size = new_rect.size - new_rect.position; //make relative again + new_rect.size = new_rect.size - new_rect.position; // make relative again return new_rect; } diff --git a/include/godot_cpp/variant/transform2d.hpp b/include/godot_cpp/variant/transform2d.hpp index 8e611d07c..ac9bc6d92 100644 --- a/include/godot_cpp/variant/transform2d.hpp +++ b/include/godot_cpp/variant/transform2d.hpp @@ -40,9 +40,11 @@ namespace godot { class Transform2D { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // M = (elements[0][0] elements[1][0]) // (elements[0][1] elements[1][1]) diff --git a/include/godot_cpp/variant/transform3d.hpp b/include/godot_cpp/variant/transform3d.hpp index 805042b92..953dbd648 100644 --- a/include/godot_cpp/variant/transform3d.hpp +++ b/include/godot_cpp/variant/transform3d.hpp @@ -40,9 +40,11 @@ namespace godot { class Transform3D { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: Basis basis; Vector3 origin; diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index 32536c8c6..06358a197 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -45,7 +45,7 @@ namespace godot { class Variant { uint8_t opaque[GODOT_CPP_VARIANT_SIZE]{ 0 }; - _FORCE_INLINE_ GDNativeVariantPtr ptr() const { return const_cast(&opaque); } + _FORCE_INLINE_ GDNativeVariantPtr _native_ptr() const { return const_cast(&opaque); } friend class GDExtensionBinding; friend class MethodBind; diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index f7ae8b065..05ba72fee 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -39,9 +39,11 @@ namespace godot { class Vector2i; class Vector2 { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: enum Axis { AXIS_X, AXIS_Y, diff --git a/include/godot_cpp/variant/vector2i.hpp b/include/godot_cpp/variant/vector2i.hpp index a97581289..69c68971c 100644 --- a/include/godot_cpp/variant/vector2i.hpp +++ b/include/godot_cpp/variant/vector2i.hpp @@ -38,9 +38,11 @@ namespace godot { class Vector2i { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: enum Axis { AXIS_X, AXIS_Y, diff --git a/include/godot_cpp/variant/vector3.hpp b/include/godot_cpp/variant/vector3.hpp index e435fb64f..f34aa054a 100644 --- a/include/godot_cpp/variant/vector3.hpp +++ b/include/godot_cpp/variant/vector3.hpp @@ -40,9 +40,11 @@ class Basis; class Vector3i; class Vector3 { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: enum Axis { AXIS_X, AXIS_Y, diff --git a/include/godot_cpp/variant/vector3i.hpp b/include/godot_cpp/variant/vector3i.hpp index 8351a8d5e..9aa034115 100644 --- a/include/godot_cpp/variant/vector3i.hpp +++ b/include/godot_cpp/variant/vector3i.hpp @@ -37,9 +37,11 @@ namespace godot { class Vector3i { -public: - _FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; } + _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } + + friend class Variant; +public: enum Axis { AXIS_X, AXIS_Y, diff --git a/src/core/method_bind.cpp b/src/core/method_bind.cpp index 4f746a152..4573eb7f4 100644 --- a/src/core/method_bind.cpp +++ b/src/core/method_bind.cpp @@ -103,7 +103,7 @@ void MethodBind::bind_call(void *p_method_userdata, GDExtensionClassInstancePtr Variant ret = bind->call(p_instance, p_args, p_argument_count, *r_error); // This assumes the return value is an empty Variant, so it doesn't need to call the destructor first. // Since only NativeExtensionMethodBind calls this from the Godot side, it should always be the case. - internal::gdn_interface->variant_new_copy(r_return, ret.ptr()); + internal::gdn_interface->variant_new_copy(r_return, ret._native_ptr()); } void MethodBind::bind_ptrcall(void *p_method_userdata, GDExtensionClassInstancePtr p_instance, const GDNativeTypePtr *p_args, GDNativeTypePtr r_return) { diff --git a/src/variant/char_string.cpp b/src/variant/char_string.cpp index 5bb6dee9b..c58c718b2 100644 --- a/src/variant/char_string.cpp +++ b/src/variant/char_string.cpp @@ -39,61 +39,157 @@ namespace godot { +int CharString::length() const { + return _length; +} + const char *CharString::get_data() const { return _data; } +CharString::CharString(CharString &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); +} + +void CharString::operator=(CharString &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); +} + CharString::CharString(const char *str, int length) : _data(str), _length(length) {} CharString::~CharString() { - memdelete_arr(_data); + if (_data != nullptr) { + memdelete_arr(_data); + } +} + +int Char16String::length() const { + return _length; +} + +const char16_t *Char16String::get_data() const { + return _data; +} + +Char16String::Char16String(Char16String &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); +} + +void Char16String::operator=(Char16String &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); } Char16String::Char16String(const char16_t *str, int length) : _data(str), _length(length) {} Char16String::~Char16String() { - memdelete_arr(_data); + if (_data != nullptr) { + memdelete_arr(_data); + } +} + +int Char32String::length() const { + return _length; +} + +const char32_t *Char32String::get_data() const { + return _data; +} + +Char32String::Char32String(Char32String &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); +} + +void Char32String::operator=(Char32String &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); } Char32String::Char32String(const char32_t *str, int length) : _data(str), _length(length) {} Char32String::~Char32String() { - memdelete_arr(_data); + if (_data != nullptr) { + memdelete_arr(_data); + } +} + +int CharWideString::length() const { + return _length; +} + +const wchar_t *CharWideString::get_data() const { + return _data; +} + +CharWideString::CharWideString(CharWideString &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); +} + +void CharWideString::operator=(CharWideString &&p_str) { + SWAP(_length, p_str._length); + SWAP(_data, p_str._data); } CharWideString::CharWideString(const wchar_t *str, int length) : _data(str), _length(length) {} CharWideString::~CharWideString() { - memdelete_arr(_data); + if (_data != nullptr) { + memdelete_arr(_data); + } } // Custom String functions that are not part of bound API. // It's easier to have them written in C++ directly than in a Python script that generates them. String::String(const char *from) { - internal::gdn_interface->string_new_with_utf8_chars(ptr(), from); + internal::gdn_interface->string_new_with_latin1_chars(_native_ptr(), from); } String::String(const wchar_t *from) { - internal::gdn_interface->string_new_with_wide_chars(ptr(), from); + internal::gdn_interface->string_new_with_wide_chars(_native_ptr(), from); } String::String(const char16_t *from) { - internal::gdn_interface->string_new_with_utf16_chars(ptr(), from); + internal::gdn_interface->string_new_with_utf16_chars(_native_ptr(), from); } String::String(const char32_t *from) { - internal::gdn_interface->string_new_with_utf32_chars(ptr(), from); + internal::gdn_interface->string_new_with_utf32_chars(_native_ptr(), from); +} + +String String::utf8(const char *from, int len) { + String ret; + ret.parse_utf8(from, len); + return ret; +} + +void String::parse_utf8(const char *from, int len) { + internal::gdn_interface->string_new_with_utf8_chars_and_len(_native_ptr(), from, len); +} + +String String::utf16(const char16_t *from, int len) { + String ret; + ret.parse_utf16(from, len); + return ret; +} + +void String::parse_utf16(const char16_t *from, int len) { + internal::gdn_interface->string_new_with_utf16_chars_and_len(_native_ptr(), from, len); } CharString String::utf8() const { - int size = internal::gdn_interface->string_to_utf8_chars(ptr(), nullptr, 0); + int size = internal::gdn_interface->string_to_utf8_chars(_native_ptr(), nullptr, 0); char *cstr = memnew_arr(char, size + 1); - internal::gdn_interface->string_to_utf8_chars(ptr(), cstr, size + 1); + internal::gdn_interface->string_to_utf8_chars(_native_ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -101,9 +197,9 @@ CharString String::utf8() const { } CharString String::ascii() const { - int size = internal::gdn_interface->string_to_latin1_chars(ptr(), nullptr, 0); + int size = internal::gdn_interface->string_to_latin1_chars(_native_ptr(), nullptr, 0); char *cstr = memnew_arr(char, size + 1); - internal::gdn_interface->string_to_latin1_chars(ptr(), cstr, size + 1); + internal::gdn_interface->string_to_latin1_chars(_native_ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -111,9 +207,9 @@ CharString String::ascii() const { } Char16String String::utf16() const { - int size = internal::gdn_interface->string_to_utf16_chars(ptr(), nullptr, 0); + int size = internal::gdn_interface->string_to_utf16_chars(_native_ptr(), nullptr, 0); char16_t *cstr = memnew_arr(char16_t, size + 1); - internal::gdn_interface->string_to_utf16_chars(ptr(), cstr, size + 1); + internal::gdn_interface->string_to_utf16_chars(_native_ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -121,9 +217,9 @@ Char16String String::utf16() const { } Char32String String::utf32() const { - int size = internal::gdn_interface->string_to_utf32_chars(ptr(), nullptr, 0); + int size = internal::gdn_interface->string_to_utf32_chars(_native_ptr(), nullptr, 0); char32_t *cstr = memnew_arr(char32_t, size + 1); - internal::gdn_interface->string_to_utf32_chars(ptr(), cstr, size + 1); + internal::gdn_interface->string_to_utf32_chars(_native_ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -131,9 +227,9 @@ Char32String String::utf32() const { } CharWideString String::wide_string() const { - int size = internal::gdn_interface->string_to_wide_chars(ptr(), nullptr, 0); + int size = internal::gdn_interface->string_to_wide_chars(_native_ptr(), nullptr, 0); wchar_t *cstr = memnew_arr(wchar_t, size + 1); - internal::gdn_interface->string_to_wide_chars(ptr(), cstr, size + 1); + internal::gdn_interface->string_to_wide_chars(_native_ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -200,6 +296,14 @@ char32_t &String::operator[](int p_index) { return *internal::gdn_interface->string_operator_index((GDNativeStringPtr)this, p_index); } +const char32_t *String::ptr() const { + return internal::gdn_interface->string_operator_index_const((GDNativeStringPtr)this, 0); +} + +char32_t *String::ptrw() { + return internal::gdn_interface->string_operator_index((GDNativeStringPtr)this, 0); +} + bool operator==(const char *p_chr, const String &p_str) { return p_str == String(p_chr); } diff --git a/src/variant/packed_arrays.cpp b/src/variant/packed_arrays.cpp index bb6bba77a..1d523343e 100644 --- a/src/variant/packed_arrays.cpp +++ b/src/variant/packed_arrays.cpp @@ -54,6 +54,14 @@ uint8_t &PackedByteArray::operator[](int p_index) { return *internal::gdn_interface->packed_byte_array_operator_index((GDNativeTypePtr *)this, p_index); } +const uint8_t *PackedByteArray::ptr() const { + return internal::gdn_interface->packed_byte_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +uint8_t *PackedByteArray::ptrw() { + return internal::gdn_interface->packed_byte_array_operator_index((GDNativeTypePtr *)this, 0); +} + const Color &PackedColorArray::operator[](int p_index) const { const Color *color = (const Color *)internal::gdn_interface->packed_color_array_operator_index_const((GDNativeTypePtr *)this, p_index); return *color; @@ -64,6 +72,14 @@ Color &PackedColorArray::operator[](int p_index) { return *color; } +const Color *PackedColorArray::ptr() const { + return (const Color *)internal::gdn_interface->packed_color_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +Color *PackedColorArray::ptrw() { + return (Color *)internal::gdn_interface->packed_color_array_operator_index((GDNativeTypePtr *)this, 0); +} + const float &PackedFloat32Array::operator[](int p_index) const { return *internal::gdn_interface->packed_float32_array_operator_index_const((GDNativeTypePtr *)this, p_index); } @@ -72,6 +88,14 @@ float &PackedFloat32Array::operator[](int p_index) { return *internal::gdn_interface->packed_float32_array_operator_index((GDNativeTypePtr *)this, p_index); } +const float *PackedFloat32Array::ptr() const { + return internal::gdn_interface->packed_float32_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +float *PackedFloat32Array::ptrw() { + return internal::gdn_interface->packed_float32_array_operator_index((GDNativeTypePtr *)this, 0); +} + const double &PackedFloat64Array::operator[](int p_index) const { return *internal::gdn_interface->packed_float64_array_operator_index_const((GDNativeTypePtr *)this, p_index); } @@ -80,6 +104,14 @@ double &PackedFloat64Array::operator[](int p_index) { return *internal::gdn_interface->packed_float64_array_operator_index((GDNativeTypePtr *)this, p_index); } +const double *PackedFloat64Array::ptr() const { + return internal::gdn_interface->packed_float64_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +double *PackedFloat64Array::ptrw() { + return internal::gdn_interface->packed_float64_array_operator_index((GDNativeTypePtr *)this, 0); +} + const int32_t &PackedInt32Array::operator[](int p_index) const { return *internal::gdn_interface->packed_int32_array_operator_index_const((GDNativeTypePtr *)this, p_index); } @@ -88,6 +120,14 @@ int32_t &PackedInt32Array::operator[](int p_index) { return *internal::gdn_interface->packed_int32_array_operator_index((GDNativeTypePtr *)this, p_index); } +const int32_t *PackedInt32Array::ptr() const { + return internal::gdn_interface->packed_int32_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +int32_t *PackedInt32Array::ptrw() { + return internal::gdn_interface->packed_int32_array_operator_index((GDNativeTypePtr *)this, 0); +} + const int64_t &PackedInt64Array::operator[](int p_index) const { return *internal::gdn_interface->packed_int64_array_operator_index_const((GDNativeTypePtr *)this, p_index); } @@ -96,6 +136,14 @@ int64_t &PackedInt64Array::operator[](int p_index) { return *internal::gdn_interface->packed_int64_array_operator_index((GDNativeTypePtr *)this, p_index); } +const int64_t *PackedInt64Array::ptr() const { + return internal::gdn_interface->packed_int64_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +int64_t *PackedInt64Array::ptrw() { + return internal::gdn_interface->packed_int64_array_operator_index((GDNativeTypePtr *)this, 0); +} + const String &PackedStringArray::operator[](int p_index) const { const String *string = (const String *)internal::gdn_interface->packed_string_array_operator_index_const((GDNativeTypePtr *)this, p_index); return *string; @@ -106,6 +154,14 @@ String &PackedStringArray::operator[](int p_index) { return *string; } +const String *PackedStringArray::ptr() const { + return (const String *)internal::gdn_interface->packed_string_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +String *PackedStringArray::ptrw() { + return (String *)internal::gdn_interface->packed_string_array_operator_index((GDNativeTypePtr *)this, 0); +} + const Vector2 &PackedVector2Array::operator[](int p_index) const { const Vector2 *vec = (const Vector2 *)internal::gdn_interface->packed_vector2_array_operator_index_const((GDNativeTypePtr *)this, p_index); return *vec; @@ -116,6 +172,14 @@ Vector2 &PackedVector2Array::operator[](int p_index) { return *vec; } +const Vector2 *PackedVector2Array::ptr() const { + return (const Vector2 *)internal::gdn_interface->packed_vector2_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +Vector2 *PackedVector2Array::ptrw() { + return (Vector2 *)internal::gdn_interface->packed_vector2_array_operator_index((GDNativeTypePtr *)this, 0); +} + const Vector3 &PackedVector3Array::operator[](int p_index) const { const Vector3 *vec = (const Vector3 *)internal::gdn_interface->packed_vector3_array_operator_index_const((GDNativeTypePtr *)this, p_index); return *vec; @@ -126,6 +190,14 @@ Vector3 &PackedVector3Array::operator[](int p_index) { return *vec; } +const Vector3 *PackedVector3Array::ptr() const { + return (const Vector3 *)internal::gdn_interface->packed_vector3_array_operator_index_const((GDNativeTypePtr *)this, 0); +} + +Vector3 *PackedVector3Array::ptrw() { + return (Vector3 *)internal::gdn_interface->packed_vector3_array_operator_index((GDNativeTypePtr *)this, 0); +} + const Variant &Array::operator[](int p_index) const { const Variant *var = (const Variant *)internal::gdn_interface->array_operator_index_const((GDNativeTypePtr *)this, p_index); return *var; diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp index 82b0b149a..f8f039c90 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -69,15 +69,15 @@ void Variant::init_bindings() { } Variant::Variant() { - internal::gdn_interface->variant_new_nil(ptr()); + internal::gdn_interface->variant_new_nil(_native_ptr()); } Variant::Variant(const GDNativeVariantPtr native_ptr) { - internal::gdn_interface->variant_new_copy(ptr(), native_ptr); + internal::gdn_interface->variant_new_copy(_native_ptr(), native_ptr); } Variant::Variant(const Variant &other) { - internal::gdn_interface->variant_new_copy(ptr(), other.ptr()); + internal::gdn_interface->variant_new_copy(_native_ptr(), other._native_ptr()); } Variant::Variant(Variant &&other) { @@ -87,163 +87,163 @@ Variant::Variant(Variant &&other) { Variant::Variant(bool v) { GDNativeBool encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[BOOL](ptr(), &encoded); + from_type_constructor[BOOL](_native_ptr(), &encoded); } Variant::Variant(int64_t v) { GDNativeInt encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[INT](ptr(), &encoded); + from_type_constructor[INT](_native_ptr(), &encoded); } Variant::Variant(double v) { double encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[FLOAT](ptr(), &encoded); + from_type_constructor[FLOAT](_native_ptr(), &encoded); } Variant::Variant(const String &v) { - from_type_constructor[STRING](ptr(), v.ptr()); + from_type_constructor[STRING](_native_ptr(), v._native_ptr()); } Variant::Variant(const Vector2 &v) { - from_type_constructor[VECTOR2](ptr(), v.ptr()); + from_type_constructor[VECTOR2](_native_ptr(), v._native_ptr()); } Variant::Variant(const Vector2i &v) { - from_type_constructor[VECTOR2I](ptr(), v.ptr()); + from_type_constructor[VECTOR2I](_native_ptr(), v._native_ptr()); } Variant::Variant(const Rect2 &v) { - from_type_constructor[RECT2](ptr(), v.ptr()); + from_type_constructor[RECT2](_native_ptr(), v._native_ptr()); } Variant::Variant(const Rect2i &v) { - from_type_constructor[RECT2I](ptr(), v.ptr()); + from_type_constructor[RECT2I](_native_ptr(), v._native_ptr()); } Variant::Variant(const Vector3 &v) { - from_type_constructor[VECTOR3](ptr(), v.ptr()); + from_type_constructor[VECTOR3](_native_ptr(), v._native_ptr()); } Variant::Variant(const Vector3i &v) { - from_type_constructor[VECTOR3I](ptr(), v.ptr()); + from_type_constructor[VECTOR3I](_native_ptr(), v._native_ptr()); } Variant::Variant(const Transform2D &v) { - from_type_constructor[TRANSFORM2D](ptr(), v.ptr()); + from_type_constructor[TRANSFORM2D](_native_ptr(), v._native_ptr()); } Variant::Variant(const Plane &v) { - from_type_constructor[PLANE](ptr(), v.ptr()); + from_type_constructor[PLANE](_native_ptr(), v._native_ptr()); } Variant::Variant(const Quaternion &v) { - from_type_constructor[QUATERNION](ptr(), v.ptr()); + from_type_constructor[QUATERNION](_native_ptr(), v._native_ptr()); } Variant::Variant(const godot::AABB &v) { - from_type_constructor[AABB](ptr(), v.ptr()); + from_type_constructor[AABB](_native_ptr(), v._native_ptr()); } Variant::Variant(const Basis &v) { - from_type_constructor[BASIS](ptr(), v.ptr()); + from_type_constructor[BASIS](_native_ptr(), v._native_ptr()); } Variant::Variant(const Transform3D &v) { - from_type_constructor[TRANSFORM3D](ptr(), v.ptr()); + from_type_constructor[TRANSFORM3D](_native_ptr(), v._native_ptr()); } Variant::Variant(const Color &v) { - from_type_constructor[COLOR](ptr(), v.ptr()); + from_type_constructor[COLOR](_native_ptr(), v._native_ptr()); } Variant::Variant(const StringName &v) { - from_type_constructor[STRING_NAME](ptr(), v.ptr()); + from_type_constructor[STRING_NAME](_native_ptr(), v._native_ptr()); } Variant::Variant(const NodePath &v) { - from_type_constructor[NODE_PATH](ptr(), v.ptr()); + from_type_constructor[NODE_PATH](_native_ptr(), v._native_ptr()); } Variant::Variant(const godot::RID &v) { - from_type_constructor[RID](ptr(), v.ptr()); + from_type_constructor[RID](_native_ptr(), v._native_ptr()); } Variant::Variant(const Object *v) { if (v) { - from_type_constructor[OBJECT](ptr(), const_cast(&v->_owner)); + from_type_constructor[OBJECT](_native_ptr(), const_cast(&v->_owner)); } else { GodotObject *nullobject = nullptr; - from_type_constructor[OBJECT](ptr(), &nullobject); + from_type_constructor[OBJECT](_native_ptr(), &nullobject); } } Variant::Variant(const Callable &v) { - from_type_constructor[CALLABLE](ptr(), v.ptr()); + from_type_constructor[CALLABLE](_native_ptr(), v._native_ptr()); } Variant::Variant(const Signal &v) { - from_type_constructor[SIGNAL](ptr(), v.ptr()); + from_type_constructor[SIGNAL](_native_ptr(), v._native_ptr()); } Variant::Variant(const Dictionary &v) { - from_type_constructor[DICTIONARY](ptr(), v.ptr()); + from_type_constructor[DICTIONARY](_native_ptr(), v._native_ptr()); } Variant::Variant(const Array &v) { - from_type_constructor[ARRAY](ptr(), v.ptr()); + from_type_constructor[ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedByteArray &v) { - from_type_constructor[PACKED_BYTE_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_BYTE_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedInt32Array &v) { - from_type_constructor[PACKED_INT32_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_INT32_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedInt64Array &v) { - from_type_constructor[PACKED_INT64_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_INT64_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedFloat32Array &v) { - from_type_constructor[PACKED_FLOAT32_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_FLOAT32_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedFloat64Array &v) { - from_type_constructor[PACKED_FLOAT64_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_FLOAT64_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedStringArray &v) { - from_type_constructor[PACKED_STRING_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_STRING_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedVector2Array &v) { - from_type_constructor[PACKED_VECTOR2_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_VECTOR2_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedVector3Array &v) { - from_type_constructor[PACKED_VECTOR3_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_VECTOR3_ARRAY](_native_ptr(), v._native_ptr()); } Variant::Variant(const PackedColorArray &v) { - from_type_constructor[PACKED_COLOR_ARRAY](ptr(), v.ptr()); + from_type_constructor[PACKED_COLOR_ARRAY](_native_ptr(), v._native_ptr()); } Variant::~Variant() { - internal::gdn_interface->variant_destroy(ptr()); + internal::gdn_interface->variant_destroy(_native_ptr()); } Variant::operator bool() const { GDNativeBool result; - to_type_constructor[BOOL](&result, ptr()); + to_type_constructor[BOOL](&result, _native_ptr()); return PtrToArg::convert(&result); } Variant::operator int64_t() const { GDNativeInt result; - to_type_constructor[INT](&result, ptr()); + to_type_constructor[INT](&result, _native_ptr()); return PtrToArg::convert(&result); } @@ -261,7 +261,7 @@ Variant::operator uint32_t() const { Variant::operator double() const { double result; - to_type_constructor[FLOAT](&result, ptr()); + to_type_constructor[FLOAT](&result, _native_ptr()); return PtrToArg::convert(&result); } @@ -271,109 +271,109 @@ Variant::operator float() const { Variant::operator String() const { String result; - to_type_constructor[STRING](result.ptr(), ptr()); + to_type_constructor[STRING](result._native_ptr(), _native_ptr()); return result; } Variant::operator Vector2() const { Vector2 result; - to_type_constructor[VECTOR2](result.ptr(), ptr()); + to_type_constructor[VECTOR2](result._native_ptr(), _native_ptr()); return result; } Variant::operator Vector2i() const { Vector2i result; - to_type_constructor[VECTOR2I](result.ptr(), ptr()); + to_type_constructor[VECTOR2I](result._native_ptr(), _native_ptr()); return result; } Variant::operator Rect2() const { Rect2 result; - to_type_constructor[RECT2](result.ptr(), ptr()); + to_type_constructor[RECT2](result._native_ptr(), _native_ptr()); return result; } Variant::operator Rect2i() const { Rect2i result; - to_type_constructor[RECT2I](result.ptr(), ptr()); + to_type_constructor[RECT2I](result._native_ptr(), _native_ptr()); return result; } Variant::operator Vector3() const { Vector3 result; - to_type_constructor[VECTOR3](result.ptr(), ptr()); + to_type_constructor[VECTOR3](result._native_ptr(), _native_ptr()); return result; } Variant::operator Vector3i() const { Vector3i result; - to_type_constructor[VECTOR3I](result.ptr(), ptr()); + to_type_constructor[VECTOR3I](result._native_ptr(), _native_ptr()); return result; } Variant::operator Transform2D() const { Transform2D result; - to_type_constructor[TRANSFORM2D](result.ptr(), ptr()); + to_type_constructor[TRANSFORM2D](result._native_ptr(), _native_ptr()); return result; } Variant::operator Plane() const { Plane result; - to_type_constructor[PLANE](result.ptr(), ptr()); + to_type_constructor[PLANE](result._native_ptr(), _native_ptr()); return result; } Variant::operator Quaternion() const { Quaternion result; - to_type_constructor[QUATERNION](result.ptr(), ptr()); + to_type_constructor[QUATERNION](result._native_ptr(), _native_ptr()); return result; } Variant::operator godot::AABB() const { godot::AABB result; - to_type_constructor[AABB](result.ptr(), ptr()); + to_type_constructor[AABB](result._native_ptr(), _native_ptr()); return result; } Variant::operator Basis() const { Basis result; - to_type_constructor[BASIS](result.ptr(), ptr()); + to_type_constructor[BASIS](result._native_ptr(), _native_ptr()); return result; } Variant::operator Transform3D() const { Transform3D result; - to_type_constructor[TRANSFORM3D](result.ptr(), ptr()); + to_type_constructor[TRANSFORM3D](result._native_ptr(), _native_ptr()); return result; } Variant::operator Color() const { Color result; - to_type_constructor[COLOR](result.ptr(), ptr()); + to_type_constructor[COLOR](result._native_ptr(), _native_ptr()); return result; } Variant::operator StringName() const { StringName result; - to_type_constructor[STRING_NAME](result.ptr(), ptr()); + to_type_constructor[STRING_NAME](result._native_ptr(), _native_ptr()); return result; } Variant::operator NodePath() const { NodePath result; - to_type_constructor[NODE_PATH](result.ptr(), ptr()); + to_type_constructor[NODE_PATH](result._native_ptr(), _native_ptr()); return result; } Variant::operator godot::RID() const { godot::RID result; - to_type_constructor[RID](result.ptr(), ptr()); + to_type_constructor[RID](result._native_ptr(), _native_ptr()); return result; } Variant::operator Object *() const { GodotObject *obj; - to_type_constructor[OBJECT](&obj, ptr()); + to_type_constructor[OBJECT](&obj, _native_ptr()); if (obj == nullptr) { return nullptr; } @@ -382,85 +382,85 @@ Variant::operator Object *() const { Variant::operator Callable() const { Callable result; - to_type_constructor[CALLABLE](result.ptr(), ptr()); + to_type_constructor[CALLABLE](result._native_ptr(), _native_ptr()); return result; } Variant::operator Signal() const { Signal result; - to_type_constructor[SIGNAL](result.ptr(), ptr()); + to_type_constructor[SIGNAL](result._native_ptr(), _native_ptr()); return result; } Variant::operator Dictionary() const { Dictionary result; - to_type_constructor[DICTIONARY](result.ptr(), ptr()); + to_type_constructor[DICTIONARY](result._native_ptr(), _native_ptr()); return result; } Variant::operator Array() const { Array result; - to_type_constructor[ARRAY](result.ptr(), ptr()); + to_type_constructor[ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedByteArray() const { PackedByteArray result; - to_type_constructor[PACKED_BYTE_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_BYTE_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedInt32Array() const { PackedInt32Array result; - to_type_constructor[PACKED_INT32_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_INT32_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedInt64Array() const { PackedInt64Array result; - to_type_constructor[PACKED_INT64_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_INT64_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedFloat32Array() const { PackedFloat32Array result; - to_type_constructor[PACKED_FLOAT32_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_FLOAT32_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedFloat64Array() const { PackedFloat64Array result; - to_type_constructor[PACKED_FLOAT64_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_FLOAT64_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedStringArray() const { PackedStringArray result; - to_type_constructor[PACKED_STRING_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_STRING_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedVector2Array() const { PackedVector2Array result; - to_type_constructor[PACKED_VECTOR2_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_VECTOR2_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedVector3Array() const { PackedVector3Array result; - to_type_constructor[PACKED_VECTOR3_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_VECTOR3_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant::operator PackedColorArray() const { PackedColorArray result; - to_type_constructor[PACKED_COLOR_ARRAY](result.ptr(), ptr()); + to_type_constructor[PACKED_COLOR_ARRAY](result._native_ptr(), _native_ptr()); return result; } Variant &Variant::operator=(const Variant &other) { clear(); - internal::gdn_interface->variant_new_copy(ptr(), other.ptr()); + internal::gdn_interface->variant_new_copy(_native_ptr(), other._native_ptr()); return *this; } @@ -500,22 +500,22 @@ bool Variant::operator<(const Variant &other) const { } void Variant::call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDNativeCallError &r_error) { - internal::gdn_interface->variant_call(ptr(), method.ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret.ptr(), &r_error); + internal::gdn_interface->variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret._native_ptr(), &r_error); } void Variant::call_static(Variant::Type type, const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDNativeCallError &r_error) { - internal::gdn_interface->variant_call_static(static_cast(type), method.ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret.ptr(), &r_error); + internal::gdn_interface->variant_call_static(static_cast(type), method._native_ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret._native_ptr(), &r_error); } void Variant::evaluate(const Operator &op, const Variant &a, const Variant &b, Variant &r_ret, bool &r_valid) { GDNativeBool valid; - internal::gdn_interface->variant_evaluate(static_cast(op), a.ptr(), b.ptr(), r_ret.ptr(), &valid); + internal::gdn_interface->variant_evaluate(static_cast(op), a._native_ptr(), b._native_ptr(), r_ret._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); } void Variant::set(const Variant &key, const Variant &value, bool *r_valid) { GDNativeBool valid; - internal::gdn_interface->variant_set(ptr(), key.ptr(), value.ptr(), &valid); + internal::gdn_interface->variant_set(_native_ptr(), key._native_ptr(), value._native_ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -523,27 +523,27 @@ void Variant::set(const Variant &key, const Variant &value, bool *r_valid) { void Variant::set_named(const StringName &name, const Variant &value, bool &r_valid) { GDNativeBool valid; - internal::gdn_interface->variant_set_named(ptr(), name.ptr(), value.ptr(), &valid); + internal::gdn_interface->variant_set_named(_native_ptr(), name._native_ptr(), value._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); } void Variant::set_indexed(int64_t index, const Variant &value, bool &r_valid, bool &r_oob) { GDNativeBool valid, oob; - internal::gdn_interface->variant_set_indexed(ptr(), index, value.ptr(), &valid, &oob); + internal::gdn_interface->variant_set_indexed(_native_ptr(), index, value._native_ptr(), &valid, &oob); r_valid = PtrToArg::convert(&valid); r_oob = PtrToArg::convert(&oob); } void Variant::set_keyed(const Variant &key, const Variant &value, bool &r_valid) { GDNativeBool valid; - internal::gdn_interface->variant_set_keyed(ptr(), key.ptr(), value.ptr(), &valid); + internal::gdn_interface->variant_set_keyed(_native_ptr(), key._native_ptr(), value._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); } Variant Variant::get(const Variant &key, bool *r_valid) const { Variant result; GDNativeBool valid; - internal::gdn_interface->variant_get(ptr(), key.ptr(), result.ptr(), &valid); + internal::gdn_interface->variant_get(_native_ptr(), key._native_ptr(), result._native_ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -553,7 +553,7 @@ Variant Variant::get(const Variant &key, bool *r_valid) const { Variant Variant::get_named(const StringName &name, bool &r_valid) const { Variant result; GDNativeBool valid; - internal::gdn_interface->variant_get_named(ptr(), name.ptr(), result.ptr(), &valid); + internal::gdn_interface->variant_get_named(_native_ptr(), name._native_ptr(), result._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } @@ -562,7 +562,7 @@ Variant Variant::get_indexed(int64_t index, bool &r_valid, bool &r_oob) const { Variant result; GDNativeBool valid; GDNativeBool oob; - internal::gdn_interface->variant_get_indexed(ptr(), index, result.ptr(), &valid, &oob); + internal::gdn_interface->variant_get_indexed(_native_ptr(), index, result._native_ptr(), &valid, &oob); r_valid = PtrToArg::convert(&valid); r_oob = PtrToArg::convert(&oob); return result; @@ -571,7 +571,7 @@ Variant Variant::get_indexed(int64_t index, bool &r_valid, bool &r_oob) const { Variant Variant::get_keyed(const Variant &key, bool &r_valid) const { Variant result; GDNativeBool valid; - internal::gdn_interface->variant_get_keyed(ptr(), key.ptr(), result.ptr(), &valid); + internal::gdn_interface->variant_get_keyed(_native_ptr(), key._native_ptr(), result._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } @@ -588,36 +588,36 @@ bool Variant::in(const Variant &index, bool *r_valid) const { bool Variant::iter_init(Variant &r_iter, bool &r_valid) const { GDNativeBool valid; - internal::gdn_interface->variant_iter_init(ptr(), r_iter.ptr(), &valid); + internal::gdn_interface->variant_iter_init(_native_ptr(), r_iter._native_ptr(), &valid); return PtrToArg::convert(&valid); } bool Variant::iter_next(Variant &r_iter, bool &r_valid) const { GDNativeBool valid; - internal::gdn_interface->variant_iter_next(ptr(), r_iter.ptr(), &valid); + internal::gdn_interface->variant_iter_next(_native_ptr(), r_iter._native_ptr(), &valid); return PtrToArg::convert(&valid); } Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { Variant result; GDNativeBool valid; - internal::gdn_interface->variant_iter_get(ptr(), r_iter.ptr(), result.ptr(), &valid); + internal::gdn_interface->variant_iter_get(_native_ptr(), r_iter._native_ptr(), result._native_ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } Variant::Type Variant::get_type() const { - return static_cast(internal::gdn_interface->variant_get_type(ptr())); + return static_cast(internal::gdn_interface->variant_get_type(_native_ptr())); } bool Variant::has_method(const StringName &method) const { - GDNativeBool has = internal::gdn_interface->variant_has_method(ptr(), method.ptr()); + GDNativeBool has = internal::gdn_interface->variant_has_method(_native_ptr(), method._native_ptr()); return PtrToArg::convert(&has); } bool Variant::has_key(const Variant &key, bool *r_valid) const { GDNativeBool valid; - GDNativeBool has = internal::gdn_interface->variant_has_key(ptr(), key.ptr(), &valid); + GDNativeBool has = internal::gdn_interface->variant_has_key(_native_ptr(), key._native_ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -625,23 +625,23 @@ bool Variant::has_key(const Variant &key, bool *r_valid) const { } bool Variant::has_member(Variant::Type type, const StringName &member) { - GDNativeBool has = internal::gdn_interface->variant_has_member(static_cast(type), member.ptr()); + GDNativeBool has = internal::gdn_interface->variant_has_member(static_cast(type), member._native_ptr()); return PtrToArg::convert(&has); } bool Variant::hash_compare(const Variant &variant) const { - GDNativeBool compare = internal::gdn_interface->variant_hash_compare(ptr(), variant.ptr()); + GDNativeBool compare = internal::gdn_interface->variant_hash_compare(_native_ptr(), variant._native_ptr()); return PtrToArg::convert(&compare); } bool Variant::booleanize() const { - GDNativeBool booleanized = internal::gdn_interface->variant_booleanize(ptr()); + GDNativeBool booleanized = internal::gdn_interface->variant_booleanize(_native_ptr()); return PtrToArg::convert(&booleanized); } String Variant::stringify() const { String result; - internal::gdn_interface->variant_stringify(ptr(), result.ptr()); + internal::gdn_interface->variant_stringify(_native_ptr(), result._native_ptr()); return result; } @@ -649,21 +649,21 @@ Variant Variant::duplicate(bool deep) const { Variant result; GDNativeBool _deep; PtrToArg::encode(deep, &_deep); - internal::gdn_interface->variant_duplicate(ptr(), result.ptr(), _deep); + internal::gdn_interface->variant_duplicate(_native_ptr(), result._native_ptr(), _deep); return result; } void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) { - internal::gdn_interface->variant_blend(a.ptr(), b.ptr(), c, r_dst.ptr()); + internal::gdn_interface->variant_blend(a._native_ptr(), b._native_ptr(), c, r_dst._native_ptr()); } void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) { - internal::gdn_interface->variant_interpolate(a.ptr(), b.ptr(), c, r_dst.ptr()); + internal::gdn_interface->variant_interpolate(a._native_ptr(), b._native_ptr(), c, r_dst._native_ptr()); } String Variant::get_type_name(Variant::Type type) { String result; - internal::gdn_interface->variant_get_type_name(static_cast(type), result.ptr()); + internal::gdn_interface->variant_get_type_name(static_cast(type), result._native_ptr()); return result; } @@ -723,9 +723,9 @@ void Variant::clear() { }; if (unlikely(needs_deinit[get_type()])) { // Make it fast for types that don't need deinit. - internal::gdn_interface->variant_destroy(ptr()); + internal::gdn_interface->variant_destroy(_native_ptr()); } - internal::gdn_interface->variant_new_nil(ptr()); + internal::gdn_interface->variant_new_nil(_native_ptr()); } } // namespace godot From 7aaab11b0fdef43482f7959ad37f0ed769ca0a4c Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Tue, 15 Feb 2022 10:47:12 +0200 Subject: [PATCH 14/18] Add Variant binders for the generated classes, structs and global enums --- binding_generator.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/binding_generator.py b/binding_generator.py index 753d67994..836052c9b 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -62,6 +62,7 @@ def generate_bindings(api_filepath, use_template_get_node, output_dir="."): target_dir.mkdir(parents=True) generate_global_constants(api, target_dir) + generate_global_constant_binds(api, target_dir) generate_builtin_bindings(api, target_dir, "float_64") generate_engine_classes_bindings(api, target_dir, use_template_get_node) generate_utility_functions(api, target_dir) @@ -860,6 +861,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node): result.append(f"\t{field};") result.append("};") + result.append("") + result.append(f"GDVIRTUAL_NATIVE_PTR({struct_name});") result.append("") result.append("} // namespace godot") result.append("") @@ -997,6 +1000,12 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us result.append("") result.append("} // namespace godot") + result.append("") + + if "enums" in class_api and class_name != "Object": + for enum_api in class_api["enums"]: + result.append(f'VARIANT_ENUM_CAST({class_name}, {class_name}::{enum_api["name"]});') + result.append("") result.append(f"#endif // ! {header_guard}") @@ -1180,6 +1189,42 @@ def generate_global_constants(api, output_dir): header_file.write("\n".join(header)) +def generate_global_constant_binds(api, output_dir): + include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "classes" + source_gen_folder = Path(output_dir) / "src" / "classes" + + include_gen_folder.mkdir(parents=True, exist_ok=True) + source_gen_folder.mkdir(parents=True, exist_ok=True) + + # Generate header + + header = [] + add_header("global_constants_binds.hpp", header) + + header_filename = include_gen_folder / "global_constants_binds.hpp" + + header_guard = "GODOT_CPP_GLOBAL_CONSTANTS_BINDS_HPP" + header.append(f"#ifndef {header_guard}") + header.append(f"#define {header_guard}") + header.append("") + header.append("#include ") + header.append("#include ") + header.append("") + + for enum_def in api["global_enums"]: + if enum_def["name"].startswith("Variant."): + continue + + header.append(f'VARIANT_ENUM_CAST(, godot::{enum_def["name"]});') + + header.append("") + + header.append(f"#endif // ! {header_guard}") + + with header_filename.open("w+") as header_file: + header_file.write("\n".join(header)) + + def generate_utility_functions(api, output_dir): include_gen_folder = Path(output_dir) / "include" / "godot_cpp" / "variant" source_gen_folder = Path(output_dir) / "src" / "variant" From a8cd21ac07ba9f5c67e952524a5c8851be705512 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 16 Feb 2022 11:35:13 +0200 Subject: [PATCH 15/18] Fix "const" NativePtr binds. --- binding_generator.py | 4 +++ include/godot_cpp/core/method_ptrcall.hpp | 42 +++++++++++------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/binding_generator.py b/binding_generator.py index ff59ce749..c389838cb 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -789,6 +789,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node): if "arguments" in method: for argument in method["arguments"]: type_name = argument["type"] + if type_name.startswith("const "): + type_name = type_name[6:] if type_name.endswith("*"): type_name = type_name[:-1] if is_included(type_name, class_name): @@ -802,6 +804,8 @@ def generate_engine_classes_bindings(api, output_dir, use_template_get_node): fully_used_classes.add("Ref") if "return_value" in method: type_name = method["return_value"]["type"] + if type_name.startswith("const "): + type_name = type_name[6:] if type_name.endswith("*"): type_name = type_name[:-1] if is_included(type_name, class_name): diff --git a/include/godot_cpp/core/method_ptrcall.hpp b/include/godot_cpp/core/method_ptrcall.hpp index 3e6f060da..5752f7eef 100644 --- a/include/godot_cpp/core/method_ptrcall.hpp +++ b/include/godot_cpp/core/method_ptrcall.hpp @@ -185,27 +185,27 @@ struct PtrToArg { }; // Pointers. -#define GDVIRTUAL_NATIVE_PTR(m_type) \ - template <> \ - struct PtrToArg { \ - _FORCE_INLINE_ static m_type *convert(const void *p_ptr) { \ - return (m_type *)(*(void **)p_ptr); \ - } \ - typedef m_type *EncodeT; \ - _FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \ - *((void **)p_ptr) = p_var; \ - } \ - }; \ - \ - template <> \ - struct PtrToArg { \ - _FORCE_INLINE_ static const m_type *convert(const void *p_ptr) { \ - return (const m_type *)(*(const void **)p_ptr); \ - } \ - typedef const m_type *EncodeT; \ - _FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \ - *((void **)p_ptr) = p_var; \ - } \ +#define GDVIRTUAL_NATIVE_PTR(m_type) \ + template <> \ + struct PtrToArg { \ + _FORCE_INLINE_ static m_type *convert(const void *p_ptr) { \ + return (m_type *)(*(void **)p_ptr); \ + } \ + typedef m_type *EncodeT; \ + _FORCE_INLINE_ static void encode(m_type *p_var, void *p_ptr) { \ + *((void **)p_ptr) = p_var; \ + } \ + }; \ + \ + template <> \ + struct PtrToArg { \ + _FORCE_INLINE_ static const m_type *convert(const void *p_ptr) { \ + return (const m_type *)(*(const void **)p_ptr); \ + } \ + typedef const m_type *EncodeT; \ + _FORCE_INLINE_ static void encode(const m_type *p_var, const void *p_ptr) { \ + *((const void **)p_ptr) = p_var; \ + } \ } GDVIRTUAL_NATIVE_PTR(bool); From 3bb86f1e01e275245d137377a001cb9d7508886d Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Wed, 16 Feb 2022 13:12:10 +0200 Subject: [PATCH 16/18] Use C++17 flag only for C++ files. --- SConstruct | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SConstruct b/SConstruct index d748f63aa..d06586ec4 100644 --- a/SConstruct +++ b/SConstruct @@ -170,9 +170,9 @@ if host_platform == "windows" and env["platform"] != "android": # Require C++17 if host_platform == "windows" and env["platform"] == "windows" and not env["use_mingw"]: # MSVC - env.Append(CCFLAGS=["/std:c++17"]) + env.Append(CXXFLAGS=["/std:c++17"]) else: - env.Append(CCFLAGS=["-std=c++17"]) + env.Append(CXXFLAGS=["-std=c++17"]) if env["target"] == "debug": env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"]) From 65dc3e89c7fbd19a0bafb0eefa60b140c41ababe Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Thu, 17 Feb 2022 10:18:04 +0200 Subject: [PATCH 17/18] Add ERR_ macros variants using `String` messages. --- include/godot_cpp/core/error_macros.hpp | 6 +++++ src/core/error_macros.cpp | 34 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/include/godot_cpp/core/error_macros.hpp b/include/godot_cpp/core/error_macros.hpp index 5a7f4e962..81ef733d8 100644 --- a/include/godot_cpp/core/error_macros.hpp +++ b/include/godot_cpp/core/error_macros.hpp @@ -32,14 +32,20 @@ #define GODOT_CPP_ERROR_MACROS_HPP #include +#include #include namespace godot { void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, bool p_is_warning = false); +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, bool p_is_warning = false); void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const char *p_message, bool p_is_warning = false); +void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, bool p_is_warning = false); +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, bool p_is_warning = false); +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, bool p_is_warning = false); void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message = "", bool fatal = false); +void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal = false); // Used to strip debug messages in release mode #ifdef DEBUG_ENABLED diff --git a/src/core/error_macros.cpp b/src/core/error_macros.cpp index d0c922ebf..4ef3f1d8a 100644 --- a/src/core/error_macros.cpp +++ b/src/core/error_macros.cpp @@ -44,14 +44,48 @@ void _err_print_error(const char *p_function, const char *p_file, int p_line, co } } +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const char *p_message, bool p_is_warning) { + if (p_is_warning) { + internal::gdn_interface->print_warning(p_message, p_function, p_file, p_line); + } else { + internal::gdn_interface->print_error(p_message, p_function, p_file, p_line); + } +} + +void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, const String &p_message, bool p_is_warning) { + if (p_is_warning) { + internal::gdn_interface->print_warning(p_message.utf8().get_data(), p_function, p_file, p_line); + } else { + internal::gdn_interface->print_error(p_message.utf8().get_data(), p_function, p_file, p_line); + } +} + +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, const String &p_message, bool p_is_warning) { + if (p_is_warning) { + internal::gdn_interface->print_warning(p_message.utf8().get_data(), p_function, p_file, p_line); + } else { + internal::gdn_interface->print_error(p_message.utf8().get_data(), p_function, p_file, p_line); + } +} + void _err_print_error(const char *p_function, const char *p_file, int p_line, const char *p_error, bool p_is_warning) { _err_print_error(p_function, p_file, p_line, "", p_error, p_is_warning); } +void _err_print_error(const char *p_function, const char *p_file, int p_line, const String &p_error, bool p_is_warning) { + _err_print_error(p_function, p_file, p_line, "", p_error, p_is_warning); +} + void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const char *p_message, bool fatal) { std::string fstr(fatal ? "FATAL: " : ""); std::string err(fstr + "Index " + p_index_str + " = " + std::to_string(p_index) + " is out of bounds (" + p_size_str + " = " + std::to_string(p_size) + ")."); _err_print_error(p_function, p_file, p_line, err.c_str(), p_message); } +void _err_print_index_error(const char *p_function, const char *p_file, int p_line, int64_t p_index, int64_t p_size, const char *p_index_str, const char *p_size_str, const String &p_message, bool fatal) { + std::string fstr(fatal ? "FATAL: " : ""); + std::string err(fstr + "Index " + p_index_str + " = " + std::to_string(p_index) + " is out of bounds (" + p_size_str + " = " + std::to_string(p_size) + ")."); + _err_print_error(p_function, p_file, p_line, err.c_str(), p_message); +} + } // namespace godot From 7e3321d1b2fc9f81191f53ee427d44bed6a2d923 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Sun, 20 Feb 2022 11:47:57 +0100 Subject: [PATCH 18/18] Use forward declares for vector math types Adds operators to convert from int vector types to float vector types as done in the upstream engine implementations. --- include/godot_cpp/variant/rect2.hpp | 3 +++ include/godot_cpp/variant/rect2i.hpp | 15 +++++++-------- include/godot_cpp/variant/vector2.hpp | 2 +- include/godot_cpp/variant/vector2i.hpp | 12 ++++-------- include/godot_cpp/variant/vector3.hpp | 3 +-- include/godot_cpp/variant/vector3i.hpp | 5 ++++- src/variant/rect2.cpp | 10 ++++++++++ src/variant/rect2i.cpp | 15 ++++++++++++++- src/variant/vector2.cpp | 19 ++++++++++--------- src/variant/vector2i.cpp | 16 +++++++++++----- src/variant/vector3.cpp | 3 ++- src/variant/vector3i.cpp | 8 +++++++- 12 files changed, 74 insertions(+), 37 deletions(-) diff --git a/include/godot_cpp/variant/rect2.hpp b/include/godot_cpp/variant/rect2.hpp index f696bca90..65e800591 100644 --- a/include/godot_cpp/variant/rect2.hpp +++ b/include/godot_cpp/variant/rect2.hpp @@ -37,6 +37,8 @@ namespace godot { +class Rect2i; +class String; class Transform2D; class Rect2 { @@ -326,6 +328,7 @@ class Rect2 { } operator String() const; + operator Rect2i() const; Rect2() {} Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) : diff --git a/include/godot_cpp/variant/rect2i.hpp b/include/godot_cpp/variant/rect2i.hpp index 9d82668b0..d1618c14b 100644 --- a/include/godot_cpp/variant/rect2i.hpp +++ b/include/godot_cpp/variant/rect2i.hpp @@ -31,11 +31,15 @@ #ifndef GODOT_RECT2I_HPP #define GODOT_RECT2I_HPP -#include +#include +#include #include namespace godot { +class Rect2; +class String; + class Rect2i { _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } @@ -206,15 +210,10 @@ class Rect2i { return position + size; } - operator String() const { return String(position) + ", " + String(size); } - - operator Rect2() const { return Rect2(position, size); } + operator String() const; + operator Rect2() const; Rect2i() {} - Rect2i(const Rect2 &p_r2) : - position(p_r2.position), - size(p_r2.size) { - } Rect2i(int p_x, int p_y, int p_width, int p_height) : position(Point2i(p_x, p_y)), size(Size2i(p_width, p_height)) { diff --git a/include/godot_cpp/variant/vector2.hpp b/include/godot_cpp/variant/vector2.hpp index 72b45e313..aba1da8fb 100644 --- a/include/godot_cpp/variant/vector2.hpp +++ b/include/godot_cpp/variant/vector2.hpp @@ -32,10 +32,10 @@ #define GODOT_VECTOR2_HPP #include -#include namespace godot { +class String; class Vector2i; class Vector2 { diff --git a/include/godot_cpp/variant/vector2i.hpp b/include/godot_cpp/variant/vector2i.hpp index 69c68971c..373bedf83 100644 --- a/include/godot_cpp/variant/vector2i.hpp +++ b/include/godot_cpp/variant/vector2i.hpp @@ -32,11 +32,12 @@ #define GODOT_VECTOR2I_HPP #include -#include -#include namespace godot { +class String; +class Vector2; + class Vector2i { _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } @@ -96,14 +97,9 @@ class Vector2i { Vector2i abs() const { return Vector2i(Math::abs(x), Math::abs(y)); } operator String() const; - - operator Vector2() const { return Vector2((real_t)x, (real_t)y); } + operator Vector2() const; inline Vector2i() {} - inline Vector2i(const Vector2 &p_vec2) { - x = (int32_t)p_vec2.x; - y = (int32_t)p_vec2.y; - } inline Vector2i(int32_t p_x, int32_t p_y) { x = p_x; y = p_y; diff --git a/include/godot_cpp/variant/vector3.hpp b/include/godot_cpp/variant/vector3.hpp index f34aa054a..ca7ba298c 100644 --- a/include/godot_cpp/variant/vector3.hpp +++ b/include/godot_cpp/variant/vector3.hpp @@ -32,11 +32,11 @@ #define GODOT_VECTOR3_HPP #include -#include namespace godot { class Basis; +class String; class Vector3i; class Vector3 { @@ -159,7 +159,6 @@ class Vector3 { y = p_y; z = p_z; } - Vector3(const Vector3i &p_ivec); }; Vector3 Vector3::cross(const Vector3 &p_b) const { diff --git a/include/godot_cpp/variant/vector3i.hpp b/include/godot_cpp/variant/vector3i.hpp index 9aa034115..b1623b198 100644 --- a/include/godot_cpp/variant/vector3i.hpp +++ b/include/godot_cpp/variant/vector3i.hpp @@ -32,10 +32,12 @@ #define GODOT_VECTOR3I_HPP #include -#include namespace godot { +class String; +class Vector3; + class Vector3i { _FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; } @@ -107,6 +109,7 @@ class Vector3i { inline bool operator>=(const Vector3i &p_v) const; operator String() const; + operator Vector3() const; inline Vector3i() {} inline Vector3i(int32_t p_x, int32_t p_y, int32_t p_z) { diff --git a/src/variant/rect2.cpp b/src/variant/rect2.cpp index 176a25060..7ca87190b 100644 --- a/src/variant/rect2.cpp +++ b/src/variant/rect2.cpp @@ -30,6 +30,8 @@ #include +#include +#include #include namespace godot { @@ -268,4 +270,12 @@ bool Rect2::intersects_transformed(const Transform2D &p_xform, const Rect2 &p_re return true; } +Rect2::operator String() const { + return String(position) + ", " + String(size); +} + +Rect2::operator Rect2i() const { + return Rect2i(position, size); +} + } // namespace godot diff --git a/src/variant/rect2i.cpp b/src/variant/rect2i.cpp index 92db0c938..ab3ad7dcf 100644 --- a/src/variant/rect2i.cpp +++ b/src/variant/rect2i.cpp @@ -30,4 +30,17 @@ #include -// No implementation left. This is here to add the header as a compiled unit. +#include +#include + +namespace godot { + +Rect2i::operator String() const { + return String(position) + ", " + String(size); +} + +Rect2i::operator Rect2() const { + return Rect2(position, size); +} + +} // namespace godot diff --git a/src/variant/vector2.cpp b/src/variant/vector2.cpp index 7ba09102c..c58589243 100644 --- a/src/variant/vector2.cpp +++ b/src/variant/vector2.cpp @@ -28,21 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include + #include #include -#include #include namespace godot { -Vector2::operator String() const { - return String::num(x, 5) + ", " + String::num(y, 5); -} - -Vector2::operator Vector2i() const { - return Vector2i(x, y); -} - real_t Vector2::angle() const { return Math::atan2(y, x); } @@ -200,4 +193,12 @@ bool Vector2::is_equal_approx(const Vector2 &p_v) const { return Math::is_equal_approx(x, p_v.x) && Math::is_equal_approx(y, p_v.y); } +Vector2::operator String() const { + return String::num(x, 5) + ", " + String::num(y, 5); +} + +Vector2::operator Vector2i() const { + return Vector2i(x, y); +} + } // namespace godot diff --git a/src/variant/vector2i.cpp b/src/variant/vector2i.cpp index fa2d3abc9..ed9d5ad5b 100644 --- a/src/variant/vector2i.cpp +++ b/src/variant/vector2i.cpp @@ -28,16 +28,14 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include + #include #include -#include +#include namespace godot { -Vector2i::operator String() const { - return String::num(x, 0) + ", " + String::num(y, 0); -} - Vector2i Vector2i::operator+(const Vector2i &p_v) const { return Vector2i(x + p_v.x, y + p_v.y); } @@ -107,4 +105,12 @@ bool Vector2i::operator!=(const Vector2i &p_vec2) const { return x != p_vec2.x || y != p_vec2.y; } +Vector2i::operator String() const { + return String::num(x, 0) + ", " + String::num(y, 0); +} + +Vector2i::operator Vector2() const { + return Vector2((real_t)x, (real_t)y); +} + } // namespace godot diff --git a/src/variant/vector3.cpp b/src/variant/vector3.cpp index 6cfb92af7..f888775d8 100644 --- a/src/variant/vector3.cpp +++ b/src/variant/vector3.cpp @@ -28,9 +28,10 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include + #include #include -#include #include namespace godot { diff --git a/src/variant/vector3i.cpp b/src/variant/vector3i.cpp index 67c0bc5ad..08497628b 100644 --- a/src/variant/vector3i.cpp +++ b/src/variant/vector3i.cpp @@ -28,9 +28,11 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ +#include + #include #include -#include +#include namespace godot { @@ -56,4 +58,8 @@ Vector3i::operator String() const { return (String::num(x, 0) + ", " + String::num(y, 0) + ", " + String::num(z, 5)); } +Vector3i::operator Vector3() const { + return Vector3((real_t)x, (real_t)y, (real_t)z); +} + } // namespace godot