summaryrefslogtreecommitdiffstats
path: root/core/object/class_db.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/object/class_db.cpp')
-rw-r--r--core/object/class_db.cpp48
1 files changed, 38 insertions, 10 deletions
diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp
index 100cb8e6a2..b757964ee0 100644
--- a/core/object/class_db.cpp
+++ b/core/object/class_db.cpp
@@ -31,6 +31,7 @@
#include "class_db.h"
#include "core/config/engine.h"
+#include "core/io/resource_loader.h"
#include "core/object/script_language.h"
#include "core/os/mutex.h"
#include "core/version.h"
@@ -221,10 +222,11 @@ uint32_t ClassDB::get_api_hash(APIType p_api) {
hash = hash_murmur3_one_64(mb->get_default_argument_count(), hash);
- for (int i = 0; i < mb->get_default_argument_count(); i++) {
- //hash should not change, i hope for tis
- Variant da = mb->get_default_argument(i);
- hash = hash_murmur3_one_64(da.hash(), hash);
+ for (int i = 0; i < mb->get_argument_count(); i++) {
+ if (mb->has_default_argument(i)) {
+ Variant da = mb->get_default_argument(i);
+ hash = hash_murmur3_one_64(da.hash(), hash);
+ }
}
hash = hash_murmur3_one_64(mb->get_hint_flags(), hash);
@@ -347,7 +349,13 @@ Object *ClassDB::instantiate(const StringName &p_class) {
}
#endif
if (ti->gdextension && ti->gdextension->create_instance) {
- return (Object *)ti->gdextension->create_instance(ti->gdextension->class_userdata);
+ Object *obj = (Object *)ti->gdextension->create_instance(ti->gdextension->class_userdata);
+#ifdef TOOLS_ENABLED
+ if (ti->gdextension->track_instance) {
+ ti->gdextension->track_instance(ti->gdextension->tracking_userdata, obj);
+ }
+#endif
+ return obj;
} else {
return ti->creation_func();
}
@@ -377,7 +385,14 @@ bool ClassDB::can_instantiate(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
- ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'.");
+ if (!ti) {
+ if (!ScriptServer::is_global_class(p_class)) {
+ ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'.");
+ }
+ String path = ScriptServer::get_global_class_path(p_class);
+ Ref<Script> scr = ResourceLoader::load(path);
+ return scr.is_valid() && scr->is_valid() && !scr->is_abstract();
+ }
#ifdef TOOLS_ENABLED
if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
return false;
@@ -394,7 +409,9 @@ bool ClassDB::is_virtual(const StringName &p_class) {
if (!ScriptServer::is_global_class(p_class)) {
ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'.");
}
- return false;
+ String path = ScriptServer::get_global_class_path(p_class);
+ Ref<Script> scr = ResourceLoader::load(path);
+ return scr.is_valid() && scr->is_valid() && scr->is_abstract();
}
#ifdef TOOLS_ENABLED
if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) {
@@ -1544,6 +1561,14 @@ bool ClassDB::is_class_exposed(const StringName &p_class) {
return ti->exposed;
}
+bool ClassDB::is_class_reloadable(const StringName &p_class) {
+ OBJTYPE_RLOCK;
+
+ ClassInfo *ti = classes.getptr(p_class);
+ ERR_FAIL_NULL_V_MSG(ti, false, "Cannot get class '" + String(p_class) + "'.");
+ return ti->reloadable;
+}
+
void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
if (resource_base_extensions.has(p_extension)) {
return;
@@ -1682,15 +1707,18 @@ void ClassDB::register_extension_class(ObjectGDExtension *p_extension) {
parent = classes.getptr(parent->name);
}
}
+ c.reloadable = p_extension->reloadable;
classes[p_extension->class_name] = c;
}
-void ClassDB::unregister_extension_class(const StringName &p_class) {
+void ClassDB::unregister_extension_class(const StringName &p_class, bool p_free_method_binds) {
ClassInfo *c = classes.getptr(p_class);
ERR_FAIL_NULL_MSG(c, "Class '" + String(p_class) + "' does not exist.");
- for (KeyValue<StringName, MethodBind *> &F : c->method_map) {
- memdelete(F.value);
+ if (p_free_method_binds) {
+ for (KeyValue<StringName, MethodBind *> &F : c->method_map) {
+ memdelete(F.value);
+ }
}
classes.erase(p_class);
}