Processing subsystems improvements (#18961)

Refactored the use of the isprocessing var into the datum flag
DF_ISPROCESSING.
Updated SSprocessing and SSmachinery to have a constant fire rate.
Updated gas cooler to be time-constant thanks to the above.
This commit is contained in:
Fluffy
2024-04-20 20:16:08 +02:00
committed by GitHub
parent edd0376490
commit 1f759338d8
15 changed files with 130 additions and 77 deletions
@@ -1,8 +1,10 @@
//Used to process objects. Fires once every two seconds.
SUBSYSTEM_DEF(processing)
name = "Processing"
priority = SS_PRIORITY_PROCESSING
priority = FIRE_PRIORITY_PROCESS
flags = SS_BACKGROUND|SS_POST_FIRE_TIMING|SS_NO_INIT
wait = 1 SECONDS
var/stat_tag = "P" //Used for logging
var/list/processing = list()
@@ -21,17 +23,31 @@ SUBSYSTEM_DEF(processing)
while(current_run.len)
var/datum/thing = current_run[current_run.len]
current_run.len--
if(!QDELETED(thing))
if (thing.process(wait, times_fired) == PROCESS_KILL)
stop_processing(thing)
else
if(QDELETED(thing))
processing -= thing
else if(thing.process(wait * 0.1) == PROCESS_KILL)
// fully stop so that a future START_PROCESSING will work
STOP_PROCESSING(src, thing)
if (MC_TICK_CHECK)
return
// Helper so PROCESS_KILL works.
/datum/controller/subsystem/processing/proc/stop_processing(datum/D)
STOP_PROCESSING(src, D)
/**
* This proc is called on a datum on every "cycle" if it is being processed by a subsystem. The time between each cycle is determined by the subsystem's "wait" setting.
* You can start and stop processing a datum using the START_PROCESSING and STOP_PROCESSING defines.
*
* Since the wait setting of a subsystem can be changed at any time, it is important that any rate-of-change that you implement in this proc is multiplied by the seconds_per_tick that is sent as a parameter,
* Additionally, any "prob" you use in this proc should instead use the SPT_PROB define to make sure that the final probability per second stays the same even if the subsystem's wait is altered.
* Examples where this must be considered:
* - Implementing a cooldown timer, use `mytimer -= seconds_per_tick`, not `mytimer -= 1`. This way, `mytimer` will always have the unit of seconds
* - Damaging a mob, do `L.adjustFireLoss(20 * seconds_per_tick)`, not `L.adjustFireLoss(20)`. This way, the damage per second stays constant even if the wait of the subsystem is changed
* - Probability of something happening, do `if(SPT_PROB(25, seconds_per_tick))`, not `if(prob(25))`. This way, if the subsystem wait is e.g. lowered, there won't be a higher chance of this event happening per second
*
* If you override this do not call parent, as it will return PROCESS_KILL. This is done to prevent objects that dont override process() from staying in the processing list
*/
/datum/proc/process(seconds_per_tick)
set waitfor = FALSE
return PROCESS_KILL
/datum/controller/subsystem/processing/ExplosionStart()
can_fire = FALSE