From 55c4ad2c135388e78f8d2f0c301489246a1e71ca Mon Sep 17 00:00:00 2001 From: Heroman3003 <31296024+Heroman3003@users.noreply.github.com> Date: Tue, 7 Feb 2023 04:07:38 +1000 Subject: [PATCH 1/2] Merge pull request #14451 from VOREStation/upstream-merge-8925 [MIRROR] Ported LemonInTheDark's scheduler offset optimization. --- code/controllers/master.dm | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/code/controllers/master.dm b/code/controllers/master.dm index fc065bc86a..83c4f6ed3e 100644 --- a/code/controllers/master.dm +++ b/code/controllers/master.dm @@ -260,7 +260,7 @@ GLOBAL_REAL(Master, /datum/controller/master) = new SS.state = SS_IDLE if (SS.flags & SS_TICKER) tickersubsystems += SS - timer += world.tick_lag * rand(1, 5) + timer += world.tick_lag * rand(0,1) SS.next_fire = timer continue @@ -335,13 +335,16 @@ GLOBAL_REAL(Master, /datum/controller/master) = new var/checking_runlevel = current_runlevel if(cached_runlevel != checking_runlevel) //resechedule subsystems + var/list/old_subsystems = current_runlevel_subsystems cached_runlevel = checking_runlevel current_runlevel_subsystems = runlevel_sorted_subsystems[cached_runlevel] - var/stagger = world.time + + //now we'll go through all the subsystems we want to offset and give them a next_fire for(var/datum/controller/subsystem/SS as anything in current_runlevel_subsystems) - if(SS.next_fire <= world.time) - stagger += world.tick_lag * rand(1, 5) - SS.next_fire = stagger + //we only want to offset it if it's new and also behind + if(SS.next_fire > world.time || (SS in old_subsystems)) + continue + SS.next_fire = world.time + world.tick_lag * rand(0, DS2TICKS(min(SS.wait, 2 SECONDS))) subsystems_to_check = current_runlevel_subsystems else