summaryrefslogtreecommitdiff
path: root/core/object
diff options
context:
space:
mode:
Diffstat (limited to 'core/object')
-rw-r--r--core/object/script_language.cpp31
-rw-r--r--core/object/script_language.h5
2 files changed, 35 insertions, 1 deletions
diff --git a/core/object/script_language.cpp b/core/object/script_language.cpp
index 66ef418e42..df5486512d 100644
--- a/core/object/script_language.cpp
+++ b/core/object/script_language.cpp
@@ -245,9 +245,12 @@ void ScriptServer::thread_exit() {
}
HashMap<StringName, ScriptServer::GlobalScriptClass> ScriptServer::global_classes;
+HashMap<StringName, Vector<StringName>> ScriptServer::inheriters_cache;
+bool ScriptServer::inheriters_cache_dirty = true;
void ScriptServer::global_classes_clear() {
global_classes.clear();
+ inheriters_cache.clear();
}
void ScriptServer::add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path) {
@@ -257,16 +260,44 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName
g.path = p_path;
g.base = p_base;
global_classes[p_class] = g;
+ inheriters_cache_dirty = true;
}
void ScriptServer::remove_global_class(const StringName &p_class) {
global_classes.erase(p_class);
+ inheriters_cache_dirty = true;
+}
+
+void ScriptServer::get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes) {
+ if (inheriters_cache_dirty) {
+ inheriters_cache.clear();
+ for (const KeyValue<StringName, GlobalScriptClass> &K : global_classes) {
+ if (!inheriters_cache.has(K.value.base)) {
+ inheriters_cache[K.value.base] = Vector<StringName>();
+ }
+ inheriters_cache[K.value.base].push_back(K.key);
+ }
+ for (KeyValue<StringName, Vector<StringName>> &K : inheriters_cache) {
+ K.value.sort_custom<StringName::AlphCompare>();
+ }
+ inheriters_cache_dirty = false;
+ }
+
+ if (!inheriters_cache.has(p_base_type)) {
+ return;
+ }
+
+ const Vector<StringName> &v = inheriters_cache[p_base_type];
+ for (int i = 0; i < v.size(); i++) {
+ r_classes->push_back(v[i]);
+ }
}
void ScriptServer::remove_global_class_by_path(const String &p_path) {
for (const KeyValue<StringName, GlobalScriptClass> &kv : global_classes) {
if (kv.value.path == p_path) {
global_classes.erase(kv.key);
+ inheriters_cache_dirty = true;
return;
}
}
diff --git a/core/object/script_language.h b/core/object/script_language.h
index 02d1880dc2..0c64b079c1 100644
--- a/core/object/script_language.h
+++ b/core/object/script_language.h
@@ -56,10 +56,12 @@ class ScriptServer {
struct GlobalScriptClass {
StringName language;
String path;
- String base;
+ StringName base;
};
static HashMap<StringName, GlobalScriptClass> global_classes;
+ static HashMap<StringName, Vector<StringName>> inheriters_cache;
+ static bool inheriters_cache_dirty;
public:
static ScriptEditRequestFunction edit_request_func;
@@ -87,6 +89,7 @@ public:
static StringName get_global_class_base(const String &p_class);
static StringName get_global_class_native_base(const String &p_class);
static void get_global_class_list(List<StringName> *r_global_classes);
+ static void get_inheriters_list(const StringName &p_base_type, List<StringName> *r_classes);
static void save_global_classes();
static void init_languages();