Files
Bubberstation/code/datums/elements/cult_halo.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

50 lines
1.6 KiB
Plaintext

/**
* # Cult halo element
*
* Applies and removes the cult halo
*/
/datum/element/cult_halo
/datum/element/cult_halo/Attach(datum/target, initial_delay = 20 SECONDS)
. = ..()
if (!isliving(target))
return ELEMENT_INCOMPATIBLE
// Register signals for mob transformation to prevent premature halo removal
RegisterSignals(target, list(COMSIG_CHANGELING_TRANSFORM, COMSIG_MONKEY_HUMANIZE, COMSIG_HUMAN_MONKEYIZE), PROC_REF(set_halo))
addtimer(CALLBACK(src, PROC_REF(set_halo), target), initial_delay)
/**
* Halo setter proc
*
* Adds the cult halo overlays, and adds the halo trait to the mob.
*/
/datum/element/cult_halo/proc/set_halo(mob/living/target)
SIGNAL_HANDLER
ADD_TRAIT(target, TRAIT_CULT_HALO, CULT_TRAIT)
var/mutable_appearance/new_halo_overlay = mutable_appearance('icons/effects/cult/halo.dmi', "halo[rand(1, 6)]", -HALO_LAYER)
if (ishuman(target))
var/mob/living/carbon/human/human_parent = target
new /obj/effect/temp_visual/cult/sparks(get_turf(human_parent), human_parent.dir)
human_parent.overlays_standing[HALO_LAYER] = new_halo_overlay
human_parent.apply_overlay(HALO_LAYER)
else
target.add_overlay(new_halo_overlay)
/**
* Detach proc
*
* Removes the halo overlays, and trait from the mob
*/
/datum/element/cult_halo/Detach(mob/living/target, ...)
REMOVE_TRAIT(target, TRAIT_CULT_HALO, CULT_TRAIT)
if (ishuman(target))
var/mob/living/carbon/human/human_parent = target
human_parent.remove_overlay(HALO_LAYER)
human_parent.update_body()
else
target.cut_overlay(HALO_LAYER)
UnregisterSignal(target, list(COMSIG_CHANGELING_TRANSFORM, COMSIG_HUMAN_MONKEYIZE, COMSIG_MONKEY_HUMANIZE))
return ..()