From d596fd831e86f0f04eee79b535ff3d37a40fa652 Mon Sep 17 00:00:00 2001 From: Matt Atlas Date: Sat, 5 Feb 2022 06:07:06 +0100 Subject: [PATCH] Fixes subsystem issues and other timer bugfixes (#13061) * Debug code to figure out why timer fire isn't yielding * please man * thing 2 * BALLS * BALLS 2 * correction * remove debug shitcode Co-authored-by: Matt Atlas --- code/__defines/subsystem-priority.dm | 3 ++- code/controllers/subsystems/arrivals.dm | 2 +- code/controllers/subsystems/evac.dm | 2 +- code/controllers/subsystems/timer.dm | 11 +++++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/code/__defines/subsystem-priority.dm b/code/__defines/subsystem-priority.dm index 8b0afbc33f0..2e7ae1fd12d 100644 --- a/code/__defines/subsystem-priority.dm +++ b/code/__defines/subsystem-priority.dm @@ -65,12 +65,13 @@ #define SS_PRIORITY_AIRFLOW 10 // Handles object movement due to ZAS airflow. #define SS_PRIORITY_PING 10 #define SS_PRIORITY_ZCOPY 10 // Z-mimic icon generation/updates. +#define SS_PRIORITY_ARRIVALS 10 // Centcomm arrivals shuttle auto-launch. Usually asleep. + // SS_BACKGROUND #define SS_PRIORITY_PROCESSING 50 // Generic datum processor. Replaces objects processor. //#define SS_PRIORITY_DEFAULT 50 // This is defined somewhere else. #define SS_PRIORITY_PSYCHICS 30 -#define SS_PRIORITY_ARRIVALS 30 // Centcomm arrivals shuttle auto-launch. Usually asleep. #define SS_PRIORITY_EVAC 30 // Processes the evac controller. #define SS_PRIORITY_EXPLOSIVES 20 // Explosion processor. Doesn't have much effect on explosion tick-checking. #define SS_PRIORITY_DISPOSALS 20 // Disposal holder movement. diff --git a/code/controllers/subsystems/arrivals.dm b/code/controllers/subsystems/arrivals.dm index 67dae98b024..692f8c575fc 100644 --- a/code/controllers/subsystems/arrivals.dm +++ b/code/controllers/subsystems/arrivals.dm @@ -2,7 +2,7 @@ /datum/controller/subsystem/arrivals name = "Arrivals" - flags = SS_NO_INIT | SS_BACKGROUND | SS_NO_TICK_CHECK + flags = SS_NO_INIT | SS_BACKGROUND priority = SS_PRIORITY_ARRIVALS var/datum/shuttle/autodock/ferry/arrival/shuttle diff --git a/code/controllers/subsystems/evac.dm b/code/controllers/subsystems/evac.dm index a23938e0ec0..94b578c2b66 100644 --- a/code/controllers/subsystems/evac.dm +++ b/code/controllers/subsystems/evac.dm @@ -4,7 +4,7 @@ var/datum/controller/subsystem/evac/SSevac name = "Evacuation" priority = SS_PRIORITY_EVAC //Initializes at default time - flags = SS_NO_TICK_CHECK|SS_BACKGROUND + flags = SS_BACKGROUND wait = 2 SECONDS /datum/controller/subsystem/evac/Initialize() diff --git a/code/controllers/subsystems/timer.dm b/code/controllers/subsystems/timer.dm index ea406f2add5..f7bee31e003 100644 --- a/code/controllers/subsystems/timer.dm +++ b/code/controllers/subsystems/timer.dm @@ -3,7 +3,7 @@ /// Helper for getting the correct bucket for a given timer #define BUCKET_POS(timer) (((round((timer.timeToRun - SStimer.head_offset) / world.tick_lag)+1) % BUCKET_LEN)||BUCKET_LEN) /// Gets the maximum time at which timers will be invoked from buckets, used for deferring to secondary queue -#define TIMER_MAX (world.time + TICKS2DS(min(BUCKET_LEN-(SStimer.practical_offset-DS2TICKS(world.time - SStimer.head_offset))-1, BUCKET_LEN-1))) +#define TIMER_MAX (SStimer.head_offset + TICKS2DS(BUCKET_LEN + SStimer.practical_offset - 1)) /// Max float with integer precision #define TIMER_ID_MAX (2**24) @@ -261,6 +261,12 @@ var/datum/controller/subsystem/timer/SStimer // Add all timed events from the secondary queue as well alltimers += second_queue + for (var/datum/timedevent/t as anything in alltimers) + t.bucket_joined = FALSE + t.bucket_pos = -1 + t.prev = null + t.next = null + // If there are no timers being tracked by the subsystem, // there is no need to do any further rebuilding if (!length(alltimers)) @@ -304,6 +310,7 @@ var/datum/controller/subsystem/timer/SStimer new_bucket_count++ var/bucket_pos = BUCKET_POS(timer) timer.bucket_pos = bucket_pos + timer.bucket_joined = TRUE var/datum/timedevent/bucket_head = bucket_list[bucket_pos] if (!bucket_head) @@ -452,7 +459,7 @@ var/datum/controller/subsystem/timer/SStimer if(buckethead == src) bucket_list[bucket_pos] = next SStimer.bucket_count-- - else if(timeToRun < TIMER_MAX) + else if(bucket_joined) SStimer.bucket_count-- else var/l = length(second_queue)