Early Assets, Lateloaded Assets, and Debugging Tools (#4696)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
Various asset systems I want in before more TGUI work. and also
byond-tracy support... and also light update debugging...
## Changelog
🆑
tweak: Chem Master UI has been reworked slightly.
This commit is contained in:
Zandario
2022-11-20 17:36:24 -07:00
committed by GitHub
parent d477ee4e43
commit 7bf4c2a34f
191 changed files with 2507 additions and 1591 deletions
+112 -24
View File
@@ -6,8 +6,16 @@
//all of our asset datums, used for referring to these later
GLOBAL_LIST_EMPTY(asset_datums)
//get an assetdatum or make a new one
/// Get an assetdatum or make a new one.
/proc/get_asset_datum(type)
var/datum/asset/loaded_asset = GLOB.asset_datums[type] || new type()
return loaded_asset.ensure_ready()
/**
* Get an assetdatum or make a new one.
*! But does NOT ensure it's filled, if you want that use get_asset_datum()
*/
/proc/load_asset_datum(type)
return GLOB.asset_datums[type] || new type()
/datum/asset
@@ -18,11 +26,25 @@ GLOBAL_LIST_EMPTY(asset_datums)
/// Whether or not this asset should be loaded in the "early assets" SS
var/early = FALSE
/// Whether or not this asset can be cached across rounds of the same commit under the `CACHE_ASSETS` config.
/// This is not a *guarantee* the asset will be cached. Not all asset subtypes respect this field, and the
/// config can, of course, be disabled.
/**
* Whether or not this asset can be cached across rounds of the same commit under the `CACHE_ASSETS` config.
* This is not a *guarantee* the asset will be cached. Not all asset subtypes respect this field, and the
* config can, of course, be disabled.
*/
var/cross_round_cachable = FALSE
/**
* Stub that allows us to react to something trying to get us.
* Not useful here, more handy for sprite sheets.
*/
/datum/asset/proc/ensure_ready()
return src
/// Stub to hook into if your asset is having its generation queued by SSasset_loading
/datum/asset/proc/queued_generation()
CRASH("[type] inserted into SSasset_loading despite not implementing /proc/queued_generation")
/datum/asset/New()
GLOB.asset_datums[type] = src
register()
@@ -51,12 +73,16 @@ GLOBAL_LIST_EMPTY(asset_datums)
/// If you don't need anything complicated.
/datum/asset/simple
_abstract = /datum/asset/simple
/// list of assets for this datum in the form of:
/// asset_filename = asset_file. At runtime the asset_file will be
/// converted into a asset_cache datum.
/**
* List of assets for this datum in the form of:
* * asset_filename = asset_file.
* At runtime the asset_file will be converted into a asset_cache datum.
*/
var/assets = list()
/// Set to true to have this asset also be sent via the legacy browse_rsc
/// system when cdn transports are enabled?
/**
* Set to true to have this asset also be sent via the legacy browse_rsc
* system when cdn transports are enabled?
*/
var/legacy = FALSE
/// TRUE for keeping local asset names when browse_rsc backend is used
var/keep_local_name = FALSE
@@ -88,7 +114,7 @@ GLOBAL_LIST_EMPTY(asset_datums)
/datum/asset/group/register()
for(var/type in children)
get_asset_datum(type)
load_asset_datum(type)
/datum/asset/group/send(client/C)
for(var/type in children)
@@ -101,28 +127,44 @@ GLOBAL_LIST_EMPTY(asset_datums)
var/datum/asset/A = get_asset_datum(type)
. += A.get_url_mappings()
// spritesheet implementation - coalesces various icons into a single .png file
// and uses CSS to select icons out of that file - saves on transferring some
// 1400-odd individual PNG files
/**
* spritesheet implementation - coalesces various icons into a single .png file
* and uses CSS to select icons out of that file - saves on transferring some
* 1400-odd individual PNG files
*/
#define SPR_SIZE 1
#define SPR_IDX 2
#define SPRSZ_COUNT 1
#define SPRSZ_ICON 2
#define SPR_IDX 2
#define SPRSZ_COUNT 1
#define SPRSZ_ICON 2
#define SPRSZ_STRIPPED 3
/datum/asset/spritesheet
_abstract = /datum/asset/spritesheet
var/name
var/list/sizes = list() // "32x32" -> list(10, icon/normal, icon/stripped)
var/list/sprites = list() // "foo_bar" -> list("32x32", 5)
/**
* List of arguments to pass into queuedInsert.
* Exists so we can queue icon insertion, mostly for stuff like preferences.
*/
var/list/to_generate = list()
/// "32x32" -> list(10, icon/normal, icon/stripped)
var/list/sizes = list()
/// "foo_bar" -> list("32x32", 5)
var/list/sprites = list()
var/list/cached_spritesheets_needed
var/generating_cache = FALSE
var/fully_generated = FALSE
/**
* If this asset should be fully loaded on new
* Defaults to false so we can process this stuff nicely
*/
var/load_immediately = FALSE
/datum/asset/spritesheet/should_refresh()
if (..())
return TRUE
// Static so that the result is the same, even when the files are created, for this run
/// Static so that the result is the same, even when the files are created, for this run.
var/static/should_refresh = null
if (isnull(should_refresh))
@@ -140,7 +182,25 @@ GLOBAL_LIST_EMPTY(asset_datums)
if (!should_refresh() && read_from_cache())
return
/// If it's cached, may as well load it now, while the loading is cheap
if(CONFIG_GET(flag/cache_assets) && cross_round_cachable)
load_immediately = TRUE
create_spritesheets()
if(load_immediately)
realize_spritesheets(yield = FALSE)
else
SSasset_loading.generate_queue += src
/datum/asset/spritesheet/proc/realize_spritesheets(yield)
if(fully_generated)
return
while(length(to_generate))
var/list/stored_args = to_generate[to_generate.len]
to_generate.len--
queuedInsert(arglist(stored_args))
if(yield && TICK_CHECK)
return
ensure_stripped()
for(var/size_id in sizes)
@@ -156,6 +216,18 @@ GLOBAL_LIST_EMPTY(asset_datums)
if (CONFIG_GET(flag/cache_assets) && cross_round_cachable)
write_to_cache()
fully_generated = TRUE
// If we were ever in there, remove ourselves
SSasset_loading.generate_queue -= src
/datum/asset/spritesheet/queued_generation()
realize_spritesheets(yield = TRUE)
/datum/asset/spritesheet/ensure_ready()
if(!fully_generated)
realize_spritesheets(yield = FALSE)
return ..()
/datum/asset/spritesheet/send(client/client)
if (!name)
return
@@ -270,17 +342,31 @@ GLOBAL_LIST_EMPTY(asset_datums)
return mappings
/// Override this in order to start the creation of the spritehseet.
/// This is where all your Insert, InsertAll, etc calls should be inside.
/**
*! Override this in order to start the creation of the spritehseet.
*! This is where all your Insert, InsertAll, etc calls should be inside.
*/
/datum/asset/spritesheet/proc/create_spritesheets()
SHOULD_CALL_PARENT(FALSE)
CRASH("create_spritesheets() not implemented for [type]!")
/datum/asset/spritesheet/proc/Insert(sprite_name, icon/I, icon_state="", dir=SOUTH, frame=1, moving=FALSE)
if(load_immediately)
queuedInsert(sprite_name, I, icon_state, dir, frame, moving)
else
to_generate += list(args.Copy())
/**
* LEMON NOTE
* A GOON CODER SAYS BAD ICON ERRORS CAN BE THROWN BY THE "ICON CACHE"
* APPARENTLY IT MAKES ICONS IMMUTABLE
* LOOK INTO USING THE MUTABLE APPEARANCE PATTERN HERE
*/
/datum/asset/spritesheet/proc/queuedInsert(sprite_name, icon/I, icon_state="", dir=SOUTH, frame=1, moving=FALSE)
I = icon(I, icon_state=icon_state, dir=dir, frame=frame, moving=moving)
if (!I || !length(icon_states(I))) // that direction or state doesn't exist
if (!I || !length(icon_states(I))) // That direction or state doesn't exist!
return
//any sprite modifications we want to do (aka, coloring a greyscaled asset)
// Any sprite modifications we want to do (aka, coloring a greyscaled asset)
I = ModifyInserted(I)
var/size_id = "[I.Width()]x[I.Height()]"
var/size = sizes[size_id]
@@ -291,8 +377,10 @@ GLOBAL_LIST_EMPTY(asset_datums)
if (size)
var/position = size[SPRSZ_COUNT]++
var/icon/sheet = size[SPRSZ_ICON]
var/icon/sheet_copy = icon(sheet)
size[SPRSZ_STRIPPED] = null
sheet.Insert(I, icon_state=sprite_name)
sheet_copy.Insert(I, icon_state=sprite_name)
size[SPRSZ_ICON] = sheet_copy
sprites[sprite_name] = list(size_id, position)
else
sizes[size_id] = size = list(1, I, null)
@@ -0,0 +1,8 @@
/datum/asset/spritesheet/simple/bottles
name = "bottles"
assets = list(
"bottle1" = 'icons/runtime/assets/medical/bottles/bottle1.png',
"bottle2" = 'icons/runtime/assets/medical/bottles/bottle2.png',
"bottle3" = 'icons/runtime/assets/medical/bottles/bottle3.png',
"bottle4" = 'icons/runtime/assets/medical/bottles/bottle4.png',
)
@@ -0,0 +1,8 @@
/datum/asset/spritesheet/simple/patches
name = "patches"
assets = list(
"patch" = 'icons/runtime/assets/medical/patches/patch.png',
"patch_brute" = 'icons/runtime/assets/medical/patches/patch_brute.png',
"patch_burn" = 'icons/runtime/assets/medical/patches/patch_burn.png',
"patch_both" = 'icons/runtime/assets/medical/patches/patch_both.png',
)
@@ -0,0 +1,26 @@
/datum/asset/spritesheet/simple/pills
name = "pills"
assets = list(
"pill1" = 'icons/runtime/assets/medical/pills/pill1.png',
"pill2" = 'icons/runtime/assets/medical/pills/pill2.png',
"pill3" = 'icons/runtime/assets/medical/pills/pill3.png',
"pill4" = 'icons/runtime/assets/medical/pills/pill4.png',
"pill5" = 'icons/runtime/assets/medical/pills/pill5.png',
"pill6" = 'icons/runtime/assets/medical/pills/pill6.png',
"pill7" = 'icons/runtime/assets/medical/pills/pill7.png',
"pill8" = 'icons/runtime/assets/medical/pills/pill8.png',
"pill9" = 'icons/runtime/assets/medical/pills/pill9.png',
"pill10" = 'icons/runtime/assets/medical/pills/pill10.png',
"pill11" = 'icons/runtime/assets/medical/pills/pill11.png',
"pill12" = 'icons/runtime/assets/medical/pills/pill12.png',
"pill13" = 'icons/runtime/assets/medical/pills/pill13.png',
"pill14" = 'icons/runtime/assets/medical/pills/pill14.png',
"pill15" = 'icons/runtime/assets/medical/pills/pill15.png',
"pill16" = 'icons/runtime/assets/medical/pills/pill16.png',
"pill17" = 'icons/runtime/assets/medical/pills/pill17.png',
"pill18" = 'icons/runtime/assets/medical/pills/pill18.png',
"pill19" = 'icons/runtime/assets/medical/pills/pill19.png',
"pill20" = 'icons/runtime/assets/medical/pills/pill20.png',
"pill21" = 'icons/runtime/assets/medical/pills/pill21.png',
"pill22" = 'icons/runtime/assets/medical/pills/pill22.png',
)
+16 -16
View File
@@ -1,20 +1,20 @@
/datum/asset/spritesheet/simple/condiments
name = "condiments"
assets = list(
CONDIMASTER_STYLE_FALLBACK = 'icons/ui_icons/condiments/emptycondiment.png',
"enzyme" = 'icons/ui_icons/condiments/enzyme.png',
"flour" = 'icons/ui_icons/condiments/flour.png',
"mayonnaise" = 'icons/ui_icons/condiments/mayonnaise.png',
"milk" = 'icons/ui_icons/condiments/milk.png',
"blackpepper" = 'icons/ui_icons/condiments/peppermillsmall.png',
"rice" = 'icons/ui_icons/condiments/rice.png',
"sodiumchloride" = 'icons/ui_icons/condiments/saltshakersmall.png',
"soymilk" = 'icons/ui_icons/condiments/soymilk.png',
"soysauce" = 'icons/ui_icons/condiments/soysauce.png',
"sugar" = 'icons/ui_icons/condiments/sugar.png',
"ketchup" = 'icons/ui_icons/condiments/ketchup.png',
"capsaicin" = 'icons/ui_icons/condiments/hotsauce.png',
"frostoil" = 'icons/ui_icons/condiments/coldsauce.png',
"bbqsauce" = 'icons/ui_icons/condiments/bbqsauce.png',
"cornoil" = 'icons/ui_icons/condiments/oliveoil.png',
CONDIMASTER_STYLE_FALLBACK = 'icons/runtime/assets/condiments/emptycondiment.png',
"enzyme" = 'icons/runtime/assets/condiments/enzyme.png',
"flour" = 'icons/runtime/assets/condiments/flour.png',
"mayonnaise" = 'icons/runtime/assets/condiments/mayonnaise.png',
"milk" = 'icons/runtime/assets/condiments/milk.png',
"blackpepper" = 'icons/runtime/assets/condiments/peppermillsmall.png',
"rice" = 'icons/runtime/assets/condiments/rice.png',
"sodiumchloride" = 'icons/runtime/assets/condiments/saltshakersmall.png',
"soymilk" = 'icons/runtime/assets/condiments/soymilk.png',
"soysauce" = 'icons/runtime/assets/condiments/soysauce.png',
"sugar" = 'icons/runtime/assets/condiments/sugar.png',
"ketchup" = 'icons/runtime/assets/condiments/ketchup.png',
"capsaicin" = 'icons/runtime/assets/condiments/hotsauce.png',
"frostoil" = 'icons/runtime/assets/condiments/coldsauce.png',
"bbqsauce" = 'icons/runtime/assets/condiments/bbqsauce.png',
"cornoil" = 'icons/runtime/assets/condiments/oliveoil.png',
)
@@ -1,8 +0,0 @@
/datum/asset/spritesheet/simple/patches
name = "patches"
assets = list(
"bandaid" = 'icons/ui_icons/patches/bandaid.png',
"bandaid_brute" = 'icons/ui_icons/patches/bandaid_brute.png',
"bandaid_burn" = 'icons/ui_icons/patches/bandaid_burn.png',
"bandaid_both" = 'icons/ui_icons/patches/bandaid_both.png'
)
-40
View File
@@ -1,40 +0,0 @@
/datum/asset/simple/namespaced/chem_master
keep_local_name = TRUE
/datum/asset/simple/namespaced/chem_master/register()
for(var/i = 1 to 24)
assets["pill[i].png"] = icon('icons/obj/chemical.dmi', "pill[i]")
for(var/i = 1 to 4)
assets["bottle-[i].png"] = icon('icons/obj/chemical.dmi', "bottle-[i]")
return ..()
/*
/datum/asset/spritesheet/simple/pills
name = "pills"
assets = list(
"pill1" = 'icons/ui_icons/pills/pill1.png',
"pill2" = 'icons/ui_icons/pills/pill2.png',
"pill3" = 'icons/ui_icons/pills/pill3.png',
"pill4" = 'icons/ui_icons/pills/pill4.png',
"pill5" = 'icons/ui_icons/pills/pill5.png',
"pill6" = 'icons/ui_icons/pills/pill6.png',
"pill7" = 'icons/ui_icons/pills/pill7.png',
"pill8" = 'icons/ui_icons/pills/pill8.png',
"pill9" = 'icons/ui_icons/pills/pill9.png',
"pill10" = 'icons/ui_icons/pills/pill10.png',
"pill11" = 'icons/ui_icons/pills/pill11.png',
"pill12" = 'icons/ui_icons/pills/pill12.png',
"pill13" = 'icons/ui_icons/pills/pill13.png',
"pill14" = 'icons/ui_icons/pills/pill14.png',
"pill15" = 'icons/ui_icons/pills/pill15.png',
"pill16" = 'icons/ui_icons/pills/pill16.png',
"pill17" = 'icons/ui_icons/pills/pill17.png',
"pill18" = 'icons/ui_icons/pills/pill18.png',
"pill19" = 'icons/ui_icons/pills/pill19.png',
"pill20" = 'icons/ui_icons/pills/pill20.png',
"pill21" = 'icons/ui_icons/pills/pill21.png',
"pill22" = 'icons/ui_icons/pills/pill22.png',
)
*/