From e057269e9bbdcdc48792bf85678188d2bffd461a Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Thu, 22 Oct 2020 04:35:27 +0200 Subject: [PATCH] [MIRROR] [Performance] Makes bot salute not do thousands of hearers_in_view calls (#1413) * [Performance] Makes bot salute not do thousands of hearers_in_view calls (#54498) It now uses view() instead, and is cooldowned per each check, instead of per each successful salute EDIT: I've changed so the commmissioned bots invoke salutes for even more performance, as AnturK suggested. * [Performance] Makes bot salute not do thousands of hearers_in_view calls Co-authored-by: Azarak --- code/modules/mob/living/simple_animal/bot/bot.dm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/code/modules/mob/living/simple_animal/bot/bot.dm b/code/modules/mob/living/simple_animal/bot/bot.dm index 880d4b6e946..f9e6ee9e576 100644 --- a/code/modules/mob/living/simple_animal/bot/bot.dm +++ b/code/modules/mob/living/simple_animal/bot/bot.dm @@ -94,7 +94,7 @@ var/robot_arm = /obj/item/bodypart/r_arm/robot var/commissioned = FALSE // Will other (noncommissioned) bots salute this bot? - var/can_salute = TRUE + COOLDOWN_DECLARE(next_salute_check) var/salute_delay = 60 SECONDS hud_possible = list(DIAG_STAT_HUD, DIAG_BOT_HUD, DIAG_HUD, DIAG_PATH_HUD = HUD_LIST_LIST) //Diagnostic HUD views @@ -273,12 +273,11 @@ if(!on || client) return - if(!commissioned && can_salute) - for(var/mob/living/simple_animal/bot/B in get_hearers_in_view(5, get_turf(src))) - if(B.commissioned) - visible_message("[src] performs an elaborate salute for [B]!") - can_salute = FALSE - addtimer(VARSET_CALLBACK(src, can_salute, TRUE), salute_delay) + if(commissioned && COOLDOWN_FINISHED(src, next_salute_check)) + COOLDOWN_START(src, next_salute_check, salute_delay) + for(var/mob/living/simple_animal/bot/B in view(5, src)) + if(!B.commissioned && B.on) + visible_message("[B] performs an elaborate salute for [src]!") break switch(mode) //High-priority overrides are processed first. Bots can do nothing else while under direct command.