class_db.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 reloadable = false;
  115. bool is_virtual = false;
  116. bool is_runtime = false;
  117. Object *(*creation_func)() = nullptr;
  118. ClassInfo() {}
  119. ~ClassInfo() {}
  120. };
  121. template <typename T>
  122. static Object *creator() {
  123. return memnew(T);
  124. }
  125. static RWLock lock;
  126. static HashMap<StringName, ClassInfo> classes;
  127. static HashMap<StringName, StringName> resource_base_extensions;
  128. static HashMap<StringName, StringName> compat_classes;
  129. #ifdef TOOLS_ENABLED
  130. static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
  131. #endif
  132. #ifdef DEBUG_METHODS_ENABLED
  133. 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);
  134. #else
  135. 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);
  136. #endif
  137. static APIType current_api;
  138. static HashMap<APIType, uint32_t> api_hashes_cache;
  139. static void _add_class2(const StringName &p_class, const StringName &p_inherits);
  140. static HashMap<StringName, HashMap<StringName, Variant>> default_values;
  141. static HashSet<StringName> default_values_cached;
  142. // Native structs, used by binder
  143. struct NativeStruct {
  144. 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.
  145. uint64_t struct_size; // local size of struct, for comparison
  146. };
  147. static HashMap<StringName, NativeStruct> native_structs;
  148. private:
  149. // Non-locking variants of get_parent_class and is_parent_class.
  150. static StringName _get_parent_class(const StringName &p_class);
  151. static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
  152. static void _bind_compatibility(ClassInfo *type, MethodBind *p_method);
  153. static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
  154. static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
  155. static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false);
  156. public:
  157. // DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
  158. template <typename T>
  159. static void _add_class() {
  160. _add_class2(T::get_class_static(), T::get_parent_class_static());
  161. }
  162. template <typename T>
  163. static void register_class(bool p_virtual = false) {
  164. GLOBAL_LOCK_FUNCTION;
  165. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  166. T::initialize_class();
  167. ClassInfo *t = classes.getptr(T::get_class_static());
  168. ERR_FAIL_NULL(t);
  169. t->creation_func = &creator<T>;
  170. t->exposed = true;
  171. t->is_virtual = p_virtual;
  172. t->class_ptr = T::get_class_ptr_static();
  173. t->api = current_api;
  174. T::register_custom_data_to_otdb();
  175. }
  176. template <typename T>
  177. static void register_abstract_class() {
  178. GLOBAL_LOCK_FUNCTION;
  179. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  180. T::initialize_class();
  181. ClassInfo *t = classes.getptr(T::get_class_static());
  182. ERR_FAIL_NULL(t);
  183. t->exposed = true;
  184. t->class_ptr = T::get_class_ptr_static();
  185. t->api = current_api;
  186. //nothing
  187. }
  188. template <typename T>
  189. static void register_internal_class() {
  190. GLOBAL_LOCK_FUNCTION;
  191. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  192. T::initialize_class();
  193. ClassInfo *t = classes.getptr(T::get_class_static());
  194. ERR_FAIL_NULL(t);
  195. t->creation_func = &creator<T>;
  196. t->exposed = false;
  197. t->is_virtual = false;
  198. t->class_ptr = T::get_class_ptr_static();
  199. t->api = current_api;
  200. T::register_custom_data_to_otdb();
  201. }
  202. template <typename T>
  203. static void register_runtime_class() {
  204. GLOBAL_LOCK_FUNCTION;
  205. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  206. T::initialize_class();
  207. ClassInfo *t = classes.getptr(T::get_class_static());
  208. ERR_FAIL_NULL(t);
  209. 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()));
  210. t->creation_func = &creator<T>;
  211. t->exposed = true;
  212. t->is_virtual = false;
  213. t->is_runtime = true;
  214. t->class_ptr = T::get_class_ptr_static();
  215. t->api = current_api;
  216. T::register_custom_data_to_otdb();
  217. }
  218. static void register_extension_class(ObjectGDExtension *p_extension);
  219. static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
  220. template <typename T>
  221. static Object *_create_ptr_func() {
  222. return T::create();
  223. }
  224. template <typename T>
  225. static void register_custom_instance_class() {
  226. GLOBAL_LOCK_FUNCTION;
  227. static_assert(std::is_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
  228. T::initialize_class();
  229. ClassInfo *t = classes.getptr(T::get_class_static());
  230. ERR_FAIL_NULL(t);
  231. t->creation_func = &_create_ptr_func<T>;
  232. t->exposed = true;
  233. t->class_ptr = T::get_class_ptr_static();
  234. t->api = current_api;
  235. T::register_custom_data_to_otdb();
  236. }
  237. static void get_class_list(List<StringName> *p_classes);
  238. #ifdef TOOLS_ENABLED
  239. static void get_extensions_class_list(List<StringName> *p_classes);
  240. static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
  241. #endif
  242. static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  243. static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
  244. static StringName get_parent_class_nocheck(const StringName &p_class);
  245. static StringName get_parent_class(const StringName &p_class);
  246. static StringName get_compatibility_remapped_class(const StringName &p_class);
  247. static bool class_exists(const StringName &p_class);
  248. static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
  249. static bool can_instantiate(const StringName &p_class);
  250. static bool is_virtual(const StringName &p_class);
  251. static Object *instantiate(const StringName &p_class);
  252. static Object *instantiate_no_placeholders(const StringName &p_class);
  253. static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
  254. static APIType get_api_type(const StringName &p_class);
  255. static uint32_t get_api_hash(APIType p_api);
  256. template <typename>
  257. struct member_function_traits;
  258. template <typename R, typename T, typename... Args>
  259. struct member_function_traits<R (T::*)(Args...)> {
  260. using return_type = R;
  261. };
  262. template <typename R, typename T, typename... Args>
  263. struct member_function_traits<R (T::*)(Args...) const> {
  264. using return_type = R;
  265. };
  266. template <typename R, typename... Args>
  267. struct member_function_traits<R (*)(Args...)> {
  268. using return_type = R;
  269. };
  270. template <typename N, typename M, typename... VarArgs>
  271. static MethodBind *bind_method(N p_method_name, M p_method, VarArgs... p_args) {
  272. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  273. const Variant *argptrs[sizeof...(p_args) + 1];
  274. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  275. argptrs[i] = &args[i];
  276. }
  277. MethodBind *bind = create_method_bind(p_method);
  278. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  279. bind->set_return_type_is_raw_object_ptr(true);
  280. }
  281. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  282. }
  283. template <typename N, typename M, typename... VarArgs>
  284. static MethodBind *bind_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  285. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  286. const Variant *argptrs[sizeof...(p_args) + 1];
  287. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  288. argptrs[i] = &args[i];
  289. }
  290. MethodBind *bind = create_static_method_bind(p_method);
  291. bind->set_instance_class(p_class);
  292. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  293. bind->set_return_type_is_raw_object_ptr(true);
  294. }
  295. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, false, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  296. }
  297. template <typename N, typename M, typename... VarArgs>
  298. static MethodBind *bind_compatibility_method(N p_method_name, M p_method, VarArgs... p_args) {
  299. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  300. const Variant *argptrs[sizeof...(p_args) + 1];
  301. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  302. argptrs[i] = &args[i];
  303. }
  304. MethodBind *bind = create_method_bind(p_method);
  305. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  306. bind->set_return_type_is_raw_object_ptr(true);
  307. }
  308. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  309. }
  310. template <typename N, typename M, typename... VarArgs>
  311. static MethodBind *bind_compatibility_static_method(const StringName &p_class, N p_method_name, M p_method, VarArgs... p_args) {
  312. Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
  313. const Variant *argptrs[sizeof...(p_args) + 1];
  314. for (uint32_t i = 0; i < sizeof...(p_args); i++) {
  315. argptrs[i] = &args[i];
  316. }
  317. MethodBind *bind = create_static_method_bind(p_method);
  318. bind->set_instance_class(p_class);
  319. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  320. bind->set_return_type_is_raw_object_ptr(true);
  321. }
  322. return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, true, p_method_name, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args));
  323. }
  324. template <typename M>
  325. 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) {
  326. GLOBAL_LOCK_FUNCTION;
  327. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  328. ERR_FAIL_NULL_V(bind, nullptr);
  329. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  330. bind->set_return_type_is_raw_object_ptr(true);
  331. }
  332. return _bind_vararg_method(bind, p_name, p_default_args, false);
  333. }
  334. template <typename M>
  335. 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) {
  336. GLOBAL_LOCK_FUNCTION;
  337. MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
  338. ERR_FAIL_NULL_V(bind, nullptr);
  339. if constexpr (std::is_same_v<typename member_function_traits<M>::return_type, Object *>) {
  340. bind->set_return_type_is_raw_object_ptr(true);
  341. }
  342. return _bind_vararg_method(bind, p_name, p_default_args, true);
  343. }
  344. static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
  345. static void bind_compatibility_method_custom(const StringName &p_class, MethodBind *p_method);
  346. static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
  347. static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
  348. static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
  349. static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
  350. static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  351. static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "", int p_indent_depth = 0);
  352. 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);
  353. static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
  354. static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
  355. static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
  356. static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
  357. static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
  358. 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);
  359. static void get_linked_properties_info(const StringName &p_class, const StringName &p_property, List<StringName> *r_properties, bool p_no_inheritance = false);
  360. static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
  361. static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
  362. static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
  363. static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  364. static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
  365. static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
  366. static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
  367. static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
  368. static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
  369. static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
  370. 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);
  371. 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);
  372. static int get_method_argument_count(const StringName &p_class, const StringName &p_method, bool *r_is_valid = nullptr, bool p_no_inheritance = false);
  373. static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
  374. 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);
  375. static Vector<uint32_t> get_method_compatibility_hashes(const StringName &p_class, const StringName &p_name);
  376. 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);
  377. static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
  378. static void add_extension_class_virtual_method(const StringName &p_class, const GDExtensionClassVirtualMethodInfo *p_method_info);
  379. 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);
  380. static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
  381. static int64_t get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
  382. static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  383. static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  384. static StringName get_integer_constant_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  385. static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
  386. static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
  387. static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  388. static bool is_enum_bitfield(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
  389. static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
  390. static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
  391. static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
  392. static void set_class_enabled(const StringName &p_class, bool p_enable);
  393. static bool is_class_enabled(const StringName &p_class);
  394. static bool is_class_exposed(const StringName &p_class);
  395. static bool is_class_reloadable(const StringName &p_class);
  396. static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
  397. static void get_resource_base_extensions(List<String> *p_extensions);
  398. static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
  399. static bool is_resource_extension(const StringName &p_extension);
  400. static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
  401. static StringName get_compatibility_class(const StringName &p_class);
  402. static void set_current_api(APIType p_api);
  403. static APIType get_current_api();
  404. static void cleanup_defaults();
  405. static void cleanup();
  406. static void register_native_struct(const StringName &p_name, const String &p_code, uint64_t p_current_size);
  407. static void get_native_struct_list(List<StringName> *r_names);
  408. static String get_native_struct_code(const StringName &p_name);
  409. static uint64_t get_native_struct_size(const StringName &p_name); // Used for asserting
  410. };
  411. #define BIND_ENUM_CONSTANT(m_constant) \
  412. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
  413. #define BIND_BITFIELD_FLAG(m_constant) \
  414. ::ClassDB::bind_integer_constant(get_class_static(), __constant_get_bitfield_name(m_constant, #m_constant), #m_constant, m_constant, true);
  415. #define BIND_CONSTANT(m_constant) \
  416. ::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
  417. #ifdef DEBUG_METHODS_ENABLED
  418. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) {
  419. }
  420. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err) {
  421. arr.push_back(p_err);
  422. }
  423. template <typename... P>
  424. _FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err, P... p_args) {
  425. arr.push_back(p_err);
  426. errarray_add_str(arr, p_args...);
  427. }
  428. template <typename... P>
  429. _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
  430. Vector<Error> arr;
  431. errarray_add_str(arr, p_args...);
  432. return arr;
  433. }
  434. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
  435. ::ClassDB::set_method_error_return_values(get_class_static(), m_method, errarray(__VA_ARGS__));
  436. #else
  437. #define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
  438. #endif
  439. #define GDREGISTER_CLASS(m_class) \
  440. if (m_class::_class_is_enabled) { \
  441. ::ClassDB::register_class<m_class>(); \
  442. }
  443. #define GDREGISTER_VIRTUAL_CLASS(m_class) \
  444. if (m_class::_class_is_enabled) { \
  445. ::ClassDB::register_class<m_class>(true); \
  446. }
  447. #define GDREGISTER_ABSTRACT_CLASS(m_class) \
  448. if (m_class::_class_is_enabled) { \
  449. ::ClassDB::register_abstract_class<m_class>(); \
  450. }
  451. #define GDREGISTER_INTERNAL_CLASS(m_class) \
  452. if (m_class::_class_is_enabled) { \
  453. ::ClassDB::register_internal_class<m_class>(); \
  454. }
  455. #define GDREGISTER_RUNTIME_CLASS(m_class) \
  456. if (m_class::_class_is_enabled) { \
  457. ::ClassDB::register_runtime_class<m_class>(); \
  458. }
  459. #define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
  460. #include "core/disabled_classes.gen.h"
  461. #endif // CLASS_DB_H