Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/object/class_db.h
21081 views
1
/**************************************************************************/
2
/* class_db.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/object/method_bind.h"
34
#include "core/object/object.h"
35
#include "core/os/rw_lock.h"
36
#include "core/string/print_string.h"
37
38
// Makes callable_mp readily available in all classes connecting signals.
39
// Needs to come after method_bind and object have been included.
40
#include "core/object/callable_method_pointer.h"
41
#include "core/templates/a_hash_map.h"
42
#include "core/templates/hash_set.h"
43
44
#include <type_traits>
45
46
template <typename T, typename = void>
47
struct is_class_enabled;
48
49
template <>
50
struct is_class_enabled<Object> : std::true_type {};
51
52
template <typename T>
53
struct is_class_enabled<T, std::enable_if_t<std::is_base_of_v<Object, T>>> {
54
static constexpr bool value = is_class_enabled<typename T::super_type>::value;
55
};
56
57
template <typename T>
58
inline constexpr bool is_class_enabled_v = is_class_enabled<T>::value;
59
60
#define GD_IS_CLASS_ENABLED(m_class) is_class_enabled_v<m_class>
61
62
#include "core/disabled_classes.gen.h"
63
64
#define DEFVAL(m_defval) (m_defval)
65
#define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
66
67
#ifdef DEBUG_ENABLED
68
69
struct MethodDefinition {
70
StringName name;
71
Vector<StringName> args;
72
MethodDefinition() {}
73
MethodDefinition(const char *p_name) :
74
name(p_name) {}
75
MethodDefinition(const StringName &p_name) :
76
name(p_name) {}
77
};
78
79
MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount);
80
81
template <typename... VarArgs>
82
MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
83
const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported.
84
const char *const *argptrs[sizeof...(p_args) + 1];
85
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
86
argptrs[i] = &args[i];
87
}
88
89
return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args));
90
}
91
92
#else
93
94
// When DEBUG_ENABLED is set this will let the engine know
95
// the argument names for easier debugging.
96
#define D_METHOD(m_c, ...) m_c
97
98
#endif // DEBUG_ENABLED
99
100
class ClassDB {
101
friend class Object;
102
103
public:
104
enum APIType {
105
API_CORE,
106
API_EDITOR,
107
API_EXTENSION,
108
API_EDITOR_EXTENSION,
109
API_NONE
110
};
111
112
public:
113
struct PropertySetGet {
114
int index;
115
StringName setter;
116
StringName getter;
117
MethodBind *_setptr = nullptr;
118
MethodBind *_getptr = nullptr;
119
Variant::Type type;
120
};
121
122
struct ClassInfo {
123
APIType api = API_NONE;
124
ClassInfo *inherits_ptr = nullptr;
125
void *class_ptr = nullptr;
126
const GDType *gdtype = nullptr;
127
128
ObjectGDExtension *gdextension = nullptr;
129
130
HashMap<StringName, MethodBind *> method_map;
131
HashMap<StringName, LocalVector<MethodBind *>> method_map_compatibility;
132
AHashMap<StringName, int64_t> constant_map;
133
struct EnumInfo {
134
List<StringName> constants;
135
bool is_bitfield = false;
136
};
137
138
HashMap<StringName, EnumInfo> enum_map;
139
AHashMap<StringName, MethodInfo> signal_map;
140
List<PropertyInfo> property_list;
141
HashMap<StringName, PropertyInfo> property_map;
142
143
#ifdef DEBUG_ENABLED
144
List<StringName> constant_order;
145
List<StringName> method_order;
146
HashSet<StringName> methods_in_properties;
147
List<MethodInfo> virtual_methods;
148
HashMap<StringName, MethodInfo> virtual_methods_map;
149
HashMap<StringName, Vector<Error>> method_error_values;
150
HashMap<StringName, List<StringName>> linked_properties;
151
#endif // DEBUG_ENABLED
152
153
#ifdef TOOLS_ENABLED
154
List<StringName> dependency_list;
155
#endif
156
157
AHashMap<StringName, PropertySetGet> property_setget;
158
HashMap<StringName, Vector<uint32_t>> virtual_methods_compat;
159
160
StringName inherits;
161
StringName name;
162
bool disabled = false;
163
bool exposed = false;
164
bool reloadable = false;
165
bool is_virtual = false;
166
bool is_runtime = false;
167
// The bool argument indicates the need to postinitialize.
168
Object *(*creation_func)(bool) = nullptr;
169
};
170
171
template <typename T>
172
static Object *creator(bool p_notify_postinitialize) {
173
Object *ret = new ("") T;
174
ret->_initialize();
175
if (p_notify_postinitialize) {
176
ret->_postinitialize();
177
}
178
return ret;
179
}
180
181
// We need a recursive r/w lock because there are various code paths
182
// that may in turn invoke other entry points with require locking.
183
class Locker {
184
public:
185
enum State {
186
STATE_UNLOCKED,
187
STATE_READ,
188
STATE_WRITE,
189
};
190
191
private:
192
inline static RWLock lock;
193
inline thread_local static State thread_state = STATE_UNLOCKED;
194
195
public:
196
class Lock {
197
State state = STATE_UNLOCKED;
198
199
public:
200
explicit Lock(State p_state);
201
~Lock();
202
};
203
};
204
205
static HashMap<StringName, ClassInfo> classes;
206
static HashMap<StringName, StringName> resource_base_extensions;
207
static HashMap<StringName, StringName> compat_classes;
208
209
#ifdef TOOLS_ENABLED
210
static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
211
#endif
212
213
#ifdef DEBUG_ENABLED
214
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
215
#else
216
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, bool p_compatibility, const char *method_name, const Variant **p_defs, int p_defcount);
217
#endif // DEBUG_ENABLED
218
219
static APIType current_api;
220
static HashMap<APIType, uint32_t> api_hashes_cache;
221
222
static void _add_class(const GDType &p_class, const GDType *p_inherits);
223
224
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
225
static HashSet<StringName> default_values_cached;
226
227
// Native structs, used by binder
228
struct NativeStruct {
229
String ccode; // C code to create the native struct, fields separated by ; Arrays accepted (even containing other structs), also function pointers. All types must be Godot types.
230
uint64_t struct_size; // local size of struct, for comparison
231
};
232
static HashMap<StringName, NativeStruct> native_structs;
233
234
static Array default_array_arg;
235
static bool is_default_array_arg(const Array &p_array);
236
237
// Types added here will be automatically cleaned up on engine shutdown.
238
// Only add types that aren't cleaned up in another way.
239
static LocalVector<GDType **> gdtype_autorelease_pool;
240
241
private:
242
// Non-locking variants of get_parent_class and is_parent_class.
243
static StringName _get_parent_class(const StringName &p_class);
244
static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
245
static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
246
static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
247
static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
248
249
static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false, bool p_notify_postinitialize = true, bool p_exposed_only = true);
250
251
static bool _can_instantiate(ClassInfo *p_class_info, bool p_exposed_only = true);
252
253
public:
254
template <typename T>
255
static void register_class(bool p_virtual = false) {
256
Locker::Lock lock(Locker::STATE_WRITE);
257
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
258
T::initialize_class();
259
ClassInfo *t = classes.getptr(T::get_class_static());
260
ERR_FAIL_NULL(t);
261
t->creation_func = &creator<T>;
262
t->exposed = true;
263
t->is_virtual = p_virtual;
264
t->class_ptr = T::get_class_ptr_static();
265
t->api = current_api;
266
T::register_custom_data_to_otdb();
267
}
268
269
template <typename T>
270
static void register_abstract_class() {
271
Locker::Lock lock(Locker::STATE_WRITE);
272
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
273
T::initialize_class();
274
ClassInfo *t = classes.getptr(T::get_class_static());
275
ERR_FAIL_NULL(t);
276
t->exposed = true;
277
t->class_ptr = T::get_class_ptr_static();
278
t->api = current_api;
279
//nothing
280
}
281
282
template <typename T>
283
static void register_internal_class() {
284
Locker::Lock lock(Locker::STATE_WRITE);
285
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
286
T::initialize_class();
287
ClassInfo *t = classes.getptr(T::get_class_static());
288
ERR_FAIL_NULL(t);
289
t->creation_func = &creator<T>;
290
t->exposed = false;
291
t->is_virtual = false;
292
t->class_ptr = T::get_class_ptr_static();
293
t->api = current_api;
294
T::register_custom_data_to_otdb();
295
}
296
297
template <typename T>
298
static void register_runtime_class() {
299
Locker::Lock lock(Locker::STATE_WRITE);
300
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
301
T::initialize_class();
302
ClassInfo *t = classes.getptr(T::get_class_static());
303
ERR_FAIL_NULL(t);
304
ERR_FAIL_COND_MSG(t->inherits_ptr && !t->inherits_ptr->creation_func, vformat("Cannot register runtime class '%s' that descends from an abstract parent class.", T::get_class_static()));
305
t->creation_func = &creator<T>;
306
t->exposed = true;
307
t->is_virtual = false;
308
t->is_runtime = true;
309
t->class_ptr = T::get_class_ptr_static();
310
t->api = current_api;
311
T::register_custom_data_to_otdb();
312
}
313
314
static void register_extension_class(ObjectGDExtension *p_extension);
315
static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
316
317
template <typename T>
318
static Object *_create_ptr_func(bool p_notify_postinitialize) {
319
return T::create(p_notify_postinitialize);
320
}
321
322
template <typename T>
323
static void register_custom_instance_class() {
324
Locker::Lock lock(Locker::STATE_WRITE);
325
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
326
T::initialize_class();
327
ClassInfo *t = classes.getptr(T::get_class_static());
328
ERR_FAIL_NULL(t);
329
t->creation_func = &_create_ptr_func<T>;
330
t->exposed = true;
331
t->class_ptr = T::get_class_ptr_static();
332
t->api = current_api;
333
T::register_custom_data_to_otdb();
334
}
335
336
static void get_class_list(LocalVector<StringName> &p_classes);
337
#ifdef TOOLS_ENABLED
338
static void get_extensions_class_list(LocalVector<StringName> &p_classes);
339
static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
340
static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
341
#endif
342
static const GDType *get_gdtype(const StringName &p_class);
343
static void get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes);
344
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
345
static StringName get_parent_class_nocheck(const StringName &p_class);
346
static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
347
static StringName get_parent_class(const StringName &p_class);
348
static StringName get_compatibility_remapped_class(const StringName &p_class);
349
static bool class_exists(const StringName &p_class);
350
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
351
static bool can_instantiate(const StringName &p_class);
352
static bool is_abstract(const StringName &p_class);
353
static bool is_virtual(const StringName &p_class);
354
static Object *instantiate(const StringName &p_class);
355
static Object *instantiate_no_placeholders(const StringName &p_class);
356
static Object *instantiate_without_postinitialization(const StringName &p_class);
357
static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
358
359
static APIType get_api_type(const StringName &p_class);
360
361
static uint32_t get_api_hash(APIType p_api);
362
363
template <typename>
364
struct member_function_traits;
365
366
template <typename R, typename T, typename... Args>
367
struct member_function_traits<R (T::*)(Args...)> {
368
using return_type = R;
369
};
370
371
template <typename R, typename T, typename... Args>
372
struct member_function_traits<R (T::*)(Args...) const> {
373
using return_type = R;
374
};
375
376
template <typename R, typename... Args>
377
struct member_function_traits<R (*)(Args...)> {
378
using return_type = R;
379
};
380
381
template <typename N, typename M, typename... VarArgs>
382
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
383
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
384
const Variant *argptrs[sizeof...(p_args) + 1];
385
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
386
argptrs[i] = &args[i];
387
}
388
MethodBind *bind = create_method_bind(p_method);
389
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
390
bind->set_return_type_is_raw_object_ptr(true);
391
}
392
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
393
}
394
395
template <typename N, typename M, typename... VarArgs>
396
static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
397
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
398
const Variant *argptrs[sizeof...(p_args) + 1];
399
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
400
argptrs[i] = &args[i];
401
}
402
MethodBind *bind = create_static_method_bind(p_method);
403
bind->set_instance_class(p_class);
404
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
405
bind->set_return_type_is_raw_object_ptr(true);
406
}
407
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
408
}
409
410
template <typename N, typename M, typename... VarArgs>
411
static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
412
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
413
const Variant *argptrs[sizeof...(p_args) + 1];
414
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
415
argptrs[i] = &args[i];
416
}
417
MethodBind *bind = create_method_bind(p_method);
418
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
419
bind->set_return_type_is_raw_object_ptr(true);
420
}
421
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
422
}
423
424
template <typename N, typename M, typename... VarArgs>
425
static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
426
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
427
const Variant *argptrs[sizeof...(p_args) + 1];
428
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
429
argptrs[i] = &args[i];
430
}
431
MethodBind *bind = create_static_method_bind(p_method);
432
bind->set_instance_class(p_class);
433
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
434
bind->set_return_type_is_raw_object_ptr(true);
435
}
436
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
437
}
438
439
template <typename M>
440
static MethodBind *bind_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
441
Locker::Lock lock(Locker::STATE_WRITE);
442
443
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
444
ERR_FAIL_NULL_V(bind, nullptr);
445
446
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
447
bind->set_return_type_is_raw_object_ptr(true);
448
}
449
return _bind_vararg_method(bind, p_name, p_default_args, false);
450
}
451
452
template <typename M>
453
static MethodBind *bind_compatibility_vararg_method(uint32_t p_flags, const StringName &p_name, M p_method, const MethodInfo &p_info = MethodInfo(), const Vector<Variant> &p_default_args = Vector<Variant>(), bool p_return_nil_is_variant = true) {
454
Locker::Lock lock(Locker::STATE_WRITE);
455
456
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
457
ERR_FAIL_NULL_V(bind, nullptr);
458
459
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
460
bind->set_return_type_is_raw_object_ptr(true);
461
}
462
return _bind_vararg_method(bind, p_name, p_default_args, true);
463
}
464
465
static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
466
static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
467
468
static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
469
static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
470
static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
471
static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
472
473
static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
474
static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
475
static void add_property_array_count(const StringName &p_class, const String &p_label, const StringName &p_count_property, const StringName &p_count_setter, const StringName &p_count_getter, const String &p_array_element_prefix, uint32_t p_count_usage = PROPERTY_USAGE_DEFAULT);
476
static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
477
static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
478
static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
479
static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
480
static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
481
static bool get_property_info(const StringName &p_class, const StringName &p_property, PropertyInfo *r_info, bool p_no_inheritance = false, const Object *p_validator = nullptr);
482
static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
483
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
484
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
485
static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
486
static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
487
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
488
static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
489
static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
490
491
static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
492
static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
493
494
static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
495
static void get_method_list_with_compatibility(const StringName &p_class, List<Pair<MethodInfo, uint32_t>> *p_methods_with_hash, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
496
static bool get_method_info(const StringName &p_class, const StringName &p_method, MethodInfo *r_info, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
497
static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
498
static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
499
static MethodBind *get_method_with_compatibility(const StringName &p_class, const StringName &p_name, uint64_t p_hash, bool *r_method_exists = nullptr, bool *r_is_deprecated = nullptr);
500
static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
501
502
static void add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false);
503
static void add_virtual_compatibility_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual = true, const Vector<String> &p_arg_names = Vector<String>(), bool p_object_core = false);
504
static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
505
static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
506
static Vector<uint32_t> get_virtual_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
507
508
static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int64_t p_constant, bool p_is_bitfield = false);
509
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
510
static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
511
static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
512
513
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
514
static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
515
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
516
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
517
static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
518
static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
519
520
static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
521
static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
522
static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
523
524
static void set_class_enabled(const StringName &p_class, bool p_enable);
525
static bool is_class_enabled(const StringName &p_class);
526
527
static bool is_class_exposed(const StringName &p_class);
528
static bool is_class_reloadable(const StringName &p_class);
529
static bool is_class_runtime(const StringName &p_class);
530
531
#ifdef TOOLS_ENABLED
532
static void add_class_dependency(const StringName &p_class, const StringName &p_dependency);
533
static void get_class_dependencies(const StringName &p_class, List<StringName> *r_rependencies);
534
#endif
535
536
static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
537
static void get_resource_base_extensions(List<String> *p_extensions);
538
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
539
static bool is_resource_extension(const StringName &p_extension);
540
541
static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
542
static StringName get_compatibility_class(const StringName &p_class);
543
544
static void set_current_api(APIType p_api);
545
static APIType get_current_api();
546
static void cleanup_defaults();
547
static void cleanup();
548
549
static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
550
static void get_native_struct_list(List<StringName> *r_names);
551
static String get_native_struct_code(const StringName &p_name);
552
static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
553
554
static Object *_instantiate_allow_unexposed(const StringName &p_class); // Used to create unexposed classes from GDExtension, typically for unexposed EditorPlugin.
555
};
556
557
#define BIND_ENUM_CONSTANT(m_constant) \
558
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant), #m_constant, m_constant);
559
560
#define BIND_BITFIELD_FLAG(m_constant) \
561
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant), #m_constant, m_constant, true);
562
563
#define BIND_CONSTANT(m_constant) \
564
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
565
566
#ifdef DEBUG_ENABLED
567
568
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
569
::ClassDB::set_method_error_return_values(get_class_static(), m_method, Vector<Error>{ __VA_ARGS__ });
570
571
#else
572
573
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
574
575
#endif // DEBUG_ENABLED
576
577
#define GDREGISTER_CLASS(m_class) \
578
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
579
::ClassDB::register_class<m_class>(); \
580
}
581
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
582
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
583
::ClassDB::register_class<m_class>(true); \
584
}
585
#define GDREGISTER_ABSTRACT_CLASS(m_class) \
586
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
587
::ClassDB::register_abstract_class<m_class>(); \
588
}
589
#define GDREGISTER_INTERNAL_CLASS(m_class) \
590
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
591
::ClassDB::register_internal_class<m_class>(); \
592
}
593
#define GDREGISTER_RUNTIME_CLASS(m_class) \
594
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
595
::ClassDB::register_runtime_class<m_class>(); \
596
}
597
598
#define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
599
600