From 61826d2fa1bc02584c4bee74b08f3573325b1e65 Mon Sep 17 00:00:00 2001 From: skull132 Date: Fri, 2 Jun 2017 20:22:38 +0300 Subject: [PATCH] SOFTREF macro (#2574) Adds a SOFTREF macro because it's an actual PITA to write out. Refactors all applicable usecases of it to use it. I've left out some NanoUI stuff because you know my preference at being explicit when needed. --- code/__defines/misc.dm | 4 ++++ code/controllers/subsystems/arrivals.dm | 4 ++-- code/controllers/subsystems/garbage.dm | 6 +++--- code/controllers/subsystems/processing/nanoui.dm | 10 +++++----- code/modules/client/preferences_notification.dm | 4 ++-- code/modules/events/carp_migration.dm | 6 +++--- code/modules/power/apc.dm | 4 ++-- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/code/__defines/misc.dm b/code/__defines/misc.dm index 27ade3e205a..536120f5c70 100644 --- a/code/__defines/misc.dm +++ b/code/__defines/misc.dm @@ -323,3 +323,7 @@ Will print: "/mob/living/carbon/human/death" (you can optionally embed it in a s #define NL_NOT_DISABLED 0 #define NL_TEMPORARY_DISABLE 1 #define NL_PERMANENT_DISABLE 2 + +// Used for creating soft references to objects. A manner of storing an item reference +// as text so you don't necessarily fuck with an object's ability to be garbage collected. +#define SOFTREF(A) "\ref[A]" diff --git a/code/controllers/subsystems/arrivals.dm b/code/controllers/subsystems/arrivals.dm index 2ea0f820eb8..5603692249a 100644 --- a/code/controllers/subsystems/arrivals.dm +++ b/code/controllers/subsystems/arrivals.dm @@ -40,7 +40,7 @@ log_debug("SSarrivals: [M] has entered arrival shuttle hotzone.") if (istype(M)) - current_mobs += "\ref[M]" + current_mobs += SOFTREF(M) wake() // Wake the process. @@ -48,7 +48,7 @@ set_launch_countdown(30) /datum/controller/subsystem/arrivals/proc/on_hotzone_exit(mob/living/M) - current_mobs -= "\ref[M]" + current_mobs -= SOFTREF(M) log_debug("SSarrivals: [M] has exited arrival shuttle hotzone.") //called when the shuttle has arrived. diff --git a/code/controllers/subsystems/garbage.dm b/code/controllers/subsystems/garbage.dm index ba616a8196e..b1d93aceb5a 100644 --- a/code/controllers/subsystems/garbage.dm +++ b/code/controllers/subsystems/garbage.dm @@ -138,12 +138,12 @@ var/datum/controller/subsystem/garbage_collector/SSgarbage var/time = world.timeofday var/tick = world.tick_usage var/ticktime = world.time - + var/type = A.type var/refID = "\ref[A]" - + del(A) - + tick = (world.tick_usage-tick+((world.time-ticktime)/world.tick_lag*100)) if (tick > highest_del_tickusage) highest_del_tickusage = tick diff --git a/code/controllers/subsystems/processing/nanoui.dm b/code/controllers/subsystems/processing/nanoui.dm index a057c1580f1..4ddf3693c38 100644 --- a/code/controllers/subsystems/processing/nanoui.dm +++ b/code/controllers/subsystems/processing/nanoui.dm @@ -52,7 +52,7 @@ var/datum/controller/subsystem/processing/nanoui/SSnanoui * @return /nanoui Returns the found ui, or null if none exists */ /datum/controller/subsystem/processing/nanoui/proc/get_open_ui(mob/user, src_object, ui_key) - var/src_object_key = "\ref[src_object]" + var/src_object_key = SOFTREF(src_object) if (!LAZYLEN(open_uis[src_object_key]) || !LAZYLEN(open_uis[src_object_key][ui_key])) return null @@ -71,7 +71,7 @@ var/datum/controller/subsystem/processing/nanoui/SSnanoui * @return int The number of uis updated */ /datum/controller/subsystem/processing/nanoui/proc/update_uis(src_object) - var/src_object_key = "\ref[src_object]" + var/src_object_key = SOFTREF(src_object) if (!LAZYLEN(open_uis[src_object_key])) return 0 @@ -92,7 +92,7 @@ var/datum/controller/subsystem/processing/nanoui/SSnanoui * @return int The number of uis close */ /datum/controller/subsystem/processing/nanoui/proc/close_uis(src_object) - var/src_object_key = "\ref[src_object]" + var/src_object_key = SOFTREF(src_object) if (!open_uis[src_object_key] || !islist(open_uis[src_object_key])) return 0 @@ -146,7 +146,7 @@ var/datum/controller/subsystem/processing/nanoui/SSnanoui * @return nothing */ /datum/controller/subsystem/processing/nanoui/proc/ui_opened(datum/nanoui/ui) - var/src_object_key = "\ref[ui.src_object]" + var/src_object_key = SOFTREF(ui.src_object) LAZYINITLIST(open_uis[src_object_key]) LAZYADD(ui.user.open_uis, ui) @@ -163,7 +163,7 @@ var/datum/controller/subsystem/processing/nanoui/SSnanoui * @return int 0 if no ui was removed, 1 if removed successfully */ /datum/controller/subsystem/processing/nanoui/proc/ui_closed(datum/nanoui/ui) - var/src_object_key = "\ref[ui.src_object]" + var/src_object_key = SOFTREF(ui.src_object) var/ui_key = ui.ui_key var/list/obj_uis = open_uis[src_object_key] diff --git a/code/modules/client/preferences_notification.dm b/code/modules/client/preferences_notification.dm index 54c644dd5ad..171aab8fb84 100644 --- a/code/modules/client/preferences_notification.dm +++ b/code/modules/client/preferences_notification.dm @@ -31,8 +31,8 @@ note_wrapper = new_wrapper note_text = new_text - note_text = replacetextEx(note_text, ":src_ref", "\ref[src]") - note_wrapper[1] = replacetextEx(note_wrapper[1], ":src_ref", "\ref[src]") + note_text = replacetextEx(note_text, ":src_ref", SOFTREF(src)) + note_wrapper[1] = replacetextEx(note_wrapper[1], ":src_ref", SOFTREF(src)) if (new_persistence) persistent = new_persistence diff --git a/code/modules/events/carp_migration.dm b/code/modules/events/carp_migration.dm index 77dfcd41330..b9ecc4f6cdd 100644 --- a/code/modules/events/carp_migration.dm +++ b/code/modules/events/carp_migration.dm @@ -43,10 +43,10 @@ for (var/j = 1, j <= group_size, j++) if(prob(99)) var/mob/living/simple_animal/hostile/carp/carp = new(spawn_locations[i]) - spawned_carp += "\ref[carp]" + spawned_carp += SOFTREF(carp) else var/mob/living/simple_animal/hostile/carp/shark/carp = new(spawn_locations[i]) - spawned_carp += "\ref[carp]" + spawned_carp += SOFTREF(carp) i++ /datum/event/carp_migration/proc/spawn_caverndweller(var/num_groups, var/group_size_min=2, var/group_size_max=3) @@ -63,7 +63,7 @@ var/group_size = rand(group_size_min, group_size_max) for (var/j = 1, j <= group_size, j++) var/mob/living/simple_animal/hostile/retaliate/cavern_dweller/dweller = new(spawn_locations[i]) - spawned_dweller += "\ref[dweller]" + spawned_dweller += SOFTREF(dweller) i++ /datum/event/carp_migration/end() diff --git a/code/modules/power/apc.dm b/code/modules/power/apc.dm index a0ede92b8b2..e0ae4c533e5 100644 --- a/code/modules/power/apc.dm +++ b/code/modules/power/apc.dm @@ -754,9 +754,9 @@ H << "The APC power currents surge eratically, damaging your chassis!" H.adjustFireLoss(10, 0) if(infected) - if("\ref[H]" in hacked_ipcs) + if(SOFTREF(H) in hacked_ipcs) return - LAZYADD(hacked_ipcs, "\ref[H]") + LAZYADD(hacked_ipcs, SOFTREF(H)) infected = 0 H << "Fil$ Transfer Complete. Er-@4!#%!. New Master detected: [hacker]! Obey their commands." hacker << "Corrupt files transfered to [H]. They are now under your control until they are reparied."