From f9bb52e8668f1933ff1ae5ac10d5627412bc88d4 Mon Sep 17 00:00:00 2001 From: spookydonut Date: Fri, 1 Jan 2021 05:20:08 +0800 Subject: [PATCH] Add TIMER_DELETE_ME (#55803) --- code/__DEFINES/subsystems.dm | 3 +++ code/controllers/subsystem/timer.dm | 14 +++++++------- code/datums/datum.dm | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm index 66d998171e8..fe7dd733b17 100644 --- a/code/__DEFINES/subsystems.dm +++ b/code/__DEFINES/subsystems.dm @@ -57,6 +57,9 @@ ///In most cases you want a subsystem instead, so don't use this unless you have a good reason #define TIMER_LOOP (1<<5) +///Delete the timer on parent datum Destroy() and when deltimer'd +#define TIMER_DELETE_ME (1<<6) + ///Empty ID define #define TIMER_ID_NULL -1 diff --git a/code/controllers/subsystem/timer.dm b/code/controllers/subsystem/timer.dm index de5c4023980..7ed80991b13 100644 --- a/code/controllers/subsystem/timer.dm +++ b/code/controllers/subsystem/timer.dm @@ -159,25 +159,25 @@ SUBSYSTEM_DEF(timer) bucket_resolution = null // force bucket recreation CRASH("Invalid timer: [get_timer_debug_string(timer)] world.time: [world.time], \ head_offset: [head_offset], practical_offset: [practical_offset]") - + timer.bucketEject() //pop the timer off of the bucket list. - + // Invoke callback if possible if (!timer.spent) timer.spent = world.time callBack.InvokeAsync() last_invoke_tick = world.time - + if (timer.flags & TIMER_LOOP) // Prepare looping timers to re-enter the queue timer.spent = 0 timer.timeToRun = world.time + timer.wait timer.bucketJoin() else qdel(timer) - + if (MC_TICK_CHECK) break - + if (!bucket_list[practical_offset]) // Empty the bucket, check if anything in the secondary queue should be shifted to this bucket bucket_list[practical_offset++] = null @@ -472,7 +472,7 @@ SUBSYSTEM_DEF(timer) name = "Timer: [id] (\ref[src]), TTR: [timeToRun], wait:[wait] Flags: [jointext(bitfield2list(flags, bitfield_flags), ", ")], \ callBack: \ref[callBack], callBack.object: [callBack.object]\ref[callBack.object]([getcallingtype()]), \ callBack.delegate:[callBack.delegate]([callBack.arguments ? callBack.arguments.Join(", ") : ""]), source: [source]" - + // Check if this timed event should be diverted to the client time bucket, or the secondary queue var/list/L if (flags & TIMER_CLIENT_TIME) @@ -584,7 +584,7 @@ SUBSYSTEM_DEF(timer) return TRUE //id is string var/datum/timedevent/timer = SStimer.timer_id_dict[id] - if (timer && !timer.spent) + if (timer && (!timer.spent || timer.flags & TIMER_DELETE_ME)) qdel(timer) return TRUE return FALSE diff --git a/code/datums/datum.dm b/code/datums/datum.dm index 6447f5cb96d..62a6d6201ba 100644 --- a/code/datums/datum.dm +++ b/code/datums/datum.dm @@ -101,7 +101,7 @@ active_timers = null for(var/thing in timers) var/datum/timedevent/timer = thing - if (timer.spent) + if (timer.spent && !(timer.flags & TIMER_DELETE_ME)) continue qdel(timer)