mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-14 01:24:21 +01:00
Ports /vg/'s asset cache system; lowers interface lag when clients connect.
Byond will queue all browse(), browse_rsc(), and winset() calls to the client, to ensure they load in order, and ensure any resources from a browse_rsc call (css/html/js) are already at the client by the time any html windows loads. How ever, each file is processed separately, and byond will wait for the reply from the client before it will send the next file. Our current system sends all of these html resource files to the client at once when they connect, this is the sole cause of the lag when a client connects. Byond will not send the client a file it already has, but it has to ask the client first, and it does so one file at a time, waiting for a reply from the client before sending the next one down the pipe. This system fixes that. Basically it works like this: Client connects: nothing happens, no massive queuing of browse_rsc() calls, so no interface delay Client opens a asset_cache controlled html based interface Asset cache gets notified by the html based interface what assets the client needs to have. Asset cache checks to see if it's sent that client those files. Asset cache sends the missing ones, adding them to the list of assets the client has. This basically spreads out the delay to when you first open a window that uses resources, where it is much more manageable. I've kinda done a halfass port without too much thought, I see some room for improvement to better fit /tg/'s coding style and make the system more flexible. I'm PRing this because if I don't, it will never get finished. PDAs and html_interface has been imported in to the new system lazily to test. at 100ms connection start interface lag went from 35 seconds to 16 seconds. Nanoui hasn't been imported, and once it is, that should drop down to almost nothing. I'll work on this some more after some sleep.
This commit is contained in:
@@ -63,6 +63,8 @@ Closes the interface on all clients.
|
||||
When working with byond:// links make sure to reference the HTML interface object and NOT the original object. Topic() will still be called on
|
||||
your object, but it will pass through the HTML interface first allowing interception at a higher level.
|
||||
|
||||
If you want to use custom resources(images/css/js) with an existing interface:
|
||||
You have to use modules/client/asset_cache to ensure they get sent BEFORE the interface opens
|
||||
|
||||
** Sample code **
|
||||
|
||||
@@ -105,6 +107,10 @@ mob/verb/test()
|
||||
// The initial height of the browser control, used when the window is first shown to a client.
|
||||
var/height
|
||||
|
||||
// A type associated list of assets the interface needs.
|
||||
//Sent to the client when the interface opens on the client for the first time.
|
||||
var/static/asset_list = list()
|
||||
|
||||
/datum/html_interface/New(atom/ref, title, width = 700, height = 480, head = "")
|
||||
html_interfaces.Add(src)
|
||||
|
||||
@@ -126,12 +132,19 @@ mob/verb/test()
|
||||
/* * Hooks */
|
||||
/datum/html_interface/proc/specificRenderTitle(datum/html_interface_client/hclient, ignore_cache = FALSE)
|
||||
|
||||
/datum/html_interface/proc/sendResources(client/client)
|
||||
client << browse_rsc('js/jquery.min.js', "jquery.min.js")
|
||||
client << browse_rsc('js/bootstrap.min.js', "bootstrap.min.js")
|
||||
client << browse_rsc('css/bootstrap.min.css', "bootstrap.min.css")
|
||||
client << browse_rsc('css/html_interface.css', "html_interface.css")
|
||||
client << browse_rsc('js/html_interface.js', "html_interface.js")
|
||||
//if you need to override this, either call ..() or add your resources to asset_list
|
||||
/datum/html_interface/proc/registerResources(var/list/resources = list())
|
||||
resources["jquery.min.js"] = 'js/jquery.min.js'
|
||||
resources["bootstrap.min.js"] = 'js/bootstrap.min.js'
|
||||
resources["bootstrap.min.css"] = 'css/bootstrap.min.css'
|
||||
resources["html_interface.css"] = 'css/html_interface.css'
|
||||
resources["html_interface.js"] = 'js/html_interface.js'
|
||||
var/assetlist = list()
|
||||
for (var/R in resources)
|
||||
register_asset(R,resources[R])
|
||||
assetlist += R
|
||||
|
||||
asset_list[type] = assetlist
|
||||
|
||||
/datum/html_interface/proc/createWindow(datum/html_interface_client/hclient)
|
||||
winclone(hclient.client, "window", "browser_\ref[src]")
|
||||
@@ -207,10 +220,7 @@ mob/verb/test()
|
||||
hclient = getClient(hclient, TRUE)
|
||||
|
||||
if (istype(hclient))
|
||||
// This needs to be commented out due to BYOND bug http://www.byond.com/forum/?post=1487244
|
||||
// /client/proc/send_resources() executes this per client to avoid the bug, but by using it here files may be deleted just as the HTML is loaded,
|
||||
// causing file not found errors.
|
||||
// src.sendResources(hclient.client)
|
||||
send_asset_list(hclient.client,asset_list[type], TRUE)
|
||||
|
||||
if (!winexists(hclient.client, "browser_\ref[src]"))
|
||||
src.createWindow(hclient)
|
||||
|
||||
Reference in New Issue
Block a user