Files
Bubberstation/code/datums/components/spinny.dm
Mothblocks c1d68698fb 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.
2023-12-28 13:52:44 -08:00

34 lines
993 B
Plaintext

/**
* spinny.dm
*
* It's a component that spins things a whole bunch, like [proc/dance_rotate] but without the sleeps)
*/
/datum/component/spinny
dupe_mode = COMPONENT_DUPE_UNIQUE
/// How many turns are left?
var/steps_left
/// Turns clockwise by default, or counterclockwise if the reverse argument is TRUE
var/turn_degrees = 90
/datum/component/spinny/Initialize(steps = 12, reverse = FALSE)
if(!isatom(parent))
return COMPONENT_INCOMPATIBLE
steps_left = steps
turn_degrees = (reverse ? -90 : 90)
START_PROCESSING(SSfastprocess, src)
/datum/component/spinny/Destroy(force)
STOP_PROCESSING(SSfastprocess, src)
return ..()
/datum/component/spinny/process(seconds_per_tick)
steps_left--
var/atom/spinny_boy = parent
if(!istype(spinny_boy) || steps_left <= 0)
qdel(src)
return
// 25% chance to make 2 turns instead of 1 since the old dance_rotate wasn't strictly clockwise/counterclockwise
spinny_boy.setDir(turn(spinny_boy.dir, turn_degrees * (prob(25) ? 2 : 1)))