Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/object/class_db.h
9896 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/string/print_string.h"
36
37
// Makes callable_mp readily available in all classes connecting signals.
38
// Needs to come after method_bind and object have been included.
39
#include "core/object/callable_method_pointer.h"
40
#include "core/templates/hash_set.h"
41
42
#include <type_traits>
43
44
#define DEFVAL(m_defval) (m_defval)
45
#define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
46
47
#ifdef DEBUG_ENABLED
48
49
struct MethodDefinition {
50
StringName name;
51
Vector<StringName> args;
52
MethodDefinition() {}
53
MethodDefinition(const char *p_name) :
54
name(p_name) {}
55
MethodDefinition(const StringName &p_name) :
56
name(p_name) {}
57
};
58
59
MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount);
60
61
template <typename... VarArgs>
62
MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
63
const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported.
64
const char *const *argptrs[sizeof...(p_args) + 1];
65
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
66
argptrs[i] = &args[i];
67
}
68
69
return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args));
70
}
71
72
#else
73
74
// When DEBUG_ENABLED is set this will let the engine know
75
// the argument names for easier debugging.
76
#define D_METHOD(m_c, ...) m_c
77
78
#endif // DEBUG_ENABLED
79
80
class ClassDB {
81
friend class Object;
82
83
public:
84
enum APIType {
85
API_CORE,
86
API_EDITOR,
87
API_EXTENSION,
88
API_EDITOR_EXTENSION,
89
API_NONE
90
};
91
92
public:
93
struct PropertySetGet {
94
int index;
95
StringName setter;
96
StringName getter;
97
MethodBind *_setptr = nullptr;
98
MethodBind *_getptr = nullptr;
99
Variant::Type type;
100
};
101
102
struct ClassInfo {
103
APIType api = API_NONE;
104
ClassInfo *inherits_ptr = nullptr;
105
void *class_ptr = nullptr;
106
107
ObjectGDExtension *gdextension = nullptr;
108
109
HashMap<StringName, MethodBind *> method_map;
110
HashMap<StringName, LocalVector<MethodBind *>> method_map_compatibility;
111
HashMap<StringName, int64_t> constant_map;
112
struct EnumInfo {
113
List<StringName> constants;
114
bool is_bitfield = false;
115
};
116
117
HashMap<StringName, EnumInfo> enum_map;
118
HashMap<StringName, MethodInfo> signal_map;
119
List<PropertyInfo> property_list;
120
HashMap<StringName, PropertyInfo> property_map;
121
122
#ifdef DEBUG_ENABLED
123
List<StringName> constant_order;
124
List<StringName> method_order;
125
HashSet<StringName> methods_in_properties;
126
List<MethodInfo> virtual_methods;
127
HashMap<StringName, MethodInfo> virtual_methods_map;
128
HashMap<StringName, Vector<Error>> method_error_values;
129
HashMap<StringName, List<StringName>> linked_properties;
130
#endif // DEBUG_ENABLED
131
132
#ifdef TOOLS_ENABLED
133
List<StringName> dependency_list;
134
#endif
135
136
HashMap<StringName, PropertySetGet> property_setget;
137
HashMap<StringName, Vector<uint32_t>> virtual_methods_compat;
138
139
StringName inherits;
140
StringName name;
141
bool disabled = false;
142
bool exposed = false;
143
bool reloadable = false;
144
bool is_virtual = false;
145
bool is_runtime = false;
146
// The bool argument indicates the need to postinitialize.
147
Object *(*creation_func)(bool) = nullptr;
148
149
ClassInfo() {}
150
~ClassInfo() {}
151
};
152
153
template <typename T>
154
static Object *creator(bool p_notify_postinitialize) {
155
Object *ret = new ("") T;
156
ret->_initialize();
157
if (p_notify_postinitialize) {
158
ret->_postinitialize();
159
}
160
return ret;
161
}
162
163
// We need a recursive r/w lock because there are various code paths
164
// that may in turn invoke other entry points with require locking.
165
class Locker {
166
public:
167
enum State {
168
STATE_UNLOCKED,
169
STATE_READ,
170
STATE_WRITE,
171
};
172
173
private:
174
inline static RWLock lock;
175
inline thread_local static State thread_state = STATE_UNLOCKED;
176
177
public:
178
class Lock {
179
State state = STATE_UNLOCKED;
180
181
public:
182
explicit Lock(State p_state);
183
~Lock();
184
};
185
};
186
187
static HashMap<StringName, ClassInfo> classes;
188
static HashMap<StringName, StringName> resource_base_extensions;
189
static HashMap<StringName, StringName> compat_classes;
190
191
#ifdef TOOLS_ENABLED
192
static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
193
#endif
194
195
#ifdef DEBUG_ENABLED
196
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);
197
#else
198
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);
199
#endif // DEBUG_ENABLED
200
201
static APIType current_api;
202
static HashMap<APIType, uint32_t> api_hashes_cache;
203
204
static void _add_class(const StringName &p_class, const StringName &p_inherits);
205
206
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
207
static HashSet<StringName> default_values_cached;
208
209
// Native structs, used by binder
210
struct NativeStruct {
211
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.
212
uint64_t struct_size; // local size of struct, for comparison
213
};
214
static HashMap<StringName, NativeStruct> native_structs;
215
216
static Array default_array_arg;
217
static bool is_default_array_arg(const Array &p_array);
218
219
private:
220
// Non-locking variants of get_parent_class and is_parent_class.
221
static StringName _get_parent_class(const StringName &p_class);
222
static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
223
static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
224
static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
225
static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
226
227
static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false, bool p_notify_postinitialize = true, bool p_exposed_only = true);
228
229
static bool _can_instantiate(ClassInfo *p_class_info, bool p_exposed_only = true);
230
231
public:
232
template <typename T>
233
static void register_class(bool p_virtual = false) {
234
Locker::Lock lock(Locker::STATE_WRITE);
235
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
236
T::initialize_class();
237
ClassInfo *t = classes.getptr(T::get_class_static());
238
ERR_FAIL_NULL(t);
239
t->creation_func = &creator<T>;
240
t->exposed = true;
241
t->is_virtual = p_virtual;
242
t->class_ptr = T::get_class_ptr_static();
243
t->api = current_api;
244
T::register_custom_data_to_otdb();
245
}
246
247
template <typename T>
248
static void register_abstract_class() {
249
Locker::Lock lock(Locker::STATE_WRITE);
250
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
251
T::initialize_class();
252
ClassInfo *t = classes.getptr(T::get_class_static());
253
ERR_FAIL_NULL(t);
254
t->exposed = true;
255
t->class_ptr = T::get_class_ptr_static();
256
t->api = current_api;
257
//nothing
258
}
259
260
template <typename T>
261
static void register_internal_class() {
262
Locker::Lock lock(Locker::STATE_WRITE);
263
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
264
T::initialize_class();
265
ClassInfo *t = classes.getptr(T::get_class_static());
266
ERR_FAIL_NULL(t);
267
t->creation_func = &creator<T>;
268
t->exposed = false;
269
t->is_virtual = false;
270
t->class_ptr = T::get_class_ptr_static();
271
t->api = current_api;
272
T::register_custom_data_to_otdb();
273
}
274
275
template <typename T>
276
static void register_runtime_class() {
277
Locker::Lock lock(Locker::STATE_WRITE);
278
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
279
T::initialize_class();
280
ClassInfo *t = classes.getptr(T::get_class_static());
281
ERR_FAIL_NULL(t);
282
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()));
283
t->creation_func = &creator<T>;
284
t->exposed = true;
285
t->is_virtual = false;
286
t->is_runtime = true;
287
t->class_ptr = T::get_class_ptr_static();
288
t->api = current_api;
289
T::register_custom_data_to_otdb();
290
}
291
292
static void register_extension_class(ObjectGDExtension *p_extension);
293
static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
294
295
template <typename T>
296
static Object *_create_ptr_func(bool p_notify_postinitialize) {
297
return T::create(p_notify_postinitialize);
298
}
299
300
template <typename T>
301
static void register_custom_instance_class() {
302
Locker::Lock lock(Locker::STATE_WRITE);
303
static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
304
T::initialize_class();
305
ClassInfo *t = classes.getptr(T::get_class_static());
306
ERR_FAIL_NULL(t);
307
t->creation_func = &_create_ptr_func<T>;
308
t->exposed = 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 get_class_list(List<StringName> *p_classes);
315
#ifdef TOOLS_ENABLED
316
static void get_extensions_class_list(List<StringName> *p_classes);
317
static void get_extension_class_list(const Ref<GDExtension> &p_extension, List<StringName> *p_classes);
318
static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
319
#endif
320
static void get_inheriters_from_class(const StringName &p_class, LocalVector<StringName> &p_classes);
321
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
322
static StringName get_parent_class_nocheck(const StringName &p_class);
323
static bool get_inheritance_chain_nocheck(const StringName &p_class, Vector<StringName> &r_result);
324
static StringName get_parent_class(const StringName &p_class);
325
static StringName get_compatibility_remapped_class(const StringName &p_class);
326
static bool class_exists(const StringName &p_class);
327
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
328
static bool can_instantiate(const StringName &p_class);
329
static bool is_abstract(const StringName &p_class);
330
static bool is_virtual(const StringName &p_class);
331
static Object *instantiate(const StringName &p_class);
332
static Object *instantiate_no_placeholders(const StringName &p_class);
333
static Object *instantiate_without_postinitialization(const StringName &p_class);
334
static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
335
336
static APIType get_api_type(const StringName &p_class);
337
338
static uint32_t get_api_hash(APIType p_api);
339
340
template <typename>
341
struct member_function_traits;
342
343
template <typename R, typename T, typename... Args>
344
struct member_function_traits<R (T::*)(Args...)> {
345
using return_type = R;
346
};
347
348
template <typename R, typename T, typename... Args>
349
struct member_function_traits<R (T::*)(Args...) const> {
350
using return_type = R;
351
};
352
353
template <typename R, typename... Args>
354
struct member_function_traits<R (*)(Args...)> {
355
using return_type = R;
356
};
357
358
template <typename N, typename M, typename... VarArgs>
359
static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
360
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
361
const Variant *argptrs[sizeof...(p_args) + 1];
362
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
363
argptrs[i] = &args[i];
364
}
365
MethodBind *bind = create_method_bind(p_method);
366
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
367
bind->set_return_type_is_raw_object_ptr(true);
368
}
369
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
370
}
371
372
template <typename N, typename M, typename... VarArgs>
373
static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
374
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
375
const Variant *argptrs[sizeof...(p_args) + 1];
376
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
377
argptrs[i] = &args[i];
378
}
379
MethodBind *bind = create_static_method_bind(p_method);
380
bind->set_instance_class(p_class);
381
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
382
bind->set_return_type_is_raw_object_ptr(true);
383
}
384
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
385
}
386
387
template <typename N, typename M, typename... VarArgs>
388
static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
389
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
390
const Variant *argptrs[sizeof...(p_args) + 1];
391
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
392
argptrs[i] = &args[i];
393
}
394
MethodBind *bind = create_method_bind(p_method);
395
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
396
bind->set_return_type_is_raw_object_ptr(true);
397
}
398
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
399
}
400
401
template <typename N, typename M, typename... VarArgs>
402
static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
403
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
404
const Variant *argptrs[sizeof...(p_args) + 1];
405
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
406
argptrs[i] = &args[i];
407
}
408
MethodBind *bind = create_static_method_bind(p_method);
409
bind->set_instance_class(p_class);
410
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
411
bind->set_return_type_is_raw_object_ptr(true);
412
}
413
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
414
}
415
416
template <typename M>
417
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) {
418
Locker::Lock lock(Locker::STATE_WRITE);
419
420
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
421
ERR_FAIL_NULL_V(bind, nullptr);
422
423
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
424
bind->set_return_type_is_raw_object_ptr(true);
425
}
426
return _bind_vararg_method(bind, p_name, p_default_args, false);
427
}
428
429
template <typename M>
430
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) {
431
Locker::Lock lock(Locker::STATE_WRITE);
432
433
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
434
ERR_FAIL_NULL_V(bind, nullptr);
435
436
if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
437
bind->set_return_type_is_raw_object_ptr(true);
438
}
439
return _bind_vararg_method(bind, p_name, p_default_args, true);
440
}
441
442
static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
443
static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
444
445
static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
446
static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
447
static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
448
static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
449
450
static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
451
static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
452
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);
453
static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
454
static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
455
static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
456
static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
457
static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
458
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);
459
static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
460
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
461
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
462
static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
463
static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
464
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
465
static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
466
static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
467
468
static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
469
static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
470
471
static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
472
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);
473
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);
474
static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
475
static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
476
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);
477
static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
478
479
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);
480
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);
481
static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
482
static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
483
static Vector<uint32_t> get_virtual_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
484
485
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);
486
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
487
static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
488
static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
489
490
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
491
static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
492
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
493
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
494
static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
495
static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
496
497
static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
498
static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
499
static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
500
501
static void set_class_enabled(const StringName &p_class, bool p_enable);
502
static bool is_class_enabled(const StringName &p_class);
503
504
static bool is_class_exposed(const StringName &p_class);
505
static bool is_class_reloadable(const StringName &p_class);
506
static bool is_class_runtime(const StringName &p_class);
507
508
#ifdef TOOLS_ENABLED
509
static void add_class_dependency(const StringName &p_class, const StringName &p_dependency);
510
static void get_class_dependencies(const StringName &p_class, List<StringName> *r_rependencies);
511
#endif
512
513
static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
514
static void get_resource_base_extensions(List<String> *p_extensions);
515
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
516
static bool is_resource_extension(const StringName &p_extension);
517
518
static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
519
static StringName get_compatibility_class(const StringName &p_class);
520
521
static void set_current_api(APIType p_api);
522
static APIType get_current_api();
523
static void cleanup_defaults();
524
static void cleanup();
525
526
static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
527
static void get_native_struct_list(List<StringName> *r_names);
528
static String get_native_struct_code(const StringName &p_name);
529
static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
530
531
static Object *_instantiate_allow_unexposed(const StringName &p_class); // Used to create unexposed classes from GDExtension, typically for unexposed EditorPlugin.
532
};
533
534
#define BIND_ENUM_CONSTANT(m_constant) \
535
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
536
537
#define BIND_BITFIELD_FLAG(m_constant) \
538
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true);
539
540
#define BIND_CONSTANT(m_constant) \
541
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
542
543
#ifdef DEBUG_ENABLED
544
545
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
546
::ClassDB::set_method_error_return_values(get_class_static(), m_method, Vector<Error>{ __VA_ARGS__ });
547
548
#else
549
550
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
551
552
#endif // DEBUG_ENABLED
553
554
#define GDREGISTER_CLASS(m_class) \
555
if (m_class::_class_is_enabled) { \
556
::ClassDB::register_class<m_class>(); \
557
}
558
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
559
if (m_class::_class_is_enabled) { \
560
::ClassDB::register_class<m_class>(true); \
561
}
562
#define GDREGISTER_ABSTRACT_CLASS(m_class) \
563
if (m_class::_class_is_enabled) { \
564
::ClassDB::register_abstract_class<m_class>(); \
565
}
566
#define GDREGISTER_INTERNAL_CLASS(m_class) \
567
if (m_class::_class_is_enabled) { \
568
::ClassDB::register_internal_class<m_class>(); \
569
}
570
571
#define GDREGISTER_RUNTIME_CLASS(m_class) \
572
if (m_class::_class_is_enabled) { \
573
::ClassDB::register_runtime_class<m_class>(); \
574
}
575
576
#define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
577
578