virtualx-engine/core/object/class_db.h

447 lines
21 KiB
C++
Raw Normal View History

2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* class_db.h */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
2014-02-10 02:10:30 +01:00
/*************************************************************************/
/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */
2014-02-10 02:10:30 +01:00
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#ifndef CLASS_DB_H
#define CLASS_DB_H
2014-02-10 02:10:30 +01:00
#include "core/object/method_bind.h"
#include "core/object/object.h"
#include "core/string/print_string.h"
/** To bind more then 6 parameters include this:
*
*/
// Makes callable_mp readily available in all classes connecting signals.
// Needs to come after method_bind and object have been included.
#include "core/object/callable_method_pointer.h"
2014-02-10 02:10:30 +01:00
#define DEFVAL(m_defval) (m_defval)
2014-02-10 02:10:30 +01:00
struct MethodDefinition {
StringName name;
Vector<StringName> args;
2016-03-09 00:00:52 +01:00
MethodDefinition() {}
MethodDefinition(const char *p_name) :
name(p_name) {}
MethodDefinition(const StringName &p_name) :
name(p_name) {}
2014-02-10 02:10:30 +01:00
};
MethodDefinition D_METHOD(const char *p_name);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10);
2017-10-20 00:24:49 +02:00
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12);
MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13);
2014-02-10 02:10:30 +01:00
class ClassDB {
public:
enum APIType {
API_CORE,
API_EDITOR,
API_EXTENSION,
API_EDITOR_EXTENSION,
API_NONE
};
public:
2014-02-10 02:10:30 +01:00
struct PropertySetGet {
int index;
StringName setter;
StringName getter;
MethodBind *_setptr;
MethodBind *_getptr;
Variant::Type type;
2014-02-10 02:10:30 +01:00
};
struct ClassInfo {
APIType api = API_NONE;
ClassInfo *inherits_ptr = nullptr;
void *class_ptr = nullptr;
ObjectNativeExtension *native_extension = nullptr;
HashMap<StringName, MethodBind *> method_map;
HashMap<StringName, int> constant_map;
HashMap<StringName, List<StringName>> enum_map;
HashMap<StringName, MethodInfo> signal_map;
2014-02-10 02:10:30 +01:00
List<PropertyInfo> property_list;
HashMap<StringName, PropertyInfo> property_map;
2014-02-10 02:10:30 +01:00
#ifdef DEBUG_METHODS_ENABLED
List<StringName> constant_order;
List<StringName> method_order;
Set<StringName> methods_in_properties;
2014-02-10 02:10:30 +01:00
List<MethodInfo> virtual_methods;
Map<StringName, MethodInfo> virtual_methods_map;
2014-02-10 02:10:30 +01:00
StringName category;
Map<StringName, Vector<Error>> method_error_values;
2014-02-10 02:10:30 +01:00
#endif
HashMap<StringName, PropertySetGet> property_setget;
2014-02-10 02:10:30 +01:00
StringName inherits;
StringName name;
bool disabled = false;
bool exposed = false;
Object *(*creation_func)() = nullptr;
ClassInfo() {}
~ClassInfo() {}
2014-02-10 02:10:30 +01:00
};
2016-03-09 00:00:52 +01:00
template <class T>
2014-02-10 02:10:30 +01:00
static Object *creator() {
return memnew(T);
2014-02-10 02:10:30 +01:00
}
2016-03-09 00:00:52 +01:00
static RWLock lock;
static HashMap<StringName, ClassInfo> classes;
static HashMap<StringName, StringName> resource_base_extensions;
static HashMap<StringName, StringName> compat_classes;
2014-02-10 02:10:30 +01:00
static MethodBind *bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount);
2014-02-10 02:10:30 +01:00
static APIType current_api;
2014-02-10 02:10:30 +01:00
static void _add_class2(const StringName &p_class, const StringName &p_inherits);
2016-03-09 00:00:52 +01:00
static HashMap<StringName, HashMap<StringName, Variant>> default_values;
static Set<StringName> default_values_cached;
private:
// Non-locking variants of get_parent_class and is_parent_class.
static StringName _get_parent_class(const StringName &p_class);
static bool _is_parent_class(const StringName &p_class, const StringName &p_inherits);
public:
2014-02-10 02:10:30 +01:00
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
static void _add_class() {
_add_class2(T::get_class_static(), T::get_parent_class_static());
2014-02-10 02:10:30 +01:00
}
template <class T>
static void register_class() {
2014-02-10 02:10:30 +01:00
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
2014-02-10 02:10:30 +01:00
ERR_FAIL_COND(!t);
t->creation_func = &creator<T>;
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
Fix ClassDB API type mismatch bug between --editor and player There are two ways a class can be added to ClassDB: - `A`: When an instance of the class is created for the first time. When this happends the class is not registered/exposed to scripts. - `B`: When calling `GDREGISTER_CLASS(ClassName)` or similar. When this happens the class is registered/exposed to scripts. ClassDB has an API type property to differentiate between the core and editor APIs. Up until now the API type was determined whenever the class is added to ClassDB (either `A` or `B`). The problem comes when a class is instantiated (`A`) before being registered (`B`). If at this point the current defined API is not the same as when the class is later registered, this will result in a mismatch between `--editor` and non-editor apps. This is specially bad for C# as it makes the editor player abort. This was happening with `EditorPaths` which, while being registered during the editor API classes registrations, it was also being instantiated earlier when running the editor or the project manager, via a call to `EditorPaths::create()`. This regression was introduced in 1074017f043ec9155b12ea97cd00cf11361ccdf0. This commit fixes this simply by re-assigning the class API type when the class is registered (`B`). This is correct because API type describes registered/exposed classes. It shouldn't cause any regressions as the API type should not be accessed of classes that are not (or not yet) registered/exposed. Code locations for reference: - Method to add a class to ClassDB: `ClassDB::_add_class2` - Code that adds classes to ClassDB post first initialization (`A`): `memnew` macros -> `Object::_postinitialize` -> `Object::initialize_class` -> `ClassDB::_add_class2`. - Code adds class to ClassDB and registers/exposes it to scripts: `GDREGISTER_CLASS` macros -> `ClassDB::register_class<T>` -> `Object::initialize_class` -> `ClassDB::_add_class2`.
2021-08-31 21:45:21 +02:00
t->api = current_api;
2014-02-10 02:10:30 +01:00
T::register_custom_data_to_otdb();
}
template <class T>
static void register_virtual_class() {
2014-02-10 02:10:30 +01:00
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
Fix ClassDB API type mismatch bug between --editor and player There are two ways a class can be added to ClassDB: - `A`: When an instance of the class is created for the first time. When this happends the class is not registered/exposed to scripts. - `B`: When calling `GDREGISTER_CLASS(ClassName)` or similar. When this happens the class is registered/exposed to scripts. ClassDB has an API type property to differentiate between the core and editor APIs. Up until now the API type was determined whenever the class is added to ClassDB (either `A` or `B`). The problem comes when a class is instantiated (`A`) before being registered (`B`). If at this point the current defined API is not the same as when the class is later registered, this will result in a mismatch between `--editor` and non-editor apps. This is specially bad for C# as it makes the editor player abort. This was happening with `EditorPaths` which, while being registered during the editor API classes registrations, it was also being instantiated earlier when running the editor or the project manager, via a call to `EditorPaths::create()`. This regression was introduced in 1074017f043ec9155b12ea97cd00cf11361ccdf0. This commit fixes this simply by re-assigning the class API type when the class is registered (`B`). This is correct because API type describes registered/exposed classes. It shouldn't cause any regressions as the API type should not be accessed of classes that are not (or not yet) registered/exposed. Code locations for reference: - Method to add a class to ClassDB: `ClassDB::_add_class2` - Code that adds classes to ClassDB post first initialization (`A`): `memnew` macros -> `Object::_postinitialize` -> `Object::initialize_class` -> `ClassDB::_add_class2`. - Code adds class to ClassDB and registers/exposes it to scripts: `GDREGISTER_CLASS` macros -> `ClassDB::register_class<T>` -> `Object::initialize_class` -> `ClassDB::_add_class2`.
2021-08-31 21:45:21 +02:00
t->api = current_api;
2014-02-10 02:10:30 +01:00
//nothing
}
static void register_extension_class(ObjectNativeExtension *p_extension);
static void unregister_extension_class(const StringName &p_class);
template <class T>
static Object *_create_ptr_func() {
return T::create();
}
template <class T>
static void register_custom_instance_class() {
GLOBAL_LOCK_FUNCTION;
T::initialize_class();
ClassInfo *t = classes.getptr(T::get_class_static());
ERR_FAIL_COND(!t);
t->creation_func = &_create_ptr_func<T>;
t->exposed = true;
t->class_ptr = T::get_class_ptr_static();
Fix ClassDB API type mismatch bug between --editor and player There are two ways a class can be added to ClassDB: - `A`: When an instance of the class is created for the first time. When this happends the class is not registered/exposed to scripts. - `B`: When calling `GDREGISTER_CLASS(ClassName)` or similar. When this happens the class is registered/exposed to scripts. ClassDB has an API type property to differentiate between the core and editor APIs. Up until now the API type was determined whenever the class is added to ClassDB (either `A` or `B`). The problem comes when a class is instantiated (`A`) before being registered (`B`). If at this point the current defined API is not the same as when the class is later registered, this will result in a mismatch between `--editor` and non-editor apps. This is specially bad for C# as it makes the editor player abort. This was happening with `EditorPaths` which, while being registered during the editor API classes registrations, it was also being instantiated earlier when running the editor or the project manager, via a call to `EditorPaths::create()`. This regression was introduced in 1074017f043ec9155b12ea97cd00cf11361ccdf0. This commit fixes this simply by re-assigning the class API type when the class is registered (`B`). This is correct because API type describes registered/exposed classes. It shouldn't cause any regressions as the API type should not be accessed of classes that are not (or not yet) registered/exposed. Code locations for reference: - Method to add a class to ClassDB: `ClassDB::_add_class2` - Code that adds classes to ClassDB post first initialization (`A`): `memnew` macros -> `Object::_postinitialize` -> `Object::initialize_class` -> `ClassDB::_add_class2`. - Code adds class to ClassDB and registers/exposes it to scripts: `GDREGISTER_CLASS` macros -> `ClassDB::register_class<T>` -> `Object::initialize_class` -> `ClassDB::_add_class2`.
2021-08-31 21:45:21 +02:00
t->api = current_api;
T::register_custom_data_to_otdb();
}
static void get_class_list(List<StringName> *p_classes);
static void get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static void get_direct_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes);
static StringName get_parent_class_nocheck(const StringName &p_class);
static StringName get_parent_class(const StringName &p_class);
2019-10-03 22:39:08 +02:00
static StringName get_compatibility_remapped_class(const StringName &p_class);
static bool class_exists(const StringName &p_class);
static bool is_parent_class(const StringName &p_class, const StringName &p_inherits);
static bool can_instantiate(const StringName &p_class);
static Object *instantiate(const StringName &p_class);
static void set_object_extension_instance(Object *p_object, const StringName &p_class, GDExtensionClassInstancePtr p_instance);
static APIType get_api_type(const StringName &p_class);
static uint64_t get_api_hash(APIType p_api);
2014-02-10 02:10:30 +01:00
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
2020-04-02 01:20:12 +02:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, nullptr, 0); //use static function, much smaller binary usage
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[1] = { &p_def1 };
2014-02-10 02:10:30 +01:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 1);
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[2] = { &p_def1, &p_def2 };
2014-02-10 02:10:30 +01:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 2);
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[3] = { &p_def1, &p_def2, &p_def3 };
2014-02-10 02:10:30 +01:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 3);
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[4] = { &p_def1, &p_def2, &p_def3, &p_def4 };
2014-02-10 02:10:30 +01:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 4);
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5) {
2014-02-10 02:10:30 +01:00
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[5] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5 };
2014-02-10 02:10:30 +01:00
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 5);
2014-02-10 02:10:30 +01:00
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[6] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 6);
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[7] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 7);
}
template <class N, class M>
static MethodBind *bind_method(N p_method_name, M p_method, const Variant &p_def1, const Variant &p_def2, const Variant &p_def3, const Variant &p_def4, const Variant &p_def5, const Variant &p_def6, const Variant &p_def7, const Variant &p_def8) {
MethodBind *bind = create_method_bind(p_method);
const Variant *ptr[8] = { &p_def1, &p_def2, &p_def3, &p_def4, &p_def5, &p_def6, &p_def7, &p_def8 };
return bind_methodfi(METHOD_FLAGS_DEFAULT, bind, p_method_name, ptr, 8);
}
template <class M>
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) {
2014-02-10 02:10:30 +01:00
GLOBAL_LOCK_FUNCTION;
MethodBind *bind = create_vararg_method_bind(p_method, p_info, p_return_nil_is_variant);
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V(!bind, nullptr);
2014-02-10 02:10:30 +01:00
bind->set_name(p_name);
bind->set_default_arguments(p_default_args);
String instance_type = bind->get_instance_class();
2014-02-10 02:10:30 +01:00
ClassInfo *type = classes.getptr(instance_type);
2014-02-10 02:10:30 +01:00
if (!type) {
memdelete(bind);
2020-04-02 01:20:12 +02:00
ERR_FAIL_COND_V(!type, nullptr);
2014-02-10 02:10:30 +01:00
}
if (type->method_map.has(p_name)) {
memdelete(bind);
// Overloading not supported
2020-04-02 01:20:12 +02:00
ERR_FAIL_V_MSG(nullptr, "Method already bound: " + instance_type + "::" + p_name + ".");
2014-02-10 02:10:30 +01:00
}
type->method_map[p_name] = bind;
2014-02-10 02:10:30 +01:00
#ifdef DEBUG_METHODS_ENABLED
// FIXME: <reduz> set_return_type is no longer in MethodBind, so I guess it should be moved to vararg method bind
//bind->set_return_type("Variant");
2014-02-10 02:10:30 +01:00
type->method_order.push_back(p_name);
#endif
return bind;
}
static void bind_method_custom(const StringName &p_class, MethodBind *p_method);
static void add_signal(const StringName &p_class, const MethodInfo &p_signal);
static bool has_signal(const StringName &p_class, const StringName &p_signal, bool p_no_inheritance = false);
static bool get_signal(const StringName &p_class, const StringName &p_signal, MethodInfo *r_signal);
static void get_signal_list(const StringName &p_class, List<MethodInfo> *p_signals, bool p_no_inheritance = false);
static void add_property_group(const StringName &p_class, const String &p_name, const String &p_prefix = "");
static void add_property_subgroup(const StringName &p_class, const String &p_name, const String &p_prefix = "");
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);
static void add_property_array(const StringName &p_class, const StringName &p_path, const String &p_array_element_prefix);
static void add_property(const StringName &p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index = -1);
static void set_property_default_value(const StringName &p_class, const StringName &p_name, const Variant &p_default);
static void add_linked_property(const StringName &p_class, const String &p_property, const String &p_linked_property);
static void get_property_list(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance = false, const Object *p_validator = nullptr);
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);
2020-04-02 01:20:12 +02:00
static bool set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid = nullptr);
static bool get_property(Object *p_object, const StringName &p_property, Variant &r_value);
static bool has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance = false);
2020-04-02 01:20:12 +02:00
static int get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
static Variant::Type get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid = nullptr);
static StringName get_property_setter(const StringName &p_class, const StringName &p_property);
static StringName get_property_getter(const StringName &p_class, const StringName &p_property);
static bool has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance = false);
static void set_method_flags(const StringName &p_class, const StringName &p_method, int p_flags);
static void get_method_list(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false, bool p_exclude_from_properties = false);
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);
static MethodBind *get_method(const StringName &p_class, const StringName &p_name);
2014-02-10 02:10:30 +01:00
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);
static void get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance = false);
2016-03-09 00:00:52 +01:00
static void bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant);
static void get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance = false);
2020-04-02 01:20:12 +02:00
static int get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success = nullptr);
static bool has_integer_constant(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static StringName get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static void get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance = false);
static void get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance = false);
static bool has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance = false);
static void set_method_error_return_values(const StringName &p_class, const StringName &p_method, const Vector<Error> &p_values);
static Vector<Error> get_method_error_return_values(const StringName &p_class, const StringName &p_method);
2020-04-02 01:20:12 +02:00
static Variant class_get_default_property_value(const StringName &p_class, const StringName &p_property, bool *r_valid = nullptr);
static StringName get_category(const StringName &p_node);
static void set_class_enabled(const StringName &p_class, bool p_enable);
static bool is_class_enabled(const StringName &p_class);
2014-02-10 02:10:30 +01:00
static bool is_class_exposed(const StringName &p_class);
static void add_resource_base_extension(const StringName &p_extension, const StringName &p_class);
2014-02-10 02:10:30 +01:00
static void get_resource_base_extensions(List<String> *p_extensions);
static void get_extensions_for_type(const StringName &p_class, List<String> *p_extensions);
static bool is_resource_extension(const StringName &p_extension);
2014-02-10 02:10:30 +01:00
static void add_compatibility_class(const StringName &p_class, const StringName &p_fallback);
static void set_current_api(APIType p_api);
static APIType get_current_api();
static void cleanup_defaults();
2014-02-10 02:10:30 +01:00
static void cleanup();
};
#ifdef DEBUG_METHODS_ENABLED
#define BIND_CONSTANT(m_constant) \
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#define BIND_ENUM_CONSTANT(m_constant) \
::ClassDB::bind_integer_constant(get_class_static(), __constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant);
_FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr) {
}
_FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err) {
arr.push_back(p_err);
}
template <class... P>
_FORCE_INLINE_ void errarray_add_str(Vector<Error> &arr, const Error &p_err, P... p_args) {
arr.push_back(p_err);
errarray_add_str(arr, p_args...);
}
template <class... P>
_FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
Vector<Error> arr;
errarray_add_str(arr, p_args...);
return arr;
}
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...) \
::ClassDB::set_method_error_return_values(get_class_static(), m_method, errarray(__VA_ARGS__));
#else
#define BIND_CONSTANT(m_constant) \
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#define BIND_ENUM_CONSTANT(m_constant) \
::ClassDB::bind_integer_constant(get_class_static(), StringName(), #m_constant, m_constant);
#define BIND_METHOD_ERR_RETURN_DOC(m_method, ...)
#endif
2014-02-10 02:10:30 +01:00
#define GDREGISTER_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
::ClassDB::register_class<m_class>(); \
}
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
::ClassDB::register_virtual_class<m_class>(); \
}
#include "core/disabled_classes.gen.h"
#endif // CLASS_DB_H