Files
Bubberstation/code/datums/components/areabound.dm
SkyratBot 067188d366 [MIRROR] Micro-optimize qdel by only permitting one parameter [MDB IGNORE] (#25889)
* Micro-optimize qdel by only permitting one parameter (#80628)

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.

* Micro-optimize qdel by only permitting one parameter

---------

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2023-12-29 14:41:12 +00:00

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)
. = ..()