mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-14 03:32:00 +00:00
Productionizes #80615. The core optimization is this: ```patch - var/hint = to_delete.Destroy(arglist(args.Copy(2))) // Let our friend know they're about to get fucked up. + var/hint = to_delete.Destroy(force) // Let our friend know they're about to get fucked up. ``` We avoid a heap allocation in the form of copying the args over to a new list. A/B testing shows this results in 33% better overtime, and in a real round shaving off a full second of self time and 0.4 seconds of overtime--both of these would be doubled in the event this is merged as the new proc was only being run 50% of the time.
51 lines
2.0 KiB
Plaintext
51 lines
2.0 KiB
Plaintext
/// When a movable has this component AND they are in the contents of a container, they will no longer be able to use their hands and be immobilized until they are removed from the container. So far, this is only useful for smites.
|
|
/datum/component/itembound
|
|
/// Weak reference to the container that the movable is inside of.
|
|
var/datum/weakref/containerref
|
|
/// Detect any movement of the container
|
|
var/datum/movement_detector/move_tracker
|
|
|
|
/datum/component/itembound/Initialize(atom/movable/passed_container)
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
if(QDELETED(passed_container))
|
|
return
|
|
containerref = WEAKREF(passed_container)
|
|
RegisterSignal(passed_container, COMSIG_ATOM_EXAMINE_MORE, PROC_REF(on_examined))
|
|
move_tracker = new(parent, CALLBACK(src, PROC_REF(verify_containment)))
|
|
|
|
|
|
/datum/component/itembound/RegisterWithParent()
|
|
. = ..()
|
|
ADD_TRAIT(parent, TRAIT_INCAPACITATED, SMITE_TRAIT)
|
|
if (isliving(parent))
|
|
var/mob/living/living_parent = parent
|
|
living_parent.apply_status_effect(/datum/status_effect/grouped/stasis, STASIS_ADMIN)
|
|
|
|
/datum/component/itembound/UnregisterFromParent()
|
|
REMOVE_TRAIT(parent, TRAIT_INCAPACITATED, SMITE_TRAIT)
|
|
if (isliving(parent))
|
|
var/mob/living/living_parent = parent
|
|
living_parent.remove_status_effect(/datum/status_effect/grouped/stasis, STASIS_ADMIN)
|
|
return ..()
|
|
|
|
/datum/component/itembound/proc/on_examined(atom/source, mob/user, list/examine_list)
|
|
SIGNAL_HANDLER
|
|
examine_list += span_notice("If you hold it up to your ear, you can hear the screams of the damned.")
|
|
|
|
/// Ensure that when we move, we still are in the container. If not in the container, remove all the traits.
|
|
/datum/component/itembound/proc/verify_containment()
|
|
var/atom/movable/container = containerref.resolve()
|
|
if(!QDELETED(container) && container.contains(parent))
|
|
return
|
|
qdel(src)
|
|
|
|
/datum/component/itembound/Destroy(force)
|
|
var/atom/movable/container = containerref?.resolve()
|
|
if (!QDELETED(container))
|
|
UnregisterSignal(container, COMSIG_ATOM_EXAMINE_MORE)
|
|
containerref = null
|
|
QDEL_NULL(move_tracker)
|
|
return ..()
|
|
|