This commit is contained in:
kevinz000
2017-11-08 22:48:03 -08:00
committed by CitadelStationBot
parent ea44e4a1d9
commit b44e31951d
7 changed files with 73 additions and 12 deletions
+2
View File
@@ -10,6 +10,8 @@
#define isatom(A) (istype(A, /atom))
#define isweakref(D) (istype(D, /datum/weakref))
//Turfs
//#define isturf(A) (istype(A, /turf)) This is actually a byond built-in. Added here for completeness sake.
+19 -1
View File
@@ -1441,4 +1441,22 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)
var/time_clock = num2hex(TICK_DELTA_TO_MS(world.tick_usage), 3)
return "{[time_high]-[time_mid]-[GUID_VERSION][time_low]-[GUID_VARIANT][time_clock]-[node_id]}"
<<<<<<< HEAD
return "{[time_high]-[time_mid]-[GUID_VERSION][time_low]-[GUID_VARIANT][time_clock]-[node_id]}"
=======
return "{[time_high]-[time_mid]-[GUID_VERSION][time_low]-[GUID_VARIANT][time_clock]-[node_id]}"
// \ref behaviour got changed in 512 so this is necesary to replicate old behaviour.
// If it ever becomes necesary to get a more performant REF(), this lies here in wait
// #define REF(thing) (thing && istype(thing, /datum) && thing:use_tag && thing:tag ? "[thing:tag]" : "\ref[thing]")
/proc/REF(input)
if(istype(input, /datum))
var/datum/thing = input
if(thing.use_tag)
if(!thing.tag)
WARNING("A ref was requested of an object with use_tag set but no tag: [thing]")
thing.use_tag = FALSE
else
return "\[[url_encode(thing.tag)]\]"
return "\ref[input]"
>>>>>>> 4edd802... Weak references + Cameras now use them (#32504)
+6
View File
@@ -3,6 +3,11 @@
var/list/active_timers //for SStimer
var/list/datum_components //for /datum/components
var/ui_screen = "home" //for tgui
<<<<<<< HEAD
=======
var/use_tag = FALSE
var/datum/weakref/weak_reference
>>>>>>> 4edd802... Weak references + Cameras now use them (#32504)
#ifdef TESTING
var/running_find_references
@@ -14,6 +19,7 @@
// Return the appropriate QDEL_HINT; in most cases this is QDEL_HINT_QUEUE.
/datum/proc/Destroy(force=FALSE, ...)
tag = null
weak_reference = null //ensure prompt GCing of weakref.
var/list/timers = active_timers
active_timers = null
for(var/thing in timers)
+19
View File
@@ -0,0 +1,19 @@
/proc/WEAKREF(datum/input)
if(istype(input) && !QDELETED(input))
if(!input.weak_reference)
input.weak_reference = new /datum/weakref(input)
return input.weak_reference
/datum/weakref
var/reference
/datum/weakref/New(datum/thing)
reference = REF(thing)
/datum/weakref/Destroy()
return QDEL_HINT_LETMELIVE //Let BYOND autoGC thiswhen nothing is using it anymore.
/datum/weakref/proc/resolve()
var/datum/D = locate(reference)
return D.weak_reference == src? D : null
+6 -1
View File
@@ -2,7 +2,7 @@
name = "AI Monitored Area"
clockwork_warp_allowed = FALSE
var/list/obj/machinery/camera/motioncameras = list()
var/list/motionTargets = list()
var/list/datum/weakref/motionTargets = list()
/area/ai_monitored/Initialize(mapload)
. = ..()
@@ -27,5 +27,10 @@
if (ismob(O) && motioncameras.len)
for(var/X in motioncameras)
var/obj/machinery/camera/cam = X
<<<<<<< HEAD
cam.lostTarget(O)
return
=======
cam.lostTargetRef(WEAKREF(O))
return
>>>>>>> 4edd802... Weak references + Cameras now use them (#32504)
+20 -10
View File
@@ -1,6 +1,6 @@
/obj/machinery/camera
var/list/localMotionTargets = list()
var/list/datum/weakref/localMotionTargets = list()
var/detectTime = 0
var/area/ai_monitored/area_motion = null
var/alarm_delay = 30 // Don't forget, there's another 3 seconds in queueAlarm()
@@ -15,11 +15,11 @@
if (elapsed > alarm_delay)
triggerAlarm()
else if (detectTime == -1)
for (var/targetref in getTargetList())
var/mob/target = locate(targetref) in GLOB.mob_list
if (QDELETED(target) || target.stat == DEAD || (!area_motion && !in_range(src, target)))
for (var/datum/weakref/targetref in getTargetList())
var/mob/target = targetref.resolve()
if(QDELETED(target) || target.stat == DEAD || (!area_motion && !in_range(src, target)))
//If not part of a monitored area and the camera is not in range or the target is dead
lostTarget(target)
lostTargetRef(targetref)
/obj/machinery/camera/proc/getTargetList()
if(area_motion)
@@ -28,22 +28,32 @@
/obj/machinery/camera/proc/newTarget(mob/target)
if(isAI(target))
return 0
return FALSE
if (detectTime == 0)
detectTime = world.time // start the clock
var/list/targets = getTargetList()
<<<<<<< HEAD
targets |= "\ref[target]"
return 1
=======
targets |= WEAKREF(target)
return TRUE
>>>>>>> 4edd802... Weak references + Cameras now use them (#32504)
/obj/machinery/camera/Destroy()
var/area/ai_monitored/A = get_area(src)
localMotionTargets = null
if(istype(A))
A.motioncameras -= src
return ..()
/obj/machinery/camera/proc/lostTarget(mob/target)
/obj/machinery/camera/proc/lostTargetRef(datum/weakref/R)
var/list/targets = getTargetList()
<<<<<<< HEAD
targets -= "\ref[target]"
=======
targets -= R
>>>>>>> 4edd802... Weak references + Cameras now use them (#32504)
if (targets.len == 0)
cancelAlarm()
@@ -53,16 +63,16 @@
if (status)
aiPlayer.cancelAlarm("Motion", get_area(src), src)
detectTime = 0
return 1
return TRUE
/obj/machinery/camera/proc/triggerAlarm()
if (!detectTime)
return 0
return FALSE
for (var/mob/living/silicon/aiPlayer in GLOB.player_list)
if (status)
aiPlayer.triggerAlarm("Motion", get_area(src), list(src), src)
detectTime = -1
return 1
return TRUE
/obj/machinery/camera/HasProximity(atom/movable/AM as mob|obj)
// Motion cameras outside of an "ai monitored" area will use this to detect stuff.
+1
View File
@@ -304,6 +304,7 @@
#include "code\datums\soullink.dm"
#include "code\datums\spawners_menu.dm"
#include "code\datums\verbs.dm"
#include "code\datums\weakrefs.dm"
#include "code\datums\world_topic.dm"
#include "code\datums\actions\flightsuit.dm"
#include "code\datums\actions\ninja.dm"