diff --git a/include/core/AABB.hpp b/include/core/AABB.hpp index 5d2f921..ce1bee0 100644 --- a/include/core/AABB.hpp +++ b/include/core/AABB.hpp @@ -33,12 +33,12 @@ #include "Vector3.hpp" -#include "Plane.hpp" - #include namespace godot { +class Plane; + class AABB { public: Vector3 position; diff --git a/include/core/Array.hpp b/include/core/Array.hpp index 8af1ded..5bf3f76 100644 --- a/include/core/Array.hpp +++ b/include/core/Array.hpp @@ -33,10 +33,10 @@ #include -#include "String.hpp" - namespace godot { +class String; + namespace helpers { template T append_all(T appendable, ValueT value) { diff --git a/include/core/Basis.hpp b/include/core/Basis.hpp index 0315ca9..b2847ec 100644 --- a/include/core/Basis.hpp +++ b/include/core/Basis.hpp @@ -332,7 +332,7 @@ public: return *this; } - Basis(const Quat &p_quat); // euler + Basis(const Quat &p_quaternion); // euler Basis(const Vector3 &p_euler); // euler Basis(const Vector3 &p_axis, real_t p_phi); diff --git a/include/core/CameraMatrix.hpp b/include/core/CameraMatrix.hpp index 035f53b..3c685bc 100644 --- a/include/core/CameraMatrix.hpp +++ b/include/core/CameraMatrix.hpp @@ -32,7 +32,7 @@ #define CAMERA_MATRIX_H #include "Defs.hpp" -#include "Math.hpp" +#include "Mathp.hpp" #include "Plane.hpp" #include "Rect2.hpp" #include "Transform.hpp" @@ -68,7 +68,7 @@ struct CameraMatrix { 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); + return Mathp::rad2deg(atan(p_aspect * tan(Mathp::deg2rad(p_fovx) * 0.5)) * 2.0); } static inline double absd(double g) { diff --git a/include/core/Dictionary.hpp b/include/core/Dictionary.hpp index 63b1745..c1a3941 100644 --- a/include/core/Dictionary.hpp +++ b/include/core/Dictionary.hpp @@ -31,14 +31,15 @@ #ifndef DICTIONARY_H #define DICTIONARY_H -#include "Variant.hpp" - #include "Array.hpp" +#include "Variant.hpp" #include namespace godot { +class Variant; + class Dictionary { pandemonium_dictionary _pandemonium_dictionary; diff --git a/include/core/Godot.hpp b/include/core/Godot.hpp index c77b5f2..ced7b18 100644 --- a/include/core/Godot.hpp +++ b/include/core/Godot.hpp @@ -336,7 +336,7 @@ __pandemonium_wrapper_method ___get_wrapper_function(R (T::*f)(A...) const) { } template -void register_method(const char *name, M method_ptr, pandemonium_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) { +void register_method(const char *name, M method_ptr, pandemonium_method_rpc_mode rpc_type = PANDEMONIUM_METHOD_RPC_MODE_DISABLED) { pandemonium_instance_method method = {}; method.method_data = ___make_wrapper_function(method_ptr); method.free_func = godot::api->pandemonium_free; @@ -352,7 +352,7 @@ void register_method(const char *name, M method_ptr, pandemonium_method_rpc_mode // User can specify a derived class D to register the method for, instead of it being inferred. template void register_method_explicit(const char *name, R (B::*method_ptr)(As...), - pandemonium_method_rpc_mode rpc_type = GODOT_METHOD_RPC_MODE_DISABLED) { + pandemonium_method_rpc_mode rpc_type = PANDEMONIUM_METHOD_RPC_MODE_DISABLED) { static_assert(std::is_base_of::value, "Explicit class must derive from method class"); register_method(name, static_cast(method_ptr), rpc_type); } @@ -422,7 +422,7 @@ struct _PropertyDefaultGetFunc { template void register_property(const char *name, P(T::*var), P default_value, - pandemonium_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, + pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_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"); @@ -478,7 +478,7 @@ void register_property(const char *name, P(T::*var), P default_value, template void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), P default_value, - pandemonium_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, + pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_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"); @@ -521,7 +521,7 @@ void register_property(const char *name, void (T::*setter)(P), P (T::*getter)(), template void register_property(const char *name, void (T::*setter)(P), P (T::*getter)() const, P default_value, - pandemonium_method_rpc_mode rpc_mode = GODOT_METHOD_RPC_MODE_DISABLED, + pandemonium_method_rpc_mode rpc_mode = PANDEMONIUM_METHOD_RPC_MODE_DISABLED, pandemonium_property_usage_flags usage = GODOT_PROPERTY_USAGE_DEFAULT, pandemonium_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); diff --git a/include/core/GodotGlobal.hpp b/include/core/GodotGlobal.hpp index 9213db8..4bca6cc 100644 --- a/include/core/GodotGlobal.hpp +++ b/include/core/GodotGlobal.hpp @@ -31,12 +31,16 @@ #ifndef GODOT_GLOBAL_HPP #define GODOT_GLOBAL_HPP -#include "Array.hpp" -#include "String.hpp" #include +#include "Array.hpp" +#include "String.hpp" + namespace godot { +class Array; +class String; + extern "C" const pandemonium_gdnative_core_api_struct *api; extern "C" const pandemonium_gdnative_ext_nativescript_api_struct *nativescript_api; diff --git a/include/core/GodotProfiling.hpp b/include/core/GodotProfiling.hpp index 124a830..1b770d2 100644 --- a/include/core/GodotProfiling.hpp +++ b/include/core/GodotProfiling.hpp @@ -31,7 +31,7 @@ #ifndef GODOT_PROFILING_HPP #define GODOT_PROFILING_HPP -#include "OS.hpp" +#include "Defs.hpp" namespace godot { @@ -40,16 +40,8 @@ class FunctionProfiling { 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); - } - } + FunctionProfiling(const char *p_function, const int p_line); + ~FunctionProfiling(); }; } // namespace godot diff --git a/include/core/Math.hpp b/include/core/Mathp.hpp similarity index 94% rename from include/core/Math.hpp rename to include/core/Mathp.hpp index f2468d3..8ebacc3 100644 --- a/include/core/Math.hpp +++ b/include/core/Mathp.hpp @@ -35,7 +35,7 @@ #include namespace godot { -namespace Math { +namespace Mathp { // 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. @@ -183,10 +183,10 @@ inline float inverse_lerp(float p_from, float p_to, float p_value) { } 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)); + return Mathp::lerp(p_ostart, p_ostop, Mathp::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)); + return Mathp::lerp(p_ostart, p_ostop, Mathp::inverse_lerp(p_istart, p_istop, p_value)); } inline bool is_equal_approx(real_t a, real_t b) { diff --git a/include/core/NodePath.hpp b/include/core/NodePath.hpp index db1bab4..e4968fd 100644 --- a/include/core/NodePath.hpp +++ b/include/core/NodePath.hpp @@ -31,12 +31,12 @@ #ifndef NODEPATH_H #define NODEPATH_H -#include "String.hpp" - #include namespace godot { +class String; + class NodePath { pandemonium_node_path _node_path; diff --git a/include/core/Quat.hpp b/include/core/Quat.hpp index e14d5a6..bb9a435 100644 --- a/include/core/Quat.hpp +++ b/include/core/Quat.hpp @@ -93,8 +93,8 @@ public: 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; + bool operator==(const Quat &p_quaternion) const; + bool operator!=(const Quat &p_quaternion) const; operator String() const; diff --git a/include/core/Variant.hpp b/include/core/Variant.hpp index 6c80aec..4808f7f 100644 --- a/include/core/Variant.hpp +++ b/include/core/Variant.hpp @@ -201,9 +201,9 @@ public: Variant(const Plane &p_plane); - Variant(const ::AABB &p_aabb); + Variant(const godot::AABB &p_aabb); - Variant(const Quat &p_quat); + Variant(const Quat &p_quaternion); Variant(const Basis &p_transform); @@ -215,7 +215,7 @@ public: Variant(const NodePath &p_path); - Variant(const ::RID &p_rid); + Variant(const godot::RID &p_rid); Variant(const Object *p_object); @@ -260,7 +260,7 @@ public: operator Rect2() const; operator Vector3() const; operator Plane() const; - operator ::AABB() const; + operator godot::AABB() const; operator Quat() const; operator Basis() const; operator Transform() const; @@ -269,7 +269,7 @@ public: operator Color() const; operator NodePath() const; - operator ::RID() const; + operator godot::RID() const; operator pandemonium_object *() const; template diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 4bcdac1..cfa51eb 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -35,7 +35,7 @@ #include "Defs.hpp" -#include +#include namespace godot { @@ -267,13 +267,13 @@ struct Vector2 { } inline Vector2 floor() const { - return Vector2(Math::floor(x), Math::floor(y)); + return Vector2(Mathp::floor(x), Mathp::floor(y)); } inline Vector2 snapped(const Vector2 &p_by) const { return Vector2( - Math::stepify(x, p_by.x), - Math::stepify(y, p_by.y)); + Mathp::stepify(x, p_by.x), + Mathp::stepify(y, p_by.y)); } inline real_t aspect() const { return width / height; } @@ -290,13 +290,13 @@ 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)); + return Vector2(Mathp::sqrt(v.x * v.x + v.y * v.y), Mathp::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)); + return Vector2(v.x * Mathp::cos(v.y), v.x * Mathp::sin(v.y)); } } // namespace Math diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 27dee73..aaab319 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -35,13 +35,12 @@ #include "Defs.hpp" -#include "String.hpp" - -#include +#include namespace godot { class Basis; +class String; struct Vector3 { enum Axis { diff --git a/src/core/Array.cpp b/src/core/Array.cpp index a5853c1..2f04fde 100644 --- a/src/core/Array.cpp +++ b/src/core/Array.cpp @@ -31,6 +31,7 @@ #include "Array.hpp" #include "GodotGlobal.hpp" #include "Variant.hpp" +#include "String.hpp" #include @@ -125,7 +126,7 @@ Variant Array::back() const { } int Array::find(const Variant &what, const int from) const { - return godot::api->pandemonium_array_find(&_pandemonium_array, (pandemonium_variant *)&what, from); + return godot::api->pandemonium_array_find_from(&_pandemonium_array, (pandemonium_variant *)&what, from); } int Array::find_last(const Variant &what) const { @@ -179,7 +180,7 @@ void Array::resize(const int size) { } int Array::rfind(const Variant &what, const int from) const { - return godot::api->pandemonium_array_rfind(&_pandemonium_array, (pandemonium_variant *)&what, from); + return godot::api->pandemonium_array_rfind_from(&_pandemonium_array, (pandemonium_variant *)&what, from); } void Array::sort() { @@ -201,7 +202,7 @@ int Array::bsearch_custom(const Variant &value, const Object *obj, } Array Array::duplicate(const bool deep) const { - pandemonium_array arr = godot::api->pandemonium_array_duplicate(&_pandemonium_array, deep); + pandemonium_array arr = godot::api->pandemonium_array_duplicate_deep(&_pandemonium_array, deep); return Array(arr); } diff --git a/src/core/Basis.cpp b/src/core/Basis.cpp index 6bae9d9..55bb124 100644 --- a/src/core/Basis.cpp +++ b/src/core/Basis.cpp @@ -640,13 +640,13 @@ Basis::Basis(const Vector3 &p_euler) { namespace godot { -Basis::Basis(const Quat &p_quat) { - real_t d = p_quat.length_squared(); +Basis::Basis(const Quat &p_quaternion) { + real_t d = p_quaternion.length_squared(); real_t s = 2.0 / d; - real_t xs = p_quat.x * s, ys = p_quat.y * s, zs = p_quat.z * s; - real_t wx = p_quat.w * xs, wy = p_quat.w * ys, wz = p_quat.w * zs; - real_t xx = p_quat.x * xs, xy = p_quat.x * ys, xz = p_quat.x * zs; - real_t yy = p_quat.y * ys, yz = p_quat.y * zs, zz = p_quat.z * zs; + real_t xs = p_quaternion.x * s, ys = p_quaternion.y * s, zs = p_quaternion.z * s; + real_t wx = p_quaternion.w * xs, wy = p_quaternion.w * ys, wz = p_quaternion.w * zs; + real_t xx = p_quaternion.x * xs, xy = p_quaternion.x * ys, xz = p_quaternion.x * zs; + real_t yy = p_quaternion.y * ys, yz = p_quaternion.y * zs, zz = p_quaternion.z * zs; set(1.0 - (yy + zz), xy - wz, xz + wy, xy + wz, 1.0 - (xx + zz), yz - wx, xz - wy, yz + wx, 1.0 - (xx + yy)); diff --git a/src/core/CameraMatrix.cpp b/src/core/CameraMatrix.cpp index 29267c3..c3638d2 100644 --- a/src/core/CameraMatrix.cpp +++ b/src/core/CameraMatrix.cpp @@ -561,7 +561,7 @@ real_t CameraMatrix::get_fov() const { right_plane.normalize(); if ((matrix[8] == 0) && (matrix[9] == 0)) { - return Math::rad2deg(acos(std::abs(right_plane.normal.x))) * 2.0; + return Mathp::rad2deg(acos(std::abs(right_plane.normal.x))) * 2.0; } else { // our frustum is asymmetrical need to calculate the left planes angle separately.. Plane left_plane = Plane(matrix[3] + matrix[0], @@ -570,7 +570,7 @@ real_t CameraMatrix::get_fov() const { matrix[15] + matrix[12]); left_plane.normalize(); - return Math::rad2deg(acos(std::abs(left_plane.normal.x))) + Math::rad2deg(acos(std::abs(right_plane.normal.x))); + return Mathp::rad2deg(acos(std::abs(left_plane.normal.x))) + Mathp::rad2deg(acos(std::abs(right_plane.normal.x))); } } diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp index 9eaeccb..4f1ab9c 100644 --- a/src/core/GodotGlobal.cpp +++ b/src/core/GodotGlobal.cpp @@ -31,6 +31,7 @@ #include "GodotGlobal.hpp" #include "String.hpp" +#include "Array.hpp" #include "Wrapped.hpp" diff --git a/src/core/GodotProfiling.cpp b/src/core/GodotProfiling.cpp new file mode 100644 index 0000000..9983838 --- /dev/null +++ b/src/core/GodotProfiling.cpp @@ -0,0 +1,22 @@ + +#include "GodotProfiling.hpp" + +#include "OS.hpp" + +#include + +namespace godot { + +FunctionProfiling::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::~FunctionProfiling() { + uint64_t t = OS::get_singleton()->get_ticks_usec() - ticks; + if (t > 0) { + Godot::gdnative_profiling_add_data(signature, t); + } +} + +} // namespace godot \ No newline at end of file diff --git a/src/core/Plane.cpp b/src/core/Plane.cpp index 8fe51a7..0fee51a 100644 --- a/src/core/Plane.cpp +++ b/src/core/Plane.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "Plane.hpp" -#include "Vector3.hpp" + +#include "Mathp.hpp" #include diff --git a/src/core/Quat.cpp b/src/core/Quat.cpp index a8bb3e1..4ff4b28 100644 --- a/src/core/Quat.cpp +++ b/src/core/Quat.cpp @@ -341,12 +341,12 @@ Quat Quat::operator/(const real_t &s) const { return *this * (1.0 / s); } -bool Quat::operator==(const Quat &p_quat) const { - return x == p_quat.x && y == p_quat.y && z == p_quat.z && w == p_quat.w; +bool Quat::operator==(const Quat &p_quaternion) const { + return x == p_quaternion.x && y == p_quaternion.y && z == p_quaternion.z && w == p_quaternion.w; } -bool Quat::operator!=(const Quat &p_quat) const { - return x != p_quat.x || y != p_quat.y || z != p_quat.z || w != p_quat.w; +bool Quat::operator!=(const Quat &p_quaternion) const { + return x != p_quaternion.x || y != p_quaternion.y || z != p_quaternion.z || w != p_quaternion.w; } } // namespace godot diff --git a/src/core/String.cpp b/src/core/String.cpp index d459bb2..bd1ae56 100644 --- a/src/core/String.cpp +++ b/src/core/String.cpp @@ -92,11 +92,11 @@ String::String(const char *contents) { } String::String(const wchar_t *contents) { - godot::api->pandemonium_string_new_with_wide_string(&_pandemonium_string, contents, wcslen(contents)); + godot::api->pandemonium_string_new_wchar_clip_to_len(&_pandemonium_string, contents, wcslen(contents)); } String::String(const wchar_t c) { - godot::api->pandemonium_string_new_with_wide_string(&_pandemonium_string, &c, 1); + godot::api->pandemonium_string_new_wchar_clip_to_len(&_pandemonium_string, &c, 1); } String::String(const String &other) { diff --git a/src/core/Variant.cpp b/src/core/Variant.cpp index f391e14..cb05c28 100644 --- a/src/core/Variant.cpp +++ b/src/core/Variant.cpp @@ -116,12 +116,12 @@ Variant::Variant(const Plane &p_plane) { godot::api->pandemonium_variant_new_plane(&_pandemonium_variant, (pandemonium_plane *)&p_plane); } -Variant::Variant(const ::AABB &p_aabb) { +Variant::Variant(const godot::AABB &p_aabb) { godot::api->pandemonium_variant_new_aabb(&_pandemonium_variant, (pandemonium_aabb *)&p_aabb); } -Variant::Variant(const Quat &p_quat) { - godot::api->pandemonium_variant_new_quat(&_pandemonium_variant, (pandemonium_quat *)&p_quat); +Variant::Variant(const Quat &p_quaternion) { + godot::api->pandemonium_variant_new_quaternion(&_pandemonium_variant, (pandemonium_quaternion *)&p_quaternion); } Variant::Variant(const Basis &p_transform) { @@ -144,7 +144,7 @@ Variant::Variant(const NodePath &p_path) { godot::api->pandemonium_variant_new_node_path(&_pandemonium_variant, (pandemonium_node_path *)&p_path); } -Variant::Variant(const ::RID &p_rid) { +Variant::Variant(const godot::RID &p_rid) { godot::api->pandemonium_variant_new_rid(&_pandemonium_variant, (pandemonium_rid *)&p_rid); } @@ -261,12 +261,12 @@ Variant::operator Plane() const { pandemonium_plane s = godot::api->pandemonium_variant_as_plane(&_pandemonium_variant); return *(Plane *)&s; } -Variant::operator ::AABB() const { +Variant::operator godot::AABB() const { pandemonium_aabb s = godot::api->pandemonium_variant_as_aabb(&_pandemonium_variant); - return *(::AABB *)&s; + return *(godot::AABB *)&s; } Variant::operator Quat() const { - pandemonium_quat s = godot::api->pandemonium_variant_as_quat(&_pandemonium_variant); + pandemonium_quaternion s = godot::api->pandemonium_variant_as_quaternion(&_pandemonium_variant); return *(Quat *)&s; } Variant::operator Basis() const { @@ -290,9 +290,9 @@ Variant::operator NodePath() const { pandemonium_node_path ret = godot::api->pandemonium_variant_as_node_path(&_pandemonium_variant); return NodePath(ret); } -Variant::operator ::RID() const { +Variant::operator godot::RID() const { pandemonium_rid s = godot::api->pandemonium_variant_as_rid(&_pandemonium_variant); - return *(::RID *)&s; + return *(godot::RID *)&s; } Variant::operator Dictionary() const { diff --git a/src/core/Vector3.cpp b/src/core/Vector3.cpp index 4bf37c3..a3cf809 100644 --- a/src/core/Vector3.cpp +++ b/src/core/Vector3.cpp @@ -109,9 +109,9 @@ void Vector3::rotate(const Vector3 &p_axis, real_t p_phi) { } void Vector3::snap(real_t p_val) { - x = Math::stepify(x, p_val); - y = Math::stepify(y, p_val); - z = Math::stepify(z, p_val); + x = Mathp::stepify(x, p_val); + y = Mathp::stepify(y, p_val); + z = Mathp::stepify(z, p_val); } Vector3::operator String() const {