generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: How does the roblox terrain plugin load so fast (My terrain Load & Save scripts)

Previous Thread :: Next Thread 
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 12:41 PM
Alright, I made a simple but [u][b]slow[/b][/u] way to save and load terrain. When I see how fast the roblox generator works I get all jelly.

How do I SetCell()'s so fast??

Also how can I GetCell()'s so fast?

My current scripts

SAVE

[code]
t = game.Workspace.Terrain

model = Instance.new("Model")
model.Name = "terrain data"
model.Parent = game.Lighting

for x = 0,255 do
for z = 0,255 do
for y = 1,64 do
cm, cb, co = t:GetCell(x,y,z)
if cm ~= Enum.CellMaterial.Empty then
cell = Instance.new("StringValue")
cell.Value = tostring(cm)..","..tostring(cb)..","..tostring(co)..","..x..","..y..","..z
cell.Name = "Cell"
cell.Parent = model
wait(0.00000000001)
end
end
end
end

print("Quad I is loaded")

for x = 1,256 do
for z = 0,255 do
for y = 1,64 do
cm, cb, co = t:GetCell(-x,y,z)
if cm ~= Enum.CellMaterial.Empty then
cell = Instance.new("StringValue")
cell.Value = tostring(cm)..","..tostring(cb)..","..tostring(co)..","..-x..","..y..","..z
cell.Name = "Cell"
cell.Parent = model
wait(0.00000000001)
end
end
end
end

print("Quad II is loaded")

for x = 1,256 do
for z = 1,256 do
for y = 1,64 do
cm, cb, co = t:GetCell(-x,y,-z)
if cm ~= Enum.CellMaterial.Empty then
cell = Instance.new("StringValue")
cell.Value = tostring(cm)..","..tostring(cb)..","..tostring(co)..","..-x..","..y..","..-z
cell.Name = "Cell"
cell.Parent = model
wait(0.00000000001)
end
end
end
end

print("Quad III is loaded")

for x = 0,255 do
for z = 1,256 do
for y = 1,64 do
cm, cb, co = t:GetCell(x,y,-z)
if cm ~= Enum.CellMaterial.Empty then
cell = Instance.new("StringValue")
cell.Value = tostring(cm)..","..tostring(cb)..","..tostring(co)..","..x..","..y..","..-z
cell.Name = "Cell"
cell.Parent = model
wait(0.00000000001)
end
end
end
end

print("Quad IV is loaded")
[/code]

LOAD

[code]
t = game.Workspace.Terrain
maps = {"terrain data"}

for a,b in pairs(maps) do
if game.Lighting:FindFirstChild(b) ~= nil then
map = game.Lighting:FindFirstChild(b)
for c,d in pairs(map:GetChildren()) do
m,mm = string.find(d.Value,",")
cm = string.sub(d.Value,1,mm-1)
n,nn = string.find(d.Value,",",mm+1)
cb = string.sub(d.Value,mm+1,nn-1)
o,oo = string.find(d.Value,",",nn+1)
co = string.sub(d.Value,nn+1,oo-1)
p,pp = string.find(d.Value,",",oo+1)
x = string.sub(d.Value,oo+1,pp-1)
q,qq = string.find(d.Value,",",pp+1)
y = string.sub(d.Value,pp+1,qq-1)
z = string.sub(d.Value,qq+1)
t:SetCell(x,y,z,loadstring("return "..cm)(),loadstring("return "..cb)(),loadstring("return "..co)())
wait(0.000000000001)
end
end
end
[/code]


Now, the scripts do work, but it takes a long time to load a terrain and even longer to save a terrain.

How can I make them run much faster?

The way my scripts work is that it checks all possible terrain cells and saves them as stringvalues if they are not "Empty". Then my load script breaks up that string and recreates each cell. Pretty simple but slow.


_____________________________________

copy/paste from another forum I posted on, so yes I know there isn't BBcode
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 01:17 PM
Instead of string values, make a table.

~I've been to nil and back.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 01:21 PM
this might help.

local string = "value1:value2:value3:value4" -- separate individual values with ":"
local Storage = {}

