class_db.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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. #ifndef CLASS_DB_H
  31. #define CLASS_DB_H
  32. #include "core/object/method_bind.h"
  33. #include "core/object/object.h"
  34. #include "core/string/print_string.h"
  35. // Makes callable_mp readily available in all classes connecting signals.
  36. // Needs to come after method_bind and object have been included.
  37. #include "core/object/callable_method_pointer.h"
  38. #include "core/templates/hash_set.h"
  39. #include <type_traits>
  40. #define DEFVAL(m_defval) (m_defval)
  41. #ifdef DEBUG_METHODS_ENABLED
  42. struct MethodDefinition {
  43. StringName name;
  44. Vector<StringName> args;
  45. MethodDefinition() {}
  46. MethodDefinition(const char *p_name) :
  47. name(p_name) {}
  48. MethodDefinition(const StringName &p_name) :
  49. name(p_name) {}
  50. };
  51. MethodDefinition D_METHODP(const char *p_name, const char *const **p_args, uint32_t p_argcount);
  52. template <typename... VarArgs>
  53. MethodDefinition D_METHOD(const char *p_name, const VarArgs... p_args) {
  54. const char *args[sizeof...(p_args) + 1] = { p_args..., nullptr }; // +1 makes sure zero sized arrays are also supported.
  55. const char *const *argptrs[sizeof...(p_args) + 1];
  56. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  57. argptrs[i] = &args[i];
  58. }
  59. return D_METHODP(p_name, sizeof...(p_args) == 0 ? nullptr : (const char *const **)argptrs, sizeof...(p_args));
  60. }
  61. #else
  62. // When DEBUG_METHODS_ENABLED is set this will let the engine know
  63. // the argument names for easier debugging.
  64. #define D_METHOD(m_c, ...) m_c
  65. #endif
  66. class ClassDB {
  67. public:
  68. enum APIType {
  69. API_CORE,
  70. API_EDITOR,
  71. API_EXTENSION,
  72. API_EDITOR_EXTENSION,
  73. API_NONE
  74. };
  75. public:
  76. struct PropertySetGet {
  77. int index;
  78. StringName setter;
  79. StringName getter;
  80. MethodBind *_setptr = nullptr;
  81. MethodBind *_getptr = nullptr;
  82. Variant::Type type;
  83. };
  84. struct ClassInfo {
  85. APIType api = API_NONE;
  86. ClassInfo *inherits_ptr = nullptr;
  87. void *class_ptr = nullptr;
  88. ObjectGDExtension *gdextension = nullptr;
  89. HashMap<StringName, MethodBind *> method_map;
  90. HashMap<StringName, LocalVector<MethodBind *>> method_map_compatibility;
  91. HashMap<StringName, int64_t> constant_map;
  92. struct EnumInfo {
  93. List<StringName> constants;
  94. bool is_bitfield = false;
  95. };
  96. HashMap<StringName, EnumInfo> enum_map;
  97. HashMap<StringName, MethodInfo> signal_map;
  98. List<PropertyInfo> property_list;
  99. HashMap<StringName, PropertyInfo> property_map;
  100. #ifdef DEBUG_METHODS_ENABLED
  101. List<StringName> constant_order;
  102. List<StringName> method_order;
  103. HashSet<StringName> methods_in_properties;
  104. List<MethodInfo> virtual_methods;
  105. HashMap<StringName, MethodInfo> virtual_methods_map;
  106. HashMap<StringName, Vector<Error>> method_error_values;
  107. HashMap<StringName, List<StringName>> linked_properties;
  108. #endif
  109. HashMap<StringName, PropertySetGet> property_setget;
  110. StringName inherits;
  111. StringName name;
  112. bool disabled = false;
  113. bool exposed = false;
  114. bool is_virtual = false;
  115. Object *(*creation_func)() = nullptr;
  116. ClassInfo() {}
  117. ~ClassInfo() {}
  118. };
  119. template <class T>
  120. static Object *creator() {
  121. return memnew(T);
  122. }
  123. static RWLock lock;
  124. static HashMap<StringName, ClassInfo> classes;
  125. static HashMap<StringName, StringName> resource_base_extensions;
  126. static HashMap<StringName, StringName> compat_classes;
  127. #ifdef DEBUG_METHODS_ENABLED
  128. 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);
  129. #else
  130. 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);
  131. #endif
  132. static APIType current_api;
  133. static HashMap<APIType, uint64_t> api_hashes_cache;
  134. static void _add_class2(const StringName &p_class, const StringName &p_inherits);
  135. static HashMap<StringName, HashMap<StringName, Variant>> default_values;
  136. static HashSet<StringName> default_values_cached;
  137. // Native structs, used by binder
  138. struct NativeStruct {
  139. 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.
  140. uint64_t struct_size; // local size of struct, for comparison
  141. };
  142. static HashMap<StringName, NativeStruct> native_structs;
  143. private:
  144. // Non-locking variants of get_parent_class and is_parent_class.
  145. static StringName _get_parent_class(const StringName &p_class);
  146. static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
  147. static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
  148. static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
  149. static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
  150. public:
  151. // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
  152. template <class T>
  153. static void _add_class() {
  154. _add_class2(T::get_class_static(), T::get_parent_class_static());
  155. }
  156. template <class T>
  157. static void register_class(bool p_virtual = false) {
  158. GLOBAL_LOCK_FUNCTION;
  159. static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
  160. T::initialize_class();
  161. ClassInfo *t = classes.getptr(T::get_class_static());
  162. ERR_FAIL_COND(!t);
  163. t->creation_func = &creator<T>;
  164. t->exposed = true;
  165. t->is_virtual = p_virtual;
  166. t->class_ptr = T::get_class_ptr_static();
  167. t->api = current_api;
  168. T::register_custom_data_to_otdb();
  169. }
  170. template <class T>
  171. static void register_abstract_class() {
  172. GLOBAL_LOCK_FUNCTION;
  173. static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
  174. T::initialize_class();
  175. ClassInfo *t = classes.getptr(T::get_class_static());
  176. ERR_FAIL_COND(!t);
  177. t->exposed = true;
  178. t->class_ptr = T::get_class_ptr_static();
  179. t->api = current_api;
  180. //nothing
  181. }
  182. static void register_extension_class(ObjectGDExtension *p_extension);
  183. static void unregister_extension_class(const StringName &p_class);
  184. template <class T>
  185. static Object *_create_ptr_func() {
  186. return T::create();
  187. }
  188. template <class T>
  189. static void register_custom_instance_class() {
  190. GLOBAL_LOCK_FUNCTION;
  191. static_assert(TypesAreSame<typename T::self_type, T>::value, "Class not declared properly, please use GDCLASS.");
  192. T::initialize_class();
  193. ClassInfo *t = classes.getptr(T::get_class_static());
  194. ERR_FAIL_COND(!t);
  195. t->creation_func = &_create_ptr_func<T>;
  196. t->exposed = true;
  197. t->class_ptr = T::get_class_ptr_static();
  198. t->api = current_api;
  199. T::register_custom_data_to_otdb();
  200. }
  201. static void get_class_list(List<StringName> *p_classes);
  202. static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  203. static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  204. static StringName get_parent_class_nocheck(const StringName &p_class);
  205. static StringName get_parent_class(const StringName &p_class);
  206. static StringName get_compatibility_remapped_class(const StringName &p_class);
  207. static bool class_exists(const StringName &p_class);
  208. static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
  209. static bool can_instantiate(const StringName &p_class);
  210. static bool is_virtual(const StringName &p_class);
  211. static Object *instantiate(const StringName &p_class);
  212. static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
  213. static APIType get_api_type(const StringName &p_class);
  214. static uint64_t get_api_hash(APIType p_api);
  215. template <typename>
  216. struct member_function_traits;
  217. template <typename R, typename T, typename... Args>
  218. struct member_function_traits<R (T::*)(Args...)> {
  219. using return_type = R;
  220. };
  221. template <typename R, typename T, typename... Args>
  222. struct member_function_traits<R (T::*)(Args...) const> {
  223. using return_type = R;
  224. };
  225. template <typename R, typename... Args>
  226. struct member_function_traits<R (*)(Args...)> {
  227. using return_type = R;
  228. };
  229. template <class N, class M, typename... VarArgs>
  230. static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
  231. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  232. const Variant *argptrs[sizeof...(p_args) + 1];
  233. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  234. argptrs[i] = &args[i];
  235. }
  236. MethodBind *bind = create_method_bind(p_method);
  237. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  238. bind->set_return_type_is_raw_object_ptr(true);
  239. }
  240. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  241. }
  242. template <class N, class M, typename... VarArgs>
  243. static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  244. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  245. const Variant *argptrs[sizeof...(p_args) + 1];
  246. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  247. argptrs[i] = &args[i];
  248. }
  249. MethodBind *bind = create_static_method_bind(p_method);
  250. bind->set_instance_class(p_class);
  251. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  252. bind->set_return_type_is_raw_object_ptr(true);
  253. }
  254. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  255. }
  256. template <class N, class M, typename... VarArgs>
  257. static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
  258. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  259. const Variant *argptrs[sizeof...(p_args) + 1];
  260. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  261. argptrs[i] = &args[i];
  262. }
  263. MethodBind *bind = create_method_bind(p_method);
  264. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  265. bind->set_return_type_is_raw_object_ptr(true);
  266. }
  267. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  268. }
  269. template <class N, class M, typename... VarArgs>
  270. static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  271. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  272. const Variant *argptrs[sizeof...(p_args) + 1];
  273. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  274. argptrs[i] = &args[i];
  275. }
  276. MethodBind *bind = create_static_method_bind(p_method);
  277. bind->set_instance_class(p_class);
  278. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  279. bind->set_return_type_is_raw_object_ptr(true);
  280. }
  281. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  282. }
  283. template <class M>
  284. 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) {
  285. GLOBAL_LOCK_FUNCTION;
  286. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  287. ERR_FAIL_COND_V(!bind, nullptr);
  288. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  289. bind->set_return_type_is_raw_object_ptr(true);
  290. }
  291. return _bind_vararg_method(bind, p_name, p_default_args, false);
  292. }
  293. template <class M>
  294. 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) {
  295. GLOBAL_LOCK_FUNCTION;
  296. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  297. ERR_FAIL_COND_V(!bind, nullptr);
  298. if constexpr (std::is_same<typename member_function_traits<M>::return_type, Object *>::value) {
  299. bind->set_return_type_is_raw_object_ptr(true);
  300. }
  301. return _bind_vararg_method(bind, p_name, p_default_args, true);
  302. }
  303. static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
  304. static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
  305. static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
  306. static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
  307. static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
  308. static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
  309. static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  310. static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  311. 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);
  312. static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
  313. static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
  314. static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
  315. static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
  316. static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  317. 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);
  318. static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
  319. static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
  320. static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
  321. static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
  322. static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  323. static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  324. static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
  325. static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
  326. static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
  327. static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
  328. static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  329. 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);
  330. static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
  331. 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);
  332. static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  333. 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);
  334. static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
  335. 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);
  336. static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
  337. static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
  338. static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  339. static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  340. static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  341. static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
  342. static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
  343. static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  344. static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  345. static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
  346. static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
  347. static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
  348. static void set_class_enabled(const StringName &p_class, bool p_enable);
  349. static bool is_class_enabled(const StringName &p_class);
  350. static bool is_class_exposed(const StringName &p_class);
  351. static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
  352. static void get_resource_base_extensions(List<String> *p_extensions);
  353. static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
  354. static bool is_resource_extension(const StringName &p_extension);
  355. static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
  356. static StringName get_compatibility_class(const StringName &p_class);
  357. static void set_current_api(APIType p_api);
  358. static APIType get_current_api();
  359. static void cleanup_defaults();
  360. static void cleanup();
  361. static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
  362. static void get_native_struct_list(List<StringName> *r_names);
  363. static String get_native_struct_code(const StringName &p_name);
  364. static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
  365. };
  366. #define BIND_ENUM_CONSTANT(m_constant) \
  367. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
  368. #define BIND_BITFIELD_FLAG(m_constant) \
  369. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true);
  370. #define BIND_CONSTANT(m_constant) \
  371. ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
  372. #ifdef DEBUG_METHODS_ENABLED
  373. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) {
  374. }
  375. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err) {
  376. arr.push_back(p_err);
  377. }
  378. template <class... P>
  379. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err, P... p_args) {
  380. arr.push_back(p_err);
  381. errarray_add_str(arr, p_args...);
  382. }
  383. template <class... P>
  384. _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
  385. Vector<Error> arr;
  386. errarray_add_str(arr, p_args...);
  387. return arr;
  388. }
  389. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
  390. ::ClassDB::set_method_error_return_values(get_class_static(), m_method, errarray(__VA_ARGS__));
  391. #else
  392. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
  393. #endif
  394. #define GDREGISTER_CLASS(m_class) \
  395. if (m_class::_class_is_enabled) { \
  396. ::ClassDB::register_class<m_class>(); \
  397. }
  398. #define GDREGISTER_VIRTUAL_CLASS(m_class) \
  399. if (m_class::_class_is_enabled) { \
  400. ::ClassDB::register_class<m_class>(true); \
  401. }
  402. #define GDREGISTER_ABSTRACT_CLASS(m_class) \
  403. if (m_class::_class_is_enabled) { \
  404. ::ClassDB::register_abstract_class<m_class>(); \
  405. }
  406. #define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
  407. #include "core/disabled_classes.gen.h"
  408. #endif // CLASS_DB_H