Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("right")
- monitor.setCursorPos(1,1)
- monitor.setTextScale(0.5)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- monitor_width, monitor_height = monitor.getSize()
- monitor_width = monitor_width - 1
- monitor_height = monitor_height - 1
- print(monitor_width, monitor_height)
- print(peripheral.getMethods(peripheral.getName(monitor)))
- rednet.open("left")
- rednet.host("motherboard", tostring(os.getComputerID()))
- gpus = {rednet.lookup("GPU_process")}
- function sendDataToGPUS(data, gpus)
- for _, computer in pairs(gpus) do
- rednet.send(computer, data)
- end
- end
- -- an array of all the pixels in the monitor
- local monitor_pixels = {}
- for x = 1, monitor_width do
- monitor_pixels[x] = {}
- for y = 1, monitor_height do
- monitor_pixels[x][y] = 0
- end
- end
- -- environment to move around
- function createEnvironment(width, height)
- local env = {}
- for x = 1, width do
- env[x] = {}
- for y = 1, height do
- env[x][y] = 0
- end
- end
- return env
- end
- function buildEnvWalls(env, width, height)
- for x = 1, width do
- env[x][1] = 1
- env[x][height] = 1
- end
- for y = 1, height do
- env[1][y] = 1
- env[width][y] = 1
- end
- end
- playground = createEnvironment(10, 10)
- buildEnvWalls(playground, 10, 10)
- player_location = {2,7}
- rot = math.pi/4
- computer_peripheral = term.current()
- function distibutedRayCast(env, player_location, gpus)
- local x = player_location[1]
- local y = player_location[2]
- computer_data_pairs = {}
- count = 0
- screen = {}
- working_gpus = #gpus
- for i, computer_id in pairs(gpus) do
- rot_i = rot + math.rad((i) - monitor_width/2)
- sin, cos = 0.1*math.sin(rot_i), 0.1*math.cos(rot_i)
- rednet.send(computer_id, {x, y, rot_i, sin, cos, env})
- computer_data_pairs[computer_id] = i
- end
- while true do
- local id, message = rednet.receive(nil, 10)
- if message == nil then
- break
- end
- x_loc = computer_data_pairs[id]
- n = message
- h = (10/(n*math.cos(math.rad(x_loc - monitor_width/2)))) * 80
- term.redirect(monitor)
- paintutils.drawLine(monitor_width-x_loc, (monitor_height/2)-(h/2), monitor_width-x_loc, (monitor_height/2)+(h/2), colors.white)
- term.redirect(computer_peripheral)
- count = count + 1
- if x_loc+#gpus < monitor_width then
- x_loc = x_loc + #gpus
- rot_i = rot + math.rad((x_loc) - monitor_width/2)
- sin, cos = 0.1*math.sin(rot_i), 0.1*math.cos(rot_i)
- rednet.send(id, {x, y, rot_i, sin, cos, env})
- computer_data_pairs[id] = x_loc
- else
- working_gpus = working_gpus - 1
- if working_gpus == 0 then
- break
- end
- end
- end
- end
- distibutedRayCast(playground, player_location, gpus)
- -- rayCast(playground, player_location)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement