From 66e9d9cfdf60740bca7bbe87ccf54c5b71af9f47 Mon Sep 17 00:00:00 2001 From: Leshana Date: Thu, 28 Dec 2017 12:51:19 -0500 Subject: [PATCH] Unify datum var definitions Inspired by https://github.com/tgstation/tgstation/pull/29636 Also consolidated some sideways overridden /datum/Delete() here to reduce proc-call overhead. --- code/controllers/subsystems/garbage.dm | 10 ---------- code/datums/datum.dm | 22 ++++++++++++++++++++++ code/datums/weakref.dm | 7 ------- polaris.dme | 1 + 4 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 code/datums/datum.dm diff --git a/code/controllers/subsystems/garbage.dm b/code/controllers/subsystems/garbage.dm index 32acbb272a..9deed740b6 100644 --- a/code/controllers/subsystems/garbage.dm +++ b/code/controllers/subsystems/garbage.dm @@ -331,16 +331,6 @@ SUBSYSTEM_DEF(garbage) else if(D.gc_destroyed == GC_CURRENTLY_BEING_QDELETED) CRASH("[D.type] destroy proc was called multiple times, likely due to a qdel loop in the Destroy logic") -// Default implementation of clean-up code. -// This should be overridden to remove all references pointing to the object being destroyed. -// Return the appropriate QDEL_HINT; in most cases this is QDEL_HINT_QUEUE. -/datum/proc/Destroy(force=FALSE) - tag = null - nanomanager.close_uis(src) - return QDEL_HINT_QUEUE - -/datum/var/gc_destroyed //Time when this object was destroyed. - #ifdef TESTING /datum/verb/find_refs() diff --git a/code/datums/datum.dm b/code/datums/datum.dm new file mode 100644 index 0000000000..f509b66042 --- /dev/null +++ b/code/datums/datum.dm @@ -0,0 +1,22 @@ +// +// datum defines! +// Note: Adding vars to /datum adds a var to EVERYTHING! Don't go overboard. +// + +/datum + var/gc_destroyed //Time when this object was destroyed. + var/weakref/weakref // Holder of weakref instance pointing to this datum + +#ifdef TESTING + var/tmp/running_find_references + var/tmp/last_find_references = 0 +#endif + +// Default implementation of clean-up code. +// This should be overridden to remove all references pointing to the object being destroyed. +// Return the appropriate QDEL_HINT; in most cases this is QDEL_HINT_QUEUE. +/datum/proc/Destroy(force=FALSE) + weakref = null // Clear this reference to ensure it's kept for as brief duration as possible. + tag = null + nanomanager.close_uis(src) + return QDEL_HINT_QUEUE diff --git a/code/datums/weakref.dm b/code/datums/weakref.dm index 348d73b0b2..6c17c18bca 100644 --- a/code/datums/weakref.dm +++ b/code/datums/weakref.dm @@ -1,10 +1,3 @@ -/datum - var/weakref/weakref - -/datum/Destroy() - weakref = null // Clear this reference to ensure it's kept for as brief duration as possible. - . = ..() - //obtain a weak reference to a datum /proc/weakref(datum/D) if(!istype(D)) diff --git a/polaris.dme b/polaris.dme index e09ddb0026..be6dea1a12 100644 --- a/polaris.dme +++ b/polaris.dme @@ -182,6 +182,7 @@ #include "code\datums\category.dm" #include "code\datums\computerfiles.dm" #include "code\datums\datacore.dm" +#include "code\datums\datum.dm" #include "code\datums\EPv2.dm" #include "code\datums\ghost_query.dm" #include "code\datums\hierarchy.dm"