Skip to content

Commit 51c752c

Browse files
authored
Merge pull request #1372 from dsnopek/4.2-cherrypicks-1
Cherry-picks for the godot-cpp 4.2 branch - 1st batch
2 parents 78ffea5 + 45dc04f commit 51c752c

File tree

12 files changed

+99
-62
lines changed

12 files changed

+99
-62
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ first-party `godot-cpp` extension.
5858
Some compatibility breakage is to be expected as GDExtension and `godot-cpp`
5959
get more used, documented, and critical issues get resolved. See the
6060
[Godot issue tracker](https://github.com/godotengine/godot/issues?q=is%3Aissue+is%3Aopen+label%3Atopic%3Agdextension)
61-
and the [godot-cpp issue tracker](https://github.com/godotengine/godot/issues)
61+
and the [godot-cpp issue tracker](https://github.com/godotengine/godot-cpp/issues)
6262
for a list of known issues, and be sure to provide feedback on issues and PRs
6363
which affect your use of this extension.
6464

@@ -74,7 +74,10 @@ so formatting is done before your changes are submitted.
7474

7575
## Getting started
7676

77-
It's a bit similar to what it was for 3.x but also a bit different.
77+
You need the same C++ pre-requisites installed that are required for the `godot` repository. Follow the [official build instructions for your target platform](https://docs.godotengine.org/en/latest/contributing/development/compiling/index.html#building-for-target-platforms).
78+
79+
Getting started with GDExtensions is a bit similar to what it was for 3.x but also a bit different.
80+
7881
This new approach is much more akin to how core Godot modules are structured.
7982

8083
Compiling this repository generates a static library to be linked with your shared lib,

binding_generator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,9 +1778,9 @@ def generate_global_constant_binds(api, output_dir):
17781778
continue
17791779

17801780
if enum_def["is_bitfield"]:
1781-
header.append(f'VARIANT_BITFIELD_CAST(godot::{enum_def["name"]});')
1781+
header.append(f'VARIANT_BITFIELD_CAST({enum_def["name"]});')
17821782
else:
1783-
header.append(f'VARIANT_ENUM_CAST(godot::{enum_def["name"]});')
1783+
header.append(f'VARIANT_ENUM_CAST({enum_def["name"]});')
17841784

17851785
# Variant::Type is not a global enum, but only one line, it is worth to place in this file instead of creating new file.
17861786
header.append(f"VARIANT_ENUM_CAST(godot::Variant::Type);")
@@ -2433,6 +2433,7 @@ def get_operator_id_name(op):
24332433
"unary-": "negate",
24342434
"unary+": "positive",
24352435
"%": "module",
2436+
"**": "power",
24362437
"<<": "shift_left",
24372438
">>": "shift_right",
24382439
"&": "bit_and",

include/godot_cpp/classes/wrapped.hpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef void GodotObject;
4848
// Base for all engine classes, to contain the pointer to the engine instance.
4949
class Wrapped {
5050
friend class GDExtensionBinding;
51+
friend class ClassDB;
5152
friend void postinitialize_handler(Wrapped *);
5253

5354
protected:
@@ -131,17 +132,6 @@ struct EngineClassRegistration {
131132

132133
} // namespace godot
133134

134-
#ifdef HOT_RELOAD_ENABLED
135-
#define _GDCLASS_RECREATE(m_class, m_inherits) \
136-
m_class *new_instance = (m_class *)memalloc(sizeof(m_class)); \
137-
Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance }; \
138-
Wrapped::recreate_instance = &recreate_data; \
139-
memnew_placement(new_instance, m_class); \
140-
return new_instance;
141-
#else
142-
#define _GDCLASS_RECREATE(m_class, m_inherits) return nullptr;
143-
#endif
144-
145135
// Use this on top of your own classes.
146136
// Note: the trail of `***` is to keep sane diffs in PRs, because clang-format otherwise moves every `\` which makes
147137
// every line of the macro different
@@ -226,15 +216,6 @@ public:
226216
return m_inherits::get_class_static(); \
227217
} \
228218
\
229-
static GDExtensionObjectPtr create(void *data) { \
230-
m_class *new_object = memnew(m_class); \
231-
return new_object->_owner; \
232-
} \
233-
\
234-
static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \
235-
_GDCLASS_RECREATE(m_class, m_inherits); \
236-
} \
237-
\
238219
static void notification_bind(GDExtensionClassInstancePtr p_instance, int32_t p_what, GDExtensionBool p_reversed) { \
239220
if (p_instance && m_class::_get_notification()) { \
240221
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
@@ -437,14 +418,6 @@ public:
437418
return m_inherits::get_class_static(); \
438419
} \
439420
\
440-
static GDExtensionObjectPtr create(void *data) { \
441-
return nullptr; \
442-
} \
443-
\
444-
static GDExtensionClassInstancePtr recreate(void *data, GDExtensionObjectPtr obj) { \
445-
return nullptr; \
446-
} \
447-
\
448421
static void free(void *data, GDExtensionClassInstancePtr ptr) { \
449422
} \
450423
\

include/godot_cpp/core/binder_common.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -281,13 +281,13 @@ void call_with_variant_args(T *p_instance, void (T::*p_method)(P...), const Vari
281281
#ifdef DEBUG_ENABLED
282282
if ((size_t)p_argcount > sizeof...(P)) {
283283
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
284-
r_error.argument = (int32_t)sizeof...(P);
284+
r_error.expected = (int32_t)sizeof...(P);
285285
return;
286286
}
287287

288288
if ((size_t)p_argcount < sizeof...(P)) {
289289
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
290-
r_error.argument = (int32_t)sizeof...(P);
290+
r_error.expected = (int32_t)sizeof...(P);
291291
return;
292292
}
293293
#endif
@@ -299,13 +299,13 @@ void call_with_variant_args_ret(T *p_instance, R (T::*p_method)(P...), const Var
299299
#ifdef DEBUG_ENABLED
300300
if ((size_t)p_argcount > sizeof...(P)) {
301301
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
302-
r_error.argument = (int32_t)sizeof...(P);
302+
r_error.expected = (int32_t)sizeof...(P);
303303
return;
304304
}
305305

306306
if ((size_t)p_argcount < sizeof...(P)) {
307307
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
308-
r_error.argument = (int32_t)sizeof...(P);
308+
r_error.expected = (int32_t)sizeof...(P);
309309
return;
310310
}
311311
#endif
@@ -317,13 +317,13 @@ void call_with_variant_args_retc(T *p_instance, R (T::*p_method)(P...) const, co
317317
#ifdef DEBUG_ENABLED
318318
if ((size_t)p_argcount > sizeof...(P)) {
319319
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
320-
r_error.argument = (int32_t)sizeof...(P);
320+
r_error.expected = (int32_t)sizeof...(P);
321321
return;
322322
}
323323

324324
if ((size_t)p_argcount < sizeof...(P)) {
325325
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
326-
r_error.argument = (int32_t)sizeof...(P);
326+
r_error.expected = (int32_t)sizeof...(P);
327327
return;
328328
}
329329
#endif
@@ -335,7 +335,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const G
335335
#ifdef DEBUG_ENABLED
336336
if ((size_t)p_argcount > sizeof...(P)) {
337337
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
338-
r_error.argument = (int32_t)sizeof...(P);
338+
r_error.expected = (int32_t)sizeof...(P);
339339
return;
340340
}
341341
#endif
@@ -346,7 +346,7 @@ void call_with_variant_args_dv(T *p_instance, void (T::*p_method)(P...), const G
346346
#ifdef DEBUG_ENABLED
347347
if (missing > dvs) {
348348
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
349-
r_error.argument = (int32_t)sizeof...(P);
349+
r_error.expected = (int32_t)sizeof...(P);
350350
return;
351351
}
352352
#endif
@@ -370,7 +370,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const,
370370
#ifdef DEBUG_ENABLED
371371
if ((size_t)p_argcount > sizeof...(P)) {
372372
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
373-
r_error.argument = (int32_t)sizeof...(P);
373+
r_error.expected = (int32_t)sizeof...(P);
374374
return;
375375
}
376376
#endif
@@ -381,7 +381,7 @@ void call_with_variant_argsc_dv(T *p_instance, void (T::*p_method)(P...) const,
381381
#ifdef DEBUG_ENABLED
382382
if (missing > dvs) {
383383
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
384-
r_error.argument = (int32_t)sizeof...(P);
384+
r_error.expected = (int32_t)sizeof...(P);
385385
return;
386386
}
387387
#endif
@@ -405,7 +405,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const
405405
#ifdef DEBUG_ENABLED
406406
if ((size_t)p_argcount > sizeof...(P)) {
407407
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
408-
r_error.argument = (int32_t)sizeof...(P);
408+
r_error.expected = (int32_t)sizeof...(P);
409409
return;
410410
}
411411
#endif
@@ -416,7 +416,7 @@ void call_with_variant_args_ret_dv(T *p_instance, R (T::*p_method)(P...), const
416416
#ifdef DEBUG_ENABLED
417417
if (missing > dvs) {
418418
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
419-
r_error.argument = (int32_t)sizeof...(P);
419+
r_error.expected = (int32_t)sizeof...(P);
420420
return;
421421
}
422422
#endif
@@ -440,7 +440,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const,
440440
#ifdef DEBUG_ENABLED
441441
if ((size_t)p_argcount > sizeof...(P)) {
442442
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
443-
r_error.argument = (int32_t)sizeof...(P);
443+
r_error.expected = (int32_t)sizeof...(P);
444444
return;
445445
}
446446
#endif
@@ -451,7 +451,7 @@ void call_with_variant_args_retc_dv(T *p_instance, R (T::*p_method)(P...) const,
451451
#ifdef DEBUG_ENABLED
452452
if (missing > dvs) {
453453
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
454-
r_error.argument = (int32_t)sizeof...(P);
454+
r_error.expected = (int32_t)sizeof...(P);
455455
return;
456456
}
457457
#endif
@@ -552,7 +552,7 @@ void call_with_variant_args_static_dv(void (*p_method)(P...), const GDExtensionC
552552
#ifdef DEBUG_ENABLED
553553
if ((size_t)p_argcount > sizeof...(P)) {
554554
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
555-
r_error.argument = sizeof...(P);
555+
r_error.expected = sizeof...(P);
556556
return;
557557
}
558558
#endif
@@ -563,7 +563,7 @@ void call_with_variant_args_static_dv(void (*p_method)(P...), const GDExtensionC
563563
#ifdef DEBUG_ENABLED
564564
if (missing > dvs) {
565565
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
566-
r_error.argument = sizeof...(P);
566+
r_error.expected = sizeof...(P);
567567
return;
568568
}
569569
#endif
@@ -597,13 +597,13 @@ void call_with_variant_args_static_ret(R (*p_method)(P...), const Variant **p_ar
597597
#ifdef DEBUG_ENABLED
598598
if ((size_t)p_argcount > sizeof...(P)) {
599599
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
600-
r_error.argument = (int32_t)sizeof...(P);
600+
r_error.expected = (int32_t)sizeof...(P);
601601
return;
602602
}
603603

604604
if ((size_t)p_argcount < sizeof...(P)) {
605605
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
606-
r_error.argument = (int32_t)sizeof...(P);
606+
r_error.expected = (int32_t)sizeof...(P);
607607
return;
608608
}
609609
#endif
@@ -615,13 +615,13 @@ void call_with_variant_args_static_ret(void (*p_method)(P...), const Variant **p
615615
#ifdef DEBUG_ENABLED
616616
if ((size_t)p_argcount > sizeof...(P)) {
617617
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
618-
r_error.argument = (int32_t)sizeof...(P);
618+
r_error.expected = (int32_t)sizeof...(P);
619619
return;
620620
}
621621

622622
if ((size_t)p_argcount < sizeof...(P)) {
623623
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
624-
r_error.argument = (int32_t)sizeof...(P);
624+
r_error.expected = (int32_t)sizeof...(P);
625625
return;
626626
}
627627
#endif
@@ -644,7 +644,7 @@ void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const GDExtension
644644
#ifdef DEBUG_ENABLED
645645
if ((size_t)p_argcount > sizeof...(P)) {
646646
r_error.error = GDEXTENSION_CALL_ERROR_TOO_MANY_ARGUMENTS;
647-
r_error.argument = sizeof...(P);
647+
r_error.expected = sizeof...(P);
648648
return;
649649
}
650650
#endif
@@ -655,7 +655,7 @@ void call_with_variant_args_static_ret_dv(R (*p_method)(P...), const GDExtension
655655
#ifdef DEBUG_ENABLED
656656
if (missing > dvs) {
657657
r_error.error = GDEXTENSION_CALL_ERROR_TOO_FEW_ARGUMENTS;
658-
r_error.argument = sizeof...(P);
658+
r_error.expected = sizeof...(P);
659659
return;
660660
}
661661
#endif

include/godot_cpp/core/class_db.hpp

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,33 @@ class ClassDB {
112112
template <class T, bool is_abstract>
113113
static void _register_class(bool p_virtual = false, bool p_exposed = true);
114114

115+
template <class T>
116+
static GDExtensionObjectPtr _create_instance_func(void *data) {
117+
if constexpr (!std::is_abstract_v<T>) {
118+
T *new_object = memnew(T);
119+
return new_object->_owner;
120+
} else {
121+
return nullptr;
122+
}
123+
}
124+
125+
template <class T>
126+
static GDExtensionClassInstancePtr _recreate_instance_func(void *data, GDExtensionObjectPtr obj) {
127+
if constexpr (!std::is_abstract_v<T>) {
128+
#ifdef HOT_RELOAD_ENABLED
129+
T *new_instance = (T *)memalloc(sizeof(T));
130+
Wrapped::RecreateInstance recreate_data = { new_instance, obj, Wrapped::recreate_instance };
131+
Wrapped::recreate_instance = &recreate_data;
132+
memnew_placement(new_instance, T);
133+
return new_instance;
134+
#else
135+
return nullptr;
136+
#endif
137+
} else {
138+
return nullptr;
139+
}
140+
}
141+
115142
public:
116143
template <class T>
117144
static void register_class(bool p_virtual = false);
@@ -202,9 +229,9 @@ void ClassDB::_register_class(bool p_virtual, bool p_exposed) {
202229
T::to_string_bind, // GDExtensionClassToString to_string_func;
203230
nullptr, // GDExtensionClassReference reference_func;
204231
nullptr, // GDExtensionClassUnreference unreference_func;
205-
T::create, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */
232+
&_create_instance_func<T>, // GDExtensionClassCreateInstance create_instance_func; /* this one is mandatory */
206233
T::free, // GDExtensionClassFreeInstance free_instance_func; /* this one is mandatory */
207-
T::recreate, // GDExtensionClassRecreateInstance recreate_instance_func;
234+
&_recreate_instance_func<T>, // GDExtensionClassRecreateInstance recreate_instance_func;
208235
&ClassDB::get_virtual_func, // GDExtensionClassGetVirtual get_virtual_func;
209236
nullptr, // GDExtensionClassGetVirtualCallData get_virtual_call_data_func;
210237
nullptr, // GDExtensionClassCallVirtualWithData call_virtual_func;

include/godot_cpp/variant/aabb.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,11 @@ inline bool AABB::encloses(const AABB &p_aabb) const {
201201

202202
return (
203203
(src_min.x <= dst_min.x) &&
204-
(src_max.x > dst_max.x) &&
204+
(src_max.x >= dst_max.x) &&
205205
(src_min.y <= dst_min.y) &&
206-
(src_max.y > dst_max.y) &&
206+
(src_max.y >= dst_max.y) &&
207207
(src_min.z <= dst_min.z) &&
208-
(src_max.z > dst_max.z));
208+
(src_max.z >= dst_max.z));
209209
}
210210

211211
Vector3 AABB::get_support(const Vector3 &p_normal) const {

include/godot_cpp/variant/variant.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class Variant {
122122
OP_NEGATE,
123123
OP_POSITIVE,
124124
OP_MODULE,
125+
OP_POWER,
125126
// bitwise
126127
OP_SHIFT_LEFT,
127128
OP_SHIFT_RIGHT,
@@ -356,6 +357,12 @@ String vformat(const String &p_text, const VarArgs... p_args) {
356357

357358
#include <godot_cpp/variant/builtin_vararg_methods.hpp>
358359

360+
#ifdef REAL_T_IS_DOUBLE
361+
using PackedRealArray = PackedFloat64Array;
362+
#else
363+
using PackedRealArray = PackedFloat32Array;
364+
#endif // REAL_T_IS_DOUBLE
365+
359366
} // namespace godot
360367

361368
#endif // GODOT_VARIANT_HPP

src/godot.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ GDExtensionBool GDExtensionBinding::init(GDExtensionInterfaceGetProcAddress p_ge
271271
} else if (internal::godot_version.minor != GODOT_VERSION_MINOR) {
272272
compatible = internal::godot_version.minor > GODOT_VERSION_MINOR;
273273
} else {
274+
#if GODOT_VERSION_PATCH > 0
274275
compatible = internal::godot_version.patch >= GODOT_VERSION_PATCH;
276+
#else
277+
// Prevent -Wtype-limits warning due to unsigned comparison.
278+
compatible = true;
279+
#endif
275280
}
276281
if (!compatible) {
277282
// We need to use snprintf() here because vformat() uses Variant, and we haven't loaded

0 commit comments

Comments
 (0)