Merge pull request #106866 from KoBeWi/more_cache

Add class icon cache to EditorNode
This commit is contained in:
Thaddeus Crews 2025-05-28 09:47:44 -05:00
commit f5bf37a2d4
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC
4 changed files with 21 additions and 7 deletions

View file

@ -4005,9 +4005,10 @@ void EditorNode::_remove_edited_scene(bool p_change_tab) {
}
void EditorNode::_remove_scene(int index, bool p_change_tab) {
// Clear icon cache in case some scripts are no longer needed.
// Clear icon cache in case some scripts are no longer needed or class icons are outdated.
// FIXME: Ideally the cache should never be cleared and only updated on per-script basis, when an icon changes.
editor_data.clear_script_icon_cache();
class_icon_cache.clear();
if (editor_data.get_edited_scene() == index) {
// Scene to remove is current scene.
@ -5188,6 +5189,13 @@ Ref<Texture2D> EditorNode::get_object_icon(const Object *p_object, const String
Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p_fallback) {
ERR_FAIL_COND_V_MSG(p_class.is_empty(), nullptr, "Class name cannot be empty.");
// Take from the local cache, if available.
{
Ref<Texture2D> *icon = class_icon_cache.getptr(p_class);
if (icon) {
return *icon;
}
}
String script_path;
if (ScriptServer::is_global_class(p_class)) {
@ -5196,7 +5204,9 @@ Ref<Texture2D> EditorNode::get_class_icon(const String &p_class, const String &p
script_path = p_class;
}
return _get_class_or_script_icon(p_class, script_path, p_fallback, true);
Ref<Texture2D> icon = _get_class_or_script_icon(p_class, script_path, p_fallback, true);
class_icon_cache[p_class] = icon;
return icon;
}
bool EditorNode::is_object_of_custom_type(const Object *p_object, const StringName &p_class) {