From 4fbed650716a0bd6014d15afb30cfc247cc69bac Mon Sep 17 00:00:00 2001 From: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Date: Sat, 10 Apr 2021 12:11:39 -0700 Subject: [PATCH] Fix connect_loc runtiming for multiple turfs (#58269) --- code/datums/elements/connect_loc.dm | 4 +++- code/modules/unit_tests/connect_loc.dm | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/code/datums/elements/connect_loc.dm b/code/datums/elements/connect_loc.dm index 15082db5326..fed672239f0 100644 --- a/code/datums/elements/connect_loc.dm +++ b/code/datums/elements/connect_loc.dm @@ -43,7 +43,9 @@ RegisterSignal(target.loc, COMSIG_TURF_CHANGE, .proc/on_turf_change) /datum/element/connect_loc/proc/unregister_signals(atom/movable/target, atom/old_loc) - LAZYREMOVE(targets[old_loc], target) + targets[old_loc] -= target + if (length(targets[old_loc]) == 0) + targets -= old_loc for (var/signal in connections) target.UnregisterSignal(old_loc, signal) diff --git a/code/modules/unit_tests/connect_loc.dm b/code/modules/unit_tests/connect_loc.dm index 3e33270d306..b9695045597 100644 --- a/code/modules/unit_tests/connect_loc.dm +++ b/code/modules/unit_tests/connect_loc.dm @@ -43,6 +43,16 @@ run_loc_floor_bottom_left.ChangeTurf(old_turf_type) return ..() +/// Tests that multiple objects can have connect_loc on the same turf without runtimes. +/datum/unit_test/connect_loc_multiple_on_turf + +/datum/unit_test/connect_loc_multiple_on_turf/Run() + var/obj/item/watches_mock_calls/watcher_one = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left) + qdel(watcher_one) + + var/obj/item/watches_mock_calls/watcher_two = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left) + qdel(watcher_two) + /obj/item/watches_mock_calls var/times_called