mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 20:48:56 +01:00
[MIRROR] Makes turfs persist their signals, uses this to optimize connect_loc (#6465)
* Makes turfs persist their signals, uses this to optimize connect_loc (#59608) * Makes turfs persist signals * Splits connect_loc up into two elements, one for stuff that wishes to connect on behalf of something, and one for stuff that just wants to connect normally. Connecting on behalf of someone has a significant amount of overhead, so let's do this to keep things clear * Converts all uses of connect_loc over to the new patterns * Adds some comments, actually makes turfs persist signals * There's no need to detach connect loc anymore, since all it does is unregister signals. Unregisters a signal from formorly decal'd turfs, and makes the changeturf signal persistance stuff actually work * bro fuck documentation * Changes from a var to a proc, prevents admemems and idiots * Extra detail on why we do the copy post qdel * Makes turfs persist their signals, uses this to optimize connect_loc Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
This commit is contained in:
co-authored by
LemonInTheDark
parent
8dc7776979
commit
5326760cb3
@@ -10,7 +10,7 @@
|
||||
if(!isatom(target)) //How
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
var/atom/to_track = target
|
||||
to_track.AddElement(/datum/element/connect_loc, to_track, pass_on)
|
||||
to_track.AddElement(/datum/element/connect_loc, pass_on)
|
||||
RegisterSignal(to_track, COMSIG_MOVABLE_MOVED, .proc/react_to_move)
|
||||
|
||||
if(!mapload && isopenturf(to_track.loc))
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
src.flags = flags
|
||||
|
||||
if(ismovable(target))
|
||||
AddElement(/datum/element/connect_loc, target, crossed_connections)
|
||||
AddElement(/datum/element/connect_loc_behalf, target, crossed_connections)
|
||||
else
|
||||
RegisterSignal(get_turf(target), COMSIG_ATOM_ENTERED, .proc/on_entered)
|
||||
|
||||
@@ -99,4 +99,4 @@
|
||||
/datum/element/caltrop/Detach(datum/target)
|
||||
. = ..()
|
||||
if(ismovable(target))
|
||||
RemoveElement(/datum/element/connect_loc, target, crossed_connections)
|
||||
RemoveElement(/datum/element/connect_loc_behalf, target, crossed_connections)
|
||||
|
||||
@@ -1,6 +1,53 @@
|
||||
/// This element hooks a signal onto the loc the current object is on.
|
||||
/// When the object moves, it will unhook the signal and rehook it to the new object.
|
||||
/datum/element/connect_loc
|
||||
element_flags = ELEMENT_BESPOKE
|
||||
id_arg_index = 2
|
||||
|
||||
/// An assoc list of signal -> procpath to register to the loc this object is on.
|
||||
var/list/connections
|
||||
|
||||
/datum/element/connect_loc/Attach(atom/movable/listener, list/connections)
|
||||
. = ..()
|
||||
if (!istype(listener))
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
|
||||
src.connections = connections
|
||||
|
||||
RegisterSignal(listener, COMSIG_MOVABLE_MOVED, .proc/on_moved, override = TRUE)
|
||||
update_signals(listener)
|
||||
|
||||
/datum/element/connect_loc/Detach(atom/movable/listener)
|
||||
. = ..()
|
||||
unregister_signals(listener, listener.loc)
|
||||
UnregisterSignal(listener, COMSIG_MOVABLE_MOVED)
|
||||
|
||||
/datum/element/connect_loc/proc/update_signals(atom/movable/listener)
|
||||
var/atom/listener_loc = listener.loc
|
||||
if(isnull(listener_loc))
|
||||
return
|
||||
|
||||
for (var/signal in connections)
|
||||
//override=TRUE because more than one connect_loc element instance tracked object can be on the same loc
|
||||
listener.RegisterSignal(listener_loc, signal, connections[signal], override=TRUE)
|
||||
|
||||
/datum/element/connect_loc/proc/unregister_signals(datum/listener, atom/old_loc)
|
||||
if(isnull(old_loc))
|
||||
return
|
||||
|
||||
for (var/signal in connections)
|
||||
listener.UnregisterSignal(old_loc, signal)
|
||||
|
||||
/datum/element/connect_loc/proc/on_moved(atom/movable/listener, atom/old_loc)
|
||||
SIGNAL_HANDLER
|
||||
unregister_signals(listener, old_loc)
|
||||
update_signals(listener)
|
||||
|
||||
/// This element behaves the same as connect_loc, hooking into a signal on a tracked object's turf
|
||||
/// It has the ability to react to that signal on behalf of a seperate listener however
|
||||
/// This has great use, primarially for components, but it carries with it some overhead
|
||||
/// So we do it seperately rather then intigrating the behavior with the main element
|
||||
/datum/element/connect_loc_behalf
|
||||
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH | ELEMENT_COMPLEX_DETACH
|
||||
id_arg_index = 3
|
||||
|
||||
@@ -10,14 +57,7 @@
|
||||
/// An assoc list of locs that are being occupied and a list of targets that occupy them.
|
||||
var/list/targets = list()
|
||||
|
||||
/// The callback used when the turf under the tracked object changes
|
||||
var/datum/callback/changeturf_callback
|
||||
|
||||
/datum/element/connect_loc/New()
|
||||
. = ..()
|
||||
changeturf_callback = CALLBACK(src, .proc/post_turf_change)
|
||||
|
||||
/datum/element/connect_loc/Attach(datum/listener, atom/movable/tracked, list/connections)
|
||||
/datum/element/connect_loc_behalf/Attach(datum/listener, atom/movable/tracked, list/connections)
|
||||
. = ..()
|
||||
if (!istype(tracked))
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
@@ -27,7 +67,7 @@
|
||||
RegisterSignal(tracked, COMSIG_MOVABLE_MOVED, .proc/on_moved, override = TRUE)
|
||||
update_signals(listener, tracked)
|
||||
|
||||
/datum/element/connect_loc/Detach(datum/listener, atom/movable/tracked, list/connections)
|
||||
/datum/element/connect_loc_behalf/Detach(datum/listener, atom/movable/tracked, list/connections)
|
||||
. = ..()
|
||||
|
||||
if(!tracked)
|
||||
@@ -36,7 +76,7 @@
|
||||
unregister_signals(listener, tracked, tracked.loc)
|
||||
UnregisterSignal(tracked, COMSIG_MOVABLE_MOVED)
|
||||
|
||||
/datum/element/connect_loc/proc/update_signals(datum/listener, atom/movable/tracked)
|
||||
/datum/element/connect_loc_behalf/proc/update_signals(datum/listener, atom/movable/tracked)
|
||||
var/existing = length(targets[tracked.loc])
|
||||
if(!existing)
|
||||
targets[tracked.loc] = list()
|
||||
@@ -49,10 +89,7 @@
|
||||
listener.RegisterSignal(tracked.loc, signal, connections[signal], override=TRUE)
|
||||
//override=TRUE because more than one connect_loc element instance tracked object can be on the same loc
|
||||
|
||||
if (!existing && isturf(tracked.loc))
|
||||
RegisterSignal(tracked.loc, COMSIG_TURF_CHANGE, .proc/on_turf_change)
|
||||
|
||||
/datum/element/connect_loc/proc/unregister_all(datum/listener)
|
||||
/datum/element/connect_loc_behalf/proc/unregister_all(datum/listener)
|
||||
for(var/atom/location as anything in targets)
|
||||
var/list/loc_targets = targets[location]
|
||||
for(var/atom/movable/tracked as anything in loc_targets)
|
||||
@@ -64,7 +101,7 @@
|
||||
continue
|
||||
UnregisterSignal(tracked, COMSIG_MOVABLE_MOVED)
|
||||
|
||||
/datum/element/connect_loc/proc/unregister_signals(datum/listener, atom/movable/tracked, atom/old_loc)
|
||||
/datum/element/connect_loc_behalf/proc/unregister_signals(datum/listener, atom/movable/tracked, atom/old_loc)
|
||||
if (length(targets[old_loc]) <= 1)
|
||||
targets -= old_loc
|
||||
else
|
||||
@@ -77,34 +114,9 @@
|
||||
for (var/signal in connections)
|
||||
listener.UnregisterSignal(old_loc, signal)
|
||||
|
||||
if (!targets[old_loc] && isturf(old_loc))
|
||||
UnregisterSignal(old_loc, COMSIG_TURF_CHANGE)
|
||||
|
||||
/datum/element/connect_loc/proc/on_moved(atom/movable/tracked, atom/old_loc)
|
||||
/datum/element/connect_loc_behalf/proc/on_moved(atom/movable/tracked, atom/old_loc)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
var/datum/listener = targets[old_loc][tracked]
|
||||
unregister_signals(listener, tracked, old_loc)
|
||||
update_signals(listener, tracked)
|
||||
|
||||
/datum/element/connect_loc/proc/on_turf_change(
|
||||
turf/source,
|
||||
path,
|
||||
new_baseturfs,
|
||||
flags,
|
||||
list/post_change_callbacks,
|
||||
)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
post_change_callbacks += changeturf_callback
|
||||
|
||||
/datum/element/connect_loc/proc/post_turf_change(turf/new_turf)
|
||||
// If we don't cut the targets list before iterating,
|
||||
// then we won't re-register the change turf signal.
|
||||
var/list/turf_targets = targets[new_turf]
|
||||
var/list/targets_copy = turf_targets.Copy()
|
||||
turf_targets.Cut()
|
||||
|
||||
for (var/atom/movable/tracked as anything in targets_copy)
|
||||
var/datum/listener = targets_copy[tracked]
|
||||
update_signals(listener, tracked)
|
||||
|
||||
@@ -118,6 +118,7 @@
|
||||
|
||||
/datum/element/decal/Detach(atom/source)
|
||||
UnregisterSignal(source, list(COMSIG_ATOM_DIR_CHANGE, COMSIG_COMPONENT_CLEAN_ACT, COMSIG_PARENT_EXAMINE, COMSIG_ATOM_UPDATE_OVERLAYS, COMSIG_TURF_ON_SHUTTLE_MOVE, COMSIG_ATOM_SMOOTHED_ICON))
|
||||
SSdcs.UnregisterSignal(source, COMSIG_ATOM_DIR_CHANGE)
|
||||
source.update_appearance(UPDATE_OVERLAYS)
|
||||
if(isitem(source))
|
||||
INVOKE_ASYNC(source, /obj/item/.proc/update_slot_icon)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
if(!src.on_squash_callback && squash_callback)
|
||||
on_squash_callback = CALLBACK(parent, squash_callback)
|
||||
|
||||
AddElement(/datum/element/connect_loc, parent, loc_connections)
|
||||
AddElement(/datum/element/connect_loc_behalf, parent, loc_connections)
|
||||
|
||||
///Handles the squashing of the mob
|
||||
/datum/component/squashable/proc/on_entered(turf/source_turf, atom/movable/crossing_movable)
|
||||
@@ -72,4 +72,4 @@
|
||||
|
||||
/datum/component/squashable/UnregisterFromParent()
|
||||
. = ..()
|
||||
RemoveElement(/datum/element/connect_loc, parent, loc_connections)
|
||||
RemoveElement(/datum/element/connect_loc_behalf, parent, loc_connections)
|
||||
|
||||
Reference in New Issue
Block a user