Files
silicons fb432cd41a airlocks 2.0 (#6593)
Co-authored-by: silicons <silicons@silicons.dev>
2026-02-24 09:41:01 +01:00

67 lines
3.2 KiB
Plaintext

/**
* Base of processing subsystems.
* This is a generic processing subsystem that ticks once per second.
*/
SUBSYSTEM_DEF(processing)
name = "Processing - 1 fps"
priority = FIRE_PRIORITY_PROCESS
subsystem_flags = SS_BACKGROUND|SS_POST_FIRE_TIMING|SS_NO_INIT
wait = 1 SECONDS
var/stat_tag = "P_DEF" //Used for logging
var/list/processing = list()
var/list/currentrun = list()
/datum/controller/subsystem/processing/stat_entry()
return ..() + " [stat_tag]:[length(processing)]"
/datum/controller/subsystem/processing/fire(resumed = FALSE)
if (!resumed)
currentrun = processing.Copy()
//cache for sanic speed (lists are references anyways)
var/list/current_run = currentrun
// tick_lag is in deciseconds
// in ticker, our wait is that many ds
// in non-ticker, our wait is either wait in ds, or a minimum of tick_lag in ds
// we convert it to seconds with * 0.1
var/dt = (subsystem_flags & SS_TICKER? (wait * world.tick_lag) : max(world.tick_lag, wait)) * 0.1
while(current_run.len)
var/datum/thing = current_run[current_run.len]
current_run.len--
if(QDELETED(thing))
log_world("GC-TRACE: Deleted entity found in [src] - [thing ? thing.type : "-- null value --"]")
if(thing)
var/list/trace = thing.gc_trace_data()
trace["type"] = thing.type
trace["refcount"] = refcount(thing)
log_world("GC-TRACE: From [src], [thing.type] had trace: [json_encode(trace)]")
stack_trace("deleted entity found in [src]; check logs.")
processing -= thing
else if(thing.process(dt) == PROCESS_KILL)
// fully stop so that a future START_PROCESSING will work
STOP_PROCESSING(src, thing)
if (MC_TICK_CHECK)
return
/**
* 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 delta_time that is sent as a parameter,
* Additionally, any "prob" you use in this proc should instead use the DT_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 -= delta_time`, not `mytimer -= 1`. This way, `mytimer` will always have the unit of seconds
* - Damaging a mob, do `L.adjustFireLoss(20 * delta_time)`, 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(DT_PROB(25, delta_time))`, 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
*
* @params
* * delta_time - time that should have elapsed, in seconds
*/
/datum/proc/process(delta_time)
set waitfor = FALSE
return PROCESS_KILL