From 19e1785eedb0bd217cde18ee4840960a88603598 Mon Sep 17 00:00:00 2001 From: Contrabang <91113370+Contrabang@users.noreply.github.com> Date: Thu, 4 Sep 2025 03:09:08 -0400 Subject: [PATCH] Adds a macro for 0 wait timers as END_OF_TICK (#30309) * Adds a macro for 0 wait timers as END_OF_TICK * comment update --- code/__DEFINES/callbacks.dm | 3 +++ code/datums/components/shelved.dm | 2 +- code/game/objects/structures/crates_lockers/closets.dm | 2 +- code/game/objects/structures/safe.dm | 2 +- code/modules/library/book.dm | 2 +- code/modules/library/library_computer.dm | 2 +- code/modules/library/library_equipment.dm | 4 ++-- code/modules/mining/lavaland/necropolis_chests.dm | 2 +- .../living/simple_animal/hostile/megafauna/ancient_robot.dm | 2 +- code/modules/recycling/disposal.dm | 4 ++-- code/modules/surgery/organs/subtypes/standard_organs.dm | 2 +- 11 files changed, 15 insertions(+), 12 deletions(-) diff --git a/code/__DEFINES/callbacks.dm b/code/__DEFINES/callbacks.dm index 8b828a6d017..bd76f826f36 100644 --- a/code/__DEFINES/callbacks.dm +++ b/code/__DEFINES/callbacks.dm @@ -5,3 +5,6 @@ /// like CALLBACK but specifically for verb callbacks #define VERB_CALLBACK new /datum/callback/verb_callback + +// This is used to delay a callback until the end of the tick or later, to ensure that some arbitrary specification is met first. (i.e. spawners spawning stuff) +#define END_OF_TICK(callback) addtimer(callback, 0) diff --git a/code/datums/components/shelved.dm b/code/datums/components/shelved.dm index dec7252efe9..0e7a1322d19 100644 --- a/code/datums/components/shelved.dm +++ b/code/datums/components/shelved.dm @@ -50,7 +50,7 @@ // See /obj/structure/closet/Initialize for explanation of // addtimer use here - addtimer(CALLBACK(src, PROC_REF(shelf_items)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(shelf_items))) /datum/component/shelver/proc/shelf_items() var/obj/structure/structure_parent = parent diff --git a/code/game/objects/structures/crates_lockers/closets.dm b/code/game/objects/structures/crates_lockers/closets.dm index ce70b199c2d..4ed92e38e14 100644 --- a/code/game/objects/structures/crates_lockers/closets.dm +++ b/code/game/objects/structures/crates_lockers/closets.dm @@ -60,7 +60,7 @@ // This includes maint loot spawners. The problem with that is if a closet loads before a spawner, // the loot will just be in a pile. Adding a timer with 0 delay will cause it to only take in contents once the MC has loaded, // therefore solving the issue on mapload. During rounds, everything will happen as normal - addtimer(CALLBACK(src, PROC_REF(take_contents)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(take_contents))) populate_contents() // Spawn all its stuff update_icon() // Set it to the right icon if needed diff --git a/code/game/objects/structures/safe.dm b/code/game/objects/structures/safe.dm index 106181499c5..430584fb87d 100644 --- a/code/game/objects/structures/safe.dm +++ b/code/game/objects/structures/safe.dm @@ -71,7 +71,7 @@ GLOBAL_LIST_EMPTY(safes) for(var/i in 1 to number_of_tumblers) tumblers.Add(rand(0, 99)) if(mapload) - addtimer(CALLBACK(src, PROC_REF(take_contents)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(take_contents))) /obj/structure/safe/proc/take_contents() // Put as many items on our turf inside as possible diff --git a/code/modules/library/book.dm b/code/modules/library/book.dm index 45cafe512b3..2da6e1b96a3 100644 --- a/code/modules/library/book.dm +++ b/code/modules/library/book.dm @@ -374,7 +374,7 @@ /obj/item/book/random/Initialize(mapload) . = ..() - addtimer(CALLBACK(src, PROC_REF(spawn_books)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(spawn_books))) /obj/item/book/random/proc/spawn_books() var/list/books = GLOB.library_catalog.get_random_book(amount) diff --git a/code/modules/library/library_computer.dm b/code/modules/library/library_computer.dm index 42390b60041..35301f08849 100644 --- a/code/modules/library/library_computer.dm +++ b/code/modules/library/library_computer.dm @@ -49,7 +49,7 @@ /obj/machinery/computer/library/Initialize(mapload) . = ..() - addtimer(CALLBACK(src, PROC_REF(populate_booklist)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(populate_booklist))) /obj/machinery/computer/library/attack_ai(mob/user) return attack_hand(user) diff --git a/code/modules/library/library_equipment.dm b/code/modules/library/library_equipment.dm index 8f4f44c14d4..7074f2f0ff0 100644 --- a/code/modules/library/library_equipment.dm +++ b/code/modules/library/library_equipment.dm @@ -24,7 +24,7 @@ . = ..() if(mapload) // same reasoning as closets - addtimer(CALLBACK(src, PROC_REF(take_contents)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(take_contents))) /obj/structure/bookcase/proc/take_contents() for(var/obj/item/I in get_turf(src)) @@ -151,7 +151,7 @@ /obj/structure/bookcase/random/Initialize(mapload) . = ..() - addtimer(CALLBACK(src, PROC_REF(load_books)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(load_books))) icon_state = "bookshelf" // to keep random_bookshelf icon for mappers /obj/structure/bookcase/random/proc/load_books() diff --git a/code/modules/mining/lavaland/necropolis_chests.dm b/code/modules/mining/lavaland/necropolis_chests.dm index d3a3131f7b4..c2096ee731a 100644 --- a/code/modules/mining/lavaland/necropolis_chests.dm +++ b/code/modules/mining/lavaland/necropolis_chests.dm @@ -377,7 +377,7 @@ ..() if(!activated || QDELETED(src)) return - addtimer(CALLBACK(src, PROC_REF(try_attach_to_owner)), 0) // Do this once the drop call stack is done. The holding limb might be getting removed + END_OF_TICK(CALLBACK(src, PROC_REF(try_attach_to_owner))) // Do this once the drop call stack is done. The holding limb might be getting removed /obj/item/rod_of_asclepius/proc/try_attach_to_owner() if(!ishuman(owner) || QDELETED(owner)) diff --git a/code/modules/mob/living/simple_animal/hostile/megafauna/ancient_robot.dm b/code/modules/mob/living/simple_animal/hostile/megafauna/ancient_robot.dm index c92ec5af951..b7054b31e77 100644 --- a/code/modules/mob/living/simple_animal/hostile/megafauna/ancient_robot.dm +++ b/code/modules/mob/living/simple_animal/hostile/megafauna/ancient_robot.dm @@ -263,7 +263,7 @@ Difficulty: Hard . = ..() var/newcolor = rgb(241, 137, 172) add_atom_colour(newcolor, TEMPORARY_COLOUR_PRIORITY) - addtimer(CALLBACK(src, PROC_REF(beam_it_up)), 0) + END_OF_TICK(CALLBACK(src, PROC_REF(beam_it_up))) /obj/effect/vetus_laser/ex_act(severity) return diff --git a/code/modules/recycling/disposal.dm b/code/modules/recycling/disposal.dm index d28f83a6de5..4e35c1efc60 100644 --- a/code/modules/recycling/disposal.dm +++ b/code/modules/recycling/disposal.dm @@ -1374,7 +1374,7 @@ /obj/structure/disposalpipe/trunk/Initialize(mapload) . = ..() dpdir = dir - addtimer(CALLBACK(src, PROC_REF(getlinked)), 0) // This has a delay of 0, but wont actually start until the MC is done + END_OF_TICK(CALLBACK(src, PROC_REF(getlinked))) update() return @@ -1515,7 +1515,7 @@ /obj/structure/disposaloutlet/Initialize(mapload) . = ..() - addtimer(CALLBACK(src, PROC_REF(setup)), 0) // Wait of 0, but this wont actually do anything until the MC is firing + END_OF_TICK(CALLBACK(src, PROC_REF(setup))) /obj/structure/disposaloutlet/proc/setup() target = get_ranged_target_turf(src, dir, 10) diff --git a/code/modules/surgery/organs/subtypes/standard_organs.dm b/code/modules/surgery/organs/subtypes/standard_organs.dm index 11db3702ea0..8fe159014eb 100644 --- a/code/modules/surgery/organs/subtypes/standard_organs.dm +++ b/code/modules/surgery/organs/subtypes/standard_organs.dm @@ -210,7 +210,7 @@ // we need to come back to this once the hand is actually removed/dead if(!owner) // Rather not have this trigger on already removed limbs return - addtimer(CALLBACK(owner, TYPE_PROC_REF(/mob/living/carbon/human, update_hands_hud), 0)) + END_OF_TICK(CALLBACK(owner, TYPE_PROC_REF(/mob/living/carbon/human, update_hands_hud))) /obj/item/organ/external/hand/right limb_name = "r_hand"