Files
Bubberstation/code/datums/components/tether.dm
Mothblocks fa7688d043 Save 0.6-0.7s of init time by splitting registering lists of signals into its own proc, and optimizing QDELETED (#71056)
- Makes QDELETED use isnull(x) instead of !x, giving about 0.2 to 0.25s
of speed.
- Make disposal constructs only update icon state rather than go through
expensive overlay code. Unfortunately did not have much effect, but is
something they should've been doing nonetheless.
- Makes RegisterSignal only take signals directly as opposed to
allocating a fresh list of signals. Very few consumers actually used
this and it costs about 0.4s. Also I think this is just a bad API anyway
and that separate procs are important

`\bRegisterSignal\((.*)list\(` replaced with `RegisterSignals($1list(`
2022-11-22 07:40:05 +00:00

40 lines
1.2 KiB
Plaintext

/datum/component/tether
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
var/atom/tether_target
var/max_dist
var/tether_name
/datum/component/tether/Initialize(atom/tether_target, max_dist = 4, tether_name)
if(!isliving(parent) || !istype(tether_target) || !tether_target.loc)
return COMPONENT_INCOMPATIBLE
src.tether_target = tether_target
src.max_dist = max_dist
if (ispath(tether_name, /atom))
var/atom/tmp = tether_name
src.tether_name = initial(tmp.name)
else
src.tether_name = tether_name
RegisterSignals(parent, list(COMSIG_MOVABLE_PRE_MOVE), PROC_REF(checkTether))
/datum/component/tether/proc/checkTether(mob/mover, newloc)
SIGNAL_HANDLER
if (get_dist(mover,newloc) > max_dist)
to_chat(mover, span_userdanger("The [tether_name] runs out of slack and prevents you from moving!"))
return COMPONENT_MOVABLE_BLOCK_PRE_MOVE
var/atom/blocker
out:
for(var/turf/T in get_line(tether_target,newloc))
if (T.density)
blocker = T
break out
for(var/a in T)
var/atom/A = a
if(A.density && A != mover && A != tether_target)
blocker = A
break out
if (blocker)
to_chat(mover, span_userdanger("The [tether_name] catches on [blocker] and prevents you from moving!"))
return COMPONENT_MOVABLE_BLOCK_PRE_MOVE