diff --git a/.gitignore b/.gitignore index 6caa2936bd27..ffe66709cea0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# monkestation addition: icon_exists cache +icon_exists_cache.json + ###Files and folders specified here will never be tracked. # Local overrides--you can use this to change the config for your dev environment (like setting up SQL) without worrying about committing it diff --git a/code/__HELPERS/icons.dm b/code/__HELPERS/icons.dm index 35da596c9bbd..fcb14ebca2b9 100644 --- a/code/__HELPERS/icons.dm +++ b/code/__HELPERS/icons.dm @@ -1470,10 +1470,25 @@ GLOBAL_LIST_EMPTY(transformation_animation_objects) /// If you want a stack trace to be output when the given state/file doesn't exist, use /// `/proc/icon_exists_or_scream()`. /proc/icon_exists(file, state) - var/static/list/icon_states_cache = list() + // monkestation start: icon_exists cache + var/static/list/icon_states_cache + if(isnull(icon_states_cache)) +#ifdef PRELOAD_ICON_EXISTS_CACHE + icon_states_cache = load_icon_exists_cache() || list() +#else + icon_states_cache = list() +#endif + // monkestation end if(isnull(file) || isnull(state)) return FALSE //This is common enough that it shouldn't panic, imo. + // monkestation start: icon_exists cache +#ifdef PRELOAD_ICON_EXISTS_CACHE + if(isfile(file) && !isnull(icon_states_cache["[file]"]?[state])) + return TRUE +#endif + // monkestation end + if(isnull(icon_states_cache[file])) icon_states_cache[file] = list() for(var/istate in icon_states(file)) diff --git a/code/__HELPERS/~monkestation-helpers/icons.dm b/code/__HELPERS/~monkestation-helpers/icons.dm index ec8d795bdf4b..f97c19425849 100644 --- a/code/__HELPERS/~monkestation-helpers/icons.dm +++ b/code/__HELPERS/~monkestation-helpers/icons.dm @@ -63,3 +63,33 @@ var/job_type = job.type if(icon_cache[job_type] && (include_unknown || !unknown_huds[job_type])) return icon(icon_cache[job_type]) + +#ifdef PRELOAD_ICON_EXISTS_CACHE +/proc/load_icon_exists_cache() + . = null + if(!fexists("icon_exists_cache.json")) + log_world("icon_exists_cache.json doesn't exist, not loading cache") + return + var/cache_file = rustg_file_read("icon_exists_cache.json") + if(!rustg_json_is_valid(cache_file)) + log_world("did not load icon_exists cache: file exists but wasn't valid json") + CRASH("did not load icon_exists cache: file exists but wasn't valid json") + var/list/cache_data = json_decode(cache_file) + if(!islist(cache_data)) + log_world("did not load icon_exists cache: file exists but wasn't valid json") + CRASH("did not load icon_exists cache: file exists and is valid json, but did not decode into an object") + var/list/icons = cache_data["icons"] + if(!islist(icons)) + log_world("did not load icon_exists cache: 'icons' key was not a list") + CRASH("did not load icon_exists cache: 'icons' key was not a list") + var/cache_revision = cache_data["revision"] + if(!isnull(cache_revision)) + var/revision = rustg_git_revparse("HEAD") + if(cache_revision != revision) + log_world("did not load icon_exists cache: revision ([cache_revision]) mismatched current server revision ([revision])") + return + log_world("loaded icon_exists cache for [revision]") + else + log_world("loaded icon_exists cache without verifying revision") + return icons +#endif diff --git a/code/_compile_options.dm b/code/_compile_options.dm index 0edf6e20950f..cf99d1ce9cc4 100644 --- a/code/_compile_options.dm +++ b/code/_compile_options.dm @@ -84,9 +84,12 @@ /// If this is uncommented, will profile mapload atom initializations // #define PROFILE_MAPLOAD_INIT_ATOM -/// If uncommented, Dreamluau will be fully disabled. +/// If this is uncommented, Dreamluau will be fully disabled. // #define DISABLE_DREAMLUAU +/// If this is uncommented, /proc/icon_exists will attempt to load an initial cache from icon_exists_cache.json +// #define PRELOAD_ICON_EXISTS_CACHE + // OpenDream currently doesn't support byondapi, so automatically disable it on OD, // unless CIBUILDING is defined - we still want to lint dreamluau-related code. // Get rid of this whenever it does have support.