From 895e78df1e2e4897753cfa35b6b4320683670ee7 Mon Sep 17 00:00:00 2001 From: Mloc Date: Sat, 9 May 2015 23:25:12 +0100 Subject: [PATCH] more lightweight camera caching no loops Signed-off-by: Mloc --- code/game/machinery/computer/camera.dm | 12 ++++++------ code/modules/alarm/alarm.dm | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/code/game/machinery/computer/camera.dm b/code/game/machinery/computer/camera.dm index a50436346d..8c81469297 100644 --- a/code/game/machinery/computer/camera.dm +++ b/code/game/machinery/computer/camera.dm @@ -1,11 +1,9 @@ //This file was auto-corrected by findeclaration.exe on 25.5.2012 20:42:31 +/var/camera_cache_id = 1 + /proc/invalidateCameraCache() - for(var/obj/machinery/computer/security/s in machines) - s.camera_cache = null - var/datum/alarm_handler/AHandler = new /datum/alarm_handler() - for(var/datum/alarm/A in AHandler.alarms) - A.cameras = null + camera_cache_id = (++camera_cache_id % 999999) /obj/machinery/computer/security name = "security camera monitor" @@ -15,6 +13,7 @@ var/last_pic = 1.0 var/list/network var/mapping = 0//For the overview file, interesting bit of code. + var/cache_id = 0 circuit = /obj/item/weapon/circuitboard/security var/camera_cache = null @@ -43,7 +42,8 @@ data["current"] = null - if(isnull(camera_cache)) + if(camera_cache_id != cache_id) + cache_id = camera_cache_id cameranet.process_sort() var/cameras[0] diff --git a/code/modules/alarm/alarm.dm b/code/modules/alarm/alarm.dm index 2d53ac3d09..aa88e170bf 100644 --- a/code/modules/alarm/alarm.dm +++ b/code/modules/alarm/alarm.dm @@ -18,6 +18,7 @@ var/list/sources = new() //List of sources triggering the alarm. Used to determine when the alarm should be cleared. var/list/sources_assoc = new() //Associative list of source triggers. Used to efficiently acquire the alarm source. var/list/cameras //List of cameras that can be switched to, if the player has that capability. + var/cache_id //ID for camera cache, changed by invalidateCameraCache(). var/area/last_area //The last acquired area, used should origin be lost (for example a destroyed borg containing an alarming camera). var/area/last_name //The last acquired name, used should origin be lost var/area/last_camera_area //The last area in which cameras where fetched, used to see if the camera list should be updated. @@ -74,8 +75,12 @@ return last_name /datum/alarm/proc/cameras() + // reset camera cache + if(camera_cache_id != cache_id) + cameras = null + cache_id = camera_cache_id // If the alarm origin has changed area, for example a borg containing an alarming camera, reset the list of cameras - if(cameras && (last_camera_area != alarm_area())) + else if(cameras && (last_camera_area != alarm_area())) cameras = null // The list of cameras is also reset by /proc/invalidateCameraCache()