summaryrefslogtreecommitdiffstats
path: root/core/object/class_db.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/class_db.h')
-rw-r--r--core/object/class_db.h31
1 files changed, 31 insertions, 0 deletions
diff --git a/core/object/class_db.h b/core/object/class_db.h
index c910b30d11..7f117b4a9b 100644
--- a/core/object/class_db.h
+++ b/core/object/class_db.h
@@ -133,6 +133,7 @@ public:
bool exposed = false;
bool reloadable = false;
bool is_virtual = false;
+ bool is_runtime = false;
Object *(*creation_func)() = nullptr;
ClassInfo() {}
@@ -149,6 +150,10 @@ public:
static HashMap<StringName, StringName> resource_base_extensions;
static HashMap<StringName, StringName> compat_classes;
+#ifdef TOOLS_ENABLED
+ static HashMap<StringName, ObjectGDExtension> placeholder_extensions;
+#endif
+
#ifdef DEBUG_METHODS_ENABLED
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);
#else
@@ -178,6 +183,8 @@ private:
static MethodBind *_bind_vararg_method(MethodBind *p_bind, const StringName &p_name, const Vector<Variant> &p_default_args, bool p_compatibility);
static void _bind_method_custom(const StringName &p_class, MethodBind *p_method, bool p_compatibility);
+ static Object *_instantiate_internal(const StringName &p_class, bool p_require_real_class = false);
+
public:
// DO NOT USE THIS!!!!!! NEEDS TO BE PUBLIC BUT DO NOT USE NO MATTER WHAT!!!
template <class T>
@@ -228,6 +235,23 @@ public:
T::register_custom_data_to_otdb();
}
+ template <class T>
+ static void register_runtime_class() {
+ GLOBAL_LOCK_FUNCTION;
+ static_assert(types_are_same_v<typename T::self_type, T>, "Class not declared properly, please use GDCLASS.");
+ T::initialize_class();
+ ClassInfo *t = classes.getptr(T::get_class_static());
+ ERR_FAIL_NULL(t);
+ 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()));
+ t->creation_func = &creator<T>;
+ t->exposed = true;
+ t->is_virtual = false;
+ t->is_runtime = true;
+ t->class_ptr = T::get_class_ptr_static();
+ t->api = current_api;
+ T::register_custom_data_to_otdb();
+ }
+
static void register_extension_class(ObjectGDExtension *p_extension);
static void unregister_extension_class(const StringName &p_class, bool p_free_method_binds = true);
@@ -253,6 +277,7 @@ public:
static void get_class_list(List<StringName> *p_classes);
#ifdef TOOLS_ENABLED
static void get_extensions_class_list(List<StringName> *p_classes);
+ static ObjectGDExtension *get_placeholder_extension(const StringName &p_class);
#endif
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);
@@ -264,6 +289,7 @@ public:
static bool can_instantiate(const StringName &p_class);
static bool is_virtual(const StringName &p_class);
static Object *instantiate(const StringName &p_class);
+ static Object *instantiate_no_placeholders(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);
@@ -510,6 +536,11 @@ _FORCE_INLINE_ Vector<Error> errarray(P... p_args) {
::ClassDB::register_internal_class<m_class>(); \
}
+#define GDREGISTER_RUNTIME_CLASS(m_class) \
+ if (m_class::_class_is_enabled) { \
+ ::ClassDB::register_runtime_class<m_class>(); \
+ }
+
#define GDREGISTER_NATIVE_STRUCT(m_class, m_code) ClassDB::register_native_struct(#m_class, m_code, sizeof(m_class))
#include "core/disabled_classes.gen.h"