From a8c489baf8c7b34ee5f98ca1f7f693e39cabc55c Mon Sep 17 00:00:00 2001 From: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Date: Fri, 24 Nov 2023 08:18:31 -0500 Subject: [PATCH] https://github.com/tgstation/tgstation/pull/64448 (#10208) --- code/controllers/subsystem.dm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/code/controllers/subsystem.dm b/code/controllers/subsystem.dm index 66ed735a7188e..e8b0f98ec3995 100644 --- a/code/controllers/subsystem.dm +++ b/code/controllers/subsystem.dm @@ -20,8 +20,16 @@ var/next_fire = 0 //scheduled world.time for next fire() var/cost = 0 //average time to execute var/tick_usage = 0 //average tick usage - var/tick_overrun = 0 //average tick overrun - var/state = SS_IDLE //tracks the current state of the ss, running, paused, etc. + /// Running average of the amount of tick usage (in percents of a game tick) the subsystem has spent past its allocated time without pausing + var/tick_overrun = 0 + + /// How much of a tick (in percents of a tick) were we allocated last fire. + var/tick_allocation_last = 0 + + /// How much of a tick (in percents of a tick) do we get allocated by the mc on avg. + var/tick_allocation_avg = 0 + /// Tracks the current execution state of the subsystem. Used to handle subsystems that sleep in fire so the mc doesn't run them again while they are sleeping + var/state = SS_IDLE var/paused_ticks = 0 //ticks this ss is taking to run right now. var/paused_tick_usage //total tick_usage of all of our runs while pausing this run var/ticks = 1 //how many ticks does this ss take to run on avg. @@ -46,8 +54,14 @@ return //This is used so the mc knows when the subsystem sleeps. do not override. -/datum/controller/subsystem/proc/ignite(resumed = 0) - set waitfor = 0 +/datum/controller/subsystem/proc/ignite(resumed = FALSE) + SHOULD_NOT_OVERRIDE(TRUE) + set waitfor = FALSE + . = SS_IDLE + + tick_allocation_last = Master.current_ticklimit-(TICK_USAGE) + tick_allocation_avg = MC_AVERAGE(tick_allocation_avg, tick_allocation_last) + . = SS_SLEEPING fire(resumed) . = state