Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c2ec46f

Browse files
authored
Merge pull request godotengine#296 from lupoDharkael/missing
Add missing class methods
2 parents cdd5026 + b895d3c commit c2ec46f

File tree

14 files changed

+305
-0
lines changed

14 files changed

+305
-0
lines changed

include/core/Array.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,19 @@ class Array {
133133

134134
void sort_custom(Object *obj, const String &func);
135135

136+
int bsearch(const Variant &value, const bool before = true);
137+
138+
int bsearch_custom(const Variant &value, const Object *obj,
139+
const String &func, const bool before = true);
140+
141+
Array duplicate(const bool deep = false) const;
142+
143+
Variant max() const;
144+
145+
Variant min() const;
146+
147+
void shuffle();
148+
136149
~Array();
137150
};
138151

include/core/Basis.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ class Basis {
348348

349349
Vector3 get_scale() const;
350350

351+
Basis slerp(Basis b, float t) const;
352+
351353
Vector3 get_euler_xyz() const;
352354
void set_euler_xyz(const Vector3 &p_euler);
353355
Vector3 get_euler_yxz() const;

include/core/Color.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,26 @@ struct Color {
3232

3333
uint32_t to_ARGB32() const;
3434

35+
uint32_t to_ABGR32() const;
36+
37+
uint64_t to_ABGR64() const;
38+
39+
uint64_t to_ARGB64() const;
40+
41+
uint32_t to_RGBA32() const;
42+
43+
uint64_t to_RGBA64() const;
44+
3545
float gray() const;
3646

47+
uint8_t get_r8() const;
48+
49+
uint8_t get_g8() const;
50+
51+
uint8_t get_b8() const;
52+
53+
uint8_t get_a8() const;
54+
3755
float get_h() const;
3856

3957
float get_s() const;
@@ -42,6 +60,12 @@ struct Color {
4260

4361
void set_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0);
4462

63+
Color darkened(const float amount) const;
64+
65+
Color lightened(const float amount) const;
66+
67+
Color from_hsv(float p_h, float p_s, float p_v, float p_a = 1.0) const;
68+
4569
inline float &operator[](int idx) {
4670
return components[idx];
4771
}

include/core/GodotGlobal.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace godot {
99

1010
extern "C" const godot_gdnative_core_api_struct *api;
11+
extern "C" const godot_gdnative_core_1_1_api_struct *core_1_1_api;
1112
extern "C" const godot_gdnative_ext_nativescript_api_struct *nativescript_api;
1213
extern "C" const godot_gdnative_ext_nativescript_1_1_api_struct *nativescript_1_1_api;
1314

include/core/NodePath.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class NodePath {
3131

3232
bool is_empty() const;
3333

34+
NodePath get_as_property_path() const;
35+
36+
String get_concatenated_subnames() const;
37+
3438
operator String() const;
3539

3640
void operator=(const NodePath &other);

include/core/Quat.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class Quat {
2020

2121
Quat normalized() const;
2222

23+
bool is_normalized() const;
24+
2325
Quat inverse() const;
2426

2527
void set_euler_xyz(const Vector3 &p_euler);
@@ -40,6 +42,8 @@ class Quat {
4042

4143
void get_axis_and_angle(Vector3 &r_axis, real_t &r_angle) const;
4244

45+
void set_axis_angle(const Vector3 &axis, const float angle);
46+
4347
void operator*=(const Quat &q);
4448
Quat operator*(const Quat &q) const;
4549

include/core/String.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class String {
132132
signed char casecmp_to(String p_str) const;
133133
signed char nocasecmp_to(String p_str) const;
134134
signed char naturalnocasecmp_to(String p_str) const;
135+
String dedent() const;
136+
PoolStringArray rsplit(const String &divisor, const bool allow_empty = true, const int maxsplit = 0) const;
137+
String rstrip(const String &chars) const;
138+
String trim_prefix(const String &prefix) const;
139+
String trim_suffix(const String &suffix) const;
135140
};
136141

137142
String operator+(const char *a, const String &b);

src/core/Array.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,35 @@ void Array::sort_custom(Object *obj, const String &func) {
158158
godot::api->godot_array_sort_custom(&_godot_array, (godot_object *)obj, (godot_string *)&func);
159159
}
160160

161+
int Array::bsearch(const Variant &value, const bool before) {
162+
return godot::api->godot_array_bsearch(&_godot_array, (godot_variant *)&value, before);
163+
}
164+
165+
int Array::bsearch_custom(const Variant &value, const Object *obj,
166+
const String &func, const bool before) {
167+
return godot::api->godot_array_bsearch_custom(&_godot_array, (godot_variant *)&value,
168+
(godot_object *)obj, (godot_string *)&func, before);
169+
}
170+
171+
Array Array::duplicate(const bool deep) const {
172+
godot_array arr = godot::core_1_1_api->godot_array_duplicate(&_godot_array, deep);
173+
return *(Array *)&arr;
174+
}
175+
176+
Variant Array::max() const {
177+
godot_variant v = godot::core_1_1_api->godot_array_max(&_godot_array);
178+
return *(Variant *)&v;
179+
}
180+
181+
Variant Array::min() const {
182+
godot_variant v = godot::core_1_1_api->godot_array_min(&_godot_array);
183+
return *(Variant *)&v;
184+
}
185+
186+
void Array::shuffle() {
187+
godot::core_1_1_api->godot_array_shuffle(&_godot_array);
188+
}
189+
161190
Array::~Array() {
162191
godot::api->godot_array_destroy(&_godot_array);
163192
}

src/core/Basis.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,15 @@ Vector3 Basis::get_scale() const {
149149
Vector3(elements[0][2], elements[1][2], elements[2][2]).length());
150150
}
151151

152+
// TODO: implement this directly without using quaternions to make it more efficient
153+
Basis Basis::slerp(Basis b, float t) const {
154+
ERR_FAIL_COND_V(!is_rotation(), Basis());
155+
ERR_FAIL_COND_V(!b.is_rotation(), Basis());
156+
Quat from(*this);
157+
Quat to(b);
158+
return Basis(from.slerp(to, t));
159+
}
160+
152161
// get_euler_xyz returns a vector containing the Euler angles in the format
153162
// (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last
154163
// (following the convention they are commonly defined in the literature).

src/core/Color.cpp

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,86 @@ uint32_t Color::to_ARGB32() const {
6767
return c;
6868
}
6969

70+
uint32_t Color::to_ABGR32() const {
71+
uint32_t c = (uint8_t)(a * 255);
72+
c <<= 8;
73+
c |= (uint8_t)(b * 255);
74+
c <<= 8;
75+
c |= (uint8_t)(g * 255);
76+
c <<= 8;
77+
c |= (uint8_t)(r * 255);
78+
79+
return c;
80+
}
81+
82+
uint64_t Color::to_ABGR64() const {
83+
uint64_t c = (uint16_t)(a * 65535);
84+
c <<= 16;
85+
c |= (uint16_t)(b * 65535);
86+
c <<= 16;
87+
c |= (uint16_t)(g * 65535);
88+
c <<= 16;
89+
c |= (uint16_t)(r * 65535);
90+
91+
return c;
92+
}
93+
94+
uint64_t Color::to_ARGB64() const {
95+
uint64_t c = (uint16_t)(a * 65535);
96+
c <<= 16;
97+
c |= (uint16_t)(r * 65535);
98+
c <<= 16;
99+
c |= (uint16_t)(g * 65535);
100+
c <<= 16;
101+
c |= (uint16_t)(b * 65535);
102+
103+
return c;
104+
}
105+
106+
uint32_t Color::to_RGBA32() const {
107+
uint32_t c = (uint8_t)(r * 255);
108+
c <<= 8;
109+
c |= (uint8_t)(g * 255);
110+
c <<= 8;
111+
c |= (uint8_t)(b * 255);
112+
c <<= 8;
113+
c |= (uint8_t)(a * 255);
114+
115+
return c;
116+
}
117+
118+
uint64_t Color::to_RGBA64() const {
119+
uint64_t c = (uint16_t)(r * 65535);
120+
c <<= 16;
121+
c |= (uint16_t)(g * 65535);
122+
c <<= 16;
123+
c |= (uint16_t)(b * 65535);
124+
c <<= 16;
125+
c |= (uint16_t)(a * 65535);
126+
127+
return c;
128+
}
129+
70130
float Color::gray() const {
71131
return (r + g + b) / 3.0;
72132
}
73133

134+
uint8_t Color::get_r8() const {
135+
return (uint8_t)(r * 255.0);
136+
}
137+
138+
uint8_t Color::get_g8() const {
139+
return (uint8_t)(g * 255.0);
140+
}
141+
142+
uint8_t Color::get_b8() const {
143+
return (uint8_t)(b * 255.0);
144+
}
145+
146+
uint8_t Color::get_a8() const {
147+
return (uint8_t)(a * 255.0);
148+
}
149+
74150
float Color::get_h() const {
75151

76152
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) {
167243
}
168244
}
169245

246+
Color Color::darkened(const float p_amount) const {
247+
Color res = *this;
248+
res.r = res.r * (1.0f - p_amount);
249+
res.g = res.g * (1.0f - p_amount);
250+
res.b = res.b * (1.0f - p_amount);
251+
return res;
252+
}
253+
254+
Color Color::lightened(const float p_amount) const {
255+
Color res = *this;
256+
res.r = res.r + (1.0f - res.r) * p_amount;
257+
res.g = res.g + (1.0f - res.g) * p_amount;
258+
res.b = res.b + (1.0f - res.b) * p_amount;
259+
return res;
260+
}
261+
262+
Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const {
263+
p_h = ::fmod(p_h * 360.0f, 360.0f);
264+
if (p_h < 0.0)
265+
p_h += 360.0f;
266+
267+
const float h_ = p_h / 60.0f;
268+
const float c = p_v * p_s;
269+
const float x = c * (1.0f - ::fabs(::fmod(h_, 2.0f) - 1.0f));
270+
float r, g, b;
271+
272+
switch ((int)h_) {
273+
case 0: {
274+
r = c;
275+
g = x;
276+
b = 0;
277+
} break;
278+
case 1: {
279+
r = x;
280+
g = c;
281+
b = 0;
282+
} break;
283+
case 2: {
284+
r = 0;
285+
g = c;
286+
b = x;
287+
} break;
288+
case 3: {
289+
r = 0;
290+
g = x;
291+
b = c;
292+
} break;
293+
case 4: {
294+
r = x;
295+
g = 0;
296+
b = c;
297+
} break;
298+
case 5: {
299+
r = c;
300+
g = 0;
301+
b = x;
302+
} break;
303+
default: {
304+
r = 0;
305+
g = 0;
306+
b = 0;
307+
} break;
308+
}
309+
310+
const float m = p_v - c;
311+
return Color(m + r, m + g, m + b, p_a);
312+
}
313+
170314
void Color::invert() {
171315
r = 1.0 - r;
172316
g = 1.0 - g;

0 commit comments

Comments
 (0)