Files
Bubberstation/code/datums/components/shuttle_move_deferred_checks.dm
Bloop 7754938c72 Makes a bunch of lists lazy (#94239)
## About The Pull Request

Empy lists. There are a lot of 'em.

<img width="981" height="512" alt="image"
src="https://github.com/user-attachments/assets/b94b041a-2904-466b-ab89-54bd1de11b4e"
/>

Going through ways to reduce memory I found a few easy ones here. Wires,
the edible component, the seethrough component. None of these are really
a concern when it comes to needing lists in memory for performance
reasons. Wires aren't going to be cut most of the time for each door. A
lot of food does not have any junkiness. Seethrough component lies
dormant most of the round. Etc.

Making lists lazy in these cases should be a no brainer.

Everything I tested still seems to work exactly the same.

## Why It's Good For The Game

Frees memory that is just taking up space a lot of the time.

## Changelog

Not player-facing, this is all under-the-hood stuff.
2025-12-03 13:42:16 -07:00

71 lines
2.6 KiB
Plaintext

// This component allows for certain movement checks, particularly those involving linked atoms existing on the same z-level, to be deferred when a shuttle moves.
/datum/component/shuttle_move_deferred_checks
dupe_mode = COMPONENT_DUPE_SOURCES
/// An list of targets to listen for the movements of
var/list/targets
/// The check to call on the parent when a target moves. Can be the name of a proc on the parent, or a `/datum/callback`.
var/check
/// A list of each target currently being moved by a shuttle - if this list is not empty, checks will not be run.
var/list/moving_targets
/datum/component/shuttle_move_deferred_checks/Initialize(check)
. = ..()
if(!check)
return COMPONENT_INCOMPATIBLE
src.check = check
/datum/component/shuttle_move_deferred_checks/Destroy(force)
targets = null
check = null
moving_targets = null
return ..()
/datum/component/shuttle_move_deferred_checks/on_source_add(source, check)
. = ..()
var/atom/movable/movable = locate(source)
if(!istype(movable) || (check != src.check))
return COMPONENT_INCOMPATIBLE
LAZYADD(targets, movable)
RegisterSignal(movable, COMSIG_MOVABLE_MOVED, PROC_REF(on_target_moved))
RegisterSignal(movable, COMSIG_ATOM_BEFORE_SHUTTLE_MOVE, PROC_REF(before_target_shuttle_move))
RegisterSignal(movable, COMSIG_ATOM_AFTER_SHUTTLE_MOVE, PROC_REF(after_target_shuttle_move))
RegisterSignal(movable, COMSIG_QDELETING, PROC_REF(on_target_deleted))
/datum/component/shuttle_move_deferred_checks/on_source_remove(source)
var/atom/movable/movable = locate(source)
if(!istype(movable))
return
LAZYREMOVE(targets, movable)
LAZYREMOVE(moving_targets, movable)
UnregisterSignal(movable, list(COMSIG_MOVABLE_MOVED, COMSIG_ATOM_BEFORE_SHUTTLE_MOVE, COMSIG_ATOM_AFTER_SHUTTLE_MOVE, COMSIG_QDELETING))
return ..()
/datum/component/shuttle_move_deferred_checks/proc/call_check()
if(istype(check, /datum/callback))
var/datum/callback/callback_check = check
callback_check.Invoke()
else
call(parent, check)()
/datum/component/shuttle_move_deferred_checks/proc/on_target_moved(atom/movable/source, atom/old_loc, dir, forced, list/old_locs)
SIGNAL_HANDLER
if(LAZYLEN(moving_targets))
return
call_check()
/datum/component/shuttle_move_deferred_checks/proc/before_target_shuttle_move(atom/source)
SIGNAL_HANDLER
LAZYOR(moving_targets, source)
/datum/component/shuttle_move_deferred_checks/proc/after_target_shuttle_move(atom/source)
SIGNAL_HANDLER
LAZYOR(moving_targets, source)
if(!LAZYLEN(moving_targets))
call_check()
/datum/component/shuttle_move_deferred_checks/proc/on_target_deleted(datum/source)
SIGNAL_HANDLER
on_source_remove(REF(source))