mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-25 09:01:40 +00:00
* Adds lazyloading to the asset subsystems (#69454) * Adds lazyloading to the asset subsystems This currently applies only to spritesheets because of how monumentally expensive they are. If an asset is requested it will immediately be fully loaded, but otherwise we slowly load them in with a separate subsystem. This allows us to not hold up initialize with hair stuff. Saves roughly 33% (16 seconds with LOW_MEMORY_MODE) of initialize on my machine My target is something closer to the 9 second init that had back in 2019, this is a good first step. Lets see how much more we can do yeah lads? Co-authored-by: san7890 <the@ san7890.com> * Adds lazyloading to the asset subsystems Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: san7890 <the@ san7890.com>
66 lines
2.2 KiB
Plaintext
66 lines
2.2 KiB
Plaintext
/// Assets generated from `/datum/preference` icons
|
|
/datum/asset/spritesheet/preferences
|
|
name = "preferences"
|
|
early = TRUE
|
|
cross_round_cachable = TRUE
|
|
|
|
/datum/asset/spritesheet/preferences/create_spritesheets()
|
|
var/list/to_insert = list()
|
|
|
|
for (var/preference_key in GLOB.preference_entries_by_key)
|
|
var/datum/preference/choiced/preference = GLOB.preference_entries_by_key[preference_key]
|
|
if (!istype(preference))
|
|
continue
|
|
|
|
if (!preference.should_generate_icons)
|
|
continue
|
|
|
|
var/list/choices = preference.get_choices_serialized()
|
|
for (var/preference_value in choices)
|
|
var/create_icon_of = choices[preference_value]
|
|
|
|
var/icon/icon
|
|
var/icon_state
|
|
|
|
if (ispath(create_icon_of, /atom))
|
|
var/atom/atom_icon_source = create_icon_of
|
|
icon = initial(atom_icon_source.icon)
|
|
icon_state = initial(atom_icon_source.icon_state)
|
|
else if (isicon(create_icon_of))
|
|
icon = create_icon_of
|
|
else
|
|
CRASH("[create_icon_of] is an invalid preference value (from [preference_key]:[preference_value]).")
|
|
|
|
to_insert[preference.get_spritesheet_key(preference_value)] = list(icon, icon_state)
|
|
|
|
for (var/spritesheet_key in to_insert)
|
|
var/list/inserting = to_insert[spritesheet_key]
|
|
Insert(spritesheet_key, inserting[1], inserting[2])
|
|
|
|
/// Returns the key that will be used in the spritesheet for a given value.
|
|
/datum/preference/proc/get_spritesheet_key(value)
|
|
return "[savefile_key]___[sanitize_css_class_name(value)]"
|
|
|
|
/// Sends information needed for shared details on individual preferences
|
|
/datum/asset/json/preferences
|
|
name = "preferences"
|
|
|
|
/datum/asset/json/preferences/generate()
|
|
var/list/preference_data = list()
|
|
|
|
for (var/middleware_type in subtypesof(/datum/preference_middleware))
|
|
var/datum/preference_middleware/middleware = new middleware_type
|
|
var/data = middleware.get_constant_data()
|
|
if (!isnull(data))
|
|
preference_data[middleware.key] = data
|
|
|
|
qdel(middleware)
|
|
|
|
for (var/preference_type in GLOB.preference_entries)
|
|
var/datum/preference/preference_entry = GLOB.preference_entries[preference_type]
|
|
var/data = preference_entry.compile_constant_data()
|
|
if (!isnull(data))
|
|
preference_data[preference_entry.savefile_key] = data
|
|
|
|
return preference_data
|