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.
This commit is contained in:
skull132
2017-06-02 20:22:38 +03:00
committed by GitHub
parent e2acfcd38e
commit 61826d2fa1
7 changed files with 21 additions and 17 deletions
+4
View File
@@ -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]"
+2 -2
View File
@@ -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.
+3 -3
View File
@@ -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
@@ -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]
@@ -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
+3 -3
View File
@@ -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()
+2 -2
View File
@@ -754,9 +754,9 @@
H << "<span class='danger'>The APC power currents surge eratically, damaging your chassis!</span>"
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 << "<span class = 'danger'>Fil$ Transfer Complete. Er-@4!#%!. New Master detected: [hacker]! Obey their commands.</span>"
hacker << "<span class = 'notice'>Corrupt files transfered to [H]. They are now under your control until they are reparied.</span>"