Merge pull request #3622 from Citadel-Station-13/upstream-merge-32029

[MIRROR] Actual performance improvements for GetAllContents
This commit is contained in:
LetterJay
2017-10-27 02:43:16 -04:00
committed by GitHub
+12 -14
View File
@@ -504,21 +504,19 @@ Turf and target are separate in case you want to teleport some distance from a t
return y
/*
Recursively gets all contents of contents and returns them all in a list.
recursive_depth is useful if you only want a turf and everything on it (recursive_depth=1)
Do not set recursive depth higher than MAX_PROC_DEPTH as byond breaks when that limit is reached.
Gets all contents of contents and returns them all in a list.
*/
/atom/proc/GetAllContents(list/output=list(), recursive_depth=MAX_PROC_DEPTH, _current_depth=0)
. = output
output += src
if(_current_depth == recursive_depth)
if(_current_depth == MAX_PROC_DEPTH)
WARNING("Get all contents reached the max recursive depth of [MAX_PROC_DEPTH]. More and we would break shit. Offending atom: [src]")
return
for(var/i in 1 to contents.len)
var/atom/thing = contents[i]
thing.GetAllContents(output, recursive_depth, ++_current_depth)
/atom/proc/GetAllContents()
var/list/processing_list = list(src)
var/list/assembled = list()
while(processing_list.len)
var/atom/A = processing_list[1]
processing_list.Cut(1, 2)
//Byond does not allow things to be in multiple contents, or double parent-child hierarchies, so only += is needed
//This is also why we don't need to check against assembled as we go along
processing_list += A.contents
assembled += A
return assembled
//Step-towards method of determining whether one atom can see another. Similar to viewers()
/proc/can_see(atom/source, atom/target, length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.