Files
Bubberstation/code/datums/elements/earhealing.dm
T
MothblocksandGitHub fa7688d043 Save 0.6-0.7s of init time by splitting registering lists of signals into its own proc, and optimizing QDELETED (#71056)
- Makes QDELETED use isnull(x) instead of !x, giving about 0.2 to 0.25s
of speed.
- Make disposal constructs only update icon state rather than go through
expensive overlay code. Unfortunately did not have much effect, but is
something they should've been doing nonetheless.
- Makes RegisterSignal only take signals directly as opposed to
allocating a fresh list of signals. Very few consumers actually used
this and it costs about 0.4s. Also I think this is just a bad API anyway
and that separate procs are important

`\bRegisterSignal\((.*)list\(` replaced with `RegisterSignals($1list(`
2022-11-22 07:40:05 +00:00

35 lines
1.2 KiB
Plaintext

/datum/element/earhealing
element_flags = ELEMENT_DETACH_ON_HOST_DESTROY
var/list/user_by_item = list()
/datum/element/earhealing/Attach(datum/target)
. = ..()
if(!isitem(target))
return ELEMENT_INCOMPATIBLE
RegisterSignals(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED), PROC_REF(on_equip))
/datum/element/earhealing/Detach(datum/target)
. = ..()
UnregisterSignal(target, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED))
user_by_item -= target
/datum/element/earhealing/proc/on_equip(datum/source, mob/living/carbon/user, slot)
SIGNAL_HANDLER
if((slot & ITEM_SLOT_EARS) && istype(user))
START_PROCESSING(SSdcs, src)
user_by_item[source] = user
else
user_by_item -= source
/datum/element/earhealing/process(delta_time)
for(var/i in user_by_item)
var/mob/living/carbon/user = user_by_item[i]
var/obj/item/organ/internal/ears/ears = user.getorganslot(ORGAN_SLOT_EARS)
if(!ears || !ears.damage || ears.organ_flags & ORGAN_FAILING)
continue
ears.deaf = max(ears.deaf - 0.25 * delta_time, (ears.damage < ears.maxHealth ? 0 : 1)) // Do not clear deafness if our ears are too damaged
ears.applyOrganDamage(-0.025 * delta_time)
CHECK_TICK