Implements UIDs and initial topic integration

This commit is contained in:
Krausus
2016-09-05 22:33:10 -04:00
parent 0ce93c9706
commit aefb664a58
3 changed files with 56 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
// Unique Datum Identifiers
// Basically, a replacement for plain \refs that ensure the reference still
// points to the exact same datum/client, but doesn't prevent GC like tags do.
// Turns this:
// var/myref = "\ref[mydatum]"
// var/datum/D = locate(myref)
// into this:
// var/myUID = mydatum.UID()
// var/datum/D = locateUID(myUID)
var/global/next_unique_datum_id = 1
/datum/var/tmp/unique_datum_id = null
/client/var/tmp/unique_datum_id = null
/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]_[next_unique_datum_id++]"
tag = tag_backup
return unique_datum_id
/client/proc/UID()
if(!unique_datum_id)
unique_datum_id = "\ref[src]_[next_unique_datum_id++]"
return unique_datum_id
/proc/locateUID(uid)
if(!istext(uid))
return null
var/splitat = findlasttext(uid, "_")
if(!splitat)
return null
var/datum/D = locate(copytext(uid, 1, splitat))
// We might locate a client instead of a datum, but just using : is easier
// than actually checking and typecasting
if(D && D:unique_datum_id == uid)
return D
return null
+9
View File
@@ -29,6 +29,15 @@
if(!usr || usr != mob) //stops us calling Topic for somebody else's client. Also helps prevent usr=null
return
// src should always be a UID; if it isn't, warn instead of failing entirely
if(href_list["src"])
hsrc = locateUID(href_list["src"])
if(!hsrc)
hsrc = locate(href_list["src"])
if(hsrc)
var/hsrc_info = datum_info_line(hsrc) || "[hsrc]"
log_runtime(EXCEPTION("Got \\ref-based src in topic from [src] for [hsrc_info], should be UID: [href]"))
#if defined(TOPIC_DEBUGGING)
to_chat(world, "[src]'s Topic: [href] destined for [hsrc].")
#endif