From ca4f4201e709d237ef8892aa11af38cc7fa5ef39 Mon Sep 17 00:00:00 2001 From: MrStonedOne Date: Wed, 25 Nov 2015 02:11:04 -0800 Subject: [PATCH] Asset Cache improvements! Adds crew monitor to the asset cache system Adds paper to the asset cache system Added a way to send files to the client slowly without clogging up the queue. (This isn't technically "safe", but the client would only have issues if they didn't have that file already (rare), and only if they used a window that needed that asset (currently only nanoui windows) within the first 15 to 90 seconds of connecting (depending on ping)) Makes NanoUI use this slow send system to blindly send it's asset files. (Once bay's nanoui is ported, i'll improve this so that nanoui fully implements asset cache checking) Makes asset cache use this system to send all registered asset files, so that ui windows don't have to wait for them if the client's been connected a while. --- code/controllers/subsystem/nanoUI.dm | 2 +- code/game/machinery/computer/crew.dm | 15 ++++-- code/game/objects/items/devices/PDA/PDA.dm | 5 +- code/modules/client/asset_cache.dm | 54 +++++++++++++++++----- code/modules/client/client procs.dm | 27 ++++------- code/modules/nano/nanomanager.dm | 3 +- code/modules/paperwork/paper.dm | 3 ++ 7 files changed, 70 insertions(+), 39 deletions(-) diff --git a/code/controllers/subsystem/nanoUI.dm b/code/controllers/subsystem/nanoUI.dm index 5ec4344fee7..6d023d193d0 100644 --- a/code/controllers/subsystem/nanoUI.dm +++ b/code/controllers/subsystem/nanoUI.dm @@ -30,7 +30,7 @@ var/datum/subsystem/nano/SSnano //Ignore directories if(copytext(filename, length(filename)) != "/") if(fexists(path + filename)) - asset_files.Add(fcopy_rsc(path + filename)) + asset_files[filename] = fcopy_rsc(path + filename) /datum/subsystem/nano/stat_entry() diff --git a/code/game/machinery/computer/crew.dm b/code/game/machinery/computer/crew.dm index 8e494829962..71e3c28f84c 100644 --- a/code/game/machinery/computer/crew.dm +++ b/code/game/machinery/computer/crew.dm @@ -77,6 +77,10 @@ var/global/datum/crewmonitor/crewmonitor = new src.jobs = jobs src.interfaces = list() src.data = list() + register_asset("crewmonitor.js",'crew.js') + register_asset("crewmonitor.css",'crew.css') + for (var/z = 1 to world.maxz) + register_asset("minimap_[z].png", file("[getMinimapFile(z)].png")) /datum/crewmonitor/Destroy() if (src.interfaces) @@ -87,6 +91,8 @@ var/global/datum/crewmonitor/crewmonitor = new return ..() /datum/crewmonitor/proc/show(mob/mob, z) + if (mob.client) + sendResources(mob.client) if (!z) z = mob.z if (z > 0 && src.interfaces) @@ -260,10 +266,11 @@ var/global/datum/crewmonitor/crewmonitor = new sendResources(C) initialized = TRUE -/datum/crewmonitor/proc/sendResources(client/C) - C << browse_rsc('crew.js', "crewmonitor.js") - C << browse_rsc('crew.css', "crewmonitor.css") - for (var/z = 1 to world.maxz) C << browse_rsc(file("[getMinimapFile(z)].png"), "minimap_[z].png") +/datum/crewmonitor/proc/sendResources(var/client/client) + send_asset(client, "crewmonitor.js") + send_asset(client, "crewmonitor.css") + for (var/z = 1 to world.maxz) + send_asset(client, "minimap_[z].png") /datum/crewmonitor/proc/getMinimapFile(z) return "data/minimaps/map_[z]" diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm index 324b2cd4dd6..9a81a7c8b2c 100644 --- a/code/game/objects/items/devices/PDA/PDA.dm +++ b/code/game/objects/items/devices/PDA/PDA.dm @@ -257,8 +257,9 @@ var/global/list/obj/item/device/pda/PDAs = list() return /obj/item/device/pda/attack_self(mob/user) - var/datum/asset/simple/pda/assetcache = new() - send_asset_list(user, assetcache.assets, verify = FALSE) + var/datum/asset/assets = get_asset_datum(/datum/asset/simple/pda) + assets.send(user) + user.set_machine(src) if(active_uplink_check(user)) diff --git a/code/modules/client/asset_cache.dm b/code/modules/client/asset_cache.dm index 74404c10fd2..0297cd4b7ba 100644 --- a/code/modules/client/asset_cache.dm +++ b/code/modules/client/asset_cache.dm @@ -71,7 +71,8 @@ return 0 for(var/asset in unreceived) - client << browse_rsc(asset_cache[asset], asset) + if (asset in asset_cache) + client << browse_rsc(asset_cache[asset], asset) if(!verify || !winexists(client, "asset_cache_browser")) // Can't access the asset cache browser, rip. client.cache += unreceived @@ -99,31 +100,55 @@ return 1 +//This proc will download the files without clogging up the browse() queue, used for passively sending files on connection start. +proc/getFilesSlow(var/client/client, var/list/files, var/register_asset = TRUE) + for(var/file in files) + if (register_asset) + register_asset(file,files[file]) + send_asset(client,file) + //This proc "registers" an asset, it adds it to the cache for further use, you cannot touch it from this point on or you'll fuck things up. //if it's an icon or something be careful, you'll have to copy it before further use. /proc/register_asset(var/asset_name, var/asset) - asset_cache |= asset_name asset_cache[asset_name] = asset - //From here on out it's populating the asset cache. - /proc/populate_asset_cache() for(var/type in typesof(/datum/asset) - list(/datum/asset, /datum/asset/simple)) var/datum/asset/A = new type() A.register() //These datums are used to populate the asset cache, the proc "register()" does this. + +//all of our asset datums, used for referring to these later +/var/global/list/asset_datums = list() + +//get a assetdatum or make a new one +/proc/get_asset_datum(var/type) + if (!(type in asset_datums)) + return new type() + return asset_datums[type] + +/datum/asset/New() + asset_datums[type] = src + /datum/asset/proc/register() return +/datum/asset/proc/send(client) + return + //If you don't need anything complicated. /datum/asset/simple var/assets = list() + var/verify = FALSE /datum/asset/simple/register() for(var/asset_name in assets) register_asset(asset_name, assets[asset_name]) +/datum/asset/simple/send(client) + send_asset_list(client,assets,verify) + //DEFINITIONS FOR ASSET DATUMS START HERE. @@ -159,16 +184,23 @@ "pda_status.png" = 'icons/pda_icons/pda_status.png' ) +/datum/asset/simple/paper + assets = list( + "large_stamp-clown.png" = 'icons/stamp_icons/large_stamp-clown.png', + "large_stamp-deny.png" = 'icons/stamp_icons/large_stamp-deny.png', + "large_stamp-ok.png" = 'icons/stamp_icons/large_stamp-ok.png', + "large_stamp-hop.png" = 'icons/stamp_icons/large_stamp-hop.png', + "large_stamp-cmo.png" = 'icons/stamp_icons/large_stamp-cmo.png', + "large_stamp-ce.png" = 'icons/stamp_icons/large_stamp-ce.png', + "large_stamp-hos.png" = 'icons/stamp_icons/large_stamp-hos.png', + "large_stamp-rd.png" = 'icons/stamp_icons/large_stamp-rd.png', + "large_stamp-cap.png" = 'icons/stamp_icons/large_stamp-cap.png', + "large_stamp-qm.png" = 'icons/stamp_icons/large_stamp-qm.png', + "large_stamp-law.png" = 'icons/stamp_icons/large_stamp-law.png' + ) //Registers HTML Interface assets. /datum/asset/HTML_interface/register() for(var/path in typesof(/datum/html_interface)) var/datum/html_interface/hi = new path() hi.registerResources() - - -//Registers NanoUI assets. -/datum/asset/NanoUI/register() - for(var/path in typesof(/datum/html_interface)) - var/datum/html_interface/hi = new path() - hi.registerResources() diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index a49d15e7846..b297b24a8e9 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -324,29 +324,18 @@ var/next_external_rsc = 0 //send resources to the client. It's here in its own proc so we can move it around easiliy if need be /client/proc/send_resources() - - // Preload the crew monitor. This needs to be done due to BYOND bug http://www.byond.com/forum/?post=1487244 - spawn - if (crewmonitor && crewmonitor.initialized) - crewmonitor.sendResources(src) - - //Send nanoui files to client - SSnano.send_resources(src) + //get the common files getFiles( 'html/search.js', 'html/panels.css', 'html/browser/common.css', 'html/browser/scannernew.css', 'html/browser/playeroptions.css', - 'icons/stamp_icons/large_stamp-clown.png', - 'icons/stamp_icons/large_stamp-deny.png', - 'icons/stamp_icons/large_stamp-ok.png', - 'icons/stamp_icons/large_stamp-hop.png', - 'icons/stamp_icons/large_stamp-cmo.png', - 'icons/stamp_icons/large_stamp-ce.png', - 'icons/stamp_icons/large_stamp-hos.png', - 'icons/stamp_icons/large_stamp-rd.png', - 'icons/stamp_icons/large_stamp-cap.png', - 'icons/stamp_icons/large_stamp-qm.png', - 'icons/stamp_icons/large_stamp-law.png' ) + + //Send nanoui files to client + SSnano.send_resources(src) + + //Precache the client with all other assets slowly, so as to not block other browse() calls + getFilesSlow(src, asset_cache, register_asset = FALSE) + diff --git a/code/modules/nano/nanomanager.dm b/code/modules/nano/nanomanager.dm index dbe242e8c08..2831ec6a2b5 100644 --- a/code/modules/nano/nanomanager.dm +++ b/code/modules/nano/nanomanager.dm @@ -208,5 +208,4 @@ //Send all needed nano ui files to the client /datum/subsystem/nano/proc/send_resources(client) - for(var/file in asset_files) - client << browse_rsc(file) \ No newline at end of file + getFilesSlow(client, asset_files) diff --git a/code/modules/paperwork/paper.dm b/code/modules/paperwork/paper.dm index 8dc2bf834cd..739b17cfff0 100644 --- a/code/modules/paperwork/paper.dm +++ b/code/modules/paperwork/paper.dm @@ -51,6 +51,9 @@ /obj/item/weapon/paper/examine(mob/user) ..() + var/datum/asset/assets = get_asset_datum(/datum/asset/simple/paper) + assets.send(user) + if(istype(src, /obj/item/weapon/paper/talisman)) //Talismans cannot be read if(!iscultist(user) && !user.stat) user << "There are indecipherable images scrawled on the paper in what looks to be... blood?"