Files
Bubberstation/code/game/objects/items/broom.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

115 lines
3.7 KiB
Plaintext

/// Max number of atoms a broom can sweep at once
#define BROOM_PUSH_LIMIT 20
/obj/item/pushbroom
name = "push broom"
desc = "This is my BROOMSTICK! It can be used manually or braced with two hands to sweep items as you move. It has a telescopic handle for compact storage."
icon = 'icons/obj/janitor.dmi'
icon_state = "broom0"
lefthand_file = 'icons/mob/inhands/equipment/custodial_lefthand.dmi'
righthand_file = 'icons/mob/inhands/equipment/custodial_righthand.dmi'
force = 8
throwforce = 10
throw_speed = 3
throw_range = 7
w_class = WEIGHT_CLASS_NORMAL
attack_verb_continuous = list("sweeps", "brushes off", "bludgeons", "whacks")
attack_verb_simple = list("sweep", "brush off", "bludgeon", "whack")
resistance_flags = FLAMMABLE
/obj/item/pushbroom/Initialize()
. = ..()
RegisterSignal(src, COMSIG_TWOHANDED_WIELD, .proc/on_wield)
RegisterSignal(src, COMSIG_TWOHANDED_UNWIELD, .proc/on_unwield)
/obj/item/pushbroom/ComponentInitialize()
. = ..()
AddComponent(/datum/component/two_handed, force_unwielded=8, force_wielded=12, icon_wielded="broom1")
/obj/item/pushbroom/update_icon_state()
icon_state = "broom0"
/**
* Handles registering the sweep proc when the broom is wielded
*
* Arguments:
* * source - The source of the on_wield proc call
* * user - The user which is wielding the broom
*/
/obj/item/pushbroom/proc/on_wield(obj/item/source, mob/user)
SIGNAL_HANDLER
to_chat(user, "<span class='notice'>You brace the [src] against the ground in a firm sweeping stance.</span>")
RegisterSignal(user, COMSIG_MOVABLE_MOVED, .proc/sweep)
/**
* Handles unregistering the sweep proc when the broom is unwielded
*
* Arguments:
* * source - The source of the on_unwield proc call
* * user - The user which is unwielding the broom
*/
/obj/item/pushbroom/proc/on_unwield(obj/item/source, mob/user)
SIGNAL_HANDLER
UnregisterSignal(user, COMSIG_MOVABLE_MOVED)
/obj/item/pushbroom/afterattack(atom/A, mob/user, proximity)
. = ..()
if(!proximity)
return
sweep(user, A, FALSE)
/**
* Attempts to push up to BROOM_PUSH_LIMIT atoms from a given location the user's faced direction
*
* Arguments:
* * user - The user of the pushbroom
* * A - The atom which is located at the location to push atoms from
* * moving - Boolean argument declaring if the sweep is from generated from movement or not
*/
/obj/item/pushbroom/proc/sweep(mob/user, atom/A, moving = TRUE)
SIGNAL_HANDLER
var/turf/target = moving ? user.loc : (isturf(A) ? A : A.loc)
if (!isturf(target))
return
if (locate(/obj/structure/table) in target.contents)
return
var/i = 1
var/turf/target_turf = get_step(target, user.dir)
var/obj/machinery/disposal/bin/target_bin = locate(/obj/machinery/disposal/bin) in target_turf.contents
for(var/obj/item/garbage in target.contents)
if(!garbage.anchored)
if (target_bin)
garbage.forceMove(target_bin)
else
garbage.Move(target_turf, user.dir)
i++
if(i > BROOM_PUSH_LIMIT)
break
if(i > 1)
if (target_bin)
target_bin.update_icon()
to_chat(user, "<span class='notice'>You sweep the pile of garbage into [target_bin].</span>")
playsound(loc, 'sound/weapons/thudswoosh.ogg', 30, TRUE, -1)
/**
* Attempts to insert the push broom into a janicart
*
* Arguments:
* * user - The user of the push broom
* * J - The janicart to insert into
*/
/obj/item/pushbroom/proc/janicart_insert(mob/user, obj/structure/janitorialcart/J) //bless you whoever fixes this copypasta
J.put_in_cart(src, user)
J.mybroom=src
J.update_icon()
/obj/item/pushbroom/cyborg
name = "robotic push broom"
/obj/item/pushbroom/cyborg/janicart_insert(mob/user, obj/structure/janitorialcart/J)
to_chat(user, "<span class='notice'>You cannot place your [src] into the [J]</span>")
return FALSE