Skip to content

Commit e0025fb

Browse files
committed
add: Rust UUID & Unbundle sun (#7069) [testmerge][d81796c]
1 parent 25e6f6f commit e0025fb

File tree

18 files changed

+116
-282
lines changed

18 files changed

+116
-282
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

@@ -53,6 +52,9 @@
5352
tag = null
5453
weak_reference = null //ensure prompt GCing of weakref.
5554

55+
if(unique_datum_id)
56+
RUSTLIB_CALL(untick_by_uuid, unique_datum_id)
57+
5658
var/list/timers = active_timers
5759
active_timers = null
5860
for(var/thing in timers)
@@ -79,7 +81,6 @@
7981

8082
return QDEL_HINT_QUEUE
8183

82-
8384
///Only override this if you know what you're doing. You do not know what you're doing
8485
///This is a threat
8586
/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/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/power/solar.dm

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
return
113113

114114
// find the smaller angle between the direction the panel is facing and the direction of the sun (the sign is not important here)
115-
var/sun_angle = SSsun.get_angle()
115+
var/sun_angle = SSsun.angle
116116
var/p_angle = min(abs(adir - sun_angle), 360 - abs(adir - sun_angle))
117117

118118
if(p_angle > 90) // if facing more than 90deg from sun, zero output
@@ -157,8 +157,8 @@
157157
var/ay = y
158158
var/turf/T = null
159159

160-
var/dx = SSsun.get_dx()
161-
var/dy = SSsun.get_dy()
160+
var/dx = SSsun.dx
161+
var/dy = SSsun.dy
162162

163163
for(var/i = 1 to 20) // 20 steps is enough
164164
ax += dx // do step
@@ -357,7 +357,7 @@
357357
search_for_connected()
358358

359359
if(connected_tracker && track == TRACKER_AUTO)
360-
connected_tracker.modify_angle(SSsun.get_angle())
360+
connected_tracker.modify_angle(SSsun.angle)
361361

362362
set_panels(cdir)
363363

@@ -368,18 +368,18 @@
368368
if(connected_tracker)
369369
connected_tracker.unset_control()
370370

371-
SSsun.remove_solar(src)
371+
SSsun.solars -= src
372372
return ..()
373373

374374
/obj/machinery/power/solar_control/disconnect_from_network()
375375
..()
376-
SSsun.remove_solar(src)
376+
SSsun.solars -= src
377377

378378
/obj/machinery/power/solar_control/connect_to_network()
379379
var/to_return = ..()
380380

381381
if(powernet) // if connected and not already in solar list...
382-
SSsun.add_solar(src) //... add it
382+
SSsun.solars |= src
383383

384384
return to_return
385385

@@ -400,7 +400,7 @@
400400
//called by the sun controller, update the facing angle (either manually or via tracking) and rotates the panels accordingly
401401
/obj/machinery/power/solar_control/proc/update()
402402
if(track == TRACKER_AUTO && connected_tracker) // auto-tracking
403-
connected_tracker.modify_angle(SSsun.get_angle())
403+
connected_tracker.modify_angle(SSsun.angle)
404404
set_panels(cdir)
405405

406406
updateDialog()
@@ -474,7 +474,7 @@
474474
track = text2num(params["track"])
475475
if(track == TRACKER_AUTO)
476476
if(connected_tracker)
477-
connected_tracker.modify_angle(SSsun.get_angle())
477+
connected_tracker.modify_angle(SSsun.angle)
478478
set_panels(cdir)
479479
else if(track == TRACKER_TIMED)
480480
targetdir = cdir
@@ -484,7 +484,7 @@
484484
if("refresh")
485485
search_for_connected()
486486
if(connected_tracker && track == TRACKER_AUTO)
487-
connected_tracker.modify_angle(SSsun.get_angle())
487+
connected_tracker.modify_angle(SSsun.angle)
488488
set_panels(cdir)
489489

490490
/obj/machinery/power/solar_control/screwdriver_act(mob/user, obj/item/I)
@@ -529,7 +529,7 @@
529529
playsound(loc, 'sound/effects/glassbr3.ogg', 100, TRUE)
530530
stat |= BROKEN
531531
update_icon(UPDATE_OVERLAYS)
532-
SSsun.remove_solar(src)
532+
SSsun.solars -= src
533533

534534
/obj/machinery/power/solar_control/process()
535535
lastgen = gen

librustlibs.so

-33.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)