mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2025-12-10 17:52:36 +00:00
* large refactor of machine/power code to cut down on processing time and wasted lists (#60317) original pr here: #59789 (Closed because he didn't think it was good enough) came back to this because i realized that all machines were area sensitive, meaning they had a list with at least a reference to themselves (assuming they arent in the contents of another movable which most arent) for the purposes of handling power differences when their area changes pipes are machines there are ~14k machines and ~6k pipes i made this problem worse with a recent pr by making it a nested list so i needed to track what machines needed power, and this pr had work already done that could be used for that purpose. now machines that have use_power == NO_POWER_USE do not have this extra memory overhead for no reason currently every machine that uses power draws that amount from its area from a dynamic channel via auto_use_power() which is called every SSmachines fire(), then in apc/process() the area's dynamic power draw is reset and the power is used. with static power its not calculated then reset every loop, its just taken from the grid. so now machines handle updating their static power usage from their current area (this doesnt touch power machines that require a wire connection). in order to allow this, use_power, idle_power_usage, and active_power_usage have setters to track state correctly and update the static power usage on the machines current area and handle area sensitivity. also goes through a lot of heavy abusers of SSmachine processing time and tries to make it faster. makes airalarm/process() into a signal handler for COMSIG_TURF_EXPOSE since air alarms only need to process for changes. Why It's Good For The Game SSmachines isnt the heaviest hitter in terms of total cpu and certainly not in terms of overtime, but its not a lightweight. it frequently takes > 50ms to complete a run and seems to be in the top 5 or so of subsystem costs looking at some round profilers also gets rid of a few thousand lists since every pipe no longer has two useless lists each (and any other machines that dont use power) Love ya kyler Co-authored-by: Rohesie <rohesie@ gmail.com> * large refactor of machine/power code to cut down on processing time and wasted lists Co-authored-by: Kylerace <kylerlumpkin1@gmail.com> Co-authored-by: Rohesie <rohesie@ gmail.com>
62 lines
1.8 KiB
Plaintext
62 lines
1.8 KiB
Plaintext
SUBSYSTEM_DEF(machines)
|
|
name = "Machines"
|
|
init_order = INIT_ORDER_MACHINES
|
|
flags = SS_KEEP_TIMING
|
|
wait = 2 SECONDS
|
|
var/list/processing = list()
|
|
var/list/currentrun = list()
|
|
var/list/powernets = list()
|
|
|
|
/datum/controller/subsystem/machines/Initialize()
|
|
makepowernets()
|
|
fire()
|
|
return ..()
|
|
|
|
/datum/controller/subsystem/machines/proc/makepowernets()
|
|
for(var/datum/powernet/power_network as anything in powernets)
|
|
qdel(power_network)
|
|
powernets.Cut()
|
|
|
|
for(var/obj/structure/cable/power_cable as anything in GLOB.cable_list)
|
|
if(!power_cable.powernet)
|
|
var/datum/powernet/new_powernet = new()
|
|
new_powernet.add_cable(power_cable)
|
|
propagate_network(power_cable, power_cable.powernet)
|
|
|
|
/datum/controller/subsystem/machines/stat_entry(msg)
|
|
msg = "M:[length(processing)]|PN:[length(powernets)]"
|
|
return ..()
|
|
|
|
/datum/controller/subsystem/machines/fire(resumed = FALSE)
|
|
if (!resumed)
|
|
for(var/datum/powernet/powernet as anything in powernets)
|
|
powernet.reset() //reset the power state.
|
|
src.currentrun = processing.Copy()
|
|
|
|
//cache for sanic speed (lists are references anyways)
|
|
var/list/currentrun = src.currentrun
|
|
|
|
while(currentrun.len)
|
|
var/obj/machinery/thing = currentrun[currentrun.len]
|
|
currentrun.len--
|
|
if(QDELETED(thing) || thing.process(wait * 0.1) == PROCESS_KILL)
|
|
processing -= thing
|
|
thing.datum_flags &= ~DF_ISPROCESSING
|
|
if (MC_TICK_CHECK)
|
|
return
|
|
|
|
/datum/controller/subsystem/machines/proc/setup_template_powernets(list/cables)
|
|
var/obj/structure/cable/PC
|
|
for(var/A in 1 to cables.len)
|
|
PC = cables[A]
|
|
if(!PC.powernet)
|
|
var/datum/powernet/NewPN = new()
|
|
NewPN.add_cable(PC)
|
|
propagate_network(PC,PC.powernet)
|
|
|
|
/datum/controller/subsystem/machines/Recover()
|
|
if (istype(SSmachines.processing))
|
|
processing = SSmachines.processing
|
|
if (istype(SSmachines.powernets))
|
|
powernets = SSmachines.powernets
|