Maybe optimize some SSmachines things

This commit is contained in:
Aronai Sieyes
2021-07-27 21:18:41 -04:00
parent 9ee28de20e
commit 8d2f4f66b7
+31 -36
View File
@@ -6,9 +6,6 @@
//
// SSmachines subsystem - Processing machines, pipenets, and powernets!
//
// Implementation Plan:
// PHASE 1 - Add subsystem using the existing global list vars
// PHASE 2 - Move the global list vars into the subsystem.
SUBSYSTEM_DEF(machines)
name = "Machines"
@@ -24,12 +21,6 @@ SUBSYSTEM_DEF(machines)
var/cost_powernets = 0
var/cost_power_objects = 0
// TODO - PHASE 2 - Switch these from globals to instance vars
// var/list/pipenets = list()
// var/list/machinery = list()
// var/list/powernets = list()
// var/list/power_objects = list()
var/list/current_run = list()
/datum/controller/subsystem/machines/Initialize(timeofday)
@@ -51,28 +42,31 @@ SUBSYSTEM_DEF(machines)
// The above is a lie. Turbolifts also call this proc.
/datum/controller/subsystem/machines/proc/makepowernets()
// TODO - check to not run while in the middle of a tick!
for(var/datum/powernet/PN in powernets)
for(var/datum/powernet/PN as anything in powernets)
qdel(PN)
powernets.Cut()
setup_powernets_for_cables(cable_list)
/datum/controller/subsystem/machines/proc/setup_powernets_for_cables(list/cables)
for(var/obj/structure/cable/PC in cables)
for(var/obj/structure/cable/PC as anything in cables)
if(!PC.powernet)
var/datum/powernet/NewPN = new()
NewPN.add_cable(PC)
propagate_network(PC,PC.powernet)
/datum/controller/subsystem/machines/proc/setup_atmos_machinery(list/atmos_machines)
var/list/actual_atmos_machines = list()
for(var/obj/machinery/atmospherics/machine in atmos_machines)
machine.atmos_init()
actual_atmos_machines += machine
CHECK_TICK
for(var/obj/machinery/atmospherics/machine in atmos_machines)
for(var/obj/machinery/atmospherics/machine as anything in actual_atmos_machines)
machine.build_network()
CHECK_TICK
for(var/obj/machinery/atmospherics/unary/U in atmos_machines)
for(var/obj/machinery/atmospherics/unary/U as anything in actual_atmos_machines)
if(istype(U, /obj/machinery/atmospherics/unary/vent_pump))
var/obj/machinery/atmospherics/unary/vent_pump/T = U
T.broadcast_status()
@@ -105,12 +99,10 @@ SUBSYSTEM_DEF(machines)
while(current_run.len)
var/datum/pipe_network/PN = current_run[current_run.len]
current_run.len--
if(istype(PN) && !QDELETED(PN))
PN.process(wait)
else
if(QDELETED(PN))
global.pipe_networks.Remove(PN)
if(!QDELETED(PN))
DISABLE_BITFIELD(PN.datum_flags, DF_ISPROCESSING)
else
PN.process(wait)
if(MC_TICK_CHECK)
return
@@ -123,11 +115,8 @@ SUBSYSTEM_DEF(machines)
while(current_run.len)
var/obj/machinery/M = current_run[current_run.len]
current_run.len--
if(!istype(M) || QDELETED(M) || (M.process(wait) == PROCESS_KILL))
if(QDELETED(M) || (M.process(wait) == PROCESS_KILL))
global.processing_machines.Remove(M)
if(!QDELETED(M))
DISABLE_BITFIELD(M.datum_flags, DF_ISPROCESSING)
if(MC_TICK_CHECK)
return
@@ -140,12 +129,10 @@ SUBSYSTEM_DEF(machines)
while(current_run.len)
var/datum/powernet/PN = current_run[current_run.len]
current_run.len--
if(istype(PN) && !QDELETED(PN))
PN.reset(wait)
else
if(QDELETED(PN))
global.powernets.Remove(PN)
if(!QDELETED(PN))
DISABLE_BITFIELD(PN.datum_flags, DF_ISPROCESSING)
else
PN.reset(wait)
if(MC_TICK_CHECK)
return
@@ -167,16 +154,24 @@ SUBSYSTEM_DEF(machines)
return
/datum/controller/subsystem/machines/Recover()
// TODO - PHASE 2
// if (istype(SSmachines.pipenets))
// pipenets = SSmachines.pipenets
// if (istype(SSmachines.machinery))
// machinery = SSmachines.machinery
// if (istype(SSmachines.powernets))
// powernets = SSmachines.powernets
// if (istype(SSmachines.power_objects))
// power_objects = SSmachines.power_objects
for(var/datum/D as anything in global.pipe_networks)
if(!istype(D, /datum/pipe_network))
error("Found wrong type during SSmachinery recovery: list=global.pipe_networks, item=[D], type=[D?.type]")
global.pipe_networks -= D
for(var/datum/D as anything in global.processing_machines)
if(!istype(D, /obj/machinery))
error("Found wrong type during SSmachinery recovery: list=global.processing_machines, item=[D], type=[D?.type]")
global.processing_machines -= D
for(var/datum/D as anything in global.powernets)
if(!istype(D, /datum/powernet))
error("Found wrong type during SSmachinery recovery: list=global.powernets, item=[D], type=[D?.type]")
global.powernets -= D
for(var/datum/D as anything in global.processing_power_items)
if(!istype(D, /obj/item))
error("Found wrong type during SSmachinery recovery: list=global.processing_power_items, item=[D], type=[D?.type]")
global.processing_power_items -= D
#undef SSMACHINES_PIPENETS
#undef SSMACHINES_MACHINERY
#undef SSMACHINES_POWERNETS
#undef SSMACHINES_POWER_OBJECTS