Skip to content

Commit

Permalink
Include more attributes in the global class names cache
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Jan 8, 2025
1 parent 914536c commit a33588f
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 125 deletions.
4 changes: 2 additions & 2 deletions core/config/project_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1222,10 +1222,10 @@ void ProjectSettings::refresh_global_class_list() {
Array script_classes = get_global_class_list();
for (int i = 0; i < script_classes.size(); i++) {
Dictionary c = script_classes[i];
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
continue;
}
ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"]);
ScriptServer::add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
}
}

Expand Down
26 changes: 21 additions & 5 deletions core/object/script_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,10 @@ void ScriptServer::init_languages() {

for (const Variant &script_class : script_classes) {
Dictionary c = script_class;
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
continue;
}
add_global_class(c["class"], c["base"], c["language"], c["path"]);
add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
}
ProjectSettings::get_singleton()->clear("_global_script_classes");
}
Expand All @@ -281,10 +281,10 @@ void ScriptServer::init_languages() {
Array script_classes = ProjectSettings::get_singleton()->get_global_class_list();
for (const Variant &script_class : script_classes) {
Dictionary c = script_class;
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base")) {
if (!c.has("class") || !c.has("language") || !c.has("path") || !c.has("base") || !c.has("is_abstract") || !c.has("is_tool")) {
continue;
}
add_global_class(c["class"], c["base"], c["language"], c["path"]);
add_global_class(c["class"], c["base"], c["language"], c["path"], c["is_abstract"], c["is_tool"]);
}
}

Expand Down Expand Up @@ -390,7 +390,7 @@ void ScriptServer::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) {
void ScriptServer::add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path, bool p_is_abstract, bool p_is_tool) {
ERR_FAIL_COND_MSG(p_class == p_base || (global_classes.has(p_base) && get_global_class_native_base(p_base) == p_class), "Cyclic inheritance in script class.");
GlobalScriptClass *existing = global_classes.getptr(p_class);
if (existing) {
Expand All @@ -399,6 +399,8 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName
existing->base = p_base;
existing->path = p_path;
existing->language = p_language;
existing->is_abstract = p_is_abstract;
existing->is_tool = p_is_tool;
inheriters_cache_dirty = true;
}
} else {
Expand All @@ -407,6 +409,8 @@ void ScriptServer::add_global_class(const StringName &p_class, const StringName
g.language = p_language;
g.path = p_path;
g.base = p_base;
g.is_abstract = p_is_abstract;
g.is_tool = p_is_tool;
global_classes[p_class] = g;
inheriters_cache_dirty = true;
}
Expand Down Expand Up @@ -480,6 +484,16 @@ StringName ScriptServer::get_global_class_native_base(const String &p_class) {
return base;
}

bool ScriptServer::is_global_class_abstract(const String &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), false);
return global_classes[p_class].is_abstract;
}

bool ScriptServer::is_global_class_tool(const String &p_class) {
ERR_FAIL_COND_V(!global_classes.has(p_class), false);
return global_classes[p_class].is_tool;
}

