mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2025-12-23 08:31:57 +00:00
Corrects a number of places where New() did not call ..(), and implements similar changes to attempt to ensure New()/initialize() complete running before qdel() runs. Cuts down on the number of created items during server start.
64 lines
1.5 KiB
Plaintext
64 lines
1.5 KiB
Plaintext
/datum/observ
|
|
var/list/listeners
|
|
|
|
/datum/observ/Destroy()
|
|
if(listeners)
|
|
for(var/listener in listeners)
|
|
unregister(listener)
|
|
listeners.Cut()
|
|
return ..()
|
|
|
|
/datum/observ/proc/register(var/datum/procOwner, var/proc_call)
|
|
if(!(procOwner && procOwner.destruction))
|
|
return
|
|
if(!listeners)
|
|
listeners = list()
|
|
listeners[procOwner] = proc_call
|
|
procOwner.destruction.register(src, /datum/observ/proc/unregister)
|
|
|
|
/datum/observ/proc/unregister(var/datum/procOwner)
|
|
if(!(listeners && procOwner && procOwner.destruction))
|
|
return
|
|
listeners -= procOwner
|
|
procOwner.destruction.unregister(src)
|
|
|
|
/datum/observ/proc/raise_event(var/list/args = list())
|
|
if(!listeners)
|
|
return
|
|
for(var/listener in listeners)
|
|
call(listener, listeners[listener]) (arglist(args))
|
|
|
|
/***********************
|
|
* Destruction Handling *
|
|
***********************/
|
|
/datum
|
|
var/datum/observ/destruction
|
|
|
|
/datum/New()
|
|
init_observers()
|
|
..()
|
|
|
|
/datum/Destroy()
|
|
destroy_observers()
|
|
return ..()
|
|
|
|
/datum/proc/init_observers()
|
|
destruction = new()
|
|
|
|
/datum/proc/destroy_observers()
|
|
if(!destruction)
|
|
return FALSE
|
|
|
|
destruction.raise_event(list(src))
|
|
qdel(destruction)
|
|
destruction = null
|
|
return TRUE
|
|
|
|
// This ensures that observer handlers don't create their own observer handlers, which create their own handlers, which create...
|
|
/datum/observ/init_observers()
|
|
return
|
|
|
|
// And this ensures that observer handlers don't attempt to notify others about their own death while being unable to.
|
|
/datum/observ/destroy_observers()
|
|
return
|