ID:2708041
 
Had an idea since my raycaster uses a 1D array for the map instead of creating ray objects and having them move on the actual BYOND map they're simulated.

This increased performance by x10 at least, my idea is that there is a function such as

cast(source,angle,fov,ray_step_size,max_steps)


that could return all the atom's hit.

I created this as an example of what I mean

proc/density_map(atom/object,range=0)
var list/density_map[range+1][range+1]
var middle = round(range / 2)
var list/turfs = block(locate(object.x-range,object.y-range,object.z),locate(object.x+range,object.y+range,object.z))
var x=0,y=1
/*Build Grid*/
for(var/turf/t in turfs)
x++
if(x > range)
x = 1
y++
density_map[x][y] = t.density
density_map[middle][middle] = 0
return density_map


Could have something like it built-in that allows us to return a 1D or 2D array of the map's density in chuncks/blocks and from there we could use that to send rays. Having a single function called cast() would be awesome af tho.
tl;dr - Add a Cast(source,angle,fov,ray_step_size,max_steps) function that creates a internal 1D/2D array of the map's density at source's location. Then send out rays along the angle and fov using the step_size specified, and stop the stepping at max_steps using the virtual map.

Results --> x10+ Increase in raycasting performance

Having this built-in would be freakin awesome o:


Running at 30fps able to cast across a 32x32 map with 120 FOV. world.cpu doesn't seem to be correct as there's no slowdown even tho it shows 100-170% CPU usage.

If there was a continuious density map built-in that could take advantage of virtual rays then this would be awesome q_q
proc/MapToGrid(z_level=1)
var max_x = world.maxx
var max_y = world.maxy
var x,y
var turf/turf
var list/objects
var object
var list/map[max_x][max_y]
for(y=1 to max_y)
for(x = 1 to max_x)
turf = locate(x,y,z_level)
objects = new
if(turf.density)
objects += turf
for(object in turf.contents)
if(object:density){objects += object}
map[x][y] = objects
return map

var list/map


mob/Login()
..()
global.map = MapToGrid(1)
src.Cast(0,32)

atom/movable/proc/Cast(angle,max_steps)
var list/hits = list()
var rx, rsx, ry, rsy, steps
for()
rx = x
ry = y
rsx = sin(angle) / 32
rsy = cos(angle) / 32
for(steps = 1 to max_steps)
rx += rsx
ry += rsy
if(map[round(rx)][round(ry)])
hits += map[round(rx)][round(ry)]
break
return hits
Able to send rays and hit objects with almost no cpu usage. Sending out 64 rays and coloring the object they hit red 30 times a second based on my angle.