Merge branch 'master' into container_leaks

This commit is contained in:
Marc
2021-01-31 20:06:56 +00:00
committed by GitHub
25 changed files with 281 additions and 137 deletions

View File

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

View File

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

View File

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

View File

@@ -149,7 +149,7 @@ struct _ArgCast<Variant> {
// instance and destroy funcs
template <class T>
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 <class T>
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 <class T, class R, class... args>
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 <class T, class R, class... args>
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<T, void, As...> {
void (T::*f)(As...);
template <int... I>
void apply(Variant *ret, T *obj, Variant **args, __Sequence<I...>) {
void apply(Variant * /*ret*/, T *obj, Variant **args, __Sequence<I...>) {
(obj->*f)(_ArgCast<As>::_arg_cast(*args[I])...);
}
};
template <class T, class R, class... As>
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 <class T, class R, class... As>
__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<T, R, As...>;
}
@@ -326,7 +326,7 @@ void register_method_explicit(const char *name, R (B::*method_ptr)(As...),
template <class T, class P>
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<T, P> *set_func = (_PropertySetFunc<T, P> *)method_data;
T *obj = (T *)user_data;
@@ -340,7 +340,7 @@ template <class T, class P>
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<T, P> *get_func = (_PropertyGetFunc<T, P> *)method_data;
T *obj = (T *)user_data;
@@ -358,7 +358,7 @@ struct _PropertyGetFunc {
template <class T, class P>
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<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *)method_data;
T *obj = (T *)user_data;
@@ -371,7 +371,7 @@ struct _PropertyDefaultSetFunc {
template <class T, class P>
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<T, P> *get_func = (_PropertyDefaultGetFunc<T, P> *)method_data;
T *obj = (T *)user_data;

View File

@@ -107,21 +107,21 @@ inline T max(T a, T b) {
template <typename T>
inline T sign(T x) {
return x < 0 ? -1 : 1;
return static_cast<T>(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<float>(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<float>(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<real_t>(p_from), static_cast<real_t>(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;
}

View File

@@ -11,6 +11,8 @@ namespace godot {
class Quat {
public:
static const Quat IDENTITY;
real_t x, y, z, w;
real_t length_squared() const;

View File

@@ -11,6 +11,10 @@ namespace godot {
// Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d.
template <class T>
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<Reference, T>::value,
// "Ref<T> 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 <class T_Other>
void operator=(const Ref<T_Other> &p_from) {
// TODO We need a safe cast
Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr()));
if (!refb) {
if (refb == nullptr) {
unref();
return;
}
Ref r;
//r.reference = Object::cast_to<T>(refb);
r.reference = (T *)refb;
r.reference = Object::cast_to<T>(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<T>(refb);
r.reference = (T *)refb;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}
@@ -128,18 +125,14 @@ public:
template <class T_Other>
Ref(const Ref<T_Other> &p_from) {
reference = nullptr;
// TODO We need a safe cast
Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr()));
if (!refb) {
if (refb == nullptr) {
unref();
return;
}
Ref r;
// TODO We need a safe cast
//r.reference = Object::cast_to<T>(refb);
r.reference = (T *)refb;
r.reference = Object::cast_to<T>(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<T>(refb);
r.reference = (T *)refb;
r.reference = Object::cast_to<T>(refb);
ref(r);
r.reference = nullptr;
}

View File

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

View File

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

View File

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

View File

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