From 8cf4a74b415e4280ccfce05962e3e41c81867c6d Mon Sep 17 00:00:00 2001 From: Mykhailo Bykhovtsev Date: Sat, 24 Oct 2020 14:27:10 -0700 Subject: [PATCH] Optimizing recursive_content_check and get_mobs_or_objects_in_view (#10282) --- code/_helpers/game.dm | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/code/_helpers/game.dm b/code/_helpers/game.dm index 904a07a876b..ad1a2a95ef1 100644 --- a/code/_helpers/game.dm +++ b/code/_helpers/game.dm @@ -128,32 +128,31 @@ // Will recursively loop through an atom's contents and check for mobs, then it will loop through every atom in that atom's contents. // It will keep doing this until it checks every content possible. This will fix any problems with mobs, that are inside objects, // being unable to hear people due to being in a box within a bag. +// Does not return list, as list is passed as reference. /proc/recursive_content_check(var/atom/O, var/list/L = list(), var/recursion_limit = 3, var/client_check = 1, var/sight_check = 1, var/include_mobs = 1, var/include_objects = 1) if(!recursion_limit) - return L + return for(var/I in O.contents) if(ismob(I)) if(!sight_check || isInSight(I, O)) - L |= recursive_content_check(I, L, recursion_limit - 1, client_check, sight_check, include_mobs, include_objects) + recursive_content_check(I, L, recursion_limit - 1, client_check, sight_check, include_mobs, include_objects) if(include_mobs) if(client_check) var/mob/M = I if(M.client) - L |= M + L += M else - L |= I + L += I - else if(istype(I,/obj/)) + else if(isobj(I)) if(!sight_check || isInSight(I, O)) - L |= recursive_content_check(I, L, recursion_limit - 1, client_check, sight_check, include_mobs, include_objects) + recursive_content_check(I, L, recursion_limit - 1, client_check, sight_check, include_mobs, include_objects) if(include_objects) - L |= I - - return L + L += I // Returns a list of mobs and/or objects in range of R from source. Used in radio and say code. @@ -169,13 +168,13 @@ for(var/I in range) if(ismob(I)) - hear |= recursive_content_check(I, hear, 3, 1, 0, include_mobs, include_objects) + recursive_content_check(I, hear, 3, 1, 0, include_mobs, include_objects) if(include_mobs) var/mob/M = I if(M.client) hear += M - else if(istype(I,/obj/)) - hear |= recursive_content_check(I, hear, 3, 1, 0, include_mobs, include_objects) + else if(istype(I, /obj/)) + recursive_content_check(I, hear, 3, 1, 0, include_mobs, include_objects) if(include_objects) hear += I