Files
Bubberstation/code/datums/components/manual_blinking.dm
SkyratBot e65a48e91f [MIRROR] Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking (#430)
* Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking (#52761)

Adds SIGNAL_HANDLER, a macro that sets SHOULD_NOT_SLEEP(TRUE). This should ideally be required on all new signal callbacks.

Adds BLOCKING_SIGNAL_HANDLER, a macro that does nothing except symbolize "this is an older signal that didn't necessitate a code rewrite". It should not be allowed for new work.

This comes from discussion around #52735, which yields by calling input, and (though it sets the return type beforehand) will not properly return the flag to prevent attack from slapping.

To fix 60% of the yielding cases, WrapAdminProcCall no longer waits for another admin's proc call to finish. I'm not an admin, so I don't know how many behinds this has saved, but if this is problematic for admins I can just make it so that it lets you do it anyway. I'm not sure what the point of this babysitting was anyway.

Requested by @optimumtact.
Changelog

cl
admin: Calling a proc while another admin is calling one will no longer wait for the first to finish. You will simply just have to call it again.
/cl

* Adds SIGNAL_HANDLER and SIGNAL_HANDLER_DOES_SLEEP to prevent signal callbacks from blocking

Co-authored-by: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com>
2020-08-19 20:17:28 -04:00

94 lines
2.9 KiB
Plaintext

/datum/component/manual_blinking
dupe_mode = COMPONENT_DUPE_UNIQUE
var/obj/item/organ/eyes/E
var/warn_grace = FALSE
var/warn_dying = FALSE
var/last_blink
var/check_every = 20 SECONDS
var/grace_period = 6 SECONDS
var/damage_rate = 1 // organ damage taken per tick
var/list/valid_emotes = list(/datum/emote/living/carbon/blink, /datum/emote/living/carbon/blink_r)
/datum/component/manual_blinking/Initialize()
if(!iscarbon(parent))
return COMPONENT_INCOMPATIBLE
var/mob/living/carbon/C = parent
E = C.getorganslot(ORGAN_SLOT_EYES)
if(E)
START_PROCESSING(SSdcs, src)
last_blink = world.time
to_chat(C, "<span class='notice'>You suddenly realize you're blinking manually.</span>")
/datum/component/manual_blinking/Destroy(force, silent)
E = null
STOP_PROCESSING(SSdcs, src)
to_chat(parent, "<span class='notice'>You revert back to automatic blinking.</span>")
return ..()
/datum/component/manual_blinking/RegisterWithParent()
RegisterSignal(parent, COMSIG_MOB_EMOTE, .proc/check_emote)
RegisterSignal(parent, COMSIG_CARBON_GAIN_ORGAN, .proc/check_added_organ)
RegisterSignal(parent, COMSIG_CARBON_LOSE_ORGAN, .proc/check_removed_organ)
RegisterSignal(parent, COMSIG_LIVING_REVIVE, .proc/restart)
RegisterSignal(parent, COMSIG_MOB_DEATH, .proc/pause)
/datum/component/manual_blinking/UnregisterFromParent()
UnregisterSignal(parent, COMSIG_MOB_EMOTE)
UnregisterSignal(parent, COMSIG_CARBON_GAIN_ORGAN)
UnregisterSignal(parent, COMSIG_CARBON_LOSE_ORGAN)
UnregisterSignal(parent, COMSIG_LIVING_REVIVE)
UnregisterSignal(parent, COMSIG_MOB_DEATH)
/datum/component/manual_blinking/proc/restart()
SIGNAL_HANDLER
START_PROCESSING(SSdcs, src)
/datum/component/manual_blinking/proc/pause()
SIGNAL_HANDLER
STOP_PROCESSING(SSdcs, src)
/datum/component/manual_blinking/process()
var/mob/living/carbon/C = parent
if(world.time > (last_blink + check_every + grace_period))
if(!warn_dying)
to_chat(C, "<span class='userdanger'>Your eyes begin to wither, you need to blink!</span>")
warn_dying = TRUE
E.applyOrganDamage(damage_rate)
else if(world.time > (last_blink + check_every))
if(!warn_grace)
to_chat(C, "<span class='danger'>You feel a need to blink!</span>")
warn_grace = TRUE
/datum/component/manual_blinking/proc/check_added_organ(mob/who_cares, obj/item/organ/O)
SIGNAL_HANDLER
var/obj/item/organ/eyes/new_eyes = O
if(istype(new_eyes,/obj/item/organ/eyes))
E = new_eyes
START_PROCESSING(SSdcs, src)
/datum/component/manual_blinking/proc/check_removed_organ(mob/who_cares, obj/item/organ/O)
SIGNAL_HANDLER
var/obj/item/organ/eyes/bye_beyes = O // oh come on, that's pretty good
if(istype(bye_beyes, /obj/item/organ/eyes))
E = null
STOP_PROCESSING(SSdcs, src)
/datum/component/manual_blinking/proc/check_emote(mob/living/carbon/user, datum/emote/emote)
SIGNAL_HANDLER
if(emote.type in valid_emotes)
warn_grace = FALSE
warn_dying = FALSE
last_blink = world.time