From 8302f1efb76a8b6e91525de4910534d6b741fbd1 Mon Sep 17 00:00:00 2001 From: "ZEUS\\samcr" Date: Sun, 25 Oct 2020 13:41:10 -0400 Subject: [PATCH] Light flickers now process asynchronously again --- code/modules/power/lighting.dm | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/code/modules/power/lighting.dm b/code/modules/power/lighting.dm index 561b0e88c07..2fcba4656a7 100644 --- a/code/modules/power/lighting.dm +++ b/code/modules/power/lighting.dm @@ -522,17 +522,27 @@ /obj/machinery/light/proc/flicker(amount = rand(10, 20)) if(flickering) return - if(on) - flickering = TRUE - for(var/i in 1 to amount) - if(status != LIGHT_OK) - break - on = !on - update() // No param means that ghosts can burn out lights - sleep(rand(5, 15)) - if(status == LIGHT_OK) - on = TRUE - update(FALSE) + + if(!on) + return + + flickering = TRUE + INVOKE_ASYNC(src, /obj/machinery/light/.proc/flicker_event, amount) + +/** + * Flicker routine for the light. + * Called by invoke_async so the parent proc can return immediately. + */ +/obj/machinery/light/proc/flicker_event(amount) + for(var/i in 1 to amount) + if(status != LIGHT_OK) + break + on = !on + update() // No param means that ghosts can burn out lights + sleep(rand(5, 15)) + if(status == LIGHT_OK) + on = TRUE + update(FALSE) flickering = FALSE // ai attack - make lights flicker, because why not