mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-10 18:22:39 +00:00
Finally optimize radios
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user