Files
CHOMPStation2/code/game/machinery/camera/motion.dm
PsiOmegaDelta e7686dd3e7 Camera fixes and performance tweaks.
Improves camera EMP handling. Now uses a var and processing to determine when the EMP should end, preventing inconsistent states when a camera is EMPd multiple times.

Reduces the process and bandwidth need for cameras.
* There is now a common camera repository, responsible for setting up cameras once for every invalidation.
* Camera consoles now only updates when the camera cache is invalidated, not every second.
* The console now only presents one network at a time, and only sends the data necessary to view that network (as opposed to sending the data for all cameras).
2016-03-21 17:30:52 -04:00

65 lines
1.8 KiB
Plaintext

/obj/machinery/camera
var/list/motionTargets = list()
var/detectTime = 0
var/area/ai_monitored/area_motion = null
var/alarm_delay = 100 // Don't forget, there's another 10 seconds in queueAlarm()
flags = PROXMOVE
/obj/machinery/camera/internal_process()
// motion camera event loop
if (stat & (EMPED|NOPOWER))
return
if(!isMotion())
. = PROCESS_KILL
return
if (detectTime > 0)
var/elapsed = world.time - detectTime
if (elapsed > alarm_delay)
triggerAlarm()
else if (detectTime == -1)
for (var/mob/target in motionTargets)
if (target.stat == 2) lostTarget(target)
// If not detecting with motion camera...
if (!area_motion)
// See if the camera is still in range
if(!in_range(src, target))
// If they aren't in range, lose the target.
lostTarget(target)
/obj/machinery/camera/proc/newTarget(var/mob/target)
if (istype(target, /mob/living/silicon/ai)) return 0
if (detectTime == 0)
detectTime = world.time // start the clock
if (!(target in motionTargets))
motionTargets += target
return 1
/obj/machinery/camera/proc/lostTarget(var/mob/target)
if (target in motionTargets)
motionTargets -= target
if (motionTargets.len == 0)
cancelAlarm()
/obj/machinery/camera/proc/cancelAlarm()
if (!status || (stat & NOPOWER))
return 0
if (detectTime == -1)
motion_alarm.clearAlarm(loc, src)
detectTime = 0
return 1
/obj/machinery/camera/proc/triggerAlarm()
if (!status || (stat & NOPOWER))
return 0
if (!detectTime) return 0
motion_alarm.triggerAlarm(loc, src)
detectTime = -1
return 1
/obj/machinery/camera/HasProximity(atom/movable/AM as mob|obj)
// Motion cameras outside of an "ai monitored" area will use this to detect stuff.
if (!area_motion)
if(isliving(AM))
newTarget(AM)