mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-29 19:42:42 +00:00
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.
32 lines
624 B
Plaintext
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
|