Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for preloading the icon_exists cache #5530

Merged
merged 10 commits into from
Feb 22, 2025
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
Expand Down
17 changes: 16 additions & 1 deletion code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
30 changes: 30 additions & 0 deletions code/__HELPERS/~monkestation-helpers/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I wouldn't mind this being uncommented by default, if you think it'd be better.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently there's not even a build step to do this, i'm doing this manually / via TGS build scripts


// 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.
Expand Down
Loading