From 62aebce039bf02c0425c7f4376419d15e29f3eef Mon Sep 17 00:00:00 2001 From: xxalpha Date: Fri, 26 Aug 2016 01:05:57 +0100 Subject: [PATCH] bettering of get area procs (#20066) typecacheof Removed get_all_area_atoms proc. else ispath is valid too --- code/__HELPERS/unsorted.dm | 76 ++++++++++--------- .../machinery/porta_turret/portable_turret.dm | 5 +- 2 files changed, 42 insertions(+), 39 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 773692ad84e..dc90e583805 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -624,58 +624,60 @@ Turf and target are seperate in case you want to teleport some distance from a t //Takes: Area type as text string or as typepath OR an instance of the area. //Returns: A list of all areas of that type in the world. -/proc/get_areas(areatype) - if(!areatype) - return null +/proc/get_areas(areatype, subtypes=TRUE) if(istext(areatype)) areatype = text2path(areatype) - if(isarea(areatype)) + else if(isarea(areatype)) var/area/areatemp = areatype areatype = areatemp.type + else if(!ispath(areatype)) + return null - var/list/areas = new/list() - for(var/area/N in world) - if(istype(N, areatype)) - areas += N + var/list/areas = list() + if(subtypes) + var/list/cache = typecacheof(areatype) + for(var/V in sortedAreas) + var/area/A = V + if(cache[A.type]) + areas += V + else + for(var/V in sortedAreas) + var/area/A = V + if(A.type == areatype) + areas += V return areas //Takes: Area type as text string or as typepath OR an instance of the area. //Returns: A list of all turfs in areas of that type of that type in the world. -/proc/get_area_turfs(areatype, target_z = 0) - if(!areatype) - return null +/proc/get_area_turfs(areatype, target_z = 0, subtypes=FALSE) if(istext(areatype)) areatype = text2path(areatype) - if(isarea(areatype)) + else if(isarea(areatype)) var/area/areatemp = areatype areatype = areatemp.type + else if(!ispath(areatype)) + return null - var/list/turfs = new/list() - for(var/area/N in world) - if(istype(N, areatype)) - for(var/turf/T in N) + var/list/turfs = list() + if(subtypes) + var/list/cache = typecacheof(areatype) + for(var/V in sortedAreas) + var/area/A = V + if(!cache[A.type]) + continue + for(var/turf/T in A) + if(target_z == 0 || target_z == T.z) + turfs += T + else + for(var/V in sortedAreas) + var/area/A = V + if(A.type != areatype) + continue + for(var/turf/T in A) if(target_z == 0 || target_z == T.z) turfs += T return turfs -//Takes: Area type as text string or as typepath OR an instance of the area. -//Returns: A list of all atoms (objs, turfs, mobs) in areas of that type of that type in the world. -/proc/get_area_all_atoms(areatype) - if(!areatype) - return null - if(istext(areatype)) - areatype = text2path(areatype) - if(isarea(areatype)) - var/area/areatemp = areatype - areatype = areatemp.type - - var/list/atoms = new/list() - for(var/area/N in world) - if(istype(N, areatype)) - for(var/atom/A in N) - atoms += A - return atoms - /proc/get_cardinal_dir(atom/A, atom/B) var/dx = abs(B.x - A.x) var/dy = abs(B.y - A.y) @@ -1299,13 +1301,13 @@ B --><-- A /proc/get_areas_in_z(zlevel) . = list() - var/validarea = 0 + var/validarea = FALSE for(var/V in sortedAreas) var/area/A = V - validarea = 1 + validarea = TRUE for(var/turf/T in A) if(T.z != zlevel) - validarea = 0 + validarea = FALSE break if(validarea) . += A diff --git a/code/game/machinery/porta_turret/portable_turret.dm b/code/game/machinery/porta_turret/portable_turret.dm index ad8778733da..c76ef4b40ef 100644 --- a/code/game/machinery/porta_turret/portable_turret.dm +++ b/code/game/machinery/porta_turret/portable_turret.dm @@ -717,7 +717,8 @@ /obj/machinery/turretid/initialize() //map-placed turrets autolink turrets if(control_area && istext(control_area)) - for(var/area/A in world) + for(var/V in sortedAreas) + var/area/A = V if(A.name == control_area) control_area = A break @@ -729,7 +730,7 @@ else control_area = CA - for(var/obj/machinery/porta_turret/T in get_area_all_atoms(control_area)) + for(var/obj/machinery/porta_turret/T in control_area) turrets |= T /obj/machinery/turretid/attackby(obj/item/I, mob/user, params)