Files
Aurora.3/code/datums/weakref.dm
Lohikar 216039eb2e Add weakrefs, because just two types of ref wasn't confusing enough (#3020)
Ports a new type of reference from bay: weakrefs.

They validate type like hard-refs, but don't block GC like soft-refs. Performance-wise are worse than both, but generally more convenient than softrefs.
2017-07-13 21:04:19 +03:00

32 lines
624 B
Plaintext

/datum
var/datum/weakref/weakref
/datum/weakref
var/ref
#if DM_VERSION < 511
// Don't use this directly, use the WEAKREF macro.
/proc/_weakref(datum/D)
if(!istype(D) || QDELETED(D))
return
if(!D.weakref)
D.weakref = new(D)
return D.weakref
#endif
/datum/weakref/New(datum/D)
ref = SOFTREF(D)
/datum/weakref/Destroy(force = 0)
crash_with("Some fuck is trying to [force ? "force-" : ""]delete a weakref!")
if (!force)
return QDEL_HINT_LETMELIVE // feck off
return ..()
/datum/weakref/proc/resolve()
var/datum/D = locate(ref)
if (!QDELETED(D) && D.weakref == src)
. = D