From 89652ae5e3b1c8b6a4387d388c1f781198feaad1 Mon Sep 17 00:00:00 2001 From: ccomp5950 Date: Sun, 25 Jan 2015 06:22:30 -0500 Subject: [PATCH 1/4] JSON caching for nanoui You get to cache data, make the best of it. NanoUI for PDA now won't shove the manifest through list2json every tick, it will cache the json for manifest and shove it into the cache_data so list2json tacks it onto the end. --- code/defines/obj.dm | 8 +++--- code/game/objects/items/devices/PDA/PDA.dm | 9 ++++++- code/modules/nano/JSON Writer.dm | 6 +++-- code/modules/nano/_JSON.dm | 4 +-- code/modules/nano/nanoui.dm | 19 ++++++++++++-- nano/templates/pda.tmpl | 30 +++++++++++----------- 6 files changed, 51 insertions(+), 25 deletions(-) diff --git a/code/defines/obj.dm b/code/defines/obj.dm index 0c971df260..a65db71d76 100644 --- a/code/defines/obj.dm +++ b/code/defines/obj.dm @@ -173,10 +173,11 @@ using /obj/effect/datacore/proc/manifest_inject( ), or manifest_insert( ) */ var/global/list/PDA_Manifest = list() +var/global/ManifestJSON -/obj/effect/datacore/proc/get_manifest_json() +/obj/effect/datacore/proc/get_manifest_json(var/client/c = null) if(PDA_Manifest.len) - return PDA_Manifest + return var/heads[0] var/sec[0] var/eng[0] @@ -247,7 +248,8 @@ var/global/list/PDA_Manifest = list() "bot" = bot,\ "misc" = misc\ ) - return PDA_Manifest + ManifestJSON = list2json(PDA_Manifest) + return diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm index b24bf75ec1..a7b69c4a17 100755 --- a/code/game/objects/items/devices/PDA/PDA.dm +++ b/code/game/objects/items/devices/PDA/PDA.dm @@ -464,7 +464,7 @@ var/global/list/obj/item/device/pda/PDAs = list() data["convo_job"] = sanitize(c["job"]) break if(mode==41) - data["manifest"] = data_core.get_manifest_json() + data_core.get_manifest_json(user.client) if(mode==3) @@ -535,12 +535,19 @@ var/global/list/obj/item/device/pda/PDAs = list() nanoUI = data // update the ui if it exists, returns null if no ui is passed/found + if(ui) + ui.load_cached_data(ManifestJSON) + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) + if (!ui) // the ui does not exist, so we'll create a new() one // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm ui = new(user, src, ui_key, "pda.tmpl", title, 520, 400) // when the ui is first opened this is the data it will use + + ui.load_cached_data(ManifestJSON) + ui.set_initial_data(data) // open the new ui window ui.open() diff --git a/code/modules/nano/JSON Writer.dm b/code/modules/nano/JSON Writer.dm index 3cd3520f17..65b9d99eb0 100644 --- a/code/modules/nano/JSON Writer.dm +++ b/code/modules/nano/JSON Writer.dm @@ -1,7 +1,7 @@ json_writer proc - WriteObject(list/L) + WriteObject(list/L, cached_data = null) . = "{" var/i = 1 for(var/k in L) @@ -9,7 +9,9 @@ json_writer . += {"\"[k]\":[write(val)]"} if(i++ < L.len) . += "," - .+= "}" + if(cached_data) + . = copytext(., 1, lentext(.)) + ",\"cached\":[cached_data]}" + . += "}" write(val) if(isnum(val)) diff --git a/code/modules/nano/_JSON.dm b/code/modules/nano/_JSON.dm index 5692e643ba..4f70e6e664 100644 --- a/code/modules/nano/_JSON.dm +++ b/code/modules/nano/_JSON.dm @@ -7,6 +7,6 @@ proc var/static/json_reader/_jsonr = new() return _jsonr.ReadObject(_jsonr.ScanJson(json)) - list2json(list/L) + list2json(list/L, var/cached_data = null) var/static/json_writer/_jsonw = new() - return _jsonw.WriteObject(L) + return _jsonw.WriteObject(L, cached_data) diff --git a/code/modules/nano/nanoui.dm b/code/modules/nano/nanoui.dm index 91e97c0cb5..bdfeffe58e 100644 --- a/code/modules/nano/nanoui.dm +++ b/code/modules/nano/nanoui.dm @@ -57,6 +57,8 @@ nanoui is used to open and update nano browser uis // the current status/visibility of the ui var/status = STATUS_INTERACTIVE + var/cached_data = null + // Only allow users with a certain user.stat to get updates. Defaults to 0 (concious) var/allowed_user_stat = 0 // -1 = ignore, 0 = alive, 1 = unconcious or alive, 2 = dead concious or alive @@ -366,7 +368,7 @@ nanoui is used to open and update nano browser uis template_data_json = list2json(templates) var/list/send_data = get_send_data(initial_data) - var/initial_data_json = list2json(send_data) + var/initial_data_json = list2json(send_data, cached_data) var/url_parameters_json = list2json(list("src" = "\ref[src]")) @@ -442,6 +444,19 @@ nanoui is used to open and update nano browser uis winset(user, window_id, "on-close=\"nanoclose [params]\"") +/** + * Appends already processed json txt to the list2json proc when setting initial-data and data pushes + * Used for data that is fucking huge like manifests and camera lists that doesn't change often. + * And we only want to process them when they change. + * Fuck javascript + * + * @return nothing + */ +/datum/nanoui/proc/load_cached_data(var/data) + cached_data = data + return + + /** * Push data to an already open UI window * @@ -455,7 +470,7 @@ nanoui is used to open and update nano browser uis var/list/send_data = get_send_data(data) //user << list2json(data) // used for debugging - user << output(list2params(list(list2json(send_data))),"[window_id].browser:receiveUpdateData") + user << output(list2params(list(list2json(send_data,cached_data))),"[window_id].browser:receiveUpdateData") /** * This Topic() proc is called whenever a user clicks on a link within a Nano UI diff --git a/nano/templates/pda.tmpl b/nano/templates/pda.tmpl index 81a75a2500..38cc5ef945 100644 --- a/nano/templates/pda.tmpl +++ b/nano/templates/pda.tmpl @@ -294,12 +294,12 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{:helper.link('Reply', 'comment', {'choice' : "Message", 'target': data.active_conversation}, null, 'fixedLeft')}} - {{else data.mode== 41}} + {{else data.mode== 41}}
- {{if data.manifest.heads.length}} + {{if data.cached.heads.length}} - {{for data.manifest["heads"]}} + {{for data.cached["heads"]}} {{if value.rank == "Captain"}} {{else}} @@ -307,9 +307,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.sec.length}} + {{if data.cached.sec.length}} - {{for data.manifest["sec"]}} + {{for data.cached["sec"]}} {{if value.rank == "Head of Security"}} {{else}} @@ -317,9 +317,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.eng.length}} + {{if data.cached.eng.length}} - {{for data.manifest["eng"]}} + {{for data.cached["eng"]}} {{if value.rank == "Chief Engineer"}} {{else}} @@ -327,9 +327,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.med.length}} + {{if data.cached.med.length}} - {{for data.manifest["med"]}} + {{for data.cached["med"]}} {{if value.rank == "Chief Medical Officer"}} {{else}} @@ -337,9 +337,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.sci.length}} + {{if data.cached.sci.length}} - {{for data.manifest["sci"]}} + {{for data.cached["sci"]}} {{if value.rank == "Research Director"}} {{else}} @@ -347,9 +347,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.civ.length}} + {{if data.cached.civ.length}} - {{for data.manifest["civ"]}} + {{for data.cached["civ"]}} {{if value.rank == "Head of Personnel"}} {{else}} @@ -357,9 +357,9 @@ Used In File(s): \code\game\objects\items\devices\PDA\PDA.dm {{/if}} {{/for}} {{/if}} - {{if data.manifest.misc.length}} + {{if data.cached.misc.length}} - {{for data.manifest["misc"]}} + {{for data.cached["misc"]}} {{/for}} {{/if}} From c0469fc9b6134a32189cf551452ac7780e511cf5 Mon Sep 17 00:00:00 2001 From: ccomp5950 Date: Sun, 25 Jan 2015 07:15:58 -0500 Subject: [PATCH 2/4] Security camera console now also caches it' list of cameras. FUCKING HUGE. --- code/game/machinery/camera/camera.dm | 11 ++++- code/game/machinery/computer/camera.dm | 56 +++++++++++++++------- nano/templates/sec_camera.tmpl | 4 +- nano/templates/sec_camera_map_content.tmpl | 4 +- 4 files changed, 52 insertions(+), 23 deletions(-) diff --git a/code/game/machinery/camera/camera.dm b/code/game/machinery/camera/camera.dm index 8fe3387467..d631ca46df 100644 --- a/code/game/machinery/camera/camera.dm +++ b/code/game/machinery/camera/camera.dm @@ -36,6 +36,9 @@ wires = new(src) assembly = new(src) assembly.state = 4 + + invalidateCameraCache() + /* // Use this to look for cameras that have the same c_tag. for(var/obj/machinery/camera/C in cameranet.cameras) var/list/tempnetwork = C.network&src.network @@ -61,6 +64,7 @@ /obj/machinery/camera/emp_act(severity) if(!isEmpProof()) if(prob(100/severity)) + invalidateCameraCache() stat |= EMPED SetLuminosity(0) kick_viewers() @@ -71,7 +75,7 @@ stat &= ~EMPED cancelCameraAlarm() update_icon() - + invalidateCameraCache() ..() /obj/machinery/camera/bullet_act(var/obj/item/projectile/P) @@ -118,7 +122,7 @@ destroy() /obj/machinery/camera/attackby(obj/W as obj, mob/living/user as mob) - + invalidateCameraCache() // DECONSTRUCTION if(isscrewdriver(W)) //user << "You start to [panel_open ? "close" : "open"] the camera's panel." @@ -199,6 +203,7 @@ //legacy support, if choice is != 1 then just kick viewers without changing status kick_viewers() else + invalidateCameraCache() set_status( !src.status ) if (!(src.status)) visible_message("\red [user] has deactivated [src]!") @@ -218,6 +223,7 @@ //Used when someone breaks a camera /obj/machinery/camera/proc/destroy() + invalidateCameraCache() stat |= BROKEN kick_viewers() triggerCameraAlarm() @@ -232,6 +238,7 @@ /obj/machinery/camera/proc/set_status(var/newstatus) if (status != newstatus) status = newstatus + invalidateCameraCache() // now disconnect anyone using the camera //Apparently, this will disconnect anyone even if the camera was re-activated. //I guess that doesn't matter since they couldn't use it anyway? diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index 0a7f27d701..7ffd7d1599 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -1,5 +1,8 @@ //This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31 +/proc/invalidateCameraCache() + for(var/obj/machinery/computer/security/s in world) + s.camera_cache = null /obj/machinery/computer/security name = "security camera monitor" @@ -10,6 +13,7 @@ var/list/network = list("SS13") var/mapping = 0//For the overview file, interesting bit of code. circuit = /obj/item/weapon/circuitboard/security + var/camera_cache = null attack_ai(var/mob/user as mob) @@ -32,29 +36,46 @@ data["current"] = null - var/list/L = list() - for (var/obj/machinery/camera/C in cameranet.cameras) - if(can_access_camera(C)) - L.Add(C) + if(isnull(camera_cache)) + var/list/L = list() + for (var/obj/machinery/camera/C in cameranet.cameras) + if(can_access_camera(C)) + L.Add(C) + camera_sort(L) - camera_sort(L) + var/cameras[0] + for(var/obj/machinery/camera/C in L) + var/cam[0] + cam["name"] = C.c_tag + cam["deact"] = !C.can_use() + cam["camera"] = "\ref[C]" + cam["x"] = C.x + cam["y"] = C.y + cam["z"] = C.z - var/cameras[0] - for(var/obj/machinery/camera/C in L) - var/cam[0] - cam["name"] = C.c_tag - cam["deact"] = !C.can_use() - cam["camera"] = "\ref[C]" - cam["x"] = C.x - cam["y"] = C.y - cam["z"] = C.z + cameras[++cameras.len] = cam - cameras[++cameras.len] = cam + if(C == current) + data["current"] = cam + + var/list/camera_list = list("cameras" = cameras) + camera_cache=list2json(camera_list) + + else + if(current) + var/cam[0] + cam["name"] = current.c_tag + cam["deact"] = !current.can_use() + cam["camera"] = "\ref[current]" + cam["x"] = current.x + cam["y"] = current.y + cam["z"] = current.z - if(C == current) data["current"] = cam + - data["cameras"] = cameras + if(ui) + ui.load_cached_data(camera_cache) ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) if (!ui) @@ -65,6 +86,7 @@ // adding a template with the key "mapHeader" replaces the map header content ui.add_template("mapHeader", "sec_camera_map_header.tmpl") + ui.load_cached_data(camera_cache) ui.set_initial_data(data) ui.open() ui.set_auto_update(1) diff --git a/nano/templates/sec_camera.tmpl b/nano/templates/sec_camera.tmpl index ea18fb2047..886cb0f87c 100644 --- a/nano/templates/sec_camera.tmpl +++ b/nano/templates/sec_camera.tmpl @@ -12,7 +12,7 @@ Used In File(s): \code\game\machinery\computer\camera.dm
None
{{/if}} -{{for data.cameras}} +{{for data.cached.cameras}} {{if data.current && value.name == data.current.name}} {{:helper.link(value.name, '', {'switchTo' : value.camera}, 'selected')}} {{else value.deact}} @@ -20,4 +20,4 @@ Used In File(s): \code\game\machinery\computer\camera.dm {{else}} {{:helper.link(value.name, '', {'switchTo' : value.camera})}} {{/if}} -{{/for}} \ No newline at end of file +{{/for}} diff --git a/nano/templates/sec_camera_map_content.tmpl b/nano/templates/sec_camera_map_content.tmpl index 52dc8aeadd..55d9e05d4d 100644 --- a/nano/templates/sec_camera_map_content.tmpl +++ b/nano/templates/sec_camera_map_content.tmpl @@ -2,7 +2,7 @@ Title: Security Camera Console (Map content) Used In File(s): \code\game\machinery\computer\camera.dm --> -{{for data.cameras}} +{{for data.cached.cameras}} {{if value.z == 1}}
{{if data.current && value.name == data.current.name}} @@ -17,4 +17,4 @@ Used In File(s): \code\game\machinery\computer\camera.dm
{{/if}} -{{/for}} \ No newline at end of file +{{/for}} From 44a9a722d020ec266ae2955405204f20c6dff04f Mon Sep 17 00:00:00 2001 From: ccomp5950 Date: Sun, 25 Jan 2015 07:21:14 -0500 Subject: [PATCH 3/4] Removed unused code that was intended for a different implenetation. --- code/defines/obj.dm | 2 +- code/game/objects/items/devices/PDA/PDA.dm | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/code/defines/obj.dm b/code/defines/obj.dm index a65db71d76..390add6394 100644 --- a/code/defines/obj.dm +++ b/code/defines/obj.dm @@ -175,7 +175,7 @@ using /obj/effect/datacore/proc/manifest_inject( ), or manifest_insert( ) var/global/list/PDA_Manifest = list() var/global/ManifestJSON -/obj/effect/datacore/proc/get_manifest_json(var/client/c = null) +/obj/effect/datacore/proc/get_manifest_json() if(PDA_Manifest.len) return var/heads[0] diff --git a/code/game/objects/items/devices/PDA/PDA.dm b/code/game/objects/items/devices/PDA/PDA.dm index a7b69c4a17..be428f4fd0 100755 --- a/code/game/objects/items/devices/PDA/PDA.dm +++ b/code/game/objects/items/devices/PDA/PDA.dm @@ -464,7 +464,7 @@ var/global/list/obj/item/device/pda/PDAs = list() data["convo_job"] = sanitize(c["job"]) break if(mode==41) - data_core.get_manifest_json(user.client) + data_core.get_manifest_json() if(mode==3) @@ -537,12 +537,12 @@ var/global/list/obj/item/device/pda/PDAs = list() // update the ui if it exists, returns null if no ui is passed/found if(ui) ui.load_cached_data(ManifestJSON) - + ui = nanomanager.try_update_ui(user, src, ui_key, ui, data, force_open) if (!ui) // the ui does not exist, so we'll create a new() one - // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm + // for a list of parameters and their descriptions see the code docs in \code\modules\nano\nanoui.dm ui = new(user, src, ui_key, "pda.tmpl", title, 520, 400) // when the ui is first opened this is the data it will use From 052ed36f7b9df62c3eea3ff57ea1c7a870571e27 Mon Sep 17 00:00:00 2001 From: ccomp5950 Date: Sun, 25 Jan 2015 07:47:55 -0500 Subject: [PATCH 4/4] Sanitized camera names removes the y infront of certain cameras names. --- code/game/machinery/computer/camera.dm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index 7ffd7d1599..bf1b1afab9 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -46,7 +46,7 @@ var/cameras[0] for(var/obj/machinery/camera/C in L) var/cam[0] - cam["name"] = C.c_tag + cam["name"] = sanitize(C.c_tag) cam["deact"] = !C.can_use() cam["camera"] = "\ref[C]" cam["x"] = C.x
Command
{{:value.name}}{{:value.rank}}{{:value.active}}
Security
{{:value.name}}{{:value.rank}}{{:value.active}}
Engineering
{{:value.name}}{{:value.rank}}{{:value.active}}
Medical
{{:value.name}}{{:value.rank}}{{:value.active}}
Science
{{:value.name}}{{:value.rank}}{{:value.active}}
Civilian
{{:value.name}}{{:value.rank}}{{:value.active}}
Misc
{{:value.name}}{{:value.rank}}{{:value.active}}