I’m working on a terrain generator, and it takes aprox 0.6 seconds to generate a chunk.
I am passing the generation job to 24 actors at a time, so I’d expect it to make 24 chunks in 0.6 seconds, but it seems that it takes the same time as serial (14.4 seconds for 24 chunks).
This is the code I’m using to generate a individual chunk:
local PerlinNoise = require(game.ReplicatedStorage.Modules.PerlinNoise)
local HttpService = game:GetService("HttpService")
--task.desynchronize()
return function (chunk, position, extras)
task.desynchronize()
local chunkSize, seed, scale, amplitude, cave_scale, cave_amplitude = unpack(extras)
local blocks = table.create(chunkSize.X)
for x = 1, chunkSize.X + 1 do
if not blocks[x] then blocks[x] = table.create(chunkSize.Z) end
local real_x = position.X * chunkSize.X + x
for z = 1, chunkSize.Z + 1 do
if not blocks[x][z] then blocks[x][z] = table.create(chunkSize.Y) end
local real_z = position.Z * chunkSize.Z + z
for y = 75, chunkSize.Y + 1 do
local real_y = position.Y * chunkSize.Y + y
local cave_density = PerlinNoise.new({real_x, real_y, real_z, seed}, cave_scale) * cave_amplitude
local density = y + chunk.splineValue + PerlinNoise.new({real_x, real_y, real_z, seed}, scale, 3) * amplitude
local block = {
--position = Vector3.new(real_x, real_y, real_z),
material = "unknown",
}
--if density < 130 then
if cave_density > 25 then
block.material = "air"
else
if density < 130 or (density > 110 and density < 145) then
block.material = "stone"
else
--block.light = 0
block.material = "air"
end
end
blocks[x][z][y] = block
end
for y = 1, 75 do
local real_y = position.Y * chunkSize.Y + y
local cave_density = PerlinNoise.new({real_x, real_y, real_z, seed}, cave_scale) * cave_amplitude
local block = {
--position = Vector3.new(real_x, real_y, real_z),
material = "unknown",
}
if y < 3 then
block.material = "barrier"
else
if cave_density > 25 then
block.material = "air"
else
block.material = "stone"
end
end
blocks[x][z][y] = block
end
end
if x % 10 == 0 then
task.wait()
end
end
task.desynchronize()
task.synchronize()
for x = 1, chunkSize.X + 1 do
for z = 1, chunkSize.Z + 1 do
for y = 1, chunkSize.Y + 1 do
local block = blocks[x][z][y]
if block.material ~= "air" then
--[[local topBlock = blocks[x][z][y + 1]
if not topBlock or topBlock.material == "air" then
block.visible = true
end]]
else
for neighbor_x = -1, 1 do
for neighbor_y = -1, 1 do
for neighbor_z = -1, 1 do
if neighbor_z ~= 0 or not (neighbor_z == neighbor_x and neighbor_z == neighbor_y and neighbor_x == neighbor_y) then
local real_x = x + neighbor_x
local real_y = y + neighbor_y
local real_z = z + neighbor_z
if blocks[real_x] and blocks[real_x][real_z] then
local neighbor = blocks[real_x][real_z][real_y]
if neighbor then
neighbor.visible = true
end
end
end
end
end
end
end
end
end
if x % 10 == 0 then
task.wait()
end
end
task.synchronize()
return blocks
end
I’m loading this code on 24 different actors, each of them being a different script and everything, so I would expect this to work, but it seems it doesn’t