Optimized radio code broadcasting code.

Rather than calling a function on every single radio object which expensively collects hearers(in closets etc.), the proc will now instead build a list of radios. This list is then passed to another proc, which iterates through all clients in the world, and checks if the client's mob can hear the message.

Note that I did shallow testing, but deeper issues may still be present with stuff like pAIs which I wasn't able to test on my single player server. If any other problems are found, please notify me.


git-svn-id: http://tgstation13.googlecode.com/svn/trunk@4019 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
CIB123@gmail.com
2012-07-09 15:16:00 +00:00
parent ae23259f3e
commit b687b75bca
7 changed files with 80 additions and 59 deletions
+11 -20
View File
@@ -4,6 +4,7 @@
icon_state = "intercom"
anchored = 1
w_class = 4.0
canhear_range = 4
var/number = 0
var/anyai = 1
var/mob/living/silicon/ai/ai = list()
@@ -26,31 +27,21 @@
send_hear(freq)
var/range = receive_range(freq)
if(range > 0)
return get_mobs_in_view(canhear_range, src)
receive_range(freq)
if (!(src.wires & WIRE_RECEIVE))
return
return 0
if (!src.listening)
return
return 0
if(freq == SYND_FREQ)
if(!(src.syndie))
return//Prevents broadcast of messages over devices lacking the encryption
/*
var/turf/T = get_turf(src)
var/list/hear = hearers(7, T)
var/list/V
//find mobs in lockers, cryo and intellycards
for(var/mob/M in world)
if (isturf(M.loc))
continue //if M can hear us it is already was found by hearers()
if (!M.client)
continue //skip monkeys and leavers
if (!V) //lasy initialisation
V = view(7, T)
if (get_turf(M) in V) //this slow, but I don't think we'd have a lot of wardrobewhores every round --rastaf0
hear+=M
*/
//return hear
return 0//Prevents broadcast of messages over devices lacking the encryption
return get_mobs_in_view(4, src)
return canhear_range
hear_talk(mob/M as mob, msg)
+16 -32
View File
@@ -619,27 +619,23 @@ var/GLOBAL_RADIO_TYPE = 1 // radio type to use
return null
return
*/
/obj/item/device/radio/proc/send_hear(freq)
/*
I'm removing this because this is apparently a REALLY REALLY bad thing and causes
people's transmissions to get cut off. This also means radios have no delay. A
fair price to pay for reliable radios. -- Doohl
if(last_transmission && world.time < (last_transmission + TRANSMISSION_DELAY))
return
last_transmission = world.time
*/
/obj/item/device/radio/proc/receive_range(freq)
// check if this radio can receive on the given frequency, and if so,
// what the range is in which mobs will hear the radio
// returns: 0 if can't receive, range otherwise
if (!(wires & WIRE_RECEIVE))
return
return 0
if(freq == SYND_FREQ)
if(!(src.syndie))//Checks to see if it's allowed on that frequency, based on the encryption keys
return
return 0
if (!on)
return
return 0
if (!freq) //recieved on main frequency
if (!listening)
return
return 0
else
var/accept = (freq==frequency && listening)
if (!accept)
@@ -649,28 +645,16 @@ var/GLOBAL_RADIO_TYPE = 1 // radio type to use
accept = 1
break
if (!accept)
return
return 0
/* // UURAAAGH ALL THE CPUS, WASTED. ALL OF THEM. NO. -- Doohl
var/turf/T = get_turf(src)
var/list/hear = hearers(1, T)
var/list/V
//find mobs in lockers, cryo and intellicards, brains, MMIs, and so on.
for (var/mob/M in world)
if (isturf(M.loc))
continue //if M can hear us it is already was found by hearers()
if (!M.client)
continue //skip monkeys and leavers
if (!V) //lasy initialisation
V = view(1, T)
if (get_turf(M) in V) //this slow, but I don't think we'd have a lot of wardrobewhores every round --rastaf0
hear+=M
*/
return canhear_range
/* Instead, let's individually search potential containers for mobs! More verbose but a LOT more efficient and less laggy */
// Check gamehelpers.dm for the proc definition:
/obj/item/device/radio/proc/send_hear(freq)
var/range = receive_range(freq)
if(range > 0)
return get_mobs_in_view(canhear_range, src)
return get_mobs_in_view(canhear_range, src)
/obj/item/device/radio/examine()
set src in view()