speeds up get_hearers_in_view/getallcontents just a little bit (#48975)

* Update game.dm

* Update unsorted.dm

* good point

* one indexed lists and ++i is faster

* ditto
This commit is contained in:
kevinz000
2020-02-01 00:43:59 -07:00
committed by GitHub
parent 6115c9213a
commit cf7cb8751e
2 changed files with 20 additions and 25 deletions

View File

@@ -152,11 +152,11 @@
/proc/recursive_hear_check(O) /proc/recursive_hear_check(O)
var/list/processing_list = list(O) var/list/processing_list = list(O)
. = list() . = list()
while(processing_list.len) var/i = 0
var/atom/A = processing_list[1] while(i < length(processing_list))
var/atom/A = processing_list[++i]
if(A.flags_1 & HEAR_1) if(A.flags_1 & HEAR_1)
. += A . += A
processing_list.Cut(1, 2)
processing_list += A.contents processing_list += A.contents
/** recursive_organ_check /** recursive_organ_check
@@ -200,10 +200,8 @@
// Returns a list of hearers in view(R) from source (ignoring luminosity). Used in saycode. // Returns a list of hearers in view(R) from source (ignoring luminosity). Used in saycode.
var/turf/T = get_turf(source) var/turf/T = get_turf(source)
. = list() . = list()
if(!T) if(!T)
return return
var/list/processing_list = list() var/list/processing_list = list()
if (R == 0) // if the range is zero, we know exactly where to look for, we can skip view if (R == 0) // if the range is zero, we know exactly where to look for, we can skip view
processing_list += T.contents // We can shave off one iteration by assuming turfs cannot hear processing_list += T.contents // We can shave off one iteration by assuming turfs cannot hear
@@ -216,12 +214,12 @@
processing_list += O processing_list += O
T.luminosity = lum T.luminosity = lum
while(processing_list.len) // recursive_hear_check inlined here var/i = 0
var/atom/A = processing_list[1] while(i < length(processing_list)) // recursive_hear_check inlined here
var/atom/A = processing_list[++i]
if(A.flags_1 & HEAR_1) if(A.flags_1 & HEAR_1)
. += A . += A
SEND_SIGNAL(A, COMSIG_ATOM_HEARER_IN_VIEW, processing_list, .) SEND_SIGNAL(A, COMSIG_ATOM_HEARER_IN_VIEW, processing_list, .)
processing_list.Cut(1, 2)
processing_list += A.contents processing_list += A.contents
/proc/get_mobs_in_radio_ranges(list/obj/item/radio/radios) /proc/get_mobs_in_radio_ranges(list/obj/item/radio/radios)
@@ -231,7 +229,6 @@
if(R) if(R)
. |= get_hearers_in_view(R.canhear_range, R) . |= get_hearers_in_view(R.canhear_range, R)
#define SIGNV(X) ((X<0)?-1:1) #define SIGNV(X) ((X<0)?-1:1)
/proc/inLineOfSight(X1,Y1,X2,Y2,Z=1,PX1=16.5,PY1=16.5,PX2=16.5,PY2=16.5) /proc/inLineOfSight(X1,Y1,X2,Y2,Z=1,PX1=16.5,PY1=16.5,PX2=16.5,PY2=16.5)

View File

@@ -460,36 +460,34 @@ Turf and target are separate in case you want to teleport some distance from a t
/atom/proc/GetAllContents(var/T) /atom/proc/GetAllContents(var/T)
var/list/processing_list = list(src) var/list/processing_list = list(src)
var/list/assembled = list()
if(T) if(T)
while(processing_list.len) . = list()
var/atom/A = processing_list[1] var/i = 0
processing_list.Cut(1, 2) while(i < length(processing_list))
var/atom/A = processing_list[++i]
//Byond does not allow things to be in multiple contents, or double parent-child hierarchies, so only += is needed //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 //This is also why we don't need to check against assembled as we go along
processing_list += A.contents processing_list += A.contents
if(istype(A,T)) if(istype(A,T))
assembled += A . += A
else else
while(processing_list.len) var/i = 0
var/atom/A = processing_list[1] while(i < length(processing_list))
processing_list.Cut(1, 2) var/atom/A = processing_list[++i]
processing_list += A.contents processing_list += A.contents
assembled += A return processing_list
return assembled
/atom/proc/GetAllContentsIgnoring(list/ignore_typecache) /atom/proc/GetAllContentsIgnoring(list/ignore_typecache)
if(!length(ignore_typecache)) if(!length(ignore_typecache))
return GetAllContents() return GetAllContents()
var/list/processing = list(src) var/list/processing = list(src)
var/list/assembled = list() . = list()
while(processing.len) var/i = 0
var/atom/A = processing[1] while(i < length(processing))
processing.Cut(1,2) var/atom/A = processing[++i]
if(!ignore_typecache[A.type]) if(!ignore_typecache[A.type])
processing += A.contents processing += A.contents
assembled += A . += A
return assembled
//Step-towards method of determining whether one atom can see another. Similar to viewers() //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. /proc/can_see(atom/source, atom/target, length=5) // I couldnt be arsed to do actual raycasting :I This is horribly inaccurate.