Merge branch 'master' of https://github.com/godotengine/godot-cpp into test_cmake_windows

pull/683/head
Nicolás Carrasco 2022-02-20 22:59:56 +01:00
commit df87396cf3
38 changed files with 721 additions and 412 deletions

View File

@ -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: |
scons target=release generate_bindings=yes -j $(nproc)
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install gcc
g++ --version
gcc --version
- name: Build test project
- 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: |
cd test
scons target=release -j $(nproc)
scons platform=${{ matrix.platform }} target=debug ${{ matrix.flags }} build_library=no -j2
- name: Build test and godot-cpp (release)
run: |
cd test
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:

View File

@ -126,20 +126,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}

View File

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

View File

@ -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",
@ -144,6 +144,8 @@ 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.Update(env)
Help(opts.GenerateHelpText(env))
@ -165,6 +167,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(CXXFLAGS=["/std:c++17"])
else:
env.Append(CXXFLAGS=["-std=c++17"])
if env["target"] == "debug":
env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"])
@ -172,7 +181,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 +210,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"]])
@ -228,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"])
@ -245,20 +251,21 @@ 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=["-std=c++17", "-arch", env["ios_arch"], "-isysroot", sdk_path])
env.Append(
LINKFLAGS=[
"-arch",
env["ios_arch"],
"-framework",
"Cocoa",
"-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"])
@ -292,14 +299,21 @@ 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"])
# 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"]:
# 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",
@ -314,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:
@ -382,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"])
@ -464,18 +481,27 @@ 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"]:
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 = env.StaticLibrary(
target="bin/" + "libgodot-cpp.{}.{}.{}{}".format(env["platform"], env["target"], arch_suffix, env["LIBSUFFIX"]),
source=sources,
)
library = None
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.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")

View File

@ -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)
@ -246,7 +247,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<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
f"\t_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const {{ return const_cast<uint8_t (*)[{snake_class_name}_SIZE]>(&opaque); }}"
)
result.append("")
@ -378,6 +379,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 +431,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 <class... Args>")
@ -443,6 +450,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;")
@ -781,6 +790,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):
@ -794,6 +805,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):
@ -860,6 +873,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 +1012,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 +1201,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 <godot_cpp/classes/global_constants.hpp>")
header.append("#include <godot_cpp/core/binder_common.hpp>")
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"

@ -1 +1 @@
Subproject commit c9fe81be49d1fd1b9b0bdcc34632192babfccec5
Subproject commit ac7e75bb2844ceea5844a821276989ab33ef0774

View File

@ -32,14 +32,20 @@
#define GODOT_CPP_ERROR_MACROS_HPP
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/variant/string.hpp>
#include <cstdint>
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

View File

@ -203,8 +203,8 @@ struct PtrToArg<const T *> {
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; \
_FORCE_INLINE_ static void encode(const m_type *p_var, const void *p_ptr) { \
*((const void **)p_ptr) = p_var; \
} \
}

View File

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

View File

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

View File

@ -48,6 +48,9 @@ public:
int length() const;
const char *get_data() const;
CharString(CharString &&p_str);
void operator=(CharString &&p_str);
CharString() {}
~CharString();
};
@ -63,6 +66,9 @@ public:
int length() const;
const char16_t *get_data() const;
Char16String(Char16String &&p_str);
void operator=(Char16String &&p_str);
Char16String() {}
~Char16String();
};
@ -78,6 +84,9 @@ public:
int length() const;
const char32_t *get_data() const;
Char32String(Char32String &&p_str);
void operator=(Char32String &&p_str);
Char32String() {}
~Char32String();
};
@ -93,6 +102,9 @@ public:
int length() const;
const wchar_t *get_data() const;
CharWideString(CharWideString &&p_str);
void operator=(CharWideString &&p_str);
CharWideString() {}
~CharWideString();
};

View File

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

View File

@ -38,9 +38,11 @@
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;

View File

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

View File

@ -37,12 +37,16 @@
namespace godot {
class Rect2i;
class String;
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;
@ -324,6 +328,7 @@ public:
}
operator String() const;
operator Rect2i() const;
Rect2() {}
Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) :

View File

