Hello guys,
I’ve been working on this cloud function today , and it seems to work as intended, however I have a problem with its loading. After initiating one cloud, the app will pause for about half a second. Is there a way to do heavy resource functions on a different thread, or having the function spread over a longer amount of time so that it doesnt lag the app?
The cloud function draws a few thousand meshes with 30k? vertices every time its called using a self feeding loop.
cloudcontainer = {}
cloudcontainer2 = {["locx"] = {}, ["locy"] = {}, ["speedx"] = {}, ["speedy"] = {}}
rWIDTH = 1000
rHEIGHT = 1000
globalScale = 1
function setup()
end
function draw()
background(40,40,40)
for i = 1, #cloudcontainer do
sprite(cloudcontainer[i],cloudcontainer2["locx"][i],cloudcontainer2["locy"][i])
end
if CurrentTouch.state == BEGAN then
table.insert(cloudcontainer, cloudini(math.random(0,1.0)))
table.insert(cloudcontainer2["locx"], math.random(rWIDTH*globalScale))
table.insert(cloudcontainer2["locy"], math.random(rWIDTH*globalScale))
end
end
function cloudini()
local objectcloudtemp = {}
local w = 40
local cWIDTH = 300
local cHEIGHT = 300
objectcloudtemp = clouddup(w,cWIDTH,cHEIGHT)
local objectcloudtemp2 = {}
for i = 1, #objectcloudtemp do
table.insert(objectcloudtemp2, ellipsemesh(objectcloudtemp[i][1], objectcloudtemp[i][2], objectcloudtemp[i][3]))
end
local cloudtemp1 = {}
for i = 1, #objectcloudtemp2 do
for j = 1, #objectcloudtemp2[i] do
table.insert(cloudtemp1, objectcloudtemp2[i][j])
end
end
local cloudtemp2 = mesh()
cloudtemp2.vertices = cloudtemp1
cloudtemp2:setColors(255,255,255,12)
local cloudImage = image(600,600)
setContext(cloudImage)
cloudtemp2:draw()
setContext()
return cloudImage
end
function clouddup(w,cWIDTH,cHEIGHT)
local containertemp = {}
local w2 = 40
local limit = 5
while w > limit do
for i = 1 , 2 do
local tempval = math.random(8)
local cloudradius = w - tempval
w = w - tempval
local cloudduptemp = {}
cloudlocvarx = math.random(-w2, w2)
cloudlocvary = math.random(math.ceil(-w2/2), math.ceil(w2/4))
cloudduptemp = clouddup(w,cWIDTH+cloudlocvarx,cHEIGHT+cloudlocvary)
for i = 1, #cloudduptemp do
table.insert(containertemp, cloudduptemp[i])
end
if cloudradius < limit then cloudsradius = limit end
table.insert(containertemp, {cWIDTH+cloudlocvarx, cHEIGHT+cloudlocvary, cloudradius})
end
end
return containertemp
end
function ellipsemesh(locx,locy,size)
local x,y,i,angle
local cos,sin,rad = math.cos,math.sin,math.rad
local vertices = {}
for i = 1,18 do
table.insert(vertices,vec3(locx+0,locy+0,0))
angle = rad(20*(i-1))
x = size*cos(angle)
y = size*sin(angle)
table.insert(vertices,vec3(locx+x,locy+y,0))
angle = rad(20*i)
x = size*cos(angle)
y = size*sin(angle)
table.insert(vertices,vec3(locx+x,locy+y,0))
end
return vertices
end