diff options
-rw-r--r-- | core/math/vector2.cpp | 12 | ||||
-rw-r--r-- | core/math/vector2.h | 30 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/aabb.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/basis.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/color.h | 5 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/math_defs.h | 65 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/plane.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/quat.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/rect2.h | 10 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/transform.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/transform2d.h | 4 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/variant.h | 19 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/vector2.h | 6 | ||||
-rw-r--r-- | modules/gdnative/include/gdnative/vector3.h | 6 |
14 files changed, 116 insertions, 61 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 496e29ebe4..5129ed336e 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -211,11 +211,11 @@ Vector2i Vector2i::operator*(const Vector2i &p_v1) const { return Vector2i(x * p_v1.x, y * p_v1.y); } -Vector2i Vector2i::operator*(const int &rvalue) const { +Vector2i Vector2i::operator*(const int32_t &rvalue) const { return Vector2i(x * rvalue, y * rvalue); } -void Vector2i::operator*=(const int &rvalue) { +void Vector2i::operator*=(const int32_t &rvalue) { x *= rvalue; y *= rvalue; } @@ -224,11 +224,11 @@ Vector2i Vector2i::operator/(const Vector2i &p_v1) const { return Vector2i(x / p_v1.x, y / p_v1.y); } -Vector2i Vector2i::operator/(const int &rvalue) const { +Vector2i Vector2i::operator/(const int32_t &rvalue) const { return Vector2i(x / rvalue, y / rvalue); } -void Vector2i::operator/=(const int &rvalue) { +void Vector2i::operator/=(const int32_t &rvalue) { x /= rvalue; y /= rvalue; } @@ -237,11 +237,11 @@ Vector2i Vector2i::operator%(const Vector2i &p_v1) const { return Vector2i(x % p_v1.x, y % p_v1.y); } -Vector2i Vector2i::operator%(const int &rvalue) const { +Vector2i Vector2i::operator%(const int32_t &rvalue) const { return Vector2i(x % rvalue, y % rvalue); } -void Vector2i::operator%=(const int &rvalue) { +void Vector2i::operator%=(const int32_t &rvalue) { x %= rvalue; y %= rvalue; } diff --git a/core/math/vector2.h b/core/math/vector2.h index 24795857a3..81bc71d590 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -265,18 +265,18 @@ struct Vector2i { }; union { - int x = 0; - int width; + int32_t x = 0; + int32_t width; }; union { - int y = 0; - int height; + int32_t y = 0; + int32_t height; }; - _FORCE_INLINE_ int &operator[](int p_idx) { + _FORCE_INLINE_ int32_t &operator[](int p_idx) { return p_idx ? y : x; } - _FORCE_INLINE_ const int &operator[](int p_idx) const { + _FORCE_INLINE_ const int32_t &operator[](int p_idx) const { return p_idx ? y : x; } @@ -286,16 +286,16 @@ struct Vector2i { void operator-=(const Vector2i &p_v); Vector2i operator*(const Vector2i &p_v1) const; - Vector2i operator*(const int &rvalue) const; - void operator*=(const int &rvalue); + Vector2i operator*(const int32_t &rvalue) const; + void operator*=(const int32_t &rvalue); Vector2i operator/(const Vector2i &p_v1) const; - Vector2i operator/(const int &rvalue) const; - void operator/=(const int &rvalue); + Vector2i operator/(const int32_t &rvalue) const; + void operator/=(const int32_t &rvalue); Vector2i operator%(const Vector2i &p_v1) const; - Vector2i operator%(const int &rvalue) const; - void operator%=(const int &rvalue); + Vector2i operator%(const int32_t &rvalue) const; + void operator%=(const int32_t &rvalue); Vector2i operator-() const; bool operator<(const Vector2i &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); } @@ -317,10 +317,10 @@ struct Vector2i { inline Vector2i() {} inline Vector2i(const Vector2 &p_vec2) { - x = (int)p_vec2.x; - y = (int)p_vec2.y; + x = (int32_t)p_vec2.x; + y = (int32_t)p_vec2.y; } - inline Vector2i(int p_x, int p_y) { + inline Vector2i(int32_t p_x, int32_t p_y) { x = p_x; y = p_y; } diff --git a/modules/gdnative/include/gdnative/aabb.h b/modules/gdnative/include/gdnative/aabb.h index 1373530fda..be0235221f 100644 --- a/modules/gdnative/include/gdnative/aabb.h +++ b/modules/gdnative/include/gdnative/aabb.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_AABB_SIZE 24 +#define GODOT_AABB_SIZE (sizeof(godot_real_t) * 6) #ifndef GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED #define GODOT_CORE_API_GODOT_AABB_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/basis.h b/modules/gdnative/include/gdnative/basis.h index 191ad660d5..d40ca3d6a5 100644 --- a/modules/gdnative/include/gdnative/basis.h +++ b/modules/gdnative/include/gdnative/basis.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_BASIS_SIZE 36 +#define GODOT_BASIS_SIZE (sizeof(godot_real_t) * 9) #ifndef GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED #define GODOT_CORE_API_GODOT_BASIS_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/color.h b/modules/gdnative/include/gdnative/color.h index dd5d5383e3..12c4a829bd 100644 --- a/modules/gdnative/include/gdnative/color.h +++ b/modules/gdnative/include/gdnative/color.h @@ -35,9 +35,10 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_COLOR_SIZE 16 +// Colors should always use 32-bit floats, so don't use real_t here. +#define GODOT_COLOR_SIZE (sizeof(float) * 4) #ifndef GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED #define GODOT_CORE_API_GODOT_COLOR_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/math_defs.h b/modules/gdnative/include/gdnative/math_defs.h new file mode 100644 index 0000000000..05de157dd0 --- /dev/null +++ b/modules/gdnative/include/gdnative/math_defs.h @@ -0,0 +1,65 @@ +/*************************************************************************/ +/* math_defs.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef GODOT_GDNATIVE_MATH_DEFS_H +#define GODOT_GDNATIVE_MATH_DEFS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +////// bool + +typedef bool godot_bool; + +#define GODOT_TRUE 1 +#define GODOT_FALSE 0 + +/////// int + +typedef int64_t godot_int; + +/////// float + +typedef double godot_float; + +#ifdef REAL_T_IS_DOUBLE +typedef double godot_real_t; +#else +typedef float godot_real_t; +#endif + +#ifdef __cplusplus +} +#endif + +#endif // GODOT_C_H diff --git a/modules/gdnative/include/gdnative/plane.h b/modules/gdnative/include/gdnative/plane.h index 7480c2d17c..ed10955e5f 100644 --- a/modules/gdnative/include/gdnative/plane.h +++ b/modules/gdnative/include/gdnative/plane.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_PLANE_SIZE 16 +#define GODOT_PLANE_SIZE (sizeof(godot_real_t) * 4) #ifndef GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED #define GODOT_CORE_API_GODOT_PLANE_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/quat.h b/modules/gdnative/include/gdnative/quat.h index fbb067ad41..a87d0bdbe5 100644 --- a/modules/gdnative/include/gdnative/quat.h +++ b/modules/gdnative/include/gdnative/quat.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_QUAT_SIZE 16 +#define GODOT_QUAT_SIZE (sizeof(godot_real_t) * 4) #ifndef GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED #define GODOT_CORE_API_GODOT_QUAT_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/rect2.h b/modules/gdnative/include/gdnative/rect2.h index 9f4bc9fb3a..9e51254cfe 100644 --- a/modules/gdnative/include/gdnative/rect2.h +++ b/modules/gdnative/include/gdnative/rect2.h @@ -35,19 +35,23 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> + +#define GODOT_RECT2_SIZE (sizeof(godot_real_t) * 4) #ifndef GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED #define GODOT_CORE_API_GODOT_RECT2_TYPE_DEFINED typedef struct godot_rect2 { - uint8_t _dont_touch_that[16]; + uint8_t _dont_touch_that[GODOT_RECT2_SIZE]; } godot_rect2; #endif +#define GODOT_RECT2I_SIZE (sizeof(int32_t) * 4) + #ifndef GODOT_CORE_API_GODOT_RECT2I_TYPE_DEFINED #define GODOT_CORE_API_GODOT_RECT2I_TYPE_DEFINED typedef struct godot_rect2i { - uint8_t _dont_touch_that[16]; + uint8_t _dont_touch_that[GODOT_RECT2I_SIZE]; } godot_rect2i; #endif diff --git a/modules/gdnative/include/gdnative/transform.h b/modules/gdnative/include/gdnative/transform.h index b5aeeff4bd..e67862d140 100644 --- a/modules/gdnative/include/gdnative/transform.h +++ b/modules/gdnative/include/gdnative/transform.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_TRANSFORM_SIZE 48 +#define GODOT_TRANSFORM_SIZE (sizeof(godot_real_t) * 12) #ifndef GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED #define GODOT_CORE_API_GODOT_TRANSFORM_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/transform2d.h b/modules/gdnative/include/gdnative/transform2d.h index 07a7cc8e79..85e3a86972 100644 --- a/modules/gdnative/include/gdnative/transform2d.h +++ b/modules/gdnative/include/gdnative/transform2d.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_TRANSFORM2D_SIZE 24 +#define GODOT_TRANSFORM2D_SIZE (sizeof(godot_real_t) * 6) #ifndef GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED #define GODOT_CORE_API_GODOT_TRANSFORM2D_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/variant.h b/modules/gdnative/include/gdnative/variant.h index 219010443a..82bd030170 100644 --- a/modules/gdnative/include/gdnative/variant.h +++ b/modules/gdnative/include/gdnative/variant.h @@ -35,24 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -////// bool - -typedef bool godot_bool; - -#define GODOT_TRUE 1 -#define GODOT_FALSE 0 - -/////// int - -typedef int64_t godot_int; - -/////// float - -typedef double godot_float; - -#define GODOT_VARIANT_SIZE (16 + sizeof(int64_t)) +#define GODOT_VARIANT_SIZE (sizeof(godot_real_t) * 4 + sizeof(int64_t)) #ifndef GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VARIANT_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/vector2.h b/modules/gdnative/include/gdnative/vector2.h index 69b67ae166..a21ab304d0 100644 --- a/modules/gdnative/include/gdnative/vector2.h +++ b/modules/gdnative/include/gdnative/vector2.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_VECTOR2_SIZE 8 +#define GODOT_VECTOR2_SIZE (sizeof(godot_real_t) * 2) #ifndef GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VECTOR2_TYPE_DEFINED @@ -46,7 +46,7 @@ typedef struct { } godot_vector2; #endif -#define GODOT_VECTOR2I_SIZE 8 +#define GODOT_VECTOR2I_SIZE (sizeof(int32_t) * 2) #ifndef GODOT_CORE_API_GODOT_VECTOR2I_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VECTOR2I_TYPE_DEFINED diff --git a/modules/gdnative/include/gdnative/vector3.h b/modules/gdnative/include/gdnative/vector3.h index d531c638e1..354c7555b6 100644 --- a/modules/gdnative/include/gdnative/vector3.h +++ b/modules/gdnative/include/gdnative/vector3.h @@ -35,9 +35,9 @@ extern "C" { #endif -#include <stdint.h> +#include <gdnative/math_defs.h> -#define GODOT_VECTOR3_SIZE 12 +#define GODOT_VECTOR3_SIZE (sizeof(godot_real_t) * 3) #ifndef GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VECTOR3_TYPE_DEFINED @@ -46,7 +46,7 @@ typedef struct { } godot_vector3; #endif -#define GODOT_VECTOR3I_SIZE 12 +#define GODOT_VECTOR3I_SIZE (sizeof(int32_t) * 3) #ifndef GODOT_CORE_API_GODOT_VECTOR3I_TYPE_DEFINED #define GODOT_CORE_API_GODOT_VECTOR3I_TYPE_DEFINED |