mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-27 18:42:44 +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)
|
||||
|
||||
29
code/game/objects/items/devices/radio/radio_ch.dm
Normal file
29
code/game/objects/items/devices/radio/radio_ch.dm
Normal file
@@ -0,0 +1,29 @@
|
||||
#define CANBROADCAST_INNERBOX 0.7071067811865476 //This is sqrt(2)/2
|
||||
/obj/item/device/radio/proc/can_broadcast_to()
|
||||
var/list/output = list()
|
||||
var/turf/T = get_turf(src)
|
||||
var/dnumber = canhear_range*CANBROADCAST_INNERBOX
|
||||
for(var/cand_x = max(0, T.x - canhear_range), cand_x <= T.x + canhear_range, cand_x++)
|
||||
for(var/cand_y = max(0, T.y - canhear_range), cand_y <= T.y + canhear_range, cand_y++)
|
||||
var/turf/cand_turf = locate(cand_x,cand_y,T.z)
|
||||
if(!cand_turf)
|
||||
continue
|
||||
if((abs(T.x - cand_x) < dnumber) || (abs(T.y - cand_y) < dnumber))
|
||||
output += cand_turf
|
||||
continue
|
||||
if(sqrt((T.x - cand_x)**2 + (T.y - cand_y)**2) <= canhear_range)
|
||||
output += cand_turf
|
||||
continue
|
||||
return output
|
||||
|
||||
/proc/testloop()
|
||||
for(var/i = 0,i<10,i++)
|
||||
world.log << i
|
||||
for(var/i = 0,i<10,++i)
|
||||
world.log << i
|
||||
|
||||
/proc/gimmeworldtime()
|
||||
return world.time
|
||||
|
||||
/proc/hehehe()
|
||||
qdel(world)
|
||||
2
code/game/turfs/turf_ch.dm
Normal file
2
code/game/turfs/turf_ch.dm
Normal file
@@ -0,0 +1,2 @@
|
||||
/turf
|
||||
var/list/temp_check = list()
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 60 KiB After Width: | Height: | Size: 76 KiB |
@@ -1223,6 +1223,7 @@
|
||||
#include "code\game\objects\items\devices\radio\jammer.dm"
|
||||
#include "code\game\objects\items\devices\radio\jammer_vr.dm"
|
||||
#include "code\game\objects\items\devices\radio\radio.dm"
|
||||
#include "code\game\objects\items\devices\radio\radio_ch.dm"
|
||||
#include "code\game\objects\items\devices\radio\radio_vr.dm"
|
||||
#include "code\game\objects\items\devices\radio\radio_yw.dm"
|
||||
#include "code\game\objects\items\devices\radio\radiopack.dm"
|
||||
@@ -1584,6 +1585,7 @@
|
||||
#include "code\game\turfs\simulated_vr.dm"
|
||||
#include "code\game\turfs\triggers_ch.dm"
|
||||
#include "code\game\turfs\turf.dm"
|
||||
#include "code\game\turfs\turf_ch.dm"
|
||||
#include "code\game\turfs\turf_changing.dm"
|
||||
#include "code\game\turfs\turf_flick_animations.dm"
|
||||
#include "code\game\turfs\unsimulated.dm"
|
||||
|
||||
Reference in New Issue
Block a user