class_db.h 24 KB

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