mirror of
https://forge.univ-lyon1.fr/tplifap4/dungeonanddeamon.git
synced 2024-02-27 13:31:50 +01:00
Let's code
This commit is contained in:
82
GodoBinding/include/core/AABB.hpp
Normal file
82
GodoBinding/include/core/AABB.hpp
Normal file
@ -0,0 +1,82 @@
|
||||
#ifndef AABB_H
|
||||
#define AABB_H
|
||||
|
||||
#include "Vector3.hpp"
|
||||
|
||||
#include "Plane.hpp"
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class AABB {
|
||||
public:
|
||||
Vector3 position;
|
||||
Vector3 size;
|
||||
|
||||
real_t get_area() const; /// get area
|
||||
inline bool has_no_area() const {
|
||||
|
||||
return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON);
|
||||
}
|
||||
|
||||
inline bool has_no_surface() const {
|
||||
|
||||
return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON);
|
||||
}
|
||||
|
||||
inline const Vector3 &get_position() const { return position; }
|
||||
inline void set_position(const Vector3 &p_position) { position = p_position; }
|
||||
inline const Vector3 &get_size() const { return size; }
|
||||
inline void set_size(const Vector3 &p_size) { size = p_size; }
|
||||
|
||||
bool operator==(const AABB &p_rval) const;
|
||||
bool operator!=(const AABB &p_rval) const;
|
||||
|
||||
bool intersects(const AABB &p_aabb) const; /// Both AABBs overlap
|
||||
bool intersects_inclusive(const AABB &p_aabb) const; /// Both AABBs (or their faces) overlap
|
||||
bool encloses(const AABB &p_aabb) const; /// p_aabb is completely inside this
|
||||
|
||||
AABB merge(const AABB &p_with) const;
|
||||
void merge_with(const AABB &p_aabb); ///merge with another AABB
|
||||
AABB intersection(const AABB &p_aabb) const; ///get box where two intersect, empty if no intersection occurs
|
||||
bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||
bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = nullptr, Vector3 *r_normal = nullptr) const;
|
||||
bool smits_intersect_ray(const Vector3 &from, const Vector3 &p_dir, real_t t0, real_t t1) const;
|
||||
|
||||
bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const;
|
||||
bool intersects_plane(const Plane &p_plane) const;
|
||||
|
||||
bool has_point(const Vector3 &p_point) const;
|
||||
Vector3 get_support(const Vector3 &p_normal) const;
|
||||
|
||||
Vector3 get_longest_axis() const;
|
||||
int get_longest_axis_index() const;
|
||||
real_t get_longest_axis_size() const;
|
||||
|
||||
Vector3 get_shortest_axis() const;
|
||||
int get_shortest_axis_index() const;
|
||||
real_t get_shortest_axis_size() const;
|
||||
|
||||
AABB grow(real_t p_by) const;
|
||||
void grow_by(real_t p_amount);
|
||||
|
||||
void get_edge(int p_edge, Vector3 &r_from, Vector3 &r_to) const;
|
||||
Vector3 get_endpoint(int p_point) const;
|
||||
|
||||
AABB expand(const Vector3 &p_vector) const;
|
||||
void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const;
|
||||
void expand_to(const Vector3 &p_vector); /** expand to contain a point if necesary */
|
||||
|
||||
operator String() const;
|
||||
|
||||
inline AABB() {}
|
||||
inline AABB(const Vector3 &p_pos, const Vector3 &p_size) {
|
||||
position = p_pos;
|
||||
size = p_size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // RECT3_H
|
154
GodoBinding/include/core/Array.hpp
Normal file
154
GodoBinding/include/core/Array.hpp
Normal file
@ -0,0 +1,154 @@
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include <gdnative/array.h>
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
namespace helpers {
|
||||
template <typename T, typename ValueT>
|
||||
T append_all(T appendable, ValueT value) {
|
||||
appendable.append(value);
|
||||
return appendable;
|
||||
}
|
||||
|
||||
template <typename T, typename ValueT, typename... Args>
|
||||
T append_all(T appendable, ValueT value, Args... args) {
|
||||
appendable.append(value);
|
||||
return append_all(appendable, args...);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T append_all(T appendable) {
|
||||
return appendable;
|
||||
}
|
||||
|
||||
template <typename KV, typename KeyT, typename ValueT>
|
||||
KV add_all(KV kv, KeyT key, ValueT value) {
|
||||
kv[key] = value;
|
||||
return kv;
|
||||
}
|
||||
|
||||
template <typename KV, typename KeyT, typename ValueT, typename... Args>
|
||||
KV add_all(KV kv, KeyT key, ValueT value, Args... args) {
|
||||
kv[key] = value;
|
||||
return add_all(kv, args...);
|
||||
}
|
||||
|
||||
template <typename KV>
|
||||
KV add_all(KV kv) {
|
||||
return kv;
|
||||
}
|
||||
} // namespace helpers
|
||||
|
||||
class Variant;
|
||||
class PoolByteArray;
|
||||
class PoolIntArray;
|
||||
class PoolRealArray;
|
||||
class PoolStringArray;
|
||||
class PoolVector2Array;
|
||||
class PoolVector3Array;
|
||||
class PoolColorArray;
|
||||
|
||||
class Object;
|
||||
|
||||
class Array {
|
||||
godot_array _godot_array;
|
||||
|
||||
public:
|
||||
Array();
|
||||
Array(const Array &other);
|
||||
Array &operator=(const Array &other);
|
||||
|
||||
Array(const PoolByteArray &a);
|
||||
|
||||
Array(const PoolIntArray &a);
|
||||
|
||||
Array(const PoolRealArray &a);
|
||||
|
||||
Array(const PoolStringArray &a);
|
||||
|
||||
Array(const PoolVector2Array &a);
|
||||
|
||||
Array(const PoolVector3Array &a);
|
||||
|
||||
Array(const PoolColorArray &a);
|
||||
|
||||
template <class... Args>
|
||||
static Array make(Args... args) {
|
||||
return helpers::append_all(Array(), args...);
|
||||
}
|
||||
|
||||
Variant &operator[](const int idx);
|
||||
|
||||
Variant operator[](const int idx) const;
|
||||
|
||||
void append(const Variant &v);
|
||||
|
||||
void clear();
|
||||
|
||||
int count(const Variant &v);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
void erase(const Variant &v);
|
||||
|
||||
Variant front() const;
|
||||
|
||||
Variant back() const;
|
||||
|
||||
int find(const Variant &what, const int from = 0);
|
||||
|
||||
int find_last(const Variant &what);
|
||||
|
||||
bool has(const Variant &what) const;
|
||||
|
||||
uint32_t hash() const;
|
||||
|
||||
void insert(const int pos, const Variant &value);
|
||||
|
||||
void invert();
|
||||
|
||||
bool is_shared() const;
|
||||
|
||||
Variant pop_back();
|
||||
|
||||
Variant pop_front();
|
||||
|
||||
void push_back(const Variant &v);
|
||||
|
||||
void push_front(const Variant &v);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
int rfind(const Variant &what, const int from = -1);
|
||||
|
||||
void sort();
|
||||
|
||||
void sort_custom(Object *obj, const String &func);
|
||||
|
||||
int bsearch(const Variant &value, const bool before = true);
|
||||
|
||||
int bsearch_custom(const Variant &value, const Object *obj,
|
||||
const String &func, const bool before = true);
|
||||
|
||||
Array duplicate(const bool deep = false) const;
|
||||
|
||||
Variant max() const;
|
||||
|
||||
Variant min() const;
|
||||
|
||||
void shuffle();
|
||||
|
||||
~Array();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // ARRAY_H
|
423
GodoBinding/include/core/Basis.hpp
Normal file
423
GodoBinding/include/core/Basis.hpp
Normal file
@ -0,0 +1,423 @@
|
||||
#ifndef BASIS_H
|
||||
#define BASIS_H
|
||||
|
||||
#include <gdnative/basis.h>
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include "Vector3.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Quat;
|
||||
|
||||
class Basis {
|
||||
private:
|
||||
// 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
|
||||
// instructions in case of matrix-vector multiplications.
|
||||
// With this helper template native scripts see the data as if it was column major
|
||||
// without actually transposing the basis matrix at the script-engine boundary.
|
||||
template <int column>
|
||||
class ColumnVector3 {
|
||||
private:
|
||||
template <int column1, int component>
|
||||
class ColumnVectorComponent {
|
||||
private:
|
||||
Vector3 elements[3];
|
||||
|
||||
protected:
|
||||
inline ColumnVectorComponent<column1, component> &operator=(const ColumnVectorComponent<column1, component> &p_value) {
|
||||
return *this = real_t(p_value);
|
||||
}
|
||||
|
||||
inline ColumnVectorComponent(const ColumnVectorComponent<column1, component> &p_value) {
|
||||
*this = real_t(p_value);
|
||||
}
|
||||
|
||||
inline ColumnVectorComponent<column1, component> &operator=(const real_t &p_value) {
|
||||
elements[component][column1] = p_value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline operator real_t() const {
|
||||
return elements[component][column1];
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
enum Axis {
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
AXIS_Z,
|
||||
};
|
||||
|
||||
union {
|
||||
ColumnVectorComponent<column, 0> x;
|
||||
ColumnVectorComponent<column, 1> y;
|
||||
ColumnVectorComponent<column, 2> z;
|
||||
|
||||
Vector3 elements[3]; // Not for direct access, use [] operator instead
|
||||
};
|
||||
|
||||
inline ColumnVector3<column> &operator=(const ColumnVector3<column> &p_value) {
|
||||
return *this = Vector3(p_value);
|
||||
}
|
||||
|
||||
inline ColumnVector3(const ColumnVector3<column> &p_value) {
|
||||
*this = Vector3(p_value);
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator=(const Vector3 &p_value) {
|
||||
elements[0][column] = p_value.x;
|
||||
elements[1][column] = p_value.y;
|
||||
elements[2][column] = p_value.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline operator Vector3() const {
|
||||
return Vector3(elements[0][column], elements[1][column], elements[2][column]);
|
||||
}
|
||||
|
||||
// Unfortunately, we also need to replicate the other interfaces of Vector3 in
|
||||
// order for being able to directly operate on these "meta-Vector3" objects without
|
||||
// an explicit cast or an intermediate assignment to a real Vector3 object.
|
||||
|
||||
inline const real_t &operator[](int p_axis) const {
|
||||
return elements[p_axis][column];
|
||||
}
|
||||
|
||||
inline real_t &operator[](int p_axis) {
|
||||
return elements[p_axis][column];
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator+=(const Vector3 &p_v) {
|
||||
return *this = *this + p_v;
|
||||
}
|
||||
|
||||
inline Vector3 operator+(const Vector3 &p_v) const {
|
||||
return Vector3(*this) + p_v;
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator-=(const Vector3 &p_v) {
|
||||
return *this = *this - p_v;
|
||||
}
|
||||
|
||||
inline Vector3 operator-(const Vector3 &p_v) const {
|
||||
return Vector3(*this) - p_v;
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator*=(const Vector3 &p_v) {
|
||||
return *this = *this * p_v;
|
||||
}
|
||||
|
||||
inline Vector3 operator*(const Vector3 &p_v) const {
|
||||
return Vector3(*this) * p_v;
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator/=(const Vector3 &p_v) {
|
||||
return *this = *this / p_v;
|
||||
}
|
||||
|
||||
inline Vector3 operator/(const Vector3 &p_v) const {
|
||||
return Vector3(*this) / p_v;
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator*=(real_t p_scalar) {
|
||||
return *this = *this * p_scalar;
|
||||
}
|
||||
|
||||
inline Vector3 operator*(real_t p_scalar) const {
|
||||
return Vector3(*this) * p_scalar;
|
||||
}
|
||||
|
||||
inline ColumnVector3<column> &operator/=(real_t p_scalar) {
|
||||
return *this = *this / p_scalar;
|
||||
}
|
||||
|
||||
inline Vector3 operator/(real_t p_scalar) const {
|
||||
return Vector3(*this) / p_scalar;
|
||||
}
|
||||
|
||||
inline Vector3 operator-() const {
|
||||
return -Vector3(*this);
|
||||
}
|
||||
|
||||
inline bool operator==(const Vector3 &p_v) const {
|
||||
return Vector3(*this) == p_v;
|
||||
}
|
||||
|
||||
inline bool operator!=(const Vector3 &p_v) const {
|
||||
return Vector3(*this) != p_v;
|
||||
}
|
||||
|
||||
inline bool operator<(const Vector3 &p_v) const {
|
||||
return Vector3(*this) < p_v;
|
||||
}
|
||||
|
||||
inline bool operator<=(const Vector3 &p_v) const {
|
||||
return Vector3(*this) <= p_v;
|
||||
}
|
||||
|
||||
inline Vector3 abs() const {
|
||||
return Vector3(*this).abs();
|
||||
}
|
||||
|
||||
inline Vector3 ceil() const {
|
||||
return Vector3(*this).ceil();
|
||||
}
|
||||
|
||||
inline Vector3 cross(const Vector3 &b) const {
|
||||
return Vector3(*this).cross(b);
|
||||
}
|
||||
|
||||
inline Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const {
|
||||
return Vector3(*this).linear_interpolate(p_b, p_t);
|
||||
}
|
||||
|
||||
inline Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const {
|
||||
return Vector3(*this).cubic_interpolate(b, pre_a, post_b, t);
|
||||
}
|
||||
|
||||
inline Vector3 bounce(const Vector3 &p_normal) const {
|
||||
return Vector3(*this).bounce(p_normal);
|
||||
}
|
||||
|
||||
inline real_t length() const {
|
||||
return Vector3(*this).length();
|
||||
}
|
||||
|
||||
inline real_t length_squared() const {
|
||||
return Vector3(*this).length_squared();
|
||||
}
|
||||
|
||||
inline real_t distance_squared_to(const Vector3 &b) const {
|
||||
return Vector3(*this).distance_squared_to(b);
|
||||
}
|
||||
|
||||
inline real_t distance_to(const Vector3 &b) const {
|
||||
return Vector3(*this).distance_to(b);
|
||||
}
|
||||
|
||||
inline real_t dot(const Vector3 &b) const {
|
||||
return Vector3(*this).dot(b);
|
||||
}
|
||||
|
||||
inline real_t angle_to(const Vector3 &b) const {
|
||||
return Vector3(*this).angle_to(b);
|
||||
}
|
||||
|
||||
inline Vector3 floor() const {
|
||||
return Vector3(*this).floor();
|
||||
}
|
||||
|
||||
inline Vector3 inverse() const {
|
||||
return Vector3(*this).inverse();
|
||||
}
|
||||
|
||||
inline bool is_normalized() const {
|
||||
return Vector3(*this).is_normalized();
|
||||
}
|
||||
|
||||
inline Basis outer(const Vector3 &b) const {
|
||||
return Vector3(*this).outer(b);
|
||||
}
|
||||
|
||||
inline int max_axis() const {
|
||||
return Vector3(*this).max_axis();
|
||||
}
|
||||
|
||||
inline int min_axis() const {
|
||||
return Vector3(*this).min_axis();
|
||||
}
|
||||
|
||||
inline void normalize() {
|
||||
Vector3 v = *this;
|
||||
v.normalize();
|
||||
*this = v;
|
||||
}
|
||||
|
||||
inline Vector3 normalized() const {
|
||||
return Vector3(*this).normalized();
|
||||
}
|
||||
|
||||
inline Vector3 reflect(const Vector3 &by) const {
|
||||
return Vector3(*this).reflect(by);
|
||||
}
|
||||
|
||||
inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {
|
||||
return Vector3(*this).rotated(axis, phi);
|
||||
}
|
||||
|
||||
inline void rotate(const Vector3 &p_axis, real_t p_phi) {
|
||||
Vector3 v = *this;
|
||||
v.rotate(p_axis, p_phi);
|
||||
*this = v;
|
||||
}
|
||||
|
||||
inline Vector3 slide(const Vector3 &by) const {
|
||||
return Vector3(*this).slide(by);
|
||||
}
|
||||
|
||||
inline void snap(real_t p_val) {
|
||||
Vector3 v = *this;
|
||||
v.snap(p_val);
|
||||
*this = v;
|
||||
}
|
||||
|
||||
inline Vector3 snapped(const float by) {
|
||||
return Vector3(*this).snapped(by);
|
||||
}
|
||||
|
||||
inline operator String() const {
|
||||
return String(Vector3(*this));
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
union {
|
||||
ColumnVector3<0> x;
|
||||
ColumnVector3<1> y;
|
||||
ColumnVector3<2> z;
|
||||
|
||||
Vector3 elements[3]; // Not for direct access, use [] operator instead
|
||||
};
|
||||
|
||||
inline Basis(const Basis &p_basis) {
|
||||
elements[0] = p_basis.elements[0];
|
||||
elements[1] = p_basis.elements[1];
|
||||
elements[2] = p_basis.elements[2];
|
||||
}
|
||||
|
||||
inline Basis &operator=(const Basis &p_basis) {
|
||||
elements[0] = p_basis.elements[0];
|
||||
elements[1] = p_basis.elements[1];
|
||||
elements[2] = p_basis.elements[2];
|
||||
return *this;
|
||||
}
|
||||
|
||||
Basis(const Quat &p_quat); // euler
|
||||
Basis(const Vector3 &p_euler); // euler
|
||||
Basis(const Vector3 &p_axis, real_t p_phi);
|
||||
|
||||
Basis(const Vector3 &row0, const Vector3 &row1, const Vector3 &row2);
|
||||
|
||||
Basis(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
||||
|
||||
Basis();
|
||||
|
||||
const Vector3 operator[](int axis) const {
|
||||
return get_axis(axis);
|
||||
}
|
||||
|
||||
ColumnVector3<0> &operator[](int axis) {
|
||||
// We need to do a little pointer magic to get this to work, because the
|
||||
// ColumnVector3 template takes the axis as a template parameter.
|
||||
// Don't touch this unless you're sure what you're doing!
|
||||
return (reinterpret_cast<Basis *>(reinterpret_cast<real_t *>(this) + axis))->x;
|
||||
}
|
||||
|
||||
void invert();
|
||||
|
||||
bool isequal_approx(const Basis &a, const Basis &b) const;
|
||||
|
||||
bool is_orthogonal() const;
|
||||
|
||||
bool is_rotation() const;
|
||||
|
||||
void transpose();
|
||||
|
||||
Basis inverse() const;
|
||||
|
||||
Basis transposed() const;
|
||||
|
||||
real_t determinant() const;
|
||||
|
||||
Vector3 get_axis(int p_axis) const;
|
||||
|
||||
void set_axis(int p_axis, const Vector3 &p_value);
|
||||
|
||||
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||
|
||||
Basis rotated(const Vector3 &p_axis, real_t p_phi) const;
|
||||
|
||||
void scale(const Vector3 &p_scale);
|
||||
|
||||
Basis scaled(const Vector3 &p_scale) const;
|
||||
|
||||
Vector3 get_scale() const;
|
||||
|
||||
Basis slerp(Basis b, float t) const;
|
||||
|
||||
Vector3 get_euler_xyz() const;
|
||||
void set_euler_xyz(const Vector3 &p_euler);
|
||||
Vector3 get_euler_yxz() const;
|
||||
void set_euler_yxz(const Vector3 &p_euler);
|
||||
|
||||
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
||||
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
|
||||
|
||||
// transposed dot products
|
||||
real_t tdotx(const Vector3 &v) const;
|
||||
real_t tdoty(const Vector3 &v) const;
|
||||
real_t tdotz(const Vector3 &v) const;
|
||||
|
||||
bool operator==(const Basis &p_matrix) const;
|
||||
|
||||
bool operator!=(const Basis &p_matrix) const;
|
||||
|
||||
Vector3 xform(const Vector3 &p_vector) const;
|
||||
|
||||
Vector3 xform_inv(const Vector3 &p_vector) const;
|
||||
void operator*=(const Basis &p_matrix);
|
||||
|
||||
Basis operator*(const Basis &p_matrix) const;
|
||||
|
||||
void operator+=(const Basis &p_matrix);
|
||||
|
||||
Basis operator+(const Basis &p_matrix) const;
|
||||
|
||||
void operator-=(const Basis &p_matrix);
|
||||
|
||||
Basis operator-(const Basis &p_matrix) const;
|
||||
|
||||
void operator*=(real_t p_val);
|
||||
|
||||
Basis operator*(real_t p_val) const;
|
||||
|
||||
int get_orthogonal_index() const; // down below
|
||||
|
||||
void set_orthogonal_index(int p_index); // down below
|
||||
|
||||
operator String() const;
|
||||
|
||||
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||
|
||||
/* create / set */
|
||||
|
||||
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz);
|
||||
|
||||
Vector3 get_column(int i) const;
|
||||
|
||||
Vector3 get_row(int i) const;
|
||||
Vector3 get_main_diagonal() const;
|
||||
|
||||
void set_row(int i, const Vector3 &p_row);
|
||||
|
||||
Basis transpose_xform(const Basis &m) const;
|
||||
|
||||
void orthonormalize();
|
||||
|
||||
Basis orthonormalized() const;
|
||||
|
||||
bool is_symmetric() const;
|
||||
|
||||
Basis diagonalize();
|
||||
|
||||
operator Quat() const;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // BASIS_H
|
125
GodoBinding/include/core/Color.hpp
Normal file
125
GodoBinding/include/core/Color.hpp
Normal file
@ -0,0 +1,125 @@
|
||||
#ifndef COLOR_H
|
||||
#define COLOR_H
|
||||
|
||||
#include <gdnative/color.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
struct Color {
|
||||
|
||||
private:
|
||||
// static float _parse_col(const String& p_str, int p_ofs);
|
||||
public:
|
||||
union {
|
||||
|
||||
struct {
|
||||
float r;
|
||||
float g;
|
||||
float b;
|
||||
float a;
|
||||
};
|
||||
float components[4];
|
||||
};
|
||||
|
||||
inline bool operator==(const Color &p_color) const { return (r == p_color.r && g == p_color.g && b == p_color.b && a == p_color.a); }
|
||||
inline bool operator!=(const Color &p_color) const { return (r != p_color.r || g != p_color.g || b != p_color.b || a != p_color.a); }
|
||||
|
||||
uint32_t to_32() const;
|
||||
|
||||
uint32_t to_ARGB32() const;
|
||||
|
||||
uint32_t to_ABGR32() const;
|
||||
|
||||
uint64_t to_ABGR64() const;
|
||||
|
||||
uint64_t to_ARGB64() const;
|
||||
|
||||
uint32_t to_RGBA32() const;
|
||||
|
||||
uint64_t to_RGBA64() const;
|
||||
|
||||
float gray() const;
|
||||
|
||||
uint8_t get_r8() const;
|
||||
|
||||
uint8_t get_g8() const;
|
||||
|
||||
uint8_t get_b8() const;
|
||||
|
||||
uint8_t get_a8() const;
|
||||
|
||||
float get_h() const;
|
||||
|
||||
float get_s() const;
|
||||
|
||||
float get_v() const;
|
||||
|
||||
void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
|
||||
|
||||
Color darkened(const float amount) const;
|
||||
|
||||
Color lightened(const float amount) const;
|
||||
|
||||
Color from_hsv(float p_h, float p_s, float p_v, float p_a = 1.0) const;
|
||||
|
||||
inline float &operator[](int idx) {
|
||||
return components[idx];
|
||||
}
|
||||
inline const float &operator[](int idx) const {
|
||||
return components[idx];
|
||||
}
|
||||
|
||||
void invert();
|
||||
|
||||
void contrast();
|
||||
|
||||
Color inverted() const;
|
||||
|
||||
Color contrasted() const;
|
||||
|
||||
Color linear_interpolate(const Color &p_b, float p_t) const;
|
||||
|
||||
Color blend(const Color &p_over) const;
|
||||
|
||||
Color to_linear() const;
|
||||
|
||||
static Color hex(uint32_t p_hex);
|
||||
|
||||
static Color html(const String &p_color);
|
||||
|
||||
static bool html_is_valid(const String &p_color);
|
||||
|
||||
String to_html(bool p_alpha = true) const;
|
||||
|
||||
bool operator<(const Color &p_color) const; //used in set keys
|
||||
|
||||
operator String() const;
|
||||
|
||||
/**
|
||||
* No construct parameters, r=0, g=0, b=0. a=255
|
||||
*/
|
||||
inline Color() {
|
||||
r = 0;
|
||||
g = 0;
|
||||
b = 0;
|
||||
a = 1.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* RGB / RGBA construct parameters. Alpha is optional, but defaults to 1.0
|
||||
*/
|
||||
inline Color(float p_r, float p_g, float p_b, float p_a = 1.0) {
|
||||
r = p_r;
|
||||
g = p_g;
|
||||
b = p_b;
|
||||
a = p_a;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // COLOR_H
|
26
GodoBinding/include/core/CoreTypes.hpp
Normal file
26
GodoBinding/include/core/CoreTypes.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef CORETYPES_H
|
||||
#define CORETYPES_H
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include "AABB.hpp"
|
||||
#include "Array.hpp"
|
||||
#include "Basis.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Dictionary.hpp"
|
||||
#include "NodePath.hpp"
|
||||
#include "Plane.hpp"
|
||||
#include "PoolArrays.hpp"
|
||||
#include "Quat.hpp"
|
||||
#include "RID.hpp"
|
||||
#include "Rect2.hpp"
|
||||
#include "String.hpp"
|
||||
#include "Transform.hpp"
|
||||
#include "Transform2D.hpp"
|
||||
#include "Variant.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
|
||||
#include "Wrapped.hpp"
|
||||
|
||||
#endif // CORETYPES_H
|
259
GodoBinding/include/core/Defs.hpp
Normal file
259
GodoBinding/include/core/Defs.hpp
Normal file
@ -0,0 +1,259 @@
|
||||
#ifndef DEFS_H
|
||||
#define DEFS_H
|
||||
|
||||
namespace godot {
|
||||
|
||||
enum class Error {
|
||||
OK,
|
||||
FAILED, ///< Generic fail error
|
||||
ERR_UNAVAILABLE, ///< What is requested is unsupported/unavailable
|
||||
ERR_UNCONFIGURED, ///< The object being used hasnt been properly set up yet
|
||||
ERR_UNAUTHORIZED, ///< Missing credentials for requested resource
|
||||
ERR_PARAMETER_RANGE_ERROR, ///< Parameter given out of range (5)
|
||||
ERR_OUT_OF_MEMORY, ///< Out of memory
|
||||
ERR_FILE_NOT_FOUND,
|
||||
ERR_FILE_BAD_DRIVE,
|
||||
ERR_FILE_BAD_PATH,
|
||||
ERR_FILE_NO_PERMISSION, // (10)
|
||||
ERR_FILE_ALREADY_IN_USE,
|
||||
ERR_FILE_CANT_OPEN,
|
||||
ERR_FILE_CANT_WRITE,
|
||||
ERR_FILE_CANT_READ,
|
||||
ERR_FILE_UNRECOGNIZED, // (15)
|
||||
ERR_FILE_CORRUPT,
|
||||
ERR_FILE_MISSING_DEPENDENCIES,
|
||||
ERR_FILE_EOF,
|
||||
ERR_CANT_OPEN, ///< Can't open a resource/socket/file
|
||||
ERR_CANT_CREATE, // (20)
|
||||
ERR_QUERY_FAILED,
|
||||
ERR_ALREADY_IN_USE,
|
||||
ERR_LOCKED, ///< resource is locked
|
||||
ERR_TIMEOUT,
|
||||
ERR_CANT_CONNECT, // (25)
|
||||
ERR_CANT_RESOLVE,
|
||||
ERR_CONNECTION_ERROR,
|
||||
ERR_CANT_AQUIRE_RESOURCE,
|
||||
ERR_CANT_FORK,
|
||||
ERR_INVALID_DATA, ///< Data passed is invalid (30)
|
||||
ERR_INVALID_PARAMETER, ///< Parameter passed is invalid
|
||||
ERR_ALREADY_EXISTS, ///< When adding, item already exists
|
||||
ERR_DOES_NOT_EXIST, ///< When retrieving/erasing, it item does not exist
|
||||
ERR_DATABASE_CANT_READ, ///< database is full
|
||||
ERR_DATABASE_CANT_WRITE, ///< database is full (35)
|
||||
ERR_COMPILATION_FAILED,
|
||||
ERR_METHOD_NOT_FOUND,
|
||||
ERR_LINK_FAILED,
|
||||
ERR_SCRIPT_FAILED,
|
||||
ERR_CYCLIC_LINK, // (40)
|
||||
ERR_INVALID_DECLARATION,
|
||||
ERR_DUPLICATE_SYMBOL,
|
||||
ERR_PARSE_ERROR,
|
||||
ERR_BUSY,
|
||||
ERR_SKIP, // (45)
|
||||
ERR_HELP, ///< user requested help!!
|
||||
ERR_BUG, ///< a bug in the software certainly happened, due to a double check failing or unexpected behavior.
|
||||
ERR_PRINTER_ON_FIRE, /// the parallel port printer is engulfed in flames
|
||||
ERR_OMFG_THIS_IS_VERY_VERY_BAD, ///< shit happens, has never been used, though
|
||||
ERR_WTF = ERR_OMFG_THIS_IS_VERY_VERY_BAD ///< short version of the above
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#include <GodotGlobal.hpp>
|
||||
|
||||
typedef float real_t;
|
||||
|
||||
#define CMP_EPSILON 0.00001
|
||||
#define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON)
|
||||
#define Math_PI 3.14159265358979323846
|
||||
|
||||
#define _PLANE_EQ_DOT_EPSILON 0.999
|
||||
#define _PLANE_EQ_D_EPSILON 0.0001
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#else
|
||||
#define likely(x) x
|
||||
#define unlikely(x) x
|
||||
#endif
|
||||
|
||||
// Don't use this directly; instead, use any of the CRASH_* macros
|
||||
#ifdef _MSC_VER
|
||||
#define GENERATE_TRAP \
|
||||
__debugbreak(); \
|
||||
/* Avoid warning about control paths */ \
|
||||
for (;;) { \
|
||||
}
|
||||
#else
|
||||
#define GENERATE_TRAP __builtin_trap();
|
||||
#endif
|
||||
|
||||
// ERR/WARN macros
|
||||
#ifndef WARN_PRINT
|
||||
#define WARN_PRINT(msg) godot::Godot::print_warning(msg, __func__, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifndef WARN_PRINTS
|
||||
#define WARN_PRINTS(msg) WARN_PRINT((msg).utf8().get_data())
|
||||
#endif
|
||||
|
||||
#ifndef ERR_PRINT
|
||||
#define ERR_PRINT(msg) godot::Godot::print_error(msg, __func__, __FILE__, __LINE__)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_PRINTS
|
||||
#define ERR_PRINTS(msg) ERR_PRINT((msg).utf8().get_data())
|
||||
#endif
|
||||
|
||||
#ifndef FATAL_PRINT
|
||||
#define FATAL_PRINT(msg) ERR_PRINT(godot::String("FATAL: ") + (msg))
|
||||
#endif
|
||||
|
||||
#ifndef ERR_MSG_INDEX
|
||||
#define ERR_MSG_INDEX(index, size) (godot::String("Index ") + #index + "=" + godot::String::num_int64(index) + " out of size (" + #size + "=" + godot::String::num_int64(size) + ")")
|
||||
#endif
|
||||
|
||||
#ifndef ERR_MSG_NULL
|
||||
#define ERR_MSG_NULL(param) (godot::String("Parameter '") + #param + "' is null.")
|
||||
#endif
|
||||
|
||||
#ifndef ERR_MSG_COND
|
||||
#define ERR_MSG_COND(cond) (godot::String("Condition '") + #cond + "' is true.")
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_INDEX
|
||||
#define ERR_FAIL_INDEX(index, size) \
|
||||
do { \
|
||||
if (unlikely((index) < 0 || (index) >= (size))) { \
|
||||
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_INDEX_V
|
||||
#define ERR_FAIL_INDEX_V(index, size, ret) \
|
||||
do { \
|
||||
if (unlikely((index) < 0 || (index) >= (size))) { \
|
||||
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_UNSIGNED_INDEX_V
|
||||
#define ERR_FAIL_UNSIGNED_INDEX_V(index, size, ret) \
|
||||
do { \
|
||||
if (unlikely((index) >= (size))) { \
|
||||
ERR_PRINT(ERR_MSG_INDEX(index, size)); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef CRASH_BAD_INDEX
|
||||
#define CRASH_BAD_INDEX(index, size) \
|
||||
do { \
|
||||
if (unlikely((index) < 0 || (index) >= (size))) { \
|
||||
FATAL_PRINT(ERR_MSG_INDEX(index, size)); \
|
||||
GENERATE_TRAP; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_NULL
|
||||
#define ERR_FAIL_NULL(param) \
|
||||
do { \
|
||||
if (unlikely(!param)) { \
|
||||
ERR_PRINT(ERR_MSG_NULL(param)); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_NULL_V
|
||||
#define ERR_FAIL_NULL_V(param, ret) \
|
||||
do { \
|
||||
if (unlikely(!param)) { \
|
||||
ERR_PRINT(ERR_MSG_NULL(param)); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_COND
|
||||
#define ERR_FAIL_COND(cond) \
|
||||
do { \
|
||||
if (unlikely(cond)) { \
|
||||
ERR_PRINT(ERR_MSG_COND(cond)); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef CRASH_COND
|
||||
#define CRASH_COND(cond) \
|
||||
do { \
|
||||
if (unlikely(cond)) { \
|
||||
FATAL_PRINT(ERR_MSG_COND(cond)); \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_COND_V
|
||||
#define ERR_FAIL_COND_V(cond, ret) \
|
||||
do { \
|
||||
if (unlikely(cond)) { \
|
||||
ERR_PRINT(ERR_MSG_COND(cond)); \
|
||||
return ret; \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_CONTINUE
|
||||
#define ERR_CONTINUE(cond) \
|
||||
{ \
|
||||
if (unlikely(cond)) { \
|
||||
ERR_PRINT(ERR_MSG_COND(cond)); \
|
||||
continue; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ERR_BREAK
|
||||
#define ERR_BREAK(cond) \
|
||||
{ \
|
||||
if (unlikely(cond)) { \
|
||||
ERR_PRINT(ERR_MSG_COND(cond)); \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL
|
||||
#define ERR_FAIL() \
|
||||
do { \
|
||||
ERR_PRINT("Method/Function Failed."); \
|
||||
return; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef ERR_FAIL_V
|
||||
#define ERR_FAIL_V(ret) \
|
||||
do { \
|
||||
ERR_PRINT("Method/Function Failed."); \
|
||||
return ret; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef CRASH_NOW
|
||||
#define CRASH_NOW() \
|
||||
do { \
|
||||
FATAL_PRINT("Method/Function Failed."); \
|
||||
GENERATE_TRAP; \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif // DEFS_H
|
54
GodoBinding/include/core/Dictionary.hpp
Normal file
54
GodoBinding/include/core/Dictionary.hpp
Normal file
@ -0,0 +1,54 @@
|
||||
#ifndef DICTIONARY_H
|
||||
#define DICTIONARY_H
|
||||
|
||||
#include "Variant.hpp"
|
||||
|
||||
#include "Array.hpp"
|
||||
|
||||
#include <gdnative/dictionary.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Dictionary {
|
||||
godot_dictionary _godot_dictionary;
|
||||
|
||||
public:
|
||||
Dictionary();
|
||||
Dictionary(const Dictionary &other);
|
||||
Dictionary &operator=(const Dictionary &other);
|
||||
|
||||
template <class... Args>
|
||||
static Dictionary make(Args... args) {
|
||||
return helpers::add_all(Dictionary(), args...);
|
||||
}
|
||||
|
||||
void clear();
|
||||
|
||||
bool empty() const;
|
||||
|
||||
void erase(const Variant &key);
|
||||
|
||||
bool has(const Variant &key) const;
|
||||
|
||||
bool has_all(const Array &keys) const;
|
||||
|
||||
uint32_t hash() const;
|
||||
|
||||
Array keys() const;
|
||||
|
||||
Variant &operator[](const Variant &key);
|
||||
|
||||
const Variant &operator[](const Variant &key) const;
|
||||
|
||||
int size() const;
|
||||
|
||||
String to_json() const;
|
||||
|
||||
Array values() const;
|
||||
|
||||
~Dictionary();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // DICTIONARY_H
|
472
GodoBinding/include/core/Godot.hpp
Normal file
472
GodoBinding/include/core/Godot.hpp
Normal file
@ -0,0 +1,472 @@
|
||||
#ifndef GODOT_HPP
|
||||
#define GODOT_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include <gdnative_api_struct.gen.h>
|
||||
#include <nativescript/godot_nativescript.h>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "CoreTypes.hpp"
|
||||
#include "Ref.hpp"
|
||||
#include "TagDB.hpp"
|
||||
#include "Variant.hpp"
|
||||
|
||||
#include "Object.hpp"
|
||||
|
||||
#include "GodotGlobal.hpp"
|
||||
|
||||
#include <GDNativeLibrary.hpp>
|
||||
#include <NativeScript.hpp>
|
||||
|
||||
namespace godot {
|
||||
|
||||
template <class T>
|
||||
T *as(const Object *obj) {
|
||||
return (obj) ? (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner) : nullptr;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T *get_wrapper(godot_object *obj) {
|
||||
return (T *)godot::nativescript_1_1_api->godot_nativescript_get_instance_binding_data(godot::_RegisterState::language_index, obj);
|
||||
}
|
||||
|
||||
#define GODOT_CLASS(Name, Base) \
|
||||
\
|
||||
public: \
|
||||
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
||||
enum { ___CLASS_IS_SCRIPT = 1, \
|
||||
}; \
|
||||
inline static Name *_new() { \
|
||||
godot::NativeScript *script = godot::NativeScript::_new(); \
|
||||
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
|
||||
script->set_class_name(#Name); \
|
||||
Name *instance = godot::as<Name>(script->new_()); \
|
||||
return instance; \
|
||||
} \
|
||||
inline static size_t ___get_id() { return typeid(Name).hash_code(); } \
|
||||
inline static size_t ___get_base_id() { return typeid(Base).hash_code(); } \
|
||||
inline static const char *___get_base_type_name() { return Base::___get_class_name(); } \
|
||||
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
||||
\
|
||||
private:
|
||||
|
||||
#define GODOT_SUBCLASS(Name, Base) \
|
||||
\
|
||||
public: \
|
||||
inline static const char *___get_type_name() { return static_cast<const char *>(#Name); } \
|
||||
enum { ___CLASS_IS_SCRIPT = 1, \
|
||||
}; \
|
||||
inline static Name *_new() { \
|
||||
godot::NativeScript *script = godot::NativeScript::_new(); \
|
||||
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
|
||||
script->set_class_name(#Name); \
|
||||
Name *instance = godot::as<Name>(script->new_()); \
|
||||
return instance; \
|
||||
} \
|
||||
inline static size_t ___get_id() { return typeid(Name).hash_code(); }; \
|
||||
inline static size_t ___get_base_id() { return typeid(Base).hash_code(); }; \
|
||||
inline static const char *___get_base_type_name() { return #Base; } \
|
||||
inline static Object *___get_from_variant(godot::Variant a) { return (godot::Object *)godot::as<Name>(godot::Object::___get_from_variant(a)); } \
|
||||
\
|
||||
private:
|
||||
|
||||
template <class T>
|
||||
struct _ArgCast {
|
||||
static T _arg_cast(Variant a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct _ArgCast<T *> {
|
||||
static T *_arg_cast(Variant a) {
|
||||
return (T *)T::___get_from_variant(a);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct _ArgCast<Variant> {
|
||||
static Variant _arg_cast(Variant a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
// instance and destroy funcs
|
||||
|
||||
template <class T>
|
||||
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();
|
||||
d->_init();
|
||||
return d;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void _godot_class_destroy_func(godot_object *p, void *method_data, void *data) {
|
||||
T *d = (T *)data;
|
||||
delete d;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void register_class() {
|
||||
godot_instance_create_func create = {};
|
||||
create.create_func = _godot_class_instance_func<T>;
|
||||
|
||||
godot_instance_destroy_func destroy = {};
|
||||
destroy.destroy_func = _godot_class_destroy_func<T>;
|
||||
|
||||
_TagDB::register_type(T::___get_id(), T::___get_base_id());
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
||||
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *)typeid(T).hash_code());
|
||||
T::_register_methods();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void register_tool_class() {
|
||||
godot_instance_create_func create = {};
|
||||
create.create_func = _godot_class_instance_func<T>;
|
||||
|
||||
godot_instance_destroy_func destroy = {};
|
||||
destroy.destroy_func = _godot_class_destroy_func<T>;
|
||||
|
||||
_TagDB::register_type(T::___get_id(), T::___get_base_id());
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_tool_class(godot::_RegisterState::nativescript_handle, T::___get_type_name(), T::___get_base_type_name(), create, destroy);
|
||||
godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, T::___get_type_name(), (const void *)typeid(T).hash_code());
|
||||
T::_register_methods();
|
||||
}
|
||||
|
||||
// method registering
|
||||
|
||||
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)) {
|
||||
return T::___get_type_name();
|
||||
}
|
||||
|
||||
template <class T, class R, class... args>
|
||||
const char *___get_method_class_name(R (T::*p)(args... a) const) {
|
||||
return T::___get_type_name();
|
||||
}
|
||||
|
||||
// Okay, time for some template magic.
|
||||
// Many thanks to manpat from the GDL Discord Server.
|
||||
|
||||
// This is stuff that's available in C++14 I think, but whatever.
|
||||
|
||||
template <int... I>
|
||||
struct __Sequence {};
|
||||
|
||||
template <int N, int... I>
|
||||
struct __construct_sequence {
|
||||
using type = typename __construct_sequence<N - 1, N - 1, I...>::type;
|
||||
};
|
||||
|
||||
template <int... I>
|
||||
struct __construct_sequence<0, I...> {
|
||||
using type = __Sequence<I...>;
|
||||
};
|
||||
|
||||
// Now the wrapping part.
|
||||
template <class T, class R, class... As>
|
||||
struct _WrappedMethod {
|
||||
R(T::*f)
|
||||
(As...);
|
||||
|
||||
template <int... I>
|
||||
void apply(Variant *ret, T *obj, Variant **args, __Sequence<I...>) {
|
||||
*ret = (obj->*f)(_ArgCast<As>::_arg_cast(*args[I])...);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class... As>
|
||||
struct _WrappedMethod<T, void, As...> {
|
||||
void (T::*f)(As...);
|
||||
|
||||
template <int... 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 v;
|
||||
godot::api->godot_variant_new_nil(&v);
|
||||
|
||||
T *obj = (T *)user_data;
|
||||
_WrappedMethod<T, R, As...> *method = (_WrappedMethod<T, R, As...> *)method_data;
|
||||
|
||||
Variant *var = (Variant *)&v;
|
||||
Variant **arg = (Variant **)args;
|
||||
|
||||
method->apply(var, obj, arg, typename __construct_sequence<sizeof...(As)>::type{});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
template <class T, class R, class... As>
|
||||
void *___make_wrapper_function(R (T::*f)(As...)) {
|
||||
using MethodType = _WrappedMethod<T, R, As...>;
|
||||
MethodType *p = (MethodType *)godot::api->godot_alloc(sizeof(MethodType));
|
||||
p->f = f;
|
||||
return (void *)p;
|
||||
}
|
||||
|
||||
template <class T, class R, class... As>
|
||||
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(As...)) {
|
||||
return (__godot_wrapper_method)&__wrapped_method<T, R, As...>;
|
||||
}
|
||||
|
||||
template <class T, class R, class... A>
|
||||
void *___make_wrapper_function(R (T::*f)(A...) const) {
|
||||
return ___make_wrapper_function((R(T::*)(A...))f);
|
||||
}
|
||||
|
||||
template <class T, class R, class... A>
|
||||
__godot_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const) {
|
||||
return ___get_wrapper_function((R(T::*)(A...))f);
|
||||
}
|
||||
|
||||
template <class M>
|
||||
void register_method(const char *name, M method_ptr, godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) {
|
||||
godot_instance_method method = {};
|
||||
method.method_data = ___make_wrapper_function(method_ptr);
|
||||
method.free_func = godot::api->godot_free;
|
||||
method.method = (__godot_wrapper_method)___get_wrapper_function(method_ptr);
|
||||
|
||||
godot_method_attributes attr = {};
|
||||
attr.rpc_type = rpc_type;
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_method(godot::_RegisterState::nativescript_handle, ___get_method_class_name(method_ptr), name, attr, method);
|
||||
}
|
||||
|
||||
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) {
|
||||
_PropertySetFunc<T, P> *set_func = (_PropertySetFunc<T, P> *)method_data;
|
||||
T *obj = (T *)user_data;
|
||||
|
||||
Variant *v = (Variant *)value;
|
||||
|
||||
(obj->*(set_func->f))(_ArgCast<P>::_arg_cast(*v));
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class P>
|
||||
struct _PropertyGetFunc {
|
||||
P(T::*f)
|
||||
();
|
||||
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;
|
||||
|
||||
godot_variant var;
|
||||
godot::api->godot_variant_new_nil(&var);
|
||||
|
||||
Variant *v = (Variant *)&var;
|
||||
|
||||
*v = (obj->*(get_func->f))();
|
||||
|
||||
return var;
|
||||
}
|
||||
};
|
||||
|
||||
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) {
|
||||
_PropertyDefaultSetFunc<T, P> *set_func = (_PropertyDefaultSetFunc<T, P> *)method_data;
|
||||
T *obj = (T *)user_data;
|
||||
|
||||
Variant *v = (Variant *)value;
|
||||
|
||||
(obj->*(set_func->f)) = _ArgCast<P>::_arg_cast(*v);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class P>
|
||||
struct _PropertyDefaultGetFunc {
|
||||
P(T::*f);
|
||||
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;
|
||||
|
||||
godot_variant var;
|
||||
godot::api->godot_variant_new_nil(&var);
|
||||
|
||||
Variant *v = (Variant *)&var;
|
||||
|
||||
*v = (obj->*(get_func->f));
|
||||
|
||||
return var;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class P>
|
||||
void register_property(const char *name, P(T::*var), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||
Variant def_val = default_value;
|
||||
|
||||
usage = (godot_property_usage_flags)((int)usage | GODOT_PROPERTY_USAGE_SCRIPT_VARIABLE);
|
||||
|
||||
if (def_val.get_type() == Variant::OBJECT) {
|
||||
Object *o = get_wrapper<Object>(def_val.operator godot_object *());
|
||||
if (o && o->is_class("Resource")) {
|
||||
hint = (godot_property_hint)((int)hint | GODOT_PROPERTY_HINT_RESOURCE_TYPE);
|
||||
hint_string = o->get_class();
|
||||
}
|
||||
}
|
||||
|
||||
godot_string *_hint_string = (godot_string *)&hint_string;
|
||||
|
||||
godot_property_attributes attr = {};
|
||||
if (def_val.get_type() == Variant::NIL) {
|
||||
attr.type = Variant::OBJECT;
|
||||
} else {
|
||||
attr.type = def_val.get_type();
|
||||
attr.default_value = *(godot_variant *)&def_val;
|
||||
}
|
||||
|
||||
attr.hint = hint;
|
||||
attr.rset_type = rpc_mode;
|
||||
attr.usage = usage;
|
||||
attr.hint_string = *_hint_string;
|
||||
|
||||
_PropertyDefaultSetFunc<T, P> *wrapped_set = (_PropertyDefaultSetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyDefaultSetFunc<T, P>));
|
||||
wrapped_set->f = var;
|
||||
|
||||
_PropertyDefaultGetFunc<T, P> *wrapped_get = (_PropertyDefaultGetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyDefaultGetFunc<T, P>));
|
||||
wrapped_get->f = var;
|
||||
|
||||
godot_property_set_func set_func = {};
|
||||
set_func.method_data = (void *)wrapped_set;
|
||||
set_func.free_func = godot::api->godot_free;
|
||||
set_func.set_func = &_PropertyDefaultSetFunc<T, P>::_wrapped_setter;
|
||||
|
||||
godot_property_get_func get_func = {};
|
||||
get_func.method_data = (void *)wrapped_get;
|
||||
get_func.free_func = godot::api->godot_free;
|
||||
get_func.get_func = &_PropertyDefaultGetFunc<T, P>::_wrapped_getter;
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
||||
}
|
||||
|
||||
template <class T, class P>
|
||||
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||
Variant def_val = default_value;
|
||||
|
||||
godot_string *_hint_string = (godot_string *)&hint_string;
|
||||
|
||||
godot_property_attributes attr = {};
|
||||
if (def_val.get_type() == Variant::NIL) {
|
||||
attr.type = Variant::OBJECT;
|
||||
} else {
|
||||
attr.type = def_val.get_type();
|
||||
attr.default_value = *(godot_variant *)&def_val;
|
||||
}
|
||||
attr.hint = hint;
|
||||
attr.rset_type = rpc_mode;
|
||||
attr.usage = usage;
|
||||
attr.hint_string = *_hint_string;
|
||||
|
||||
_PropertySetFunc<T, P> *wrapped_set = (_PropertySetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertySetFunc<T, P>));
|
||||
wrapped_set->f = setter;
|
||||
|
||||
_PropertyGetFunc<T, P> *wrapped_get = (_PropertyGetFunc<T, P> *)godot::api->godot_alloc(sizeof(_PropertyGetFunc<T, P>));
|
||||
wrapped_get->f = getter;
|
||||
|
||||
godot_property_set_func set_func = {};
|
||||
set_func.method_data = (void *)wrapped_set;
|
||||
set_func.free_func = godot::api->godot_free;
|
||||
set_func.set_func = &_PropertySetFunc<T, P>::_wrapped_setter;
|
||||
|
||||
godot_property_get_func get_func = {};
|
||||
get_func.method_data = (void *)wrapped_get;
|
||||
get_func.free_func = godot::api->godot_free;
|
||||
get_func.get_func = &_PropertyGetFunc<T, P>::_wrapped_getter;
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_property(godot::_RegisterState::nativescript_handle, T::___get_type_name(), name, &attr, set_func, get_func);
|
||||
}
|
||||
|
||||
template <class T, class P>
|
||||
void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, godot_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, godot_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, godot_property_hint hint = GODOT_PROPERTY_HINT_NONE, String hint_string = "") {
|
||||
register_property(name, setter, (P(T::*)())getter, default_value, rpc_mode, usage, hint, hint_string);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void register_signal(String name, Dictionary args = Dictionary()) {
|
||||
godot_signal signal = {};
|
||||
signal.name = *(godot_string *)&name;
|
||||
signal.num_args = args.size();
|
||||
signal.num_default_args = 0;
|
||||
|
||||
// Need to check because malloc(0) is platform-dependent. Zero arguments will leave args to nullptr.
|
||||
if (signal.num_args != 0) {
|
||||
signal.args = (godot_signal_argument *)godot::api->godot_alloc(sizeof(godot_signal_argument) * signal.num_args);
|
||||
memset((void *)signal.args, 0, sizeof(godot_signal_argument) * signal.num_args);
|
||||
}
|
||||
|
||||
for (int i = 0; i < signal.num_args; i++) {
|
||||
// Array entry = args[i];
|
||||
// String name = entry[0];
|
||||
String name = args.keys()[i];
|
||||
godot_string *_key = (godot_string *)&name;
|
||||
godot::api->godot_string_new_copy(&signal.args[i].name, _key);
|
||||
|
||||
// if (entry.size() > 1) {
|
||||
// signal.args[i].type = entry[1];
|
||||
// }
|
||||
signal.args[i].type = args.values()[i];
|
||||
}
|
||||
|
||||
godot::nativescript_api->godot_nativescript_register_signal(godot::_RegisterState::nativescript_handle, T::___get_type_name(), &signal);
|
||||
|
||||
for (int i = 0; i < signal.num_args; i++) {
|
||||
godot::api->godot_string_destroy(&signal.args[i].name);
|
||||
}
|
||||
|
||||
if (signal.args) {
|
||||
godot::api->godot_free(signal.args);
|
||||
}
|
||||
}
|
||||
|
||||
template <class T, class... Args>
|
||||
void register_signal(String name, Args... varargs) {
|
||||
register_signal<T>(name, Dictionary::make(varargs...));
|
||||
}
|
||||
|
||||
#ifndef GODOT_CPP_NO_OBJECT_CAST
|
||||
template <class T>
|
||||
T *Object::cast_to(const Object *obj) {
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
|
||||
size_t have_tag = (size_t)godot::nativescript_1_1_api->godot_nativescript_get_type_tag(obj->_owner);
|
||||
|
||||
if (have_tag) {
|
||||
if (!godot::_TagDB::is_type_known((size_t)have_tag)) {
|
||||
have_tag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!have_tag) {
|
||||
have_tag = obj->_type_tag;
|
||||
}
|
||||
|
||||
if (godot::_TagDB::is_type_compatible(typeid(T).hash_code(), have_tag)) {
|
||||
return (T::___CLASS_IS_SCRIPT) ? godot::as<T>(obj) : (T *)obj;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // GODOT_H
|
52
GodoBinding/include/core/GodotGlobal.hpp
Normal file
52
GodoBinding/include/core/GodotGlobal.hpp
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef GODOT_GLOBAL_HPP
|
||||
#define GODOT_GLOBAL_HPP
|
||||
|
||||
#include "Array.hpp"
|
||||
#include "String.hpp"
|
||||
#include <gdnative_api_struct.gen.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
extern "C" const godot_gdnative_core_api_struct *api;
|
||||
extern "C" const godot_gdnative_core_1_1_api_struct *core_1_1_api;
|
||||
extern "C" const godot_gdnative_core_1_2_api_struct *core_1_2_api;
|
||||
|
||||
extern "C" const godot_gdnative_ext_nativescript_api_struct *nativescript_api;
|
||||
extern "C" const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api;
|
||||
extern "C" const godot_gdnative_ext_pluginscript_api_struct *pluginscript_api;
|
||||
extern "C" const godot_gdnative_ext_android_api_struct *android_api;
|
||||
extern "C" const godot_gdnative_ext_arvr_api_struct *arvr_api;
|
||||
extern "C" const godot_gdnative_ext_videodecoder_api_struct *videodecoder_api;
|
||||
extern "C" const godot_gdnative_ext_net_api_struct *net_api;
|
||||
extern "C" const godot_gdnative_ext_net_3_2_api_struct *net_3_2_api;
|
||||
|
||||
extern "C" const void *gdnlib;
|
||||
|
||||
class Godot {
|
||||
|
||||
public:
|
||||
static void print(const String &message);
|
||||
static void print_warning(const String &description, const String &function, const String &file, int line);
|
||||
static void print_error(const String &description, const String &function, const String &file, int line);
|
||||
|
||||
static void gdnative_init(godot_gdnative_init_options *o);
|
||||
static void gdnative_terminate(godot_gdnative_terminate_options *o);
|
||||
static void nativescript_init(void *handle);
|
||||
static void nativescript_terminate(void *handle);
|
||||
|
||||
static void gdnative_profiling_add_data(const char *p_signature, uint64_t p_time);
|
||||
|
||||
template <class... Args>
|
||||
static void print(const String &fmt, Args... values) {
|
||||
print(fmt.format(Array::make(values...)));
|
||||
}
|
||||
};
|
||||
|
||||
struct _RegisterState {
|
||||
static void *nativescript_handle;
|
||||
static int language_index;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif
|
34
GodoBinding/include/core/GodotProfiling.hpp
Normal file
34
GodoBinding/include/core/GodotProfiling.hpp
Normal file
@ -0,0 +1,34 @@
|
||||
#ifndef GODOT_PROFILING_HPP
|
||||
#define GODOT_PROFILING_HPP
|
||||
|
||||
#include "OS.hpp"
|
||||
|
||||
|
||||
namespace godot {
|
||||
|
||||
class FunctionProfiling {
|
||||
char signature[1024];
|
||||
uint64_t ticks;
|
||||
|
||||
public:
|
||||
FunctionProfiling(const char *p_function, const int p_line) {
|
||||
snprintf(signature, 1024, "::%d::%s", p_line, p_function);
|
||||
ticks = OS::get_singleton()->get_ticks_usec();
|
||||
}
|
||||
~FunctionProfiling() {
|
||||
uint64_t t = OS::get_singleton()->get_ticks_usec() - ticks;
|
||||
if (t > 0) {
|
||||
Godot::gdnative_profiling_add_data(signature, t);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#ifdef DEBUG_ENABLED
|
||||
#define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__);
|
||||
#else
|
||||
#define GODOT_PROFILING_FUNCTION
|
||||
#endif
|
||||
|
||||
#endif
|
49
GodoBinding/include/core/NodePath.hpp
Normal file
49
GodoBinding/include/core/NodePath.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef NODEPATH_H
|
||||
#define NODEPATH_H
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
#include <gdnative/node_path.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class NodePath {
|
||||
godot_node_path _node_path;
|
||||
|
||||
public:
|
||||
NodePath();
|
||||
|
||||
NodePath(const NodePath &other);
|
||||
|
||||
NodePath(const String &from);
|
||||
|
||||
NodePath(const char *contents);
|
||||
|
||||
String get_name(const int idx) const;
|
||||
|
||||
int get_name_count() const;
|
||||
|
||||
String get_subname(const int idx) const;
|
||||
|
||||
int get_subname_count() const;
|
||||
|
||||
bool is_absolute() const;
|
||||
|
||||
bool is_empty() const;
|
||||
|
||||
NodePath get_as_property_path() const;
|
||||
|
||||
String get_concatenated_subnames() const;
|
||||
|
||||
operator String() const;
|
||||
|
||||
void operator=(const NodePath &other);
|
||||
|
||||
bool operator==(const NodePath &other);
|
||||
|
||||
~NodePath();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // NODEPATH_H
|
68
GodoBinding/include/core/Plane.hpp
Normal file
68
GodoBinding/include/core/Plane.hpp
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef PLANE_H
|
||||
#define PLANE_H
|
||||
|
||||
#include "Vector3.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace godot {
|
||||
|
||||
enum ClockDirection {
|
||||
|
||||
CLOCKWISE,
|
||||
COUNTERCLOCKWISE
|
||||
};
|
||||
|
||||
class Plane {
|
||||
public:
|
||||
Vector3 normal;
|
||||
real_t d;
|
||||
|
||||
void set_normal(const Vector3 &p_normal);
|
||||
|
||||
inline Vector3 get_normal() const { return normal; } ///Point is coplanar, CMP_EPSILON for precision
|
||||
|
||||
void normalize();
|
||||
|
||||
Plane normalized() const;
|
||||
|
||||
/* Plane-Point operations */
|
||||
|
||||
inline Vector3 center() const { return normal * d; }
|
||||
Vector3 get_any_point() const;
|
||||
Vector3 get_any_perpendicular_normal() const;
|
||||
|
||||
bool is_point_over(const Vector3 &p_point) const; ///< Point is over plane
|
||||
real_t distance_to(const Vector3 &p_point) const;
|
||||
bool has_point(const Vector3 &p_point, real_t _epsilon = CMP_EPSILON) const;
|
||||
|
||||
/* intersections */
|
||||
|
||||
bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const;
|
||||
bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const;
|
||||
bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const;
|
||||
|
||||
Vector3 project(const Vector3 &p_point) const;
|
||||
|
||||
/* misc */
|
||||
|
||||
inline Plane operator-() const { return Plane(-normal, -d); }
|
||||
bool is_almost_like(const Plane &p_plane) const;
|
||||
|
||||
bool operator==(const Plane &p_plane) const;
|
||||
bool operator!=(const Plane &p_plane) const;
|
||||
operator String() const;
|
||||
|
||||
inline Plane() { d = 0; }
|
||||
inline Plane(real_t p_a, real_t p_b, real_t p_c, real_t p_d) :
|
||||
normal(p_a, p_b, p_c),
|
||||
d(p_d) {}
|
||||
|
||||
Plane(const Vector3 &p_normal, real_t p_d);
|
||||
Plane(const Vector3 &p_point, const Vector3 &p_normal);
|
||||
Plane(const Vector3 &p_point1, const Vector3 &p_point2, const Vector3 &p_point3, ClockDirection p_dir = CLOCKWISE);
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // PLANE_H
|
700
GodoBinding/include/core/PoolArrays.hpp
Normal file
700
GodoBinding/include/core/PoolArrays.hpp
Normal file
@ -0,0 +1,700 @@
|
||||
#ifndef POOLARRAYS_H
|
||||
#define POOLARRAYS_H
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "GodotGlobal.hpp"
|
||||
#include "String.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
|
||||
#include <gdnative/pool_arrays.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Array;
|
||||
|
||||
class PoolByteArray {
|
||||
godot_pool_byte_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
|
||||
friend class PoolByteArray;
|
||||
godot_pool_byte_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_byte_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_byte_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const uint8_t *ptr() const {
|
||||
return godot::api->godot_pool_byte_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const uint8_t &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_byte_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolByteArray;
|
||||
godot_pool_byte_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_byte_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_byte_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline uint8_t *ptr() const {
|
||||
return godot::api->godot_pool_byte_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline uint8_t &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_byte_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolByteArray();
|
||||
PoolByteArray(const PoolByteArray &p_other);
|
||||
PoolByteArray &operator=(const PoolByteArray &p_other);
|
||||
|
||||
PoolByteArray(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const uint8_t data);
|
||||
|
||||
void append_array(const PoolByteArray &array);
|
||||
|
||||
int insert(const int idx, const uint8_t data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const uint8_t data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const uint8_t data);
|
||||
|
||||
uint8_t operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolByteArray();
|
||||
};
|
||||
|
||||
class PoolIntArray {
|
||||
godot_pool_int_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolIntArray;
|
||||
godot_pool_int_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_int_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_int_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const int *ptr() const {
|
||||
return godot::api->godot_pool_int_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const int &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_int_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolIntArray;
|
||||
godot_pool_int_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_int_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_int_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline int *ptr() const {
|
||||
return godot::api->godot_pool_int_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline int &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_int_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolIntArray();
|
||||
PoolIntArray(const PoolIntArray &p_other);
|
||||
PoolIntArray &operator=(const PoolIntArray &p_other);
|
||||
|
||||
PoolIntArray(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const int data);
|
||||
|
||||
void append_array(const PoolIntArray &array);
|
||||
|
||||
int insert(const int idx, const int data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const int data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const int data);
|
||||
|
||||
int operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolIntArray();
|
||||
};
|
||||
|
||||
class PoolRealArray {
|
||||
godot_pool_real_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolRealArray;
|
||||
godot_pool_real_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_real_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_real_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const real_t *ptr() const {
|
||||
return godot::api->godot_pool_real_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const real_t &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_real_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolRealArray;
|
||||
godot_pool_real_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_real_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_real_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline real_t *ptr() const {
|
||||
return godot::api->godot_pool_real_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline real_t &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_real_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolRealArray();
|
||||
PoolRealArray(const PoolRealArray &p_other);
|
||||
PoolRealArray &operator=(const PoolRealArray &p_other);
|
||||
|
||||
PoolRealArray(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const real_t data);
|
||||
|
||||
void append_array(const PoolRealArray &array);
|
||||
|
||||
int insert(const int idx, const real_t data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const real_t data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const real_t data);
|
||||
|
||||
real_t operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolRealArray();
|
||||
};
|
||||
|
||||
class PoolStringArray {
|
||||
godot_pool_string_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolStringArray;
|
||||
godot_pool_string_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_string_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_string_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const String *ptr() const {
|
||||
return (const String *)godot::api->godot_pool_string_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const String &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_string_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolStringArray;
|
||||
godot_pool_string_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_string_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_string_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline String *ptr() const {
|
||||
return (String *)godot::api->godot_pool_string_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline String &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_string_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolStringArray();
|
||||
PoolStringArray(const PoolStringArray &p_other);
|
||||
PoolStringArray &operator=(const PoolStringArray &p_other);
|
||||
|
||||
PoolStringArray(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const String &data);
|
||||
|
||||
void append_array(const PoolStringArray &array);
|
||||
|
||||
int insert(const int idx, const String &data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const String &data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const String &data);
|
||||
|
||||
const String operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolStringArray();
|
||||
};
|
||||
|
||||
class PoolVector2Array {
|
||||
godot_pool_vector2_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolVector2Array;
|
||||
godot_pool_vector2_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_vector2_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_vector2_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const Vector2 *ptr() const {
|
||||
return (const Vector2 *)godot::api->godot_pool_vector2_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const Vector2 &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_vector2_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolVector2Array;
|
||||
godot_pool_vector2_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_vector2_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_vector2_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline Vector2 *ptr() const {
|
||||
return (Vector2 *)godot::api->godot_pool_vector2_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline Vector2 &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_vector2_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolVector2Array();
|
||||
PoolVector2Array(const PoolVector2Array &p_other);
|
||||
PoolVector2Array &operator=(const PoolVector2Array &p_other);
|
||||
|
||||
PoolVector2Array(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const Vector2 &data);
|
||||
|
||||
void append_array(const PoolVector2Array &array);
|
||||
|
||||
int insert(const int idx, const Vector2 &data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const Vector2 &data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const Vector2 &data);
|
||||
|
||||
const Vector2 operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolVector2Array();
|
||||
};
|
||||
|
||||
class PoolVector3Array {
|
||||
godot_pool_vector3_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolVector3Array;
|
||||
godot_pool_vector3_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_vector3_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_vector3_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const Vector3 *ptr() const {
|
||||
return (const Vector3 *)godot::api->godot_pool_vector3_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const Vector3 &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_vector3_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolVector3Array;
|
||||
godot_pool_vector3_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_vector3_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_vector3_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline Vector3 *ptr() const {
|
||||
return (Vector3 *)godot::api->godot_pool_vector3_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline Vector3 &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_vector3_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolVector3Array();
|
||||
PoolVector3Array(const PoolVector3Array &p_other);
|
||||
PoolVector3Array &operator=(const PoolVector3Array &p_other);
|
||||
|
||||
PoolVector3Array(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const Vector3 &data);
|
||||
|
||||
void append_array(const PoolVector3Array &array);
|
||||
|
||||
int insert(const int idx, const Vector3 &data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const Vector3 &data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const Vector3 &data);
|
||||
|
||||
const Vector3 operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolVector3Array();
|
||||
};
|
||||
|
||||
class PoolColorArray {
|
||||
godot_pool_color_array _godot_array;
|
||||
|
||||
public:
|
||||
class Read {
|
||||
friend class PoolColorArray;
|
||||
godot_pool_color_array_read_access *_read_access;
|
||||
|
||||
public:
|
||||
inline Read() {
|
||||
_read_access = nullptr;
|
||||
}
|
||||
|
||||
inline Read(const Read &p_other) {
|
||||
_read_access = godot::api->godot_pool_color_array_read_access_copy(p_other._read_access);
|
||||
}
|
||||
|
||||
inline ~Read() {
|
||||
godot::api->godot_pool_color_array_read_access_destroy(_read_access);
|
||||
}
|
||||
|
||||
inline const Color *ptr() const {
|
||||
return (const Color *)godot::api->godot_pool_color_array_read_access_ptr(_read_access);
|
||||
}
|
||||
|
||||
inline const Color &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Read &p_other) {
|
||||
godot::api->godot_pool_color_array_read_access_operator_assign(_read_access, p_other._read_access);
|
||||
}
|
||||
};
|
||||
|
||||
class Write {
|
||||
friend class PoolColorArray;
|
||||
godot_pool_color_array_write_access *_write_access;
|
||||
|
||||
public:
|
||||
inline Write() {
|
||||
_write_access = nullptr;
|
||||
}
|
||||
|
||||
inline Write(const Write &p_other) {
|
||||
_write_access = godot::api->godot_pool_color_array_write_access_copy(p_other._write_access);
|
||||
}
|
||||
|
||||
inline ~Write() {
|
||||
godot::api->godot_pool_color_array_write_access_destroy(_write_access);
|
||||
}
|
||||
|
||||
inline Color *ptr() const {
|
||||
return (Color *)godot::api->godot_pool_color_array_write_access_ptr(_write_access);
|
||||
}
|
||||
|
||||
inline Color &operator[](int p_idx) const {
|
||||
return ptr()[p_idx];
|
||||
}
|
||||
|
||||
inline void operator=(const Write &p_other) {
|
||||
godot::api->godot_pool_color_array_write_access_operator_assign(_write_access, p_other._write_access);
|
||||
}
|
||||
};
|
||||
|
||||
PoolColorArray();
|
||||
PoolColorArray(const PoolColorArray &p_other);
|
||||
PoolColorArray &operator=(const PoolColorArray &p_other);
|
||||
|
||||
PoolColorArray(const Array &array);
|
||||
|
||||
Read read() const;
|
||||
|
||||
Write write();
|
||||
|
||||
void append(const Color &data);
|
||||
|
||||
void append_array(const PoolColorArray &array);
|
||||
|
||||
int insert(const int idx, const Color &data);
|
||||
|
||||
void invert();
|
||||
|
||||
void push_back(const Color &data);
|
||||
|
||||
void remove(const int idx);
|
||||
|
||||
void resize(const int size);
|
||||
|
||||
void set(const int idx, const Color &data);
|
||||
|
||||
const Color operator[](const int idx);
|
||||
|
||||
int size() const;
|
||||
|
||||
~PoolColorArray();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // POOLARRAYS_H
|
93
GodoBinding/include/core/Quat.hpp
Normal file
93
GodoBinding/include/core/Quat.hpp
Normal file
@ -0,0 +1,93 @@
|
||||
#ifndef QUAT_H
|
||||
#define QUAT_H
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "Vector3.hpp"
|
||||
|
||||
// #include "Basis.h"
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Quat {
|
||||
public:
|
||||
real_t x, y, z, w;
|
||||
|
||||
real_t length_squared() const;
|
||||
real_t length() const;
|
||||
|
||||
void normalize();
|
||||
|
||||
Quat normalized() const;
|
||||
|
||||
bool is_normalized() const;
|
||||
|
||||
Quat inverse() const;
|
||||
|
||||
void set_euler_xyz(const Vector3 &p_euler);
|
||||
Vector3 get_euler_xyz() const;
|
||||
void set_euler_yxz(const Vector3 &p_euler);
|
||||
Vector3 get_euler_yxz() const;
|
||||
|
||||
inline void set_euler(const Vector3 &p_euler) { set_euler_yxz(p_euler); }
|
||||
inline Vector3 get_euler() const { return get_euler_yxz(); }
|
||||
|
||||
real_t dot(const Quat &q) const;
|
||||
|
||||
Quat slerp(const Quat &q, const real_t &t) const;
|
||||
|
||||
Quat slerpni(const Quat &q, const real_t &t) const;
|
||||
|
||||
Quat cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const;
|
||||
|
||||
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
|
||||
|
||||
void set_axis_angle(const Vector3 &axis, const float angle);
|
||||
|
||||
void operator*=(const Quat &q);
|
||||
Quat operator*(const Quat &q) const;
|
||||
|
||||
Quat operator*(const Vector3 &v) const;
|
||||
|
||||
Vector3 xform(const Vector3 &v) const;
|
||||
|
||||
void operator+=(const Quat &q);
|
||||
void operator-=(const Quat &q);
|
||||
void operator*=(const real_t &s);
|
||||
void operator/=(const real_t &s);
|
||||
Quat operator+(const Quat &q2) const;
|
||||
Quat operator-(const Quat &q2) const;
|
||||
Quat operator-() const;
|
||||
Quat operator*(const real_t &s) const;
|
||||
Quat operator/(const real_t &s) const;
|
||||
|
||||
bool operator==(const Quat &p_quat) const;
|
||||
bool operator!=(const Quat &p_quat) const;
|
||||
|
||||
operator String() const;
|
||||
|
||||
inline void set(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
||||
x = p_x;
|
||||
y = p_y;
|
||||
z = p_z;
|
||||
w = p_w;
|
||||
}
|
||||
inline Quat(real_t p_x, real_t p_y, real_t p_z, real_t p_w) {
|
||||
x = p_x;
|
||||
y = p_y;
|
||||
z = p_z;
|
||||
w = p_w;
|
||||
}
|
||||
Quat(const Vector3 &axis, const real_t &angle);
|
||||
|
||||
Quat(const Vector3 &v0, const Vector3 &v1);
|
||||
|
||||
inline Quat() {
|
||||
x = y = z = 0;
|
||||
w = 1;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // QUAT_H
|
35
GodoBinding/include/core/RID.hpp
Normal file
35
GodoBinding/include/core/RID.hpp
Normal file
@ -0,0 +1,35 @@
|
||||
#ifndef RID_H
|
||||
#define RID_H
|
||||
|
||||
#include <gdnative/rid.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Object;
|
||||
|
||||
class RID {
|
||||
godot_rid _godot_rid;
|
||||
|
||||
public:
|
||||
RID();
|
||||
|
||||
RID(Object *p);
|
||||
|
||||
int32_t get_rid() const;
|
||||
|
||||
inline bool is_valid() const {
|
||||
// is_valid() is not available in the C API...
|
||||
return *this != RID();
|
||||
}
|
||||
|
||||
bool operator==(const RID &p_other) const;
|
||||
bool operator!=(const RID &p_other) const;
|
||||
bool operator<(const RID &p_other) const;
|
||||
bool operator>(const RID &p_other) const;
|
||||
bool operator<=(const RID &p_other) const;
|
||||
bool operator>=(const RID &p_other) const;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // RID_H
|
135
GodoBinding/include/core/Rect2.hpp
Normal file
135
GodoBinding/include/core/Rect2.hpp
Normal file
@ -0,0 +1,135 @@
|
||||
#ifndef RECT2_H
|
||||
#define RECT2_H
|
||||
|
||||
#include "Vector2.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include <cstdlib>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class String;
|
||||
|
||||
typedef Vector2 Size2;
|
||||
typedef Vector2 Point2;
|
||||
|
||||
struct Transform2D;
|
||||
|
||||
struct Rect2 {
|
||||
|
||||
Point2 position;
|
||||
Size2 size;
|
||||
|
||||
inline const Vector2 &get_position() const { return position; }
|
||||
inline void set_position(const Vector2 &p_position) { position = p_position; }
|
||||
inline const Vector2 &get_size() const { return size; }
|
||||
inline void set_size(const Vector2 &p_size) { size = p_size; }
|
||||
|
||||
inline real_t get_area() const { return size.width * size.height; }
|
||||
|
||||
inline bool intersects(const Rect2 &p_rect) const {
|
||||
if (position.x >= (p_rect.position.x + p_rect.size.width))
|
||||
return false;
|
||||
if ((position.x + size.width) <= p_rect.position.x)
|
||||
return false;
|
||||
if (position.y >= (p_rect.position.y + p_rect.size.height))
|
||||
return false;
|
||||
if ((position.y + size.height) <= p_rect.position.y)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
real_t distance_to(const Vector2 &p_point) const;
|
||||
|
||||
bool intersects_transformed(const Transform2D &p_xform, const Rect2 &p_rect) const;
|
||||
|
||||
bool intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_position = nullptr, Point2 *r_normal = nullptr) const;
|
||||
|
||||
inline bool encloses(const Rect2 &p_rect) const {
|
||||
|
||||
return (p_rect.position.x >= position.x) && (p_rect.position.y >= position.y) &&
|
||||
((p_rect.position.x + p_rect.size.x) < (position.x + size.x)) &&
|
||||
((p_rect.position.y + p_rect.size.y) < (position.y + size.y));
|
||||
}
|
||||
|
||||
inline bool has_no_area() const {
|
||||
|
||||
return (size.x <= 0 || size.y <= 0);
|
||||
}
|
||||
Rect2 clip(const Rect2 &p_rect) const;
|
||||
|
||||
Rect2 merge(const Rect2 &p_rect) const;
|
||||
|
||||
inline bool has_point(const Point2 &p_point) const {
|
||||
if (p_point.x < position.x)
|
||||
return false;
|
||||
if (p_point.y < position.y)
|
||||
return false;
|
||||
|
||||
if (p_point.x >= (position.x + size.x))
|
||||
return false;
|
||||
if (p_point.y >= (position.y + size.y))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool no_area() const { return (size.width <= 0 || size.height <= 0); }
|
||||
|
||||
inline bool operator==(const Rect2 &p_rect) const { return position == p_rect.position && size == p_rect.size; }
|
||||
inline bool operator!=(const Rect2 &p_rect) const { return position != p_rect.position || size != p_rect.size; }
|
||||
|
||||
inline Rect2 grow(real_t p_by) const {
|
||||
|
||||
Rect2 g = *this;
|
||||
g.position.x -= p_by;
|
||||
g.position.y -= p_by;
|
||||
g.size.width += p_by * 2;
|
||||
g.size.height += p_by * 2;
|
||||
return g;
|
||||
}
|
||||
|
||||
inline Rect2 expand(const Vector2 &p_vector) const {
|
||||
|
||||
Rect2 r = *this;
|
||||
r.expand_to(p_vector);
|
||||
return r;
|
||||
}
|
||||
|
||||
inline void expand_to(const Vector2 &p_vector) { //in place function for speed
|
||||
|
||||
Vector2 begin = position;
|
||||
Vector2 end = position + size;
|
||||
|
||||
if (p_vector.x < begin.x)
|
||||
begin.x = p_vector.x;
|
||||
if (p_vector.y < begin.y)
|
||||
begin.y = p_vector.y;
|
||||
|
||||
if (p_vector.x > end.x)
|
||||
end.x = p_vector.x;
|
||||
if (p_vector.y > end.y)
|
||||
end.y = p_vector.y;
|
||||
|
||||
position = begin;
|
||||
size = end - begin;
|
||||
}
|
||||
|
||||
operator String() const;
|
||||
|
||||
inline Rect2() {}
|
||||
inline Rect2(real_t p_x, real_t p_y, real_t p_width, real_t p_height) {
|
||||
position = Point2(p_x, p_y);
|
||||
size = Size2(p_width, p_height);
|
||||
}
|
||||
inline Rect2(const Point2 &p_position, const Size2 &p_size) {
|
||||
position = p_position;
|
||||
size = p_size;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // RECT2_H
|
214
GodoBinding/include/core/Ref.hpp
Normal file
214
GodoBinding/include/core/Ref.hpp
Normal file
@ -0,0 +1,214 @@
|
||||
#ifndef REF_H
|
||||
#define REF_H
|
||||
|
||||
#include "GodotGlobal.hpp"
|
||||
#include "Reference.hpp"
|
||||
#include "Variant.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
// Replicates Godot's Ref<T> behavior
|
||||
// Rewritten from f5234e70be7dec4930c2d5a0e829ff480d044b1d.
|
||||
template <class T>
|
||||
class Ref {
|
||||
|
||||
T *reference = nullptr;
|
||||
|
||||
void ref(const Ref &p_from) {
|
||||
|
||||
if (p_from.reference == reference)
|
||||
return;
|
||||
|
||||
unref();
|
||||
|
||||
reference = p_from.reference;
|
||||
if (reference)
|
||||
reference->reference();
|
||||
}
|
||||
|
||||
void ref_pointer(T *p_ref) {
|
||||
|
||||
ERR_FAIL_COND(!p_ref);
|
||||
|
||||
if (p_ref->init_ref())
|
||||
reference = p_ref;
|
||||
}
|
||||
|
||||
public:
|
||||
inline bool operator<(const Ref<T> &p_r) const {
|
||||
|
||||
return reference < p_r.reference;
|
||||
}
|
||||
inline bool operator==(const Ref<T> &p_r) const {
|
||||
|
||||
return reference == p_r.reference;
|
||||
}
|
||||
inline bool operator!=(const Ref<T> &p_r) const {
|
||||
|
||||
return reference != p_r.reference;
|
||||
}
|
||||
|
||||
inline T *operator->() {
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
inline T *operator*() {
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
inline const T *operator->() const {
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
inline const T *ptr() const {
|
||||
|
||||
return reference;
|
||||
}
|
||||
inline T *ptr() {
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
inline const T *operator*() const {
|
||||
|
||||
return reference;
|
||||
}
|
||||
|
||||
operator Variant() const {
|
||||
// Note: the C API handles the cases where the object is a Reference,
|
||||
// so the Variant will be correctly constructed with a RefPtr engine-side
|
||||
return Variant((Object *)reference);
|
||||
}
|
||||
|
||||
void operator=(const Ref &p_from) {
|
||||
|
||||
ref(p_from);
|
||||
}
|
||||
|
||||
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) {
|
||||
unref();
|
||||
return;
|
||||
}
|
||||
Ref r;
|
||||
//r.reference = Object::cast_to<T>(refb);
|
||||
r.reference = (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) {
|
||||
unref();
|
||||
return;
|
||||
}
|
||||
Ref r;
|
||||
// TODO We need a safe cast
|
||||
//r.reference = Object::cast_to<T>(refb);
|
||||
r.reference = (T *)refb;
|
||||
ref(r);
|
||||
r.reference = nullptr;
|
||||
}
|
||||
|
||||
Ref(const Ref &p_from) {
|
||||
|
||||
reference = nullptr;
|
||||
ref(p_from);
|
||||
}
|
||||
|
||||
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) {
|
||||
unref();
|
||||
return;
|
||||
}
|
||||
Ref r;
|
||||
// TODO We need a safe cast
|
||||
//r.reference = Object::cast_to<T>(refb);
|
||||
r.reference = (T *)refb;
|
||||
ref(r);
|
||||
r.reference = nullptr;
|
||||
}
|
||||
|
||||
Ref(T *p_reference) {
|
||||
|
||||
if (p_reference)
|
||||
ref_pointer(p_reference);
|
||||
else
|
||||
reference = nullptr;
|
||||
}
|
||||
|
||||
Ref(const Variant &p_variant) {
|
||||
|
||||
reference = nullptr;
|
||||
// TODO We need a safe cast
|
||||
Reference *refb = (Reference *)T::___get_from_variant(p_variant);
|
||||
if (!refb) {
|
||||
unref();
|
||||
return;
|
||||
}
|
||||
Ref r;
|
||||
// TODO We need a safe cast
|
||||
//r.reference = Object::cast_to<T>(refb);
|
||||
r.reference = (T *)refb;
|
||||
ref(r);
|
||||
r.reference = nullptr;
|
||||
}
|
||||
|
||||
inline bool is_valid() const { return reference != nullptr; }
|
||||
inline bool is_null() const { return reference == nullptr; }
|
||||
|
||||
void unref() {
|
||||
//TODO this should be moved to mutexes, since this engine does not really
|
||||
// do a lot of referencing on references and stuff
|
||||
// mutexes will avoid more crashes?
|
||||
|
||||
if (reference && reference->unreference()) {
|
||||
|
||||
//memdelete(reference);
|
||||
reference->free();
|
||||
}
|
||||
reference = nullptr;
|
||||
}
|
||||
|
||||
void instance() {
|
||||
//ref(memnew(T));
|
||||
ref(T::_new());
|
||||
}
|
||||
|
||||
Ref() {
|
||||
|
||||
reference = nullptr;
|
||||
}
|
||||
|
||||
~Ref() {
|
||||
|
||||
unref();
|
||||
}
|
||||
|
||||
// Used exclusively in the bindings to recreate the Ref Godot encapsulates in return values,
|
||||
// without adding to the refcount.
|
||||
inline static Ref<T> __internal_constructor(Object *obj) {
|
||||
Ref<T> r;
|
||||
r.reference = (T *)obj;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif
|
147
GodoBinding/include/core/String.hpp
Normal file
147
GodoBinding/include/core/String.hpp
Normal file
@ -0,0 +1,147 @@
|
||||
#ifndef STRING_H
|
||||
#define STRING_H
|
||||
|
||||
#include <gdnative/string.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class NodePath;
|
||||
class Variant;
|
||||
class PoolByteArray;
|
||||
class PoolIntArray;
|
||||
class PoolRealArray;
|
||||
class PoolStringArray;
|
||||
class String;
|
||||
|
||||
class CharString {
|
||||
|
||||
friend class String;
|
||||
|
||||
godot_char_string _char_string;
|
||||
|
||||
public:
|
||||
~CharString();
|
||||
|
||||
int length() const;
|
||||
const char *get_data() const;
|
||||
};
|
||||
|
||||
class String {
|
||||
godot_string _godot_string;
|
||||
|
||||
public:
|
||||
String();
|
||||
String(const char *contents);
|
||||
String(const wchar_t *contents);
|
||||
String(const wchar_t c);
|
||||
String(const String &other);
|
||||
|
||||
~String();
|
||||
|
||||
static String num(double p_num, int p_decimals = -1);
|
||||
static String num_scientific(double p_num);
|
||||
static String num_real(double p_num);
|
||||
static String num_int64(int64_t p_num, int base = 10, bool capitalize_hex = false);
|
||||
static String chr(godot_char_type p_char);
|
||||
static String md5(const uint8_t *p_md5);
|
||||
static String hex_encode_buffer(const uint8_t *p_buffer, int p_len);
|
||||
|
||||
wchar_t &operator[](const int idx);
|
||||
wchar_t operator[](const int idx) const;
|
||||
|
||||
void operator=(const String &s);
|
||||
bool operator==(const String &s) const;
|
||||
bool operator!=(const String &s) const;
|
||||
String operator+(const String &s) const;
|
||||
void operator+=(const String &s);
|
||||
void operator+=(const wchar_t c);
|
||||
bool operator<(const String &s) const;
|
||||
bool operator<=(const String &s) const;
|
||||
bool operator>(const String &s) const;
|
||||
bool operator>=(const String &s) const;
|
||||
|
||||
operator NodePath() const;
|
||||
|
||||
int length() const;
|
||||
const wchar_t *unicode_str() const;
|
||||
char *alloc_c_string() const;
|
||||
CharString utf8() const;
|
||||
CharString ascii(bool p_extended = false) const;
|
||||
|
||||
bool begins_with(String &s) const;
|
||||
bool begins_with_char_array(const char *p_char_array) const;
|
||||
PoolStringArray bigrams() const;
|
||||
String c_escape() const;
|
||||
String c_unescape() const;
|
||||
String capitalize() const;
|
||||
bool empty() const;
|
||||
bool ends_with(String &text) const;
|
||||
void erase(int position, int chars);
|
||||
int find(String what, int from = 0) const;
|
||||
int find_last(String what) const;
|
||||
int findn(String what, int from = 0) const;
|
||||
String format(Variant values) const;
|
||||
String format(Variant values, String placeholder) const;
|
||||
String get_base_dir() const;
|
||||
String get_basename() const;
|
||||
String get_extension() const;
|
||||
String get_file() const;
|
||||
int hash() const;
|
||||
int hex_to_int() const;
|
||||
String insert(int position, String what) const;
|
||||
bool is_abs_path() const;
|
||||
bool is_rel_path() const;
|
||||
bool is_subsequence_of(String text) const;
|
||||
bool is_subsequence_ofi(String text) const;
|
||||
bool is_valid_float() const;
|
||||
bool is_valid_html_color() const;
|
||||
bool is_valid_identifier() const;
|
||||
bool is_valid_integer() const;
|
||||
bool is_valid_ip_address() const;
|
||||
String json_escape() const;
|
||||
String left(int position) const;
|
||||
bool match(String expr) const;
|
||||
bool matchn(String expr) const;
|
||||
PoolByteArray md5_buffer() const;
|
||||
String md5_text() const;
|
||||
int ord_at(int at) const;
|
||||
String pad_decimals(int digits) const;
|
||||
String pad_zeros(int digits) const;
|
||||
String percent_decode() const;
|
||||
String percent_encode() const;
|
||||
String plus_file(String file) const;
|
||||
String replace(String what, String forwhat) const;
|
||||
String replacen(String what, String forwhat) const;
|
||||
int rfind(String what, int from = -1) const;
|
||||
int rfindn(String what, int from = -1) const;
|
||||
String right(int position) const;
|
||||
PoolByteArray sha256_buffer() const;
|
||||
String sha256_text() const;
|
||||
float similarity(String text) const;
|
||||
PoolStringArray split(String divisor, bool allow_empty = true) const;
|
||||
PoolIntArray split_ints(String divisor, bool allow_empty = true) const;
|
||||
PoolRealArray split_floats(String divisor, bool allow_empty = true) const;
|
||||
String strip_edges(bool left = true, bool right = true) const;
|
||||
String substr(int from, int len) const;
|
||||
float to_float() const;
|
||||
int64_t to_int() const;
|
||||
String to_lower() const;
|
||||
String to_upper() const;
|
||||
String xml_escape() const;
|
||||
String xml_unescape() const;
|
||||
signed char casecmp_to(String p_str) const;
|
||||
signed char nocasecmp_to(String p_str) const;
|
||||
signed char naturalnocasecmp_to(String p_str) const;
|
||||
String dedent() const;
|
||||
PoolStringArray rsplit(const String &divisor, const bool allow_empty = true, const int maxsplit = 0) const;
|
||||
String rstrip(const String &chars) const;
|
||||
String trim_prefix(const String &prefix) const;
|
||||
String trim_suffix(const String &suffix) const;
|
||||
};
|
||||
|
||||
String operator+(const char *a, const String &b);
|
||||
String operator+(const wchar_t *a, const String &b);
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // STRING_H
|
19
GodoBinding/include/core/TagDB.hpp
Normal file
19
GodoBinding/include/core/TagDB.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef TAGDB_HPP
|
||||
#define TAGDB_HPP
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
namespace _TagDB {
|
||||
|
||||
void register_type(size_t type_tag, size_t base_type_tag);
|
||||
bool is_type_known(size_t type_tag);
|
||||
void register_global_type(const char *name, size_t type_tag, size_t base_type_tag);
|
||||
bool is_type_compatible(size_t type_tag, size_t base_type_tag);
|
||||
|
||||
} // namespace _TagDB
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // TAGDB_HPP
|
86
GodoBinding/include/core/Transform.hpp
Normal file
86
GodoBinding/include/core/Transform.hpp
Normal file
@ -0,0 +1,86 @@
|
||||
#ifndef TRANSFORM_H
|
||||
#define TRANSFORM_H
|
||||
|
||||
#include "Basis.hpp"
|
||||
|
||||
#include "AABB.hpp"
|
||||
#include "Plane.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Transform {
|
||||
public:
|
||||
Basis basis;
|
||||
Vector3 origin;
|
||||
|
||||
void invert();
|
||||
Transform inverse() const;
|
||||
|
||||
void affine_invert();
|
||||
Transform affine_inverse() const;
|
||||
|
||||
Transform rotated(const Vector3 &p_axis, real_t p_phi) const;
|
||||
|
||||
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||
void rotate_basis(const Vector3 &p_axis, real_t p_phi);
|
||||
|
||||
void set_look_at(const Vector3 &p_eye, const Vector3 &p_target, const Vector3 &p_up);
|
||||
Transform looking_at(const Vector3 &p_target, const Vector3 &p_up) const;
|
||||
|
||||
void scale(const Vector3 &p_scale);
|
||||
Transform scaled(const Vector3 &p_scale) const;
|
||||
void scale_basis(const Vector3 &p_scale);
|
||||
void translate(real_t p_tx, real_t p_ty, real_t p_tz);
|
||||
void translate(const Vector3 &p_translation);
|
||||
Transform translated(const Vector3 &p_translation) const;
|
||||
|
||||
inline const Basis &get_basis() const { return basis; }
|
||||
inline void set_basis(const Basis &p_basis) { basis = p_basis; }
|
||||
|
||||
inline const Vector3 &get_origin() const { return origin; }
|
||||
inline void set_origin(const Vector3 &p_origin) { origin = p_origin; }
|
||||
|
||||
void orthonormalize();
|
||||
Transform orthonormalized() const;
|
||||
|
||||
bool operator==(const Transform &p_transform) const;
|
||||
bool operator!=(const Transform &p_transform) const;
|
||||
|
||||
Vector3 xform(const Vector3 &p_vector) const;
|
||||
Vector3 xform_inv(const Vector3 &p_vector) const;
|
||||
|
||||
Plane xform(const Plane &p_plane) const;
|
||||
Plane xform_inv(const Plane &p_plane) const;
|
||||
|
||||
AABB xform(const AABB &p_aabb) const;
|
||||
AABB xform_inv(const AABB &p_aabb) const;
|
||||
|
||||
void operator*=(const Transform &p_transform);
|
||||
Transform operator*(const Transform &p_transform) const;
|
||||
|
||||
inline Vector3 operator*(const Vector3 &p_vector) const {
|
||||
return Vector3(
|
||||
basis.elements[0].dot(p_vector) + origin.x,
|
||||
basis.elements[1].dot(p_vector) + origin.y,
|
||||
basis.elements[2].dot(p_vector) + origin.z);
|
||||
}
|
||||
|
||||
Transform interpolate_with(const Transform &p_transform, real_t p_c) const;
|
||||
|
||||
Transform inverse_xform(const Transform &t) const;
|
||||
|
||||
void set(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz);
|
||||
|
||||
operator String() const;
|
||||
|
||||
inline Transform(real_t xx, real_t xy, real_t xz, real_t yx, real_t yy, real_t yz, real_t zx, real_t zy, real_t zz, real_t tx, real_t ty, real_t tz) {
|
||||
set(xx, xy, xz, yx, yy, yz, zx, zy, zz, tx, ty, tz);
|
||||
}
|
||||
|
||||
Transform(const Basis &p_basis, const Vector3 &p_origin = Vector3());
|
||||
inline Transform() {}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // TRANSFORM_H
|
102
GodoBinding/include/core/Transform2D.hpp
Normal file
102
GodoBinding/include/core/Transform2D.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
#ifndef TRANSFORM2D_H
|
||||
#define TRANSFORM2D_H
|
||||
|
||||
#include "Vector2.hpp"
|
||||
|
||||
namespace godot {
|
||||
|
||||
typedef Vector2 Size2;
|
||||
|
||||
struct Rect2;
|
||||
|
||||
struct Transform2D {
|
||||
// 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])
|
||||
// This is such that the columns, which can be interpreted as basis vectors of the coordinate system "painted" on the object, can be accessed as elements[i].
|
||||
// Note that this is the opposite of the indices in mathematical texts, meaning: $M_{12}$ in a math book corresponds to elements[1][0] here.
|
||||
// This requires additional care when working with explicit indices.
|
||||
// See https://en.wikipedia.org/wiki/Row-_and_column-major_order for further reading.
|
||||
|
||||
// Warning #2: 2D be aware that unlike 3D code, 2D code uses a left-handed coordinate system: Y-axis points down,
|
||||
// and angle is measure from +X to +Y in a clockwise-fashion.
|
||||
|
||||
Vector2 elements[3];
|
||||
|
||||
inline real_t tdotx(const Vector2 &v) const { return elements[0][0] * v.x + elements[1][0] * v.y; }
|
||||
inline real_t tdoty(const Vector2 &v) const { return elements[0][1] * v.x + elements[1][1] * v.y; }
|
||||
|
||||
inline const Vector2 &operator[](int p_idx) const { return elements[p_idx]; }
|
||||
inline Vector2 &operator[](int p_idx) { return elements[p_idx]; }
|
||||
|
||||
inline Vector2 get_axis(int p_axis) const {
|
||||
ERR_FAIL_INDEX_V(p_axis, 3, Vector2());
|
||||
return elements[p_axis];
|
||||
}
|
||||
inline void set_axis(int p_axis, const Vector2 &p_vec) {
|
||||
ERR_FAIL_INDEX(p_axis, 3);
|
||||
elements[p_axis] = p_vec;
|
||||
}
|
||||
|
||||
void invert();
|
||||
Transform2D inverse() const;
|
||||
|
||||
void affine_invert();
|
||||
Transform2D affine_inverse() const;
|
||||
|
||||
void set_rotation(real_t p_phi);
|
||||
real_t get_rotation() const;
|
||||
void set_rotation_and_scale(real_t p_phi, const Size2 &p_scale);
|
||||
void rotate(real_t p_phi);
|
||||
|
||||
void scale(const Size2 &p_scale);
|
||||
void scale_basis(const Size2 &p_scale);
|
||||
void translate(real_t p_tx, real_t p_ty);
|
||||
void translate(const Vector2 &p_translation);
|
||||
|
||||
real_t basis_determinant() const;
|
||||
|
||||
Size2 get_scale() const;
|
||||
|
||||
inline const Vector2 &get_origin() const { return elements[2]; }
|
||||
inline void set_origin(const Vector2 &p_origin) { elements[2] = p_origin; }
|
||||
|
||||
Transform2D scaled(const Size2 &p_scale) const;
|
||||
Transform2D basis_scaled(const Size2 &p_scale) const;
|
||||
Transform2D translated(const Vector2 &p_offset) const;
|
||||
Transform2D rotated(real_t p_phi) const;
|
||||
|
||||
Transform2D untranslated() const;
|
||||
|
||||
void orthonormalize();
|
||||
Transform2D orthonormalized() const;
|
||||
|
||||
bool operator==(const Transform2D &p_transform) const;
|
||||
bool operator!=(const Transform2D &p_transform) const;
|
||||
|
||||
void operator*=(const Transform2D &p_transform);
|
||||
Transform2D operator*(const Transform2D &p_transform) const;
|
||||
|
||||
Transform2D interpolate_with(const Transform2D &p_transform, real_t p_c) const;
|
||||
|
||||
Vector2 basis_xform(const Vector2 &p_vec) const;
|
||||
Vector2 basis_xform_inv(const Vector2 &p_vec) const;
|
||||
Vector2 xform(const Vector2 &p_vec) const;
|
||||
Vector2 xform_inv(const Vector2 &p_vec) const;
|
||||
Rect2 xform(const Rect2 &p_vec) const;
|
||||
Rect2 xform_inv(const Rect2 &p_vec) const;
|
||||
|
||||
operator String() const;
|
||||
|
||||
Transform2D(real_t xx, real_t xy, real_t yx, real_t yy, real_t ox, real_t oy);
|
||||
|
||||
Transform2D(real_t p_rot, const Vector2 &p_pos);
|
||||
inline Transform2D() {
|
||||
elements[0][0] = 1.0;
|
||||
elements[1][1] = 1.0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // TRANSFORM2D_H
|
269
GodoBinding/include/core/Variant.hpp
Normal file
269
GodoBinding/include/core/Variant.hpp
Normal file
@ -0,0 +1,269 @@
|
||||
#ifndef VARIANT_H
|
||||
#define VARIANT_H
|
||||
|
||||
#include <gdnative/variant.h>
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include "AABB.hpp"
|
||||
#include "Basis.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "NodePath.hpp"
|
||||
#include "Plane.hpp"
|
||||
#include "PoolArrays.hpp"
|
||||
#include "Quat.hpp"
|
||||
#include "RID.hpp"
|
||||
#include "Rect2.hpp"
|
||||
#include "String.hpp"
|
||||
#include "Transform.hpp"
|
||||
#include "Transform2D.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Dictionary;
|
||||
|
||||
class Array;
|
||||
|
||||
class Variant {
|
||||
godot_variant _godot_variant;
|
||||
|
||||
public:
|
||||
enum Type {
|
||||
|
||||
NIL,
|
||||
|
||||
// atomic types
|
||||
BOOL,
|
||||
INT,
|
||||
REAL,
|
||||
STRING,
|
||||
|
||||
// math types
|
||||
|
||||
VECTOR2, // 5
|
||||
RECT2,
|
||||
VECTOR3,
|
||||
TRANSFORM2D,
|
||||
PLANE,
|
||||
QUAT, // 10
|
||||
RECT3, //sorry naming convention fail :( not like it's used often
|
||||
BASIS,
|
||||
TRANSFORM,
|
||||
|
||||
// misc types
|
||||
COLOR,
|
||||
NODE_PATH, // 15
|
||||
_RID,
|
||||
OBJECT,
|
||||
DICTIONARY,
|
||||
ARRAY,
|
||||
|
||||
// arrays
|
||||
POOL_BYTE_ARRAY, // 20
|
||||
POOL_INT_ARRAY,
|
||||
POOL_REAL_ARRAY,
|
||||
POOL_STRING_ARRAY,
|
||||
POOL_VECTOR2_ARRAY,
|
||||
POOL_VECTOR3_ARRAY, // 25
|
||||
POOL_COLOR_ARRAY,
|
||||
|
||||
VARIANT_MAX
|
||||
|
||||
};
|
||||
|
||||
enum Operator {
|
||||
|
||||
//comparation
|
||||
OP_EQUAL,
|
||||
OP_NOT_EQUAL,
|
||||
OP_LESS,
|
||||
OP_LESS_EQUAL,
|
||||
OP_GREATER,
|
||||
OP_GREATER_EQUAL,
|
||||
|
||||
//mathematic
|
||||
OP_ADD,
|
||||
OP_SUBSTRACT,
|
||||
OP_MULTIPLY,
|
||||
OP_DIVIDE,
|
||||
OP_NEGATE,
|
||||
OP_POSITIVE,
|
||||
OP_MODULE,
|
||||
OP_STRING_CONCAT,
|
||||
|
||||
//bitwise
|
||||
OP_SHIFT_LEFT,
|
||||
OP_SHIFT_RIGHT,
|
||||
OP_BIT_AND,
|
||||
OP_BIT_OR,
|
||||
OP_BIT_XOR,
|
||||
OP_BIT_NEGATE,
|
||||
|
||||
//logic
|
||||
OP_AND,
|
||||
OP_OR,
|
||||
OP_XOR,
|
||||
OP_NOT,
|
||||
|
||||
//containment
|
||||
OP_IN,
|
||||
OP_MAX
|
||||
|
||||
};
|
||||
|
||||
Variant();
|
||||
|
||||
Variant(const Variant &v);
|
||||
|
||||
Variant(bool p_bool);
|
||||
|
||||
Variant(signed int p_int);
|
||||
|
||||
Variant(unsigned int p_int);
|
||||
|
||||
Variant(signed short p_short);
|
||||
|
||||
inline Variant(unsigned short p_short) :
|
||||
Variant((unsigned int)p_short) {}
|
||||
|
||||
inline Variant(signed char p_char) :
|
||||
Variant((signed int)p_char) {}
|
||||
|
||||
inline Variant(unsigned char p_char) :
|
||||
Variant((unsigned int)p_char) {}
|
||||
Variant(int64_t p_char);
|
||||
|
||||
Variant(uint64_t p_char);
|
||||
|
||||
Variant(float p_float);
|
||||
|
||||
Variant(double p_double);
|
||||
|
||||
Variant(const String &p_string);
|
||||
|
||||
Variant(const char *const p_cstring);
|
||||
|
||||
Variant(const wchar_t *p_wstring);
|
||||
|
||||
Variant(const Vector2 &p_vector2);
|
||||
|
||||
Variant(const Rect2 &p_rect2);
|
||||
|
||||
Variant(const Vector3 &p_vector3);
|
||||
|
||||
Variant(const Plane &p_plane);
|
||||
|
||||
Variant(const AABB &p_aabb);
|
||||
|
||||
Variant(const Quat &p_quat);
|
||||
|
||||
Variant(const Basis &p_transform);
|
||||
|
||||
Variant(const Transform2D &p_transform);
|
||||
|
||||
Variant(const Transform &p_transform);
|
||||
|
||||
Variant(const Color &p_color);
|
||||
|
||||
Variant(const NodePath &p_path);
|
||||
|
||||
Variant(const RID &p_rid);
|
||||
|
||||
Variant(const Object *p_object);
|
||||
|
||||
Variant(const Dictionary &p_dictionary);
|
||||
|
||||
Variant(const Array &p_array);
|
||||
|
||||
Variant(const PoolByteArray &p_raw_array);
|
||||
|
||||
Variant(const PoolIntArray &p_int_array);
|
||||
|
||||
Variant(const PoolRealArray &p_real_array);
|
||||
|
||||
Variant(const PoolStringArray &p_string_array);
|
||||
|
||||
Variant(const PoolVector2Array &p_vector2_array);
|
||||
|
||||
Variant(const PoolVector3Array &p_vector3_array);
|
||||
|
||||
Variant(const PoolColorArray &p_color_array);
|
||||
|
||||
Variant &operator=(const Variant &v);
|
||||
|
||||
operator bool() const;
|
||||
operator signed int() const;
|
||||
operator unsigned int() const;
|
||||
operator signed short() const;
|
||||
operator unsigned short() const;
|
||||
operator signed char() const;
|
||||
operator unsigned char() const;
|
||||
operator int64_t() const;
|
||||
operator uint64_t() const;
|
||||
|
||||
operator wchar_t() const;
|
||||
|
||||
operator float() const;
|
||||
|
||||
operator double() const;
|
||||
operator String() const;
|
||||
operator Vector2() const;
|
||||
operator Rect2() const;
|
||||
operator Vector3() const;
|
||||
operator Plane() const;
|
||||
operator AABB() const;
|
||||
operator Quat() const;
|
||||
operator Basis() const;
|
||||
operator Transform() const;
|
||||
operator Transform2D() const;
|
||||
|
||||
operator Color() const;
|
||||
|
||||
operator NodePath() const;
|
||||
operator RID() const;
|
||||
operator godot_object *() const;
|
||||
template <typename T> operator T*() const { return static_cast<T*>(T::___get_from_variant(*this)); }
|
||||
|
||||
operator Dictionary() const;
|
||||
operator Array() const;
|
||||
|
||||
operator PoolByteArray() const;
|
||||
operator PoolIntArray() const;
|
||||
operator PoolRealArray() const;
|
||||
operator PoolStringArray() const;
|
||||
operator PoolVector2Array() const;
|
||||
operator PoolVector3Array() const;
|
||||
operator PoolColorArray() const;
|
||||
|
||||
Type get_type() const;
|
||||
|
||||
Variant call(const String &method, const Variant **args, const int arg_count);
|
||||
|
||||
bool has_method(const String &method);
|
||||
|
||||
bool operator==(const Variant &b) const;
|
||||
|
||||
bool operator!=(const Variant &b) const;
|
||||
|
||||
bool operator<(const Variant &b) const;
|
||||
|
||||
bool operator<=(const Variant &b) const;
|
||||
|
||||
bool operator>(const Variant &b) const;
|
||||
|
||||
bool operator>=(const Variant &b) const;
|
||||
|
||||
bool hash_compare(const Variant &b) const;
|
||||
|
||||
bool booleanize() const;
|
||||
|
||||
~Variant();
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // VARIANT_H
|
232
GodoBinding/include/core/Vector2.hpp
Normal file
232
GodoBinding/include/core/Vector2.hpp
Normal file
@ -0,0 +1,232 @@
|
||||
#ifndef VECTOR2_H
|
||||
#define VECTOR2_H
|
||||
|
||||
#include <gdnative/vector2.h>
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class String;
|
||||
|
||||
struct Vector2 {
|
||||
|
||||
union {
|
||||
real_t x;
|
||||
real_t width;
|
||||
};
|
||||
union {
|
||||
real_t y;
|
||||
real_t height;
|
||||
};
|
||||
|
||||
inline Vector2(real_t p_x, real_t p_y) {
|
||||
x = p_x;
|
||||
y = p_y;
|
||||
}
|
||||
|
||||
inline Vector2() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
inline real_t &operator[](int p_idx) {
|
||||
return p_idx ? y : x;
|
||||
}
|
||||
|
||||
inline const real_t &operator[](int p_idx) const {
|
||||
return p_idx ? y : x;
|
||||
}
|
||||
|
||||
inline Vector2 operator+(const Vector2 &p_v) const {
|
||||
return Vector2(x + p_v.x, y + p_v.y);
|
||||
}
|
||||
|
||||
inline void operator+=(const Vector2 &p_v) {
|
||||
x += p_v.x;
|
||||
y += p_v.y;
|
||||
}
|
||||
|
||||
inline Vector2 operator-(const Vector2 &p_v) const {
|
||||
return Vector2(x - p_v.x, y - p_v.y);
|
||||
}
|
||||
|
||||
inline void operator-=(const Vector2 &p_v) {
|
||||
x -= p_v.x;
|
||||
y -= p_v.y;
|
||||
}
|
||||
|
||||
inline Vector2 operator*(const Vector2 &p_v1) const {
|
||||
return Vector2(x * p_v1.x, y * p_v1.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator*(const real_t &rvalue) const {
|
||||
return Vector2(x * rvalue, y * rvalue);
|
||||
}
|
||||
|
||||
inline void operator*=(const real_t &rvalue) {
|
||||
x *= rvalue;
|
||||
y *= rvalue;
|
||||
}
|
||||
|
||||
inline void operator*=(const Vector2 &rvalue) {
|
||||
*this = *this * rvalue;
|
||||
}
|
||||
|
||||
inline Vector2 operator/(const Vector2 &p_v1) const {
|
||||
return Vector2(x / p_v1.x, y / p_v1.y);
|
||||
}
|
||||
|
||||
inline Vector2 operator/(const real_t &rvalue) const {
|
||||
return Vector2(x / rvalue, y / rvalue);
|
||||
}
|
||||
|
||||
inline void operator/=(const real_t &rvalue) {
|
||||
x /= rvalue;
|
||||
y /= rvalue;
|
||||
}
|
||||
|
||||
inline Vector2 operator-() const {
|
||||
return Vector2(-x, -y);
|
||||
}
|
||||
|
||||
bool operator==(const Vector2 &p_vec2) const;
|
||||
|
||||
bool operator!=(const Vector2 &p_vec2) const;
|
||||
|
||||
inline bool operator<(const Vector2 &p_vec2) const { return (x == p_vec2.x) ? (y < p_vec2.y) : (x < p_vec2.x); }
|
||||
inline bool operator<=(const Vector2 &p_vec2) const { return (x == p_vec2.x) ? (y <= p_vec2.y) : (x <= p_vec2.x); }
|
||||
|
||||
inline void normalize() {
|
||||
real_t l = x * x + y * y;
|
||||
if (l != 0) {
|
||||
l = sqrt(l);
|
||||
x /= l;
|
||||
y /= l;
|
||||
}
|
||||
}
|
||||
|
||||
inline Vector2 normalized() const {
|
||||
Vector2 v = *this;
|
||||
v.normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
inline real_t length() const {
|
||||
return sqrt(x * x + y * y);
|
||||
}
|
||||
|
||||
inline real_t length_squared() const {
|
||||
return x * x + y * y;
|
||||
}
|
||||
|
||||
inline real_t distance_to(const Vector2 &p_vector2) const {
|
||||
return sqrt((x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y));
|
||||
}
|
||||
|
||||
inline real_t distance_squared_to(const Vector2 &p_vector2) const {
|
||||
return (x - p_vector2.x) * (x - p_vector2.x) + (y - p_vector2.y) * (y - p_vector2.y);
|
||||
}
|
||||
|
||||
inline real_t angle_to(const Vector2 &p_vector2) const {
|
||||
return atan2(cross(p_vector2), dot(p_vector2));
|
||||
}
|
||||
|
||||
inline real_t angle_to_point(const Vector2 &p_vector2) const {
|
||||
return atan2(y - p_vector2.y, x - p_vector2.x);
|
||||
}
|
||||
|
||||
inline real_t dot(const Vector2 &p_other) const {
|
||||
return x * p_other.x + y * p_other.y;
|
||||
}
|
||||
|
||||
inline real_t cross(const Vector2 &p_other) const {
|
||||
return x * p_other.y - y * p_other.x;
|
||||
}
|
||||
|
||||
inline Vector2 cross(real_t p_other) const {
|
||||
return Vector2(p_other * y, -p_other * x);
|
||||
}
|
||||
|
||||
Vector2 project(const Vector2 &p_vec) const;
|
||||
|
||||
Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const;
|
||||
|
||||
Vector2 clamped(real_t p_len) const;
|
||||
|
||||
static inline Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) {
|
||||
Vector2 res = p_a;
|
||||
res.x += (p_t * (p_b.x - p_a.x));
|
||||
res.y += (p_t * (p_b.y - p_a.y));
|
||||
return res;
|
||||
}
|
||||
|
||||
inline Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const {
|
||||
Vector2 res = *this;
|
||||
res.x += (p_t * (p_b.x - x));
|
||||
res.y += (p_t * (p_b.y - y));
|
||||
return res;
|
||||
}
|
||||
|
||||
Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const;
|
||||
|
||||
inline Vector2 slide(const Vector2 &p_vec) const {
|
||||
return p_vec - *this * this->dot(p_vec);
|
||||
}
|
||||
|
||||
inline Vector2 bounce(const Vector2 &p_normal) const {
|
||||
return -reflect(p_normal);
|
||||
}
|
||||
|
||||
inline Vector2 reflect(const Vector2 &p_vec) const {
|
||||
return p_vec - *this * this->dot(p_vec) * 2.0;
|
||||
}
|
||||
|
||||
inline real_t angle() const {
|
||||
return atan2(y, x);
|
||||
}
|
||||
|
||||
inline void set_rotation(real_t p_radians) {
|
||||
x = cosf(p_radians);
|
||||
y = sinf(p_radians);
|
||||
}
|
||||
|
||||
inline Vector2 abs() const {
|
||||
return Vector2(fabs(x), fabs(y));
|
||||
}
|
||||
|
||||
inline Vector2 rotated(real_t p_by) const {
|
||||
Vector2 v;
|
||||
v.set_rotation(angle() + p_by);
|
||||
v *= length();
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector2 tangent() const {
|
||||
return Vector2(y, -x);
|
||||
}
|
||||
|
||||
inline Vector2 floor() const {
|
||||
return Vector2(::floor(x), ::floor(y));
|
||||
}
|
||||
|
||||
inline Vector2 snapped(const Vector2 &p_by) const {
|
||||
return Vector2(
|
||||
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
|
||||
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y);
|
||||
}
|
||||
|
||||
inline real_t aspect() const { return width / height; }
|
||||
|
||||
operator String() const;
|
||||
};
|
||||
|
||||
inline Vector2 operator*(real_t p_scalar, const Vector2 &p_vec) {
|
||||
return p_vec * p_scalar;
|
||||
}
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // VECTOR2_H
|
279
GodoBinding/include/core/Vector3.hpp
Normal file
279
GodoBinding/include/core/Vector3.hpp
Normal file
@ -0,0 +1,279 @@
|
||||
#ifndef VECTOR3_H
|
||||
#define VECTOR3_H
|
||||
|
||||
#include <gdnative/vector3.h>
|
||||
|
||||
#include "Defs.hpp"
|
||||
|
||||
#include "String.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class Basis;
|
||||
|
||||
struct Vector3 {
|
||||
|
||||
enum Axis {
|
||||
AXIS_X,
|
||||
AXIS_Y,
|
||||
AXIS_Z,
|
||||
};
|
||||
|
||||
union {
|
||||
struct {
|
||||
real_t x;
|
||||
real_t y;
|
||||
real_t z;
|
||||
};
|
||||
|
||||
real_t coord[3]; // Not for direct access, use [] operator instead
|
||||
};
|
||||
|
||||
inline Vector3(real_t x, real_t y, real_t z) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
inline Vector3() {
|
||||
this->x = 0;
|
||||
this->y = 0;
|
||||
this->z = 0;
|
||||
}
|
||||
|
||||
inline const real_t &operator[](int p_axis) const {
|
||||
return coord[p_axis];
|
||||
}
|
||||
|
||||
inline real_t &operator[](int p_axis) {
|
||||
return coord[p_axis];
|
||||
}
|
||||
|
||||
inline Vector3 &operator+=(const Vector3 &p_v) {
|
||||
x += p_v.x;
|
||||
y += p_v.y;
|
||||
z += p_v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator+(const Vector3 &p_v) const {
|
||||
Vector3 v = *this;
|
||||
v += p_v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 &operator-=(const Vector3 &p_v) {
|
||||
x -= p_v.x;
|
||||
y -= p_v.y;
|
||||
z -= p_v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator-(const Vector3 &p_v) const {
|
||||
Vector3 v = *this;
|
||||
v -= p_v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 &operator*=(const Vector3 &p_v) {
|
||||
x *= p_v.x;
|
||||
y *= p_v.y;
|
||||
z *= p_v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator*(const Vector3 &p_v) const {
|
||||
Vector3 v = *this;
|
||||
v *= p_v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 &operator/=(const Vector3 &p_v) {
|
||||
x /= p_v.x;
|
||||
y /= p_v.y;
|
||||
z /= p_v.z;
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator/(const Vector3 &p_v) const {
|
||||
Vector3 v = *this;
|
||||
v /= p_v;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 &operator*=(real_t p_scalar) {
|
||||
*this *= Vector3(p_scalar, p_scalar, p_scalar);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator*(real_t p_scalar) const {
|
||||
Vector3 v = *this;
|
||||
v *= p_scalar;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 &operator/=(real_t p_scalar) {
|
||||
*this /= Vector3(p_scalar, p_scalar, p_scalar);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline Vector3 operator/(real_t p_scalar) const {
|
||||
Vector3 v = *this;
|
||||
v /= p_scalar;
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 operator-() const {
|
||||
return Vector3(-x, -y, -z);
|
||||
}
|
||||
|
||||
inline bool operator==(const Vector3 &p_v) const {
|
||||
return (x == p_v.x && y == p_v.y && z == p_v.z);
|
||||
}
|
||||
|
||||
inline bool operator!=(const Vector3 &p_v) const {
|
||||
return (x != p_v.x || y != p_v.y || z != p_v.z);
|
||||
}
|
||||
|
||||
bool operator<(const Vector3 &p_v) const;
|
||||
|
||||
bool operator<=(const Vector3 &p_v) const;
|
||||
|
||||
inline Vector3 abs() const {
|
||||
return Vector3(::fabs(x), ::fabs(y), ::fabs(z));
|
||||
}
|
||||
|
||||
inline Vector3 ceil() const {
|
||||
return Vector3(::ceil(x), ::ceil(y), ::ceil(z));
|
||||
}
|
||||
|
||||
inline Vector3 cross(const Vector3 &b) const {
|
||||
Vector3 ret(
|
||||
(y * b.z) - (z * b.y),
|
||||
(z * b.x) - (x * b.z),
|
||||
(x * b.y) - (y * b.x));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline Vector3 linear_interpolate(const Vector3 &p_b, real_t p_t) const {
|
||||
return Vector3(
|
||||
x + (p_t * (p_b.x - x)),
|
||||
y + (p_t * (p_b.y - y)),
|
||||
z + (p_t * (p_b.z - z)));
|
||||
}
|
||||
|
||||
Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const;
|
||||
|
||||
Vector3 bounce(const Vector3 &p_normal) const {
|
||||
return -reflect(p_normal);
|
||||
}
|
||||
|
||||
inline real_t length() const {
|
||||
real_t x2 = x * x;
|
||||
real_t y2 = y * y;
|
||||
real_t z2 = z * z;
|
||||
|
||||
return ::sqrt(x2 + y2 + z2);
|
||||
}
|
||||
|
||||
inline real_t length_squared() const {
|
||||
real_t x2 = x * x;
|
||||
real_t y2 = y * y;
|
||||
real_t z2 = z * z;
|
||||
|
||||
return x2 + y2 + z2;
|
||||
}
|
||||
|
||||
inline real_t distance_squared_to(const Vector3 &b) const {
|
||||
return (b - *this).length_squared();
|
||||
}
|
||||
|
||||
inline real_t distance_to(const Vector3 &b) const {
|
||||
return (b - *this).length();
|
||||
}
|
||||
|
||||
inline real_t dot(const Vector3 &b) const {
|
||||
return x * b.x + y * b.y + z * b.z;
|
||||
}
|
||||
|
||||
inline real_t angle_to(const Vector3 &b) const {
|
||||
return std::atan2(cross(b).length(), dot(b));
|
||||
}
|
||||
|
||||
inline Vector3 floor() const {
|
||||
return Vector3(::floor(x), ::floor(y), ::floor(z));
|
||||
}
|
||||
|
||||
inline Vector3 inverse() const {
|
||||
return Vector3(1.f / x, 1.f / y, 1.f / z);
|
||||
}
|
||||
|
||||
inline bool is_normalized() const {
|
||||
return std::abs(length_squared() - 1.f) < 0.00001f;
|
||||
}
|
||||
|
||||
Basis outer(const Vector3 &b) const;
|
||||
|
||||
int max_axis() const;
|
||||
|
||||
int min_axis() const;
|
||||
|
||||
inline void normalize() {
|
||||
real_t l = length();
|
||||
if (l == 0) {
|
||||
x = y = z = 0;
|
||||
} else {
|
||||
x /= l;
|
||||
y /= l;
|
||||
z /= l;
|
||||
}
|
||||
}
|
||||
|
||||
inline Vector3 normalized() const {
|
||||
Vector3 v = *this;
|
||||
v.normalize();
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Vector3 reflect(const Vector3 &by) const {
|
||||
return by - *this * this->dot(by) * 2.f;
|
||||
}
|
||||
|
||||
inline Vector3 rotated(const Vector3 &axis, const real_t phi) const {
|
||||
Vector3 v = *this;
|
||||
v.rotate(axis, phi);
|
||||
return v;
|
||||
}
|
||||
|
||||
void rotate(const Vector3 &p_axis, real_t p_phi);
|
||||
|
||||
inline Vector3 slide(const Vector3 &by) const {
|
||||
return by - *this * this->dot(by);
|
||||
}
|
||||
|
||||
void snap(real_t p_val);
|
||||
|
||||
inline Vector3 snapped(const float by) {
|
||||
Vector3 v = *this;
|
||||
v.snap(by);
|
||||
return v;
|
||||
}
|
||||
|
||||
operator String() const;
|
||||
};
|
||||
|
||||
inline Vector3 operator*(real_t p_scalar, const Vector3 &p_vec) {
|
||||
return p_vec * p_scalar;
|
||||
}
|
||||
|
||||
inline Vector3 vec3_cross(const Vector3 &p_a, const Vector3 &p_b) {
|
||||
|
||||
return p_a.cross(p_b);
|
||||
}
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // VECTOR3_H
|
16
GodoBinding/include/core/Wrapped.hpp
Normal file
16
GodoBinding/include/core/Wrapped.hpp
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef WRAPPED_HPP
|
||||
#define WRAPPED_HPP
|
||||
|
||||
#include <gdnative/gdnative.h>
|
||||
|
||||
namespace godot {
|
||||
|
||||
class _Wrapped {
|
||||
public:
|
||||
godot_object *_owner;
|
||||
size_t _type_tag;
|
||||
};
|
||||
|
||||
} // namespace godot
|
||||
|
||||
#endif // WRAPPED_HPP
|
2
GodoBinding/include/gen/.gitignore
vendored
Normal file
2
GodoBinding/include/gen/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
Reference in New Issue
Block a user