Merge pull request #7937 from Ccomp5950/cached_json

Cached json (Improvements for camera monitor and PDA - Manifest)
This commit is contained in:
PsiOmegaDelta
2015-01-25 20:37:24 +01:00
10 changed files with 103 additions and 48 deletions

View File

@@ -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()
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

View File

@@ -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 << "<span class='notice'>You start to [panel_open ? "close" : "open"] the camera's panel.</span>"
@@ -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?

View File

@@ -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"] = sanitize(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)

View File

@@ -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()
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
// 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()

View File

@@ -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))

View File

@@ -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)

View File

@@ -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