diff --git a/code/controllers/subsystem.dm b/code/controllers/subsystem.dm index cd029b58ed8..be9c8a88032 100644 --- a/code/controllers/subsystem.dm +++ b/code/controllers/subsystem.dm @@ -97,9 +97,9 @@ return //This is used so the mc knows when the subsystem sleeps. do not override. -/datum/controller/subsystem/proc/ignite(resumed = 0) +/datum/controller/subsystem/proc/ignite(resumed = FALSE) SHOULD_NOT_OVERRIDE(TRUE) - set waitfor = 0 + set waitfor = FALSE . = SS_SLEEPING fire(resumed) . = state @@ -114,7 +114,7 @@ //previously, this would have been named 'process()' but that name is used everywhere for different things! //fire() seems more suitable. This is the procedure that gets called every 'wait' deciseconds. //Sleeping in here prevents future fires until returned. -/datum/controller/subsystem/proc/fire(resumed = 0) +/datum/controller/subsystem/proc/fire(resumed = FALSE) flags |= SS_NO_FIRE CRASH("Subsystem [src]([type]) does not fire() but did not set the SS_NO_FIRE flag. Please add the SS_NO_FIRE flag to any subsystem that doesn't fire so it doesn't get added to the processing list and waste cpu.") diff --git a/code/controllers/subsystem/air.dm b/code/controllers/subsystem/air.dm index e8e6f9209ac..61c9c3e953d 100644 --- a/code/controllers/subsystem/air.dm +++ b/code/controllers/subsystem/air.dm @@ -6,6 +6,7 @@ SUBSYSTEM_DEF(air) flags = SS_BACKGROUND runlevels = RUNLEVEL_GAME | RUNLEVEL_POSTGAME + var/cached_cost = 0 var/cost_turfs = 0 var/cost_groups = 0 var/cost_highpressure = 0 @@ -40,7 +41,6 @@ SUBSYSTEM_DEF(air) var/list/queued_for_activation var/display_all_groups = FALSE - var/lasttick = 0 /datum/controller/subsystem/air/stat_entry(msg) msg += "C:{" @@ -78,76 +78,101 @@ SUBSYSTEM_DEF(air) var/delta_time = wait * 0.1 if(currentpart == SSAIR_REBUILD_PIPENETS) + if(!resumed) //We track the use for each subprocess for the full tick, so we can get an acccurate idea of how much each part costs + cached_cost = 0 var/list/pipenet_rebuilds = pipenets_needing_rebuilt for(var/thing in pipenet_rebuilds) var/obj/machinery/atmospherics/AT = thing AT.build_network() - cost_rebuilds = MC_AVERAGE(cost_rebuilds, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer pipenets_needing_rebuilt.Cut() if(state != SS_RUNNING) return + cost_rebuilds = MC_AVERAGE(cost_rebuilds, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_PIPENETS if(currentpart == SSAIR_PIPENETS || !resumed) + timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_pipenets(delta_time, resumed) - cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_pipenets = MC_AVERAGE(cost_pipenets, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_ATMOSMACHINERY if(currentpart == SSAIR_ATMOSMACHINERY) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_atmos_machinery(delta_time, resumed) - cost_atmos_machinery = MC_AVERAGE(cost_atmos_machinery, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_atmos_machinery = MC_AVERAGE(cost_atmos_machinery, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_ACTIVETURFS if(currentpart == SSAIR_ACTIVETURFS) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_active_turfs(resumed) - cost_turfs = MC_AVERAGE(cost_turfs, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_turfs = MC_AVERAGE(cost_turfs, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_EXCITEDGROUPS if(currentpart == SSAIR_EXCITEDGROUPS) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_excited_groups(resumed) - cost_groups = MC_AVERAGE(cost_groups, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_groups = MC_AVERAGE(cost_groups, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_HIGHPRESSURE if(currentpart == SSAIR_HIGHPRESSURE) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_high_pressure_delta(resumed) - cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_highpressure = MC_AVERAGE(cost_highpressure, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_HOTSPOTS if(currentpart == SSAIR_HOTSPOTS) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_hotspots(delta_time, resumed) - cost_hotspots = MC_AVERAGE(cost_hotspots, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_hotspots = MC_AVERAGE(cost_hotspots, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_SUPERCONDUCTIVITY if(currentpart == SSAIR_SUPERCONDUCTIVITY) timer = TICK_USAGE_REAL + if(!resumed) + cached_cost = 0 process_super_conductivity(resumed) - cost_superconductivity = MC_AVERAGE(cost_superconductivity, TICK_DELTA_TO_MS(TICK_USAGE_REAL - timer)) + cached_cost += TICK_USAGE_REAL - timer if(state != SS_RUNNING) return + cost_superconductivity = MC_AVERAGE(cost_superconductivity, TICK_DELTA_TO_MS(cached_cost)) resumed = FALSE currentpart = SSAIR_REBUILD_PIPENETS