Skip to content

Commit 855aa7c

Browse files
committed
add: Rust UUID & Unbundle sun (#7069) [testmerge][42606ee]
1 parent 174de31 commit 855aa7c

File tree

23 files changed

+158
-283
lines changed

23 files changed

+158
-283
lines changed

code/__HELPERS/unique_ids.dm

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
// var/myUID = mydatum.UID()
1515
// var/datum/D = locateUID(myUID)
1616

17-
/// The next UID to be used (Increments by 1 for each UID)
18-
GLOBAL_VAR_INIT(next_unique_datum_id, 1)
1917
/// Log of all UIDs created in the round. Assoc list with type as key and amount as value
2018
GLOBAL_LIST_EMPTY(uid_log)
2119

@@ -27,28 +25,15 @@ GLOBAL_LIST_EMPTY(uid_log)
2725
*/
2826
/datum/proc/UID()
2927
if(!unique_datum_id)
30-
var/tag_backup = tag
31-
tag = null // Grab the raw ref, not the tag
32-
// num2text can output 8 significant figures max. If we go above 10 million UIDs in a round, shit breaks
33-
unique_datum_id = "\ref[src]_[num2text(GLOB.next_unique_datum_id++, 8)]"
34-
tag = tag_backup
28+
unique_datum_id = RUSTLIB_CALL(get_uuid, src)
3529
GLOB.uid_log[type]++
36-
return unique_datum_id
37-
38-
/datum/proc/get_num_uid()
39-
if(numeric_datum_id)
40-
return numeric_datum_id
41-
42-
numeric_datum_id = GLOB.next_unique_datum_id
4330

44-
GLOB.next_unique_datum_id++
45-
GLOB.uid_log[type]++
46-
47-
return numeric_datum_id
31+
return unique_datum_id
4832

4933
/proc/UID_of(datum/target)
5034
if(!isdatum(target))
5135
CRASH("Non-datum passed as argument.")
36+
5237
return target.UID()
5338

5439

@@ -59,19 +44,10 @@ GLOBAL_LIST_EMPTY(uid_log)
5944
* Returns the datum, if found
6045
*/
6146
/proc/locateUID(uid)
62-
if(!istext(uid))
63-
return null
64-
65-
var/splitat = findlasttext(uid, "_")
66-
67-
if(!splitat)
68-
return null
69-
70-
var/datum/D = locate(copytext(uid, 1, splitat))
47+
if(!uid)
48+
return
7149

72-
if(D && D.unique_datum_id == uid)
73-
return D
74-
return null
50+
return RUSTLIB_CALL(get_by_uuid, uid)
7551

7652

7753
/**
@@ -101,7 +77,7 @@ GLOBAL_LIST_EMPTY(uid_log)
10177
return
10278

10379
var/list/sorted = sortTim(GLOB.uid_log, cmp = /proc/cmp_numeric_dsc, associative = TRUE)
104-
var/list/text = list("<h1>UID Log</h1>", "<p>Current UID: [GLOB.next_unique_datum_id]</p>", "<ul>")
80+
var/list/text = list("<h1>UID Log</h1>", "<p>Current UID: [RUSTLIB_CALL(get_uuid_counter_value)]</p>", "<ul>")
10581
for(var/key in sorted)
10682
text += "<li>[key] - [sorted[key]]</li>"
10783

code/controllers/subsystem/sun.dm

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,53 @@ SUBSYSTEM_DEF(sun)
66
offline_implications = "Solar panels will no longer rotate. No immediate action is needed."
77
cpu_display = SS_CPUDISPLAY_LOW
88
ss_id = "sun"
9-
var/solar_gen_rate = 1500
10-
119

12-
/datum/controller/subsystem/sun/Initialize()
13-
RUSTLIB_CALL(sun_subsystem_initialize)
14-
return SS_INIT_SUCCESS
10+
var/angle
11+
var/dx
12+
var/dy
13+
var/rate
1514

15+
var/list/solars = list()
16+
var/solar_gen_rate = 1500
1617

17-
/datum/controller/subsystem/sun/get_stat_details()
18-
return "P:[get_solars_length()]"
1918

19+
/datum/controller/subsystem/sun/Initialize()
20+
// Lets work out an angle for the "sun" to rotate around the station
21+
angle = rand (0, 360) // the station position to the sun is randomised at round start
22+
rate = rand(50, 200) / 100 // 50% - 200% of standard rotation
2023

21-
/datum/controller/subsystem/sun/fire()
22-
RUSTLIB_CALL(sun_subsystem_fire)
24+
if(prob(50)) // same chance to rotate clockwise than counter-clockwise
25+
rate = -rate
2326

24-
/datum/controller/subsystem/sun/proc/get_angle()
25-
return RUSTLIB_CALL(get_sun_angle)
27+
// Solar consoles need to load after machines init, so this handles that
28+
for(var/obj/machinery/power/solar_control/control in solars)
29+
control.setup()
2630

27-
/datum/controller/subsystem/sun/proc/add_solar(obj/machinery/power/solar_control/solar)
28-
return RUSTLIB_CALL(add_solar, solar, solar.get_num_uid())
31+
return SS_INIT_SUCCESS
2932

30-
/datum/controller/subsystem/sun/proc/remove_solar(obj/machinery/power/solar_control/solar)
31-
return RUSTLIB_CALL(remove_solar, solar.get_num_uid())
3233

33-
/datum/controller/subsystem/sun/proc/get_solars_length()
34-
return RUSTLIB_CALL(get_solars_length)
34+
/datum/controller/subsystem/sun/get_stat_details()
35+
return "P:[solars.len]"
3536

36-
/datum/controller/subsystem/sun/proc/get_dy()
37-
return RUSTLIB_CALL(get_sun_dy)
3837

39-
/datum/controller/subsystem/sun/proc/get_dx()
40-
return RUSTLIB_CALL(get_sun_dx)
38+
/datum/controller/subsystem/sun/fire()
39+
angle = (360 + angle + rate * 6) % 360 // increase/decrease the angle to the sun, adjusted by the rate
40+
41+
// now calculate and cache the (dx,dy) increments for line drawing
42+
var/ang_sin = sin(angle)
43+
var/ang_cos = cos(angle)
44+
45+
if(abs(ang_sin) < abs(ang_cos))
46+
dx = ang_sin / abs(ang_cos)
47+
dy = ang_cos / abs(ang_cos)
48+
else
49+
dx = ang_sin / abs(ang_sin)
50+
dy = ang_cos / abs(ang_sin)
51+
52+
// now tell the solar control computers to update their status and linked devices
53+
for(var/obj/machinery/power/solar_control/control in solars)
54+
if(!control.powernet)
55+
solars.Remove(control)
56+
continue
57+
58+
control.update()

code/datums/datum.dm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
var/list/list/signal_procs
2727

2828
var/tmp/unique_datum_id = null
29-
var/tmp/numeric_datum_id = null
3029
/// Datum level flags
3130
var/datum_flags = NONE
3231

@@ -67,6 +66,9 @@
6766
tag = null
6867
weak_reference = null //ensure prompt GCing of weakref.
6968

69+
if(unique_datum_id)
70+
RUSTLIB_CALL(untick_by_uuid, unique_datum_id)
71+
7072
var/list/timers = active_timers
7173
active_timers = null
7274
for(var/thing in timers)
@@ -93,7 +95,6 @@
9395

9496
return QDEL_HINT_QUEUE
9597

96-
9798
///Only override this if you know what you're doing. You do not know what you're doing
9899
///This is a threat
99100
/datum/proc/_clear_signal_refs()

code/datums/weakrefs.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@
7373
* This will return `null` if the datum was deleted. This MUST be respected.
7474
*/
7575
/datum/weakref/proc/resolve()
76-
var/datum/D = locate(reference)
77-
return (!QDELETED(D) && D.weak_reference == src) ? D : null
76+
var/datum/datum = locateUID(reference)
77+
return (!QDELETED(datum) && datum.weak_reference == src) ? datum : null

code/game/machinery/computer/camera.dm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,12 @@
133133
return
134134

135135
if(action == "switch_camera")
136-
var/obj/machinery/camera/selected_camera = locate(params["camera"]) in GLOB.cameranet.cameras
136+
var/obj/machinery/camera/selected_camera = locateUID(params["camera"])
137+
137138
if(isnull(selected_camera))
138139
to_chat(usr, span_warning("ОШИБКА. Камера не найдена."))
139140
return
141+
140142
active_camera?.computers_watched_by -= src
141143
active_camera = selected_camera
142144
active_camera.computers_watched_by += src

code/modules/antagonists/vampire/vampire_datum.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,8 +508,8 @@
508508
var/ay = owner.current.y
509509

510510
for(var/i = 1 to 20)
511-
ax += SSsun.get_dy()
512-
ay += SSsun.get_dx()
511+
ax += SSsun.dy
512+
ay += SSsun.dx
513513

514514
var/turf/T = locate(round(ax, 0.5), round(ay, 0.5), owner.current.z)
515515

code/modules/hydroponics/gene_modder.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274

275275
var/mob/user = ui.user
276276

277-
target = seed?.get_gene(params["id"])
277+
target = locateUID(params["id"])
278278

279279
switch(action)
280280
if("eject_seed")

code/modules/lootpanel/ui.dm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
/// Clicks an object from the contents. Validates the object and the user
1818
/datum/lootpanel/proc/grab(mob/user, list/params)
1919
var/uid = params["uid"]
20+
2021
if(isnull(uid))
2122
return FALSE
2223

2324
if(!source_turf.Adjacent(user)) // Source tile is no longer valid
2425
reset_contents()
2526
return FALSE
2627

27-
var/datum/search_object/index = locate(uid) in contents
28+
var/datum/search_object/index = locateUID(uid)
2829
var/atom/thing = index?.item
30+
2931
if(QDELETED(index) || QDELETED(thing)) // Obj is gone
3032
return FALSE
3133

code/modules/mob/dead/observer/observer.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
637637
ManualFollow(target)
638638

639639
if(href_list["follow"])
640-
var/atom/target = locate(href_list["follow"])
640+
var/atom/target = locateUID(href_list["follow"])
641641
if(target)
642642
ManualFollow(target)
643643

code/modules/mob/dead/observer/orbit.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
/datum/orbit_menu/proc/handle_orbit_action(list/params)
3939
var/ref = params["ref"]
4040
var/atom/movable/poi = (locate(ref) in GLOB.mob_list) || (locate(ref) in GLOB.poi_list)
41+
4142
if(!poi)
4243
return
4344

0 commit comments

Comments
 (0)