From 917f48ae2ac9648695fb548c7c5cd046edabbaf6 Mon Sep 17 00:00:00 2001 From: Kapu1178 <75460809+Kapu1178@users.noreply.github.com> Date: Tue, 11 Jul 2023 01:28:35 -0400 Subject: [PATCH] Optimize get_hearers_in_view() (#421) * swap out view() for hearers() * docs --- code/__HELPERS/spatial_info.dm | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/code/__HELPERS/spatial_info.dm b/code/__HELPERS/spatial_info.dm index 58f4cd95ec30..6786f3e3944b 100644 --- a/code/__HELPERS/spatial_info.dm +++ b/code/__HELPERS/spatial_info.dm @@ -104,23 +104,17 @@ var/list/assigned_oranges_ears = SSspatial_grid.assign_oranges_ears(hearables_from_grid) - var/old_luminosity = center_turf.luminosity - center_turf.luminosity = 6 //man if only we had an inbuilt dview() - //this is the ENTIRE reason all this shit is worth it due to how view() works and can be optimized //view() constructs lists of viewed atoms by default and specifying a specific type of atom to look for limits the lists it constructs to those of that //primitive type and then when the view operation is completed the output is then typechecked to only iterate through objects in view with the same - //typepath. by assigning one /mob/oranges_ear to every turf with hearable atoms on it and giving them references to each one means that: - //1. view() only constructs lists of atoms with the mob primitive type and - //2. the mobs returned by view are fast typechecked to only iterate through /mob/oranges_ear mobs, which guarantees at most one per turf - //on a whole this can outperform iterating through all movables in view() by ~2x especially when hearables are a tiny percentage of movables in view - for(var/mob/oranges_ear/ear in view(view_radius, center_turf)) + //typepath. by assigning one /mob/oranges_ear to every turf with hearable atoms on it and giving them references to each one means that + //hearers() can be used over view(), which is a huge speed increase. + for(var/mob/oranges_ear/ear in hearers(view_radius, center_turf)) . += ear.references for(var/mob/oranges_ear/remaining_ear as anything in assigned_oranges_ears)//we need to clean up our mess remaining_ear.unassign() - center_turf.luminosity = old_luminosity return . /**