Actual performance improvements for GetAllContents (#32029)

* Actual performance improvements for GetAllContents

* Shaving off literal tens of clock cycles
This commit is contained in:
Remie Richards
2017-10-26 11:02:11 +01:00
committed by CitadelStationBot
parent 630b332848
commit 649fe581fd

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.