mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-11 10:11:09 +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.
32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
/// Movables with this component will automatically return to their original turf if moved outside their initial area
|
|
/datum/component/areabound
|
|
var/area/bound_area
|
|
var/turf/reset_turf
|
|
var/datum/movement_detector/move_tracker
|
|
var/moving = FALSE //Used to prevent infinite recursion if your reset turf places you somewhere on enter or something
|
|
|
|
/datum/component/areabound/Initialize()
|
|
if(!ismovable(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
bound_area = get_area(parent)
|
|
reset_turf = get_turf(parent)
|
|
move_tracker = new(parent,CALLBACK(src, PROC_REF(check_bounds)))
|
|
|
|
/datum/component/areabound/proc/check_bounds()
|
|
var/atom/movable/AM = parent
|
|
var/area/current = get_area(AM)
|
|
if(current != bound_area)
|
|
if(!reset_turf || reset_turf.loc != bound_area)
|
|
stack_trace("Invalid areabound configuration") //qdel(src)
|
|
return
|
|
if(moving)
|
|
stack_trace("Moved during a reset move, giving up to prevent infinite recursion. Turf: [reset_turf.type] at [reset_turf.x], [reset_turf.y], [reset_turf.z]")
|
|
return
|
|
moving = TRUE
|
|
AM.forceMove(reset_turf)
|
|
moving = FALSE
|
|
|
|
/datum/component/areabound/Destroy(force)
|
|
QDEL_NULL(move_tracker)
|
|
. = ..()
|