Define GDNative sizes using sizeof(godot_real_t) and sizeof(int32_t)

This commit is contained in:
Aaron Franke 2021-01-22 05:36:48 -05:00
parent 38db12b45a
commit 6c197cf259
No known key found for this signature in database
GPG key ID: 40A1750B977E56BF
14 changed files with 116 additions and 61 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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