diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..12301490 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..90001616 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,126 @@ +name: Continuous integration +on: [push, pull_request] + +jobs: + linux: + name: Build (Linux, GCC) + runs-on: ubuntu-16.04 + steps: + - name: Checkout + uses: actions/checkout@v2.3.4 + with: + submodules: recursive + + - name: Set up Python (for SCons) + uses: actions/setup-python@v2 + with: + python-version: '3.9.1' + + - name: Install dependencies + run: | + sudo apt-get update -qq + sudo apt-get install -qqq build-essential pkg-config + python -m pip install scons + + - name: Build godot-cpp + run: | + scons target=release generate_bindings=yes -j $(nproc) + + - name: Upload artifact + uses: actions/upload-artifact@v2.2.1 + with: + name: godot-cpp-linux-glibc2.23-x86_64-release + path: bin/libgodot-cpp.linux.release.64.a + if-no-files-found: error + + windows-msvc: + name: Build (Windows, MSVC) + runs-on: windows-2019 + steps: + - name: Checkout + uses: actions/checkout@v2.3.4 + with: + submodules: recursive + + - name: Set up Python (for SCons) + uses: actions/setup-python@v2 + with: + python-version: '3.9.1' + + - name: Install dependencies + run: | + python -m pip install scons + + - name: Build godot-cpp + run: | + scons target=release generate_bindings=yes -j $env:NUMBER_OF_PROCESSORS + + - name: Upload artifact + uses: actions/upload-artifact@v2.2.1 + with: + name: godot-cpp-windows-msvc2019-x86_64-release + path: bin/libgodot-cpp.windows.release.64.lib + if-no-files-found: error + + windows-mingw: + name: Build (Windows, MinGW) + runs-on: windows-2019 + steps: + - name: Checkout + uses: actions/checkout@v2.3.4 + with: + submodules: recursive + + - name: Set up Python (for SCons) + uses: actions/setup-python@v2 + with: + python-version: '3.9.1' + + - name: Install dependencies + run: | + python -m pip install scons + + - name: Build godot-cpp + # Install GCC from Scoop as the default supplied GCC doesn't work ("Error 1"). + run: | + Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh') + scoop install gcc + g++ --version + gcc --version + scons target=release generate_bindings=yes use_mingw=yes -j $env:NUMBER_OF_PROCESSORS + + - name: Upload artifact + uses: actions/upload-artifact@v2.2.1 + with: + name: godot-cpp-linux-mingw-x86_64-release + path: bin/libgodot-cpp.windows.release.64.a + if-no-files-found: error + + macos: + name: Build (macOS, Clang) + runs-on: macos-11.0 + steps: + - name: Checkout + uses: actions/checkout@v2.3.4 + with: + submodules: recursive + + - name: Set up Python (for SCons) + uses: actions/setup-python@v2 + with: + python-version: '3.9.1' + + - name: Install dependencies + run: | + python -m pip install scons + + - name: Build godot-cpp + run: | + scons target=release generate_bindings=yes -j $(sysctl -n hw.logicalcpu) + + - name: Upload artifact + uses: actions/upload-artifact@v2.2.1 + with: + name: godot-cpp-macos-x86_64-release + path: bin/libgodot-cpp.osx.release.64.a + if-no-files-found: error diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index c6b08f25..00000000 --- a/.travis.yml +++ /dev/null @@ -1,75 +0,0 @@ -language: cpp -dist: xenial -osx_image: xcode10.1 - -env: - global: - - SCONS_CACHE="$HOME/.scons_cache" - - SCONS_CACHE_LIMIT=1024 - -cache: - directories: - - $SCONS_CACHE - -matrix: - include: - - name: Linux Debug + Static Checks - os: linux - compiler: gcc - env: TARGET=debug STATIC_CHECKS=yes - addons: - apt: - packages: - - clang-format-8 - - [scons, pkg-config, build-essential, p7zip-full] - - - name: Linux Release - os: linux - compiler: gcc - addons: - apt: - packages: - - [scons, pkg-config, build-essential, p7zip-full] - env: TARGET=release - - - name: macOS Debug - os: osx - compiler: clang - env: TARGET=debug - - - name: macOS Release - os: osx - compiler: clang - env: TARGET=release - - - name: Windows MSVC Debug - os: windows - env: TARGET=debug - - - name: Windows MSVC Release - os: windows - env: TARGET=release - -install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then - brew update; - brew install scons p7zip; - fi - - - if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then - curl -LO https://downloads.sourceforge.net/project/scons/scons-local/3.1.2/scons-local-3.1.2.zip; - unzip scons-local-3.1.2.zip; - fi - -script: - - if [[ "$TRAVIS_OS_NAME" == "windows" ]]; then - export SCONS="./scons.bat"; - else - export SCONS="scons"; - fi - - - $SCONS target="$TARGET" bits=64 generate_bindings=yes $SCONS_FLAGS; - - - if [[ "$STATIC_CHECKS" == "yes" ]]; then - sh ./misc/travis/clang-format.sh; - fi diff --git a/README.md b/README.md index e960be63..301add93 100644 --- a/README.md +++ b/README.md @@ -292,8 +292,8 @@ platform-independent manner. Once your GDNative library is compiled and referenced in a `.gdns` file, you can use it in GDScript or C#. Here's an example with GDScript: ```gdscript -var simpleclass = load("res://simpleclass.gdns").new(); -simpleclass.method("Test argument"); +var simpleclass = load("res://simpleclass.gdns").new() +simpleclass.method("Test argument") ``` ### Using Godot classes in C++ diff --git a/SConstruct b/SConstruct index d22c9a3f..46599369 100644 --- a/SConstruct +++ b/SConstruct @@ -134,6 +134,11 @@ opts.Add(EnumVariable( 'armv7', ['armv7','arm64v8','x86','x86_64'] )) +opts.Add( + 'macos_deployment_target', + 'macOS deployment target', + 'default' +) opts.Add(EnumVariable( 'ios_arch', 'Target iOS architecture', @@ -204,6 +209,10 @@ elif env['platform'] == 'osx': ) env.Append(CCFLAGS=['-std=c++14', '-arch', 'x86_64']) + + if env['macos_deployment_target'] != 'default': + env.Append(CCFLAGS=['-mmacosx-version-min=' + env['macos_deployment_target']]) + env.Append(LINKFLAGS=[ '-arch', 'x86_64', diff --git a/godot_headers b/godot_headers index ddf67cc7..f2122198 160000 --- a/godot_headers +++ b/godot_headers @@ -1 +1 @@ -Subproject commit ddf67cc7b8274c5fb77a71c828bab2991f1ee12a +Subproject commit f2122198d51f230d903f9585527248f6cf411494 diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 84dc0123..5913faeb 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -106,9 +106,9 @@ public: Variant back() const; - int find(const Variant &what, const int from = 0); + int find(const Variant &what, const int from = 0) const; - int find_last(const Variant &what); + int find_last(const Variant &what) const; bool has(const Variant &what) const; @@ -134,7 +134,7 @@ public: void resize(const int size); - int rfind(const Variant &what, const int from = -1); + int rfind(const Variant &what, const int from = -1) const; void sort(); diff --git a/include/core/Basis.hpp b/include/core/Basis.hpp index 76a345ba..0fd697ed 100644 --- a/include/core/Basis.hpp +++ b/include/core/Basis.hpp @@ -13,6 +13,11 @@ class Quat; class Basis { private: + static const Basis IDENTITY; + static const Basis FLIP_X; + static const Basis FLIP_Y; + static const Basis FLIP_Z; + // This helper template is for mimicking the behavior difference between the engine // and script interfaces that logically script sees matrices as column major, while // the engine stores them in row major to efficiently take advantage of SIMD diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp index 67e32796..e90f6ceb 100644 --- a/include/core/Defs.hpp +++ b/include/core/Defs.hpp @@ -70,9 +70,12 @@ enum class Error { typedef float real_t; -#define CMP_EPSILON 0.00001 +// This epsilon should match the one used by Godot for consistency. +// Using `f` when `real_t` is float. +#define CMP_EPSILON 0.00001f #define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON) -#define Math_PI 3.14159265358979323846 + +#define Math_PI 3.1415926535897932384626433833 #define Math_TAU 6.2831853071795864769252867666 #define _PLANE_EQ_DOT_EPSILON 0.999 diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index 322a7632..db5a8716 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -149,7 +149,7 @@ struct _ArgCast { // instance and destroy funcs template -void *_godot_class_instance_func(godot_object *p, void *method_data) { +void *_godot_class_instance_func(godot_object *p, void * /*method_data*/) { T *d = new T(); d->_owner = p; d->_type_tag = typeid(T).hash_code(); @@ -158,7 +158,7 @@ void *_godot_class_instance_func(godot_object *p, void *method_data) { } template -void _godot_class_destroy_func(godot_object *p, void *method_data, void *data) { +void _godot_class_destroy_func(godot_object * /*p*/, void * /*method_data*/, void *data) { T *d = (T *)data; delete d; } @@ -210,13 +210,13 @@ void register_tool_class() { typedef godot_variant (*__godot_wrapper_method)(godot_object *, void *, void *, int, godot_variant **); template -const char *___get_method_class_name(R (T::*p)(args... a)) { +const char *___get_method_class_name(R (T::*/*p*/)(args... a)) { static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); return T::___get_class_name(); } template -const char *___get_method_class_name(R (T::*p)(args... a) const) { +const char *___get_method_class_name(R (T::*/*p*/)(args... a) const) { static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); return T::___get_class_name(); } @@ -256,13 +256,13 @@ struct _WrappedMethod { void (T::*f)(As...); template - void apply(Variant *ret, T *obj, Variant **args, __Sequence) { + void apply(Variant * /*ret*/, T *obj, Variant **args, __Sequence) { (obj->*f)(_ArgCast::_arg_cast(*args[I])...); } }; template -godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int num_args, godot_variant **args) { +godot_variant __wrapped_method(godot_object *, void *method_data, void *user_data, int /*num_args*/, godot_variant **args) { godot_variant v; godot::api->godot_variant_new_nil(&v); @@ -286,7 +286,7 @@ void *___make_wrapper_function(R (T::*f)(As...)) { } template -__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...)) { +__godot_wrapper_method ___get_wrapper_function(R (T::* /*f*/)(As...)) { return (__godot_wrapper_method)&__wrapped_method; } @@ -326,7 +326,7 @@ void register_method_explicit(const char *name, R (B::*method_ptr)(As...), template struct _PropertySetFunc { void (T::*f)(P); - static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) { + static void _wrapped_setter(godot_object * /*object*/, void *method_data, void *user_data, godot_variant *value) { _PropertySetFunc *set_func = (_PropertySetFunc *)method_data; T *obj = (T *)user_data; @@ -340,7 +340,7 @@ template struct _PropertyGetFunc { P(T::*f) (); - static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) { + static godot_variant _wrapped_getter(godot_object * /*object*/, void *method_data, void *user_data) { _PropertyGetFunc *get_func = (_PropertyGetFunc *)method_data; T *obj = (T *)user_data; @@ -358,7 +358,7 @@ struct _PropertyGetFunc { template struct _PropertyDefaultSetFunc { P(T::*f); - static void _wrapped_setter(godot_object *object, void *method_data, void *user_data, godot_variant *value) { + static void _wrapped_setter(godot_object * /*object*/, void *method_data, void *user_data, godot_variant *value) { _PropertyDefaultSetFunc *set_func = (_PropertyDefaultSetFunc *)method_data; T *obj = (T *)user_data; @@ -371,7 +371,7 @@ struct _PropertyDefaultSetFunc { template struct _PropertyDefaultGetFunc { P(T::*f); - static godot_variant _wrapped_getter(godot_object *object, void *method_data, void *user_data) { + static godot_variant _wrapped_getter(godot_object * /*object*/, void *method_data, void *user_data) { _PropertyDefaultGetFunc *get_func = (_PropertyDefaultGetFunc *)method_data; T *obj = (T *)user_data; diff --git a/include/core/Math.hpp b/include/core/Math.hpp index 4d0d32eb..a971bb8e 100644 --- a/include/core/Math.hpp +++ b/include/core/Math.hpp @@ -107,21 +107,21 @@ inline T max(T a, T b) { template inline T sign(T x) { - return x < 0 ? -1 : 1; + return static_cast(x < 0 ? -1 : 1); } inline double deg2rad(double p_y) { return p_y * Math_PI / 180.0; } inline float deg2rad(float p_y) { - return p_y * Math_PI / 180.0; + return p_y * static_cast(Math_PI) / 180.f; } inline double rad2deg(double p_y) { return p_y * 180.0 / Math_PI; } inline float rad2deg(float p_y) { - return p_y * 180.0 / Math_PI; + return p_y * 180.f / static_cast(Math_PI); } inline double inverse_lerp(double p_from, double p_to, double p_value) { @@ -165,7 +165,7 @@ inline bool is_zero_approx(real_t s) { } inline double smoothstep(double p_from, double p_to, double p_weight) { - if (is_equal_approx(p_from, p_to)) { + if (is_equal_approx(static_cast(p_from), static_cast(p_to))) { return p_from; } double x = clamp((p_weight - p_from) / (p_to - p_from), 0.0, 1.0); @@ -205,7 +205,7 @@ inline double round(double p_val) { return (p_val >= 0) ? floor(p_val + 0.5) : -floor(-p_val + 0.5); } inline float round(float p_val) { - return (p_val >= 0) ? floor(p_val + 0.5) : -floor(-p_val + 0.5); + return (p_val >= 0) ? floor(p_val + 0.5f) : -floor(-p_val + 0.5f); } inline int64_t wrapi(int64_t value, int64_t min, int64_t max) { @@ -213,16 +213,18 @@ inline int64_t wrapi(int64_t value, int64_t min, int64_t max) { return range == 0 ? min : min + ((((value - min) % range) + range) % range); } -inline double wrapf(double value, double min, double max) { - double range = max - min; - return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); -} -inline float wrapf(float value, float min, float max) { - float range = max - min; +inline float wrapf(real_t value, real_t min, real_t max) { + const real_t range = max - min; return is_zero_approx(range) ? min : value - (range * floor((value - min) / range)); } -inline real_t stepify(real_t p_value, real_t p_step) { +inline float stepify(float p_value, float p_step) { + if (p_step != 0) { + p_value = floor(p_value / p_step + 0.5f) * p_step; + } + return p_value; +} +inline double stepify(double p_value, double p_step) { if (p_step != 0) { p_value = floor(p_value / p_step + 0.5) * p_step; } diff --git a/include/core/Quat.hpp b/include/core/Quat.hpp index f0471784..4add6be0 100644 --- a/include/core/Quat.hpp +++ b/include/core/Quat.hpp @@ -11,6 +11,8 @@ namespace godot { class Quat { public: + static const Quat IDENTITY; + real_t x, y, z, w; real_t length_squared() const; diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp index 8cbd134c..80133a11 100644 --- a/include/core/Ref.hpp +++ b/include/core/Ref.hpp @@ -11,6 +11,10 @@ namespace godot { // Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d. template class Ref { + // TODO For this nice check to work, each class must actually #include Reference classes mentionned in its methods, + // which might be annoying for coders who prefer to forward-declare to reduce compile times + // static_assert(std::is_base_of::value, + // "Ref can only be used with classes deriving from Reference"); T *reference = nullptr; @@ -28,7 +32,7 @@ class Ref { void ref_pointer(T *p_ref) { - ERR_FAIL_COND(!p_ref); + ERR_FAIL_COND(p_ref == nullptr); if (p_ref->init_ref()) reference = p_ref; @@ -90,32 +94,25 @@ public: template void operator=(const Ref &p_from) { - - // TODO We need a safe cast Reference *refb = const_cast(static_cast(p_from.ptr())); - if (!refb) { + if (refb == nullptr) { unref(); return; } Ref r; - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } void operator=(const Variant &p_variant) { - - // TODO We need a safe cast - Reference *refb = (Reference *)T::___get_from_variant(p_variant); - if (!refb) { + Object *refb = T::___get_from_variant(p_variant); + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } @@ -128,18 +125,14 @@ public: template Ref(const Ref &p_from) { - reference = nullptr; - // TODO We need a safe cast Reference *refb = const_cast(static_cast(p_from.ptr())); - if (!refb) { + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } @@ -155,16 +148,13 @@ public: Ref(const Variant &p_variant) { reference = nullptr; - // TODO We need a safe cast - Reference *refb = (Reference *)T::___get_from_variant(p_variant); - if (!refb) { + Object *refb = T::___get_from_variant(p_variant); + if (refb == nullptr) { unref(); return; } Ref r; - // TODO We need a safe cast - //r.reference = Object::cast_to(refb); - r.reference = (T *)refb; + r.reference = Object::cast_to(refb); ref(r); r.reference = nullptr; } diff --git a/include/core/Transform.hpp b/include/core/Transform.hpp index 9da63669..836792ca 100644 --- a/include/core/Transform.hpp +++ b/include/core/Transform.hpp @@ -10,6 +10,11 @@ namespace godot { class Transform { public: + static const Transform IDENTITY; + static const Transform FLIP_X; + static const Transform FLIP_Y; + static const Transform FLIP_Z; + Basis basis; Vector3 origin; diff --git a/include/core/Transform2D.hpp b/include/core/Transform2D.hpp index ae01b7fa..6a5010f8 100644 --- a/include/core/Transform2D.hpp +++ b/include/core/Transform2D.hpp @@ -10,6 +10,10 @@ typedef Vector2 Size2; struct Rect2; struct Transform2D { + static const Transform2D IDENTITY; + static const Transform2D FLIP_X; + static const Transform2D FLIP_Y; + // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": // M = (elements[0][0] elements[1][0]) // (elements[0][1] elements[1][1]) diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 031d47fe..3c2a4030 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -12,6 +12,21 @@ namespace godot { class String; struct Vector2 { + enum Axis { + AXIS_X = 0, + AXIS_Y, + AXIS_COUNT + }; + + static const Vector2 ZERO; + static const Vector2 ONE; + static const Vector2 INF; + + // Coordinate system of the 2D engine + static const Vector2 LEFT; + static const Vector2 RIGHT; + static const Vector2 UP; + static const Vector2 DOWN; union { real_t x; diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 5971787b..cbd4f75e 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -19,8 +19,21 @@ struct Vector3 { AXIS_X, AXIS_Y, AXIS_Z, + AXIS_COUNT }; + static const Vector3 ZERO; + static const Vector3 ONE; + static const Vector3 INF; + + // Coordinate system of the 3D engine + static const Vector3 LEFT; + static const Vector3 RIGHT; + static const Vector3 UP; + static const Vector3 DOWN; + static const Vector3 FORWARD; + static const Vector3 BACK; + union { struct { real_t x; diff --git a/src/core/Array.cpp b/src/core/Array.cpp index 04b4a3d8..dee4a5f0 100644 --- a/src/core/Array.cpp +++ b/src/core/Array.cpp @@ -94,11 +94,11 @@ Variant Array::back() const { return Variant(v); } -int Array::find(const Variant &what, const int from) { +int Array::find(const Variant &what, const int from) const { return godot::api->godot_array_find(&_godot_array, (godot_variant *)&what, from); } -int Array::find_last(const Variant &what) { +int Array::find_last(const Variant &what) const { return godot::api->godot_array_find_last(&_godot_array, (godot_variant *)&what); } @@ -148,7 +148,7 @@ void Array::resize(const int size) { godot::api->godot_array_resize(&_godot_array, size); } -int Array::rfind(const Variant &what, const int from) { +int Array::rfind(const Variant &what, const int from) const { return godot::api->godot_array_rfind(&_godot_array, (godot_variant *)&what, from); } diff --git a/src/core/Basis.cpp b/src/core/Basis.cpp index 368afa1e..903566c6 100644 --- a/src/core/Basis.cpp +++ b/src/core/Basis.cpp @@ -7,6 +7,11 @@ namespace godot { +const Basis Basis::IDENTITY = Basis(); +const Basis Basis::FLIP_X = Basis(-1, 0, 0, 0, 1, 0, 0, 0, 1); +const Basis Basis::FLIP_Y = Basis(1, 0, 0, 0, -1, 0, 0, 0, 1); +const Basis Basis::FLIP_Z = Basis(1, 0, 0, 0, 1, 0, 0, 0, -1); + Basis::Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2) { elements[0] = row0; elements[1] = row1; diff --git a/src/core/Quat.cpp b/src/core/Quat.cpp index 00fa43df..dc179e21 100644 --- a/src/core/Quat.cpp +++ b/src/core/Quat.cpp @@ -7,6 +7,8 @@ namespace godot { +const Quat Quat::IDENTITY = Quat(); + // set_euler_xyz expects a vector containing the Euler angles in the format // (ax,ay,az), where ax is the angle of rotation around x axis, // and similar for other axes. diff --git a/src/core/String.cpp b/src/core/String.cpp index 552ebfec..9db84622 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -392,17 +392,20 @@ float String::similarity(String text) const { return godot::api->godot_string_similarity(&_godot_string, &text._godot_string); } -PoolStringArray String::split(String divisor, bool allow_empty) const { +// TODO Suport allow_empty +PoolStringArray String::split(String divisor, bool /*allow_empty*/) const { godot_array arr = godot::api->godot_string_split(&_godot_string, &divisor._godot_string); return Array(arr); } -PoolIntArray String::split_ints(String divisor, bool allow_empty) const { +// TODO Suport allow_empty +PoolIntArray String::split_ints(String divisor, bool /*allow_empty*/) const { godot_array arr = godot::api->godot_string_split_floats(&_godot_string, &divisor._godot_string); return Array(arr); } -PoolRealArray String::split_floats(String divisor, bool allow_empty) const { +// TODO Suport allow_empty +PoolRealArray String::split_floats(String divisor, bool /*allow_empty*/) const { // TODO The GDNative API returns godot_array, when according to the doc, it should have been godot_pool_real_array godot_array arr = godot::api->godot_string_split_floats(&_godot_string, &divisor._godot_string); Array wrapped_array(arr); diff --git a/src/core/Transform.cpp b/src/core/Transform.cpp index d32de8de..1eca983a 100644 --- a/src/core/Transform.cpp +++ b/src/core/Transform.cpp @@ -9,6 +9,11 @@ namespace godot { +const Transform Transform::IDENTITY = Transform(); +const Transform Transform::FLIP_X = Transform(-1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0); +const Transform Transform::FLIP_Y = Transform(1, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0); +const Transform Transform::FLIP_Z = Transform(1, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0); + Transform Transform::inverse_xform(const Transform &t) const { Vector3 v = t.origin - origin; diff --git a/src/core/Transform2D.cpp b/src/core/Transform2D.cpp index acd6af15..6395c3dd 100644 --- a/src/core/Transform2D.cpp +++ b/src/core/Transform2D.cpp @@ -7,6 +7,10 @@ namespace godot { +const Transform2D Transform2D::IDENTITY; +const Transform2D Transform2D::FLIP_X = Transform2D(-1, 0, 0, 1, 0, 0); +const Transform2D Transform2D::FLIP_Y = Transform2D(1, 0, 0, -1, 0, 0); + Transform2D::Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy) { elements[0][0] = xx; diff --git a/src/core/Vector2.cpp b/src/core/Vector2.cpp index 44dc001f..eeeeb856 100644 --- a/src/core/Vector2.cpp +++ b/src/core/Vector2.cpp @@ -6,6 +6,15 @@ namespace godot { +const Vector2 Vector2::ZERO; +const Vector2 Vector2::ONE; +const Vector2 Vector2::INF; + +const Vector2 Vector2::LEFT = Vector2(-1, 0); +const Vector2 Vector2::RIGHT = Vector2(1, 0); +const Vector2 Vector2::UP = Vector2(0, -1); +const Vector2 Vector2::DOWN = Vector2(0, 1); + bool Vector2::operator==(const Vector2 &p_vec2) const { return x == p_vec2.x && y == p_vec2.y; } diff --git a/src/core/Vector3.cpp b/src/core/Vector3.cpp index 879de0bb..f4db4627 100644 --- a/src/core/Vector3.cpp +++ b/src/core/Vector3.cpp @@ -8,6 +8,17 @@ namespace godot { +const Vector3 Vector3::ZERO = Vector3(); +const Vector3 Vector3::ONE = Vector3(); +const Vector3 Vector3::INF = Vector3(INFINITY, INFINITY, INFINITY); + +const Vector3 Vector3::LEFT = Vector3(-1, 0, 0); +const Vector3 Vector3::RIGHT = Vector3(1, 0, 0); +const Vector3 Vector3::UP = Vector3(0, 1, 0); +const Vector3 Vector3::DOWN = Vector3(0, -1, 0); +const Vector3 Vector3::FORWARD = Vector3(0, 0, -1); +const Vector3 Vector3::BACK = Vector3(0, 0, 1); + bool Vector3::operator<(const Vector3 &p_v) const { if (x == p_v.x) { if (y == p_v.y)