diff options
| author | George Marques <george@gmarqu.es> | 2021-08-18 11:03:52 -0300 |
|---|---|---|
| committer | Bastiaan Olij <mux213@gmail.com> | 2021-09-27 23:08:08 +1000 |
| commit | e4ed48976a962b67e9585cc2d20d11f115ef7949 (patch) | |
| tree | 7830ad6926b5cd14a91784b07c2eff5b77e3f533 /include/core | |
| parent | ee708668944430a7f1d69e8faf7b3f3160432dc2 (diff) | |
| download | redot-cpp-e4ed48976a962b67e9585cc2d20d11f115ef7949.tar.gz | |
Replace bindgins to work with extensions
Diffstat (limited to 'include/core')
27 files changed, 0 insertions, 5567 deletions
diff --git a/include/core/AABB.hpp b/include/core/AABB.hpp deleted file mode 100644 index 5c6944f..0000000 --- a/include/core/AABB.hpp +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************/ -/* AABB.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 diff --git a/include/core/Array.hpp b/include/core/Array.hpp deleted file mode 100644 index 91948a4..0000000 --- a/include/core/Array.hpp +++ /dev/null @@ -1,191 +0,0 @@ -/*************************************************************************/ -/* Array.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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; - - friend class Variant; - friend class Dictionary; - friend class String; - inline explicit Array(const godot_array &other) { - _godot_array = other; - } - -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); - - const 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) const; - - int find_last(const Variant &what) const; - - 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) const; - - 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 diff --git a/include/core/Basis.hpp b/include/core/Basis.hpp deleted file mode 100644 index de956e6..0000000 --- a/include/core/Basis.hpp +++ /dev/null @@ -1,458 +0,0 @@ -/*************************************************************************/ -/* Basis.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef BASIS_H -#define BASIS_H - -#include <gdnative/basis.h> - -#include "Defs.hpp" - -#include "Vector3.hpp" - -namespace godot { - -class Quat; - -class Basis { -private: - static const Basis IDENTITY; - static const Basis FLIP_X; - static const Basis FLIP_Y; - static const Basis FLIP_Z; - - // This helper template is for mimicking the behavior difference between the engine - // and script interfaces that logically script sees matrices as column major, while - // the engine stores them in row major to efficiently take advantage of SIMD - // 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 diff --git a/include/core/CameraMatrix.hpp b/include/core/CameraMatrix.hpp deleted file mode 100644 index 27b6f73..0000000 --- a/include/core/CameraMatrix.hpp +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************/ -/* CameraMatrix.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef CAMERA_MATRIX_H -#define CAMERA_MATRIX_H - -#include "Defs.hpp" -#include "Math.hpp" -#include "Plane.hpp" -#include "Rect2.hpp" -#include "Transform.hpp" - -#include <vector> - -namespace { -using namespace godot; -} // namespace - -struct CameraMatrix { - enum Planes { - PLANE_NEAR, - PLANE_FAR, - PLANE_LEFT, - PLANE_TOP, - PLANE_RIGHT, - PLANE_BOTTOM - }; - - real_t matrix[4][4]; - - void set_identity(); - void set_zero(); - void set_light_bias(); - void set_light_atlas_rect(const Rect2 &p_rect); - void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov = false); - void set_perspective(real_t p_fovy_degrees, real_t p_aspect, real_t p_z_near, real_t p_z_far, bool p_flip_fov, int p_eye, real_t p_intraocular_dist, real_t p_convergence_dist); - void set_for_hmd(int p_eye, real_t p_aspect, real_t p_intraocular_dist, real_t p_display_width, real_t p_display_to_lens, real_t p_oversample, real_t p_z_near, real_t p_z_far); - void set_orthogonal(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_znear, real_t p_zfar); - void set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear, real_t p_zfar, bool p_flip_fov = false); - void set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far); - void set_frustum(real_t p_size, real_t p_aspect, Vector2 p_offset, real_t p_near, real_t p_far, bool p_flip_fov = false); - - static real_t get_fovy(real_t p_fovx, real_t p_aspect) { - return Math::rad2deg(atan(p_aspect * tan(Math::deg2rad(p_fovx) * 0.5)) * 2.0); - } - - static inline double absd(double g) { - union { - double d; - uint64_t i; - } u; - u.d = g; - u.i &= (uint64_t)9223372036854775807ll; - return u.d; - } - - real_t get_z_far() const; - real_t get_z_near() const; - real_t get_aspect() const; - real_t get_fov() const; - bool is_orthogonal() const; - - std::vector<Plane> get_projection_planes(const Transform &p_transform) const; - - bool get_endpoints(const Transform &p_transform, Vector3 *p_8points) const; - Vector2 get_viewport_half_extents() const; - - void invert(); - CameraMatrix inverse() const; - - CameraMatrix operator*(const CameraMatrix &p_matrix) const; - - Plane xform4(const Plane &p_vec4) const; - inline Vector3 xform(const Vector3 &p_vec3) const; - - operator String() const; - - void scale_translate_to_fit(const AABB &p_aabb); - void make_scale(const Vector3 &p_scale); - int get_pixels_per_meter(int p_for_pixel_width) const; - operator Transform() const; - - CameraMatrix(); - CameraMatrix(const Transform &p_transform); - ~CameraMatrix(); -}; - -Vector3 CameraMatrix::xform(const Vector3 &p_vec3) const { - Vector3 ret; - ret.x = matrix[0][0] * p_vec3.x + matrix[1][0] * p_vec3.y + matrix[2][0] * p_vec3.z + matrix[3][0]; - ret.y = matrix[0][1] * p_vec3.x + matrix[1][1] * p_vec3.y + matrix[2][1] * p_vec3.z + matrix[3][1]; - ret.z = matrix[0][2] * p_vec3.x + matrix[1][2] * p_vec3.y + matrix[2][2] * p_vec3.z + matrix[3][2]; - real_t w = matrix[0][3] * p_vec3.x + matrix[1][3] * p_vec3.y + matrix[2][3] * p_vec3.z + matrix[3][3]; - return ret / w; -} - -#endif diff --git a/include/core/Color.hpp b/include/core/Color.hpp deleted file mode 100644 index 36d3254..0000000 --- a/include/core/Color.hpp +++ /dev/null @@ -1,171 +0,0 @@ -/*************************************************************************/ -/* Color.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef COLOR_H -#define COLOR_H - -#include <gdnative/color.h> - -#include <cmath> - -#include "Defs.hpp" -#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]; - } - - Color operator+(const Color &p_color) const; - void operator+=(const Color &p_color); - - Color operator-() const; - Color operator-(const Color &p_color) const; - void operator-=(const Color &p_color); - - Color operator*(const Color &p_color) const; - Color operator*(const real_t &rvalue) const; - void operator*=(const Color &p_color); - void operator*=(const real_t &rvalue); - - Color operator/(const Color &p_color) const; - Color operator/(const real_t &rvalue) const; - void operator/=(const Color &p_color); - void operator/=(const real_t &rvalue); - - 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 diff --git a/include/core/CoreTypes.hpp b/include/core/CoreTypes.hpp deleted file mode 100644 index 95ba2a7..0000000 --- a/include/core/CoreTypes.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************/ -/* CoreTypes.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 diff --git a/include/core/Defs.hpp b/include/core/Defs.hpp deleted file mode 100644 index 369240e..0000000 --- a/include/core/Defs.hpp +++ /dev/null @@ -1,298 +0,0 @@ -/*************************************************************************/ -/* Defs.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 -}; - -} // namespace godot - -#include <GodotGlobal.hpp> - -// alloca() is non-standard. When using MSVC, it's in malloc.h. -#if defined(__linux__) || defined(__APPLE__) -#include <alloca.h> -#else -#include <malloc.h> -#endif - -typedef float real_t; - -// This epsilon should match the one used by Godot for consistency. -// Using `f` when `real_t` is float. -#define CMP_EPSILON 0.00001f -#define CMP_EPSILON2 (CMP_EPSILON * CMP_EPSILON) - -#define Math_PI 3.1415926535897932384626433833 -#define Math_TAU 6.2831853071795864769252867666 - -#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)); \ - GENERATE_TRAP; \ - } \ - } 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 diff --git a/include/core/Dictionary.hpp b/include/core/Dictionary.hpp deleted file mode 100644 index 9f01c52..0000000 --- a/include/core/Dictionary.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************/ -/* Dictionary.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef DICTIONARY_H -#define DICTIONARY_H - -#include "Variant.hpp" - -#include "Array.hpp" - -#include <gdnative/dictionary.h> - -namespace godot { - -class Dictionary { - godot_dictionary _godot_dictionary; - - friend Variant::operator Dictionary() const; - inline explicit Dictionary(const godot_dictionary &other) { - _godot_dictionary = other; - } - -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 diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp deleted file mode 100644 index 265bc71..0000000 --- a/include/core/Godot.hpp +++ /dev/null @@ -1,619 +0,0 @@ -/*************************************************************************/ -/* Godot.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_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 <type_traits> - -namespace godot { -namespace detail { - -// Godot classes are wrapped by heap-allocated instances mimicking them through the C API. -// They all inherit `_Wrapped`. -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); -} - -// Custom class instances are not obtainable by just casting the pointer to the base class they inherit, -// partly because in Godot, scripts are not instances of the classes themselves, they are only attached to them. -// Yet we want to "fake" it as if they were the same entity. -template <class T> -T *get_custom_class_instance(const Object *obj) { - return (obj) ? (T *)godot::nativescript_api->godot_nativescript_get_userdata(obj->_owner) : nullptr; -} - -template <class T> -inline T *create_custom_class_instance() { - // Usually, script instances hold a reference to their NativeScript resource. - // that resource is obtained from a `.gdns` file, which in turn exists because - // of the resource system of Godot. We can't cleanly hardcode that here, - // so the easiest for now (though not really clean) is to create new resource instances, - // individually attached to the script instances. - - // We cannot use wrappers because of https://github.com/godotengine/godot/issues/39181 - // godot::NativeScript *script = godot::NativeScript::_new(); - // script->set_library(get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); - // script->set_class_name(T::___get_class_name()); - - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - // So we use the C API directly. - static godot_class_constructor script_constructor = godot::api->godot_get_class_constructor("NativeScript"); - static godot_method_bind *mb_set_library = godot::api->godot_method_bind_get_method("NativeScript", "set_library"); - static godot_method_bind *mb_set_class_name = godot::api->godot_method_bind_get_method("NativeScript", "set_class_name"); - godot_object *script = script_constructor(); - { - const void *args[] = { godot::gdnlib }; - godot::api->godot_method_bind_ptrcall(mb_set_library, script, args, nullptr); - } - { - const String class_name = T::___get_class_name(); - const void *args[] = { &class_name }; - godot::api->godot_method_bind_ptrcall(mb_set_class_name, script, args, nullptr); - } - - // Now to instanciate T, we initially did this, however in case of Reference it returns a variant with refcount - // already initialized, which woud cause inconsistent behavior compared to other classes (we still have to return a pointer). - //Variant instance_variant = script->new_(); - //T *instance = godot::get_custom_class_instance<T>(instance_variant); - - // So we should do this instead, however while convenient, it uses unnecessary wrapper objects. - // Object *base_obj = T::___new_godot_base(); - // base_obj->set_script(script); - // return get_custom_class_instance<T>(base_obj); - - // Again using the C API to do exactly what we have to do. - static godot_class_constructor base_constructor = godot::api->godot_get_class_constructor(T::___get_godot_class_name()); - static godot_method_bind *mb_set_script = godot::api->godot_method_bind_get_method("Object", "set_script"); - godot_object *base_obj = base_constructor(); - { - const void *args[] = { script }; - godot::api->godot_method_bind_ptrcall(mb_set_script, base_obj, args, nullptr); - } - - return (T *)godot::nativescript_api->godot_nativescript_get_userdata(base_obj); -} - -} // namespace detail - -// Used in the definition of a custom class. -// -// Name: Name of your class, without namespace -// Base: Name of the direct base class, with namespace if necessary -// -// ___get_class_name: Name of the class -// ___get_godot_class_name: Name of the Godot base class this class inherits from (i.e not direct) -// _new: Creates a new instance of the class -// ___get_id: Gets the unique ID of the class. Godot and custom classes are both within that set. -// ___get_base_id: Gets the ID of the direct base class, as returned by ___get_id -// ___get_base_class_name: Name of the direct base class -// ___get_from_variant: Converts a Variant into an Object*. Will be non-null if the class matches. -#define GODOT_CLASS(Name, Base) \ - \ -public: \ - inline static const char *___get_class_name() { return #Name; } \ - enum { ___CLASS_IS_SCRIPT = 1 }; \ - inline static const char *___get_godot_class_name() { \ - return Base::___get_godot_class_name(); \ - } \ - inline static Name *_new() { \ - return godot::detail::create_custom_class_instance<Name>(); \ - } \ - inline static size_t ___get_id() { return typeid(Name).hash_code(); } \ - inline static size_t ___get_base_id() { return Base::___get_id(); } \ - inline static const char *___get_base_class_name() { return Base::___get_class_name(); } \ - inline static godot::Object *___get_from_variant(godot::Variant a) { \ - return (godot::Object *)godot::detail::get_custom_class_instance<Name>( \ - godot::Object::___get_from_variant(a)); \ - } \ - \ -private: - -// Legacy compatibility -#define GODOT_SUBCLASS(Name, Base) GODOT_CLASS(Name, Base) - -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() { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - 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_class_name(), T::___get_base_class_name(), create, destroy); - - godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, - T::___get_class_name(), (const void *)T::___get_id()); - - T::_register_methods(); -} - -template <class T> -void register_tool_class() { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - 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_class_name(), T::___get_base_class_name(), create, destroy); - - godot::nativescript_1_1_api->godot_nativescript_set_type_tag(godot::_RegisterState::nativescript_handle, - T::___get_class_name(), (const void *)T::___get_id()); - - 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)) { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - (void)p; // To avoid "unused parameter" warnings. `p` is required for template matching. - return T::___get_class_name(); -} - -// This second version is also required to match constant functions -template <class T, class R, class... args> -const char *___get_method_class_name(R (T::*p)(args... a) const) { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - (void)p; // To avoid "unused parameter" warnings. `p` is required for template matching. - return T::___get_class_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); -} - -// User can specify a derived class D to register the method for, instead of it being inferred. -template <class D, class B, class R, class... As> -void register_method_explicit(const char *name, R (B::*method_ptr)(As...), - godot_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) { - static_assert(std::is_base_of<B, D>::value, "Explicit class must derive from method class"); - register_method(name, static_cast<R (D::*)(As...)>(method_ptr), rpc_type); -} - -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 = "") { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - 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 = detail::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_class_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 = "") { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - 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_class_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) { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - 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_class_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...)); -} - -template <class T> -void register_signal(String name) { - static_assert(T::___CLASS_IS_SCRIPT, "This function must only be used on custom classes"); - - godot_signal signal = {}; - signal.name = *(godot_string *)&name; - - godot::nativescript_api->godot_nativescript_register_signal(godot::_RegisterState::nativescript_handle, - T::___get_class_name(), &signal); -} - -#ifndef GODOT_CPP_NO_OBJECT_CAST -template <class T> -T *Object::cast_to(const Object *obj) { - if (!obj) - return nullptr; - - if (T::___CLASS_IS_SCRIPT) { - 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(T::___get_id(), have_tag)) { - return detail::get_custom_class_instance<T>(obj); - } - } else { - if (godot::core_1_2_api->godot_object_cast_to(obj->_owner, (void *)T::___get_id())) { - return (T *)obj; - } - } - - return nullptr; -} -#endif - -} // namespace godot - -#endif // GODOT_HPP diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp deleted file mode 100644 index 6312d19..0000000 --- a/include/core/GodotGlobal.hpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************/ -/* GodotGlobal.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_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 diff --git a/include/core/GodotProfiling.hpp b/include/core/GodotProfiling.hpp deleted file mode 100644 index fc34343..0000000 --- a/include/core/GodotProfiling.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************/ -/* GodotProfiling.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef GODOT_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); - } - } -}; - -} // namespace godot - -#ifdef DEBUG_ENABLED -#define GODOT_PROFILING_FUNCTION FunctionProfiling __function_profiling(__FUNCTION__, __LINE__); -#else -#define GODOT_PROFILING_FUNCTION -#endif - -#endif diff --git a/include/core/Math.hpp b/include/core/Math.hpp deleted file mode 100644 index 1f54f98..0000000 --- a/include/core/Math.hpp +++ /dev/null @@ -1,302 +0,0 @@ -/*************************************************************************/
-/* Math.hpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-
-#ifndef GODOT_MATH_H
-#define GODOT_MATH_H
-
-#include "Defs.hpp"
-#include <cmath>
-
-namespace godot {
-namespace Math {
-
-// Functions reproduced as in Godot's source code `math_funcs.h`.
-// Some are overloads to automatically support changing real_t into either double or float in the way Godot does.
-
-inline double fmod(double p_x, double p_y) {
- return ::fmod(p_x, p_y);
-}
-inline float fmod(float p_x, float p_y) {
- return ::fmodf(p_x, p_y);
-}
-
-inline double floor(double p_x) {
- return ::floor(p_x);
-}
-inline float floor(float p_x) {
- return ::floorf(p_x);
-}
-
-inline double exp(double p_x) {
- return ::exp(p_x);
-}
-inline float exp(float p_x) {
- return ::expf(p_x);
-}
-
-inline double sin(double p_x) {
- return ::sin(p_x);
-}
-inline float sin(float p_x) {
- return ::sinf(p_x);
-}
-
-inline double cos(double p_x) {
- return ::cos(p_x);
-}
-inline float cos(float p_x) {
- return ::cosf(p_x);
-}
-
-inline double tan(double p_x) {
- return ::tan(p_x);
-}
-inline float tan(float p_x) {
- return ::tanf(p_x);
-}
-
-inline double asin(double p_x) {
- return ::asin(p_x);
-}
-inline float asin(float p_x) {
- return ::asinf(p_x);
-}
-
-inline double acos(double p_x) {
- return ::acos(p_x);
-}
-inline float acos(float p_x) {
- return ::acosf(p_x);
-}
-
-inline double atan(double p_x) {
- return ::atan(p_x);
-}
-inline float atan(float p_x) {
- return ::atanf(p_x);
-}
-
-inline double atan2(double p_y, double p_x) {
- return ::atan2(p_y, p_x);
-}
-inline float atan2(float p_y, float p_x) {
- return ::atan2f(p_y, p_x);
-}
-
-inline double sqrt(double p_x) {
- return ::sqrt(p_x);
-}
-inline float sqrt(float p_x) {
- return ::sqrtf(p_x);
-}
-
-inline float lerp(float minv, float maxv, float t) {
- return minv + t * (maxv - minv);
-}
-inline double lerp(double minv, double maxv, double t) {
- return minv + t * (maxv - minv);
-}
-
-inline double lerp_angle(double p_from, double p_to, double p_weight) {
- double difference = fmod(p_to - p_from, Math_TAU);
- double distance = fmod(2.0 * difference, Math_TAU) - difference;
- return p_from + distance * p_weight;
-}
-inline float lerp_angle(float p_from, float p_to, float p_weight) {
- float difference = fmod(p_to - p_from, (float)Math_TAU);
- float distance = fmod(2.0f * difference, (float)Math_TAU) - difference;
- return p_from + distance * p_weight;
-}
-
-template <typename T>
-inline T clamp(T x, T minv, T maxv) {
- if (x < minv) {
- return minv;
- }
- if (x > maxv) {
- return maxv;
- }
- return x;
-}
-
-template <typename T>
-inline T min(T a, T b) {
- return a < b ? a : b;
-}
-
-template <typename T>
-inline T max(T a, T b) {
- return a > b ? a : b;
-}
-
-template <typename T>
-inline T sign(T x) {
- return static_cast<T>(x < 0 ? -1 : 1);
-}
-
-inline double deg2rad(double p_y) {
- return p_y * Math_PI / 180.0;
-}
-inline float deg2rad(float p_y) {
- return p_y * static_cast<float>(Math_PI) / 180.f;
-}
-
-inline double rad2deg(double p_y) {
- return p_y * 180.0 / Math_PI;
-}
-inline float rad2deg(float p_y) {
- return p_y * 180.f / static_cast<float>(Math_PI);
-}
-
-inline double inverse_lerp(double p_from, double p_to, double p_value) {
- return (p_value - p_from) / (p_to - p_from);
-}
-inline float inverse_lerp(float p_from, float p_to, float p_value) {
- return (p_value - p_from) / (p_to - p_from);
-}
-
-inline double range_lerp(double p_value, double p_istart, double p_istop, double p_ostart, double p_ostop) {
- return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value));
-}
-inline float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) {
- return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value));
-}
-
-inline bool is_equal_approx(real_t a, real_t b) {
- // Check for exact equality first, required to handle "infinity" values.
- if (a == b) {
- return true;
- }
- // Then check for approximate equality.
- real_t tolerance = CMP_EPSILON * std::abs(a);
- if (tolerance < CMP_EPSILON) {
- tolerance = CMP_EPSILON;
- }
- return std::abs(a - b) < tolerance;
-}
-
-inline bool is_equal_approx(real_t a, real_t b, real_t tolerance) {
- // Check for exact equality first, required to handle "infinity" values.
- if (a == b) {
- return true;
- }
- // Then check for approximate equality.
- return std::abs(a - b) < tolerance;
-}
-
-inline bool is_zero_approx(real_t s) {
- return std::abs(s) < CMP_EPSILON;
-}
-
-inline double smoothstep(double p_from, double p_to, double p_weight) {
- if (is_equal_approx(static_cast<real_t>(p_from), static_cast<real_t>(p_to))) {
- return p_from;
- }
- double x = clamp((p_weight - p_from) / (p_to - p_from), 0.0, 1.0);
- return x * x * (3.0 - 2.0 * x);
-}
-inline float smoothstep(float p_from, float p_to, float p_weight) {
- if (is_equal_approx(p_from, p_to)) {
- return p_from;
- }
- float x = clamp((p_weight - p_from) / (p_to - p_from), 0.0f, 1.0f);
- return x * x * (3.0f - 2.0f * x);
-}
-
-inline double move_toward(double p_from, double p_to, double p_delta) {
- return std::abs(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta;
-}
-
-inline float move_toward(float p_from, float p_to, float p_delta) {
- return std::abs(p_to - p_from) <= p_delta ? p_to : p_from + sign(p_to - p_from) * p_delta;
-}
-
-inline double linear2db(double p_linear) {
- return log(p_linear) * 8.6858896380650365530225783783321;
-}
-inline float linear2db(float p_linear) {
- return log(p_linear) * 8.6858896380650365530225783783321f;
-}
-
-inline double db2linear(double p_db) {
- return exp(p_db * 0.11512925464970228420089957273422);
-}
-inline float db2linear(float p_db) {
- return exp(p_db * 0.11512925464970228420089957273422f);
-}
-
-inline double round(double p_val) {
- return (p_val >= 0) ? floor(p_val + 0.5) : -floor(-p_val + 0.5);
-}
-inline float round(float p_val) {
- return (p_val >= 0) ? floor(p_val + 0.5f) : -floor(-p_val + 0.5f);
-}
-
-inline int64_t wrapi(int64_t value, int64_t min, int64_t max) {
- int64_t range = max - min;
- return range == 0 ? min : min + ((((value - min) % range) + range) % range);
-}
-
-inline float wrapf(real_t value, real_t min, real_t max) {
- const real_t range = max - min;
- return is_zero_approx(range) ? min : value - (range * floor((value - min) / range));
-}
-
-inline float stepify(float p_value, float p_step) {
- if (p_step != 0) {
- p_value = floor(p_value / p_step + 0.5f) * p_step;
- }
- return p_value;
-}
-inline double stepify(double p_value, double p_step) {
- if (p_step != 0) {
- p_value = floor(p_value / p_step + 0.5) * p_step;
- }
- return p_value;
-}
-
-inline unsigned int next_power_of_2(unsigned int x) {
- if (x == 0)
- return 0;
-
- --x;
- x |= x >> 1;
- x |= x >> 2;
- x |= x >> 4;
- x |= x >> 8;
- x |= x >> 16;
-
- return ++x;
-}
-
-} // namespace Math
-} // namespace godot
-
-#endif // GODOT_MATH_H
diff --git a/include/core/NodePath.hpp b/include/core/NodePath.hpp deleted file mode 100644 index f76537b..0000000 --- a/include/core/NodePath.hpp +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************/ -/* NodePath.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef NODEPATH_H -#define NODEPATH_H - -#include "String.hpp" - -#include <gdnative/node_path.h> - -namespace godot { - -class NodePath { - godot_node_path _node_path; - - friend class Variant; - inline explicit NodePath(godot_node_path node_path) { - _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 diff --git a/include/core/Plane.hpp b/include/core/Plane.hpp deleted file mode 100644 index be01591..0000000 --- a/include/core/Plane.hpp +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************/ -/* Plane.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 diff --git a/include/core/PoolArrays.hpp b/include/core/PoolArrays.hpp deleted file mode 100644 index 233b146..0000000 --- a/include/core/PoolArrays.hpp +++ /dev/null @@ -1,766 +0,0 @@ -/*************************************************************************/ -/* PoolArrays.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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; - - friend class String; - friend class Variant; - inline explicit PoolByteArray(godot_pool_byte_array a) { - _godot_array = a; - } - -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; - - friend class Variant; - explicit inline PoolIntArray(godot_pool_int_array a) { - _godot_array = a; - } - -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; - - friend class Variant; - explicit inline PoolRealArray(godot_pool_real_array a) { - _godot_array = a; - } - -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; - - friend class String; - friend class Variant; - explicit inline PoolStringArray(godot_pool_string_array a) { - _godot_array = a; - } - -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; - - friend class Variant; - explicit inline PoolVector2Array(godot_pool_vector2_array a) { - _godot_array = a; - } - -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; - - friend class Variant; - explicit inline PoolVector3Array(godot_pool_vector3_array a) { - _godot_array = a; - } - -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; - - friend class Variant; - explicit inline PoolColorArray(godot_pool_color_array a) { - _godot_array = a; - } - -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 diff --git a/include/core/Quat.hpp b/include/core/Quat.hpp deleted file mode 100644 index fba5ec6..0000000 --- a/include/core/Quat.hpp +++ /dev/null @@ -1,125 +0,0 @@ -/*************************************************************************/ -/* Quat.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef QUAT_H -#define QUAT_H - -#include <cmath> - -#include "Vector3.hpp" - -// #include "Basis.h" - -namespace godot { - -class Quat { -public: - static const Quat IDENTITY; - - 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 diff --git a/include/core/RID.hpp b/include/core/RID.hpp deleted file mode 100644 index e36e1c3..0000000 --- a/include/core/RID.hpp +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************/ -/* RID.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef RID_H -#define RID_H - -#include <gdnative/rid.h> - -namespace godot { - -class Object; - -class RID { - godot_rid _godot_rid; - -public: - RID(); - - RID(Object *p); - - godot_rid _get_godot_rid() const; - - int32_t get_id() 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 diff --git a/include/core/Rect2.hpp b/include/core/Rect2.hpp deleted file mode 100644 index 9cd7d10..0000000 --- a/include/core/Rect2.hpp +++ /dev/null @@ -1,160 +0,0 @@ -/*************************************************************************/ -/* Rect2.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 diff --git a/include/core/Ref.hpp b/include/core/Ref.hpp deleted file mode 100644 index 77a0aa4..0000000 --- a/include/core/Ref.hpp +++ /dev/null @@ -1,216 +0,0 @@ -/*************************************************************************/ -/* Ref.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 { - // TODO For this nice check to work, each class must actually #include Reference classes mentionned in its methods, - // which might be annoying for coders who prefer to forward-declare to reduce compile times - // static_assert(std::is_base_of<Reference, T>::value, - // "Ref<T> can only be used with classes deriving from Reference"); - - T *reference = nullptr; - - 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 == nullptr); - - 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) { - Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr())); - if (refb == nullptr) { - unref(); - return; - } - Ref r; - r.reference = Object::cast_to<T>(refb); - ref(r); - r.reference = nullptr; - } - - void operator=(const Variant &p_variant) { - Object *refb = T::___get_from_variant(p_variant); - if (refb == nullptr) { - unref(); - return; - } - Ref r; - r.reference = Object::cast_to<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; - Reference *refb = const_cast<Reference *>(static_cast<const Reference *>(p_from.ptr())); - if (refb == nullptr) { - unref(); - return; - } - Ref r; - r.reference = Object::cast_to<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; - Object *refb = T::___get_from_variant(p_variant); - if (refb == nullptr) { - unref(); - return; - } - Ref r; - r.reference = Object::cast_to<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 diff --git a/include/core/String.hpp b/include/core/String.hpp deleted file mode 100644 index 91400c7..0000000 --- a/include/core/String.hpp +++ /dev/null @@ -1,184 +0,0 @@ -/*************************************************************************/ -/* String.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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; - - friend class Dictionary; - friend class NodePath; - friend class Variant; - explicit inline String(godot_string contents) : - _godot_string(contents) {} - -public: - String(); - String(const char *contents); - String(const wchar_t *contents); - String(const wchar_t c); - String(const String &other); - String(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); - void operator=(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(const 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(const 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 diff --git a/include/core/TagDB.hpp b/include/core/TagDB.hpp deleted file mode 100644 index 71f5e5c..0000000 --- a/include/core/TagDB.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************/ -/* TagDB.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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 diff --git a/include/core/Transform.hpp b/include/core/Transform.hpp deleted file mode 100644 index 9dea7f2..0000000 --- a/include/core/Transform.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/*************************************************************************/ -/* Transform.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TRANSFORM_H -#define TRANSFORM_H - -#include "Basis.hpp" - -#include "AABB.hpp" -#include "Plane.hpp" - -namespace godot { - -class Transform { -public: - static const Transform IDENTITY; - static const Transform FLIP_X; - static const Transform FLIP_Y; - static const Transform FLIP_Z; - - Basis basis; - Vector3 origin; - - 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 diff --git a/include/core/Transform2D.hpp b/include/core/Transform2D.hpp deleted file mode 100644 index 659ac1a..0000000 --- a/include/core/Transform2D.hpp +++ /dev/null @@ -1,136 +0,0 @@ -/*************************************************************************/ -/* Transform2D.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef TRANSFORM2D_H -#define TRANSFORM2D_H - -#include "Vector2.hpp" - -namespace godot { - -typedef Vector2 Size2; - -struct Rect2; - -struct Transform2D { - static const Transform2D IDENTITY; - static const Transform2D FLIP_X; - static const Transform2D FLIP_Y; - - // Warning #1: basis of Transform2D is stored differently from Basis. In terms of elements array, the basis matrix looks like "on paper": - // M = (elements[0][0] elements[1][0]) - // (elements[0][1] elements[1][1]) - // 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 diff --git a/include/core/Variant.hpp b/include/core/Variant.hpp deleted file mode 100644 index 7f388d3..0000000 --- a/include/core/Variant.hpp +++ /dev/null @@ -1,304 +0,0 @@ -/*************************************************************************/ -/* Variant.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef 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" - -namespace godot { - -class Dictionary; - -class Array; - -class Variant { - godot_variant _godot_variant; - - friend class Array; - inline explicit Variant(godot_variant v) { - _godot_variant = v; - } - -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 diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp deleted file mode 100644 index a3a8897..0000000 --- a/include/core/Vector2.hpp +++ /dev/null @@ -1,306 +0,0 @@ -/*************************************************************************/ -/* Vector2.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef VECTOR2_H -#define VECTOR2_H - -#include <gdnative/vector2.h> - -#include "Defs.hpp" - -#include <Math.hpp> - -namespace godot { - -class String; - -struct Vector2 { - enum Axis { - AXIS_X = 0, - AXIS_Y, - AXIS_COUNT - }; - - static const Vector2 ZERO; - static const Vector2 ONE; - static const Vector2 INF; - - // Coordinate system of the 2D engine - static const Vector2 LEFT; - static const Vector2 RIGHT; - static const Vector2 UP; - static const Vector2 DOWN; - - union { - real_t x; - 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 Vector2 direction_to(const Vector2 &p_b) const { - Vector2 ret(p_b.x - x, p_b.y - y); - ret.normalize(); - return ret; - } - - 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; - - Vector2 move_toward(const Vector2 &p_to, const real_t p_delta) const { - Vector2 v = *this; - Vector2 vd = p_to - v; - real_t len = vd.length(); - return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta; - } - - 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_normal) const { - return -(*this - p_normal * this->dot(p_normal) * 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(Math::floor(x), Math::floor(y)); - } - - inline Vector2 snapped(const Vector2 &p_by) const { - return Vector2( - Math::stepify(x, p_by.x), - Math::stepify(y, p_by.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 Math { - -// Convenience, since they exist in GDScript - -inline Vector2 cartesian2polar(Vector2 v) { - return Vector2(Math::sqrt(v.x * v.x + v.y * v.y), Math::atan2(v.y, v.x)); -} - -inline Vector2 polar2cartesian(Vector2 v) { - // x == radius - // y == angle - return Vector2(v.x * Math::cos(v.y), v.x * Math::sin(v.y)); -} - -} // namespace Math - -} // namespace godot - -#endif // VECTOR2_H diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp deleted file mode 100644 index aa28c61..0000000 --- a/include/core/Vector3.hpp +++ /dev/null @@ -1,342 +0,0 @@ -/*************************************************************************/ -/* Vector3.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef VECTOR3_H -#define VECTOR3_H - -#include <gdnative/vector3.h> - -#include "Defs.hpp" - -#include "String.hpp" - -#include <Math.hpp> - -namespace godot { - -class Basis; - -struct Vector3 { - enum Axis { - AXIS_X, - AXIS_Y, - AXIS_Z, - AXIS_COUNT - }; - - static const Vector3 ZERO; - static const Vector3 ONE; - static const Vector3 INF; - - // Coordinate system of the 3D engine - static const Vector3 LEFT; - static const Vector3 RIGHT; - static const Vector3 UP; - static const Vector3 DOWN; - static const Vector3 FORWARD; - static const Vector3 BACK; - - union { - struct { - real_t x; - 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))); - } - - inline Vector3 slerp(const Vector3 &p_b, real_t p_t) const { - real_t theta = angle_to(p_b); - return rotated(cross(p_b).normalized(), theta * p_t); - } - - Vector3 cubic_interpolate(const Vector3 &b, const Vector3 &pre_a, const Vector3 &post_b, const real_t t) const; - - Vector3 move_toward(const Vector3 &p_to, const real_t p_delta) const { - Vector3 v = *this; - Vector3 vd = p_to - v; - real_t len = vd.length(); - return len <= p_delta || len < CMP_EPSILON ? p_to : v + vd / len * p_delta; - } - - 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 Vector3 project(const Vector3 &p_b) const { - return p_b * (dot(p_b) / p_b.length_squared()); - } - - inline real_t angle_to(const Vector3 &b) const { - return std::atan2(cross(b).length(), dot(b)); - } - - inline Vector3 direction_to(const Vector3 &p_b) const { - Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z); - ret.normalize(); - return ret; - } - - 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 &p_normal) const { - return -(*this - p_normal * this->dot(p_normal) * 2.0); - } - - 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 *this - by * 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 diff --git a/include/core/Wrapped.hpp b/include/core/Wrapped.hpp deleted file mode 100644 index 26f2f0c..0000000 --- a/include/core/Wrapped.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************/ -/* Wrapped.hpp */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/*************************************************************************/ - -#ifndef WRAPPED_HPP -#define WRAPPED_HPP - -#include <gdnative/gdnative.h> - -namespace godot { - -// This is an internal base class used by the bindings. You should not need to access its members. -class _Wrapped { -public: - godot_object *_owner; - size_t _type_tag; -}; - -} // namespace godot - -#endif // WRAPPED_HPP |
