From 8bcf32a61946620017f61568f4aa10070db4bd4e Mon Sep 17 00:00:00 2001 From: George Marques Date: Thu, 19 Aug 2021 14:47:56 -0300 Subject: [PATCH] Fix issues with method calls --- CMakeLists.txt | 2 + SConstruct | 14 +- binding_generator.py | 12 +- include/godot_cpp/core/binder_common.hpp | 8 +- include/godot_cpp/core/type_info.hpp | 48 +++++ include/godot_cpp/variant/variant.hpp | 10 +- src/core/method_bind.cpp | 2 +- src/variant/char_string.cpp | 28 +-- src/variant/variant.cpp | 216 +++++++++++------------ 9 files changed, 191 insertions(+), 149 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d655382e..c08f5870 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,8 @@ endif() if(CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-D_DEBUG) + add_definitions(-DDEBUG_ENABLED) + add_definitions(-DDEBUG_METHODS_ENABLED) else() add_definitions(-DNDEBUG) endif(CMAKE_BUILD_TYPE MATCHES Debug) diff --git a/SConstruct b/SConstruct index 2e52abf3..7049baf1 100644 --- a/SConstruct +++ b/SConstruct @@ -158,11 +158,14 @@ if host_platform == "windows" and env["platform"] != "android": opts.Update(env) +if env["target"] == "debug": + env.Append(CPPDEFINES=["DEBUG_ENABLED", "DEBUG_METHODS_ENABLED"]) + if env["platform"] == "linux" or env["platform"] == "freebsd": if env["use_llvm"]: env["CXX"] = "clang++" - env.Append(CCFLAGS=["-fPIC", "-std=c++14", "-Wwrite-strings"]) + env.Append(CCFLAGS=["-fPIC", "-std=c++17", "-Wwrite-strings"]) env.Append(LINKFLAGS=["-Wl,-R,'$$ORIGIN'"]) if env["target"] == "debug": @@ -184,7 +187,7 @@ elif env["platform"] == "osx": if env["bits"] == "32": raise ValueError("Only 64-bit builds are supported for the macOS target.") - env.Append(CCFLAGS=["-std=c++14", "-arch", env["macos_arch"]]) + env.Append(CCFLAGS=["-std=c++17", "-arch", env["macos_arch"]]) if env["macos_deployment_target"] != "default": env.Append(CCFLAGS=["-mmacosx-version-min=" + env["macos_deployment_target"]]) @@ -231,7 +234,7 @@ elif env["platform"] == "ios": env["AR"] = compiler_path + "ar" env["RANLIB"] = compiler_path + "ranlib" - env.Append(CCFLAGS=["-std=c++14", "-arch", env["ios_arch"], "-isysroot", sdk_path]) + env.Append(CCFLAGS=["-std=c++17", "-arch", env["ios_arch"], "-isysroot", sdk_path]) env.Append( LINKFLAGS=[ "-arch", @@ -283,7 +286,7 @@ elif env["platform"] == "windows": # 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++14", "-Wwrite-strings"]) + env.Append(CCFLAGS=["-O3", "-std=c++17", "-Wwrite-strings"]) env.Append( LINKFLAGS=[ "--static", @@ -429,7 +432,7 @@ else: if env["generate_bindings"] == "auto": # Check if generated files exist - should_generate_bindings = not os.path.isfile(os.path.join(os.getcwd(), "src", "gen", "object.cpp")) + should_generate_bindings = not os.path.isfile(os.path.join(os.getcwd(), "gen", "src", "classes", "object.cpp")) else: should_generate_bindings = env["generate_bindings"] in ["yes", "true"] @@ -441,6 +444,7 @@ if should_generate_bindings: # Sources to compile sources = [] +add_sources(sources, "src", "cpp") add_sources(sources, "src/core", "cpp") add_sources(sources, "src/variant", "cpp") add_sources(sources, "gen/src/variant", "cpp") diff --git a/binding_generator.py b/binding_generator.py index c8be0d1e..3b45a976 100644 --- a/binding_generator.py +++ b/binding_generator.py @@ -179,7 +179,7 @@ def generate_builtin_bindings(api, output_dir, build_config): builtin_header.append("") for builtin in builtin_classes: - builtin_header.append(f'#include ') + builtin_header.append(f"#include ") builtin_header.append("") @@ -229,7 +229,9 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl result.append(f"class {class_name} {{") result.append(f"\tstatic constexpr size_t {snake_class_name}_SIZE = {size};") result.append(f"\tuint8_t opaque[{snake_class_name}_SIZE] {{ 0 }};") - result.append(f"\tGDNativeTypePtr ptr = const_cast(&opaque);") + result.append( + f"\t_FORCE_INLINE_ GDNativeTypePtr ptr() const {{ return const_cast(&opaque); }}" + ) result.append("") result.append("\tfriend class Variant;") @@ -1007,10 +1009,10 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us if is_pod_type(return_type) or is_variant(return_type) or is_enum(return_type): method_call += f"return internal::_call_native_mb_ret<{correct_type(return_type, meta_type)}>(___method_bind, _owner" elif is_refcounted(return_type): - method_call += f"return Ref<{return_type}>::___internal_constructor(internal::_call_native_mb_ret_obj<{class_name}>(___method_bind, _owner" + method_call += f"return Ref<{return_type}>::___internal_constructor(internal::_call_native_mb_ret_obj<{return_type}>(___method_bind, _owner" is_ref = True else: - method_call += f"return ({correct_type(return_type)})internal::_call_native_mb_ret_obj<{class_name}>(___method_bind, _owner" + method_call += f"return ({correct_type(return_type)})internal::_call_native_mb_ret_obj<{return_type}>(___method_bind, _owner" else: method_call += f"internal::_call_native_mb_no_ret(___method_bind, _owner" @@ -1029,7 +1031,7 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us else: # vararg. result.append("\tGDNativeCallError error;") result.append("\tVariant ret;") - method_call += "internal::interface->object_method_bind_call(___method_bind, _owner, (const GDNativeVariantPtr *)args, arg_count, ret, &error" + method_call += "internal::interface->object_method_bind_call(___method_bind, _owner, (const GDNativeVariantPtr *)args, arg_count, &ret, &error" if is_ref: method_call += ")" # Close Ref<> constructor. diff --git a/include/godot_cpp/core/binder_common.hpp b/include/godot_cpp/core/binder_common.hpp index c1827fa2..a2ce8f50 100644 --- a/include/godot_cpp/core/binder_common.hpp +++ b/include/godot_cpp/core/binder_common.hpp @@ -259,7 +259,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const G std::array argsp; for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { if (i < p_argcount) { - args[i] = p_args[i]; + args[i] = Variant(p_args[i]); } else { args[i] = default_values[i - p_argcount + (dvs - missing)]; } @@ -294,7 +294,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const, std::array argsp; for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { if (i < p_argcount) { - args[i] = p_args[i]; + args[i] = Variant(p_args[i]); } else { args[i] = default_values[i - p_argcount + (dvs - missing)]; } @@ -329,7 +329,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const std::array argsp; for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { if (i < p_argcount) { - args[i] = p_args[i]; + args[i] = Variant(p_args[i]); } else { args[i] = default_values[i - p_argcount + (dvs - missing)]; } @@ -364,7 +364,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const, std::array argsp; for (int32_t i = 0; i < (int32_t)sizeof...(P); i++) { if (i < p_argcount) { - args[i] = p_args[i]; + args[i] = Variant(p_args[i]); } else { args[i] = default_values[i - p_argcount + (dvs - missing)]; } diff --git a/include/godot_cpp/core/type_info.hpp b/include/godot_cpp/core/type_info.hpp index d7a7473e..94ffb3b3 100644 --- a/include/godot_cpp/core/type_info.hpp +++ b/include/godot_cpp/core/type_info.hpp @@ -38,6 +38,36 @@ namespace godot { +template +struct EnableIf { + typedef T type; +}; + +template +struct EnableIf { +}; + +template +struct TypesAreSame { + static bool const value = false; +}; + +template +struct TypesAreSame { + static bool const value = true; +}; + +template +struct TypeInherits { + static D *get_d(); + + static char (&test(B *))[1]; + static char (&test(...))[2]; + + static bool const value = sizeof(test(get_d())) == sizeof(char) && + !TypesAreSame::value; +}; + // If the compiler fails because it's trying to instantiate the primary 'GetTypeInfo' template // instead of one of the specializations, it's most likely because the type 'T' is not supported. // If 'T' is a class that inherits 'Object', make sure it can see the actual class declaration @@ -147,6 +177,24 @@ struct GetTypeInfo { } }; +template +struct GetTypeInfo::value>::type> { + static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT; + static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; + static inline PropertyInfo get_class_info() { + return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static()); + } +}; + +template +struct GetTypeInfo::value>::type> { + static const GDNativeVariantType VARIANT_TYPE = GDNATIVE_VARIANT_TYPE_OBJECT; + static const GDNativeExtensionClassMethodArgumentMetadata METADATA = GDNATIVE_EXTENSION_METHOD_ARGUMENT_METADATA_NONE; + static inline PropertyInfo get_class_info() { + return PropertyInfo(GDNATIVE_VARIANT_TYPE_OBJECT, T::get_class_static()); + } +}; + #define TEMPL_MAKE_ENUM_TYPE_INFO(m_class, m_enum, m_impl) \ template <> \ struct GetTypeInfo { \ diff --git a/include/godot_cpp/variant/variant.hpp b/include/godot_cpp/variant/variant.hpp index f94f9076..32536c8c 100644 --- a/include/godot_cpp/variant/variant.hpp +++ b/include/godot_cpp/variant/variant.hpp @@ -44,7 +44,8 @@ namespace godot { class Variant { uint8_t opaque[GODOT_CPP_VARIANT_SIZE]{ 0 }; - GDNativeVariantPtr ptr = const_cast(&opaque); + + _FORCE_INLINE_ GDNativeVariantPtr ptr() const { return const_cast(&opaque); } friend class GDExtensionBinding; friend class MethodBind; @@ -141,7 +142,7 @@ public: Variant(); Variant(std::nullptr_t n) : Variant() {} - Variant(const GDNativeVariantPtr native_ptr); + explicit Variant(const GDNativeVariantPtr native_ptr); Variant(const Variant &other); Variant(Variant &&other); Variant(bool v); @@ -235,17 +236,12 @@ public: operator PackedVector3Array() const; operator PackedColorArray() const; - operator const GDNativeVariantPtr() const; - operator GDNativeVariantPtr(); - Variant &operator=(const Variant &other); Variant &operator=(Variant &&other); bool operator==(const Variant &other) const; bool operator!=(const Variant &other) const; bool operator<(const Variant &other) const; - void operator=(const GDNativeVariantPtr other_ptr); - void call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDNativeCallError &r_error); template diff --git a/src/core/method_bind.cpp b/src/core/method_bind.cpp index cd956b67..4d5f356c 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::interface->variant_new_copy(r_return, ret.ptr); + internal::interface->variant_new_copy(r_return, ret.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 975b8408..19c99b40 100644 --- a/src/variant/char_string.cpp +++ b/src/variant/char_string.cpp @@ -75,25 +75,25 @@ CharWideString::~CharWideString() { // It's easier to have them written in C++ directly than in a Python script that generates them. String::String(const char *from) { - internal::interface->string_new_with_utf8_chars(ptr, from); + internal::interface->string_new_with_utf8_chars(ptr(), from); } String::String(const wchar_t *from) { - internal::interface->string_new_with_wide_chars(ptr, from); + internal::interface->string_new_with_wide_chars(ptr(), from); } String::String(const char16_t *from) { - internal::interface->string_new_with_utf16_chars(ptr, from); + internal::interface->string_new_with_utf16_chars(ptr(), from); } String::String(const char32_t *from) { - internal::interface->string_new_with_utf32_chars(ptr, from); + internal::interface->string_new_with_utf32_chars(ptr(), from); } CharString String::utf8() const { - int size = internal::interface->string_to_utf8_chars(ptr, nullptr, 0); + int size = internal::interface->string_to_utf8_chars(ptr(), nullptr, 0); char *cstr = memnew_arr(char, size + 1); - internal::interface->string_to_utf8_chars(ptr, cstr, size + 1); + internal::interface->string_to_utf8_chars(ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -101,9 +101,9 @@ CharString String::utf8() const { } CharString String::ascii() const { - int size = internal::interface->string_to_latin1_chars(ptr, nullptr, 0); + int size = internal::interface->string_to_latin1_chars(ptr(), nullptr, 0); char *cstr = memnew_arr(char, size + 1); - internal::interface->string_to_latin1_chars(ptr, cstr, size + 1); + internal::interface->string_to_latin1_chars(ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -111,9 +111,9 @@ CharString String::ascii() const { } Char16String String::utf16() const { - int size = internal::interface->string_to_utf16_chars(ptr, nullptr, 0); + int size = internal::interface->string_to_utf16_chars(ptr(), nullptr, 0); char16_t *cstr = memnew_arr(char16_t, size + 1); - internal::interface->string_to_utf16_chars(ptr, cstr, size + 1); + internal::interface->string_to_utf16_chars(ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -121,9 +121,9 @@ Char16String String::utf16() const { } Char32String String::utf32() const { - int size = internal::interface->string_to_utf32_chars(ptr, nullptr, 0); + int size = internal::interface->string_to_utf32_chars(ptr(), nullptr, 0); char32_t *cstr = memnew_arr(char32_t, size + 1); - internal::interface->string_to_utf32_chars(ptr, cstr, size + 1); + internal::interface->string_to_utf32_chars(ptr(), cstr, size + 1); cstr[size] = '\0'; @@ -131,9 +131,9 @@ Char32String String::utf32() const { } CharWideString String::wide_string() const { - int size = internal::interface->string_to_wide_chars(ptr, nullptr, 0); + int size = internal::interface->string_to_wide_chars(ptr(), nullptr, 0); wchar_t *cstr = memnew_arr(wchar_t, size + 1); - internal::interface->string_to_wide_chars(ptr, cstr, size + 1); + internal::interface->string_to_wide_chars(ptr(), cstr, size + 1); cstr[size] = '\0'; diff --git a/src/variant/variant.cpp b/src/variant/variant.cpp index a63e3f67..fa1d54cf 100644 --- a/src/variant/variant.cpp +++ b/src/variant/variant.cpp @@ -82,15 +82,15 @@ void Variant::init_bindings() { } Variant::Variant() { - internal::interface->variant_new_nil(ptr); + internal::interface->variant_new_nil(ptr()); } Variant::Variant(const GDNativeVariantPtr native_ptr) { - internal::interface->variant_new_copy(ptr, native_ptr); + internal::interface->variant_new_copy(ptr(), native_ptr); } Variant::Variant(const Variant &other) { - internal::interface->variant_new_copy(ptr, other.ptr); + internal::interface->variant_new_copy(ptr(), other.ptr()); } Variant::Variant(Variant &&other) { @@ -100,158 +100,158 @@ Variant::Variant(Variant &&other) { Variant::Variant(bool v) { GDNativeBool encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[BOOL](ptr, &encoded); + from_type_constructor[BOOL](ptr(), &encoded); } Variant::Variant(int64_t v) { GDNativeInt encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[INT](ptr, &encoded); + from_type_constructor[INT](ptr(), &encoded); } Variant::Variant(double v) { double encoded; PtrToArg::encode(v, &encoded); - from_type_constructor[FLOAT](ptr, &encoded); + from_type_constructor[FLOAT](ptr(), &encoded); } Variant::Variant(const String &v) { - from_type_constructor[STRING](ptr, v.ptr); + from_type_constructor[STRING](ptr(), v.ptr()); } Variant::Variant(const Vector2 &v) { - from_type_constructor[VECTOR2](ptr, v.ptr); + from_type_constructor[VECTOR2](ptr(), v.ptr()); } Variant::Variant(const Vector2i &v) { - from_type_constructor[VECTOR2I](ptr, v.ptr); + from_type_constructor[VECTOR2I](ptr(), v.ptr()); } Variant::Variant(const Rect2 &v) { - from_type_constructor[RECT2](ptr, v.ptr); + from_type_constructor[RECT2](ptr(), v.ptr()); } Variant::Variant(const Rect2i &v) { - from_type_constructor[RECT2I](ptr, v.ptr); + from_type_constructor[RECT2I](ptr(), v.ptr()); } Variant::Variant(const Vector3 &v) { - from_type_constructor[VECTOR3](ptr, v.ptr); + from_type_constructor[VECTOR3](ptr(), v.ptr()); } Variant::Variant(const Vector3i &v) { - from_type_constructor[VECTOR3I](ptr, v.ptr); + from_type_constructor[VECTOR3I](ptr(), v.ptr()); } Variant::Variant(const Transform2D &v) { - from_type_constructor[TRANSFORM2D](ptr, v.ptr); + from_type_constructor[TRANSFORM2D](ptr(), v.ptr()); } Variant::Variant(const Plane &v) { - from_type_constructor[PLANE](ptr, v.ptr); + from_type_constructor[PLANE](ptr(), v.ptr()); } Variant::Variant(const Quaternion &v) { - from_type_constructor[QUATERNION](ptr, v.ptr); + from_type_constructor[QUATERNION](ptr(), v.ptr()); } Variant::Variant(const godot::AABB &v) { - from_type_constructor[AABB](ptr, v.ptr); + from_type_constructor[AABB](ptr(), v.ptr()); } Variant::Variant(const Basis &v) { - from_type_constructor[BASIS](ptr, v.ptr); + from_type_constructor[BASIS](ptr(), v.ptr()); } Variant::Variant(const Transform3D &v) { - from_type_constructor[TRANSFORM3D](ptr, v.ptr); + from_type_constructor[TRANSFORM3D](ptr(), v.ptr()); } Variant::Variant(const Color &v) { - from_type_constructor[COLOR](ptr, v.ptr); + from_type_constructor[COLOR](ptr(), v.ptr()); } Variant::Variant(const StringName &v) { - from_type_constructor[STRING_NAME](ptr, v.ptr); + from_type_constructor[STRING_NAME](ptr(), v.ptr()); } Variant::Variant(const NodePath &v) { - from_type_constructor[NODE_PATH](ptr, v.ptr); + from_type_constructor[NODE_PATH](ptr(), v.ptr()); } Variant::Variant(const godot::RID &v) { - from_type_constructor[RID](ptr, v.ptr); + from_type_constructor[RID](ptr(), v.ptr()); } Variant::Variant(const Object *v) { - from_type_constructor[OBJECT](ptr, v->_owner); + from_type_constructor[OBJECT](ptr(), const_cast(&v->_owner)); } Variant::Variant(const Callable &v) { - from_type_constructor[CALLABLE](ptr, v.ptr); + from_type_constructor[CALLABLE](ptr(), v.ptr()); } Variant::Variant(const Signal &v) { - from_type_constructor[SIGNAL](ptr, v.ptr); + from_type_constructor[SIGNAL](ptr(), v.ptr()); } Variant::Variant(const Dictionary &v) { - from_type_constructor[DICTIONARY](ptr, v.ptr); + from_type_constructor[DICTIONARY](ptr(), v.ptr()); } Variant::Variant(const Array &v) { - from_type_constructor[ARRAY](ptr, v.ptr); + from_type_constructor[ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedByteArray &v) { - from_type_constructor[PACKED_BYTE_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_BYTE_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedInt32Array &v) { - from_type_constructor[PACKED_INT32_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_INT32_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedInt64Array &v) { - from_type_constructor[PACKED_INT64_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_INT64_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedFloat32Array &v) { - from_type_constructor[PACKED_FLOAT32_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_FLOAT32_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedFloat64Array &v) { - from_type_constructor[PACKED_FLOAT64_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_FLOAT64_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedStringArray &v) { - from_type_constructor[PACKED_STRING_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_STRING_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedVector2Array &v) { - from_type_constructor[PACKED_VECTOR2_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_VECTOR2_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedVector3Array &v) { - from_type_constructor[PACKED_VECTOR3_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_VECTOR3_ARRAY](ptr(), v.ptr()); } Variant::Variant(const PackedColorArray &v) { - from_type_constructor[PACKED_COLOR_ARRAY](ptr, v.ptr); + from_type_constructor[PACKED_COLOR_ARRAY](ptr(), v.ptr()); } Variant::~Variant() { - internal::interface->variant_destroy(ptr); + internal::interface->variant_destroy(ptr()); } Variant::operator bool() const { GDNativeBool result; - to_type_constructor[BOOL](&result, ptr); + to_type_constructor[BOOL](&result, ptr()); return PtrToArg::convert(&result); } Variant::operator int64_t() const { GDNativeInt result; - to_type_constructor[INT](&result, ptr); + to_type_constructor[INT](&result, ptr()); return PtrToArg::convert(&result); } @@ -269,7 +269,7 @@ Variant::operator uint32_t() const { Variant::operator double() const { double result; - to_type_constructor[FLOAT](&result, ptr); + to_type_constructor[FLOAT](&result, ptr()); return PtrToArg::convert(&result); } @@ -279,201 +279,196 @@ Variant::operator float() const { Variant::operator String() const { String result; - to_type_constructor[STRING](result.ptr, ptr); + to_type_constructor[STRING](result.ptr(), ptr()); return result; } Variant::operator Vector2() const { Vector2 result; - to_type_constructor[VECTOR2](result.ptr, ptr); + to_type_constructor[VECTOR2](result.ptr(), ptr()); return result; } Variant::operator Vector2i() const { Vector2i result; - to_type_constructor[VECTOR2I](result.ptr, ptr); + to_type_constructor[VECTOR2I](result.ptr(), ptr()); return result; } Variant::operator Rect2() const { Rect2 result; - to_type_constructor[RECT2](result.ptr, ptr); + to_type_constructor[RECT2](result.ptr(), ptr()); return result; } Variant::operator Rect2i() const { Rect2i result; - to_type_constructor[RECT2I](result.ptr, ptr); + to_type_constructor[RECT2I](result.ptr(), ptr()); return result; } Variant::operator Vector3() const { Vector3 result; - to_type_constructor[VECTOR3](result.ptr, ptr); + to_type_constructor[VECTOR3](result.ptr(), ptr()); return result; } Variant::operator Vector3i() const { Vector3i result; - to_type_constructor[VECTOR3I](result.ptr, ptr); + to_type_constructor[VECTOR3I](result.ptr(), ptr()); return result; } Variant::operator Transform2D() const { Transform2D result; - to_type_constructor[TRANSFORM2D](result.ptr, ptr); + to_type_constructor[TRANSFORM2D](result.ptr(), ptr()); return result; } Variant::operator Plane() const { Plane result; - to_type_constructor[PLANE](result.ptr, ptr); + to_type_constructor[PLANE](result.ptr(), ptr()); return result; } Variant::operator Quaternion() const { Quaternion result; - to_type_constructor[QUATERNION](result.ptr, ptr); + to_type_constructor[QUATERNION](result.ptr(), ptr()); return result; } Variant::operator godot::AABB() const { godot::AABB result; - to_type_constructor[AABB](result.ptr, ptr); + to_type_constructor[AABB](result.ptr(), ptr()); return result; } Variant::operator Basis() const { Basis result; - to_type_constructor[BASIS](result.ptr, ptr); + to_type_constructor[BASIS](result.ptr(), ptr()); return result; } Variant::operator Transform3D() const { Transform3D result; - to_type_constructor[TRANSFORM3D](result.ptr, ptr); + to_type_constructor[TRANSFORM3D](result.ptr(), ptr()); return result; } Variant::operator Color() const { Color result; - to_type_constructor[COLOR](result.ptr, ptr); + to_type_constructor[COLOR](result.ptr(), ptr()); return result; } Variant::operator StringName() const { StringName result; - to_type_constructor[STRING_NAME](result.ptr, ptr); + to_type_constructor[STRING_NAME](result.ptr(), ptr()); return result; } Variant::operator NodePath() const { NodePath result; - to_type_constructor[NODE_PATH](result.ptr, ptr); + to_type_constructor[NODE_PATH](result.ptr(), ptr()); return result; } Variant::operator godot::RID() const { godot::RID result; - to_type_constructor[RID](result.ptr, ptr); + to_type_constructor[RID](result.ptr(), ptr()); return result; } Variant::operator Object *() const { GodotObject *obj; - to_type_constructor[OBJECT](&obj, ptr); + to_type_constructor[OBJECT](&obj, ptr()); + if (obj == nullptr) { + return nullptr; + } return reinterpret_cast(internal::interface->object_get_instance_binding(obj, internal::token, &Object::___binding_callbacks)); } Variant::operator Callable() const { Callable result; - to_type_constructor[CALLABLE](result.ptr, ptr); + to_type_constructor[CALLABLE](result.ptr(), ptr()); return result; } Variant::operator Signal() const { Signal result; - to_type_constructor[SIGNAL](result.ptr, ptr); + to_type_constructor[SIGNAL](result.ptr(), ptr()); return result; } Variant::operator Dictionary() const { Dictionary result; - to_type_constructor[DICTIONARY](result.ptr, ptr); + to_type_constructor[DICTIONARY](result.ptr(), ptr()); return result; } Variant::operator Array() const { Array result; - to_type_constructor[ARRAY](result.ptr, ptr); + to_type_constructor[ARRAY](result.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), 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.ptr(), ptr()); return result; } -Variant::operator const GDNativeVariantPtr() const { - return reinterpret_cast(const_cast(&opaque)); -} - -Variant::operator GDNativeVariantPtr() { - return reinterpret_cast(&opaque); -} - Variant &Variant::operator=(const Variant &other) { clear(); - internal::interface->variant_new_copy(ptr, other.ptr); + internal::interface->variant_new_copy(ptr(), other.ptr()); return *this; } @@ -512,28 +507,23 @@ bool Variant::operator<(const Variant &other) const { return result.operator bool(); } -void Variant::operator=(const GDNativeVariantPtr other_ptr) { - internal::interface->variant_destroy(ptr); - internal::interface->variant_new_copy(ptr, other_ptr); -} - void Variant::call(const StringName &method, const Variant **args, int argcount, Variant &r_ret, GDNativeCallError &r_error) { - internal::interface->variant_call(ptr, method.ptr, reinterpret_cast(const_cast(args)), argcount, r_ret.ptr, &r_error); + internal::interface->variant_call(ptr(), method.ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret.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::interface->variant_call_static(static_cast(type), method.ptr, reinterpret_cast(const_cast(args)), argcount, r_ret.ptr, &r_error); + internal::interface->variant_call_static(static_cast(type), method.ptr(), reinterpret_cast(const_cast(args)), argcount, r_ret.ptr(), &r_error); } void Variant::evaluate(const Operator &op, const Variant &a, const Variant &b, Variant &r_ret, bool &r_valid) { GDNativeBool valid; - internal::interface->variant_evaluate(static_cast(op), a.ptr, b.ptr, r_ret.ptr, &valid); + internal::interface->variant_evaluate(static_cast(op), a.ptr(), b.ptr(), r_ret.ptr(), &valid); r_valid = PtrToArg::convert(&valid); } void Variant::set(const Variant &key, const Variant &value, bool *r_valid) { GDNativeBool valid; - internal::interface->variant_set(ptr, key.ptr, value.ptr, &valid); + internal::interface->variant_set(ptr(), key.ptr(), value.ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -541,27 +531,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::interface->variant_set_named(ptr, name.ptr, value.ptr, &valid); + internal::interface->variant_set_named(ptr(), name.ptr(), value.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::interface->variant_set_indexed(ptr, index, value.ptr, &valid, &oob); + internal::interface->variant_set_indexed(ptr(), index, value.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::interface->variant_set_keyed(ptr, key.ptr, value.ptr, &valid); + internal::interface->variant_set_keyed(ptr(), key.ptr(), value.ptr(), &valid); r_valid = PtrToArg::convert(&valid); } Variant Variant::get(const Variant &key, bool *r_valid) const { Variant result; GDNativeBool valid; - internal::interface->variant_get(ptr, key.ptr, result.ptr, &valid); + internal::interface->variant_get(ptr(), key.ptr(), result.ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -571,7 +561,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::interface->variant_get_named(ptr, name.ptr, result.ptr, &valid); + internal::interface->variant_get_named(ptr(), name.ptr(), result.ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } @@ -580,7 +570,7 @@ Variant Variant::get_indexed(int64_t index, bool &r_valid, bool &r_oob) const { Variant result; GDNativeBool valid; GDNativeBool oob; - internal::interface->variant_get_indexed(ptr, index, result.ptr, &valid, &oob); + internal::interface->variant_get_indexed(ptr(), index, result.ptr(), &valid, &oob); r_valid = PtrToArg::convert(&valid); r_oob = PtrToArg::convert(&oob); return result; @@ -589,7 +579,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::interface->variant_get_keyed(ptr, key.ptr, result.ptr, &valid); + internal::interface->variant_get_keyed(ptr(), key.ptr(), result.ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } @@ -606,36 +596,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::interface->variant_iter_init(ptr, r_iter.ptr, &valid); + internal::interface->variant_iter_init(ptr(), r_iter.ptr(), &valid); return PtrToArg::convert(&valid); } bool Variant::iter_next(Variant &r_iter, bool &r_valid) const { GDNativeBool valid; - internal::interface->variant_iter_next(ptr, r_iter.ptr, &valid); + internal::interface->variant_iter_next(ptr(), r_iter.ptr(), &valid); return PtrToArg::convert(&valid); } Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const { Variant result; GDNativeBool valid; - internal::interface->variant_iter_get(ptr, r_iter.ptr, result.ptr, &valid); + internal::interface->variant_iter_get(ptr(), r_iter.ptr(), result.ptr(), &valid); r_valid = PtrToArg::convert(&valid); return result; } Variant::Type Variant::get_type() const { - return static_cast(internal::interface->variant_get_type(ptr)); + return static_cast(internal::interface->variant_get_type(ptr())); } bool Variant::has_method(const StringName &method) const { - GDNativeBool has = internal::interface->variant_has_method(ptr, method.ptr); + GDNativeBool has = internal::interface->variant_has_method(ptr(), method.ptr()); return PtrToArg::convert(&has); } bool Variant::has_key(const Variant &key, bool *r_valid) const { GDNativeBool valid; - GDNativeBool has = internal::interface->variant_has_key(ptr, key.ptr, &valid); + GDNativeBool has = internal::interface->variant_has_key(ptr(), key.ptr(), &valid); if (r_valid) { *r_valid = PtrToArg::convert(&valid); } @@ -643,23 +633,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::interface->variant_has_member(static_cast(type), member.ptr); + GDNativeBool has = internal::interface->variant_has_member(static_cast(type), member.ptr()); return PtrToArg::convert(&has); } bool Variant::hash_compare(const Variant &variant) const { - GDNativeBool compare = internal::interface->variant_hash_compare(ptr, variant.ptr); + GDNativeBool compare = internal::interface->variant_hash_compare(ptr(), variant.ptr()); return PtrToArg::convert(&compare); } bool Variant::booleanize() const { - GDNativeBool booleanized = internal::interface->variant_booleanize(ptr); + GDNativeBool booleanized = internal::interface->variant_booleanize(ptr()); return PtrToArg::convert(&booleanized); } String Variant::stringify() const { String result; - internal::interface->variant_stringify(ptr, result.ptr); + internal::interface->variant_stringify(ptr(), result.ptr()); return result; } @@ -667,21 +657,21 @@ Variant Variant::duplicate(bool deep) const { Variant result; GDNativeBool _deep; PtrToArg::encode(deep, &_deep); - internal::interface->variant_duplicate(ptr, result.ptr, _deep); + internal::interface->variant_duplicate(ptr(), result.ptr(), _deep); return result; } void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) { - internal::interface->variant_blend(a.ptr, b.ptr, c, r_dst.ptr); + internal::interface->variant_blend(a.ptr(), b.ptr(), c, r_dst.ptr()); } void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) { - internal::interface->variant_interpolate(a.ptr, b.ptr, c, r_dst.ptr); + internal::interface->variant_interpolate(a.ptr(), b.ptr(), c, r_dst.ptr()); } String Variant::get_type_name(Variant::Type type) { String result; - internal::interface->variant_get_type_name(static_cast(type), result.ptr); + internal::interface->variant_get_type_name(static_cast(type), result.ptr()); return result; } @@ -741,9 +731,9 @@ void Variant::clear() { }; if (unlikely(needs_deinit[get_type()])) { // Make it fast for types that don't need deinit. - internal::interface->variant_destroy(ptr); + internal::interface->variant_destroy(ptr()); } - internal::interface->variant_new_nil(ptr); + internal::interface->variant_new_nil(ptr()); } } // namespace godot