mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 14:08:31 +01:00
Optimizes /proc/icon_exists() (#89357)
## About The Pull Request This PR reimplements https://github.com/tgstation/tgstation/pull/71538 atop `master`. Quoting the original PR: > Every `icon_exists()` call will cache the entire file. Past me didn't realise _why_ file opts were so expensive, but I do now. This is immeasurably slower on a single call, and _significantly_ faster on subsequent calls to the same file. I attempted to handle some of the review comments that were posted there, by splitting screaming functionality into its own proc. * `if(icon_state in icon_states(file))` and `if(!(icon_state in icon_states(file)))` were refactored to use `icon_exists(file, icon_state)`. * Where screaming was seemingly wanted (and where there wasn't a more descriptive error inside the `if` block), I refactored them to use `icon_exists_or_scream(file, icon_state)` * The exception to the above was under `/datum/unit_test/turf_icons/Run()` and `/datum/unit_test/worn_icons/Run()`, where `icon_states()` was being passed a mode flag. Given that this is only used in unit tests (where performance isn't a priority), I opted to leave these be. Additionally, I revised the documentation comment for `/proc/icon_exists()`, as I felt it was a bit vague currently. ## Why It's Good For The Game https://youtu.be/Z9G1Mf6TZRs ## Changelog No player-facing changes (hopefully). --------- Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
This commit is contained in:
@@ -35,12 +35,12 @@
|
||||
continue
|
||||
|
||||
if(worn_icon) //easiest to check since we override everything.
|
||||
if(!(icon_state in icon_states(worn_icon)))
|
||||
if(!icon_exists(worn_icon, icon_state))
|
||||
log_test("\t[count] - [item_path] using invalid [worn_icon_state ? "worn_icon_state" : "icon_state"], \"[icon_state]\" in worn_icon override file, '[worn_icon]'")
|
||||
count++
|
||||
continue
|
||||
|
||||
if(!(icon_state in icon_states('icons/mob/clothing/belt_mirror.dmi')))
|
||||
if(!icon_exists('icons/mob/clothing/belt_mirror.dmi', icon_state))
|
||||
already_warned_icons += icon_state
|
||||
log_test("\t[count] - [item_path] using invalid [worn_icon_state ? "worn_icon_state" : "icon_state"], \"[icon_state]\"")
|
||||
count++
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
var/icon_file = initial(turf_path.icon)
|
||||
if(isnull(icon_state) || isnull(icon_file))
|
||||
continue
|
||||
if(!(icon_state in icon_states(icon_file)))
|
||||
if(!icon_exists(icon_file, icon_state))
|
||||
TEST_FAIL("[turf_path] using invalid icon_state - \"[icon_state]\" in icon file, '[icon_file]")
|
||||
|
||||
for(var/turf/closed/mineral/turf_path as anything in typesof(/turf/closed/mineral)) //minerals use a special (read: snowflake) MAP_SWITCH definition that changes their icon based on if we're just compiling or if we're actually PLAYING the game.
|
||||
@@ -18,7 +18,7 @@
|
||||
var/icon_file = initial(turf_path.icon)
|
||||
if(isnull(icon_state) || isnull(icon_file))
|
||||
continue
|
||||
if(!(icon_state in icon_states(icon_file)))
|
||||
if(!icon_exists(icon_file, icon_state))
|
||||
if(modular_mineral_turf_file && (icon_state in icon_states(modular_mineral_turf_file, 1)))
|
||||
continue
|
||||
if(!(icon_state in icon_states('icons/turf/mining.dmi', 1)))
|
||||
@@ -45,13 +45,13 @@
|
||||
|
||||
var/list/burnt_states = instanced_turf.burnt_states()
|
||||
for(var/state in burnt_states)
|
||||
if(!(state in icon_states(damaged_dmi)))
|
||||
if(!icon_exists(damaged_dmi, state))
|
||||
TEST_FAIL("[open_turf_path] has an invalid icon in burnt_states - \"[state]\", in '[damaged_dmi]'")
|
||||
|
||||
|
||||
var/list/broken_states = instanced_turf.broken_states()
|
||||
for(var/state in broken_states)
|
||||
if(!(state in icon_states(damaged_dmi)))
|
||||
if(!icon_exists(damaged_dmi, state))
|
||||
TEST_FAIL("[open_turf_path] has an invalid icon in broken_states - \"[state]\", in '[damaged_dmi]'")
|
||||
|
||||
run_loc_floor_bottom_left = run_loc_floor_bottom_left.ChangeTurf(initial_turf_type) //cleanup.
|
||||
|
||||
Reference in New Issue
Block a user