mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-18 11:36:24 +01:00
optimizes icon2html() for icon files known to be in the rsc at compile time (#67429)
* makes compile time icons not do expensive file io for asset gen * better documentation on some asset vars and procs * makes generate_and_hash_rsc_file() do fcopy() and passes down the chain * implements msos suggestion to optimize get_icon_dmi_path()
This commit is contained in:
@@ -4,9 +4,13 @@
|
||||
* An internal datum containing info on items in the asset cache. Mainly used to cache md5 info for speed.
|
||||
*/
|
||||
/datum/asset_cache_item
|
||||
/// the name of this asset item, becomes the key in SSassets.cache list
|
||||
var/name
|
||||
/// md5() of the file this asset item represents.
|
||||
var/hash
|
||||
/// the file this asset represents
|
||||
var/resource
|
||||
/// our file extension e.g. .png, .gif, etc
|
||||
var/ext = ""
|
||||
/// Should this file also be sent via the legacy browse_rsc system
|
||||
/// when cdn transports are enabled?
|
||||
@@ -21,11 +25,20 @@
|
||||
/// TRUE for keeping local asset names when browse_rsc backend is used
|
||||
var/keep_local_name = FALSE
|
||||
|
||||
/datum/asset_cache_item/New(name, file)
|
||||
///pass in a valid file_hash if you have one to save it from needing to do it again.
|
||||
///pass in a valid dmi file path string e.g. "icons/path/to/dmi_file.dmi" to make generating the hash less expensive
|
||||
/datum/asset_cache_item/New(name, file, file_hash, dmi_file_path)
|
||||
if (!isfile(file))
|
||||
file = fcopy_rsc(file)
|
||||
|
||||
hash = md5asfile(file) //icons sent to the rsc sometimes md5 incorrectly
|
||||
|
||||
hash = file_hash
|
||||
|
||||
//the given file is directly from a dmi file and is thus in the rsc already, we know that its file_hash will be correct
|
||||
if(!hash)
|
||||
if(dmi_file_path)
|
||||
hash = md5(file)
|
||||
else
|
||||
hash = md5asfile(file) //icons sent to the rsc md5 incorrectly when theyre given incorrect data
|
||||
if (!hash)
|
||||
CRASH("invalid asset sent to asset cache")
|
||||
src.name = name
|
||||
|
||||
@@ -25,15 +25,21 @@
|
||||
addtimer(CALLBACK(src, .proc/send_assets_slow, C, preload), 1 SECONDS)
|
||||
|
||||
|
||||
/// Register a browser asset with the asset cache system
|
||||
/// asset_name - the identifier of the asset
|
||||
/// asset - the actual asset file (or an asset_cache_item datum)
|
||||
/// returns a /datum/asset_cache_item.
|
||||
/// mutiple calls to register the same asset under the same asset_name return the same datum
|
||||
/datum/asset_transport/proc/register_asset(asset_name, asset)
|
||||
/**
|
||||
* Register a browser asset with the asset cache system.
|
||||
* returns a /datum/asset_cache_item.
|
||||
* mutiple calls to register the same asset under the same asset_name return the same datum.
|
||||
*
|
||||
* Arguments:
|
||||
* * asset_name - the identifier of the asset.
|
||||
* * asset - the actual asset file (or an asset_cache_item datum).
|
||||
* * file_hash - optional, a hash of the contents of the asset files contents. used so asset_cache_item doesnt have to hash it again
|
||||
* * dmi_file_path - optional, means that the given asset is from the rsc and thus we dont need to do some expensive operations
|
||||
*/
|
||||
/datum/asset_transport/proc/register_asset(asset_name, asset, file_hash, dmi_file_path)
|
||||
var/datum/asset_cache_item/ACI = asset
|
||||
if (!istype(ACI))
|
||||
ACI = new(asset_name, asset)
|
||||
ACI = new(asset_name, asset, file_hash, dmi_file_path)
|
||||
if (!ACI || !ACI.hash)
|
||||
CRASH("ERROR: Invalid asset: [asset_name]:[asset]:[ACI]")
|
||||
if (SSassets.cache[asset_name])
|
||||
|
||||
Reference in New Issue
Block a user