[MIRROR] SendSignal() speedup (#2910)
* SendSignal() speedup (#30929) * Rename component.dm to _component.dm * Merges RecieveSignal() into SendSignal() * Makes ComponentActivated() and AfterComponentActivated() async * SendSignal() speedup
This commit is contained in:
committed by
Poojawa
parent
51d8182b13
commit
442689219e
@@ -62,7 +62,7 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo
|
||||
* Returns the component that was created. Or the old component in a dupe situation where `COMPONENT_DUPE_UNIQUE` was set
|
||||
1. `/datum/proc/LoadComponent(component_type(type), ...) -> datum/component` (public, final)
|
||||
* Equivalent to calling `GetComponent(component_type)` where, if the result would be `null`, returns `AddComponent(component_type, ...)` instead
|
||||
1. `/datum/proc/ComponentActivated(datum/component/C)` (abstract)
|
||||
1. `/datum/proc/ComponentActivated(datum/component/C)` (abstract, async)
|
||||
* Called on a component's `parent` after a signal recieved causes it to activate. `src` is the parameter
|
||||
* Will only be called if a component's callback returns `TRUE`
|
||||
1. `/datum/proc/TakeComponent(datum/component/C)` (public, final)
|
||||
@@ -87,7 +87,7 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo
|
||||
* Called on a component when a component of the same type was added to the same parent
|
||||
* See `/datum/component/var/dupe_mode`
|
||||
* `C`'s type will always be the same of the called component
|
||||
1. `/datum/component/proc/AfterComponentActivated()` (abstract)
|
||||
1. `/datum/component/proc/AfterComponentActivated()` (abstract, async)
|
||||
* Called on a component that was activated after it's `parent`'s `ComponentActivated()` is called
|
||||
1. `/datum/component/proc/OnTransfer(datum/new_parent)` (abstract, no-sleep)
|
||||
* Called before the new `parent` is assigned in `TakeComponent()`, after the remove signal, before the added signal
|
||||
@@ -101,8 +101,5 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo
|
||||
* If a previous registration is overwritten by the call, a runtime occurs. Setting `override` to TRUE prevents this
|
||||
* These callbacks run asyncronously
|
||||
* Returning `TRUE` from these callbacks will trigger a `TRUE` return from the `SendSignal()` that initiated it
|
||||
1. `/datum/component/proc/ReceiveSignal(signal, ...)` (virtual)
|
||||
* Called when a component recieves any signal and is enabled
|
||||
* Default implementation looks if the signal is registered and runs the appropriate proc
|
||||
|
||||
### See/Define signals and their arguments in __DEFINES\components.dm
|
||||
|
||||
@@ -110,15 +110,6 @@
|
||||
|
||||
procs[sig_type] = CALLBACK(src, proc_on_self)
|
||||
|
||||
/datum/component/proc/ReceiveSignal(sigtype, ...)
|
||||
var/list/sps = signal_procs
|
||||
var/datum/callback/CB = LAZYACCESS(sps, sigtype)
|
||||
if(!CB)
|
||||
return FALSE
|
||||
var/list/arguments = args.Copy()
|
||||
arguments.Cut(1, 2)
|
||||
return CB.InvokeAsync(arglist(arguments))
|
||||
|
||||
/datum/component/proc/InheritComponent(datum/component/C, i_am_original)
|
||||
return
|
||||
|
||||
@@ -126,6 +117,7 @@
|
||||
return
|
||||
|
||||
/datum/component/proc/AfterComponentActivated()
|
||||
set waitfor = FALSE
|
||||
return
|
||||
|
||||
/datum/component/proc/_GetInverseTypeList(current_type)
|
||||
@@ -136,26 +128,40 @@
|
||||
|
||||
/datum/proc/SendSignal(sigtype, ...)
|
||||
var/list/comps = datum_components
|
||||
. = FALSE
|
||||
if(!comps)
|
||||
return
|
||||
return FALSE
|
||||
var/list/arguments = args.Copy()
|
||||
arguments.Cut(1, 2)
|
||||
var/target = comps[/datum/component]
|
||||
if(!islist(target))
|
||||
var/datum/component/C = target
|
||||
if(C.enabled && C.ReceiveSignal(arglist(args)))
|
||||
if(!C.enabled)
|
||||
return FALSE
|
||||
var/list/sps = C.signal_procs
|
||||
var/datum/callback/CB = LAZYACCESS(sps, sigtype)
|
||||
if(!CB)
|
||||
return FALSE
|
||||
. = CB.InvokeAsync(arglist(arguments))
|
||||
if(.)
|
||||
ComponentActivated(C)
|
||||
C.AfterComponentActivated()
|
||||
return TRUE
|
||||
else
|
||||
. = FALSE
|
||||
for(var/I in target)
|
||||
var/datum/component/C = I
|
||||
if(!C.enabled)
|
||||
continue
|
||||
var/list/sps = C.signal_procs
|
||||
var/datum/callback/CB = LAZYACCESS(sps, sigtype)
|
||||
if(!CB)
|
||||
continue
|
||||
if(C.ReceiveSignal(arglist(args)))
|
||||
if(CB.InvokeAsync(arglist(arguments)))
|
||||
ComponentActivated(C)
|
||||
C.AfterComponentActivated()
|
||||
. = TRUE
|
||||
|
||||
/datum/proc/ComponentActivated(datum/component/C)
|
||||
set waitfor = FALSE
|
||||
return
|
||||
|
||||
/datum/proc/GetComponent(c_type)
|
||||
Reference in New Issue
Block a user