From 1755b9ecb94f7732a82d8fb4f050b48f20befebc Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 26 Sep 2020 10:12:27 +0100 Subject: [PATCH 1/3] Fixes UIs breaking from running out of UIDs --- code/__HELPERS/unique_ids.dm | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/code/__HELPERS/unique_ids.dm b/code/__HELPERS/unique_ids.dm index b66b1a11b90..4504fc6a4a2 100644 --- a/code/__HELPERS/unique_ids.dm +++ b/code/__HELPERS/unique_ids.dm @@ -1,3 +1,7 @@ +/// At what number do we roll UIDs over for the next ground. +#define UID_ROLLOVER_COUNT 950000 +// ^ This needs to exist because BYOND will print a number in scientific notation if its big enough, breaking all hrefs + // Unique Datum Identifiers // Basically, a replacement for plain \refs that ensure the reference still @@ -14,16 +18,36 @@ // var/myUID = mydatum.UID() // var/datum/D = locateUID(myUID) +/// The next UID to be used (Increments by 1 for each UID) GLOBAL_VAR_INIT(next_unique_datum_id, 1) +/// The next UID group to be used (Increments by 1 every time UID goes above a certain number [UID_ROLLOVER_COUNT]) +GLOBAL_VAR_INIT(next_uid_group, 1) + +/** + * Gets the UID of a datum + * + * BYOND refs are recycled, so this system prevents that. If a datum does not have a UID when this proc is ran, one will be created + * Returns the UID of the datum + */ /datum/proc/UID() if(!unique_datum_id) var/tag_backup = tag tag = null // Grab the raw ref, not the tag - unique_datum_id = "\ref[src]_[GLOB.next_unique_datum_id++]" + if(GLOB.next_unique_datum_id >= UID_ROLLOVER_COUNT) + GLOB.next_unique_datum_id = 1 + GLOB.next_uid_group++ // Increase by 1 for next group + log_debug("UID() encountered a UID greater than the rollover count ([UID_ROLLOVER_COUNT]). Incrementing UID group.") + unique_datum_id = "\ref[src]_[GLOB.next_unique_datum_id++]-[GLOB.next_uid_group]" tag = tag_backup return unique_datum_id +/** + * Locates a datum based off of the UID + * + * Replacement for locate() which takes a UID instead of a ref + * Returns the datum, if found + */ /proc/locateUID(uid) if(!istext(uid)) return null From a3154d77507a550fafef6566594564b44ec11796 Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Sat, 26 Sep 2020 13:12:10 +0100 Subject: [PATCH 2/3] **TEMPORARY** UID LOGGING --- code/__HELPERS/unique_ids.dm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/code/__HELPERS/unique_ids.dm b/code/__HELPERS/unique_ids.dm index 4504fc6a4a2..cfad22debf8 100644 --- a/code/__HELPERS/unique_ids.dm +++ b/code/__HELPERS/unique_ids.dm @@ -22,7 +22,8 @@ GLOBAL_VAR_INIT(next_unique_datum_id, 1) /// The next UID group to be used (Increments by 1 every time UID goes above a certain number [UID_ROLLOVER_COUNT]) GLOBAL_VAR_INIT(next_uid_group, 1) - +/// Log of all UIDs created in the round +GLOBAL_LIST_EMPTY(uid_log) /** * Gets the UID of a datum @@ -40,6 +41,7 @@ GLOBAL_VAR_INIT(next_uid_group, 1) log_debug("UID() encountered a UID greater than the rollover count ([UID_ROLLOVER_COUNT]). Incrementing UID group.") unique_datum_id = "\ref[src]_[GLOB.next_unique_datum_id++]-[GLOB.next_uid_group]" tag = tag_backup + GLOB.uid_log[type]++ return unique_datum_id /** @@ -62,3 +64,19 @@ GLOBAL_VAR_INIT(next_uid_group, 1) if(D && D.unique_datum_id == uid) return D return null + +/client/verb/uid_testing() + set name = "View UID Log" + set category = "Debug" + set desc = "If this got merged in, please scream at someone" + + if(!check_rights(R_DEBUG)) + return + + var/list/sorted = sortTim(GLOB.uid_log, cmp=/proc/cmp_numeric_dsc, associative = TRUE) + var/list/text = list("
Current UID: [GLOB.next_unique_datum_id]
", "