mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2025-12-25 17:42:26 +00:00
Code effeciency project: /proc/get_mobs_in_view
Before: Everytime you say something. This proc is ran. Along with it, recurses through EVERY /obj/ & /mob/ in view's contents, and EVERY /obj/ & /mob/ in that contents...and once again. After: Fuck recursion, we're going to loop through clients and see if they are within any obj's or mobs within one iteration. MUCH cheaper, and probably less buggy. If someone can't hear everyone and they are within an object and it's not catching? add it to the list commented for it of type checks.
This commit is contained in:
@@ -161,6 +161,8 @@
|
||||
// The old system would loop through lists for a total of 5000 per function call, in an empty server.
|
||||
// This new system will loop at around 1000 in an empty server.
|
||||
|
||||
// SCREW THAT SHIT, we're not recursing.
|
||||
|
||||
/proc/get_mobs_in_view(var/R, var/atom/source)
|
||||
// Returns a list of mobs in range of R from source. Used in radio and say code.
|
||||
|
||||
@@ -172,18 +174,45 @@
|
||||
|
||||
var/list/range = hear(R, T)
|
||||
|
||||
for(var/atom/A in range)
|
||||
if(ismob(A))
|
||||
var/mob/M = A
|
||||
if(M.client)
|
||||
hear += M
|
||||
//world.log << "Start = [M] - [get_turf(M)] - ([M.x], [M.y], [M.z])"
|
||||
else if(istype(A, /obj/item/device/radio))
|
||||
hear += A
|
||||
for(var/mob/M in range)
|
||||
if(M.client)
|
||||
hear += M
|
||||
|
||||
var/list/objects = list()
|
||||
|
||||
if(isobj(A) || ismob(A))
|
||||
hear |= recursive_mob_check(A, hear, 3, 1, 0, 1)
|
||||
var/list/obj_to_check = list() //IF SOMEONE DOESN'T HEAR SOMETHING AND ARE IN INSIDE A CONTAINER ADD IT TO THIS LIST.
|
||||
obj_to_check += typesof(/obj/item/device/paicard)
|
||||
obj_to_check += typesof(/obj/item/device/aicard)
|
||||
obj_to_check += typesof(/obj/machinery/computer/aifixer)
|
||||
|
||||
for(var/obj/O in range) //Get a list of objects in hearing range. We'll check to see if any clients have their "eye" set to the object
|
||||
if(istype(O, /obj/item/device/radio)) //This avoids all that bullshit with recursion. FUCK RECURSION ~Ccomp
|
||||
hear += O
|
||||
if(O.type in obj_to_check)
|
||||
for(var/mob/living/M in O.contents)
|
||||
if(!(M in hear))
|
||||
hear += M
|
||||
|
||||
|
||||
objects += O
|
||||
|
||||
for(var/client/C in clients)
|
||||
if(!istype(C) || !C.eye)
|
||||
continue //I have no idea when this client check would be needed, but if this runtimes people won't hear anything
|
||||
//So kinda paranoid about runtime avoidance.
|
||||
if(C.mob in hear)
|
||||
continue
|
||||
if(C.eye in (hear|objects))
|
||||
if(!(C.mob in hear))
|
||||
hear += C.mob
|
||||
|
||||
else if(!(C.mob in hear))
|
||||
if(C.mob.loc in (hear|objects))
|
||||
hear += C.mob
|
||||
else if(C.mob.loc.loc in (hear|objects))
|
||||
hear += C.mob
|
||||
|
||||
|
||||
return hear
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user