summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/Array.cpp29
-rw-r--r--src/core/Basis.cpp9
-rw-r--r--src/core/Color.cpp144
-rw-r--r--src/core/GodotGlobal.cpp12
-rw-r--r--src/core/NodePath.cpp9
-rw-r--r--src/core/Quat.cpp19
-rw-r--r--src/core/String.cpp30
7 files changed, 252 insertions, 0 deletions
diff --git a/src/core/Array.cpp b/src/core/Array.cpp
index 9737275..676eba5 100644
--- a/src/core/Array.cpp
+++ b/src/core/Array.cpp
@@ -158,6 +158,35 @@ void Array::sort_custom(Object *obj, const String &func) {
godot::api->godot_array_sort_custom(&_godot_array, (godot_object *)obj, (godot_string *)&func);
}
+int Array::bsearch(const Variant &value, const bool before) {
+ return godot::api->godot_array_bsearch(&_godot_array, (godot_variant *)&value, before);
+}
+
+int Array::bsearch_custom(const Variant &value, const Object *obj,
+ const String &func, const bool before) {
+ return godot::api->godot_array_bsearch_custom(&_godot_array, (godot_variant *)&value,
+ (godot_object *)obj, (godot_string *)&func, before);
+}
+
+Array Array::duplicate(const bool deep) const {
+ godot_array arr = godot::core_1_1_api->godot_array_duplicate(&_godot_array, deep);
+ return *(Array *)&arr;
+}
+
+Variant Array::max() const {
+ godot_variant v = godot::core_1_1_api->godot_array_max(&_godot_array);
+ return *(Variant *)&v;
+}
+
+Variant Array::min() const {
+ godot_variant v = godot::core_1_1_api->godot_array_min(&_godot_array);
+ return *(Variant *)&v;
+}
+
+void Array::shuffle() {
+ godot::core_1_1_api->godot_array_shuffle(&_godot_array);
+}
+
Array::~Array() {
godot::api->godot_array_destroy(&_godot_array);
}
diff --git a/src/core/Basis.cpp b/src/core/Basis.cpp
index 73d9cd5..f5bf90f 100644
--- a/src/core/Basis.cpp
+++ b/src/core/Basis.cpp
@@ -158,6 +158,15 @@ Vector3 Basis::get_scale() const {
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
}
+// TODO: implement this directly without using quaternions to make it more efficient
+Basis Basis::slerp(Basis b, float t) const {
+ ERR_FAIL_COND_V(!is_rotation(), Basis());
+ ERR_FAIL_COND_V(!b.is_rotation(), Basis());
+ Quat from(*this);
+ Quat to(b);
+ return Basis(from.slerp(to, t));
+}
+
// get_euler_xyz returns a vector containing the Euler angles in the format
// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last
// (following the convention they are commonly defined in the literature).
diff --git a/src/core/Color.cpp b/src/core/Color.cpp
index a8e6651..f6a061a 100644
--- a/src/core/Color.cpp
+++ b/src/core/Color.cpp
@@ -67,10 +67,86 @@ uint32_t Color::to_ARGB32() const {
return c;
}
+uint32_t Color::to_ABGR32() const {
+ uint32_t c = (uint8_t)(a * 255);
+ c <<= 8;
+ c |= (uint8_t)(b * 255);
+ c <<= 8;
+ c |= (uint8_t)(g * 255);
+ c <<= 8;
+ c |= (uint8_t)(r * 255);
+
+ return c;
+}
+
+uint64_t Color::to_ABGR64() const {
+ uint64_t c = (uint16_t)(a * 65535);
+ c <<= 16;
+ c |= (uint16_t)(b * 65535);
+ c <<= 16;
+ c |= (uint16_t)(g * 65535);
+ c <<= 16;
+ c |= (uint16_t)(r * 65535);
+
+ return c;
+}
+
+uint64_t Color::to_ARGB64() const {
+ uint64_t c = (uint16_t)(a * 65535);
+ c <<= 16;
+ c |= (uint16_t)(r * 65535);
+ c <<= 16;
+ c |= (uint16_t)(g * 65535);
+ c <<= 16;
+ c |= (uint16_t)(b * 65535);
+
+ return c;
+}
+
+uint32_t Color::to_RGBA32() const {
+ uint32_t c = (uint8_t)(r * 255);
+ c <<= 8;
+ c |= (uint8_t)(g * 255);
+ c <<= 8;
+ c |= (uint8_t)(b * 255);
+ c <<= 8;
+ c |= (uint8_t)(a * 255);
+
+ return c;
+}
+
+uint64_t Color::to_RGBA64() const {
+ uint64_t c = (uint16_t)(r * 65535);
+ c <<= 16;
+ c |= (uint16_t)(g * 65535);
+ c <<= 16;
+ c |= (uint16_t)(b * 65535);
+ c <<= 16;
+ c |= (uint16_t)(a * 65535);
+
+ return c;
+}
+
float Color::gray() const {
return (r + g + b) / 3.0;
}
+uint8_t Color::get_r8() const {
+ return (uint8_t)(r * 255.0);
+}
+
+uint8_t Color::get_g8() const {
+ return (uint8_t)(g * 255.0);
+}
+
+uint8_t Color::get_b8() const {
+ return (uint8_t)(b * 255.0);
+}
+
+uint8_t Color::get_a8() const {
+ return (uint8_t)(a * 255.0);
+}
+
float Color::get_h() const {
float min = MIN(r, g);
@@ -167,6 +243,74 @@ void Color::set_hsv(float p_h, float p_s, float p_v, float p_alpha) {
}
}
+Color Color::darkened(const float p_amount) const {
+ Color res = *this;
+ res.r = res.r * (1.0f - p_amount);
+ res.g = res.g * (1.0f - p_amount);
+ res.b = res.b * (1.0f - p_amount);
+ return res;
+}
+
+Color Color::lightened(const float p_amount) const {
+ Color res = *this;
+ res.r = res.r + (1.0f - res.r) * p_amount;
+ res.g = res.g + (1.0f - res.g) * p_amount;
+ res.b = res.b + (1.0f - res.b) * p_amount;
+ return res;
+}
+
+Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
+ p_h = ::fmod(p_h * 360.0f, 360.0f);
+ if (p_h < 0.0)
+ p_h += 360.0f;
+
+ const float h_ = p_h / 60.0f;
+ const float c = p_v * p_s;
+ const float x = c * (1.0f - ::fabs(::fmod(h_, 2.0f) - 1.0f));
+ float r, g, b;
+
+ switch ((int)h_) {
+ case 0: {
+ r = c;
+ g = x;
+ b = 0;
+ } break;
+ case 1: {
+ r = x;
+ g = c;
+ b = 0;
+ } break;
+ case 2: {
+ r = 0;
+ g = c;
+ b = x;
+ } break;
+ case 3: {
+ r = 0;
+ g = x;
+ b = c;
+ } break;
+ case 4: {
+ r = x;
+ g = 0;
+ b = c;
+ } break;
+ case 5: {
+ r = c;
+ g = 0;
+ b = x;
+ } break;
+ default: {
+ r = 0;
+ g = 0;
+ b = 0;
+ } break;
+ }
+
+ const float m = p_v - c;
+ return Color(m + r, m + g, m + b, p_a);
+}
+
void Color::invert() {
r = 1.0 - r;
g = 1.0 - g;
diff --git a/src/core/GodotGlobal.cpp b/src/core/GodotGlobal.cpp
index ba984a8..3e00f19 100644
--- a/src/core/GodotGlobal.cpp
+++ b/src/core/GodotGlobal.cpp
@@ -24,7 +24,10 @@ namespace godot {
void *_RegisterState::nativescript_handle;
int _RegisterState::language_index;
+
const godot_gdnative_core_api_struct *api = nullptr;
+const godot_gdnative_core_1_1_api_struct *core_1_1_api = nullptr;
+
const godot_gdnative_ext_nativescript_api_struct *nativescript_api = nullptr;
const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api = nullptr;
@@ -72,6 +75,15 @@ void Godot::gdnative_init(godot_gdnative_init_options *options) {
godot::api = options->api_struct;
godot::gdnlib = options->gd_native_library;
+ const godot_gdnative_api_struct *core_extension = godot::api->next;
+
+ while (core_extension) {
+ if (core_extension->version.major == 1 && core_extension->version.minor == 1) {
+ godot::core_1_1_api = (const godot_gdnative_core_1_1_api_struct *)core_extension;
+ }
+ core_extension = core_extension->next;
+ }
+
// now find our extensions
for (int i = 0; i < godot::api->num_extensions; i++) {
switch (godot::api->extensions[i]->type) {
diff --git a/src/core/NodePath.cpp b/src/core/NodePath.cpp
index 021bf35..37ab2a3 100644
--- a/src/core/NodePath.cpp
+++ b/src/core/NodePath.cpp
@@ -52,6 +52,15 @@ bool NodePath::is_empty() const {
return godot::api->godot_node_path_is_empty(&_node_path);
}
+NodePath NodePath::get_as_property_path() const {
+ godot_node_path path = godot::core_1_1_api->godot_node_path_get_as_property_path(&_node_path);
+ return *(NodePath *)&path;
+}
+String NodePath::get_concatenated_subnames() const {
+ godot_string str = godot::api->godot_node_path_get_concatenated_subnames(&_node_path);
+ return *(String *)&str;
+}
+
NodePath::operator String() const {
godot_string str = godot::api->godot_node_path_as_string(&_node_path);
diff --git a/src/core/Quat.cpp b/src/core/Quat.cpp
index abfe056..7837e41 100644
--- a/src/core/Quat.cpp
+++ b/src/core/Quat.cpp
@@ -89,6 +89,10 @@ Quat Quat::normalized() const {
return *this / length();
}
+bool Quat::is_normalized() const {
+ return std::abs(length_squared() - 1.0) < 0.00001;
+}
+
Quat Quat::inverse() const {
return Quat(-x, -y, -z, w);
}
@@ -171,6 +175,21 @@ void Quat::get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const {
r_axis.z = z / ::sqrt(1 - w * w);
}
+void Quat::set_axis_angle(const Vector3 &axis, const float angle) {
+ ERR_FAIL_COND(!axis.is_normalized());
+
+ real_t d = axis.length();
+ if (d == 0)
+ set(0, 0, 0, 0);
+ else {
+ real_t sin_angle = ::sin(angle * 0.5);
+ real_t cos_angle = ::cos(angle * 0.5);
+ real_t s = sin_angle / d;
+ set(axis.x * s, axis.y * s, axis.z * s,
+ cos_angle);
+ }
+}
+
Quat Quat::operator*(const Vector3 &v) const {
return Quat(w * v.x + y * v.z - z * v.y,
w * v.y + z * v.x - x * v.z,
diff --git a/src/core/String.cpp b/src/core/String.cpp
index 3535322..91d9941 100644
--- a/src/core/String.cpp
+++ b/src/core/String.cpp
@@ -555,4 +555,34 @@ signed char String::naturalnocasecmp_to(String p_str) const {
return godot::api->godot_string_naturalnocasecmp_to(&_godot_string, &p_str._godot_string);
}
+String String::dedent() const {
+ String new_string;
+ new_string._godot_string = godot::core_1_1_api->godot_string_dedent(&_godot_string);
+ return new_string;
+}
+
+PoolStringArray String::rsplit(const String &divisor, const bool allow_empty,
+ const int maxsplit) const {
+ godot_pool_string_array arr = godot::core_1_1_api->godot_string_rsplit(&_godot_string, &divisor._godot_string, allow_empty, maxsplit);
+ return *(PoolStringArray *)&arr;
+}
+
+String String::rstrip(const String &chars) const {
+ String new_string;
+ new_string._godot_string = godot::core_1_1_api->godot_string_rstrip(&_godot_string, &chars._godot_string);
+ return new_string;
+}
+
+String String::trim_prefix(const String &prefix) const {
+ String new_string;
+ new_string._godot_string = godot::core_1_1_api->godot_string_trim_prefix(&_godot_string, &prefix._godot_string);
+ return new_string;
+}
+
+String String::trim_suffix(const String &suffix) const {
+ String new_string;
+ new_string._godot_string = godot::core_1_1_api->godot_string_trim_suffix(&_godot_string, &suffix._godot_string);
+ return new_string;
+}
+
} // namespace godot