Merge pull request #14441 from AffectedArc07/uid_patch

Fixes UIs breaking from running out of UIDs
This commit is contained in:
Fox McCloud
2020-09-27 04:05:43 -04:00
committed by GitHub
2 changed files with 40 additions and 1 deletions
+39 -1
View File
@@ -14,16 +14,33 @@
// 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)
/// Log of all UIDs created in the round. Assoc list with type as key and amount as value
GLOBAL_LIST_EMPTY(uid_log)
/**
* Gets or creates 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++]"
// num2text can output 8 significant figures max. If we go above 10 million UIDs in a round, shit breaks
unique_datum_id = "\ref[src]_[num2text(GLOB.next_unique_datum_id++, 8)]"
tag = tag_backup
GLOB.uid_log[type]++
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
@@ -38,3 +55,24 @@ GLOBAL_VAR_INIT(next_unique_datum_id, 1)
if(D && D.unique_datum_id == uid)
return D
return null
/**
* Opens a lof of UIDs
*
* In-round ability to view what has created a UID, and how many times a UID for that path has been declared
*/
/client/proc/uid_log()
set name = "View UID Log"
set category = "Debug"
set desc = "Shows the log of created UIDs this round"
if(!check_rights(R_DEBUG))
return
var/list/sorted = sortTim(GLOB.uid_log, cmp=/proc/cmp_numeric_dsc, associative = TRUE)
var/list/text = list("<h1>UID Log</h1>", "<p>Current UID: [GLOB.next_unique_datum_id]</p>", "<ul>")
for(var/key in sorted)
text += "<li>[key] - [sorted[key]]</li>"
text += "</ul>"
usr << browse(text.Join(), "window=uidlog")
+1
View File
@@ -166,6 +166,7 @@ GLOBAL_LIST_INIT(admin_verbs_debug, list(
/client/proc/admin_serialize,
/client/proc/jump_to_ruin,
/client/proc/toggle_medal_disable,
/client/proc/uid_log
))
GLOBAL_LIST_INIT(admin_verbs_possess, list(
/proc/possess,