Skip to content

Commit 4889b33

Browse files
authored
SSmachines instancing PR (#9080)
* Consistency Pass #1 Power cells of all types are now considered stock parts Went through materials.dm and did some copy+paste work make material definitions consistent across the codebase (eg "steel" = 50 -> MAT_STEEL = 50) * Machines are now instances in SSMachines * Performance improvements by way of instancing all of SSmachines * Fixes the powersink * Revert "Consistency Pass #1" This reverts commit cbeef1b. * Update machines.dm Styling changes * Update machines.dm * Update machines.dm forgot to update the doc
1 parent 567f003 commit 4889b33

File tree

17 files changed

+151
-127
lines changed

17 files changed

+151
-127
lines changed

code/ATMOSPHERICS/datum_pipe_network.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var/global/list/datum/pipe_network/pipe_networks = list() // TODO - Move into SS
1414
//var/datum/gas_mixture/air_transient = null
1515

1616
/datum/pipe_network/Destroy()
17-
STOP_PROCESSING_PIPENET(src)
17+
STOP_PROCESSING_MACHINERY(src, SSMACHINES_PIPENETS_LIST)
1818
for(var/datum/pipeline/line_member in line_members)
1919
line_member.network = null
2020
for(var/obj/machinery/atmospherics/normal_member in normal_members)
@@ -48,7 +48,7 @@ var/global/list/datum/pipe_network/pipe_networks = list() // TODO - Move into SS
4848
update_network_gases()
4949

5050
if((normal_members.len>0)||(line_members.len>0))
51-
START_PROCESSING_PIPENET(src)
51+
START_PROCESSING_MACHINERY(src, SSMACHINES_PIPENETS_LIST)
5252
else
5353
qdel(src)
5454

code/ATMOSPHERICS/pipes/pipe_base.dm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@
3535
/obj/machinery/atmospherics/pipe/proc/set_leaking(var/new_leaking)
3636
if(new_leaking && !leaking)
3737
if(!speed_process)
38-
START_MACHINE_PROCESSING(src)
38+
begin_processing()
3939
else
40-
START_PROCESSING(SSfastprocess, src)
40+
begin_speed_processing()
4141
leaking = TRUE
4242
if(parent)
4343
parent.leaks |= src
4444
if(parent.network)
4545
parent.network.leaks |= src
4646
else if (!new_leaking && leaking)
4747
if(!speed_process)
48-
STOP_MACHINE_PROCESSING(src)
48+
end_processing()
4949
else
50-
STOP_PROCESSING(SSfastprocess, src)
50+
end_speed_processing()
5151
leaking = FALSE
5252
if(parent)
5353
parent.leaks -= src

code/__defines/machinery.dm

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ var/global/defer_powernet_rebuild = 0 // True if net rebuild will be called
1717
#define USE_POWER_IDLE 1 // Machine is using power at its idle power level
1818
#define USE_POWER_ACTIVE 2 // Machine is using power at its active power level
1919

20+
/// Bitflags for a machine's preferences on when it should start processing. For use with machinery's `processing_flags` var.
21+
#define START_PROCESSING_ON_INIT (1<<0) /// Indicates the machine will automatically start processing right after it's `Initialize()` is ran.
22+
#define START_PROCESSING_MANUALLY (1<<1) /// Machines with this flag will not start processing when it's spawned. Use this if you want to manually control when a machine starts processing.
23+
24+
2025
// Channel numbers for power.
2126
#define CURRENT_CHANNEL -1 // Passed as an argument this means "use whatever current channel is"
2227
#define EQUIP 1
@@ -139,30 +144,22 @@ var/global/list/restricted_camera_networks = list(NETWORK_ERT,NETWORK_MERCENARY,
139144
#define SUPERMATTER_EMERGENCY 5 // Integrity < 25%
140145
#define SUPERMATTER_DELAMINATING 6 // Pretty obvious.
141146

142-
//wIP - PORT ALL OF THESE TO SUBSYSTEMS AND GET RID OF THE WHOLE LIST PROCESS THING
143-
// Fancy-pants START/STOP_PROCESSING() macros that lets us custom define what the list is.
144-
#define START_PROCESSING_IN_LIST(DATUM, LIST) \
145-
if (!(DATUM.datum_flags & DF_ISPROCESSING)) {\
146-
LIST += DATUM;\
147-
DATUM.datum_flags |= DF_ISPROCESSING\
148-
}
149-
150-
#define STOP_PROCESSING_IN_LIST(DATUM, LIST) LIST.Remove(DATUM);DATUM.datum_flags &= ~DF_ISPROCESSING
151-
152-
// Note - I would prefer these be defined machines.dm, but some are used prior in file order. ~Leshana
153-
#define START_MACHINE_PROCESSING(Datum) START_PROCESSING_IN_LIST(Datum, global.processing_machines)
154-
#define STOP_MACHINE_PROCESSING(Datum) STOP_PROCESSING_IN_LIST(Datum, global.processing_machines)
155-
156-
#define START_PROCESSING_PIPENET(Datum) START_PROCESSING_IN_LIST(Datum, global.pipe_networks)
157-
#define STOP_PROCESSING_PIPENET(Datum) STOP_PROCESSING_IN_LIST(Datum, global.pipe_networks)
158-
159-
#define START_PROCESSING_POWERNET(Datum) START_PROCESSING_IN_LIST(Datum, global.powernets)
160-
#define STOP_PROCESSING_POWERNET(Datum) STOP_PROCESSING_IN_LIST(Datum, global.powernets)
161-
162-
#define START_PROCESSING_POWER_OBJECT(Datum) START_PROCESSING_IN_LIST(Datum, global.processing_power_items)
163-
#define STOP_PROCESSING_POWER_OBJECT(Datum) STOP_PROCESSING_IN_LIST(Datum, global.processing_power_items)
147+
// SSmachines categories
148+
#define SSMACHINES_MACHINERY_LIST 0 // The default, most things processed by SSmachines are the machinery type
149+
#define SSMACHINES_POWERNETS_LIST 1 // Powernets to be processed
150+
#define SSMACHINES_POWEROBJS_LIST 2 // Power objects to be processed (only powersinks atm)
151+
#define SSMACHINES_PIPENETS_LIST 3 // Pipenets to be worked through
152+
153+
/// Takes a datum and optionally a flag (`SSMACHINES_MACHINERY_LIST` (default), `SSMACHINES_POWERNETS_LIST`, `SSMACHINES_POWEROJBS_LIST`, `SSMACHINES_PIPENETS_LIST`) and adds that datum
154+
/// to SSmachines
155+
#define START_PROCESSING_MACHINERY(Datum, List) if (!(Datum.datum_flags & DF_ISPROCESSING)) {Datum.datum_flags |= DF_ISPROCESSING;SSmachines.start_processing(Datum, List)}
156+
#define STOP_PROCESSING_MACHINERY(Datum, List) Datum.datum_flags &= ~DF_ISPROCESSING;SSmachines.stop_processing(Datum, List)
157+
/// Takes a datum and optionally a flag (`SSMACHINES_MACHINERY_LIST` (default), `SSMACHINES_POWERNETS_LIST`, `SSMACHINES_POWEROJBS_LIST`, `SSMACHINES_PIPENETS_LIST`) and removes that datum
158+
/// from SSmachines
159+
#define START_SPEED_PROCESSING(Datum) if (!(Datum.datum_flags & DF_ISPROCESSING)) {Datum.datum_flags |= DF_ISPROCESSING;SSfastprocess.processing += Datum}
160+
#define STOP_SPEED_PROCESSING(Datum) Datum.datum_flags &= ~DF_ISPROCESSING;SSfastprocess.processing -= Datum
164161

165162
// Computer login types
166163
#define LOGIN_TYPE_NORMAL 1
167164
#define LOGIN_TYPE_AI 2
168-
#define LOGIN_TYPE_ROBOT 3
165+
#define LOGIN_TYPE_ROBOT 3

code/controllers/subsystems/machines.dm

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
#define SSMACHINES_PIPENETS 1
22
#define SSMACHINES_MACHINERY 2
33
#define SSMACHINES_POWERNETS 3
4-
#define SSMACHINES_POWER_OBJECTS 4
5-
6-
//
7-
// SSmachines subsystem - Processing machines, pipenets, and powernets!
8-
//
9-
// Implementation Plan:
10-
// PHASE 1 - Add subsystem using the existing global list vars
11-
// PHASE 2 - Move the global list vars into the subsystem.
4+
#define SSMACHINES_POWER_ITEMS 4
125

136
SUBSYSTEM_DEF(machines)
147
name = "Machines"
@@ -19,18 +12,17 @@ SUBSYSTEM_DEF(machines)
1912

2013
var/current_step = SSMACHINES_PIPENETS
2114

22-
var/cost_pipenets = 0
23-
var/cost_machinery = 0
24-
var/cost_powernets = 0
25-
var/cost_power_objects = 0
15+
var/cost_pipenets = 0
16+
var/cost_machinery = 0
17+
var/cost_powernets = 0
18+
var/cost_power_objects = 0
2619

27-
// TODO - PHASE 2 - Switch these from globals to instance vars
28-
// var/list/pipenets = list()
29-
// var/list/machinery = list()
30-
// var/list/powernets = list()
31-
// var/list/power_objects = list()
20+
var/list/pipenets = list()
21+
var/list/machinery = list()
22+
var/list/powernets = list()
23+
var/list/power_objects = list()
3224

33-
var/list/current_run = list()
25+
var/list/current_run = list()
3426

3527
/datum/controller/subsystem/machines/Initialize(timeofday)
3628
makepowernets()
@@ -41,10 +33,10 @@ SUBSYSTEM_DEF(machines)
4133
/datum/controller/subsystem/machines/fire(resumed, no_mc_tick)
4234
var/timer = TICK_USAGE
4335

44-
INTERNAL_PROCESS_STEP(SSMACHINES_POWER_OBJECTS,FALSE,process_power_objects,cost_power_objects,SSMACHINES_PIPENETS) // Higher priority, damnit
36+
INTERNAL_PROCESS_STEP(SSMACHINES_POWER_ITEMS,FALSE,process_power_objects,cost_power_objects,SSMACHINES_PIPENETS) // Higher priority, damnit
4537
INTERNAL_PROCESS_STEP(SSMACHINES_PIPENETS,TRUE,process_pipenets,cost_pipenets,SSMACHINES_MACHINERY)
4638
INTERNAL_PROCESS_STEP(SSMACHINES_MACHINERY,FALSE,process_machinery,cost_machinery,SSMACHINES_POWERNETS)
47-
INTERNAL_PROCESS_STEP(SSMACHINES_POWERNETS,FALSE,process_powernets,cost_powernets,SSMACHINES_POWER_OBJECTS)
39+
INTERNAL_PROCESS_STEP(SSMACHINES_POWERNETS,FALSE,process_powernets,cost_powernets,SSMACHINES_POWER_ITEMS)
4840

4941
// rebuild all power networks from scratch - only called at world creation or by the admin verb
5042
// The above is a lie. Turbolifts also call this proc.
@@ -88,16 +80,16 @@ SUBSYSTEM_DEF(machines)
8880
msg += "PN:[round(cost_powernets,1)]|"
8981
msg += "PO:[round(cost_power_objects,1)]"
9082
msg += "} "
91-
msg += "PI:[global.pipe_networks.len]|"
92-
msg += "MC:[global.processing_machines.len]|"
93-
msg += "PN:[global.powernets.len]|"
94-
msg += "PO:[global.processing_power_items.len]|"
95-
msg += "MC/MS:[round((cost ? global.processing_machines.len/cost_machinery : 0),0.1)]"
83+
msg += "PI:[pipe_networks.len]|"
84+
msg += "MC:[machinery.len]|"
85+
msg += "PN:[powernets.len]|"
86+
msg += "PO:[power_objects.len]|"
87+
msg += "MC/MS:[round((cost ? machinery.len/cost_machinery : 0),0.1)]"
9688
..(jointext(msg, null))
9789

9890
/datum/controller/subsystem/machines/proc/process_pipenets(resumed = 0)
9991
if (!resumed)
100-
src.current_run = global.pipe_networks.Copy()
92+
src.current_run = pipe_networks.Copy()
10193
//cache for sanic speed (lists are references anyways)
10294
var/list/current_run = src.current_run
10395
while(current_run.len)
@@ -106,31 +98,31 @@ SUBSYSTEM_DEF(machines)
10698
if(istype(PN) && !QDELETED(PN))
10799
PN.process(wait)
108100
else
109-
global.pipe_networks.Remove(PN)
101+
pipe_networks.Remove(PN)
110102
if(!QDELETED(PN))
111103
DISABLE_BITFIELD(PN.datum_flags, DF_ISPROCESSING)
112104
if(MC_TICK_CHECK)
113105
return
114106

115107
/datum/controller/subsystem/machines/proc/process_machinery(resumed = 0)
116108
if (!resumed)
117-
src.current_run = global.processing_machines.Copy()
109+
src.current_run = machines.Copy()
118110

119111
var/list/current_run = src.current_run
120112
while(current_run.len)
121113
var/obj/machinery/M = current_run[current_run.len]
122114
current_run.len--
123115

124116
if(!istype(M) || QDELETED(M) || (M.process(wait) == PROCESS_KILL))
125-
global.processing_machines.Remove(M)
117+
machines.Remove(M)
126118
if(!QDELETED(M))
127119
DISABLE_BITFIELD(M.datum_flags, DF_ISPROCESSING)
128120
if(MC_TICK_CHECK)
129121
return
130122

131123
/datum/controller/subsystem/machines/proc/process_powernets(resumed = 0)
132124
if (!resumed)
133-
src.current_run = global.powernets.Copy()
125+
src.current_run = powernets.Copy()
134126

135127
var/list/current_run = src.current_run
136128
while(current_run.len)
@@ -139,7 +131,7 @@ SUBSYSTEM_DEF(machines)
139131
if(istype(PN) && !QDELETED(PN))
140132
PN.reset(wait)
141133
else
142-
global.powernets.Remove(PN)
134+
powernets.Remove(PN)
143135
if(!QDELETED(PN))
144136
DISABLE_BITFIELD(PN.datum_flags, DF_ISPROCESSING)
145137
if(MC_TICK_CHECK)
@@ -149,19 +141,44 @@ SUBSYSTEM_DEF(machines)
149141
// Currently only used by powersinks. These items get priority processed before machinery
150142
/datum/controller/subsystem/machines/proc/process_power_objects(resumed = 0)
151143
if (!resumed)
152-
src.current_run = global.processing_power_items.Copy()
144+
src.current_run = power_objects.Copy()
153145

154146
var/list/current_run = src.current_run
155147
while(current_run.len)
156148
var/obj/item/I = current_run[current_run.len]
157149
current_run.len--
158150
if(!I.pwr_drain(wait)) // 0 = Process Kill, remove from processing list.
159-
global.processing_power_items.Remove(I)
151+
power_objects.Remove(I)
160152
DISABLE_BITFIELD(I.datum_flags, DF_ISPROCESSING)
161153
if(MC_TICK_CHECK)
162154
return
163155

156+
/** Adds a datum to this subsystem
157+
*
158+
* `dat` - datum to be added
159+
*
160+
* `list = SSMACHINES_MACHINERY_LIST` - list to be added to, defaults to machines
161+
*/
162+
/datum/controller/subsystem/machines/proc/start_processing(dat, list = SSMACHINES_MACHINERY_LIST)
163+
switch(list)
164+
if(SSMACHINES_MACHINERY_LIST) machinery += dat
165+
if(SSMACHINES_POWERNETS_LIST) powernets += dat
166+
if(SSMACHINES_POWEROBJS_LIST) power_objects += dat
167+
if(SSMACHINES_PIPENETS_LIST) pipenets += dat
168+
169+
/** Removes a datum from this subsystem
170+
*
171+
* ```dat``` - datum to be removed
172+
*
173+
*```list``` = SSMACHINES_MACHINERY_LIST` - list to be removed from, defaults to machines
174+
*/
175+
/datum/controller/subsystem/machines/proc/stop_processing(dat, list = SSMACHINES_MACHINERY_LIST)
176+
switch(list)
177+
if(SSMACHINES_MACHINERY_LIST) machinery -= dat
178+
if(SSMACHINES_POWERNETS_LIST) powernets -= dat
179+
if(SSMACHINES_POWEROBJS_LIST) power_objects -= dat
180+
if(SSMACHINES_PIPENETS_LIST) pipenets -= dat
164181

165182
#undef SSMACHINES_PIPENETS
166183
#undef SSMACHINES_MACHINERY
167-
#undef SSMACHINES_POWER_OBJECTS
184+
#undef SSMACHINES_POWER_ITEMS

code/controllers/subsystems/processing/fastprocess.dm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PROCESSING_SUBSYSTEM_DEF(fastprocess)
44
name = "Fast Processing"
55
wait = 0.2 SECONDS
66
stat_tag = "FP"
7+
var/list/machinery = list()
78

89
/datum/controller/subsystem/processing/fastprocess/Recover()
910
log_debug("[name] subsystem Recover().")
@@ -12,4 +13,4 @@ PROCESSING_SUBSYSTEM_DEF(fastprocess)
1213
var/list/old_processing = SSfastprocess.processing.Copy()
1314
for(var/datum/D in old_processing)
1415
if(CHECK_BITFIELD(D.datum_flags, DF_ISPROCESSING))
15-
processing |= D
16+
processing |= D

code/game/machinery/camera/presets.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ var/global/list/engineering_networks = list(
171171
var/list/my_area = by_area[A.name]
172172
my_area += src
173173
var/number = my_area.len
174-
174+
175175
c_tag = "[A.name] #[number]"
176-
176+
177177
/obj/machinery/camera/autoname/Destroy()
178178
var/area/A = get_area(src)
179179
if(!A || !by_area || !by_area[A.name])
@@ -215,7 +215,7 @@ var/global/list/engineering_networks = list(
215215
return //nooooo
216216
assembly.upgrades.Add(new /obj/item/assembly/prox_sensor(assembly))
217217
setPowerUsage()
218-
START_MACHINE_PROCESSING(src)
218+
begin_processing()
219219
sense_proximity(callback = /atom/proc/HasProximity)
220220
update_coverage()
221221

code/game/machinery/doors/airlock.dm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ About the new airlock wires panel:
643643
backup_power_lost_until = world.time + SecondsToTicks(10)
644644

645645
if(main_power_lost_until > 0 || backup_power_lost_until > 0)
646-
START_MACHINE_PROCESSING(src)
646+
begin_processing()
647647

648648
// Disable electricity if required
649649
if(electrified_until && isAllPowerLoss())
@@ -655,7 +655,7 @@ About the new airlock wires panel:
655655
backup_power_lost_until = backupPowerCablesCut() ? -1 : world.time + SecondsToTicks(60)
656656

657657
if(backup_power_lost_until > 0)
658-
START_MACHINE_PROCESSING(src)
658+
begin_processing()
659659

660660
// Disable electricity if required
661661
if(electrified_until && isAllPowerLoss())
@@ -700,7 +700,7 @@ About the new airlock wires panel:
700700
src.electrified_until = duration == -1 ? -1 : world.time + SecondsToTicks(duration)
701701

702702
if(electrified_until > 0)
703-
START_MACHINE_PROCESSING(src)
703+
begin_processing()
704704

705705
if(feedback && message)
706706
to_chat(usr,message)

0 commit comments

Comments
 (0)