@ -31,15 +31,21 @@
#ifndef GODOT_RECT2I_HPP
#define GODOT_RECT2I_HPP
#include <godot_cpp/variant/rect2.hpp>
#include <godot_cpp/classes/global_constants.hpp>
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/vector2i.hpp>
namespace godot {
class Rect2i {
public:
_FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; }
class Rect2;
class String;
class Rect2i {
_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; }
friend class Variant;
public:
Point2i position;
Size2i size;
@ -204,15 +210,10 @@ public:
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)) {

View File

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

View File

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

View File

@ -45,7 +45,7 @@ namespace godot {
class Variant {
uint8_t opaque[GODOT_CPP_VARIANT_SIZE]{ 0 };
_FORCE_INLINE_ GDNativeVariantPtr ptr() const { return const_cast<uint8_t(*)[GODOT_CPP_VARIANT_SIZE]>(&opaque); }
_FORCE_INLINE_ GDNativeVariantPtr _native_ptr() const { return const_cast<uint8_t(*)[GODOT_CPP_VARIANT_SIZE]>(&opaque); }
friend class GDExtensionBinding;
friend class MethodBind;

View File

@ -32,16 +32,18 @@
#define GODOT_VECTOR2_HPP
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/string.hpp>
namespace godot {
class String;
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,
@ -151,6 +153,7 @@ public:
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) {

View File

@ -32,15 +32,18 @@
#define GODOT_VECTOR2I_HPP
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector2.hpp>
namespace godot {
class Vector2i {
public:
_FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; }
class String;
class Vector2;
class Vector2i {
_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; }
friend class Variant;
public:
enum Axis {
AXIS_X,
AXIS_Y,
@ -94,14 +97,9 @@ public:
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;

View File

@ -32,17 +32,19 @@
#define GODOT_VECTOR3_HPP
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/string.hpp>
namespace godot {
class Basis;
class String;
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,
@ -157,7 +159,6 @@ public:
y = p_y;
z = p_z;
}
Vector3(const Vector3i &p_ivec);
};
Vector3 Vector3::cross(const Vector3 &p_b) const {

View File

@ -32,14 +32,18 @@
#define GODOT_VECTOR3I_HPP
#include <godot_cpp/core/math.hpp>
#include <godot_cpp/variant/string.hpp>
namespace godot {
class Vector3i {
public:
_FORCE_INLINE_ GDNativeTypePtr ptr() const { return (void *)this; }
class String;
class Vector3;
class Vector3i {
_FORCE_INLINE_ GDNativeTypePtr _native_ptr() const { return (void *)this; }
friend class Variant;
public:
enum Axis {
AXIS_X,
AXIS_Y,
@ -105,6 +109,7 @@ public:
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) {

View File

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

View File

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

View File

@ -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() {
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() {
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() {
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() {
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);
}

View File

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

View File

@ -30,6 +30,8 @@
#include <godot_cpp/variant/rect2.hpp>
#include <godot_cpp/variant/rect2i.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/transform2d.hpp>
namespace godot {
@ -268,4 +270,12 @@ next4:
return true;
}
Rect2::operator String() const {
return String(position) + ", " + String(size);
}
Rect2::operator Rect2i() const {
return Rect2i(position, size);
}
} // namespace godot

View File

@ -30,4 +30,17 @@
#include <godot_cpp/variant/rect2i.hpp>
// No implementation left. This is here to add the header as a compiled unit.
#include <godot_cpp/variant/rect2.hpp>
#include <godot_cpp/variant/string.hpp>
namespace godot {
Rect2i::operator String() const {
return String(position) + ", " + String(size);
}
Rect2i::operator Rect2() const {
return Rect2(position, size);
}
} // namespace godot

View File

@ -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<bool>::encode(v, &encoded);
from_type_constructor[BOOL](ptr(), &encoded);
from_type_constructor[BOOL](_native_ptr(), &encoded);
}
Variant::Variant(int64_t v) {
GDNativeInt encoded;
PtrToArg<int64_t>::encode(v, &encoded);
from_type_constructor[INT](ptr(), &encoded);
from_type_constructor[INT](_native_ptr(), &encoded);
}
Variant::Variant(double v) {
double encoded;
PtrToArg<double>::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<GodotObject **>(&v->_owner));
from_type_constructor[OBJECT](_native_ptr(), const_cast<GodotObject **>(&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<bool>::convert(&result);
}
Variant::operator int64_t() const {
GDNativeInt result;
to_type_constructor[INT](&result, ptr());
to_type_constructor[INT](&result, _native_ptr());
return PtrToArg<int64_t>::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<double>::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 GDNativeVariantPtr *>(const_cast<Variant **>(args)), argcount, r_ret.ptr(), &r_error);
internal::gdn_interface->variant_call(_native_ptr(), method._native_ptr(), reinterpret_cast<const GDNativeVariantPtr *>(const_cast<Variant **>(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<GDNativeVariantType>(type), method.ptr(), reinterpret_cast<const GDNativeVariantPtr *>(const_cast<Variant **>(args)), argcount, r_ret.ptr(), &r_error);
internal::gdn_interface->variant_call_static(static_cast<GDNativeVariantType>(type), method._native_ptr(), reinterpret_cast<const GDNativeVariantPtr *>(const_cast<Variant **>(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<GDNativeVariantOperator>(op), a.ptr(), b.ptr(), r_ret.ptr(), &valid);
internal::gdn_interface->variant_evaluate(static_cast<GDNativeVariantOperator>(op), a._native_ptr(), b._native_ptr(), r_ret._native_ptr(), &valid);
r_valid = PtrToArg<bool>::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<bool>::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<bool>::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<bool>::convert(&valid);
r_oob = PtrToArg<bool>::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<bool>::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<bool>::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<bool>::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<bool>::convert(&valid);
r_oob = PtrToArg<bool>::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<bool>::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<bool>::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<bool>::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<bool>::convert(&valid);
return result;
}
Variant::Type Variant::get_type() const {
return static_cast<Variant::Type>(internal::gdn_interface->variant_get_type(ptr()));
return static_cast<Variant::Type>(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<bool>::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<bool>::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<GDNativeVariantType>(type), member.ptr());
GDNativeBool has = internal::gdn_interface->variant_has_member(static_cast<GDNativeVariantType>(type), member._native_ptr());
return PtrToArg<bool>::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<bool>::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<bool>::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<bool>::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<GDNativeVariantType>(type), result.ptr());
internal::gdn_interface->variant_get_type_name(static_cast<GDNativeVariantType>(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

View File

@ -28,15 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector2.hpp>
namespace godot {
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector2i.hpp>
Vector2::operator String() const {
return String::num(x, 5) + ", " + String::num(y, 5);
}
namespace godot {
real_t Vector2::angle() const {
return Math::atan2(y, x);
@ -195,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

View File

@ -28,15 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector2i.hpp>
namespace godot {
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector2.hpp>
Vector2i::operator String() const {
return String::num(x, 0) + ", " + String::num(y, 0);
}
namespace godot {
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

View File

@ -28,9 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/basis.hpp>
#include <godot_cpp/variant/vector3.hpp>
#include <godot_cpp/variant/vector3i.hpp>
namespace godot {
@ -121,4 +123,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

View File

@ -28,9 +28,11 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include <godot_cpp/variant/vector3i.hpp>
#include <godot_cpp/core/error_macros.hpp>
#include <godot_cpp/variant/string.hpp>
#include <godot_cpp/variant/vector3i.hpp>
#include <godot_cpp/variant/vector3.hpp>
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

View File

@ -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=<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,13 @@ 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"])
library = env.SharedLibrary("demo/bin/libgdexample.{}.{}.framework/libgdexample.{}.{}".format(env["platform"], env["target"], env["platform"], env["target"]), source=sources)
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.{}.{}.{}{}".format(env["platform"], env["target"], env["arch_suffix"], env["SHLIBSUFFIX"]), source=sources)
Default(library)

View File

@ -9,7 +9,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libgdexample.debug</string>
<string>libgdexample.osx.debug</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>

View File

@ -9,7 +9,7 @@
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>libgdexample.release</string>
<string>libgdexample.osx.release</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>

View File

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