Hello Fellows, I need a lil’ help getting this renderer working faster and better.
The idea is to lower the amount of loops in the program and get the grid of pixels that the screen is, bigger. Currently the limit I have it for decent running is at a 25 FPS and a 40x40 grid screen.
Game: 2D Raycast Renderer - Roblox
RBXL File:–
Beware of some bizzare variable names…
Client Renderer Code (Inside a SurfaceGui in PlayerGui)
--scripted by GreekForge
local rs = game:GetService("RunService")
local lib = require(script.Parent.Parent:WaitForChild("Library")) --cuts down on other uses, isn't involved in rendering
local coms = game.ReplicatedStorage.Remotes.Simple
local gui = script.Parent
local pFold = gui.Pixels --folder that contains the pixels
local on = false
local loading = false
local grid = 40 --50 is a lil mucho
local fovM = 0.6 -- 0.5 is about 90 degree fov
local pixel = Instance.new("TextLabel")
pixel.Text = "" --lmao
pixel.Size = UDim2.new(0, (800/grid), 0, (800/grid)) --800 is the size of the surfaceGui, I should just reference it tbh
pixel.BackgroundColor3 = Color3.fromRGB(170, 0, 0)
pixel.BorderSizePixel = 0
--What we shall use to render, the MINIMAP si (on the server)
local mach = workspace.MinimapMachine
local minMap = mach.MiniMap
local user = minMap.User --this is the lil part in the minimap machine
local function generatePixels()
loading = true
coroutine.wrap(function()
for x=0, (grid-1) do
coroutine.wrap(function()
for y=0, (grid-1) do
local p = pixel:Clone()
p.Position = UDim2.new(0, x*(800/grid), 0, y*(800/grid))
p.Name = "Pixel("..x..","..y..")"
p.Parent = pFold
wait()
end
end)()
--wait()
end
repeat wait() until #pFold:GetChildren() >= (grid*grid)
loading = false
end)()
end
local function clear() --creates the "sky box"
for i=0, (grid-1) do
local gH = grid/2
for j=0, (grid-1) do
local nam = "Pixel("..i..","..j..")"
local pix = pFold:FindFirstChild(nam)
if j > gH then
pix.BackgroundColor3 = Color3.fromRGB(150, 100, 100)
else
pix.BackgroundColor3 = Color3.fromRGB(150, 150, 255)
end
end
end
end
coms.OnClientEvent:Connect(function(pass) --si, wasteful I guess
if pass == "On" then
on = true
elseif pass == "Off" then
on = false
end
end)
coroutine.wrap(function() --sends the keys used to the server "Bleh"
while wait() do
if on then
local kys = lib.getKeys()
coms:FireServer(kys) --means the part is server side, possibly not a good idea
wait(0.05)
end
end
end)()
while wait(1/25) do --wait seems to have a cap :T I think 30 Mhz
if on then --if not using, why render?
if #pFold:GetChildren() == 0 and not loading then
generatePixels() --gotta have a screen
end
if not loading then
clear()
local uCF = user.CFrame
local edge1 = -uCF.LookVector + (uCF.UpVector*fovM)
local edge2 = -uCF.LookVector - (uCF.UpVector*fovM)
for i=0, (grid-1) do --its grid -1 because of how its generated
local dir = edge2:Lerp(edge1, ((i+0.5)/grid)) --starts on edge1 and as we travel on the x axis of the gui we get closer to edge2
local hit, pos = workspace:FindPartOnRayWithIgnoreList(Ray.new(user.Position, dir*10), {user, user.Face})
if hit then
local gH = grid/2 --gridHalf
local m1 = 1 - math.clamp(((pos - uCF.Position).Magnitude)/8, 0, 1) --simply the ratio of how far
local m2 = math.floor((m1 * grid)/2) --gets the pixels needed to fill, by half
local s1 = gH - m2 --where it begins shading the walls
if m2 ~= 0 then
for j=s1, math.clamp(((gH+m2)-1), (gH+1), (grid-1)) do --renders
local nam = "Pixel("..i..","..j..")"
local pix = pFold:FindFirstChild(nam)
if pix then
local perc = ((pos - user.Position).Magnitude / 3.5) or 1 --how "bright" the colors are
pix.BackgroundColor3 = Color3.new(hit.Color.r*perc, hit.Color.g*perc, hit.Color.b*perc)
end
end
end
end
end
end
end
end
Picture of device: