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

Optimizes /proc/icon_exists #5287

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions code/__HELPERS/icons.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1467,26 +1467,23 @@ GLOBAL_LIST_EMPTY(transformation_animation_objects)

///Checks if the given iconstate exists in the given file, caching the result. Setting scream to TRUE will print a stack trace ONCE.
/proc/icon_exists(file, state, scream)
var/static/list/screams = list()
var/static/list/icon_states_cache = list()
if(icon_states_cache[file]?[state])
return TRUE

if(icon_states_cache[file]?[state] == FALSE)
return FALSE

var/list/states = icon_states(file)
if(isnull(file) || isnull(state))
return FALSE //This is common enough that it shouldn't panic, imo.

if(!icon_states_cache[file])
if(isnull(icon_states_cache[file]))
icon_states_cache[file] = list()
for(var/istate in icon_states(file))
icon_states_cache[file][istate] = TRUE

if(state in states)
icon_states_cache[file][state] = TRUE
return TRUE
else
icon_states_cache[file][state] = FALSE
if(scream)
if(isnull(icon_states_cache[file][state]))
if(isnull(screams[file]) && scream)
screams[file] = TRUE
stack_trace("Icon Lookup for state: [state] in file [file] failed.")
return FALSE
else
return TRUE

/// Cache of the width and height of icon files, to avoid repeating the same expensive operation
GLOBAL_LIST_EMPTY(icon_dimensions)
Expand Down
Loading