#Need help with optimization

1 messages · Page 1 of 1 (latest)

gloomy mesa
#

Im making a voxel based world gen system for my game but it loads painfully slow. it took about 3 minutes to load the terrain in the image. Can anyone help with making it quicker / more effective?

local seed = math.random(1, 1000)

local MAPSIZE = 200
local MAPSCALE = MAPSIZE / 2
local GROUND_DEPTH = 5
local STONE_DEPTH = 30

local grassTemplate = script.Parent.grass
local dirtTemplate = script.Parent.dirt
local stoneTemplate = script.Parent.rock

local terrainFolder = Instance.new("Folder")
terrainFolder.Name = "GeneratedTerrain"
terrainFolder.Parent = workspace

local BLOCK_SIZE = 3
local NOISE_SCALE = 1/10
local HEIGHT_MULT = 2.5
local HEIGHT_STEP = 3

for x = -MAPSCALE, MAPSCALE do
for z = -MAPSCALE, MAPSCALE do

    local height = math.floor(
        math.noise(seed, x * NOISE_SCALE, z * NOISE_SCALE) * HEIGHT_MULT
    ) * HEIGHT_STEP


    local worldX = x * BLOCK_SIZE
    local worldZ = z * BLOCK_SIZE


    local grassBlock = grassTemplate:Clone()
    grassBlock.CFrame = CFrame.new(worldX, height, worldZ)
    grassBlock.Parent = terrainFolder


    for d = 1, GROUND_DEPTH do
        local dirtBlock = dirtTemplate:Clone()
        dirtBlock.CFrame = CFrame.new(worldX, height - d * BLOCK_SIZE, worldZ)
        dirtBlock.Parent = terrainFolder
    end
    
    for d = 5, STONE_DEPTH do
        local stoneBlock = stoneTemplate:Clone()
        stoneBlock.CFrame = CFrame.new(worldX, height - d * BLOCK_SIZE, worldZ)
        stoneBlock.Parent = terrainFolder
    end
end

end

solemn escarp
#

i can tell you used ai

manic hedge
#

😮‍💨

gloomy mesa
#

this might js be a game theory but i think im going to be relentlessly bullied

manic hedge
limber knoll
#

Load terrain as you go or smth

gloomy mesa
solemn escarp
#

everyone ridicule this guy

manic hedge
limber knoll
#

atleast like 1000

#

woah more than that

manic hedge
limber knoll
#

i read 5 for some reason

manic hedge
#

try 1.2 million

gloomy mesa
manic hedge
gloomy mesa
#

i usually just do crappy web dev

manic hedge
#

this is why you don't copy code you don't understand, is it really any wonder you're confused why code you don't understand is slow?

solemn escarp
#

prolly like 6 or 7 instances 😂 🐒

manic hedge
#

perhaps try understanding it first before trying to optimize it

#

the number of instances this code creates is a very trivial fact you ought to know when making something like this, if you can't tell me that basic beginner fact, you aren't ready to work with this code.

gloomy mesa
#

by instances are you talking about the individual parts?

rustic widgetBOT
#

studio** You are now Level 1! **studio

manic hedge
gloomy mesa
#

oh

#

so im sped

#

its 200 x 200z 35 y

manic hedge
gloomy mesa
#

each part is about 3,3,3

limber knoll
#

I know this one!
1,400,000

manic hedge
#

that's how many instances there are.

#

i had 1.2mil from 200*200*30

#

same order of magnitude.

limber knoll
#

not including the dirt!

manic hedge
#

you can't expect 1.4million instances to somehow be created in a single frame

gloomy mesa
#

im aware there are that many

manic hedge
gloomy mesa
#

im asking how to limit the amount loaded at a time

manic hedge
#

that's why it's slow.

gloomy mesa
#

yeah i know why its slow

#

im asking how to limit the amount loaded without looking like poop

manic hedge
#

in fact if you want this to run at all reasonably you almost shouldn't even be using instances, why does voxels that couldn't ever possibly be visible to the player created?

#

with just that one change you'd probably cut that 1.4mil down to what, 200*200*3 at a guess? still extreme but that's already 10% of what you started with

gloomy mesa
#

well its also a semi minecraft clone so there is mining

manic hedge
#

how do you think minecraft does it...

limber knoll
#

but minecraft doesnt render every block at once, it renders only what the player can see.

manic hedge
#

this is just one of the many tricks minecraft does

gloomy mesa
#

yes i get that

limber knoll
#

Pryo im getting scripter 5 with these comms am i right or am i right

gloomy mesa
#

im trying to ask to hide the ones outside of view

limber knoll
#

just dont create them at all

manic hedge
#

because that is not entirely trivial depending what blocks you have, i.e glass

gloomy mesa
#

i js need a push in the right direction gng

#

not asking you to write my code

limber knoll
#

You need to figure what your render distance will be, then make them render when you reach a spot that needs to be rendered

manic hedge
# gloomy mesa i js need a push in the right direction gng

well i'm sure theres hundreds of videos out there on how minecraft pulls off what it does, and no doubt you have first hand experience, the first and most obvious technique you should know is simply not generating so much at once. in minecraft this is done with chunks. instead of loading the entire world at once, it loads it in smaller chunks at a time

#

the rest i mean

#

google bruh

#

google how does minecraft work with millions of blocks at once

#

watch videos

#

read documentation

#

etc

#

put in the effort, no one can do that for you even if they wanted to.

#

because you're just looking at merely generating a grid of cubes

#

wait until you get to saving and loading the whole thing as an entirely persistent world spanishkek you aint even beginner yet

solemn escarp
#

lmaooo

#

newgen

#

how long have u been scripting for nedla

rustic widgetBOT
#

studio** You are now Level 1! **studio

gloomy mesa
solemn escarp
#

lol

#

figures

#

def watch youtube

#

theres many good videos

manic hedge