for i in string.gmatch(info.Value,"[^:]+") do --splits all strings
table.insert(Storage,i) -- puts the values into a table
end
print(unpack(storage) -- prints the contents of the table.

~I've been to nil and back.
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 01:34 PM
I can't use tables as this stores each cell as a stringvalue in into a model. The load script then loads each cell from each string value in said model
Report Abuse
Phrosty is not online. Phrosty
Joined: 04 Jan 2012
Total Posts: 346
16 Jan 2012 01:41 PM
Herm.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 01:42 PM
what if you were to use the method i mentioned above, but instead, store all the values in one stringvalue and separate each value with a ":". Then when loading it split the strings and remove the ":".

~I've been to nil and back.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 01:47 PM
oh gawd. this certainly saves a LOT of values. i tryed to convert this to table form and it still saving all the values its at 5500

~I've been to nil and back.
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 01:49 PM
It would save on values but I don't think it would make it any faster.

I need a way to load and save several cells at one time.
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 01:52 PM
Actually, it may save time on the loading part, but the saving part would still be the same speed
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 01:56 PM
wait, i'm speeding it up. i'm seeing how many values i can input without crashing. i'm up to 200 right now, its starting to get a little laggy here and there.
(inserts 200 values then waits and repeats.)

~I've been to nil and back.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2012 01:58 PM
Every time I try to make a terrain save/load plugin, I end up having too many indices in a table and not enough memory which causes studio to crash :/

If I was good at math, I'd find a way to find similarities in quadrants and save them as a region3 instead of individual
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 01:59 PM
Oh ya, speaking of region3, how do you use that? :p

The wiki does not have documentation on it.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 02:01 PM
mmmm... yes it seems to freeze up at 20,000 values eventually unfreezes and starts to save slower (like 1 values perframe apposed to the previous 200), but maybe thats something with the script. i'll have to look.

~I've been to nil and back.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2012 02:02 PM
If you save a game with terrain then open up the game in Notepad++ or whatever, you can see how ROBLOX saves the terrain. It's just tons of numbers and stuff. But tables only can hold so much.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 02:07 PM
I'm just going to let this sit for a little while and see how much a table can hold, currently at 33,500

~I've been to nil and back.
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 02:10 PM
My script searches for 16,777,216 cells. If I can use a string value to hold 10 cells instead of one I may be able to load terrain 10 times faster.

hmmmmm
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 02:10 PM
But saving will still take forever.
Report Abuse
crazyman32 is not online. crazyman32
Joined: 13 Apr 2008
Total Posts: 18027
16 Jan 2012 02:11 PM
ROBLOX should let us write data to a folder. Then we could do this easily
Report Abuse
qaz32152 is not online. qaz32152
Joined: 21 Jul 2006
Total Posts: 6920
16 Jan 2012 02:12 PM
Roblox should let us access cells that are not "Empty" directly :\

At least then the saving would be probably 100 times faster.
Report Abuse
rayoma is not online. rayoma
Joined: 13 Nov 2009
Total Posts: 1911
16 Jan 2012 02:37 PM
How do you run out of indices when instantiating a 3-dimensional array? I believe the roblox terrain is only 2048x2048 and I've had much more data saved for terrain in roblox than that.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 02:46 PM
The script created a black hole and was sucked in O_O. i tried reworking it a little bit and after 5,000 it froze up, unfroze and the script disappeared!

~I've been to nil and back.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 03:39 PM
:\ i don't fully understand how the loading part works... this is what i have turned it into, but it gets stuck on the loading part.

t = game.Workspace.Terrain

model = Instance.new("Model")
model.Name = "terrain data"
model.Parent = game.Lighting
local Quad = {}
local message = Instance.new("Message",Workspace)
local numberCells = t:CountCells()
message.Text = "Saving Cells - "..0
local LoadSpeed = 10
local count = 0
for x = 0,255 do
for z = 0,255 do
for y = 1,64 do
cm, cb, co = t:GetCell(x,y,z)
if cm ~= Enum.CellMaterial.Empty then
count = count+1
if count == LoadSpeed then
wait()
count = 0
end
message.Text = "Saving Cells - "..#Quad.."/"..numberCells
table.insert(Quad,tostring(cm)..","..tostring(cb)..","..tostring(co)..","..x..","..y..","..z)
end
end
end
end

print("Quad I is loaded")

for x = 1,256 do
for z = 0,255 do
for y = 1,64 do
cm, cb, co = t:GetCell(-x,y,z)
if cm ~= Enum.CellMaterial.Empty then
count = count+1
if count == LoadSpeed then
wait()
count = 0
end
message.Text = "Saving Cells - "..#Quad.."/"..numberCells
table.insert(Quad,tostring(cm)..","..tostring(cb)..","..tostring(co)..","..-x..","..y..","..z)
wait()
end
end
end
end

print("Quad II is loaded")

for x = 1,256 do
for z = 1,256 do
for y = 1,64 do
cm, cb, co = t:GetCell(-x,y,-z)
if cm ~= Enum.CellMaterial.Empty then
count = count+1
if count == LoadSpeed then
wait()
count = 0
end
message.Text = "Saving Cells - "..#Quad.."/"..numberCells
table.insert(Quad,tostring(cm)..","..tostring(cb)..","..tostring(co)..","..-x..","..y..","..-z)
wait()
end
end
end
end

print("Quad III is loaded")

for x = 0,255 do
for z = 1,256 do
for y = 1,64 do
cm, cb, co = t:GetCell(x,y,-z)
if cm ~= Enum.CellMaterial.Empty then
count = count+1
if count == LoadSpeed then
wait()
count = 0
end
message.Text = "Saving Cells - "..#Quad.."/"..numberCells
table.insert(Quad,tostring(cm)..","..tostring(cb)..","..tostring(co)..","..x..","..y..","..-z)
wait()
end
end
end
end

print("Quad IV is loaded")
Workspace.Terrain:Clear()
-----------------Load----------------------
wait(5)

t = game.Workspace.Terrain
maps = {"terrain data"}
message.Text = "Loading Terrain - 0/"..#Quad
--cm = cell material, cb = cell block , co = cell orientation
for i = 1,#Quad do
message.Text = "Loading Terrain - "..i.."/"..#Quad
m,mm = string.find(Quad[i].Value,",")
cm = string.sub(Quad[i].Value,1,mm-1)
n,nn = string.find(Quad[i].Value,",",mm+1)
cb = string.sub(Quad[i].Value,mm+1,nn-1)
o,oo = string.find(Quad[i].Value,",",nn+1)
co = string.sub(Quad[i].Value,nn+1,oo-1)
p,pp = string.find(d.Value,",",oo+1)
x = string.sub(Quad[i].Value,oo+1,pp-1)
q,qq = string.find(Quad[i].Value,",",pp+1)
y = string.sub(Quad[i].Value,pp+1,qq-1)
z = string.sub(Quad[i].Value,qq+1)
t:SetCell(x,y,z,loadstring("return "..cm)(),loadstring("return "..cb)(),loadstring("return "..co)())
wait(0.000000000001)
end


~I've been to nil and back.
Report Abuse
MrgamesNwatch is not online. MrgamesNwatch
Joined: 02 Feb 2009
Total Posts: 7729
16 Jan 2012 04:22 PM
nvm, i got it working with a table now :D
now to see if i can improve the speed...

~I've been to nil and back.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image