Finally optimize radios

This commit is contained in:
cadyn
2020-11-22 21:20:05 -08:00
parent 6d9a342c0c
commit c55132d06d
5 changed files with 47 additions and 4 deletions

View File

@@ -223,11 +223,11 @@
return hear
var/mobs_radio_range_fired = 1 //CHOMPEdit
/proc/get_mobs_in_radio_ranges(var/list/obj/item/device/radio/radios)
set background = 1
var/our_iter = num2text(++mobs_radio_range_fired) //CHOMPEdit
. = list()
// Returns a list of mobs who can hear any of the radios given in @radios
var/list/speaker_coverage = list()
@@ -235,15 +235,25 @@
var/obj/item/device/radio/R = r // You better fucking be a radio.
var/turf/speaker = get_turf(R)
if(speaker)
for(var/turf/T in hear(R.canhear_range,speaker))
for(var/turf/T in R.can_broadcast_to()) //CHOMPEdit
T.temp_check[our_iter] = TRUE
speaker_coverage[T] = R
// Try to find all the players who can hear the message
//CHOMPEdit Begin
//So, to explain a bit here: The old code that used to be here was pretty slow for a few reasons, most of which have been addressed now.
//Unsurprisingly, checking through the entire list of turfs within a radio's range for every mob's turf to see if it's in there is very slow.
//So, instead, we set a variable in a list on the turf that's unique to this runthrough(and thus multiple of these can run simultaneously)
//Then we just have to check if that variable is true for the turf the mob is on, and if it is, add that mob to our list.
for(var/i = 1; i <= player_list.len; i++)
var/mob/M = player_list[i]
if(M.can_hear_radio(speaker_coverage))
var/turf/T = get_turf(M)
if(istype(T) && T.temp_check[our_iter])
. += M
for(var/turf/T in speaker_coverage)
T.temp_check -= our_iter //Freeing up the memory.
//CHOMPEdit End
return .
/mob/proc/can_hear_radio(var/list/hearturfs)