void ScriptServer::get_global_class_list(List<StringName> *r_global_classes) {
List<StringName> classes;
for (const KeyValue<StringName, GlobalScriptClass> &E : global_classes) {
Expand Down Expand Up @@ -513,6 +527,8 @@ void ScriptServer::save_global_classes() {
d["path"] = global_classes[E].path;
d["base"] = global_classes[E].base;
d["icon"] = class_icons.get(E, "");
d["is_abstract"] = global_classes[E].is_abstract;
d["is_tool"] = global_classes[E].is_tool;
gcarr.push_back(d);
}
ProjectSettings::get_singleton()->store_global_class_list(gcarr);
Expand Down
8 changes: 6 additions & 2 deletions core/object/script_language.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class ScriptServer {
StringName language;
String path;
StringName base;
bool is_abstract = false;
bool is_tool = false;
};

static HashMap<StringName, GlobalScriptClass> global_classes;
Expand All @@ -86,14 +88,16 @@ class ScriptServer {
static void thread_exit();

static void global_classes_clear();
static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path);
static void add_global_class(const StringName &p_class, const StringName &p_base, const StringName &p_language, const String &p_path, bool p_is_abstract, bool p_is_tool);
static void remove_global_class(const StringName &p_class);
static void remove_global_class_by_path(const String &p_path);
static bool is_global_class(const StringName &p_class);
static StringName get_global_class_language(const StringName &p_class);
static String get_global_class_path(const String &p_class);
static StringName get_global_class_base(const String &p_class);
static StringName get_global_class_native_base(const String &p_class);
static bool is_global_class_abstract(const String &p_class);
static bool is_global_class_tool(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();
Expand Down Expand Up @@ -443,7 +447,7 @@ class ScriptLanguage : public Object {
virtual void frame();

virtual bool handles_global_class_type(const String &p_type) const { return false; }
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const { return String(); }
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr, bool *r_is_abstract, bool *r_is_tool = nullptr) const { return String(); }

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with clang sanitizers (target=editor, tests=yes, dev_build=yes, use_asan=yes, use_ubsan=yes, use_llvm=yes, linker=lld)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Editor (target=editor)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Editor (target=editor, tests=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with ThreadSanitizer (target=editor, tests=yes, dev_build=yes, use_tsan=yes, use_llvm=yes, linker=lld)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'ScriptLanguage::get_global_class_name': missing default argument for parameter 4

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'ScriptLanguage::get_global_class_name': missing default argument for parameter 4

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor w/ clang-cl (target=editor, tests=yes, use_llvm=yes)

missing default argument on parameter 'r_is_abstract'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'ScriptLanguage::get_global_class_name': missing default argument for parameter 4

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'ScriptLanguage::get_global_class_name': missing default argument for parameter 4

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

'ScriptLanguage::get_global_class_name': missing default argument for parameter 4

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor with doubles and GCC sanitizers (target=editor, tests=yes, dev_build=yes, scu_build=yes, precision=double, use_asan=yes, use_ubsan=yes, linker=gold)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

Check failure on line 450 in core/object/script_language.h

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Editor w/ Mono (target=editor)

default argument missing for parameter 4 of 'virtual String ScriptLanguage::get_global_class_name(const String&, String*, String*, bool*, bool*) const'

virtual ~ScriptLanguage() {}
};
Expand Down
8 changes: 7 additions & 1 deletion core/object/script_language_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ class ScriptLanguageExtension : public ScriptLanguage {

GDVIRTUAL1RC_REQUIRED(Dictionary, _get_global_class_name, const String &)

virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override {
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr, bool *r_is_abstract, bool *r_is_tool = nullptr) const override {
Dictionary ret;
GDVIRTUAL_CALL(_get_global_class_name, p_path, ret);
if (!ret.has("name")) {
Expand All @@ -684,6 +684,12 @@ class ScriptLanguageExtension : public ScriptLanguage {
if (r_icon_path != nullptr && ret.has("icon_path")) {
*r_icon_path = ret["icon_path"];
}
if (r_is_abstract != nullptr && ret.has("is_abstract")) {
*r_is_abstract = ret["is_abstract"];
}
if (r_is_tool != nullptr && ret.has("is_tool")) {
*r_is_tool = ret["is_tool"];
}
return ret["name"];
}
};
Expand Down
8 changes: 2 additions & 6 deletions editor/create_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,10 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN
r_item->set_metadata(0, p_type);
r_item->set_text(0, p_type);

String script_path = ScriptServer::get_global_class_path(p_type);
Ref<Script> scr = ResourceLoader::load(script_path, "Script");

ERR_FAIL_COND(scr.is_null());
is_abstract = scr->is_abstract();
is_abstract = ScriptServer::is_global_class_abstract(p_type);

String tooltip = TTR("Script path: %s");
bool is_tool = scr->is_tool();
bool is_tool = ScriptServer::is_global_class_tool(p_type);
if (is_tool) {
tooltip = TTR("The script will run in the editor.") + "\n" + tooltip;
}
Expand Down
Loading

0 comments on commit a33588f

Please sign in to comment.