From 0ac63dbde7971dfde658462fcfb86ff4d43fc3fd Mon Sep 17 00:00:00 2001 From: ninjanomnom Date: Wed, 13 Jun 2018 19:18:44 -0400 Subject: [PATCH] Primary changes --- code/__DEFINES/components.dm | 2 ++ code/datums/components/README.md | 12 ++++++++---- code/datums/components/_component.dm | 14 +++++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/code/__DEFINES/components.dm b/code/__DEFINES/components.dm index fcc2b8301bc..7a124b045c8 100644 --- a/code/__DEFINES/components.dm +++ b/code/__DEFINES/components.dm @@ -1,3 +1,5 @@ +#define SEND_SIGNAL(target, sigtype, arguments...) ( !target.datum_components ? NONE : target._SendSignal(sigtype, list(##arguments)) ) + //shorthand #define GET_COMPONENT_FROM(varname, path, target) var##path/##varname = ##target.GetComponent(##path) #define GET_COMPONENT(varname, path) GET_COMPONENT_FROM(varname, path, src) diff --git a/code/datums/components/README.md b/code/datums/components/README.md index 4908ed6e25c..0a19f7d9ecb 100644 --- a/code/datums/components/README.md +++ b/code/datums/components/README.md @@ -64,6 +64,11 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo * Returns a reference to a component whose type MATCHES component_type if that component exists in the datum, null otherwise 1. `GET_COMPONENT(varname, component_type)` OR `GET_COMPONENT_FROM(varname, component_type, src)` * Shorthand for `var/component_type/varname = src.GetComponent(component_type)` +1. `SEND_SIGNAL(target, sigtype, ...)` (public, final) + * Use to send signals to target datum + * Extra arguments are to be specified in the signal definition + * Returns a bitflag with signal specific information assembled from all activated components + * Arguments are packaged in a list and handed off to _SendSignal() 1. `/datum/proc/AddComponent(component_type(type), ...) -> datum/component` (public, final) * Creates an instance of `component_type` in the datum and passes `...` to its `Initialize()` call * Sends the `COMSIG_COMPONENT_ADDED` signal to the datum @@ -80,10 +85,9 @@ Stands have a lot of procs which mimic mob procs. Rather than inserting hooks fo * Properly transfers ownership of a component from one datum to another * Signals `COMSIG_COMPONENT_REMOVING` on the parent * Called on the datum you want to own the component with another datum's component -1. `/datum/proc/SendSignal(signal, ...)` (public, final) - * Call to send a signal to the components of the target datum - * Extra arguments are to be specified in the signal definition - * Returns a bitflag with signal specific information assembled from all activated components +1. `/datum/proc/_SendSignal(signal, list/arguments)` (private, final) + * Handles most of the actual signaling procedure + * Will runtime if used on datums with an empty component list 1. `/datum/component/New(datum/parent, ...)` (private, final) * Runs internal setup for the component * Extra arguments are passed to `Initialize()` diff --git a/code/datums/components/_component.dm b/code/datums/components/_component.dm index 57aca592f32..15ff482ba3f 100644 --- a/code/datums/components/_component.dm +++ b/code/datums/components/_component.dm @@ -57,7 +57,7 @@ if(!force) _RemoveFromParent() if(!silent) - P.SendSignal(COMSIG_COMPONENT_REMOVING, src) + SEND_SIGNAL(P, COMSIG_COMPONENT_REMOVING, src) parent = null LAZYCLEARLIST(signal_procs) return ..() @@ -117,12 +117,8 @@ current_type = type2parent(current_type) . += current_type -/datum/proc/SendSignal(sigtype, ...) - var/list/comps = datum_components - if(!comps) - return NONE - var/list/arguments = args.Copy(2) - var/target = comps[/datum/component] +/datum/proc/_SendSignal(sigtype, list/arguments) + var/target = datum_components[/datum/component] if(!length(target)) var/datum/component/C = target if(!C.enabled) @@ -225,7 +221,7 @@ new_comp = new nt(arglist(args)) // Dupes are allowed, act like normal if(!old_comp && !QDELETED(new_comp)) // Nothing related to duplicate components happened and the new component is healthy - SendSignal(COMSIG_COMPONENT_ADDED, new_comp) + SEND_SIGNAL(src, COMSIG_COMPONENT_ADDED, new_comp) return new_comp return old_comp @@ -240,7 +236,7 @@ var/datum/old_parent = parent PreTransfer() _RemoveFromParent() - old_parent.SendSignal(COMSIG_COMPONENT_REMOVING, src) + SEND_SIGNAL(old_parent, COMSIG_COMPONENT_REMOVING, src) /datum/proc/TakeComponent(datum/component/target) if(!target)